RepairSaleService.java 12 KB

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