RepairCustomerService.java 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. package com.fdkankan.sale.service.impl;
  2. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  3. import com.fdkankan.sale.common.RepairStatusEnum;
  4. import com.fdkankan.sale.common.ResultCode;
  5. import com.fdkankan.sale.entity.*;
  6. import com.fdkankan.sale.exception.BusinessException;
  7. import com.fdkankan.sale.service.*;
  8. import com.fdkankan.sale.util.StatusUtil;
  9. import com.fdkankan.sale.vo.request.RepairParam;
  10. import com.fdkankan.sale.vo.response.RepairRegisterPartVo;
  11. import org.apache.commons.lang3.StringUtils;
  12. import org.springframework.beans.BeanUtils;
  13. import org.springframework.beans.factory.annotation.Autowired;
  14. import org.springframework.stereotype.Service;
  15. import java.math.BigDecimal;
  16. import java.util.ArrayList;
  17. import java.util.HashMap;
  18. import java.util.List;
  19. import java.util.stream.Collectors;
  20. @Service
  21. public class RepairCustomerService {
  22. @Autowired
  23. ICustomerService customerService;
  24. @Autowired
  25. ICustomerAddressService customerAddressService;
  26. @Autowired
  27. IRepairService repairService;
  28. @Autowired
  29. IRepairLogService repairLogService;
  30. @Autowired
  31. IRepairCommentService repairCommentService;
  32. @Autowired
  33. IRepairInvoiceService repairInvoiceService;
  34. @Autowired
  35. IRepairPayService repairPayService;
  36. @Autowired
  37. IPriceListService priceListService;
  38. @Autowired
  39. IPriceListLogService priceListLogService;
  40. @Autowired
  41. RepairSupplyService repairSupplyService;
  42. @Autowired
  43. IPartLogService partLogService;
  44. public Object getRepairByOpenId(String openId) {
  45. List<Customer> list = customerService.getByOpenId(openId);
  46. if(list!= null && list.size() >0){
  47. List<String> repairIds = list.stream().map(Customer::getRepairId).collect(Collectors.toList());
  48. if(repairIds.size() >0){
  49. LambdaQueryWrapper<Repair> wrapper = new LambdaQueryWrapper<>();
  50. wrapper.in(Repair::getRepairId,repairIds);
  51. wrapper.orderByDesc(Repair::getCreateTime);
  52. List<Repair> repairList = repairService.list(wrapper);
  53. for (Repair repair : repairList) {
  54. List<PriceList> priceLists = new ArrayList<>();
  55. if(repair.getCancelStatus() == 1){
  56. priceLists = priceListService.getCheckAmountByRepairId(repair.getRepairId());
  57. }
  58. if(repair.getCancelStatus() == 0){
  59. priceLists = priceListService.getByRepairId(repair.getRepairId());
  60. }
  61. BigDecimal payAmount = BigDecimal.ZERO;
  62. for (PriceList priceList : priceLists) {
  63. BigDecimal price = priceList.getDiscount() == 1 ? priceList.getPriceDiscount() : priceList.getPrice();
  64. payAmount = payAmount.add(price);
  65. }
  66. repair.setPayAmount(payAmount);
  67. }
  68. return repairList;
  69. }
  70. }
  71. return null;
  72. }
  73. /**
  74. * * status 0待接单,10待检测,20待报价,30待确认,40已取消,50待备料,60维修中,70待测试,
  75. * * 80待支付(已完结),90待回收,100待发货,110已发货
  76. */
  77. public void confirmRepair(RepairParam param) {
  78. if(StringUtils.isBlank(param.getRepairId()) ){
  79. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  80. }
  81. Repair repair = repairService.getById(param.getRepairId());
  82. if(repair == null){
  83. throw new BusinessException(ResultCode.ORDER_PAY_NOT_EXITS);
  84. }
  85. if(!repair.getStatus().equals(RepairStatusEnum.TO_BE_CONFIRMED.status())){
  86. throw new BusinessException(ResultCode.REPAIR_STATUS_NOT_EXITS);
  87. }
  88. if(param.getConfirm() == 0){
  89. priceListService.updateStatusByRepairId(repair.getRepairId());
  90. priceListLogService.updateByRepairId(repair.getRepairId());
  91. //无备件更换,不需要备料,应直接进入维修中
  92. List<PriceList> partList = priceListService.getByRepairId(repair.getRepairId());
  93. List<PriceList> collect = partList.stream().filter(entity -> entity.getType() == 0).collect(Collectors.toList());
  94. if(collect.size() <=0){
  95. repairLogService.saveBySysUser(param.getUserId(),repair.getRepairId(),RepairStatusEnum.TO_BE_REPAIRED.status(),repair.getStatus(),"维修确认");
  96. return;
  97. }
  98. List<RepairRegisterPartVo> partVoList = repairSupplyService.partInfo(repair.getRepairId(), 0);
  99. if(partVoList.size() <=0){
  100. repairLogService.saveBySysUser(param.getUserId(),repair.getRepairId(),RepairStatusEnum.TO_BE_REPAIRED.status(),repair.getStatus(),"维修确认");
  101. return;
  102. }
  103. repairLogService.saveBySysUser(param.getUserId(),repair.getRepairId(),RepairStatusEnum.TO_BE_U8SEND.status(),repair.getStatus(),"维修确认");
  104. }
  105. if(param.getConfirm() == 1) {
  106. //有检测费用,已取消,无检测费用,直接到代发货
  107. BigDecimal robAmount = priceListService.getRobAmountByRepairId(repair.getRepairId());
  108. repairService.updateCancelStatus(repair.getRepairId(),1,param.getRemark());
  109. Integer status = null;
  110. if(robAmount.compareTo(BigDecimal.ZERO) <=0 || StatusUtil.getWarranty(repair.getWarrantyType())){
  111. status = RepairStatusEnum.TO_BE_SHIPPED.status();
  112. } else {
  113. status = RepairStatusEnum.TO_BE_CANCELED.status();
  114. }
  115. String remark = null;
  116. if(StringUtils.isNotBlank(param.getRemark())){
  117. remark = "取消维修备注:"+param.getRemark();
  118. }
  119. repairLogService.saveBySysUser(param.getUserId(),repair.getRepairId(),status,repair.getStatus(),"取消维修",remark);
  120. }
  121. }
  122. public void comment(RepairParam param) {
  123. if(StringUtils.isBlank(param.getRepairId()) ){
  124. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  125. }
  126. RepairComment repairComment = repairCommentService.getByRepairId(param.getRepairId());
  127. if(repairComment !=null){
  128. throw new BusinessException(ResultCode.ORDER_COMMENT_EXITS);
  129. }
  130. repairComment = new RepairComment();
  131. BeanUtils.copyProperties(param,repairComment);
  132. repairCommentService.save(repairComment);
  133. repairService.updateCommentStatus(param.getRepairId());
  134. }
  135. public void invoiceApply(RepairInvoice param) {
  136. if(StringUtils.isBlank(param.getRepairId()) ){
  137. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  138. }
  139. Repair repair = repairService.getById(param.getRepairId());
  140. if(repair == null){
  141. throw new BusinessException(ResultCode.ORDER_PAY_NOT_EXITS);
  142. }
  143. RepairInvoice repairInvoice = repairInvoiceService.getByRepairId(param.getRepairId());
  144. if(repairInvoice !=null){
  145. throw new BusinessException(ResultCode.ORDER_INVOICE_EXITS);
  146. }
  147. RepairPay repairPay = repairPayService.getByRepairId(param.getRepairId(), 1);
  148. if(repairPay == null){
  149. throw new BusinessException(ResultCode.ORDER_NOt_PAY);
  150. }
  151. repairInvoice = new RepairInvoice();
  152. BeanUtils.copyProperties(param,repairInvoice);
  153. repairInvoiceService.save(repairInvoice);
  154. repairService.updateRepairInvoiceStatus(repair.getRepairId(),1);
  155. }
  156. public Object getInvoiceAddress(String repairId) {
  157. CustomerAddress customerAddress = customerAddressService.getByRepairId(repairId);
  158. RepairPay repairPay = repairPayService.getByRepairId(repairId, 1);
  159. if(repairPay == null){
  160. throw new BusinessException(ResultCode.ORDER_NOt_PAY);
  161. }
  162. customerAddress.setPayAmount(repairPay.getPayAmount());
  163. return customerAddress;
  164. }
  165. }