From 4d1a30da0ec4d37694baeb129a9a21aa29c157b7 Mon Sep 17 00:00:00 2001
From: Fancy <Fancy.fx@outlook.com>
Date: 星期四, 22 八月 2024 10:19:15 +0800
Subject: [PATCH] fix order complete Rate
---
pms-parent/pms-web-product/src/main/java/com/dy/pmsProduct/order/OrderSv.java | 56 +++++++++++++++---
pms-parent/pms-global/src/main/resources/mapper/PrOrderMapper.xml | 66 +++++++++++-----------
2 files changed, 80 insertions(+), 42 deletions(-)
diff --git a/pms-parent/pms-global/src/main/resources/mapper/PrOrderMapper.xml b/pms-parent/pms-global/src/main/resources/mapper/PrOrderMapper.xml
index 38ea656..705cb10 100644
--- a/pms-parent/pms-global/src/main/resources/mapper/PrOrderMapper.xml
+++ b/pms-parent/pms-global/src/main/resources/mapper/PrOrderMapper.xml
@@ -46,27 +46,27 @@
<include refid="Base_Column_List" />
from pr_order p
where p.deleted!=1
- <trim prefix="and " suffixOverrides="and">
+ <trim prefix="and" suffixOverrides="and">
<if test="name != null and name != ''">
- and name like concat('%', #{name}, '%')
+ name like concat('%', #{name}, '%') and
</if>
<if test="customerName != null and customerName != ''">
- and customer_name like concat('%', #{customerName}, '%')
+ customer_name like concat('%', #{customerName}, '%') and
</if>
<if test="projectName != null and projectName != ''">
- and project_name like concat('%', #{projectName}, '%')
+ project_name like concat('%', #{projectName}, '%') and
</if>
<if test="director != null and director != ''">
- and director like concat('%', #{director}, '%')
+ director like concat('%', #{director}, '%') and
</if>
- <if test="startDate != null">
- and delivery_date <![CDATA[ > ]]> #{startDate,jdbcType=VARCHAR}
+ <if test="startDate != null and startDate != ''">
+ delivery_date <![CDATA[ > ]]> #{startDate,jdbcType=VARCHAR} and
</if>
- <if test="endDate != null">
- and delivery_date <![CDATA[ < ]]> #{endDate,jdbcType=VARCHAR}
+ <if test="endDate != null and endDate != ''">
+ delivery_date <![CDATA[ < ]]> #{endDate,jdbcType=VARCHAR} and
</if>
- <if test="status != null">
- and status = #{status,jdbcType=TINYINT}
+ <if test="status != null and status != ''">
+ status = #{status,jdbcType=TINYINT} and
</if>
</trim>
order by id desc
@@ -81,27 +81,27 @@
select count(1)
from pr_order p
where p.deleted!=1
- <trim prefix="and " suffixOverrides="and">
+ <trim prefix="and" suffixOverrides="and">
<if test="name != null and name != ''">
- and name like concat('%', #{name}, '%')
+ name like concat('%', #{name}, '%') and
</if>
<if test="customerName != null and customerName != ''">
- and customer_name like concat('%', #{customerName}, '%')
+ customer_name like concat('%', #{customerName}, '%') and
</if>
<if test="projectName != null and projectName != ''">
- and project_name like concat('%', #{projectName}, '%')
+ project_name like concat('%', #{projectName}, '%') and
</if>
<if test="director != null and director != ''">
- and director like concat('%', #{director}, '%')
+ director like concat('%', #{director}, '%') and
</if>
- <if test="startDate != null">
- and delivery_date <![CDATA[ > ]]> #{startDate,jdbcType=VARCHAR}
+ <if test="startDate != null and startDate != ''">
+ delivery_date <![CDATA[ > ]]> #{startDate,jdbcType=VARCHAR} and
</if>
- <if test="endDate != null">
- and delivery_date <![CDATA[ < ]]> #{endDate,jdbcType=VARCHAR}
+ <if test="endDate != null and endDate != ''">
+ delivery_date <![CDATA[ < ]]> #{endDate,jdbcType=VARCHAR} and
</if>
- <if test="status != null">
- and status = #{status,jdbcType=TINYINT}
+ <if test="status != null and status != ''">
+ status = #{status,jdbcType=TINYINT} and
</if>
</trim>
</select>
@@ -110,27 +110,27 @@
<include refid="Base_Column_List" />
from pr_order p
where p.deleted!=1
- <trim prefix="and " suffixOverrides="and">
+ <trim prefix="and" suffixOverrides="and">
<if test="name != null and name != ''">
- and name like concat('%', #{name}, '%')
+ name like concat('%', #{name}, '%') and
</if>
<if test="customerName != null and customerName != ''">
- and customer_name like concat('%', #{customerName}, '%')
+ customer_name like concat('%', #{customerName}, '%') and
</if>
<if test="projectName != null and projectName != ''">
- and project_name like concat('%', #{projectName}, '%')
+ project_name like concat('%', #{projectName}, '%') and
</if>
<if test="director != null and director != ''">
- and director like concat('%', #{director}, '%')
+ director like concat('%', #{director}, '%') and
</if>
- <if test="startDate != null">
- and delivery_date <![CDATA[ > ]]> #{startDate,jdbcType=VARCHAR}
+ <if test="startDate != null and startDate != ''">
+ delivery_date <![CDATA[ > ]]> #{startDate,jdbcType=VARCHAR} and
</if>
- <if test="endDate != null">
- and delivery_date <![CDATA[ < ]]> #{endDate,jdbcType=VARCHAR}
+ <if test="endDate != null and endDate != ''">
+ delivery_date <![CDATA[ < ]]> #{endDate,jdbcType=VARCHAR} and
</if>
- <if test="status != null">
- and status = #{status,jdbcType=TINYINT}
+ <if test="status != null and status != ''">
+ status = #{status,jdbcType=TINYINT} and
</if>
</trim>
order by id desc
diff --git a/pms-parent/pms-web-product/src/main/java/com/dy/pmsProduct/order/OrderSv.java b/pms-parent/pms-web-product/src/main/java/com/dy/pmsProduct/order/OrderSv.java
index d0140b4..c50b240 100644
--- a/pms-parent/pms-web-product/src/main/java/com/dy/pmsProduct/order/OrderSv.java
+++ b/pms-parent/pms-web-product/src/main/java/com/dy/pmsProduct/order/OrderSv.java
@@ -19,6 +19,8 @@
import org.springframework.transaction.annotation.Transactional;
import java.io.IOException;
+import java.math.BigDecimal;
+import java.math.RoundingMode;
import java.util.List;
import java.util.Map;
@@ -32,6 +34,7 @@
private OthFileMapper othFileMapper;
@Value("${dy.webFile.fmUrl}")
private String fmUrl;
+
@Autowired
public void setOrderDao(PrOrderMapper orderDao) {
this.orderDao = orderDao;
@@ -66,29 +69,33 @@
}
p.setDeleted(false);
BaUser loginUser = userUtil.getUser(UserTokenContext.get());
- if(loginUser!=null){
+ if (loginUser != null) {
p.creator = loginUser.id;
}
int count = orderDao.insertSelective(p);
saveOrderItems(p);
return count;
}
+
@Transactional
public int update(PrOrder p) {
if (orderDao.exists(p.name, p.id)) {
throw new RuntimeException("璁㈠崟鍚嶇О涓嶈兘閲嶅");
}
int count = orderDao.updateByPrimaryKeySelective(p);
- saveOrderItems(p);
+ if (count > 0) {
+ saveOrderItems(p);
+ }
return count;
}
+
private void saveOrderItems(PrOrder p) {
- p.items.forEach(param->{
- param.orderId=p.id;
- if(param.id !=null){
+ p.items.forEach(param -> {
+ param.orderId = p.id;
+ if (param.id != null) {
orderItemDao.updateByPrimaryKeySelective(param);
- }else{
- param.deleted=false;
+ } else {
+ param.deleted = false;
orderItemDao.insert(param);
}
});
@@ -96,6 +103,7 @@
/**
* 閫昏緫鍒犻櫎瀹炰綋
+ *
* @param id 瀹炰綋ID
* @return 褰卞搷璁板綍鏁伴噺
*/
@@ -105,7 +113,7 @@
}
public PrOrder selectById(String proId) {
- PrOrder pro=orderDao.selectByPrimaryKey(Long.valueOf(proId));
+ PrOrder pro = orderDao.selectByPrimaryKey(Long.valueOf(proId));
return pro;
}
@@ -122,11 +130,41 @@
//璁$畻鍒嗛〉绛変俊鎭�
rsVo.calculateAndSet(itemTotal, params);
+ List<PrOrder> orderList = orderDao.selectSome(params);
+ for (PrOrder prOrder : orderList) {
+ changeRate(prOrder);
+ }
//鏌ヨ绗﹀悎鏉′欢鐨勮褰�
- rsVo.obj = orderDao.selectSome(params);
+ rsVo.obj = orderList;
return rsVo;
}
+ private void changeRate(PrOrder prOrder) {
+ List<PrOrderItem> items = prOrder.items;
+ for (int i = 1; i < items.size(); i++) {
+ for (int j = i - 1; j >= 0; j--) {
+ //鎷跨潃i渚濇璺熶笂涓�涓瘮杈�,濡傛灉浜у搧鐩稿悓,鍒欎笂涓�涓褰昪omplete_number - number 濡傛灉 > 0 鍒嗙粰i ,濡傛灉 < 0 鍒欏皢 complete_number 缃负0
+ if (items.get(j).getProId().intValue() == items.get(i).getProId().intValue()) {
+ int remainNumber = items.get(j).getCompleteNumber() - items.get(j).getNumber();
+ if (remainNumber > 0) {
+ items.get(j).setCompleteNumber(items.get(j).getNumber());
+ items.get(j).setCompleteRate("100.00%");
+ items.get(i).setCompleteNumber(remainNumber);
+ BigDecimal remainBig = new BigDecimal(remainNumber * 100);
+ BigDecimal iNumberBig = new BigDecimal(items.get(i).getNumber());
+ BigDecimal result = remainBig.divide(iNumberBig, 2, RoundingMode.HALF_UP);
+ items.get(i).setCompleteRate(result.toString() +"%");
+ }else{
+ items.get(i).setCompleteNumber(0);
+ items.get(i).setCompleteRate("0.00%");
+ }
+ break;
+ }
+ }
+ }
+ prOrder.setItems(items);
+ }
+
public List<PrOrder> selectAll(QueryVo queryVo) {
Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(queryVo);
return orderDao.selectAll(params);
--
Gitblit v1.8.0