| | |
| | | package com.ruoyi.tms.service.impl; |
| | | |
| | | import java.util.Arrays; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import cn.hutool.core.bean.BeanUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.ruoyi.common.core.domain.AjaxResult; |
| | | import com.ruoyi.common.core.domain.entity.SysUser; |
| | | import com.ruoyi.common.enums.SystemDataNoEnum; |
| | |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.system.service.ISysUserService; |
| | | import com.ruoyi.system.service.ISystemDataNoService; |
| | | import com.ruoyi.tms.domain.TmsDriverDispatch; |
| | | import com.ruoyi.tms.domain.*; |
| | | import com.ruoyi.tms.domain.vo.DriverDispatchVo; |
| | | import com.ruoyi.tms.mapper.TmsFinanceMapper; |
| | | import com.ruoyi.tms.mapper.TmsQuoteDetailMapper; |
| | | import com.ruoyi.tms.mapper.TmsQuotePlanMapper; |
| | | import com.ruoyi.tms.service.ITmsDriverDispatchService; |
| | | import com.ruoyi.tms.service.ITmsFinanceService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | import com.ruoyi.common.core.service.BaseService; |
| | | |
| | | import com.ruoyi.tms.mapper.TmsDispatchOrderMapper; |
| | | import com.ruoyi.tms.domain.TmsDispatchOrder; |
| | | import com.ruoyi.tms.service.ITmsDispatchOrderService; |
| | | import com.ruoyi.common.core.text.Convert; |
| | | |
| | |
| | | private ISysUserService userService; |
| | | @Autowired |
| | | private ITmsDriverDispatchService tmsDriverDispatchService; |
| | | @Resource |
| | | private TmsQuoteDetailMapper tmsQuoteDetailMapper; |
| | | |
| | | @Resource |
| | | private TmsQuotePlanMapper tmsQuotePlanMapper; |
| | | |
| | | |
| | | @Autowired |
| | | ITmsFinanceService tmsFinanceService; |
| | | /** |
| | | * 查询调度单管理 |
| | | * |
| | |
| | | return AjaxResult.error("操作失败"); |
| | | } |
| | | |
| | | @Override |
| | | public AjaxResult dropHook(Integer id) { |
| | | TmsDispatchOrder tmsDispatchOrder = selectTmsDispatchOrderById(id); |
| | | if (tmsDispatchOrder == null){ |
| | | return AjaxResult.error("未找到该数据"); |
| | | } |
| | | tmsDriverDispatchService.update( |
| | | null, |
| | | new LambdaUpdateWrapper<TmsDriverDispatch>() |
| | | .eq(TmsDriverDispatch::getDispatchId, tmsDispatchOrder.getId()) |
| | | .eq(TmsDriverDispatch::getDriverId, tmsDispatchOrder.getMainDriverId()) |
| | | .set(TmsDriverDispatch::getStatus, 1) |
| | | ); |
| | | |
| | | tmsDispatchOrderMapper.update(new LambdaUpdateWrapper<TmsDispatchOrder>() |
| | | .eq(TmsDispatchOrder::getId, tmsDispatchOrder.getId()) |
| | | .set(TmsDispatchOrder::getStatus, 6) |
| | | ); |
| | | return AjaxResult.success("操作成功"); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public AjaxResult connectHang(TmsDriverDispatch driverDispatch) { |
| | | TmsDispatchOrder tmsDispatchOrder = selectTmsDispatchOrderById(driverDispatch.getDispatchId()); |
| | | if (tmsDispatchOrder == null){ |
| | | return AjaxResult.error("未找到该数据"); |
| | | } |
| | | driverDispatch.setStatus(2); |
| | | tmsDriverDispatchService.insertTmsDriverDispatch(driverDispatch); |
| | | return AjaxResult.success(); |
| | | } |
| | | |
| | | @Override |
| | | public AjaxResult assignedItineraryList() { |
| | |
| | | { |
| | | return tmsDispatchOrderMapper.deleteTmsDispatchOrderById(id); |
| | | } |
| | | |
| | | @Override |
| | | public List<TmsDispatchOrder> initGenerate(List<Integer> ids) { |
| | | List<TmsDispatchOrder> tmsDispatchOrders = tmsDispatchOrderMapper.selectBatchIds(ids); |
| | | if (tmsDispatchOrders != null && !tmsDispatchOrders.isEmpty()){ |
| | | tmsDispatchOrders.forEach(tmsDispatchOrder -> { |
| | | // 客户ID |
| | | Integer customerId = tmsDispatchOrder.getCustomerId(); |
| | | |
| | | // 车型 |
| | | String actualVehicleType = tmsDispatchOrder.getActualVehicleType(); |
| | | |
| | | // 运输路线 = 发货地行政区域 + 收货地行政区域 |
| | | String shipperRegionCode = tmsDispatchOrder.getShipperRegionCode(); |
| | | String receiverRegionCode = tmsDispatchOrder.getReceiverRegionCode(); |
| | | if (tmsDispatchOrder.getAccountsReceivableStatus() != null && tmsDispatchOrder.getAccountsReceivableStatus() == 1){ |
| | | TmsQuotePlan tmsQuotePlan = tmsQuotePlanMapper.selectTmsQuotePlanById(tmsDispatchOrder.getCollectionPlanId()); |
| | | tmsDispatchOrder.setCollectionPlanId(tmsQuotePlan.getId()); |
| | | tmsDispatchOrder.setCollectionPlanName(tmsQuotePlan.getPlanName()); |
| | | }else{ |
| | | // 查询应收规则 |
| | | TmsQuoteDetail tmsQuoteDetail = tmsQuoteDetailMapper.selectOne(new LambdaQueryWrapper<TmsQuoteDetail>() |
| | | .eq(TmsQuoteDetail::getCustomerId, customerId) |
| | | .eq(TmsQuoteDetail::getVehicleType, actualVehicleType) |
| | | .eq(TmsQuoteDetail::getStartRegionCode, shipperRegionCode) |
| | | .eq(TmsQuoteDetail::getEndRegionCode, receiverRegionCode) |
| | | .eq(TmsQuoteDetail::getPlanType, 0) |
| | | .last("limit 1") |
| | | ); |
| | | if (tmsQuoteDetail != null){ |
| | | TmsQuotePlan tmsQuotePlan = tmsQuotePlanMapper.selectTmsQuotePlanById(tmsQuoteDetail.getQuotePlanId()); |
| | | tmsDispatchOrder.setCollectionPlanId(tmsQuotePlan.getId()); |
| | | tmsDispatchOrder.setCollectionPlanName(tmsQuotePlan.getPlanName()); |
| | | tmsDispatchOrder.setCollectionPlanDetailId(tmsQuoteDetail.getId()); |
| | | tmsDispatchOrder.setCollectionPlanAmount(tmsQuoteDetail.getFreightPrice()); |
| | | }else{ |
| | | tmsDispatchOrder.setAccountsReceivableStatus(2); |
| | | } |
| | | } |
| | | |
| | | if (tmsDispatchOrder.getAccountsPayableStatus() != null && tmsDispatchOrder.getAccountsPayableStatus() == 1){ |
| | | TmsQuotePlan tmsQuotePlan = tmsQuotePlanMapper.selectTmsQuotePlanById(tmsDispatchOrder.getPaymentPlanId()); |
| | | tmsDispatchOrder.setPaymentPlanId(tmsQuotePlan.getId()); |
| | | tmsDispatchOrder.setPaymentPlanName(tmsQuotePlan.getPlanName()); |
| | | }else{ |
| | | // 查询应付规则 |
| | | TmsQuoteDetail tmsQuoteDetail2 = tmsQuoteDetailMapper.selectOne(new LambdaQueryWrapper<TmsQuoteDetail>() |
| | | .eq(TmsQuoteDetail::getCustomerId, customerId) |
| | | .eq(TmsQuoteDetail::getVehicleType, actualVehicleType) |
| | | .eq(TmsQuoteDetail::getStartRegionCode, shipperRegionCode) |
| | | .eq(TmsQuoteDetail::getEndRegionCode, receiverRegionCode) |
| | | .eq(TmsQuoteDetail::getPlanType, 1) |
| | | .last("limit 1") |
| | | ); |
| | | |
| | | if (tmsQuoteDetail2 != null){ |
| | | TmsQuotePlan tmsQuotePlan = tmsQuotePlanMapper.selectTmsQuotePlanById(tmsQuoteDetail2.getQuotePlanId()); |
| | | tmsDispatchOrder.setPaymentPlanId(tmsQuotePlan.getId()); |
| | | tmsDispatchOrder.setPaymentPlanName(tmsQuotePlan.getPlanName()); |
| | | tmsDispatchOrder.setPaymentPlanDetailId(tmsQuoteDetail2.getId()); |
| | | tmsDispatchOrder.setPaymentPlanAmount(tmsQuoteDetail2.getFreightPrice()); |
| | | |
| | | }else{ |
| | | tmsDispatchOrder.setAccountsPayableStatus(2); |
| | | } |
| | | } |
| | | |
| | | |
| | | }); |
| | | } |
| | | return tmsDispatchOrders; |
| | | } |
| | | |
| | | @Override |
| | | public AjaxResult generateTmsDispatchOrder(List<Integer> ids) { |
| | | List<TmsDispatchOrder> tmsDispatchOrders = initGenerate(ids); |
| | | List<TmsDispatchOrder> receivableList = tmsDispatchOrders.stream().filter(item -> item.getAccountsReceivableStatus() == 0).collect(Collectors.toList()); |
| | | if (!receivableList.isEmpty()){ |
| | | List<TmsDispatchOrder> collect = receivableList.stream().map(item -> { |
| | | TmsDispatchOrder tmsDispatchOrder = new TmsDispatchOrder(); |
| | | tmsDispatchOrder.setId(item.getId()); |
| | | tmsDispatchOrder.setAccountsReceivableStatus(1); |
| | | tmsDispatchOrder.setCollectionPlanId(item.getCollectionPlanId()); |
| | | tmsDispatchOrder.setUpdateBy(SecurityUtils.getUsername()); |
| | | return tmsDispatchOrder; |
| | | }).collect(Collectors.toList()); |
| | | // 1、修改调度 |
| | | tmsDispatchOrderMapper.updateTmsDispatchOrderBatch(collect); |
| | | // 2、生成应收账单 |
| | | List<TmsFinance> tmsFinances = BeanUtil.copyToList(receivableList, TmsFinance.class); |
| | | tmsFinances.forEach(item ->{ |
| | | item.setSystemCode(systemDataNoService.getNoByKey(SystemDataNoEnum.YSD)); |
| | | item.setPlanName(item.getCollectionPlanName()); |
| | | item.setDispatchId(item.getId()); |
| | | item.setCreateBy(SecurityUtils.getUsername()); |
| | | item.setCreateTime(new Date()); |
| | | item.setUpdateBy(SecurityUtils.getUsername()); |
| | | item.setUpdateTime(new Date()); |
| | | item.setStatus(0); |
| | | item.setType(0); |
| | | item.setTotalAmount(item.getCollectionPlanAmount()); |
| | | }); |
| | | tmsFinanceService.insertTmsFinanceYFBatch(tmsFinances); |
| | | } |
| | | |
| | | List<TmsDispatchOrder> playList = tmsDispatchOrders.stream().filter(item -> item.getAccountsPayableStatus() == 0).collect(Collectors.toList()); |
| | | if (!playList.isEmpty()){ |
| | | List<TmsDispatchOrder> collect = playList.stream().map(item -> { |
| | | TmsDispatchOrder tmsDispatchOrder = new TmsDispatchOrder(); |
| | | tmsDispatchOrder.setId(item.getId()); |
| | | tmsDispatchOrder.setAccountsPayableStatus(1); |
| | | tmsDispatchOrder.setPaymentPlanId(item.getPaymentPlanId()); |
| | | tmsDispatchOrder.setUpdateBy(SecurityUtils.getUsername()); |
| | | return tmsDispatchOrder; |
| | | }).collect(Collectors.toList()); |
| | | // 1、修改调度 |
| | | tmsDispatchOrderMapper.updateTmsDispatchOrderBatch(collect); |
| | | // 2、生成应付账单 |
| | | List<TmsFinance> tmsFinances = BeanUtil.copyToList(receivableList, TmsFinance.class); |
| | | tmsFinances.forEach(item ->{ |
| | | item.setSystemCode(systemDataNoService.getNoByKey(SystemDataNoEnum.YFD)); |
| | | item.setPlanName(item.getPaymentPlanName()); |
| | | item.setDispatchId(item.getId()); |
| | | item.setCreateBy(SecurityUtils.getUsername()); |
| | | item.setCreateTime(new Date()); |
| | | item.setUpdateBy(SecurityUtils.getUsername()); |
| | | item.setUpdateTime(new Date()); |
| | | item.setStatus(0); |
| | | item.setType(1); |
| | | item.setTotalAmount(item.getPaymentPlanAmount()); |
| | | }); |
| | | tmsFinanceService.insertTmsFinanceYFBatch(tmsFinances); |
| | | |
| | | } |
| | | |
| | | return AjaxResult.success(); |
| | | } |
| | | } |