| | |
| | | package com.ruoyi.cwgl.service.impl; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.Arrays; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Optional; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import com.ruoyi.common.utils.DateUtils; |
| | | import cn.hutool.core.collection.CollectionUtil; |
| | | import com.ruoyi.common.exception.ServiceException; |
| | | import com.ruoyi.common.utils.*; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | import com.ruoyi.cwgl.domain.EstimatedReceivableBill; |
| | | import com.ruoyi.cwgl.domain.ReceivableLineTruckPriceRule; |
| | | import com.ruoyi.cwgl.domain.vo.CreateBillVo; |
| | | import com.ruoyi.cwgl.mapper.EstimatedReceivableBillMapper; |
| | | import com.ruoyi.cwgl.mapper.EstimatedReceivableMapper; |
| | | import com.ruoyi.cwgl.service.IEstimatedReceivableBillService; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.scheduling.annotation.Async; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import com.ruoyi.common.utils.PageUtils; |
| | | import com.ruoyi.common.constant.Constants; |
| | | import com.ruoyi.common.annotation.DataSource; |
| | | import com.ruoyi.common.enums.DataSourceType; |
| | |
| | | protected final Logger logger = LoggerFactory.getLogger(getClass()); |
| | | @Resource |
| | | private PendingSettlementBusinessMapper pendingSettlementBusinessMapper; |
| | | |
| | | @Resource |
| | | private EstimatedReceivableBillMapper estimatedReceivableBillMapper; |
| | | @Resource |
| | | private EstimatedReceivableMapper estimatedReceivableMapper; |
| | | |
| | | /** |
| | | * 查询待入账业务 |
| | |
| | | { |
| | | return pendingSettlementBusinessMapper.deletePendingSettlementBusinessById(id); |
| | | } |
| | | |
| | | @Override |
| | | public void insertPendingSettlement(List<PendingSettlementBusiness> pendingSettlementBusinesses ) { |
| | | |
| | | if (CollectionUtil.isNotEmpty(pendingSettlementBusinesses)) { |
| | | pendingSettlementBusinessMapper.insertPendingSettlementBusinessBatch(pendingSettlementBusinesses); |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | @DataSource(DataSourceType.CWSJ) |
| | | @Override |
| | | public List<PendingSettlementBusiness> selectPendingSettlement2Cw() { |
| | | List<PendingSettlementBusiness> pendingSettlementBusinesses = pendingSettlementBusinessMapper.selectPendingSettlement2Cw(); |
| | | //更新同步状态用 |
| | | /* Integer[] ids = pendingSettlementBusinesses.stream().map(PendingSettlementBusiness::getServiceId).toArray(Integer[]::new); |
| | | int i = pendingSettlementBusinessMapper.updeteCwData(ids); |
| | | if (i>0){ |
| | | logger.info("同步状态更新成功"); |
| | | }*/ |
| | | return pendingSettlementBusinesses; |
| | | } |
| | | |
| | | @DataSource(DataSourceType.CWSJ) |
| | | @Override |
| | | public int updateCwData(Integer[] ids) { |
| | | return pendingSettlementBusinessMapper.updeteCwData(ids); |
| | | } |
| | | |
| | | @DataSource(DataSourceType.CWSJ) |
| | | @Override |
| | | public List<ReceivableLineTruckPriceRule> selectReceivableLineTruckPriceRule() { |
| | | return pendingSettlementBusinessMapper.selectReceivableLineTruckPriceRule(); |
| | | } |
| | | |
| | | @DataSource(DataSourceType.CWSJ) |
| | | @Override |
| | | public List<ReceivableLineTruckPriceRule> selectPayableLineTruckPriceRule() { |
| | | return pendingSettlementBusinessMapper.selectPayableLineTruckPriceRule(); |
| | | } |
| | | |
| | | @Override |
| | | public CreateBillVo billIds(Integer[] ids) { |
| | | List<PendingSettlementBusiness> pendingSettlementBusinesses = pendingSettlementBusinessMapper.selectBatchIds(Arrays.asList(ids)); |
| | | if (CollectionUtil.isEmpty(pendingSettlementBusinesses)){ |
| | | throw new ServiceException("账单不存在"); |
| | | } |
| | | CreateBillVo createBillVo = new CreateBillVo(); |
| | | String customerName = pendingSettlementBusinesses.get(0).getCustomerName(); |
| | | createBillVo.setCustomerName(customerName); |
| | | createBillVo.setCount(pendingSettlementBusinesses.size()); |
| | | BigDecimal priceTotal = BigDecimal.ZERO; |
| | | for (PendingSettlementBusiness pendingSettlementBusiness : pendingSettlementBusinesses) { |
| | | if (pendingSettlementBusiness.getIsCreate().equals(1)){ |
| | | throw new ServiceException(pendingSettlementBusiness.getDispatchNo()+"已入账"); |
| | | |
| | | } |
| | | if (!pendingSettlementBusiness.getCustomerName().equals(customerName)){ |
| | | throw new ServiceException("只能选择相同客户名称的数据"); |
| | | |
| | | } |
| | | priceTotal =priceTotal.add( pendingSettlementBusiness.getEstimatedTotalIncome()==null?BigDecimal.ZERO:pendingSettlementBusiness.getEstimatedTotalIncome()); |
| | | } |
| | | createBillVo.setPrice(priceTotal); |
| | | return createBillVo; |
| | | } |
| | | |
| | | @Override |
| | | public CreateBillVo billList(PendingSettlementBusiness pendingSettlementBusiness) { |
| | | String customerName = pendingSettlementBusiness.getCustomerName(); |
| | | if (StringUtils.isEmpty(customerName)){ |
| | | throw new ServiceException("客户名称不能为空"); |
| | | } |
| | | pendingSettlementBusiness.setIsCreate(0); |
| | | List<PendingSettlementBusiness> pendingSettlementBusinesses = pendingSettlementBusinessMapper.selectPendingSettlementBusinessList(pendingSettlementBusiness); |
| | | BigDecimal priceTotal = pendingSettlementBusinesses.stream() |
| | | .map(b -> Optional.ofNullable(b.getEstimatedTotalIncome()).orElse(BigDecimal.ZERO)) |
| | | .reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | CreateBillVo createBillVo = new CreateBillVo(); |
| | | createBillVo.setCustomerName(customerName); |
| | | createBillVo.setCount(pendingSettlementBusinesses.size()); |
| | | createBillVo.setPrice(priceTotal); |
| | | return createBillVo; |
| | | } |
| | | |
| | | @Override |
| | | public int createBillIds(Integer[] ids, CreateBillVo createBillVo) { |
| | | String username = SecurityUtils.getUsername(); |
| | | SimpleDateFormat dateFormat = new SimpleDateFormat("yyMMdd"); |
| | | Date date = new Date(); |
| | | String datePart = dateFormat.format(date); |
| | | List<PendingSettlementBusiness> pendingSettlementBusinesses = pendingSettlementBusinessMapper.selectBatchIds(Arrays.asList(ids)); |
| | | if (CollectionUtil.isEmpty(pendingSettlementBusinesses)){ |
| | | throw new ServiceException("账单不存在"); |
| | | } |
| | | for (PendingSettlementBusiness pendingSettlementBusiness : pendingSettlementBusinesses) { |
| | | if (pendingSettlementBusiness.getIsCreate().equals(1)){ |
| | | throw new ServiceException(pendingSettlementBusiness.getDispatchNo()+"已入账"); |
| | | |
| | | } |
| | | String customerName = pendingSettlementBusinesses.get(0).getCustomerName(); |
| | | |
| | | if (!pendingSettlementBusiness.getCustomerName().equals(customerName)){ |
| | | throw new ServiceException("只能选择相同客户名称的数据"); |
| | | |
| | | } |
| | | } |
| | | //调度单集合 |
| | | List<String> collect = pendingSettlementBusinesses.stream().map(PendingSettlementBusiness::getDispatchNo).collect(Collectors.toList()); |
| | | EstimatedReceivableBill estimatedReceivableBill = new EstimatedReceivableBill(); |
| | | estimatedReceivableBill.setCreateTime(date); |
| | | estimatedReceivableBill.setBillSystemNo("ZD"+datePart+RandomUtils.random(4)); |
| | | estimatedReceivableBill.setBillName(createBillVo.getBillName()); |
| | | estimatedReceivableBill.setCustomerName(createBillVo.getCustomerName()); |
| | | estimatedReceivableBill.setDispatchCount(createBillVo.getCount()); |
| | | estimatedReceivableBill.setTotalAmount(createBillVo.getPrice()); |
| | | estimatedReceivableBill.setSettledAmount(BigDecimal.ZERO); |
| | | estimatedReceivableBill.setInvoiceStatus(0); |
| | | estimatedReceivableBill.setStatus(0); |
| | | estimatedReceivableBill.setCreateBy(username); |
| | | estimatedReceivableBillMapper.insertEstimatedReceivableBill(estimatedReceivableBill); |
| | | //修改入账 |
| | | estimatedReceivableMapper.updateEstimatedReceivableBillStatus(collect,1); |
| | | |
| | | //修改调度单为已创建账单 |
| | | return pendingSettlementBusinessMapper.updatePendingSettlementBusinessIsCreate(collect,estimatedReceivableBill.getId(),createBillVo.getBillName()); |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public int createBillList(PendingSettlementBusiness pendingSettlementBusiness) { |
| | | String customerName = pendingSettlementBusiness.getCustomerName(); |
| | | if (StringUtils.isEmpty(customerName)){ |
| | | throw new ServiceException("客户名称不能为空"); |
| | | } |
| | | String billName = pendingSettlementBusiness.getBillName(); |
| | | if (StringUtils.isEmpty(billName)){ |
| | | throw new ServiceException("账单名称不能为空"); |
| | | } |
| | | pendingSettlementBusiness.setIsCreate(0); |
| | | List<PendingSettlementBusiness> pendingSettlementBusinesses = pendingSettlementBusinessMapper.selectPendingSettlementBusinessList(pendingSettlementBusiness); |
| | | if (CollectionUtil.isEmpty(pendingSettlementBusinesses)){ |
| | | throw new ServiceException("填写的客户没有能入账数据"); |
| | | |
| | | } |
| | | String username = SecurityUtils.getUsername(); |
| | | SimpleDateFormat dateFormat = new SimpleDateFormat("yyMMdd"); |
| | | Date date = new Date(); |
| | | String datePart = dateFormat.format(date); |
| | | |
| | | BigDecimal priceTotal = pendingSettlementBusinesses.stream() |
| | | .map(b -> Optional.ofNullable(b.getEstimatedTotalIncome()).orElse(BigDecimal.ZERO)) |
| | | .reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | //调度单集合 |
| | | List<String> collect = pendingSettlementBusinesses.stream().map(PendingSettlementBusiness::getDispatchNo).collect(Collectors.toList()); |
| | | EstimatedReceivableBill estimatedReceivableBill = new EstimatedReceivableBill(); |
| | | estimatedReceivableBill.setCreateTime(date); |
| | | estimatedReceivableBill.setBillSystemNo("ZD"+datePart+RandomUtils.random(4)); |
| | | estimatedReceivableBill.setBillName(billName); |
| | | estimatedReceivableBill.setCustomerName(customerName); |
| | | estimatedReceivableBill.setDispatchCount(pendingSettlementBusinesses.size()); |
| | | estimatedReceivableBill.setTotalAmount(priceTotal); |
| | | estimatedReceivableBill.setSettledAmount(BigDecimal.ZERO); |
| | | estimatedReceivableBill.setInvoiceStatus(0); |
| | | estimatedReceivableBill.setStatus(0); |
| | | estimatedReceivableBill.setCreateBy(username); |
| | | estimatedReceivableBillMapper.insertEstimatedReceivableBill(estimatedReceivableBill); |
| | | //修改应收管理表已入账 |
| | | estimatedReceivableMapper.updateEstimatedReceivableBillStatus(collect,1); |
| | | //修改调度单为已创建账单 |
| | | return pendingSettlementBusinessMapper.updatePendingSettlementBusinessIsCreate(collect,estimatedReceivableBill.getId(),billName); |
| | | } |
| | | |
| | | @Override |
| | | public List<String> selectCustomName() { |
| | | return pendingSettlementBusinessMapper.selectCustomName(); |
| | | } |
| | | } |