Commit 2831d52fbcb46c8f48374806c17e6c177b8ac4d0
1 parent
8143bdf5
feat: 问题修复项
1、修改订单数量同时更新利润率
Showing
3 changed files
with
65 additions
and
59 deletions
src/main/java/com/order/erp/job/OrderJob.java
@@ -5,13 +5,11 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; | @@ -5,13 +5,11 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; | ||
5 | import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; | 5 | import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; |
6 | import com.order.erp.common.constant.Constant; | 6 | import com.order.erp.common.constant.Constant; |
7 | import com.order.erp.common.utils.DateUtils; | 7 | import com.order.erp.common.utils.DateUtils; |
8 | -import com.order.erp.common.utils.ProfitUtils; | ||
9 | import com.order.erp.common.utils.TransactionHelper; | 8 | import com.order.erp.common.utils.TransactionHelper; |
10 | import com.order.erp.domain.OrderStatusEnum; | 9 | import com.order.erp.domain.OrderStatusEnum; |
11 | import com.order.erp.domain.dto.BaseDO; | 10 | import com.order.erp.domain.dto.BaseDO; |
12 | import com.order.erp.domain.dto.order.*; | 11 | import com.order.erp.domain.dto.order.*; |
13 | import com.order.erp.domain.vo.order.OrderInfoResultVO; | 12 | import com.order.erp.domain.vo.order.OrderInfoResultVO; |
14 | -import com.order.erp.domain.vo.order.ProfitCalculateVO; | ||
15 | import com.order.erp.service.order.*; | 13 | import com.order.erp.service.order.*; |
16 | import lombok.extern.slf4j.Slf4j; | 14 | import lombok.extern.slf4j.Slf4j; |
17 | import org.joda.time.DateTime; | 15 | import org.joda.time.DateTime; |
@@ -19,10 +17,9 @@ import org.springframework.scheduling.annotation.Scheduled; | @@ -19,10 +17,9 @@ import org.springframework.scheduling.annotation.Scheduled; | ||
19 | import org.springframework.stereotype.Component; | 17 | import org.springframework.stereotype.Component; |
20 | 18 | ||
21 | import javax.annotation.Resource; | 19 | import javax.annotation.Resource; |
22 | -import java.math.BigDecimal; | ||
23 | -import java.math.RoundingMode; | ||
24 | -import java.util.*; | ||
25 | -import java.util.function.Function; | 20 | +import java.util.List; |
21 | +import java.util.Objects; | ||
22 | +import java.util.Set; | ||
26 | import java.util.stream.Collectors; | 23 | import java.util.stream.Collectors; |
27 | 24 | ||
28 | /** | 25 | /** |
@@ -105,59 +102,7 @@ public class OrderJob { | @@ -105,59 +102,7 @@ public class OrderJob { | ||
105 | // @Scheduled(cron = "*/5 * * * * ?") | 102 | // @Scheduled(cron = "*/5 * * * * ?") |
106 | public void checkChargeOrderCount() { | 103 | public void checkChargeOrderCount() { |
107 | log.info("执行开始时间:{}", DateTime.now().toString("yyyy-MM-dd HH:mm:ss")); | 104 | log.info("执行开始时间:{}", DateTime.now().toString("yyyy-MM-dd HH:mm:ss")); |
108 | - LambdaQueryWrapper<OrderBaseInfoDO> queryWrapper = new LambdaQueryWrapper<OrderBaseInfoDO>() | ||
109 | - .eq(BaseDO::getEnableFlag, Constant.ENABLE_TEN) | ||
110 | - .ge(OrderBaseInfoDO::getCreateTime, DateUtils.format(DateTime.now().minusMonths(Constant.TWO).toDate(), DateUtils.DATE_TIME)) | ||
111 | - .le(OrderBaseInfoDO::getCreateTime, DateUtils.format(DateTime.now().toDate(), DateUtils.DATE_TIME)) | ||
112 | - .ne(OrderBaseInfoDO::getOrderStatus, OrderStatusEnum.ORDER_FINISH.getStatus()); | ||
113 | - List<OrderBaseInfoDO> ordersDOS = orderBaseInfoService.list(queryWrapper); | ||
114 | - | ||
115 | - List<OrderInfoResultVO> orderInfoResultVOS = orderBaseInfoService.wrapperOrderResultList(false, ordersDOS); | ||
116 | - if (CollectionUtils.isNotEmpty(orderInfoResultVOS)) { | ||
117 | - Set<Long> orderIds = orderInfoResultVOS.stream().map(OrderInfoResultVO::getId).collect(Collectors.toSet()); | ||
118 | - if (CollectionUtils.isNotEmpty(orderIds)) { | ||
119 | - List<OrderProfitAnalysisDO> profitAnalysisDOS = profitAnalysisService.list(new LambdaQueryWrapper<OrderProfitAnalysisDO>() | ||
120 | - .eq(BaseDO::getEnableFlag, Constant.ENABLE_TEN) | ||
121 | - .in(OrderProfitAnalysisDO::getOrderId, orderIds)); | ||
122 | - | ||
123 | - Map<Long, OrderProfitAnalysisDO> profitAnalysisDOMap = new HashMap<>(); | ||
124 | - if (CollectionUtils.isNotEmpty(profitAnalysisDOS)) { | ||
125 | - profitAnalysisDOMap = profitAnalysisDOS.stream().collect(Collectors.toMap(OrderProfitAnalysisDO::getOrderId, Function.identity(), (x, y) -> y)); | ||
126 | - } | ||
127 | - | ||
128 | - for (OrderInfoResultVO resultVO : orderInfoResultVOS) { | ||
129 | - if (profitAnalysisDOMap.containsKey(resultVO.getId())) { | ||
130 | - OrderProfitAnalysisDO profitAnalysisDO = profitAnalysisDOMap.get(resultVO.getId()); | ||
131 | - Integer orderCount = resultVO.getOrderCount(); | ||
132 | - BigDecimal customerTotalPrice = new BigDecimal(profitAnalysisDO.getCustomerTotalPrice()).setScale(Constant.TWO, RoundingMode.HALF_UP); | ||
133 | - BigDecimal customerPrice = new BigDecimal(profitAnalysisDO.getCustomerPrice()).setScale(Constant.TWO, RoundingMode.HALF_UP); | ||
134 | - | ||
135 | - BigDecimal calculateTotalPrice = new BigDecimal(orderCount).multiply(customerPrice).setScale(Constant.TWO, RoundingMode.HALF_UP); | ||
136 | - if (customerTotalPrice.compareTo(calculateTotalPrice) != Constant.ZERO) { | ||
137 | - BigDecimal customerRmbPrice = new BigDecimal(profitAnalysisDO.getCustomerRmbPrice()); | ||
138 | - BigDecimal customerRmbTotalPrice = new BigDecimal(orderCount).multiply(customerRmbPrice).setScale(Constant.TWO, RoundingMode.HALF_UP); | ||
139 | - BigDecimal productionDepartmentPrice = new BigDecimal(profitAnalysisDO.getProductionDepartmentPrice()); | ||
140 | - BigDecimal productionDepartmentTotalPrice = new BigDecimal(orderCount).multiply(productionDepartmentPrice).setScale(Constant.TWO, RoundingMode.HALF_UP); | ||
141 | - BigDecimal packetPrice = new BigDecimal(profitAnalysisDO.getPacketPrice()); | ||
142 | - BigDecimal packetTotalPrice = new BigDecimal(orderCount).multiply(packetPrice).setScale(Constant.TWO, RoundingMode.HALF_UP); | ||
143 | - Double profitRate = ProfitUtils.calculateProfitRate(ProfitCalculateVO.builder() | ||
144 | - .exchangeRate(profitAnalysisDO.getExchangeRate()) | ||
145 | - .profitType(profitAnalysisDO.getProfitType()) | ||
146 | - .customerTotalPrice(calculateTotalPrice.doubleValue()) | ||
147 | - .productionDepartmentTotalPrice(productionDepartmentTotalPrice.doubleValue()) | ||
148 | - .packetTotalPrice(packetTotalPrice.doubleValue()).build()); | ||
149 | - | ||
150 | - profitAnalysisDO.setCustomerTotalPrice(calculateTotalPrice.doubleValue()); | ||
151 | - profitAnalysisDO.setCustomerRmbTotalPrice(customerRmbTotalPrice.doubleValue()); | ||
152 | - profitAnalysisDO.setProductionDepartmentTotalPrice(productionDepartmentTotalPrice.doubleValue()); | ||
153 | - profitAnalysisDO.setPacketTotalPrice(packetTotalPrice.doubleValue()); | ||
154 | - profitAnalysisDO.setProfitRate(profitRate); | ||
155 | - profitAnalysisService.updateById(profitAnalysisDO); | ||
156 | - } | ||
157 | - } | ||
158 | - } | ||
159 | - } | ||
160 | - } | 105 | +// orderBaseInfoService.checkChargeOrderCount(null); |
161 | log.info("执行结束时间:{}", DateTime.now().toString("yyyy-MM-dd HH:mm:ss")); | 106 | log.info("执行结束时间:{}", DateTime.now().toString("yyyy-MM-dd HH:mm:ss")); |
162 | } | 107 | } |
163 | 108 |
src/main/java/com/order/erp/service/order/OrderBaseInfoService.java
@@ -109,4 +109,6 @@ public interface OrderBaseInfoService extends IService<OrderBaseInfoDO> { | @@ -109,4 +109,6 @@ public interface OrderBaseInfoService extends IService<OrderBaseInfoDO> { | ||
109 | long countAll(); | 109 | long countAll(); |
110 | 110 | ||
111 | long countRecentYear(); | 111 | long countRecentYear(); |
112 | + | ||
113 | + ServerResult checkChargeOrderCount(List<Long> orderIds); | ||
112 | } | 114 | } |
src/main/java/com/order/erp/service/order/impl/OrderBaseInfoServiceImpl.java
@@ -35,6 +35,7 @@ import com.order.erp.service.SystemSettingService; | @@ -35,6 +35,7 @@ import com.order.erp.service.SystemSettingService; | ||
35 | import com.order.erp.service.admin.AdminUserService; | 35 | import com.order.erp.service.admin.AdminUserService; |
36 | import com.order.erp.service.order.*; | 36 | import com.order.erp.service.order.*; |
37 | import lombok.extern.slf4j.Slf4j; | 37 | import lombok.extern.slf4j.Slf4j; |
38 | +import org.joda.time.DateTime; | ||
38 | import org.springframework.beans.BeanUtils; | 39 | import org.springframework.beans.BeanUtils; |
39 | import org.springframework.beans.factory.annotation.Value; | 40 | import org.springframework.beans.factory.annotation.Value; |
40 | import org.springframework.stereotype.Service; | 41 | import org.springframework.stereotype.Service; |
@@ -45,6 +46,7 @@ import javax.servlet.http.HttpServletResponse; | @@ -45,6 +46,7 @@ import javax.servlet.http.HttpServletResponse; | ||
45 | import java.io.IOException; | 46 | import java.io.IOException; |
46 | import java.io.InputStream; | 47 | import java.io.InputStream; |
47 | import java.math.BigDecimal; | 48 | import java.math.BigDecimal; |
49 | +import java.math.RoundingMode; | ||
48 | import java.net.URL; | 50 | import java.net.URL; |
49 | import java.util.*; | 51 | import java.util.*; |
50 | import java.util.function.Function; | 52 | import java.util.function.Function; |
@@ -1796,6 +1798,7 @@ public class OrderBaseInfoServiceImpl extends ServiceImpl<OrderBaseInfoMapper, O | @@ -1796,6 +1798,7 @@ public class OrderBaseInfoServiceImpl extends ServiceImpl<OrderBaseInfoMapper, O | ||
1796 | } | 1798 | } |
1797 | if (Objects.nonNull(baseInfoVO.getOrderCount())) { | 1799 | if (Objects.nonNull(baseInfoVO.getOrderCount())) { |
1798 | baseInfoDO.setOrderCount(baseInfoVO.getOrderCount()); | 1800 | baseInfoDO.setOrderCount(baseInfoVO.getOrderCount()); |
1801 | + checkChargeOrderCount(Arrays.asList(baseInfoVO.getId())); | ||
1799 | } | 1802 | } |
1800 | if (StringUtils.isNotBlank(baseInfoVO.getOrderComposition())) { | 1803 | if (StringUtils.isNotBlank(baseInfoVO.getOrderComposition())) { |
1801 | baseInfoDO.setOrderComposition(baseInfoVO.getOrderComposition()); | 1804 | baseInfoDO.setOrderComposition(baseInfoVO.getOrderComposition()); |
@@ -1911,4 +1914,60 @@ public class OrderBaseInfoServiceImpl extends ServiceImpl<OrderBaseInfoMapper, O | @@ -1911,4 +1914,60 @@ public class OrderBaseInfoServiceImpl extends ServiceImpl<OrderBaseInfoMapper, O | ||
1911 | } | 1914 | } |
1912 | 1915 | ||
1913 | 1916 | ||
1917 | + @Override | ||
1918 | + public ServerResult checkChargeOrderCount(List<Long> ids) { | ||
1919 | + LambdaQueryWrapper<OrderBaseInfoDO> queryWrapper = new LambdaQueryWrapper<OrderBaseInfoDO>() | ||
1920 | + .eq(BaseDO::getEnableFlag, Constant.ENABLE_TEN) | ||
1921 | + .in(CollectionUtils.isNotEmpty(ids), OrderBaseInfoDO::getId, ids) | ||
1922 | + .ne(OrderBaseInfoDO::getOrderStatus, OrderStatusEnum.ORDER_FINISH.getStatus()); | ||
1923 | + List<OrderBaseInfoDO> ordersDOS = list(queryWrapper); | ||
1924 | + | ||
1925 | + List<OrderInfoResultVO> orderInfoResultVOS = wrapperOrderResultList(false, ordersDOS); | ||
1926 | + if (CollectionUtils.isNotEmpty(orderInfoResultVOS)) { | ||
1927 | + Set<Long> orderIds = orderInfoResultVOS.stream().map(OrderInfoResultVO::getId).collect(Collectors.toSet()); | ||
1928 | + if (CollectionUtils.isNotEmpty(orderIds)) { | ||
1929 | + List<OrderProfitAnalysisDO> profitAnalysisDOS = profitAnalysisService.list(new LambdaQueryWrapper<OrderProfitAnalysisDO>() | ||
1930 | + .eq(BaseDO::getEnableFlag, Constant.ENABLE_TEN) | ||
1931 | + .in(OrderProfitAnalysisDO::getOrderId, orderIds)); | ||
1932 | + | ||
1933 | + Map<Long, OrderProfitAnalysisDO> profitAnalysisDOMap = new HashMap<>(); | ||
1934 | + if (CollectionUtils.isNotEmpty(profitAnalysisDOS)) { | ||
1935 | + profitAnalysisDOMap = profitAnalysisDOS.stream().collect(Collectors.toMap(OrderProfitAnalysisDO::getOrderId, Function.identity(), (x, y) -> y)); | ||
1936 | + } | ||
1937 | + | ||
1938 | + for (OrderInfoResultVO resultVO : orderInfoResultVOS) { | ||
1939 | + if (profitAnalysisDOMap.containsKey(resultVO.getId())) { | ||
1940 | + OrderProfitAnalysisDO profitAnalysisDO = profitAnalysisDOMap.get(resultVO.getId()); | ||
1941 | + Integer orderCount = resultVO.getOrderCount(); | ||
1942 | + BigDecimal customerTotalPrice = new BigDecimal(profitAnalysisDO.getCustomerTotalPrice()).setScale(Constant.TWO, RoundingMode.HALF_UP); | ||
1943 | + BigDecimal customerPrice = new BigDecimal(profitAnalysisDO.getCustomerPrice()).setScale(Constant.TWO, RoundingMode.HALF_UP); | ||
1944 | + | ||
1945 | + BigDecimal calculateTotalPrice = new BigDecimal(orderCount).multiply(customerPrice).setScale(Constant.TWO, RoundingMode.HALF_UP); | ||
1946 | + if (customerTotalPrice.compareTo(calculateTotalPrice) != Constant.ZERO) { | ||
1947 | + BigDecimal customerRmbPrice = new BigDecimal(profitAnalysisDO.getCustomerRmbPrice()); | ||
1948 | + BigDecimal customerRmbTotalPrice = new BigDecimal(orderCount).multiply(customerRmbPrice).setScale(Constant.TWO, RoundingMode.HALF_UP); | ||
1949 | + BigDecimal productionDepartmentPrice = new BigDecimal(profitAnalysisDO.getProductionDepartmentPrice()); | ||
1950 | + BigDecimal productionDepartmentTotalPrice = new BigDecimal(orderCount).multiply(productionDepartmentPrice).setScale(Constant.TWO, RoundingMode.HALF_UP); | ||
1951 | + BigDecimal packetPrice = new BigDecimal(profitAnalysisDO.getPacketPrice()); | ||
1952 | + BigDecimal packetTotalPrice = new BigDecimal(orderCount).multiply(packetPrice).setScale(Constant.TWO, RoundingMode.HALF_UP); | ||
1953 | + Double profitRate = ProfitUtils.calculateProfitRate(ProfitCalculateVO.builder() | ||
1954 | + .exchangeRate(profitAnalysisDO.getExchangeRate()) | ||
1955 | + .profitType(profitAnalysisDO.getProfitType()) | ||
1956 | + .customerTotalPrice(calculateTotalPrice.doubleValue()) | ||
1957 | + .productionDepartmentTotalPrice(productionDepartmentTotalPrice.doubleValue()) | ||
1958 | + .packetTotalPrice(packetTotalPrice.doubleValue()).build()); | ||
1959 | + | ||
1960 | + profitAnalysisDO.setCustomerTotalPrice(calculateTotalPrice.doubleValue()); | ||
1961 | + profitAnalysisDO.setCustomerRmbTotalPrice(customerRmbTotalPrice.doubleValue()); | ||
1962 | + profitAnalysisDO.setProductionDepartmentTotalPrice(productionDepartmentTotalPrice.doubleValue()); | ||
1963 | + profitAnalysisDO.setPacketTotalPrice(packetTotalPrice.doubleValue()); | ||
1964 | + profitAnalysisDO.setProfitRate(profitRate); | ||
1965 | + profitAnalysisService.updateById(profitAnalysisDO); | ||
1966 | + } | ||
1967 | + } | ||
1968 | + } | ||
1969 | + } | ||
1970 | + } | ||
1971 | + return ServerResult.success(); | ||
1972 | + } | ||
1914 | } | 1973 | } |