Browse Source

日常物耗申请服务注册代码更新

fyz 9 months ago
parent
commit
285f6d56e5

+ 10 - 0
mjava-lanyun/src/main/java/com/malk/lanyun/controller/TimerController.java

@@ -106,6 +106,16 @@ public class TimerController {
         timerService.updateMaterialConsumption(formInstId,firstCost,nowCost);
     }
 
+    /**
+     * 日常物耗申请单中采购专员提交占用项目点月度物耗定额
+     * @param
+     */
+    @PostMapping("materialProject")
+    void updateMaterialProject(String projectCode,String date,Double firstCost,Double nowCost,int type){
+        log.info("进入更新字段初始物耗费用总计方法");
+        timerService.updateMaterialProject(projectCode,date,firstCost,nowCost,type);
+    }
+
     /**
      * 催款函
      */

+ 9 - 0
mjava-lanyun/src/main/java/com/malk/lanyun/service/TimerService.java

@@ -62,4 +62,13 @@ public interface TimerService {
      * @param data 实例ID或表单ID
      */
     void freshVersion(Map<String,Object> data);
+
+    /**
+     * 日常物耗申请单中采购专员提交占用项目点月度物耗定额
+     * @param projectCode 项目点编号
+     * @param date 日期文本
+     * @param firstCost 初始物耗费用合计
+     * @param nowCost 本次物耗
+     */
+    void updateMaterialProject(String projectCode, String date, Double firstCost, Double nowCost, int type);
 }

+ 34 - 35
mjava-lanyun/src/main/java/com/malk/lanyun/service/impl/SyncAssetsImpl.java

@@ -1,7 +1,6 @@
 package com.malk.lanyun.service.impl;
 
 import cn.hutool.core.date.DateBetween;
-import cn.hutool.core.date.DateTime;
 import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.util.ObjectUtil;
 import com.alibaba.fastjson.JSON;
@@ -19,9 +18,7 @@ import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
-import java.math.BigDecimal;
 import java.time.LocalDate;
-import java.time.LocalDateTime;
 import java.time.ZoneId;
 import java.time.chrono.ChronoLocalDate;
 import java.time.format.DateTimeFormatter;
@@ -60,43 +57,45 @@ public class SyncAssetsImpl implements SyncAssetsService {
             dataList = (List<Map>) ydClient.queryData(ydParam, YDConf.FORM_QUERY.retrieve_search_form).getData();
             dataList.forEach(dataItem -> {
                 Map formMap = (Map) dataItem.get("formData");
-                //净值
-                float metValue = UtilMap.getFloat((Map) formMap,"numberField_lu2ejqd4");
-                //月折旧额
-                float depreciation = UtilMap.getFloat((Map) formMap,"numberField_lu2eb47d");
-                //已计提期数
-                int count = UtilMap.getInt((Map) formMap,"numberField_lutjo2dt");
-                long toMonth = DateUtil.beginOfMonth(new Date()).getTime();
-                //购入日期
-                long buyTime = Long.parseLong(formMap.get("dateField_lty0oyv9").toString());
-                if (metValue>0 && depreciation>0){
-                    log.info("metValue:"+metValue);
-                    log.info("depreciation:"+depreciation);
-                    float updateDepreciation = (metValue - depreciation) >0 ? (metValue - depreciation) : 0;
-                    if (ObjectUtil.isNotEmpty(formMap.get("dateField_lty0oyva"))){
-                        //折旧截止日
-                        long endTime = Long.parseLong(formMap.get("dateField_lty0oyva").toString());
-                        String endDate = DateUtil.date(endTime).toString("yyyy-MM");
-                        long parseTime = DateUtil.beginOfMonth(DateUtil.parse(endDate, "yyyy-MM")).getTime();
-                        if (toMonth <= parseTime){
-                            count = count + 1;
+                //资产状态
+                String status = formMap.get("selectField_lty0oyvd").toString();
+                if (!"报废".equals(status)){
+
+                    //净值
+                    float metValue = UtilMap.getFloat((Map) formMap,"numberField_lu2ejqd4");
+                    //月折旧额
+                    float depreciation = UtilMap.getFloat((Map) formMap,"numberField_lu2eb47d");
+                    //已计提期数
+                    int count = UtilMap.getInt((Map) formMap,"numberField_lutjo2dt");
+                    long toMonth = DateUtil.beginOfMonth(new Date()).getTime();
+                    //购入日期
+                    long buyTime = Long.parseLong(formMap.get("dateField_lty0oyv9").toString());
+                    if (metValue > 0 && depreciation > 0 && buyTime < toMonth){
+                        log.info("metValue:"+metValue);
+                        log.info("depreciation:"+depreciation);
+                        float updateDepreciation = (metValue - depreciation) >0 ? (metValue - depreciation) : 0;
+                        if (ObjectUtil.isNotEmpty(formMap.get("dateField_lty0oyva"))){
+                            //折旧截止日
+                            long endTime = Long.parseLong(formMap.get("dateField_lty0oyva").toString());
+                            String endDate = DateUtil.date(endTime).toString("yyyy-MM");
+                            long parseTime = DateUtil.beginOfMonth(DateUtil.parse(endDate, "yyyy-MM")).getTime();
+                            if (toMonth <= parseTime){
+                                count = count + 1;
+                            }
                         }
+                        DateBetween dateBetween = new DateBetween(DateUtil.date(buyTime),DateUtil.date(toMonth));
+                        long months = dateBetween.betweenMonth(true);
+                        // 更新
+                        ydClient.operateData(YDParam.builder()
+                                .appType("APP_ERBDTFS82HOVBPL3NFH0")
+                                .systemToken("RRB66F91T97H1WN89QZYC47PKLZO2ZQOUMOQLP")
+                                .formInstanceId((String) dataItem.get("formInstanceId"))
+                                .updateFormDataJson(JSON.toJSONString(UtilMap.map("numberField_lu2ejqd4, numberField_lutjo2dt, numberField_m207nu7h",updateDepreciation,count,months)))
+                                .build(), YDConf.FORM_OPERATION.update);
                     }
-                    DateBetween dateBetween = new DateBetween(DateUtil.date(buyTime),DateUtil.date(toMonth));
-                    long months = dateBetween.betweenMonth(true);
-                    // 更新
-                    ydClient.operateData(YDParam.builder()
-                            .appType("APP_ERBDTFS82HOVBPL3NFH0")
-                            .systemToken("RRB66F91T97H1WN89QZYC47PKLZO2ZQOUMOQLP")
-                            .formInstanceId((String) dataItem.get("formInstanceId"))
-                            .updateFormDataJson(JSON.toJSONString(UtilMap.map("numberField_lu2ejqd4, numberField_lutjo2dt, numberField_m207nu7h",updateDepreciation,count,months)))
-                            .build(), YDConf.FORM_OPERATION.update);
                 }
-
-
             });
         }
-
     }
 
     @Autowired

+ 54 - 0
mjava-lanyun/src/main/java/com/malk/lanyun/service/impl/TimerServiceImpl.java

@@ -1,6 +1,7 @@
 package com.malk.lanyun.service.impl;
 
 import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.map.MapUtil;
 import cn.hutool.core.util.ObjectUtil;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
@@ -721,4 +722,57 @@ public class TimerServiceImpl implements TimerService {
             }
         }
     }
