RepairSaleService.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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. BigDecimal payAmount;
  64. for (RepairerVo record : voPage.getRecords()) {
  65. if(record.getStatus() == 4){
  66. payAmount = priceListService.getRobAmountByRepairId(param.getRepairId());
  67. }else {
  68. payAmount = priceListService.getAmountByRepairId(record.getRepairId());
  69. }
  70. record.setPayAmount(payAmount);
  71. }
  72. return PageInfo.PageInfo(voPage);
  73. }
  74. public void orderReceiving(OrderReceivingParam param, Long sysUserId ) {
  75. if(param.getRepairId() == null){
  76. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  77. }
  78. Repair repair = repairService.getById(param.getRepairId());
  79. if(repair == null){
  80. throw new BusinessException(ResultCode.REPAIR_NOT_EXITS);
  81. }
  82. if(repair.getStatus() !=0 ){
  83. throw new BusinessException(ResultCode.REPAIR_STATUS_NOT_EXITS);
  84. }
  85. param.setSysUserId(sysUserId);
  86. param.setOrderFaultMsg(param.getCameraFaultInfo());
  87. param.setOrderFaultImg(param.getImageUrl());
  88. orderReceivingService.save(param);
  89. repairLogService.saveBySysUser(sysUserId,param.getRepairId(),1,"接单");
  90. }
  91. public void recording(RecordingParam param, Long userId,Integer receiverType) {
  92. if(StringUtils.isBlank(param.getCameraSnCode())){
  93. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  94. }
  95. Camera camera = cameraService.getBySnCode(param.getCameraSnCode());
  96. if(camera == null){
  97. throw new BusinessException(ResultCode.CAMERA_SN_NOT_EXITS);
  98. }
  99. List<Repair> repairList = repairService.getBySnCode(camera.getSnCode());
  100. if(repairList.size() >0){
  101. for (Repair repair : repairList) {
  102. if(!StatusUtil.overStatusList.contains(repair.getStatus())){
  103. throw new BusinessException(ResultCode.REPAIR_SN_EXITS);
  104. }
  105. }
  106. }
  107. Integer cameraType = cameraService.getCameraTypeByCameraId(camera.getId());
  108. Repair repair = new Repair();
  109. BeanUtils.copyProperties(param,repair);
  110. repair.setRepairId(DateUtil.getDate(DateUtil.repairIdFmt));
  111. repair.setReceiverType(receiverType);
  112. repair.setCameraType(cameraType);
  113. repair.setSysUserId(userId);
  114. Customer customer = new Customer();
  115. BeanUtils.copyProperties(param,customer);
  116. customer.setRepairId(repair.getRepairId());
  117. customerService.save(customer);
  118. CustomerAddress customerAddress = new CustomerAddress();
  119. BeanUtils.copyProperties(param,customerAddress);
  120. customerAddress.setCustomerId(customer.getCustomerId());
  121. customerAddress.setRepairId(repair.getRepairId());
  122. customerAddressService.save(customerAddress);
  123. repairService.save(repair);
  124. repairLogService.saveBySysUser(userId,repair.getRepairId(),0,"录单");
  125. //自动接单
  126. if(receiverType == 0){
  127. OrderReceiving orderReceiving = new OrderReceiving();
  128. BeanUtils.copyProperties(param,orderReceiving);
  129. orderReceiving.setOrderFaultImg(param.getFaultImg());
  130. orderReceiving.setOrderFaultMsg(param.getFaultMsg());
  131. orderReceiving.setSysUserId(userId);
  132. orderReceiving.setRepairId(repair.getRepairId());
  133. orderReceivingService.save(orderReceiving);
  134. repairLogService.saveBySysUser(userId,repair.getRepairId(),1,"接单");
  135. }
  136. }
  137. public void addOrUpdatePriceList(PriceListParam param, Long userId) {
  138. if(StringUtils.isBlank(param.getRepairId()) ||
  139. param.getPriceLists() == null || param.getPriceLists().size() <=0){
  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. if(repair.getStatus() !=2 && repair.getStatus() !=3){
  147. throw new BusinessException(ResultCode.REPAIR_STATUS_NOT_EXITS);
  148. }
  149. HashMap<Integer,Part> partMap = partService.getHashMap();
  150. HashMap<Integer,LaborCost> laborMap = laborCostService.getHashMap();
  151. for (PriceList priceList : param.getPriceLists()) {
  152. if(priceList.getType() == null){
  153. throw new BusinessException(ResultCode.PRICE_TYPE_NOT);
  154. }
  155. if(priceList.getType() == 0){
  156. if(priceList.getPartId() == null || partMap.get(priceList.getPartId()) == null
  157. || priceList.getPriceListId() == null){
  158. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  159. }
  160. Part part = partMap.get(priceList.getPartId());
  161. priceList.setPrice(part.getPartPrice());
  162. priceList.setName(part.getPartName());
  163. }
  164. if(priceList.getType() == 1){
  165. if(priceList.getLaborId() == null || laborMap.get(priceList.getLaborId()) == null){
  166. throw new BusinessException(ResultCode.LABOR_ID_EMPTY);
  167. }
  168. LaborCost laborCost = laborMap.get(priceList.getLaborId());
  169. priceList.setPrice(laborCost.getPrice());
  170. priceList.setName(laborCost.getName());
  171. }
  172. priceList.setRepairId(param.getRepairId());
  173. if(priceList.getPriceListId() != null){
  174. PriceList dbPriceList = priceListService.getById(priceList.getPriceListId());
  175. if(dbPriceList.getStatus() != 1){
  176. priceListService.updateById(priceList);
  177. }
  178. }else {
  179. priceListService.save(priceList);
  180. }
  181. }
  182. repairLogService.saveBySysUser(userId,param.getRepairId(),3,"维修报价");
  183. }
  184. public PriceListVo getPriceList(String repairId) {
  185. if(StringUtils.isBlank(repairId)){
  186. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  187. }
  188. List<PriceList> priceLists = priceListService.getByRepairId(repairId);
  189. List<RepairLog> repairLogs = repairLogService.getByRepairIdAndStatus(repairId, 3);
  190. PriceListVo priceListVo = new PriceListVo();
  191. priceListVo.setPriceLists(priceLists);
  192. priceListVo.setCount(repairLogs.size() +1);
  193. return priceListVo;
  194. }
  195. public void payRegister(PayRegisterParam param,Long userId) {
  196. if(StringUtils.isBlank(param.getRepairId())
  197. || param.getPayType() == null || param.getPayImg() == null){
  198. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  199. }
  200. Repair repair = repairService.getById(param.getRepairId());
  201. if(repair == null){
  202. throw new BusinessException(ResultCode.REPAIR_NOT_EXITS);
  203. }
  204. if(repair.getStatus() != 4 && repair.getStatus() !=9){
  205. throw new BusinessException(ResultCode.REPAIR_STATUS_NOT_EXITS);
  206. }
  207. BigDecimal payAmount;
  208. if(repair.getStatus() == 4){
  209. payAmount = priceListService.getRobAmountByRepairId(repair.getRepairId());
  210. }else {
  211. payAmount = priceListService.getAmountByRepairId(repair.getRepairId());
  212. }
  213. RepairPay repairPay = new RepairPay();
  214. repairPay.setRepairId(repair.getRepairId());
  215. repairPay.setPayType(param.getPayType());
  216. repairPay.setPayImg(param.getPayImg());
  217. repairPay.setPayStatus(1);
  218. repairPay.setSysUserId(userId);
  219. repairPay.setPayAmount(payAmount);
  220. repairPay.setPayTime(DateUtil.getDate());
  221. repairPay.setOrderType(0);
  222. repairPay.setOrderSn("se_s"+DateUtil.getDate(DateUtil.repairIdFmt));
  223. repairPayService.save(repairPay);
  224. repairLogService.saveBySysUser(userId,param.getRepairId(),10,"付款登记");
  225. }
  226. public void sendRegister(PayRegisterParam param,Long userId) {
  227. if(StringUtils.isBlank(param.getRepairId()) || param.getGetType() == null){
  228. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  229. }
  230. Repair repair = repairService.getById(param.getRepairId());
  231. if(repair == null){
  232. throw new BusinessException(ResultCode.REPAIR_NOT_EXITS);
  233. }
  234. if(repair.getStatus() !=10){
  235. throw new BusinessException(ResultCode.REPAIR_STATUS_NOT_EXITS);
  236. }
  237. customerAddressService.setTrackingNumByRepairId(repair.getRepairId(),param.getGetType(),param.getTrackingNum());
  238. repairLogService.saveBySysUser(userId,param.getRepairId(),11,"发货登记");
  239. }
  240. }