package com.fdkankan.sale.service.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; 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.vo.request.RepairParam; 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.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; 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); return repairService.list(wrapper); } } return null; } /** * * status 0待接单,1待检测,2待报价,3待确认,4已取消,5待备料,6待回收,7维修中,8待测试, * * 9待支付(已完结),10待收货,11已发货,12已评价 */ 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() != 3){ throw new BusinessException(ResultCode.REPAIR_STATUS_NOT_EXITS); } if(param.getConfirm() == 0){ priceListService.updateStatusByRepairId(repair.getRepairId()); repairLogService.saveBySysUser(param.getUserId(),repair.getRepairId(),5,"确认维修"); } if(param.getConfirm() == 1) { repairLogService.saveBySysUser(param.getUserId(),repair.getRepairId(),4,"拒绝报价"); //存在确认过的报价单,返回维修中 List priceLists = priceListService.getByRepairIdAndStatus(repair.getRepairId(),1); if(priceLists !=null && priceLists.size() >0){ repairService.updateRepairStatus(repair.getRepairId(),6); } } } 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); } 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; } }