RepairSaleService.java 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. package com.fdkankan.sale.service.impl;
  2. import java.math.BigDecimal;
  3. import java.util.*;
  4. import com.alibaba.fastjson.JSONObject;
  5. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  6. import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
  7. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  8. import com.fdkankan.sale.common.PageInfo;
  9. import com.fdkankan.sale.common.RepairStatusEnum;
  10. import com.fdkankan.sale.common.ResultCode;
  11. import com.fdkankan.sale.common.ResultData;
  12. import com.fdkankan.sale.entity.*;
  13. import com.fdkankan.sale.exception.BusinessException;
  14. import com.fdkankan.sale.service.*;
  15. import com.fdkankan.sale.util.DateUtil;
  16. import com.fdkankan.sale.util.StatusUtil;
  17. import com.fdkankan.sale.vo.request.*;
  18. import com.fdkankan.sale.vo.response.PriceListVo;
  19. import com.fdkankan.sale.vo.response.RepairRegisterPartVo;
  20. import com.fdkankan.sale.vo.response.RepairerVo;
  21. import org.apache.commons.lang3.StringUtils;
  22. import org.springframework.beans.BeanUtils;
  23. import org.springframework.beans.factory.annotation.Autowired;
  24. import org.springframework.stereotype.Service;
  25. import java.util.stream.Collectors;
  26. @Service
  27. public class RepairSaleService {
  28. @Autowired
  29. IRepairService repairService;
  30. @Autowired
  31. IRepairLogService repairLogService;
  32. @Autowired
  33. IOrderReceivingService orderReceivingService;
  34. @Autowired
  35. ICustomerService customerService;
  36. @Autowired
  37. ICustomerAddressService customerAddressService;
  38. @Autowired
  39. ICameraService cameraService;
  40. @Autowired
  41. ISysUserService sysUserService;
  42. @Autowired
  43. IRepairRegisterService repairRegisterService;
  44. @Autowired
  45. IRepairRegisterPartService repairRegisterPartService;
  46. @Autowired
  47. IPriceListService priceListService;
  48. @Autowired
  49. IRepairPayService repairPayService;
  50. @Autowired
  51. IPartService partService;
  52. @Autowired
  53. ILaborCostService laborCostService;
  54. @Autowired
  55. RepairSupplyService repairSupplyService;
  56. /**
  57. * 售后工程师
  58. * statusParam 0 待接单,1待跟进,2已完结
  59. * * status 0待接单,10待检测,20待报价,30待确认,40已取消,50待备料,60维修中,70待测试,
  60. * * 80待支付(已完结),90待回收,100待发货,110已发货
  61. */
  62. public PageInfo saleOrderList(RepairParam param) {
  63. List<Integer> repairStatus = StatusUtil.getSaleStatus(param.getStatusParam());
  64. param.setStatusList(repairStatus);
  65. Page<RepairerVo> voPage = repairService.saleOrderList(param);
  66. sysUserService.setSaleNameAndRepairManName(voPage.getRecords());
  67. BigDecimal payAmount;
  68. for (RepairerVo record : voPage.getRecords()) {
  69. if(record.getStatus().equals(RepairStatusEnum.TO_BE_CANCELED.status())){
  70. payAmount = priceListService.getRobAmountByRepairId(record.getRepairId());
  71. }else {
  72. payAmount = priceListService.getAmountByRepairId(record.getRepairId());
  73. }
  74. record.setPayAmount(payAmount);
  75. }
  76. return PageInfo.PageInfo(voPage);
  77. }
  78. public void orderReceiving(OrderReceivingParam param, Long sysUserId ) {
  79. if(param.getRepairId() == null){
  80. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  81. }
  82. Repair repair = repairService.getById(param.getRepairId());
  83. if(repair == null){
  84. throw new BusinessException(ResultCode.REPAIR_NOT_EXITS);
  85. }
  86. if(!repair.getStatus().equals(RepairStatusEnum.TO_BE_RECEIVED.status())){
  87. throw new BusinessException(ResultCode.REPAIR_STATUS_NOT_EXITS);
  88. }
  89. param.setSysUserId(sysUserId);
  90. param.setOrderFaultMsg(param.getCameraFaultInfo());
  91. param.setOrderFaultImg(param.getImageUrl());
  92. orderReceivingService.save(param);
  93. repairLogService.saveBySysUser(sysUserId,param.getRepairId(), RepairStatusEnum.TO_BE_CHECK.status(),"客服接单");
  94. }
  95. public void recording(RecordingParam param, Long userId,Integer receiverType) {
  96. if(StringUtils.isBlank(param.getCameraSnCode())){
  97. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  98. }
  99. Camera camera = cameraService.getBySnCode(param.getCameraSnCode());
  100. if(camera == null){
  101. throw new BusinessException(ResultCode.CAMERA_SN_NOT_EXITS);
  102. }
  103. List<Repair> repairList = repairService.getBySnCode(camera.getSnCode());
  104. if(repairList.size() >0){
  105. for (Repair repair : repairList) {
  106. if(!StatusUtil.overStatusList.contains(repair.getStatus())){
  107. throw new BusinessException(ResultCode.REPAIR_SN_EXITS);
  108. }
  109. }
  110. }
  111. CameraDetail cameraDetail = cameraService.getCameraTypeByCameraId(camera.getId());
  112. Integer cameraType = null;
  113. switch (cameraDetail.getType()){
  114. case 9: cameraType = 1;break;
  115. case 10: cameraType = 2;break;
  116. default: cameraType = 0; break;
  117. }
  118. Date outTime = cameraDetail.getOutTime() == null ? cameraDetail.getCreateTime() : cameraDetail.getOutTime();
  119. Date date = DateUtil.dateAddOneYear(outTime, 1);
  120. date = DateUtil.dateAddOne(date, 7);
  121. String date1 = DateUtil.getDate(DateUtil.dayFmt, date) +" 23:59:59";
  122. Repair repair = new Repair();
  123. BeanUtils.copyProperties(param,repair);
  124. repair.setRepairId(DateUtil.getDate(DateUtil.repairIdFmt));
  125. repair.setReceiverType(receiverType);
  126. repair.setCameraType(cameraType);
  127. repair.setSysUserId(userId);
  128. repair.setWarrantyDate(date1);
  129. repair.setWarrantyType(2);
  130. if(DateUtil.getDateByStr(date1).getTime() >= new Date().getTime()){
  131. repair.setWarrantyType(0);
  132. }
  133. Customer customer = new Customer();
  134. BeanUtils.copyProperties(param,customer);
  135. customer.setRepairId(repair.getRepairId());
  136. customerService.save(customer);
  137. CustomerAddress customerAddress = new CustomerAddress();
  138. BeanUtils.copyProperties(param,customerAddress);
  139. customerAddress.setCustomerId(customer.getCustomerId());
  140. customerAddress.setRepairId(repair.getRepairId());
  141. customerAddressService.save(customerAddress);
  142. repairService.save(repair);
  143. repairLogService.saveBySysUser(userId,repair.getRepairId(),RepairStatusEnum.TO_BE_RECEIVED.status(),"报修");
  144. }
  145. public void addOrUpdatePriceList(PriceListParam param, Long userId) {
  146. if(StringUtils.isBlank(param.getRepairId()) ||
  147. param.getPriceLists() == null || param.getPriceLists().size() <=0){
  148. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  149. }
  150. Repair repair = repairService.getById(param.getRepairId());
  151. if(repair == null){
  152. throw new BusinessException(ResultCode.REPAIR_NOT_EXITS);
  153. }
  154. if(!repair.getStatus().equals(RepairStatusEnum.TO_BE_QUOTED.status())
  155. && !repair.getStatus().equals(RepairStatusEnum.TO_BE_CONFIRMED.status())){
  156. throw new BusinessException(ResultCode.REPAIR_STATUS_NOT_EXITS);
  157. }
  158. HashMap<Integer,Part> partMap = partService.getHashMap();
  159. HashMap<Integer,LaborCost> laborMap = laborCostService.getHashMap();
  160. List<PriceList> priceListList = priceListService.getByRepairId(repair.getRepairId());
  161. HashMap<Integer,PriceList> priceListHashMap = new HashMap<>();
  162. priceListList.forEach(entity -> priceListHashMap.put(entity.getPriceListId(),entity));
  163. priceListService.delNoCm(repair.getRepairId());
  164. for (PriceList priceList : param.getPriceLists()) {
  165. if(priceList.getType() == null){
  166. throw new BusinessException(ResultCode.PRICE_TYPE_NOT);
  167. }
  168. if(priceList.getType() == 0){
  169. if(priceList.getPartId() == null || partMap.get(priceList.getPartId()) == null || priceList.getDiscount() == null){
  170. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  171. }
  172. Part part = partMap.get(priceList.getPartId());
  173. priceList.setPrice(part.getPartPrice());
  174. priceList.setPriceDiscount(part.getPartPriceDiscount());
  175. priceList.setName(part.getPartName());
  176. }
  177. if(priceList.getType() == 1){
  178. if(priceList.getLaborId() == null || laborMap.get(priceList.getLaborId()) == null){
  179. throw new BusinessException(ResultCode.LABOR_ID_EMPTY);
  180. }
  181. LaborCost laborCost = laborMap.get(priceList.getLaborId());
  182. priceList.setPrice(laborCost.getPrice());
  183. priceList.setName(laborCost.getName());
  184. priceList.setPriceListId(null);
  185. }
  186. priceList.setRepairId(param.getRepairId());
  187. if(priceList.getPriceListId() != null){
  188. PriceList priceList1 = priceListHashMap.get(priceList.getPriceListId());
  189. if(priceList1 != null){
  190. priceList.setStatus(priceList1.getStatus());
  191. }
  192. priceList.setPriceListId(null);
  193. priceListService.save(priceList);
  194. }else {
  195. priceListService.save(priceList);
  196. }
  197. }
  198. repairLogService.saveBySysUser(userId,param.getRepairId(),RepairStatusEnum.TO_BE_CONFIRMED.status(),"维修报价");
  199. }
  200. public PriceListVo getPriceList(String repairId) {
  201. if(StringUtils.isBlank(repairId)){
  202. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  203. }
  204. List<PriceList> priceLists = priceListService.getByRepairId(repairId);
  205. List<RepairLog> repairLogs = repairLogService.getByRepairIdAndStatus(repairId, RepairStatusEnum.TO_BE_CONFIRMED.status());
  206. PriceListVo priceListVo = new PriceListVo();
  207. priceListVo.setPriceLists(priceLists);
  208. priceListVo.setCount(repairLogs.size() +1);
  209. return priceListVo;
  210. }
  211. public void payRegister(PayRegisterParam param,Long userId) {
  212. if(StringUtils.isBlank(param.getRepairId())
  213. || param.getPayType() == null || param.getPayImg() == null){
  214. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  215. }
  216. Repair repair = repairService.getById(param.getRepairId());
  217. if(repair == null){
  218. throw new BusinessException(ResultCode.REPAIR_NOT_EXITS);
  219. }
  220. if(!repair.getStatus().equals(RepairStatusEnum.TO_BE_CANCELED.status()) && !repair.getStatus().equals(RepairStatusEnum.TO_BE_PAID.status())){
  221. throw new BusinessException(ResultCode.REPAIR_STATUS_NOT_EXITS);
  222. }
  223. BigDecimal payAmount;
  224. if(repair.getStatus().equals(RepairStatusEnum.TO_BE_CANCELED.status())){
  225. payAmount = priceListService.getRobAmountByRepairId(repair.getRepairId());
  226. }else {
  227. payAmount = priceListService.getAmountByRepairId(repair.getRepairId());
  228. }
  229. RepairPay repairPay = new RepairPay();
  230. repairPay.setRepairId(repair.getRepairId());
  231. repairPay.setPayType(param.getPayType());
  232. repairPay.setPayImg(param.getPayImg());
  233. repairPay.setPayStatus(1);
  234. repairPay.setSysUserId(userId);
  235. repairPay.setPayAmount(payAmount);
  236. repairPay.setPayTime(DateUtil.getDate());
  237. repairPay.setOrderType(0);
  238. repairPay.setOrderSn("se_s"+DateUtil.getDate(DateUtil.repairIdFmt));
  239. repairPayService.save(repairPay);
  240. List<RepairRegisterPartVo> partVoList = repairSupplyService.partInfo(repairPay.getRepairId(), 1);
  241. if(partVoList.size() >0){
  242. repairLogService.saveBySysUser(userId,param.getRepairId(),RepairStatusEnum.TO_BE_RECOVERED.status(), "付款登记");
  243. }else {
  244. repairLogService.saveBySysUser(userId,param.getRepairId(),RepairStatusEnum.TO_BE_SHIPPED.status(), "付款登记");
  245. }
  246. }
  247. public void sendRegister(PayRegisterParam param,Long userId) {
  248. if(StringUtils.isBlank(param.getRepairId()) || param.getGetType() == null){
  249. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  250. }
  251. Repair repair = repairService.getById(param.getRepairId());
  252. if(repair == null){
  253. throw new BusinessException(ResultCode.REPAIR_NOT_EXITS);
  254. }
  255. if(!repair.getStatus().equals(RepairStatusEnum.TO_BE_SHIPPED.status())){
  256. throw new BusinessException(ResultCode.REPAIR_STATUS_NOT_EXITS);
  257. }
  258. customerAddressService.setTrackingNumByRepairId(repair.getRepairId(),param.getGetType(),param.getTrackingNum());
  259. repairLogService.saveBySysUser(userId,param.getRepairId(),RepairStatusEnum.OVER_SHIPPED.status(),"发货登记");
  260. }
  261. }