RepairCustomerService.java 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. RepairSupplyService repairSupplyService;
  40. @Autowired
  41. IPartLogService partLogService;
  42. public Object getRepairByOpenId(String openId) {
  43. List<Customer> list = customerService.getByOpenId(openId);
  44. if(list!= null && list.size() >0){
  45. List<String> repairIds = list.stream().map(Customer::getRepairId).collect(Collectors.toList());
  46. if(repairIds.size() >0){
  47. LambdaQueryWrapper<Repair> wrapper = new LambdaQueryWrapper<>();
  48. wrapper.in(Repair::getRepairId,repairIds);
  49. wrapper.orderByDesc(Repair::getCreateTime);
  50. List<Repair> repairList = repairService.list(wrapper);
  51. for (Repair repair : repairList) {
  52. List<PriceList> priceLists = new ArrayList<>();
  53. if(repair.getCancelStatus() == 1){
  54. priceLists = priceListService.getCheckAmountByRepairId(repair.getRepairId());
  55. }
  56. if(repair.getCancelStatus() == 0){
  57. priceLists = priceListService.getByRepairId(repair.getRepairId());
  58. }
  59. BigDecimal payAmount = BigDecimal.ZERO;
  60. for (PriceList priceList : priceLists) {
  61. BigDecimal price = priceList.getDiscount() == 1 ? priceList.getPriceDiscount() : priceList.getPrice();
  62. payAmount = payAmount.add(price);
  63. }
  64. repair.setPayAmount(payAmount);
  65. }
  66. return repairList;
  67. }
  68. }
  69. return null;
  70. }
  71. /**
  72. * * status 0待接单,10待检测,20待报价,30待确认,40已取消,50待备料,60维修中,70待测试,
  73. * * 80待支付(已完结),90待回收,100待发货,110已发货
  74. */
  75. public void confirmRepair(RepairParam param) {
  76. if(StringUtils.isBlank(param.getRepairId()) ){
  77. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  78. }
  79. Repair repair = repairService.getById(param.getRepairId());
  80. if(repair == null){
  81. throw new BusinessException(ResultCode.ORDER_PAY_NOT_EXITS);
  82. }
  83. if(!repair.getStatus().equals(RepairStatusEnum.TO_BE_CONFIRMED.status())){
  84. throw new BusinessException(ResultCode.REPAIR_STATUS_NOT_EXITS);
  85. }
  86. if(param.getConfirm() == 0){
  87. priceListService.updateStatusByRepairId(repair.getRepairId());
  88. //无备件更换,不需要备料,应直接进入维修中
  89. List<PriceList> partList = priceListService.getByRepairId(repair.getRepairId());
  90. List<PriceList> collect = partList.stream().filter(entity -> entity.getType() == 0).collect(Collectors.toList());
  91. if(collect.size() <=0){
  92. repairLogService.saveBySysUser(param.getUserId(),repair.getRepairId(),RepairStatusEnum.TO_BE_REPAIRED.status(),repair.getStatus(),"维修确认");
  93. }else {
  94. List<RepairRegisterPartVo> partVoList = repairSupplyService.partInfo(repair.getRepairId(), 0);
  95. if(partVoList.size() <=0){
  96. repairLogService.saveBySysUser(param.getUserId(),repair.getRepairId(),RepairStatusEnum.TO_BE_REPAIRED.status(),repair.getStatus(),"维修确认");
  97. }
  98. repairLogService.saveBySysUser(param.getUserId(),repair.getRepairId(),RepairStatusEnum.TO_BE_U8SEND.status(),repair.getStatus(),"维修确认");
  99. }
  100. }
  101. if(param.getConfirm() == 1) {
  102. //有检测费用,已取消,无检测费用,直接到代发货
  103. List<RepairRegisterPartVo> partVoList = repairSupplyService.partInfo(repair.getRepairId(), 1);
  104. BigDecimal robAmount = priceListService.getRobAmountByRepairId(repair.getRepairId());
  105. repairService.updateCancelStatus(repair.getRepairId(),1,param.getRemark());
  106. Integer status = null;
  107. if(robAmount.compareTo(BigDecimal.ZERO) <=0 || StatusUtil.getWarranty(repair.getWarrantyType())){
  108. if(partVoList.size() >0){
  109. status = RepairStatusEnum.TO_BE_CANCELED_RECOVERED.status();
  110. }else {
  111. status = RepairStatusEnum.TO_BE_SHIPPED.status();
  112. }
  113. } else {
  114. status = RepairStatusEnum.TO_BE_CANCELED.status();
  115. }
  116. String remark = null;
  117. if(StringUtils.isNotBlank(param.getRemark())){
  118. remark = "取消维修备注:"+param.getRemark();
  119. }
  120. repairLogService.saveBySysUser(param.getUserId(),repair.getRepairId(),status,repair.getStatus(),"取消维修",remark);
  121. }
  122. }
  123. public void comment(RepairParam param) {
  124. if(StringUtils.isBlank(param.getRepairId()) ){
  125. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  126. }
  127. RepairComment repairComment = repairCommentService.getByRepairId(param.getRepairId());
  128. if(repairComment !=null){
  129. throw new BusinessException(ResultCode.ORDER_COMMENT_EXITS);
  130. }
  131. repairComment = new RepairComment();
  132. BeanUtils.copyProperties(param,repairComment);
  133. repairCommentService.save(repairComment);
  134. repairService.updateCommentStatus(param.getRepairId());
  135. }
  136. public void invoiceApply(RepairInvoice param) {
  137. if(StringUtils.isBlank(param.getRepairId()) ){
  138. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  139. }
  140. Repair repair = repairService.getById(param.getRepairId());
  141. if(repair == null){
  142. throw new BusinessException(ResultCode.ORDER_PAY_NOT_EXITS);
  143. }
  144. RepairInvoice repairInvoice = repairInvoiceService.getByRepairId(param.getRepairId());
  145. if(repairInvoice !=null){
  146. throw new BusinessException(ResultCode.ORDER_INVOICE_EXITS);
  147. }
  148. RepairPay repairPay = repairPayService.getByRepairId(param.getRepairId(), 1);
  149. if(repairPay == null){
  150. throw new BusinessException(ResultCode.ORDER_NOt_PAY);
  151. }
  152. repairInvoice = new RepairInvoice();
  153. BeanUtils.copyProperties(param,repairInvoice);
  154. repairInvoiceService.save(repairInvoice);
  155. repairService.updateRepairInvoiceStatus(repair.getRepairId(),1);
  156. }
  157. public Object getInvoiceAddress(String repairId) {
  158. CustomerAddress customerAddress = customerAddressService.getByRepairId(repairId);
  159. RepairPay repairPay = repairPayService.getByRepairId(repairId, 1);
  160. if(repairPay == null){
  161. throw new BusinessException(ResultCode.ORDER_NOt_PAY);
  162. }
  163. customerAddress.setPayAmount(repairPay.getPayAmount());
  164. return customerAddress;
  165. }
  166. }