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 list = customerService.getByOpenId(openId); if(list!= null && list.size() >0){ List repairIds = list.stream().map(Customer::getRepairId).collect(Collectors.toList()); if(repairIds.size() >0){ LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); wrapper.in(Repair::getRepairId,repairIds); wrapper.orderByDesc(Repair::getCreateTime); List repairList = repairService.list(wrapper); for (Repair repair : repairList) { List 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 partList = priceListService.getByRepairId(repair.getRepairId()); List 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 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; } }