quartz/pom.xml
@@ -35,6 +35,10 @@ <artifactId>common</artifactId> </dependency> <dependency> <groupId>com.ruoyi</groupId> <artifactId>service</artifactId> </dependency> </dependencies> </project> quartz/src/main/java/com/ruoyi/quartz/task/SettlementTask.java
New file @@ -0,0 +1,83 @@ package com.ruoyi.quartz.task; import cn.hutool.core.collection.CollectionUtil; import com.ruoyi.common.utils.RandomUtils; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.cwgl.domain.EstimatedReceivable; import com.ruoyi.cwgl.domain.PendingSettlementBusiness; import com.ruoyi.cwgl.domain.ReceivableLineTruckPriceRule; import com.ruoyi.cwgl.service.IEstimatedReceivableService; import com.ruoyi.cwgl.service.IPendingSettlementBusinessService; import com.ruoyi.cwgl.service.impl.ExactPricingRuleMatcher; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.math.BigDecimal; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; /** * 定时任务调度测试 * * @author ruoyi */ @Component("settlementTask") public class SettlementTask { @Autowired private IPendingSettlementBusinessService pendingSettlementBusinessService; @Autowired private IEstimatedReceivableService estimatedReceivableService; public void insertPendingSettlement() { SimpleDateFormat dateFormat = new SimpleDateFormat("yyMMdd"); Date date = new Date(); String datePart = dateFormat.format(date); List<PendingSettlementBusiness> pendingSettlementBusinesses = pendingSettlementBusinessService.selectPendingSettlement2Cw(); //应收规则 List<ReceivableLineTruckPriceRule> receivableLineTruckPriceRules = pendingSettlementBusinessService.selectReceivableLineTruckPriceRule(); //应付规则 List<ReceivableLineTruckPriceRule> payableLineTruckPriceRules= pendingSettlementBusinessService.selectPayableLineTruckPriceRule(); List<EstimatedReceivable> estimatedReceivables = new ArrayList<>(); for (PendingSettlementBusiness pendingSettlementBusiness : pendingSettlementBusinesses) { ReceivableLineTruckPriceRule exactMatchingRule = ExactPricingRuleMatcher.findExactMatchingRule(receivableLineTruckPriceRules, pendingSettlementBusiness.getCustomerName(), pendingSettlementBusiness.getDepartureLocation(), pendingSettlementBusiness.getArrivalLocation(), pendingSettlementBusiness.getVehicleType()); if (exactMatchingRule!=null) { pendingSettlementBusiness.setEstimatedTotalIncome(exactMatchingRule.getFreight()); pendingSettlementBusiness.setCreateTime(date); EstimatedReceivable estimatedReceivable = new EstimatedReceivable(); estimatedReceivable.setFeeSystemNo("YS"+datePart+RandomUtils.random(5)); estimatedReceivable.setDispatchNo(pendingSettlementBusiness.getDispatchNo()); estimatedReceivable.setCustomerName(pendingSettlementBusiness.getCustomerName()); estimatedReceivable.setProjectName(pendingSettlementBusiness.getProjectName()); estimatedReceivable.setOrderDate(pendingSettlementBusiness.getCreatedTime()); estimatedReceivable.setFeeName("运费"); estimatedReceivable.setEstimatedAmount(exactMatchingRule.getFreight()); estimatedReceivable.setCurrency("人民币"); estimatedReceivable.setIsConfirmed(1); estimatedReceivables.add(estimatedReceivable); } ReceivableLineTruckPriceRule exactMatchingRule2 = ExactPricingRuleMatcher.findExactMatchingRule(payableLineTruckPriceRules, pendingSettlementBusiness.getCarrierName(), pendingSettlementBusiness.getDepartureLocation(), pendingSettlementBusiness.getArrivalLocation(), pendingSettlementBusiness.getVehicleType()); if (exactMatchingRule2!=null) { pendingSettlementBusiness.setEstimatedTotalCost(exactMatchingRule2.getFreight()); } } if (CollectionUtil.isNotEmpty(estimatedReceivables)){ estimatedReceivableService.insertEstimatedReceivableBatch(estimatedReceivables); } pendingSettlementBusinessService.insertPendingSettlement(pendingSettlementBusinesses); } } service/src/main/java/com/ruoyi/cwgl/domain/EstimatedReceivable.java
@@ -69,7 +69,7 @@ @Excel(name = "预估费用金额") @TableField("estimated_amount") private BigDecimal estimatedAmount; private Long estimatedAmount; /** 币制 */ service/src/main/java/com/ruoyi/cwgl/domain/PendingSettlementBusiness.java
@@ -167,21 +167,21 @@ @Excel(name = "预估总收入") @TableField("estimated_total_income") private BigDecimal estimatedTotalIncome; private Long estimatedTotalIncome; /** 预估总成本 */ @Excel(name = "预估总成本") @TableField("estimated_total_cost") private BigDecimal estimatedTotalCost; private Long estimatedTotalCost; /** 预估利润 */ @Excel(name = "预估利润") @TableField("estimated_profit") private BigDecimal estimatedProfit; private Long estimatedProfit; /** 电子锁 */ service/src/main/java/com/ruoyi/cwgl/domain/ReceivableLineTruckPriceRule.java
New file @@ -0,0 +1,42 @@ package com.ruoyi.cwgl.domain; import lombok.Data; import java.math.BigDecimal; import java.util.Date; /** * 应收线路整车价格规则实体类 */ @Data public class ReceivableLineTruckPriceRule { private Long id; // 规则ID private String feeType; // 费用类型 private String customerName; // 客户名称 private String departureCity; // 发货市名称 private String departureDistrict; // 发货区名称 private String arrivalCity; // 收货市名称 private String arrivalDistrict; // 收货区名称 private String vehicleType; // 车型名称 private Long freight; // 运费 private Date createdTime; // 创建时间 @Override public String toString() { return "ReceivableLineTruckPriceRule{" + "id=" + id + ", feeType='" + feeType + '\'' + ", customerName='" + customerName + '\'' + ", departureCity='" + departureCity + '\'' + ", departureDistrict='" + departureDistrict + '\'' + ", arrivalCity='" + arrivalCity + '\'' + ", arrivalDistrict='" + arrivalDistrict + '\'' + ", vehicleType='" + vehicleType + '\'' + ", freight=" + freight + ", createdTime=" + createdTime + '}'; } } service/src/main/java/com/ruoyi/cwgl/mapper/PendingSettlementBusinessMapper.java
@@ -3,6 +3,7 @@ import java.util.List; import com.ruoyi.cwgl.domain.PendingSettlementBusiness; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.ruoyi.cwgl.domain.ReceivableLineTruckPriceRule; /** @@ -84,4 +85,16 @@ * @return 结果 */ public int deletePendingSettlementBusinessByIds(Integer[] ids); /** * 查询财务库入账数据库数据 * @return */ List<PendingSettlementBusiness> selectPendingSettlement2Cw(); int updeteCwData(Integer[] ids); List<ReceivableLineTruckPriceRule> selectReceivableLineTruckPriceRule(); List<ReceivableLineTruckPriceRule> selectPayableLineTruckPriceRule(); } service/src/main/java/com/ruoyi/cwgl/service/IPendingSettlementBusinessService.java
@@ -3,6 +3,8 @@ import java.util.List; import com.ruoyi.cwgl.domain.PendingSettlementBusiness; import com.baomidou.mybatisplus.extension.service.IService; import com.ruoyi.cwgl.domain.ReceivableLineTruckPriceRule; /** * 待入账业务Service接口 * @@ -99,4 +101,33 @@ * @return 结果 */ public int deletePendingSettlementBusinessById(Integer id); /** * 新增待入账数据 */ void insertPendingSettlement(List<PendingSettlementBusiness> pendingSettlementBusinesses ); /** * 查询财务库入账数据 * @return */ List<PendingSettlementBusiness> selectPendingSettlement2Cw(); /** * 修改财务数据库数据为已同步 * @param ids * @return */ int updateCwData(Integer [] ids); /** * 应收线路整车价格 * @return */ List<ReceivableLineTruckPriceRule> selectReceivableLineTruckPriceRule(); /** * 应付线路整车价格 * @return */ List<ReceivableLineTruckPriceRule> selectPayableLineTruckPriceRule(); } service/src/main/java/com/ruoyi/cwgl/service/impl/PendingSettlementBusinessServiceImpl.java
@@ -2,8 +2,11 @@ import java.util.List; import cn.hutool.core.collection.CollectionUtil; import com.ruoyi.common.utils.DateUtils; import javax.annotation.Resource; import com.ruoyi.cwgl.domain.ReceivableLineTruckPriceRule; import org.springframework.transaction.annotation.Transactional; import org.springframework.stereotype.Service; import org.springframework.scheduling.annotation.Async; @@ -179,4 +182,45 @@ { 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(); } } service/src/main/resources/mapper/cwgl/EstimatedReceivableMapper.xml
@@ -119,7 +119,7 @@ </trim> </insert> <insert id="insertEstimatedReceivableBatch" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="id"> <insert id="insertEstimatedReceivableBatch" parameterType="java.util.List" > insert into estimated_receivable <trim prefix="(" suffix=") values" suffixOverrides=","> id,fee_system_no,dispatch_no,customer_name,project_name,order_date,fee_name,estimated_amount,currency,related_bill_name,related_bill_status,is_confirmed,confirm_by,confirm_time,remark,create_by,update_by,create_time,update_time,deleted, service/src/main/resources/mapper/cwgl/PendingSettlementBusinessMapper.xml
@@ -130,6 +130,141 @@ </where> order by thisTab.id desc </select> <select id="selectPendingSettlement2Cw" resultType="com.ruoyi.cwgl.domain.PendingSettlementBusiness"> SELECT -- ord.BOOKING_NO '客户订单号', -- ord.CUSTOMER_ID, -- ts.CARRIER_ID, ts.ID as serviceId, brd.PROJECT_NAME as projectName, ts.DISPATCH_NO as dispatchNo, ts.CREATED_TIME as createdTime, -- ts.TRANSPORT_MODE '运输方式', -- ts.PRODUCT_ID '服务产品', customer.NAME as customerName, case when ts.CARRIER_ID=50 then '自营' else '外协' end as operationMode, bp.NAME as carrierName, location_d.NAME_TREE as departureLocation, location_a.NAME_TREE as arrivalLocation, -- ts.VEHICLE_ID '运输工具ID', vhc.LICENSE_PLATE_NUMBER as licensePlateNumber, bvt.NAME as vehicleType, driver_m.NAME as mainDriver, ts.POINT_NUM as pointNum, ts.CREATOR as businessContact, -- ts.ELECTRONIC_LOCK '电子锁', -- ts.RE_WEIGHING_WEIGHT '复磅重量', ts.QUANTITY as quantity, driver_a.NAME as assistantDriver, ts.ACTUAL_DEPARTURE_TIME as actualDepartureTime, ts.REQUIRED_ARRIVAL_TIME as requiredArrivalTime, ts.ACTUAL_ARRIVAL_TIME as actualArrivalTime, ts.BE_RETURN as beReturn, ts.DISPATCH_QUANTITY as dispatchQuantity, ts.DISPATCH_WEIGHT as dispatchWeight, ts.DISPATCH_VOLUME as dispatchVolume, -- ts.EMPTY_MILEAGE '空载里程(公里)', -- ts.EMPTY_FUEL '空载油耗(升)', -- ts.HEAVY_MILEAGE '重载里程(公里)', -- ts.HEAVY_FUEL '重载油耗(升)', -- ts.BE_SCHEDULED '是否按班次', -- ts.TRACKING_NO '快递单号', -- ts.SEAL_NO '铅封号', -- ts.SCHEDULE_NO '班次号', CASE ts.STATUS WHEN 'A' THEN '生效' WHEN 'O' THEN '打开' WHEN 'J' THEN '已接单' WHEN 'K' THEN '已到库' WHEN 'Z' THEN '已装车' WHEN 'T' THEN '在途' WHEN 'F' THEN '已复磅' WHEN 'D' THEN '已运抵' ELSE '未知状态' END AS transportStatus FROM tms_shipment ts -- 订单表 LEFT JOIN oms_order ord ON ts.DISPATCH_NO = ord.DISPATCH_CODE -- 客户表 LEFT join base_customer customer on customer.ID=ord.CUSTOMER_ID -- 运输工具表 left join tms_vehicle vhc on ts.VEHICLE_ID=vhc.id -- 车型数据表 LEFT JOIN base_vehicle_type bvt on bvt.ID=vhc.VEHICLE_TYPE_ID -- 承运商表 left join base_provider bp on bp.ID=ts.CARRIER_ID -- 司机表 left join tms_driver driver_m on driver_m.ID=ts.MAIN_DRIVER_ID -- 司机表 left join tms_driver driver_a on driver_a.ID=ts.ASSISTANT_DRIVER_ID -- 地区表 left join base_location location_a on location_a.ID =ts.ARRIVAL_LOCATION_ID -- 地区表 left join base_location location_d on location_d.ID =ts.DEPARTURE_LOCATION_ID -- 路线详情表表 left join base_plan_road_detail prd on prd.ID =ts.PLAN_ROAD_DETAIL_ID -- 路线表 LEFT join base_road_survey brd on brd.ID = prd.ROAD_SURVEY_ID where ts.STATUS='D' and ts.IS_SYNC = 0 </select> <select id="selectReceivableLineTruckPriceRule" resultType="com.ruoyi.cwgl.domain.ReceivableLineTruckPriceRule"> SELECT rtd.id as id, rtd.REFERENCE1 as feeType, rtd.REFERENCE2 as customerName, rtd.REFERENCE3 as departureCity, rtd.REFERENCE4 as departureDistrict, rtd.REFERENCE5 as arrivalCity, rtd.REFERENCE6 as arrivalDistrict, rtd.REFERENCE7 as vehicleType, rtd.VALUE1 as freight, rtd.CREATED_TIME as createdTime FROM thorn_rule_table_detail rtd LEFT JOIN thorn_rule_version rv ON rtd.VERSION_ID = rv.id LEFT JOIN thorn_rule_table rt ON rv.RULE_TABLE_ID = rt.id WHERE rt.STATUS = 'ACTIVE' AND rt.NAME = '应收线路整车价格' and rtd.REFERENCE1='运费' </select> <select id="selectPayableLineTruckPriceRule" resultType="com.ruoyi.cwgl.domain.ReceivableLineTruckPriceRule"> SELECT rtd.id as id, rtd.REFERENCE1 as feeType, rtd.REFERENCE2 as customerName, rtd.REFERENCE3 as departureCity, rtd.REFERENCE4 as departureDistrict, rtd.REFERENCE5 as arrivalCity, rtd.REFERENCE6 as arrivalDistrict, rtd.REFERENCE7 as vehicleType, rtd.VALUE1 as freight, rtd.CREATED_TIME as createdTime FROM thorn_rule_table_detail rtd LEFT JOIN thorn_rule_version rv ON rtd.VERSION_ID = rv.id LEFT JOIN thorn_rule_table rt ON rv.RULE_TABLE_ID = rt.id WHERE rt.STATUS = 'ACTIVE' AND rt.NAME = '应付线路整车价格' and rtd.REFERENCE1='运费' </select> <!-- 新增 --> <insert id="insertPendingSettlementBusiness" parameterType="com.ruoyi.cwgl.domain.PendingSettlementBusiness" useGeneratedKeys="true" keyProperty="id"> @@ -356,6 +491,14 @@ where id = #{item.id} </foreach> </update> <update id="updeteCwData"> update pending_settlement_business set IS_SYNC = 1 where ID in <foreach item="id" collection="array" open="(" separator="," close=")"> #{id} </foreach> </update> <!--删除--> <delete id="deletePendingSettlementBusinessById" parameterType="Integer">