소스 검색

定时任务

ZeroLiYi 3 달 전
부모
커밋
e935fe981b

+ 3 - 3
unis-plugin/unis-plugin-biz/src/main/java/com/unis/financialSupervision/modular/fsstoragesubsidysettle/mapper/mapping/FsStorageSubsidySettleMapper.xml

@@ -10,7 +10,7 @@
10 10
             sum(ROUND(qmkc/10000, 2)) AS qmkc
11 11
         FROM
12 12
             depot_qh.data_kcgl_kcyjd_default
13
-        where pz!=7144 and nf=#{Year} and UnitID=#{orgId}
13
+        where pz!=7144 and nf=#{year} and UnitID=#{orgId}
14 14
         GROUP BY
15 15
             nf,
16 16
             UnitID
@@ -24,7 +24,7 @@
24 24
         FROM
25 25
             province_all.biz_pss_storage_empty_period a
26 26
         left join depot_qh.business_rp_report b on a.rp_report_id =b.id and plan_type=1
27
-        where a.org_id=#{orgId} and a.plan_year =#{Year} and a.rotation_status=1
27
+        where a.org_id=#{orgId} and a.plan_year =#{year} and a.rotation_status=1
28 28
         GROUP BY a.org_id
29 29
 
30 30
     </select>
@@ -36,7 +36,7 @@
36 36
             sum(ROUND(qmkc/10000, 2)) AS qmkc
37 37
         FROM
38 38
             depot_qh.data_kcgl_kcyjd_default
39
-        where pz=7144 and nf=#{Year}
39
+        where pz=7144 and nf=#{year}
40 40
         GROUP BY
41 41
             nf,
42 42
             UnitID

+ 90 - 21
unis-plugin/unis-plugin-biz/src/main/java/com/unis/financialSupervision/modular/fsstoragesubsidysettle/service/impl/FsStorageSubsidySettleServiceImpl.java

@@ -14,12 +14,14 @@ package com.unis.financialSupervision.modular.fsstoragesubsidysettle.service.imp
14 14
 
15 15
 import cn.hutool.core.bean.BeanUtil;
16 16
 import cn.hutool.core.collection.CollStreamUtil;
17
+import cn.hutool.core.date.DateUtil;
17 18
 import cn.hutool.core.util.NumberUtil;
18 19
 import cn.hutool.core.util.ObjectUtil;
19 20
 import cn.hutool.core.util.StrUtil;
20 21
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
21 22
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
22 23
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
24
+import com.qcloud.cos.utils.DateUtils;
23 25
 import com.unis.rotationPlan.info.modular.rpWarnThreshold.mapper.RpWarnThresholdMapper;
24 26
 import io.swagger.annotations.ApiModelProperty;
25 27
 import org.springframework.stereotype.Service;
@@ -39,6 +41,9 @@ import javax.annotation.Resource;
39 41
 import java.math.BigDecimal;
40 42
 import java.time.LocalDate;
41 43
 import java.time.LocalDateTime;
44
+import java.time.Year;
45
+import java.time.ZoneId;
46
+import java.util.Date;
42 47
 import java.util.List;
43 48
 import java.util.Map;
44 49
 
@@ -112,16 +117,23 @@ public class FsStorageSubsidySettleServiceImpl extends ServiceImpl<FsStorageSubs
112 117
     /**
113 118
      * 定时添加保管费用补贴清算表
114 119
      */
120
+    @Transactional
115 121
     @Override
