refactor(work): 优化订单相关服务层逻辑

- 修改数据库连接配置
- 优化客户排名查询和统计逻辑
- 修复订单价格计算相关问题
- 优化微信数据统计查询
This commit is contained in:
清晨
2025-04-18 17:41:14 +08:00
parent f9206bc3da
commit 2b0fe7d92a
5 changed files with 76 additions and 20 deletions

View File

@@ -50,12 +50,9 @@ spring:
url: jdbc:mysql://erp9.52o.site:13308/erp20241208?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true
username: erp20241208
password: a2aLeLYbzfZY4MZH
# url: jdbc:mysql://erp.52o.site:13306/erp20241128?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true
# username: erp20241128
# password: 74SenGey6GAKkFRx
# url: jdbc:mysql://erp.52o.site:13306/erp2024?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true
# username: erp2024
# password: h7DJsL8jF3WDz4JS
# url: jdbc:mysql://erp9.52o.site:13308/sjzxerp-test?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true
# username: sjzxerp-test
# password: EYpxAtdHmzHrTNGL
# 从库数据源
slave:
lazy: false

View File

@@ -53,9 +53,9 @@ spring:
url: jdbc:mysql://erp9.52o.site:13308/erp20241208?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true
username: erp20241208
password: a2aLeLYbzfZY4MZH
# url: jdbc:mysql://erp.52o.site:13306/erp20241128?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true
# username: erp20241128
# password: 74SenGey6GAKkFRx
# url: jdbc:mysql://erp9.52o.site:13308/sjzxerp-test?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true
# username: sjzxerp-test
# password: EYpxAtdHmzHrTNGL
# 从库数据源
slave:
lazy: false

View File

