mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-20 02:55:04 +08:00
update 更新数据接口
This commit is contained in:
@@ -201,4 +201,8 @@ public interface OrderBasicInfoMapper {
|
||||
* @return
|
||||
*/
|
||||
List<AccumulativeInfoVO> getAccumulativeInfoForLianLian(QueryStationInfoDTO dto);
|
||||
|
||||
List<OrderDetail> queryElecAmountNullList();
|
||||
|
||||
int batchUpdateOrderDetail(@Param("list") List<OrderDetail> orderDetailList);
|
||||
}
|
||||
|
||||
@@ -126,6 +126,8 @@ public interface IOrderBasicInfoService {
|
||||
|
||||
List<OrderVO> getListByMemberIdAndOrderStatus(String memberId, List<String> orderStatusList, LocalDateTime dateTime);
|
||||
|
||||
void updateElecAmount();
|
||||
|
||||
/**
|
||||
* 结算订单退款和用户余额退款调这个方法
|
||||
*/
|
||||
|
||||
@@ -3,6 +3,8 @@ package com.jsowell.pile.service.impl;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.jsowell.common.constant.CacheConstants;
|
||||
@@ -605,9 +607,8 @@ public class OrderBasicInfoServiceImpl implements IOrderBasicInfoService {
|
||||
|
||||
// 更新订单详情
|
||||
try {
|
||||
// 总电费金额,总服务费金额
|
||||
// 总电费金额
|
||||
BigDecimal totalElectricityAmount = BigDecimal.ZERO;
|
||||
BigDecimal totalServiceAmount = BigDecimal.ZERO;
|
||||
|
||||
// 尖时段用电量
|
||||
String sharpUsedElectricity = data.getSharpUsedElectricity();
|
||||
@@ -694,6 +695,74 @@ public class OrderBasicInfoServiceImpl implements IOrderBasicInfoService {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateElecAmount() {
|
||||
// 查询 elecAmount为空的订单数据
|
||||
int pageNum = 1;
|
||||
int pageSize = 10;
|
||||
|
||||
while (true) {
|
||||
// 分页处理
|
||||
PageHelper.startPage(pageNum, pageSize);
|
||||
List<OrderDetail> list = orderBasicInfoMapper.queryElecAmountNullList();
|
||||
PageInfo<OrderDetail> pageInfo = new PageInfo<>(list);
|
||||
if (CollectionUtils.isEmpty(pageInfo.getList())) {
|
||||
break;
|
||||
}
|
||||
|
||||
// 计算电量总金额
|
||||
List<OrderDetail> orderDetailList = calculateData(pageInfo.getList());
|
||||
|
||||
// 更新数据库
|
||||
orderBasicInfoMapper.batchUpdateOrderDetail(orderDetailList);
|
||||
}
|
||||
}
|
||||
|
||||
// 计算数据
|
||||
private List<OrderDetail> calculateData(List<OrderDetail> list) {
|
||||
for (OrderDetail orderDetail : list) {
|
||||
// 总电费金额
|
||||
BigDecimal totalElectricityAmount = BigDecimal.ZERO;
|
||||
|
||||
// 尖时段用电量
|
||||
BigDecimal sharpUsedElectricity = orderDetail.getSharpUsedElectricity();
|
||||
if (sharpUsedElectricity != null) {
|
||||
// 计算该时段电费
|
||||
BigDecimal multiply = orderDetail.getSharpElectricityPrice().multiply(sharpUsedElectricity).setScale(2,BigDecimal.ROUND_DOWN);
|
||||
totalElectricityAmount = totalElectricityAmount.add(multiply);
|
||||
}
|
||||
|
||||
// 峰时段用电量
|
||||
BigDecimal peakUsedElectricity = orderDetail.getPeakUsedElectricity();
|
||||
if (peakUsedElectricity != null) {
|
||||
// 计算该时段电费
|
||||
BigDecimal multiply = orderDetail.getPeakElectricityPrice().multiply(peakUsedElectricity).setScale(2,BigDecimal.ROUND_DOWN);
|
||||
totalElectricityAmount = totalElectricityAmount.add(multiply);
|
||||
}
|
||||
|
||||
|
||||
// 平时段用电量
|
||||
BigDecimal flatUsedElectricity = orderDetail.getFlatUsedElectricity();
|
||||
if (flatUsedElectricity != null) {
|
||||
// 计算该时段电费
|
||||
BigDecimal multiply = orderDetail.getFlatElectricityPrice().multiply(flatUsedElectricity).setScale(2,BigDecimal.ROUND_DOWN);
|
||||
totalElectricityAmount = totalElectricityAmount.add(multiply);
|
||||
}
|
||||
|
||||
// 谷时段用电量
|
||||
BigDecimal valleyUsedElectricity = orderDetail.getValleyUsedElectricity();
|
||||
if (valleyUsedElectricity != null) {
|
||||
// 计算该时段电费
|
||||
BigDecimal multiply = orderDetail.getValleyElectricityPrice().multiply(valleyUsedElectricity).setScale(2,BigDecimal.ROUND_DOWN);
|
||||
totalElectricityAmount = totalElectricityAmount.add(multiply);
|
||||
}
|
||||
|
||||
orderDetail.setTotalElectricityAmount(totalElectricityAmount);
|
||||
orderDetail.setTotalServiceAmount(orderDetail.getTotalOrderAmount().subtract(totalElectricityAmount));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 余额支付 计算需要退回的金额
|
||||
*
|
||||
|
||||
@@ -940,4 +940,38 @@
|
||||
AND t1.create_time <![CDATA[ <= ]]> #{endTime,jdbcType=VARCHAR}
|
||||
|
||||
</select>
|
||||
|
||||
<select id="queryElecAmountNullList" resultMap="OrderDetailResult">
|
||||
select
|
||||
<include refid="Detail_Base_Column_List"/>
|
||||
from order_detail
|
||||
where del_flag = '0'
|
||||
and total_order_amount is not null
|
||||
AND total_order_amount > '0.00'
|
||||
and total_electricity_amount is null
|
||||
</select>
|
||||
|
||||
<update id="batchUpdateOrderDetail">
|
||||
update order_detail
|
||||
<trim prefix="set" suffixOverrides=",">
|
||||
<trim prefix="total_electricity_amount =case" suffix="end,">
|
||||
<foreach collection="list" item="item" index="index">
|
||||
<if test="item.totalElectricityAmount!=null">
|
||||
when id=#{item.id} then #{item.totalElectricityAmount}
|
||||
</if>
|
||||
</foreach>
|
||||
</trim>
|
||||
<trim prefix="total_service_amount =case" suffix="end,">
|
||||
<foreach collection="list" item="item" index="index">
|
||||
<if test="item.totalServiceAmount!=null">
|
||||
when id=#{item.id} then #{item.totalServiceAmount}
|
||||
</if>
|
||||
</foreach>
|
||||
</trim>
|
||||
</trim>
|
||||
where
|
||||
<foreach collection="list" separator="or" item="i" index="index" >
|
||||
id=#{i.id}
|
||||
</foreach>
|
||||
</update>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user