116 122
     public void addFsStorageSubsidySettle() {
117 123
         int year = LocalDate.now().getYear();
124
+        Year PlayYear = Year.of(year);
118 125
 
119 126
         LocalDate today = LocalDate.now();
120 127
 
121 128
         // 获取当前月份
122 129
         int ys = today.getMonthValue();
130
+        QueryWrapper<FsStorageSubsidySettle> queryWrapper = new QueryWrapper<>();
131
+        queryWrapper.lambda().eq(FsStorageSubsidySettle::getPlanYear,PlayYear);
132
+        List<FsStorageSubsidySettle> subsidySettles = this.list(queryWrapper);
133
+         if(subsidySettles.size()>0){
134
+             this.removeByIds(subsidySettles);
135
+         }
123 136
         //查询data_kcgl_kcyjd_default单位
124
-
125 137
         List<Map<String, Object>> listOrg = fsStorageSubsidySettleMapper.selectOrgInfo();
126 138
 
127 139
         for (int i = 0; i < listOrg.size(); i++) {
@@ -136,6 +148,7 @@ public class FsStorageSubsidySettleServiceImpl extends ServiceImpl<FsStorageSubs
136 148
             BigDecimal averageRawGrainInventoryEmpty = new BigDecimal(0.0);/** 储备粮-原粮平均库存数量-平均正常轮空期内轮空数量 */
137 149
             BigDecimal averageRawGrainInventory = new BigDecimal(0.00);    /** 储备粮-原粮平均库存数量-小计 */
138 150
             BigDecimal averageRawGrainInventoryPhysical = new BigDecimal(0.0);/** 储备粮-原粮平均库存数量-平均月末实物库存 */
151
+
139 152
             List<Map<String, Object>> listyy = fsStorageSubsidySettleMapper.getOrgAndKcSum(year,orgId);
140 153
             for (int j = 0; j < listyy.size(); j++) {
141 154
                 Map<String, Object> map = listyy.get(j);
@@ -150,8 +163,9 @@ public class FsStorageSubsidySettleServiceImpl extends ServiceImpl<FsStorageSubs
150 163
                 if (ys != 0) {
151 164
                     averageRawGrainInventoryPhysical = qmkc.divide(BigDecimal.valueOf(ys), 2, BigDecimal.ROUND_HALF_UP);
152 165
                 }
166
+                averageRawGrainInventoryPhysical = (averageRawGrainInventoryPhysical != null) ? averageRawGrainInventoryPhysical :new BigDecimal(0.00) ;
153 167
 
154
-                fsStorageSubsidySettle.setAverageInventory(averageRawGrainInventoryPhysical); //平均月末实物库存
168
+                fsStorageSubsidySettle.setAverageRawGrainInventoryPhysical(averageRawGrainInventoryPhysical); //平均月末实物库存
155 169
 
156 170
                 //根据单位 和 日期 查询架空期
157 171
                 Map<String, Object> staetAndEnd = fsStorageSubsidySettleMapper.getStaetAndEnd(orgId, year);
@@ -163,12 +177,18 @@ public class FsStorageSubsidySettleServiceImpl extends ServiceImpl<FsStorageSubs
163 177
                 if (ys != 0) {
164 178
                     averageRawGrainInventoryEmpty = quantity.divide(BigDecimal.valueOf(ys), 2, BigDecimal.ROUND_HALF_UP);
165 179
                 }
180
+                averageRawGrainInventoryEmpty = (averageRawGrainInventoryEmpty != null) ? averageRawGrainInventoryEmpty :new BigDecimal(0.00) ;
181
+
166 182
                 fsStorageSubsidySettle.setAverageRawGrainInventoryEmpty(averageRawGrainInventoryEmpty);//平均正常轮空期内轮空数量
167 183
                 averageRawGrainInventory = averageRawGrainInventoryPhysical.add(averageRawGrainInventoryEmpty);
168
-                averageRawGrainInventory = averageRawGrainInventory.multiply(new BigDecimal("0.2"));
184
+               // averageRawGrainInventory = averageRawGrainInventory.multiply(new BigDecimal("0.2"));
185
+                fsStorageSubsidySettle.setAverageRawGrainInventory(averageRawGrainInventory);//(1)
186
+            }
187
+            if(listyy.isEmpty()){
188
+                fsStorageSubsidySettle.setAverageRawGrainInventoryPhysical(averageRawGrainInventoryPhysical);
189
+                fsStorageSubsidySettle.setAverageRawGrainInventoryEmpty(averageRawGrainInventoryEmpty);
169 190
                 fsStorageSubsidySettle.setAverageRawGrainInventory(averageRawGrainInventory);//(1)
170 191
             }
171
-
172 192
 
173 193
 
174 194
             /**
@@ -182,42 +202,75 @@ public class FsStorageSubsidySettleServiceImpl extends ServiceImpl<FsStorageSubs
182 202
             BigDecimal sjsysl = new BigDecimal(0.0);
183 203
             for (int j1 = 0; j1 < list1.size(); j1++) {
184 204
                 Map<String, Object> map1 = list1.get(j1);
185
-                LocalDateTime firstTime = (LocalDateTime) map1.getOrDefault("startTime", LocalDateTime.now()); //第一车出库时间
186
-                LocalDateTime firstDayOfNextMonth = firstTime.plusMonths(1).withDayOfMonth(1);
187
-                LocalDateTime futureDate = firstDayOfNextMonth.plusMonths(4);
188
-                LocalDateTime endTime = (LocalDateTime) map1.get("endTime");
189
-                if (endTime != null && endTime.isBefore(futureDate)) {
190
-                    BigDecimal wcsl = (BigDecimal) map1.getOrDefault("wcsl", BigDecimal.ZERO);
191
-                    sjlcsl = sjlcsl.add(wcsl);
192
-                    BigDecimal sysl = (BigDecimal) map1.getOrDefault("sysl", BigDecimal.ZERO);
193
-                    sjsysl = sjsysl.add(sysl);
205
+                Object startTimeObj = map1.get("startTime");
206
+                Date firstTime;
207
+                if (startTimeObj == null || startTimeObj.toString().isEmpty()) {
208
+                    firstTime = new Date(); // 设置默认值为当前日期
209
+                } else {
210
+                    firstTime = DateUtil.parseDate(startTimeObj.toString());
211
+                } // 第一车出库时间
212
+                Date endTime;
213
+                // 检查 firstTime 不为 null
214
+                if (firstTime != null) {
215
+                    LocalDateTime localDateTime = firstTime.toInstant()
216
+                            .atZone(ZoneId.systemDefault())
217
+                            .toLocalDateTime();
218
+                    LocalDateTime firstDayOfNextMonth = localDateTime.plusMonths(1).withDayOfMonth(1);
219
+                    LocalDateTime futureDate = firstDayOfNextMonth.plusMonths(4);
220
+                    Object endTimeObj = map1.get("endTime");
221
+                    if (endTimeObj == null || endTimeObj.toString().isEmpty()) {
222
+                        endTime = new Date(); // 设置默认值为当前日期
223
+                    } else {
224
+                        endTime = DateUtil.parseDate(endTimeObj.toString());
225
+                    }
226
+
227
+                    // 检查 endTime 不为 null
228
+                    if (endTime != null) {
229
+                        LocalDateTime endTime1 = endTime.toInstant()
230
+                                .atZone(ZoneId.systemDefault())
231
+                                .toLocalDateTime();
232
+
233
+                        // 先确保 endTime 不为 null,然后进行比较
234
+                        if (endTime1.isBefore(futureDate)) {
235
+                            BigDecimal wcsl = (BigDecimal) map1.getOrDefault("wcsl", BigDecimal.ZERO);
236
+                            sjlcsl = sjlcsl.add(wcsl);
237
+                            BigDecimal sysl = (BigDecimal) map1.getOrDefault("sysl", BigDecimal.ZERO);
238
+                            sjsysl = sjsysl.add(sysl);
239
+                        }
240
+                    }
194 241
                 }
195
-
196 242
             }
197 243
             if (ys != 0) {
198 244
                 averageProcessedGrainInventoryEmpty = sjlcsl.divide(BigDecimal.valueOf(ys), 2, BigDecimal.ROUND_HALF_UP);
199 245
             }
246
+            averageProcessedGrainInventoryEmpty = (averageProcessedGrainInventoryEmpty != null) ? averageProcessedGrainInventoryEmpty :new BigDecimal(0.00) ;
247
+
248
+
200 249
             fsStorageSubsidySettle.setAverageProcessedGrainInventoryEmpty(averageProcessedGrainInventoryEmpty);/** 储备粮-成品粮平均库存数量-平均正常轮空期内轮空数量 */
201 250
 
202 251
             BigDecimal averageProcessedGrainInventoryPhysical = new BigDecimal(0.0); /** 储备粮-成品粮平均库存数量-平均月末实物库存 */
203 252
             if (ys != 0) {
204 253
                 averageProcessedGrainInventoryPhysical = sjsysl.divide(BigDecimal.valueOf(ys), 2, BigDecimal.ROUND_HALF_UP);
205 254
             }
255
+            averageProcessedGrainInventoryPhysical = (averageProcessedGrainInventoryPhysical != null) ? averageProcessedGrainInventoryPhysical :new BigDecimal(0.00) ;
256
+
206 257
             fsStorageSubsidySettle.setAverageProcessedGrainInventoryPhysical(averageProcessedGrainInventoryPhysical);/** 储备粮-成品粮平均库存数量-平均月末实物库存 */
207 258
 
208 259
             BigDecimal averageProcessedGrainInventory = new BigDecimal(0.0);//(2)  /** 储备粮-成品粮平均库存数量-小计 */
260
+            averageProcessedGrainInventory=averageProcessedGrainInventoryPhysical.add(averageProcessedGrainInventory);
261
+            fsStorageSubsidySettle.setAverageProcessedGrainInventory(averageProcessedGrainInventory); /** (2)储备粮-成品粮平均库存数量-小计 */
209 262
 
210 263
 
211 264
             BigDecimal averageInventory = new BigDecimal(0.0);/** 储备粮平均库存数量 */
212
-            averageInventory = averageRawGrainInventory.add(averageProcessedGrainInventoryEmpty);
213
-            fsStorageSubsidySettle.setAverageOilInventory(averageInventory);//(1)+(2)
265
+            averageInventory = averageProcessedGrainInventory.add(averageRawGrainInventory);
266
+            fsStorageSubsidySettle.setAverageInventory(averageInventory);//(1)+(2)
214 267
 
215 268
             /**
216 269
              * 保管费用补贴
217 270
              */
218 271
             BigDecimal storageSubsidyStandardRawGrain = new BigDecimal(0.0);//(1) /** 储备粮-原粮保管费用补贴(标准:0.12元/公斤)应拨数 */
219 272
             storageSubsidyStandardRawGrain = averageRawGrainInventory.multiply(new BigDecimal("0.12"));//单位:万元
220
-            fsStorageSubsidySettle.setStorageSubsidyRawGrain(storageSubsidyStandardRawGrain);
273
+            fsStorageSubsidySettle.setStorageSubsidyStandardRawGrain(storageSubsidyStandardRawGrain);
221 274
 
222 275
             BigDecimal storageSubsidyProcessedGrain = new BigDecimal(0.0);/** 储备粮-成品粮保管费用补贴(标准:0.20元/公斤)应拨数 */
223 276
             storageSubsidyProcessedGrain = averageProcessedGrainInventory.multiply(new BigDecimal("0.20"));//单位:万元
@@ -233,6 +286,8 @@ public class FsStorageSubsidySettleServiceImpl extends ServiceImpl<FsStorageSubs
233 286
             BigDecimal averageOilInventoryPhysical = new BigDecimal(0.0);/** 储备油-储油平均库存数量-平均月末实物库存 */
234 287
             BigDecimal averageOilInventoryEmpty = new BigDecimal(0.0);/** 储备油-储油平均库存数量-平均正常轮空期内轮空数量 */
235 288
             BigDecimal averageOilInventory = new BigDecimal(0.0);/** 储备油-储油平均库存数量-小计 */
289
+
290
+            BigDecimal storageSubsidyOil = new BigDecimal(0.0);/** 储备油-油料保管费用补贴(标准:0.40元/公斤)应拨数 */
236 291
             List<Map<String, Object>> list2 = fsStorageSubsidySettleMapper.getOrgAndYlKcSum(year, orgId);
237 292
             for (int j2 = 0; j2< list2.size(); j2++) {
238 293
                 Map<String, Object> mapy = listyy.get(j2);
@@ -246,27 +301,41 @@ public class FsStorageSubsidySettleServiceImpl extends ServiceImpl<FsStorageSubs
246 301
                 if (ys != 0) {
247 302
                     averageOilInventoryPhysical = qmkc.divide(BigDecimal.valueOf(ys), 2, BigDecimal.ROUND_HALF_UP);
248 303
                 }
304
+                averageOilInventoryPhysical = (averageOilInventoryPhysical != null) ? averageOilInventoryPhysical :new BigDecimal(0.00) ;
249 305
 
250 306
                 fsStorageSubsidySettle.setAverageOilInventoryPhysical(averageOilInventoryPhysical); //平均月末实物库存
251 307
 
252 308
                 //根据单位 和 日期 查询架空期
253 309
                 Map<String, Object> staetAndEnd = fsStorageSubsidySettleMapper.getStaetAndEnd(orgId, year);
254
-                LocalDateTime startTime = (LocalDateTime) mapy.getOrDefault("rotationStart", LocalDateTime.now()); //开始时间
255
-                LocalDateTime endTime = (LocalDateTime) mapy.getOrDefault("rotationEnd", LocalDateTime.now()); //截至时间
310
+//                LocalDateTime startTime = (LocalDateTime) mapy.getOrDefault("rotationStart", LocalDateTime.now()); //开始时间
311
+//                LocalDateTime endTime = (LocalDateTime) mapy.getOrDefault("rotationEnd", LocalDateTime.now()); //截至时间
256 312
                 // 获取 quantity 的值,如果没有则默认为 0.0
257 313
                 BigDecimal quantity = NumberUtil.toBigDecimal(mapy.getOrDefault("quantity", "0.0").toString());
258 314
 
259 315
                 if (ys != 0) {
260 316
                     averageOilInventoryEmpty = quantity.divide(BigDecimal.valueOf(ys), 2, BigDecimal.ROUND_HALF_UP);
261 317
                 }
318
+                averageOilInventoryEmpty = (averageOilInventoryEmpty != null) ? averageOilInventoryEmpty :new BigDecimal(0.00) ;
319
+
262 320
                 fsStorageSubsidySettle.setAverageOilInventoryEmpty(averageOilInventoryEmpty);//平均正常轮空期内轮空数量
263 321
                 averageOilInventory = averageOilInventoryPhysical.add(averageOilInventoryEmpty);
322
+                fsStorageSubsidySettle.setAverageOilInventory(averageOilInventory);
264 323
 
265
-                BigDecimal storageSubsidyOil = new BigDecimal(0.0);/** 储备油-油料保管费用补贴(标准:0.40元/公斤)应拨数 */
266
-                storageSubsidyOil = averageOilInventory.multiply(new BigDecimal("0.2"));
324
+                storageSubsidyOil = averageOilInventory.multiply(new BigDecimal("0.4"));
267 325
                 fsStorageSubsidySettle.setStorageSubsidyOil(storageSubsidyOil);//(5)
268 326
 
327
+
328
+            }
329
+            if(list2.isEmpty()){
330
+                fsStorageSubsidySettle.setAverageOilInventoryPhysical(averageOilInventoryPhysical); //平均月末实物库存
331
+                fsStorageSubsidySettle.setAverageOilInventoryEmpty(averageOilInventoryEmpty);//平均正常轮空期内轮空数量
332
+                fsStorageSubsidySettle.setAverageOilInventory(averageOilInventory);
333
+                fsStorageSubsidySettle.setStorageSubsidyOil(storageSubsidyOil);//(5)
269 334
             }
335
+            fsStorageSubsidySettle.setOrgId(Integer.parseInt(orgId));
336
+
337
+
338
+            fsStorageSubsidySettle.setPlanYear(PlayYear);
270 339
             this.save(fsStorageSubsidySettle);
271 340
         }
272 341
 

+ 1 - 1
unis-plugin/unis-plugin-biz/src/main/java/com/unis/rotationPlan/info/modular/rpWarnThreshold/mapper/mapping/RpWarnThresholdMapper.xml

@@ -209,7 +209,7 @@
209 209
             depot_qh.business_pg_gops_plan
210 210
 
211 211
         WHERE
212
-            org_id=#{orgId} and YEAR(plan_year)=#{year} and plan_type=1
212
+            org_id=#{orgId} and YEAR(plan_start_time)=#{year} and plan_type=1
213 213
     </select>
214 214
 
215 215
 </mapper>