| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.web.controller;
|
1 |
package com.spice.profitmandi.web.controller;
|
| 2 |
|
2 |
|
| 3 |
import java.time.LocalDate;
|
3 |
import java.time.LocalDate;
|
| 4 |
import java.time.LocalDateTime;
|
4 |
import java.time.LocalDateTime;
|
| - |
|
5 |
import java.time.format.DateTimeFormatter;
|
| 5 |
import java.util.ArrayList;
|
6 |
import java.util.ArrayList;
|
| 6 |
import java.util.Arrays;
|
7 |
import java.util.Arrays;
|
| 7 |
import java.util.Comparator;
|
8 |
import java.util.Comparator;
|
| 8 |
import java.util.HashMap;
|
9 |
import java.util.HashMap;
|
| 9 |
import java.util.List;
|
10 |
import java.util.List;
|
| Line 11... |
Line 12... |
| 11 |
import java.util.Map.Entry;
|
12 |
import java.util.Map.Entry;
|
| 12 |
import java.util.Set;
|
13 |
import java.util.Set;
|
| 13 |
import java.util.stream.Collectors;
|
14 |
import java.util.stream.Collectors;
|
| 14 |
|
15 |
|
| 15 |
import javax.servlet.http.HttpServletRequest;
|
16 |
import javax.servlet.http.HttpServletRequest;
|
| - |
|
17 |
import javax.servlet.http.HttpServletResponse;
|
| 16 |
|
18 |
|
| - |
|
19 |
import org.apache.commons.csv.CSVRecord;
|
| 17 |
import org.apache.logging.log4j.LogManager;
|
20 |
import org.apache.logging.log4j.LogManager;
|
| 18 |
import org.apache.logging.log4j.Logger;
|
21 |
import org.apache.logging.log4j.Logger;
|
| 19 |
import org.springframework.beans.factory.annotation.Autowired;
|
22 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 20 |
import org.springframework.format.annotation.DateTimeFormat;
|
23 |
import org.springframework.format.annotation.DateTimeFormat;
|
| 21 |
import org.springframework.http.MediaType;
|
24 |
import org.springframework.http.MediaType;
|
| Line 25... |
Line 28... |
| 25 |
import org.springframework.ui.Model;
|
28 |
import org.springframework.ui.Model;
|
| 26 |
import org.springframework.web.bind.annotation.RequestBody;
|
29 |
import org.springframework.web.bind.annotation.RequestBody;
|
| 27 |
import org.springframework.web.bind.annotation.RequestMapping;
|
30 |
import org.springframework.web.bind.annotation.RequestMapping;
|
| 28 |
import org.springframework.web.bind.annotation.RequestMethod;
|
31 |
import org.springframework.web.bind.annotation.RequestMethod;
|
| 29 |
import org.springframework.web.bind.annotation.RequestParam;
|
32 |
import org.springframework.web.bind.annotation.RequestParam;
|
| - |
|
33 |
import org.springframework.web.bind.annotation.RequestPart;
|
| - |
|
34 |
import org.springframework.web.multipart.MultipartFile;
|
| 30 |
|
35 |
|
| 31 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
36 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 32 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
37 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
| 33 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
38 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| - |
|
39 |
import com.spice.profitmandi.common.util.FileUtil;
|
| 34 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
40 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
| 35 |
import com.spice.profitmandi.dao.entity.auth.AuthUser;
|
41 |
import com.spice.profitmandi.dao.entity.auth.AuthUser;
|
| 36 |
import com.spice.profitmandi.dao.entity.auth.PartnerCollectionPlan;
|
42 |
import com.spice.profitmandi.dao.entity.auth.PartnerCollectionPlan;
|
| 37 |
import com.spice.profitmandi.dao.entity.auth.PartnerCollectionRemark;
|
43 |
import com.spice.profitmandi.dao.entity.auth.PartnerCollectionRemark;
|
| 38 |
import com.spice.profitmandi.dao.entity.auth.PartnerSecondaryPlan;
|
44 |
import com.spice.profitmandi.dao.entity.auth.PartnerSecondaryPlan;
|
| Line 85... |
Line 91... |
| 85 |
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
|
91 |
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
|
| 86 |
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
|
92 |
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
|
| 87 |
import com.spice.profitmandi.service.PartnerCollectionService;
|
93 |
import com.spice.profitmandi.service.PartnerCollectionService;
|
| 88 |
import com.spice.profitmandi.service.user.RetailerService;
|
94 |
import com.spice.profitmandi.service.user.RetailerService;
|
| 89 |
import com.spice.profitmandi.service.user.StoreTimelineTatService;
|
95 |
import com.spice.profitmandi.service.user.StoreTimelineTatService;
|
| - |
|
96 |
|
| 90 |
import com.spice.profitmandi.web.req.CreateFranchiseeRequest;
|
97 |
import com.spice.profitmandi.web.req.CreateFranchiseeRequest;
|
| 91 |
import com.spice.profitmandi.web.res.Partner;
|
98 |
import com.spice.profitmandi.web.res.Partner;
|
| 92 |
|
99 |
|
| 93 |
import io.swagger.annotations.ApiImplicitParam;
|
100 |
import io.swagger.annotations.ApiImplicitParam;
|
| 94 |
import io.swagger.annotations.ApiImplicitParams;
|
101 |
import io.swagger.annotations.ApiImplicitParams;
|
| Line 944... |
Line 951... |
| 944 |
&& partnerCollectionPlan.getCollectionPlan() == ptam.getCollectionTarget()) {
|
951 |
&& partnerCollectionPlan.getCollectionPlan() == ptam.getCollectionTarget()) {
|
| 945 |
partnerCollectionPlan.setCommitedTimestamp(ptam.getCollectionCommitmentDate().atStartOfDay());
|
952 |
partnerCollectionPlan.setCommitedTimestamp(ptam.getCollectionCommitmentDate().atStartOfDay());
|
| 946 |
partnerCollectionPlan.setUpdatedTimestamp(LocalDateTime.now());
|
953 |
partnerCollectionPlan.setUpdatedTimestamp(LocalDateTime.now());
|
| 947 |
}
|
954 |
}
|
| 948 |
|
955 |
|
| 949 |
PartnerCollectionRemark pcr = new PartnerCollectionRemark();
|
- |
|
| 950 |
pcr.setFofoId(ptam.getFofoId());
|
- |
|
| 951 |
pcr.setAuthId(authUser.getId());
|
- |
|
| 952 |
pcr.setMessage("Collection plan for" + ptam.getCollectionCommitmentDate());
|
- |
|
| 953 |
pcr.setRemark(CollectionRemark.COLLECTION_PLAN);
|
- |
|
| 954 |
pcr.setCreateTimestamp(LocalDateTime.now());
|
- |
|
| 955 |
partnerCollectionRemarkRepository.persist(pcr);
|
- |
|
| 956 |
}
|
956 |
}
|
| - |
|
957 |
|
| - |
|
958 |
PartnerCollectionRemark pcr = new PartnerCollectionRemark();
|
| - |
|
959 |
pcr.setFofoId(ptam.getFofoId());
|
| - |
|
960 |
pcr.setAuthId(authUser.getId());
|
| - |
|
961 |
pcr.setMessage("Collection plan for" + ptam.getCollectionCommitmentDate());
|
| - |
|
962 |
pcr.setRemark(CollectionRemark.COLLECTION_PLAN);
|
| - |
|
963 |
pcr.setCreateTimestamp(LocalDateTime.now());
|
| - |
|
964 |
partnerCollectionRemarkRepository.persist(pcr);
|
| 957 |
} else {
|
965 |
} else {
|
| 958 |
throw new ProfitMandiBusinessException("Date", "",
|
966 |
throw new ProfitMandiBusinessException("Date", "",
|
| 959 |
"you can't select the back date " + ptam.getCollectionCommitmentDate());
|
967 |
"you can't select the back date " + ptam.getCollectionCommitmentDate());
|
| 960 |
}
|
968 |
}
|
| 961 |
|
969 |
|
| Line 1122... |
Line 1130... |
| 1122 |
@RequestMapping(value = "/getCollectionRemark", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
1130 |
@RequestMapping(value = "/getCollectionRemark", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 1123 |
@ApiImplicitParams({
|
1131 |
@ApiImplicitParams({
|
| 1124 |
|
1132 |
|
| 1125 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
1133 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
| 1126 |
public ResponseEntity<?> getCollectionRemark(HttpServletRequest request) throws ProfitMandiBusinessException {
|
1134 |
public ResponseEntity<?> getCollectionRemark(HttpServletRequest request) throws ProfitMandiBusinessException {
|
| 1127 |
|
- |
|
| - |
|
1135 |
List<CollectionRemark> remarks = Arrays.asList(CollectionRemark.values()).stream()
|
| - |
|
1136 |
.filter(x -> !x.equals(CollectionRemark.COLLECTION_PLAN)).collect(Collectors.toList());
|
| 1128 |
return responseSender.ok(CollectionRemark.values());
|
1137 |
return responseSender.ok(remarks);
|
| 1129 |
}
|
1138 |
}
|
| 1130 |
|
1139 |
|
| 1131 |
@RequestMapping(value = "/createPartnerColectionRemark", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
|
1140 |
@RequestMapping(value = "/createPartnerColectionRemark", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 1132 |
@ApiImplicitParams({
|
1141 |
@ApiImplicitParams({
|
| 1133 |
|
1142 |
|
| Line 1145... |
Line 1154... |
| 1145 |
pcr.setCreateTimestamp(LocalDateTime.now());
|
1154 |
pcr.setCreateTimestamp(LocalDateTime.now());
|
| 1146 |
partnerCollectionRemarkRepository.persist(pcr);
|
1155 |
partnerCollectionRemarkRepository.persist(pcr);
|
| 1147 |
return responseSender.ok(true);
|
1156 |
return responseSender.ok(true);
|
| 1148 |
|
1157 |
|
| 1149 |
}
|
1158 |
}
|
| - |
|
1159 |
|
| - |
|
1160 |
@RequestMapping(value = "/uploadFranchiseeVisit", method = RequestMethod.POST)
|
| - |
|
1161 |
public ResponseEntity<?> readCsvFileAndSetLead(HttpServletRequest request, @RequestPart MultipartFile multipartFile)
|
| - |
|
1162 |
throws Throwable {
|
| - |
|
1163 |
|
| - |
|
1164 |
int id = (int) request.getAttribute("userId");
|
| - |
|
1165 |
|
| - |
|
1166 |
LOGGER.info("id" + id);
|
| - |
|
1167 |
|
| - |
|
1168 |
User user = userRepository.selectById(id);
|
| - |
|
1169 |
|
| - |
|
1170 |
AuthUser authUser = authRepository.selectByEmailOrMobile(user.getEmailId());
|
| - |
|
1171 |
|
| - |
|
1172 |
String fileName = multipartFile.getName();
|
| - |
|
1173 |
String fileNames = multipartFile.getOriginalFilename();
|
| - |
|
1174 |
|
| - |
|
1175 |
LOGGER.info("fileName" + fileName);
|
| - |
|
1176 |
LOGGER.info("fileNames" + fileNames);
|
| - |
|
1177 |
|
| - |
|
1178 |
List<CSVRecord> records = FileUtil.readFile(multipartFile);
|
| - |
|
1179 |
|
| - |
|
1180 |
for (CSVRecord record : records) {
|
| - |
|
1181 |
FranchiseeVisit franchiseeVisit = new FranchiseeVisit();
|
| - |
|
1182 |
franchiseeVisit.setFofoId(Integer.parseInt(record.get(0)));
|
| - |
|
1183 |
CustomRetailer customRetailer = retailerService.getFofoRetailer(Integer.parseInt(record.get(0)));
|
| - |
|
1184 |
|
| - |
|
1185 |
franchiseeVisit.setPartnerName(customRetailer.getBusinessName());
|
| - |
|
1186 |
franchiseeVisit.setAgenda(record.get(1));
|
| - |
|
1187 |
franchiseeVisit.setCreatedTimestamp(LocalDateTime.now());
|
| - |
|
1188 |
franchiseeVisit.setUpdatedTimestamp(LocalDateTime.now());
|
| - |
|
1189 |
franchiseeVisit.setStatus(FranchiseeVisitStatus.OPEN);
|
| - |
|
1190 |
|
| - |
|
1191 |
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy");
|
| - |
|
1192 |
LOGGER.info(record.get(1));
|
| - |
|
1193 |
LocalDate dateTime = LocalDate.parse(record.get(2), formatter);
|
| - |
|
1194 |
|
| - |
|
1195 |
franchiseeVisit.setSchelduleTimestamp(dateTime.atStartOfDay());
|
| - |
|
1196 |
// change
|
| - |
|
1197 |
|
| - |
|
1198 |
String authUserName = authUser.getFirstName() + " " + authUser.getLastName();
|
| - |
|
1199 |
franchiseeVisit.setCreatedBy(authUserName);
|
| - |
|
1200 |
franchiseeVisit.setAuthId(authUser.getId());
|
| - |
|
1201 |
|
| - |
|
1202 |
franchiseeVisitRepository.persist(franchiseeVisit);
|
| - |
|
1203 |
|
| - |
|
1204 |
return responseSender.ok(true);
|
| - |
|
1205 |
}
|
| - |
|
1206 |
|
| - |
|
1207 |
return responseSender.ok(true);
|
| - |
|
1208 |
|
| - |
|
1209 |
}
|
| 1150 |
}
|
1210 |
}
|
| 1151 |
|
1211 |
|