+
+    @Override
+    public void updateMaterialProject(String projectCode, String date, Double firstCost, Double nowCost, int type) {
+        double cost;
+        if(ObjectUtil.isEmpty(firstCost) || firstCost == 0.0){
+            cost = nowCost;
+        } else {
+            cost = firstCost;
+        }
+
+        List<Map> bigList = ydService.queryFormData_all(YDParam.builder()
+                .appType("APP_ERBDTFS82HOVBPL3NFH0")
+                .systemToken("RRB66F91T97H1WN89QZYC47PKLZO2ZQOUMOQLP")
+//                .formUuid("FORM-97BA6C6C8C50416A9E5854F2F4B5C3F3R4WC")
+                //测试档案
+                .formUuid("FORM-CE163643B967429CABA97CC8733E3B5B1RZZ")
+                .searchFieldJson(JSON.toJSONString(UtilMap.map("textField_ltxrn8h1", projectCode)))
+                .build());
+        bigList.forEach(e->{
+            List<Map> sonList = (List<Map>) e.get("tableField_lrru2tnq");
+            if (ObjectUtil.isNotEmpty(sonList)){
+                sonList.forEach(s->{
+                    //年月文本
+                    String projectDate = s.get("textField_luh0k82j").toString();
+                    //剩余物耗定额
+                    double remaining = Double.parseDouble(s.get("numberField_lrru2tnv").toString());
+                    //已用物耗定额
+                    double used = Double.parseDouble(s.get("numberField_ludujw4f").toString());
+                    log.info("cost:{}",cost);
+                    if (date.equals(projectDate)){
+                        if (type == 0){
+                            remaining = remaining - cost;
+                            s.put("numberField_lrru2tnv",remaining);
+                            used = used + cost;
+                            s.put("numberField_ludujw4f",used);
+                        } else if (type == 1) {
+                            remaining = remaining + cost - nowCost;
+                            s.put("numberField_lrru2tnv",remaining);
+                            used = used - cost + nowCost;
+                            s.put("numberField_ludujw4f",used);
+                        }
+                    }
+                });
+            }
+            ydClient.operateData(YDParam.builder()
+                    .appType("APP_ERBDTFS82HOVBPL3NFH0")
+                    .systemToken("RRB66F91T97H1WN89QZYC47PKLZO2ZQOUMOQLP")
+                    .formInstanceId(e.get("formInstanceId").toString())
+//                    .useLatestVersion(true)
+                    .updateFormDataJson(JSON.toJSONString(UtilMap.map("tableField_lrru2tnq", sonList)))
+                    .build(), YDConf.FORM_OPERATION.update);
+        });
+    }
 }