RepairSaleService.java 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  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.common.util.SecurityUtil;
  9. import com.fdkankan.sale.common.PageInfo;
  10. import com.fdkankan.sale.common.RepairStatusEnum;
  11. import com.fdkankan.sale.common.ResultCode;
  12. import com.fdkankan.sale.common.ResultData;
  13. import com.fdkankan.sale.entity.*;
  14. import com.fdkankan.sale.exception.BusinessException;
  15. import com.fdkankan.sale.service.*;
  16. import com.fdkankan.sale.util.DateUtil;
  17. import com.fdkankan.sale.util.StatusUtil;
  18. import com.fdkankan.sale.vo.request.*;
  19. import com.fdkankan.sale.vo.response.PriceListVo;
  20. import com.fdkankan.sale.vo.response.RepairRegisterPartVo;
  21. import com.fdkankan.sale.vo.response.RepairerVo;
  22. import org.apache.commons.lang3.StringUtils;
  23. import org.springframework.beans.BeanUtils;
  24. import org.springframework.beans.factory.annotation.Autowired;
  25. import org.springframework.stereotype.Service;
  26. import java.util.stream.Collectors;
  27. @Service
  28. public class RepairSaleService {
  29. @Autowired
  30. IRepairService repairService;
  31. @Autowired
  32. IRepairLogService repairLogService;
  33. @Autowired
  34. IOrderReceivingService orderReceivingService;
  35. @Autowired
  36. ICustomerService customerService;
  37. @Autowired
  38. ICustomerAddressService customerAddressService;
  39. @Autowired
  40. ICameraService cameraService;
  41. @Autowired
  42. ISysUserService sysUserService;
  43. @Autowired
  44. IRepairRegisterService repairRegisterService;
  45. @Autowired
  46. IRepairRegisterPartService repairRegisterPartService;
  47. @Autowired
  48. IPriceListService priceListService;
  49. @Autowired
  50. IRepairPayService repairPayService;
  51. @Autowired
  52. IPartService partService;
  53. @Autowired
  54. ILaborCostService laborCostService;
  55. @Autowired
  56. RepairSupplyService repairSupplyService;
  57. /**
  58. * 售后工程师
  59. * statusParam 0 待接单,1待跟进,2已完结
  60. * * status 0待接单,10待检测,20待报价,30待确认,40已取消,50待备料,60维修中,70待测试,
  61. * * 80待支付(已完结),90待回收,100待发货,110已发货
  62. */
  63. public PageInfo saleOrderList(RepairParam param) {
  64. List<Integer> repairStatus = StatusUtil.getSaleStatus(param.getStatusParam());
  65. param.setStatusList(repairStatus);
  66. Page<RepairerVo> voPage = repairService.saleOrderList(param);
  67. sysUserService.setSaleNameAndRepairManName(voPage.getRecords());
  68. BigDecimal payAmount;
  69. for (RepairerVo record : voPage.getRecords()) {
  70. if(record.getStatus().equals(RepairStatusEnum.TO_BE_CANCELED.status())){
  71. payAmount = priceListService.getRobAmountByRepairId(record.getRepairId());
  72. }else {
  73. payAmount = priceListService.getAmountByRepairId(record.getRepairId());
  74. }
  75. record.setPayAmount(payAmount);
  76. }
  77. return PageInfo.PageInfo(voPage);
  78. }
  79. public void orderReceiving(OrderReceivingParam param, Long sysUserId ) {
  80. if(param.getRepairId() == null){
  81. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  82. }
  83. Repair repair = repairService.getById(param.getRepairId());
  84. if(repair == null){
  85. throw new BusinessException(ResultCode.REPAIR_NOT_EXITS);
  86. }
  87. if(!repair.getStatus().equals(RepairStatusEnum.TO_BE_RECEIVED.status())){
  88. throw new BusinessException(ResultCode.REPAIR_STATUS_NOT_EXITS);
  89. }
  90. param.setSysUserId(sysUserId);
  91. param.setOrderFaultMsg(param.getCameraFaultInfo());
  92. param.setOrderFaultImg(param.getImageUrl());
  93. orderReceivingService.save(param);
  94. //保外转保内
  95. if(repair.getWarrantyType() !=0 && param.getConvertWarranty() == 1){
  96. repairService.updateWarrantyType(repair.getRepairId(),3);
  97. }
  98. repairLogService.saveBySysUser(sysUserId,param.getRepairId(), RepairStatusEnum.TO_BE_CHECK.status(),repair.getStatus(),"售后接单");
  99. }
  100. public void recording(RecordingParam param, Long userId,Integer receiverType) {
  101. if(StringUtils.isBlank(param.getCameraSnCode())){
  102. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  103. }
  104. Camera camera = cameraService.getBySnCode(param.getCameraSnCode());
  105. if(camera == null){
  106. throw new BusinessException(ResultCode.CAMERA_SN_NOT_EXITS);
  107. }
  108. // List<Repair> repairList = repairService.getBySnCode(camera.getSnCode());
  109. // if(repairList.size() >0){
  110. // for (Repair repair : repairList) {
  111. // if(!StatusUtil.overStatusList.contains(repair.getStatus())){
  112. // throw new BusinessException(ResultCode.REPAIR_SN_EXITS);
  113. // }
  114. // }
  115. // }
  116. CameraDetail cameraDetail = cameraService.getCameraTypeByCameraId(camera.getId());
  117. Integer cameraType = null;
  118. switch (cameraDetail.getType()){
  119. case 9: cameraType = 1;break;
  120. case 10: cameraType = 2;break;
  121. case 11: cameraType = 3;break;
  122. default: cameraType = 0; break;
  123. }
  124. Date outTime = cameraDetail.getBuyDate() == null ? cameraDetail.getCreateTime() : DateUtil.getDateByStr2(cameraDetail.getBuyDate());
  125. Date date = DateUtil.dateAddOneYear(outTime, 1);
  126. date = DateUtil.dateAddOne(date, 7);
  127. String date1 = DateUtil.getDate(DateUtil.dayFmt, date) +" 23:59:59";
  128. Repair repair = new Repair();
  129. BeanUtils.copyProperties(param,repair);
  130. repair.setRepairId(DateUtil.getDate(DateUtil.repairIdFmt));
  131. repair.setReceiverType(receiverType);
  132. repair.setCameraType(cameraType);
  133. repair.setSysUserId(userId);
  134. repair.setWarrantyDate(date1);
  135. repair.setWarrantyType(2);
  136. if(DateUtil.getDateByStr(date1).getTime() >= new Date().getTime()){
  137. repair.setWarrantyType(0);
  138. }
  139. Customer customer = new Customer();
  140. BeanUtils.copyProperties(param,customer);
  141. customer.setRepairId(repair.getRepairId());
  142. customerService.save(customer);
  143. CustomerAddress customerAddress = new CustomerAddress();
  144. BeanUtils.copyProperties(param,customerAddress);
  145. customerAddress.setCustomerId(customer.getCustomerId());
  146. customerAddress.setRepairId(repair.getRepairId());
  147. customerAddressService.save(customerAddress);
  148. repairService.save(repair);
  149. repairLogService.saveBySysUser(userId,repair.getRepairId(),RepairStatusEnum.TO_BE_RECEIVED.status(),repair.getStatus(),"报修");
  150. }
  151. public void addOrUpdatePriceList(PriceListParam param, Long userId) {
  152. if(StringUtils.isBlank(param.getRepairId()) ||
  153. param.getPriceLists() == null || param.getPriceLists().size() <=0){
  154. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  155. }
  156. Repair repair = repairService.getById(param.getRepairId());
  157. if(repair == null){
  158. throw new BusinessException(ResultCode.REPAIR_NOT_EXITS);
  159. }
  160. if(!repair.getStatus().equals(RepairStatusEnum.TO_BE_QUOTED.status())
  161. && !repair.getStatus().equals(RepairStatusEnum.TO_BE_CONFIRMED.status())){
  162. throw new BusinessException(ResultCode.REPAIR_STATUS_NOT_EXITS);
  163. }
  164. if(param.getConvertWarranty() == 1){ //保外转保内
  165. repairService.updateWarrantyType(repair.getRepairId(),3);
  166. }
  167. HashMap<Integer,Part> partMap = partService.getHashMap();
  168. HashMap<Integer,LaborCost> laborMap = laborCostService.getHashMap();
  169. List<PriceList> priceListList = priceListService.getByRepairId(repair.getRepairId());
  170. HashMap<Integer,PriceList> priceListHashMap = new HashMap<>();
  171. priceListList.forEach(entity -> priceListHashMap.put(entity.getPriceListId(),entity));
  172. priceListService.delNoCm(repair.getRepairId());
  173. Integer status = RepairStatusEnum.TO_BE_CONFIRMED.status();
  174. for (PriceList priceList : param.getPriceLists()) {
  175. if(priceList.getType() == null){
  176. throw new BusinessException(ResultCode.PRICE_TYPE_NOT);
  177. }
  178. if(priceList.getCount() == null){
  179. throw new BusinessException(ResultCode.PRICE_COUNT_NOT);
  180. }
  181. if(priceList.getCount() <= 0){
  182. throw new BusinessException(ResultCode.PRICE_COUNT_NOT);
  183. }
  184. if(priceList.getType() == 0){ //设备备件
  185. if(priceList.getPartId() == null || partMap.get(priceList.getPartId()) == null || priceList.getDiscount() == null){
  186. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  187. }
  188. Part part = partMap.get(priceList.getPartId());
  189. priceList.setPrice(part.getPartPrice());
  190. priceList.setPriceDiscount(part.getPartPriceDiscount());
  191. priceList.setName(part.getPartName());
  192. if(param.getConvertWarranty() == 1){
  193. status = RepairStatusEnum.TO_BE_PREPARED.status();
  194. }
  195. }
  196. if(priceList.getType() == 1){ //人工费用
  197. if(priceList.getLaborId() == null || laborMap.get(priceList.getLaborId()) == null){
  198. throw new BusinessException(ResultCode.LABOR_ID_EMPTY);
  199. }
  200. LaborCost laborCost = laborMap.get(priceList.getLaborId());
  201. priceList.setPrice(laborCost.getPrice());
  202. priceList.setName(laborCost.getName());
  203. }
  204. if(priceList.getType() == 2){ //自定义费用
  205. if(StringUtils.isBlank(priceList.getName()) || priceList.getPrice() == null){
  206. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  207. }
  208. }
  209. priceList.setRepairId(param.getRepairId());
  210. if(priceList.getPriceListId() != null){
  211. PriceList priceList1 = priceListHashMap.get(priceList.getPriceListId());
  212. if(priceList1 != null){
  213. priceList.setStatus(priceList1.getStatus());
  214. priceList.setRemark(priceList1.getRemark());
  215. }
  216. priceList.setPriceListId(null);
  217. }
  218. if(param.getConvertWarranty() == 1){
  219. priceList.setStatus(1);
  220. }
  221. priceListService.save(priceList);
  222. }
  223. if(param.getConvertWarranty() == 1 && !status.equals(RepairStatusEnum.TO_BE_PREPARED.status())){
  224. status = RepairStatusEnum.TO_BE_REPAIRED.status();
  225. }
  226. repairLogService.saveBySysUser(userId,param.getRepairId(),status,repair.getStatus(),"维修报价");
  227. }
  228. public PriceListVo getPriceList(String repairId,Integer isRest) {
  229. if(StringUtils.isBlank(repairId)){
  230. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  231. }
  232. if(isRest == 1){
  233. return repairRegisterService.getPriceList(repairId);
  234. }
  235. List<PriceList> priceLists = priceListService.getByRepairId(repairId);
  236. Set<Integer> collect = priceLists.stream().map(PriceList::getPartId).collect(Collectors.toSet());
  237. HashMap<Integer,Part> partHashMap = new HashMap<>();
  238. if(collect.size() >0){
  239. List<Part> parts = partService.listByIds(collect);
  240. parts.forEach(entity -> partHashMap.put(entity.getPartId(),entity));
  241. }
  242. for (PriceList priceList : priceLists) {
  243. if(priceList.getType() == 0 && priceList.getPartId() != null && partHashMap.get(priceList.getPartId()) !=null) {
  244. priceList.setPartUnit(partHashMap.get(priceList.getPartId()).getPartUnit());
  245. }
  246. }
  247. List<RepairLog> repairLogs = repairLogService.getByRepairIdAndStatus(repairId, RepairStatusEnum.TO_BE_CONFIRMED.status());
  248. PriceListVo priceListVo = new PriceListVo();
  249. priceListVo.setPriceLists(priceLists);
  250. priceListVo.setCount(repairLogs.size() +1);
  251. return priceListVo;
  252. }
  253. public void payRegister(PayRegisterParam param,Long userId) {
  254. if(StringUtils.isBlank(param.getRepairId())
  255. || param.getPayType() == null || param.getPayImg() == null){
  256. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  257. }
  258. Repair repair = repairService.getById(param.getRepairId());
  259. if(repair == null){
  260. throw new BusinessException(ResultCode.REPAIR_NOT_EXITS);
  261. }
  262. if(!repair.getStatus().equals(RepairStatusEnum.TO_BE_CANCELED.status()) && !repair.getStatus().equals(RepairStatusEnum.TO_BE_PAID.status())){
  263. throw new BusinessException(ResultCode.REPAIR_STATUS_NOT_EXITS);
  264. }
  265. RepairPay byRepairId = repairPayService.getByRepairId(repair.getRepairId(), 1);
  266. if(byRepairId != null){
  267. throw new BusinessException(ResultCode.ORDER_PAY_ERROR);
  268. }
  269. BigDecimal payAmount;
  270. String orderSn = null;
  271. Integer status = null;
  272. Integer orderType = null;
  273. if(repair.getStatus().equals(RepairStatusEnum.TO_BE_CANCELED.status())){
  274. payAmount = priceListService.getRobAmountByRepairId(repair.getRepairId());
  275. orderSn = "c"+DateUtil.getDate(DateUtil.repairIdFmt);
  276. //status = RepairStatusEnum.TO_BE_CANCELED_RECOVERED.status();
  277. orderType = 1;
  278. }else {
  279. payAmount = priceListService.getAmountByRepairId(repair.getRepairId());
  280. orderSn = "s"+DateUtil.getDate(DateUtil.repairIdFmt);
  281. //status = RepairStatusEnum.TO_BE_RECOVERED.status();
  282. orderType = 0;
  283. }
  284. RepairPay repairPay = new RepairPay();
  285. repairPay.setRepairId(repair.getRepairId());
  286. repairPay.setPayType(param.getPayType());
  287. repairPay.setPayImg(param.getPayImg());
  288. repairPay.setPayStatus(1);
  289. repairPay.setSysUserId(userId);
  290. repairPay.setPayAmount(payAmount);
  291. repairPay.setPayTime(DateUtil.getDate());
  292. repairPay.setOrderType(orderType);
  293. repairPay.setOrderSn(orderSn);
  294. repairPay.setRemark(param.getRemark());
  295. repairPayService.save(repairPay);
  296. repairLogService.saveBySysUser(userId,param.getRepairId(),RepairStatusEnum.TO_BE_PAID_OVER.status(),repair.getStatus(), "付款登记");
  297. }
  298. public void sendRegister(PayRegisterParam param,Long userId) {
  299. if(StringUtils.isBlank(param.getRepairId()) || param.getGetType() == null){
  300. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  301. }
  302. Repair repair = repairService.getById(param.getRepairId());
  303. if(repair == null){
  304. throw new BusinessException(ResultCode.REPAIR_NOT_EXITS);
  305. }
  306. if(!repair.getStatus().equals(RepairStatusEnum.TO_BE_SHIPPED.status())){
  307. throw new BusinessException(ResultCode.REPAIR_STATUS_NOT_EXITS);
  308. }
  309. customerAddressService.setTrackingNumByRepairId(repair.getRepairId(),param.getGetType(),param.getTrackingNum());
  310. repairLogService.saveBySysUser(userId,param.getRepairId(),RepairStatusEnum.OVER_SHIPPED.status(),repair.getStatus(),"发货登记");
  311. }
  312. public void signFor(PayRegisterParam param, Long userId) {
  313. if(StringUtils.isBlank(param.getRepairId()) || param.getTrackingImg() == null || param.getTrackingImg().isEmpty()){
  314. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  315. }
  316. Repair repair = repairService.getById(param.getRepairId());
  317. if(repair == null){
  318. throw new BusinessException(ResultCode.REPAIR_NOT_EXITS);
  319. }
  320. customerAddressService.setTrackingImgByRepairId(repair.getRepairId(),param.getTrackingImg(),userId);
  321. }
  322. }