RepairSaleService.java 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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.ResultCode;
  10. import com.fdkankan.sale.common.ResultData;
  11. import com.fdkankan.sale.entity.*;
  12. import com.fdkankan.sale.exception.BusinessException;
  13. import com.fdkankan.sale.service.*;
  14. import com.fdkankan.sale.util.DateUtil;
  15. import com.fdkankan.sale.util.StatusUtil;
  16. import com.fdkankan.sale.vo.request.*;
  17. import com.fdkankan.sale.vo.response.PriceListVo;
  18. import com.fdkankan.sale.vo.response.RepairerVo;
  19. import org.apache.commons.lang3.StringUtils;
  20. import org.springframework.beans.BeanUtils;
  21. import org.springframework.beans.factory.annotation.Autowired;
  22. import org.springframework.stereotype.Service;
  23. import java.util.stream.Collectors;
  24. @Service
  25. public class RepairSaleService {
  26. @Autowired
  27. IRepairService repairService;
  28. @Autowired
  29. IRepairLogService repairLogService;
  30. @Autowired
  31. IOrderReceivingService orderReceivingService;
  32. @Autowired
  33. ICustomerService customerService;
  34. @Autowired
  35. ICustomerAddressService customerAddressService;
  36. @Autowired
  37. ICameraService cameraService;
  38. @Autowired
  39. ISysUserService sysUserService;
  40. @Autowired
  41. IRepairRegisterService repairRegisterService;
  42. @Autowired
  43. IRepairRegisterPartService repairRegisterPartService;
  44. @Autowired
  45. IPriceListService priceListService;
  46. @Autowired
  47. IRepairPayService repairPayService;
  48. @Autowired
  49. IPartService partService;
  50. @Autowired
  51. ILaborCostService laborCostService;
  52. /**
  53. * 售后工程师
  54. * statusParam 0 待接单,1待跟进,2已完结
  55. * status 0待接单,1待检测,2待报价,3待确认,4已取消,5待备料,6待回收,7维修中,8待测试,
  56. * 9待支付(已完结),10待发货,11已发货,12已评价
  57. */
  58. public PageInfo saleOrderList(RepairParam param) {
  59. List<Integer> repairStatus = StatusUtil.getSaleStatus(param.getStatusParam());
  60. param.setStatusList(repairStatus);
  61. Page<RepairerVo> voPage = repairService.saleOrderList(param);
  62. sysUserService.setSaleNameAndRepairManName(voPage.getRecords());
  63. for (RepairerVo record : voPage.getRecords()) {
  64. BigDecimal payAmount = priceListService.getAmountByRepairId(record.getRepairId());
  65. record.setPayAmount(payAmount);
  66. }
  67. return PageInfo.PageInfo(voPage);
  68. }
  69. public void orderReceiving(OrderReceivingParam param, Long sysUserId ) {
  70. if(param.getRepairId() == null){
  71. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  72. }
  73. Repair repair = repairService.getById(param.getRepairId());
  74. if(repair == null){
  75. throw new BusinessException(ResultCode.REPAIR_NOT_EXITS);
  76. }
  77. if(repair.getStatus() !=0 ){
  78. throw new BusinessException(ResultCode.REPAIR_STATUS_NOT_EXITS);
  79. }
  80. param.setSysUserId(sysUserId);
  81. orderReceivingService.save(param);
  82. repairLogService.saveBySysUser(sysUserId,param.getRepairId(),1,"接单");
  83. }
  84. public void recording(RecordingParam param, Long userId,Integer receiverType) {
  85. if(StringUtils.isBlank(param.getCameraSnCode())){
  86. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  87. }
  88. Camera camera = cameraService.getBySnCode(param.getCameraSnCode());
  89. if(camera == null){
  90. throw new BusinessException(ResultCode.CAMERA_SN_NOT_EXITS);
  91. }
  92. List<Repair> repairList = repairService.getBySnCode(camera.getSnCode());
  93. if(repairList.size() >0){
  94. for (Repair repair : repairList) {
  95. if(!StatusUtil.overStatusList.contains(repair.getStatus())){
  96. throw new BusinessException(ResultCode.REPAIR_SN_EXITS);
  97. }
  98. }
  99. }
  100. Integer cameraType = cameraService.getCameraTypeByCameraId(camera.getId());
  101. Repair repair = new Repair();
  102. BeanUtils.copyProperties(param,repair);
  103. repair.setRepairId(DateUtil.getDate(DateUtil.repairIdFmt));
  104. repair.setCameraType(cameraType);
  105. repair.setSysUserId(userId);
  106. Customer customer = new Customer();
  107. BeanUtils.copyProperties(param,customer);
  108. customer.setRepairId(repair.getRepairId());
  109. customerService.save(customer);
  110. CustomerAddress customerAddress = new CustomerAddress();
  111. BeanUtils.copyProperties(param,customerAddress);
  112. customerAddress.setCustomerId(customer.getCustomerId());
  113. customerAddress.setRepairId(repair.getRepairId());
  114. customerAddressService.save(customerAddress);
  115. repairService.save(repair);
  116. repairLogService.saveBySysUser(userId,repair.getRepairId(),0,"录单");
  117. //自动接单
  118. if(receiverType == 0){
  119. OrderReceiving orderReceiving = new OrderReceiving();
  120. BeanUtils.copyProperties(param,orderReceiving);
  121. orderReceiving.setOrderFaultImg(param.getFaultImg());
  122. orderReceiving.setOrderFaultMsg(param.getFaultMsg());
  123. orderReceiving.setSysUserId(userId);
  124. orderReceiving.setRepairId(repair.getRepairId());
  125. orderReceivingService.save(orderReceiving);
  126. repairLogService.saveBySysUser(userId,repair.getRepairId(),1,"接单");
  127. }
  128. }
  129. public void addOrUpdatePriceList(PriceListParam param, Long userId) {
  130. if(StringUtils.isBlank(param.getRepairId()) ||
  131. param.getPriceLists() == null || param.getPriceLists().size() <=0){
  132. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  133. }
  134. Repair repair = repairService.getById(param.getRepairId());
  135. if(repair == null){
  136. throw new BusinessException(ResultCode.REPAIR_NOT_EXITS);
  137. }
  138. if(repair.getStatus() !=2 && repair.getStatus() !=3){
  139. throw new BusinessException(ResultCode.REPAIR_STATUS_NOT_EXITS);
  140. }
  141. HashMap<Integer,Part> partMap = partService.getHashMap();
  142. HashMap<Integer,LaborCost> laborMap = laborCostService.getHashMap();
  143. priceListService.delNoCm(param.getRepairId());
  144. for (PriceList priceList : param.getPriceLists()) {
  145. if(priceList.getType() == null){
  146. throw new BusinessException(ResultCode.PRICE_TYPE_NOT);
  147. }
  148. if(priceList.getType() == 0){
  149. if(priceList.getPartId() == null || partMap.get(priceList.getPartId()) == null){
  150. throw new BusinessException(ResultCode.PART_ID_EMPTY);
  151. }
  152. Part part = partMap.get(priceList.getPartId());
  153. priceList.setPrice(part.getPartPrice());
  154. priceList.setName(part.getPartName());
  155. }
  156. if(priceList.getType() == 1){
  157. if(priceList.getLaborId() == null || laborMap.get(priceList.getLaborId()) == null){
  158. throw new BusinessException(ResultCode.LABOR_ID_EMPTY);
  159. }
  160. LaborCost laborCost = laborMap.get(priceList.getLaborId());
  161. priceList.setPrice(laborCost.getPrice());
  162. priceList.setName(laborCost.getName());
  163. }
  164. priceList.setRepairId(param.getRepairId());
  165. }
  166. priceListService.saveOrUpdateBatch(param.getPriceLists());
  167. repairLogService.saveBySysUser(userId,param.getRepairId(),3,"维修报价");
  168. }
  169. public PriceListVo getPriceList(String repairId) {
  170. if(StringUtils.isBlank(repairId)){
  171. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  172. }
  173. List<PriceList> priceLists = priceListService.getByRepairId(repairId);
  174. List<RepairLog> repairLogs = repairLogService.getByRepairIdAndStatus(repairId, 3);
  175. PriceListVo priceListVo = new PriceListVo();
  176. priceListVo.setPriceLists(priceLists);
  177. priceListVo.setCount(repairLogs.size() +1);
  178. return priceListVo;
  179. }
  180. public void payRegister(PayRegisterParam param,Long userId) {
  181. if(StringUtils.isBlank(param.getRepairId())
  182. || param.getPayType() == null || param.getPayImg() == null){
  183. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  184. }
  185. Repair repair = repairService.getById(param.getRepairId());
  186. if(repair == null){
  187. throw new BusinessException(ResultCode.REPAIR_NOT_EXITS);
  188. }
  189. if(repair.getStatus() !=9){
  190. throw new BusinessException(ResultCode.REPAIR_STATUS_NOT_EXITS);
  191. }
  192. BigDecimal payAmount = priceListService.getAmountByRepairId(repair.getRepairId());
  193. RepairPay repairPay = new RepairPay();
  194. repairPay.setRepairId(repair.getRepairId());
  195. repairPay.setPayType(param.getPayType());
  196. repairPay.setPayImg(param.getPayImg());
  197. repairPay.setPayStatus(1);
  198. repairPay.setSysUserId(userId);
  199. repairPay.setPayAmount(payAmount);
  200. repairPay.setPayTime(DateUtil.getDate());
  201. repairPayService.save(repairPay);
  202. repairLogService.saveBySysUser(userId,param.getRepairId(),10,"付款登记");
  203. }
  204. public void sendRegister(PayRegisterParam param,Long userId) {
  205. if(StringUtils.isBlank(param.getRepairId()) || StringUtils.isBlank(param.getTrackingNum())){
  206. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  207. }
  208. Repair repair = repairService.getById(param.getRepairId());
  209. if(repair == null){
  210. throw new BusinessException(ResultCode.REPAIR_NOT_EXITS);
  211. }
  212. if(repair.getStatus() !=10){
  213. throw new BusinessException(ResultCode.REPAIR_STATUS_NOT_EXITS);
  214. }
  215. customerAddressService.setTrackingNumByRepairId(repair.getRepairId(),param.getTrackingNum());
  216. repairLogService.saveBySysUser(userId,param.getRepairId(),11,"发货登记");
  217. }
  218. }