@@ -100,7 +100,26 @@ public class TpNewOrderServiceImpl extends MPJBaseServiceImpl<TpOrderMapper, TpO
}
private MPJLambdaWrapper<TpOrder> buildKHRankingMPJWrapper(OrderRankingBo bo) {
LoginUser loginUser = LoginHelper.getLoginUser();
MPJLambdaWrapper<TpOrder> lqw = new MPJLambdaWrapper<>();
if(bo.getDeptIds()!= null && bo.getDeptIds().size() > 0){
lqw.in(TpOrder::getDeptId,bo.getDeptIds());
}else {
int scope = getDataScope();
if(scope == 2){
List<Long> deptIds = getDeptIds();
lqw.in(TpOrder::getDeptId,deptIds);
}else if(scope == 3){
lqw.eq(TpOrder::getDeptId,loginUser.getDeptId());
}else if(scope == 4){
List<Long> deptIds = deptMapper.selectList(new LambdaQueryWrapper<SysDept>().like(SysDept::getAncestors, loginUser.getDeptId())).stream().map(SysDept::getDeptId).collect(Collectors.toList());
deptIds.add(loginUser.getDeptId());
lqw.in(TpOrder::getDeptId,deptIds);
}else if(scope == 5){
lqw.eq(TpOrder::getSid,loginUser.getUserId());
}
}
lqw.eq(StringUtils.isNotBlank(bo.getUserName()), TpClient::getCode, bo.getUserName());
lqw.eq(StringUtils.isNotBlank(bo.getRealName()), TpClient::getName, bo.getRealName());
lqw.between(bo.getStartTime() != null && bo.getEndTime() != null,
@@ -279,7 +298,15 @@ public class TpNewOrderServiceImpl extends MPJBaseServiceImpl<TpOrderMapper, TpO
*/
@Override
public OrderRankingSumVo khRankingListSum(OrderRankingBo bo) {
Long totalNum = clientMapper.selectCount(new LambdaQueryWrapper<TpClient>().eq(TpClient::getIsDel, 1));
// Long totalNum = clientMapper.selectCount(new LambdaQueryWrapper<TpClient>().eq(TpClient::getIsDel, 1));
// 统计下单客户数量(去重)
MPJLambdaWrapper<TpOrder> lqw = buildKHRankingMPJWrapper(bo)
.selectAs("count(t.sid)", OrderRankingSumVo::getTotalNum)
.leftJoin(TpClient.class, TpClient::getId, TpOrder::getKid)
.groupBy(TpOrder::getKid);
List<OrderRankingSumVo> list = baseMapper.selectJoinList(OrderRankingSumVo.class, lqw);
MPJLambdaWrapper<TpOrder> wrapper = buildKHRankingMPJWrapper(bo)
.selectAs("count(1)",OrderRankingSumVo::getTotalOrderNum)
.selectAs("sum(t.price)",OrderRankingSumVo::getTotalPerformance)
@@ -290,7 +317,7 @@ public class TpNewOrderServiceImpl extends MPJBaseServiceImpl<TpOrderMapper, TpO
// .ne(TpOrder::getPayState,1);
OrderRankingSumVo orderRankingSumVo = baseMapper.selectJoinOne(OrderRankingSumVo.class, wrapper);
orderRankingSumVo.setTotalNum(totalNum);
orderRankingSumVo.setTotalNum((long) list.size());
return orderRankingSumVo;
}

View File

@@ -775,7 +775,8 @@ public class TpOrderServiceImpl extends MPJBaseServiceImpl<TpOrderMapper,TpOrder
if(order.getGjPrice() != null || order.getGjPrice().compareTo(BigDecimal.ZERO) > 0){
order.setGpay(getGjPayPrice(order.getPrice(),newPayPrice,order.getGjPrice()));
}
order.setJsPayPrice(getJsPayPrice(order.getPrice(),newPayPrice,order.getPrice().subtract(order.getGjPrice()).subtract(order.getCdPrice())));
BigDecimal jsPayPrice = getJsPayPrice(order.getPrice(),newPayPrice,order.getPrice().subtract(order.getGjPrice()).subtract(order.getCdPrice()));
order.setJsPayPrice(getJsPay(jsPayPrice));
order.setState(2);
order.setPayPrice(newPayPrice);
BigDecimal endPrice = order.getPrice().subtract(newPayPrice);
@@ -863,7 +864,8 @@ public class TpOrderServiceImpl extends MPJBaseServiceImpl<TpOrderMapper,TpOrder
if(order.getGjPrice() != null || order.getGjPrice().compareTo(BigDecimal.ZERO) > 0){
order.setGpay(getGjPayPrice(order.getPrice(),payPrice,order.getGjPrice()));
}
order.setJsPayPrice(getJsPayPrice(order.getPrice(),payPrice,order.getPrice().subtract(order.getGjPrice()).subtract(order.getCdPrice())));
BigDecimal jsPayPrice = getJsPayPrice(order.getPrice(),payPrice,order.getPrice().subtract(order.getGjPrice()).subtract(order.getCdPrice()));
order.setJsPayPrice(getJsPay(jsPayPrice));
order.setPayPrice(payPrice);
return baseMapper.updateById(order);
@@ -911,7 +913,8 @@ public class TpOrderServiceImpl extends MPJBaseServiceImpl<TpOrderMapper,TpOrder
if(order.getGjPrice() != null || order.getGjPrice().compareTo(BigDecimal.ZERO) > 0){
order.setGpay(getGjPayPrice(order.getPrice(),order.getPayPrice(),order.getGjPrice()));
}
order.setJsPayPrice(getJsPayPrice(order.getPrice(),order.getPayPrice(),order.getPrice().subtract(order.getGjPrice()).subtract(price)));
BigDecimal jsPayPrice = getJsPayPrice(order.getPrice(),order.getPayPrice(),order.getPrice().subtract(order.getGjPrice()).subtract(price));
order.setJsPayPrice(getJsPay(jsPayPrice));
}
boolean res = saveOrderRecord(order.getId(),"订单拆单","订单:"+order.getOrderId()+"拆单成功!拆单金额:"+price,1,null);
if(!res){
@@ -954,7 +957,8 @@ public class TpOrderServiceImpl extends MPJBaseServiceImpl<TpOrderMapper,TpOrder
order.setGjPrice(price);
order.setJsPrice(order.getPrice().subtract(order.getCdPrice()).subtract(price));
order.setGpay(getGjPayPrice(order.getPrice(),order.getPayPrice(),price));
order.setJsPayPrice(getJsPayPrice(order.getPrice(),order.getPayPrice(),order.getPrice().subtract(order.getCdPrice()).subtract(price)));
BigDecimal jsPayPrice = getJsPayPrice(order.getPrice(),order.getPayPrice(),order.getPrice().subtract(order.getCdPrice()).subtract(price));
order.setJsPayPrice(getJsPay(jsPayPrice));
}else{
order.setGjPrice(price);
order.setJsPrice(order.getPrice().subtract(order.getCdPrice()).subtract(price));
@@ -1337,4 +1341,12 @@ public class TpOrderServiceImpl extends MPJBaseServiceImpl<TpOrderMapper,TpOrder
// 比较两个日期时间
return !inputLocalDateTime.isBefore(today9AM);
}
private static BigDecimal getJsPay(BigDecimal number){
// 定义除数和舍入模式
BigDecimal divisor = new BigDecimal("50");
RoundingMode mode = RoundingMode.DOWN;
// 计算逻辑
return number.divide(divisor, 0, mode).multiply(divisor);
}
}

View File

