123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- package com.fdkankan.sale.service.impl;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.fdkankan.sale.common.RepairStatusEnum;
- import com.fdkankan.sale.common.ResultCode;
- import com.fdkankan.sale.entity.*;
- import com.fdkankan.sale.exception.BusinessException;
- import com.fdkankan.sale.service.*;
- import com.fdkankan.sale.util.StatusUtil;
- import com.fdkankan.sale.vo.request.RepairParam;
- import com.fdkankan.sale.vo.response.RepairRegisterPartVo;
- import org.apache.commons.lang3.StringUtils;
- import org.springframework.beans.BeanUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import java.math.BigDecimal;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.stream.Collectors;
- @Service
- public class RepairCustomerService {
- @Autowired
- ICustomerService customerService;
- @Autowired
- ICustomerAddressService customerAddressService;
- @Autowired
- IRepairService repairService;
- @Autowired
- IRepairLogService repairLogService;
- @Autowired
- IRepairCommentService repairCommentService;
- @Autowired
- IRepairInvoiceService repairInvoiceService;
- @Autowired
- IRepairPayService repairPayService;
- @Autowired
- IPriceListService priceListService;
- @Autowired
- IPriceListLogService priceListLogService;
- @Autowired
- RepairSupplyService repairSupplyService;
- @Autowired
- IPartLogService partLogService;
- public Object getRepairByOpenId(String openId) {
- List<Customer> list = customerService.getByOpenId(openId);
- if(list!= null && list.size() >0){
- List<String> repairIds = list.stream().map(Customer::getRepairId).collect(Collectors.toList());
- if(repairIds.size() >0){
- LambdaQueryWrapper<Repair> wrapper = new LambdaQueryWrapper<>();
- wrapper.in(Repair::getRepairId,repairIds);
- wrapper.orderByDesc(Repair::getCreateTime);
- List<Repair> repairList = repairService.list(wrapper);
- for (Repair repair : repairList) {
- List<PriceList> priceLists = new ArrayList<>();
- if(repair.getCancelStatus() == 1){
- priceLists = priceListService.getCheckAmountByRepairId(repair.getRepairId());
- }
- if(repair.getCancelStatus() == 0){
- priceLists = priceListService.getByRepairId(repair.getRepairId());
- }
- BigDecimal payAmount = BigDecimal.ZERO;
- for (PriceList priceList : priceLists) {
- BigDecimal price = priceList.getDiscount() == 1 ? priceList.getPriceDiscount() : priceList.getPrice();
- payAmount = payAmount.add(price);
- }
- repair.setPayAmount(payAmount);
- }
- return repairList;
- }
- }
- return null;
- }
- /**
- * * status 0待接单,10待检测,20待报价,30待确认,40已取消,50待备料,60维修中,70待测试,
- * * 80待支付(已完结),90待回收,100待发货,110已发货
- */
- public void confirmRepair(RepairParam param) {
- if(StringUtils.isBlank(param.getRepairId()) ){
- throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
- }
- Repair repair = repairService.getById(param.getRepairId());
- if(repair == null){
- throw new BusinessException(ResultCode.ORDER_PAY_NOT_EXITS);
- }
- if(!repair.getStatus().equals(RepairStatusEnum.TO_BE_CONFIRMED.status())){
- throw new BusinessException(ResultCode.REPAIR_STATUS_NOT_EXITS);
- }
- if(param.getConfirm() == 0){
- priceListService.updateStatusByRepairId(repair.getRepairId());
- priceListLogService.updateByRepairId(repair.getRepairId());
- //无备件更换,不需要备料,应直接进入维修中
- List<PriceList> partList = priceListService.getByRepairId(repair.getRepairId());
- List<PriceList> collect = partList.stream().filter(entity -> entity.getType() == 0).collect(Collectors.toList());
- if(collect.size() <=0){
- repairLogService.saveBySysUser(param.getUserId(),repair.getRepairId(),RepairStatusEnum.TO_BE_REPAIRED.status(),repair.getStatus(),"维修确认");
- return;
- }
- List<RepairRegisterPartVo> partVoList = repairSupplyService.partInfo(repair.getRepairId(), 0);
- if(partVoList.size() <=0){
- repairLogService.saveBySysUser(param.getUserId(),repair.getRepairId(),RepairStatusEnum.TO_BE_REPAIRED.status(),repair.getStatus(),"维修确认");
- return;
- }
- repairLogService.saveBySysUser(param.getUserId(),repair.getRepairId(),RepairStatusEnum.TO_BE_U8SEND.status(),repair.getStatus(),"维修确认");
- }
- if(param.getConfirm() == 1) {
- //有检测费用,已取消,无检测费用,直接到代发货
- BigDecimal robAmount = priceListService.getRobAmountByRepairId(repair.getRepairId());
- repairService.updateCancelStatus(repair.getRepairId(),1,param.getRemark());
- Integer status = null;
- if(robAmount.compareTo(BigDecimal.ZERO) <=0 || StatusUtil.getWarranty(repair.getWarrantyType())){
- status = RepairStatusEnum.TO_BE_SHIPPED.status();
- } else {
- status = RepairStatusEnum.TO_BE_CANCELED.status();
- }
- String remark = null;
- if(StringUtils.isNotBlank(param.getRemark())){
- remark = "取消维修备注:"+param.getRemark();
- }
- repairLogService.saveBySysUser(param.getUserId(),repair.getRepairId(),status,repair.getStatus(),"取消维修",remark);
- }
- }
- public void comment(RepairParam param) {
- if(StringUtils.isBlank(param.getRepairId()) ){
- throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
- }
- RepairComment repairComment = repairCommentService.getByRepairId(param.getRepairId());
- if(repairComment !=null){
- throw new BusinessException(ResultCode.ORDER_COMMENT_EXITS);
- }
- repairComment = new RepairComment();
- BeanUtils.copyProperties(param,repairComment);
- repairCommentService.save(repairComment);
- repairService.updateCommentStatus(param.getRepairId());
- }
- public void invoiceApply(RepairInvoice param) {
- if(StringUtils.isBlank(param.getRepairId()) ){
- throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
- }
- Repair repair = repairService.getById(param.getRepairId());
- if(repair == null){
- throw new BusinessException(ResultCode.ORDER_PAY_NOT_EXITS);
- }
- RepairInvoice repairInvoice = repairInvoiceService.getByRepairId(param.getRepairId());
- if(repairInvoice !=null){
- throw new BusinessException(ResultCode.ORDER_INVOICE_EXITS);
- }
- RepairPay repairPay = repairPayService.getByRepairId(param.getRepairId(), 1);
- if(repairPay == null){
- throw new BusinessException(ResultCode.ORDER_NOt_PAY);
- }
- repairInvoice = new RepairInvoice();
- BeanUtils.copyProperties(param,repairInvoice);
- repairInvoiceService.save(repairInvoice);
- repairService.updateRepairInvoiceStatus(repair.getRepairId(),1);
- }
- public Object getInvoiceAddress(String repairId) {
- CustomerAddress customerAddress = customerAddressService.getByRepairId(repairId);
- RepairPay repairPay = repairPayService.getByRepairId(repairId, 1);
- if(repairPay == null){
- throw new BusinessException(ResultCode.ORDER_NOt_PAY);
- }
- customerAddress.setPayAmount(repairPay.getPayAmount());
- return customerAddress;
- }
- }
|