RepairSaleService.java 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. package com.fdkankan.sale.service.impl;
  2. import java.math.BigDecimal;
  3. import java.util.Date;
  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.ResultCode;
  10. import com.fdkankan.sale.entity.*;
  11. import com.fdkankan.sale.exception.BusinessException;
  12. import com.fdkankan.sale.service.*;
  13. import com.fdkankan.sale.util.DateUtil;
  14. import com.fdkankan.sale.util.StatusUtil;
  15. import com.fdkankan.sale.vo.request.*;
  16. import com.fdkankan.sale.vo.response.PriceListVo;
  17. import com.fdkankan.sale.vo.response.RepairerVo;
  18. import org.apache.commons.lang3.StringUtils;
  19. import org.springframework.beans.BeanUtils;
  20. import org.springframework.beans.factory.annotation.Autowired;
  21. import org.springframework.stereotype.Service;
  22. import java.util.ArrayList;
  23. import java.util.List;
  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. /**
  50. * 售后工程师
  51. * statusParam 0 待接单,1待跟进,2已完结
  52. * status 0待接单,1待检测,2待报价,3待确认,4已取消,5待备料,6待回收,7维修中,8待测试,
  53. * 9待支付(已完结),10待发货,11已发货,12已评价
  54. */
  55. public PageInfo saleOrderList(RepairParam param) {
  56. List<Integer> repairStatus = StatusUtil.getSaleStatus(param.getStatusParam());
  57. param.setStatusList(repairStatus);
  58. Page<RepairerVo> voPage = repairService.saleOrderList(param);
  59. for (RepairerVo record : voPage.getRecords()) {
  60. BigDecimal payAmount = priceListService.getAmountByRepairId(record.getRepairId());
  61. record.setPayAmount(payAmount);
  62. }
  63. return PageInfo.PageInfo(voPage);
  64. }
  65. public void orderReceiving(OrderReceivingParam param, Long sysUserId ) {
  66. if(param.getRepairId() == null){
  67. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  68. }
  69. param.setSysUserId(sysUserId);
  70. orderReceivingService.save(param);
  71. repairLogService.saveBySysUser(sysUserId,param.getRepairId(),1,"接单");
  72. }
  73. public void recording(RecordingParam param, Long userId,Integer receiverType) {
  74. if(StringUtils.isBlank(param.getCameraSnCode())){
  75. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  76. }
  77. Camera camera = cameraService.getBySnCode(param.getCameraSnCode());
  78. if(camera == null){
  79. throw new BusinessException(ResultCode.CAMERA_SN_NOT_EXITS);
  80. }
  81. Integer cameraType = cameraService.getCameraTypeByCameraId(camera.getId());
  82. Repair repair = new Repair();
  83. BeanUtils.copyProperties(param,repair);
  84. repair.setRepairId(DateUtil.getDate(DateUtil.repairIdFmt));
  85. repair.setCameraType(cameraType);
  86. repair.setSysUserId(userId);
  87. Customer customer = new Customer();
  88. BeanUtils.copyProperties(param,customer);
  89. customer.setRepairId(repair.getRepairId());
  90. customerService.save(customer);
  91. CustomerAddress customerAddress = new CustomerAddress();
  92. BeanUtils.copyProperties(param,customerAddress);
  93. customerAddress.setCustomerId(customer.getCustomerId());
  94. customerAddress.setRepairId(repair.getRepairId());
  95. customerAddressService.save(customerAddress);
  96. repairService.save(repair);
  97. repairLogService.saveBySysUser(userId,repair.getRepairId(),0,"录单");
  98. //自动接单
  99. if(receiverType == 0){
  100. OrderReceiving orderReceiving = new OrderReceiving();
  101. BeanUtils.copyProperties(param,orderReceiving);
  102. orderReceiving.setOrderFaultImg(param.getFaultImg());
  103. orderReceiving.setOrderFaultMsg(param.getFaultMsg());
  104. orderReceiving.setSysUserId(userId);
  105. orderReceiving.setRepairId(repair.getRepairId());
  106. orderReceivingService.save(orderReceiving);
  107. repairLogService.saveBySysUser(userId,repair.getRepairId(),1,"接单");
  108. }
  109. }
  110. public void addOrUpdatePriceList(PriceListParam param, Long userId) {
  111. if(StringUtils.isBlank(param.getRepairId()) ||
  112. param.getPriceLists() == null || param.getPriceLists().size() <=0){
  113. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  114. }
  115. Repair repair = repairService.getById(param.getRepairId());
  116. if(repair == null){
  117. throw new BusinessException(ResultCode.REPAIR_NOT_EXITS);
  118. }
  119. List<PriceList> priceLists = param.getPriceLists();
  120. for (PriceList priceList : priceLists) {
  121. priceList.setRepairId(param.getRepairId());
  122. }
  123. priceListService.saveOrUpdateBatch(priceLists);
  124. repairLogService.saveBySysUser(userId,param.getRepairId(),3,"维修报价");
  125. }
  126. public PriceListVo getPriceList(String repairId) {
  127. if(StringUtils.isBlank(repairId)){
  128. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  129. }
  130. List<PriceList> priceLists = priceListService.getByRepairId(repairId);
  131. List<RepairLog> repairLogs = repairLogService.getByRepairIdAndStatus(repairId, 3);
  132. PriceListVo priceListVo = new PriceListVo();
  133. priceListVo.setPriceLists(priceLists);
  134. priceListVo.setCount(repairLogs.size() +1);
  135. return priceListVo;
  136. }
  137. public void payRegister(PayRegisterParam param,Long userId) {
  138. if(StringUtils.isBlank(param.getRepairId())
  139. || param.getPayType() == null || StringUtils.isBlank(param.getPayImg())){
  140. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  141. }
  142. Repair repair = repairService.getById(param.getRepairId());
  143. if(repair == null){
  144. throw new BusinessException(ResultCode.REPAIR_NOT_EXITS);
  145. }
  146. RepairPay repairPay = new RepairPay();
  147. repairPay.setRepairId(repair.getRepairId());
  148. repairPay.setPayType(param.getPayType());
  149. repairPay.setPayImg(param.getPayImg());
  150. repairPay.setSysUserId(userId);
  151. repairPayService.save(repairPay);
  152. repairLogService.saveBySysUser(userId,param.getRepairId(),10,"付款登记");
  153. }
  154. public void sendRegister(PayRegisterParam param,Long userId) {
  155. if(StringUtils.isBlank(param.getRepairId()) || StringUtils.isBlank(param.getTrackingNum())){
  156. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  157. }
  158. Repair repair = repairService.getById(param.getRepairId());
  159. if(repair == null){
  160. throw new BusinessException(ResultCode.REPAIR_NOT_EXITS);
  161. }
  162. customerAddressService.setTrackingNumByRepairId(repair.getRepairId(),param.getTrackingNum());
  163. repairLogService.saveBySysUser(userId,param.getRepairId(),11,"发货登记");
  164. }
  165. }