@@ -470,32 +470,52 @@ public class TpWechatServiceImpl implements ITpWechatService {
wechatSumVo.setCjdsSum(list.stream().count());
wechatSumVo.setCjzjeSum(list.stream().map(f -> f.getPrice()).reduce(BigDecimal.ZERO, BigDecimal::add));
QueryWrapper<TpOrder> lqwo = new QueryWrapper<>();
/*QueryWrapper<TpOrder> lqwo = new QueryWrapper<>();
lqwo.select("COUNT(DISTINCT kid) as count");
String idsStr = ids.stream().map(f -> f.toString()).collect(Collectors.joining(","));
lqwo.inSql("wid", idsStr);
Map<String, Object> result = orderMapper.selectMaps(lqwo).get(0);
Long cjkhSum = (Long) result.get("count");
wechatSumVo.setCjkhSum(cjkhSum);*/
QueryWrapper<TpOrder> lqwo = new QueryWrapper<>();
lqwo.select("COUNT(DISTINCT kid) as count");
lqwo.in("wid", ids);
Map<String, Object> result = orderMapper.selectMaps(lqwo).get(0);
Long cjkhSum = (Long) result.get("count");
wechatSumVo.setCjkhSum(cjkhSum);
}
LambdaQueryWrapper<TpWechatNum> lqw1 = new LambdaQueryWrapper<>();
/*LambdaQueryWrapper<TpWechatNum> lqw1 = new LambdaQueryWrapper<>();
lqw1.inSql(bo.getUid() != null,TpWechatNum::getWid,"SELECT id FROM tp_wechat as w WHERE w.is_del = 1 and w.uid = "+bo.getUid());
lqw1.geSql(TpWechatNum::getAddTime,"CONCAT( YEAR ( CURDATE()), '-01-01' )");
Long yearNum = wechatNumMapper.selectList(lqw1).stream().mapToLong(TpWechatNum::getNum).sum();*/
LambdaQueryWrapper<TpWechatNum> lqw1 = new LambdaQueryWrapper<>();
lqw1.in(TpWechatNum::getWid,ids);
lqw1.geSql(TpWechatNum::getAddTime,"CONCAT( YEAR ( CURRENT_DATE ()), '-01-01' )");
Long yearNum = wechatNumMapper.selectList(lqw1).stream().mapToLong(TpWechatNum::getNum).sum();
/*LambdaQueryWrapper<TpWechatNum> lqw2 = new LambdaQueryWrapper<>();
lqw2.inSql(bo.getUid() != null,TpWechatNum::getWid,"SELECT id FROM tp_wechat as w WHERE w.is_del = 1 and w.uid = "+bo.getUid());
lqw2.geSql(TpWechatNum::getAddTime,"CONCAT( YEAR ( CURRENT_DATE ()), '-', MONTH ( CURRENT_DATE ()), '-01' )");
Long monthNum = wechatNumMapper.selectList(lqw2).stream().mapToLong(TpWechatNum::getNum).sum();*/
LambdaQueryWrapper<TpWechatNum> lqw2 = new LambdaQueryWrapper<>();
lqw2.inSql(bo.getUid() != null,TpWechatNum::getWid,"SELECT id FROM tp_wechat as w WHERE w.is_del = 1 and w.uid = "+bo.getUid());
lqw2.in(TpWechatNum::getWid,ids);
lqw2.geSql(TpWechatNum::getAddTime,"CONCAT( YEAR ( CURRENT_DATE ()), '-', MONTH ( CURRENT_DATE ()), '-01' )");
Long monthNum = wechatNumMapper.selectList(lqw2).stream().mapToLong(TpWechatNum::getNum).sum();
LambdaQueryWrapper<TpWechatNum> lqw3 = new LambdaQueryWrapper<>();
/*LambdaQueryWrapper<TpWechatNum> lqw3 = new LambdaQueryWrapper<>();
lqw3.inSql(bo.getUid() != null,TpWechatNum::getWid,"SELECT id FROM tp_wechat as w WHERE w.is_del = 1 and w.uid = "+bo.getUid());
lqw3.geSql(TpWechatNum::getAddTime,"( CURDATE() - INTERVAL 1 DAY )");
Long dayNum = wechatNumMapper.selectList(lqw3).stream().mapToLong(TpWechatNum::getNum).sum();
Long dayNum = wechatNumMapper.selectList(lqw3).stream().mapToLong(TpWechatNum::getNum).sum();*/
LambdaQueryWrapper<TpWechatNum> lqw3 = new LambdaQueryWrapper<>();
lqw3.in(TpWechatNum::getWid,ids);
lqw3.geSql(TpWechatNum::getAddTime,"( CURDATE() - INTERVAL 1 DAY )");
Long dayNum = wechatNumMapper.selectList(lqw3).stream().mapToLong(TpWechatNum::getNum).sum();
wechatSumVo.setBnxzSum(yearNum);
wechatSumVo.setByxzSum(monthNum);