ソースを参照

类型转换精度问题修复

梁世豪 2 ヶ月 前
コミット
f83c52f557

+ 14 - 13
src/main/java/com/liang/controller/PrjPayplanController.java

@@ -129,14 +129,15 @@ public class PrjPayplanController extends BaseController {
129 129
         // 判断当前 合同下支付计划是否超额
130 130
         List<PrjPayplan> list = prjPayplanService.getPayPlanList(prjPayplan.getHt());
131 131
         // 使用 Stream 计算总和
132
-        Double je = 0.00 + prjPayplan.getZfje();
133
-        for (int i = 0; i<list.size();i++){
134
-            je = je + list.get(i).getZfje();
132
+        BigDecimal je = BigDecimal.ZERO;
133
+        for (int i = 0; i < list.size(); i++) {
134
+            BigDecimal currentZfje = BigDecimal.valueOf(list.get(i).getZfje());
135
+            je = je.add(currentZfje);
135 136
         }
136
-        BigDecimal jes = BigDecimal.valueOf(je);
137
-        jes = jes.setScale(3, BigDecimal.ROUND_HALF_UP);
137
+        je = je.setScale(3, BigDecimal.ROUND_HALF_UP);
138 138
         BigDecimal htjes = BigDecimal.valueOf(htje);
139
-        if (jes.compareTo(htjes) <= 0){
139
+
140
+        if (je.compareTo(htjes) <= 0){
140 141
             prjPayplan.setCjr(getSysUserId());
141 142
             int num = prjPayplanService.insert(prjPayplan);
142 143
             if (num > 0)
@@ -161,17 +162,17 @@ public class PrjPayplanController extends BaseController {
161 162
 
162 163
         //再次校验付款计划总金额
163 164
         Double count = 0.0;
164
-        for (int i = 0; i <prjPayplanList.size(); i++) {
165
-            count +=prjPayplanList.get(i).getZfje();
165
+        BigDecimal countBD = BigDecimal.ZERO;
166
+        for (int i = 0; i < prjPayplanList.size(); i++) {
167
+            BigDecimal currentZfje = BigDecimal.valueOf(prjPayplanList.get(i).getZfje());
168
+            countBD = countBD.add(currentZfje);
166 169
             Integer id = prjPayplanList.get(i).getId();
167 170
             if (id!=null){
168
-            prjPayplanUpdateList.add(prjPayplanList.get(i));
169
-            }else {
170
-            prjPayplanAddList.add(prjPayplanList.get(i));
171
+                prjPayplanUpdateList.add(prjPayplanList.get(i));
172
+            } else {
173
+                prjPayplanAddList.add(prjPayplanList.get(i));
171 174
             }
172
-
173 175
         }
174
-        BigDecimal countBD = BigDecimal.valueOf(count);
175 176
         BigDecimal htjeBD = BigDecimal.valueOf(htje);
176 177
         if (countBD.compareTo(htjeBD) == 0) {
177 178
             for (int i = 0; i < prjPayplanAddList.size(); i++) {

+ 3 - 2
src/main/java/com/liang/controller/PrjPayplanXgController.java

@@ -147,15 +147,16 @@ public class PrjPayplanXgController extends BaseController {
147 147
         prjPayplanXgService.deleteByHtId(ht);
148 148
         //再次校验付款计划总金额
149 149
         Double count = 0.0;
150
+        BigDecimal countBD = BigDecimal.ZERO;
150 151
         for (int i = 0; i <prjPayplanList.size(); i++) {
151
-            count +=prjPayplanList.get(i).getZfje();
152
+            BigDecimal currentZfje = BigDecimal.valueOf(prjPayplanList.get(i).getZfje());
153
+            countBD = countBD.add(currentZfje);
152 154
             Integer id = prjPayplanList.get(i).getId();
153 155
             if (id!=null){
154 156
                 prjPayplanList.get(i).setOldid(id);
155 157
             }
156 158
 
157 159
         }
158
-        BigDecimal countBD = BigDecimal.valueOf(count);
159 160
         BigDecimal htjeBD = BigDecimal.valueOf(htje);
160 161
         if (countBD.compareTo(htjeBD) == 0) {
161 162
             for (int i = 0; i < prjPayplanList.size(); i++) {

+ 11 - 7
src/main/resources/templates/prjcontract/update.html

@@ -1226,14 +1226,18 @@
1226 1226
                     contentType: "application/json",
1227 1227
                     data: JSON.stringify(prjPayplanList),
1228 1228
                     success: function (res) {
1229
-                        // layer.msg(res.message);
1230
-                        Message.success(res.message,1500)
1231
-                        layer.close(index);
1229
+                        if (res.code ==-1){
1230
+                            layer.close(index);
1231
+                            Message.warning(res.message,1500)
1232
+                        }else {
1233
+                            Message.success(res.message,1500)
1234
+                            layer.close(index);
1232 1235
 
1233
-                        var iframeIndex = parent.layer.getFrameIndex(window.name);
1234
-                        setTimeout(function() {
1235
-                            parent.layer.close(iframeIndex);
1236
-                        }, 1500);
1236
+                            var iframeIndex = parent.layer.getFrameIndex(window.name);
1237
+                            setTimeout(function() {
1238
+                                parent.layer.close(iframeIndex);
1239
+                            }, 1500);
1240
+                        }
1237 1241
                     },
1238 1242
                     error: function (error) {
1239 1243
                         Message.error(error.message, 1000);

+ 5 - 16
src/main/resources/templates/prjcontract/xg_update.html

@@ -207,8 +207,6 @@
207 207
         var spzt =xmApproval.spzt;
208 208
         var oldHtId = [[${htId}]]
209 209
         var contract = [[${contract}]]
210
-        var staPayapproval = [[${staPayapproval}]]
211
-        console.log(staPayapproval)
212 210
         //申请时间
213 211
         laydate.render({
214 212
             elem: '#kssj',
@@ -422,14 +420,6 @@
422 420
 
423 421
         // 监听确认按钮(常规)
424 422
         form.on('submit(saveBtn)', function (data) {
425
-            var xghtje = $("#htje").val();
426
-            var jhtje  = contract.htje;
427
-            if (xghtje != jhtje){
428
-                if (staPayapproval.length>0){
429
-                    layer.alert("该合同关联了"+staPayapproval.length+"笔付款申请,如需修改合同请先删除相关的付款申请!")
430
-                    return false;
431
-                }
432
-            }
433 423
             console.log(spList)
434 424
             console.log(spListId)
435 425
             //合同文件
@@ -464,7 +454,6 @@
464 454
             if (spList == false){
465 455
                 layer.confirm("该合同还存在未结束的审批流程,是否重新提交?",function (index) {
466 456
                     url = AjaxUtil.ctx + "prjContractXg/doAdd";
467
-                    // var index = layer.load(0, {shade: 0.1});
468 457
                     AjaxUtil.get({
469 458
                         url:AjaxUtil.ctx + 'prjApproverecord/updatSpList/'+spListId,
470 459
                         success:function (res) {
@@ -802,13 +791,17 @@
802 791
             var htje =parseFloat($("#htje").val())
803 792
             var prjPayplanList =[];
804 793
             var count = 0;
794
+            var sum = 0;
805 795
             if (!subTopics && subTopics.length === 0) {
806 796
                 Message.warning("请先创建付款计划!!!", 1500);
807 797
                 return;
808 798
             }
809 799
             for (let i = 0; i < subTopics.length; i++) {
810
-                count += parseFloat(subTopics[i].zfje) || 0;
800
+                let zfje = parseFloat(subTopics[i].zfje) || 0;
801
+                let scaledValue = (zfje * 100000).toFixed(8);
802
+                sum += parseFloat(scaledValue);
811 803
             }
804
+            count =sum/100000;
812 805
             for (const item of subTopics) {
813 806
                 var prjPayplan = {
814 807
                     "id":item.id,
@@ -840,10 +833,6 @@
840 833
                     success: function (res) {
841 834
                         layer.close(index);
842 835
                         Message.success(res.message,1500)
843
-                        // var iframeIndex = parent.layer.getFrameIndex(window.name);
844
-                        // setTimeout(function() {
845
-                        //     parent.layer.close(iframeIndex);
846
-                        // }, 1500);
847 836
                     },
848 837
                     error: function (error) {
849 838
                         Message.error(error.message, 1000);