Compare commits

..

2 Commits

Author SHA1 Message Date
ljw badc3786ba Merge branch 'dev' of https://git.njzscloud.com/lzq/njzscloud into dev 2025-12-23 11:48:09 +08:00
ljw 9285618aa3 对账单 2025-12-23 11:47:46 +08:00
5 changed files with 104 additions and 58 deletions

View File

@ -3,6 +3,7 @@ package com.njzscloud.supervisory.money.pojo.entity;
import com.baomidou.mybatisplus.annotation.*; import com.baomidou.mybatisplus.annotation.*;
import com.njzscloud.supervisory.money.contant.BillStatus; import com.njzscloud.supervisory.money.contant.BillStatus;
import com.njzscloud.supervisory.money.contant.InvoiceStatus; import com.njzscloud.supervisory.money.contant.InvoiceStatus;
import com.njzscloud.supervisory.order.contant.OrderCategory;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import lombok.ToString; import lombok.ToString;
@ -137,4 +138,9 @@ public class MoneyBillEntity {
*/ */
private String goodsName; private String goodsName;
/**
* ; order_category
*/
private String orderCategory;
} }

View File

@ -8,6 +8,9 @@ import lombok.experimental.Accessors;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.time.LocalDateTime; import java.time.LocalDateTime;
/**
* @author ljw
*/
@Getter @Getter
@Setter @Setter
@ToString @ToString
@ -23,6 +26,10 @@ public class MoneyBillResult {
private Long orderId; private Long orderId;
private BigDecimal discountMoney; private BigDecimal discountMoney;
private BigDecimal settleMoney; private BigDecimal settleMoney;
/**
* ; order_category
*/
private String orderCategory;
/** /**
* *
*/ */

View File

@ -1,6 +1,5 @@
package com.njzscloud.supervisory.money.quartz; package com.njzscloud.supervisory.money.quartz;
import com.njzscloud.supervisory.goods.contant.MoneyStrategy;
import com.njzscloud.supervisory.money.mapper.MoneyBillMapper; import com.njzscloud.supervisory.money.mapper.MoneyBillMapper;
import com.njzscloud.supervisory.money.pojo.entity.MoneyBillEntity; import com.njzscloud.supervisory.money.pojo.entity.MoneyBillEntity;
import com.njzscloud.supervisory.money.pojo.result.MoneyBillResult; import com.njzscloud.supervisory.money.pojo.result.MoneyBillResult;
@ -17,6 +16,9 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/**
* @author ljw
*/
@Slf4j @Slf4j
@Component @Component
@RequiredArgsConstructor @RequiredArgsConstructor
@ -24,8 +26,8 @@ public class MoneyBillQuartz {
private final MoneyBillMapper moneyBillMapper; private final MoneyBillMapper moneyBillMapper;
// @Scheduled(cron = "0 0/1 * * * ?")//每1分钟一次 @Scheduled(cron = "0 0/5 * * * ?")//每1分钟一次
@Scheduled(cron = "0 0 1 27 * ?")//每月27号凌晨1点执行 // @Scheduled(cron = "0 0 1 27 * ?")//每月27号凌晨1点执行
public void syncAssetsDiscover() { public void syncAssetsDiscover() {
generateMoneyBill(); generateMoneyBill();
} }
@ -33,9 +35,11 @@ public class MoneyBillQuartz {
public void generateMoneyBill() { public void generateMoneyBill() {
// 计算上个月的时间范围 // 计算上个月的时间范围
LocalDateTime now = LocalDateTime.now(); LocalDateTime now = LocalDateTime.now();
LocalDateTime lastMonthStart = now.minusMonths(1).withDayOfMonth(1).with(LocalTime.MIN); // 上个月1号0点0分0秒 // 上个月1号0点0分0秒
LocalDateTime lastMonthStart = now.minusMonths(1).withDayOfMonth(1).with(LocalTime.MIN);
// 上个月月末23点59分59秒
LocalDateTime lastMonthEnd = now.minusMonths(1).withDayOfMonth(now.minusMonths(1).toLocalDate().lengthOfMonth()) LocalDateTime lastMonthEnd = now.minusMonths(1).withDayOfMonth(now.minusMonths(1).toLocalDate().lengthOfMonth())
.with(LocalTime.MAX); // 上个月月末23点59分59秒 .with(LocalTime.MAX);
// 创建查询条件 // 创建查询条件
MoneyBillResult queryCondition = new MoneyBillResult(); MoneyBillResult queryCondition = new MoneyBillResult();
@ -44,38 +48,46 @@ public class MoneyBillQuartz {
// 执行查询 // 执行查询
List<MoneyBillResult> billResults = moneyBillMapper.selectMoneyBillList(queryCondition); List<MoneyBillResult> billResults = moneyBillMapper.selectMoneyBillList(queryCondition);
// 仅保留订单类型为 PuTong 或 DuanBoRu 的记录
billResults = billResults.stream()
.filter(r -> "PuTong".equals(r.getOrderCategory()) || "DuanBoRu".equals(r.getOrderCategory()))
.collect(Collectors.toList());
log.info("查询到上个月账单数据 {} 条", billResults.size()); log.info("查询到上个月账单数据 {} 条", billResults.size());
if (billResults.size() > 0) { if (!billResults.isEmpty()) {
// 先按transCompanyId分组再按originExpenseItemId分组 // 先按transCompanyId、originExpenseItemId、orderCategory三层分组区分不同订单类型如 DuanBoRu 与 PuTong
Map<Long, Map<Long, List<MoneyBillResult>>> groupedResults = billResults.stream() Map<Long, Map<Long, Map<String, List<MoneyBillResult>>>> groupedResults = billResults.stream()
.collect(Collectors.groupingBy( .collect(Collectors.groupingBy(
MoneyBillResult::getTransCompanyId, MoneyBillResult::getTransCompanyId,
Collectors.groupingBy(MoneyBillResult::getOriginExpenseItemId) Collectors.groupingBy(MoneyBillResult::getOriginExpenseItemId,
Collectors.groupingBy(MoneyBillResult::getOrderCategory))
)); ));
log.info("按transCompanyId和originExpenseItemId二级分组后共 {} 个公司分组", groupedResults.size()); log.info("按transCompanyId、originExpenseItemId和orderCategory三级分组后共 {} 个公司分组", groupedResults.size());
// 处理每个公司分组的数据 // 处理每个公司分组的数据
List<MoneyBillEntity> entityList = Lists.newArrayList(); List<MoneyBillEntity> entityList = Lists.newArrayList();
for (Map.Entry<Long, Map<Long, List<MoneyBillResult>>> companyEntry : groupedResults.entrySet()) { for (Map.Entry<Long, Map<Long, Map<String, List<MoneyBillResult>>>> companyEntry : groupedResults.entrySet()) {
Long transCompanyId = companyEntry.getKey(); Long transCompanyId = companyEntry.getKey();
Map<Long, List<MoneyBillResult>> companyGroupResults = companyEntry.getValue(); Map<Long, Map<String, List<MoneyBillResult>>> companyGroupResults = companyEntry.getValue();
log.info("transCompanyId: {}, 该公司包含 {} 个originExpenseItemId分组", log.info("transCompanyId: {}, 该公司包含 {} 个originExpenseItemId分组",
transCompanyId, companyGroupResults.size()); transCompanyId, companyGroupResults.size());
// 处理该公司下的每个originExpenseItemId分组 // 处理该公司下的每个originExpenseItemId分组
for (Map.Entry<Long, List<MoneyBillResult>> itemEntry : companyGroupResults.entrySet()) { for (Map.Entry<Long, Map<String, List<MoneyBillResult>>> itemEntry : companyGroupResults.entrySet()) {
Long originExpenseItemId = itemEntry.getKey(); Long originExpenseItemId = itemEntry.getKey();
List<MoneyBillResult> itemGroupResults = itemEntry.getValue(); Map<String, List<MoneyBillResult>> categoryGroupMap = itemEntry.getValue();
log.info("transCompanyId: {}, originExpenseItemId: {}, 该分组包含 {} 条数据", for (Map.Entry<String, List<MoneyBillResult>> categoryEntry : categoryGroupMap.entrySet()) {
transCompanyId, originExpenseItemId, itemGroupResults.size()); String orderCategoryStr = categoryEntry.getKey();
List<MoneyBillResult> itemGroupResults = categoryEntry.getValue();
// 这里可以根据业务需求处理每个分组的数据 log.info("transCompanyId: {}, originExpenseItemId: {}, orderCategory: {}, 该分组包含 {} 条数据",
// 例如计算总金额、创建MoneyBillEntity等 transCompanyId, originExpenseItemId, orderCategoryStr, itemGroupResults.size());
// 创建账单实体并计算汇总字段
MoneyBillEntity entity = new MoneyBillEntity(); MoneyBillEntity entity = new MoneyBillEntity();
entity.setStationId(transCompanyId); entity.setStationId(transCompanyId);
entity.setStartTime(lastMonthStart.toLocalDate()); entity.setStartTime(lastMonthStart.toLocalDate());
@ -114,9 +126,16 @@ public class MoneyBillQuartz {
MoneyBillResult firstResult = itemGroupResults.get(0); MoneyBillResult firstResult = itemGroupResults.get(0);
entity.setUserId(firstResult.getUserId()); entity.setUserId(firstResult.getUserId());
entity.setGoodsName(firstResult.getExpenseItemName()); entity.setGoodsName(firstResult.getExpenseItemName());
// 如果存在订单类型字符串,则直接设置(实体中为 String 类型)
if (orderCategoryStr != null) {
entity.setOrderCategory(orderCategoryStr);
}
entityList.add(entity); entityList.add(entity);
log.info("生成账单实体: transCompanyId={}, originExpenseItemId={}, 订单数={}, 总质量={}, 车数={}, 优惠金额={}, 账单金额={}", log.info("生成账单实体: transCompanyId={}, originExpenseItemId={}, orderCategory={}, 订单数={}, 总质量={}, 车数={}, 优惠金额={}, 账单金额={}",
transCompanyId, originExpenseItemId, orderCount, totalWeight, orderCount, totalDiscountMoney, totalSettleMoney); transCompanyId, originExpenseItemId, orderCategoryStr, orderCount, totalWeight, orderCount, totalDiscountMoney, totalSettleMoney);
}
} }
} }
// 账单入库 // 账单入库

View File

@ -7,7 +7,6 @@ import com.njzscloud.common.mp.support.PageParam;
import com.njzscloud.common.mp.support.PageResult; import com.njzscloud.common.mp.support.PageResult;
import com.njzscloud.common.security.util.SecurityUtil; import com.njzscloud.common.security.util.SecurityUtil;
import com.njzscloud.supervisory.biz.pojo.result.SearchCompanyResult; import com.njzscloud.supervisory.biz.pojo.result.SearchCompanyResult;
import com.njzscloud.supervisory.goods.contant.MoneyStrategy;
import com.njzscloud.supervisory.money.mapper.MoneyBillMapper; import com.njzscloud.supervisory.money.mapper.MoneyBillMapper;
import com.njzscloud.supervisory.money.pojo.entity.MoneyBillEntity; import com.njzscloud.supervisory.money.pojo.entity.MoneyBillEntity;
import com.njzscloud.supervisory.money.pojo.result.MoneyBillResult; import com.njzscloud.supervisory.money.pojo.result.MoneyBillResult;
@ -31,6 +30,7 @@ import java.util.Map;
/** /**
* *
* @author ljw
*/ */
@Slf4j @Slf4j
@Service @Service
@ -107,9 +107,10 @@ public class MoneyBillService extends ServiceImpl<MoneyBillMapper, MoneyBillEnti
queryCondition.setEndTime(endTime); queryCondition.setEndTime(endTime);
queryCondition.setOriginExpenseItemId(entity.getGoodsId()); queryCondition.setOriginExpenseItemId(entity.getGoodsId());
queryCondition.setTransCompanyId(entity.getStationId()); queryCondition.setTransCompanyId(entity.getStationId());
queryCondition.setOrderCategory(entity.getOrderCategory());
// 执行查询 // 执行查询
List<MoneyBillResult> billResults = baseMapper.selectMoneyBillList(queryCondition); List<MoneyBillResult> billResults = baseMapper.selectMoneyBillList(queryCondition);
if (null != billResults && billResults.size() > 0) { if (null != billResults && !billResults.isEmpty()) {
// 1. 订单数量通过orderId分组条数就是订单数 // 1. 订单数量通过orderId分组条数就是订单数
long orderCount = billResults.stream(). long orderCount = billResults.stream().
map(MoneyBillResult::getOrderId) map(MoneyBillResult::getOrderId)

View File

@ -27,7 +27,8 @@
u.nickname, u.nickname,
bc.company_name as companyName, bc.company_name as companyName,
mb.goods_name as goodsName, mb.goods_name as goodsName,
mb.car_count mb.car_count,
mb.order_category
FROM money_bill mb FROM money_bill mb
LEFT JOIN sys_user u ON mb.user_id = u.id LEFT JOIN sys_user u ON mb.user_id = u.id
LEFT JOIN biz_company bc ON mb.station_id = bc.id LEFT JOIN biz_company bc ON mb.station_id = bc.id
@ -59,6 +60,9 @@
<if test="entity.goodsName != null and entity.goodsName != ''"> <if test="entity.goodsName != null and entity.goodsName != ''">
AND mb.goods_name LIKE CONCAT('%', #{entity.goodsName}, '%') AND mb.goods_name LIKE CONCAT('%', #{entity.goodsName}, '%')
</if> </if>
<if test="entity.orderCategory != null">
AND mb.order_category = #{entity.orderCategory}
</if>
</where> </where>
ORDER BY mb.modify_time DESC ORDER BY mb.modify_time DESC
</select> </select>
@ -66,12 +70,16 @@
<select id="selectMoneyBillList" resultType="com.njzscloud.supervisory.money.pojo.result.MoneyBillResult"> <select id="selectMoneyBillList" resultType="com.njzscloud.supervisory.money.pojo.result.MoneyBillResult">
SELECT SELECT
oi.trans_company_id, oi.trans_company_id,
oi.order_category,
bc.user_id, bc.user_id,
bc.company_name, bc.company_name,
su.nickname, su.nickname,
oei.expense_item_name, oei.expense_item_name,
oei.money_strategy, oei.money_strategy,
oei.origin_expense_item_id, CASE
WHEN oei.expense_item_category = 'ChanPin' THEN gi.id
ELSE oei.origin_expense_item_id
END AS origin_expense_item_id,
oei.order_id, oei.order_id,
oei.discount_money, oei.discount_money,
oei.settle_money, oei.settle_money,
@ -79,6 +87,8 @@
FROM FROM
order_expense_items oei order_expense_items oei
LEFT JOIN order_info oi ON oi.id = oei.order_id LEFT JOIN order_info oi ON oi.id = oei.order_id
LEFT JOIN order_goods og on og.id = oi.goods_id
LEFT JOIN goods_info gi on gi.id = og.origin_goods_id
LEFT JOIN biz_company bc ON oi.trans_company_id = bc.id LEFT JOIN biz_company bc ON oi.trans_company_id = bc.id
LEFT JOIN sys_user su ON bc.user_id = su.id LEFT JOIN sys_user su ON bc.user_id = su.id
LEFT JOIN order_car_in_out ocio ON ocio.id = oi.car_in_out_id LEFT JOIN order_car_in_out ocio ON ocio.id = oi.car_in_out_id
@ -94,7 +104,10 @@
AND oi.trans_company_id = #{entity.transCompanyId} AND oi.trans_company_id = #{entity.transCompanyId}
</if> </if>
<if test="entity.originExpenseItemId != null"> <if test="entity.originExpenseItemId != null">
AND oei.origin_expense_item_id = #{entity.originExpenseItemId} AND (CASE WHEN oei.expense_item_category = 'ChanPin' THEN gi.id ELSE oei.origin_expense_item_id END) = #{entity.originExpenseItemId}
</if>
<if test="entity.orderCategory != null">
AND oi.order_category = #{entity.orderCategory}
</if> </if>
order by oei.create_time desc order by oei.create_time desc
</select> </select>