Jelajahi Sumber

成本报表 保存

liuchaohui 2 tahun lalu
induk
melakukan
fcf4820622

+ 12 - 5
jeecg-boot-module-system/src/main/java/org/jeecg/modules/cost/controller/SyCostAllocationController.java

@@ -1,6 +1,5 @@
 package org.jeecg.modules.cost.controller;
 
-import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
@@ -8,6 +7,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.poi.ss.formula.functions.T;
 import org.apache.shiro.SecurityUtils;
 import org.jeecg.common.api.vo.Result;
 import org.jeecg.common.aspect.annotation.AutoLog;
@@ -25,6 +25,7 @@ import org.jeecgframework.poi.excel.entity.ImportParams;
 import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.validation.BindingResult;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 import org.springframework.web.multipart.MultipartHttpServletRequest;
@@ -190,10 +191,16 @@ public class SyCostAllocationController {
      */
     @AutoLog(value = "成本分配-添加")
     @PostMapping(value = "/add")
-    public Result<?> add(@RequestParam(name = "plannum", required = true) String plannum,
-                         @RequestParam(name = "json", required = true) JSONObject json) {
-        syCostAllocationService.saveMain(plannum, json);
-        return Result.OK("添加成功!");
+    public Result<?> add(@RequestBody SyCostAllocation json) {
+        if(json==null){
+            return Result.error("请不要保存无效单据!!!");
+        }
+        String planNum=json.getPlanNum();
+        if(null==planNum||planNum.equals("")){
+            return Result.error("单据计划号不能为空!!!");
+        }
+        Result<T> result = syCostAllocationService.saveMain(planNum, json);
+        return result;
     }
 
     @AutoLog(value = "成本分配-添加")

+ 5 - 1
jeecg-boot-module-system/src/main/java/org/jeecg/modules/cost/entity/SyCostJson.java

@@ -1,8 +1,11 @@
 package org.jeecg.modules.cost.entity;
 
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
+import com.baomidou.mybatisplus.extension.handlers.FastjsonTypeHandler;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
@@ -26,6 +29,7 @@ public class SyCostJson implements Serializable {
     private String planNum;
 
     @ApiModelProperty(value = "内容")
-    private String costInfo;
+    @TableField(typeHandler = FastjsonTypeHandler.class)
+    private JSONObject costInfo;
 
 }

+ 3 - 1
jeecg-boot-module-system/src/main/java/org/jeecg/modules/cost/service/ISyCostAllocationService.java

@@ -1,6 +1,8 @@
 package org.jeecg.modules.cost.service;
 
 import com.alibaba.fastjson.JSONObject;
+import org.apache.poi.ss.formula.functions.T;
+import org.jeecg.common.api.vo.Result;
 import org.jeecg.modules.cost.entity.SyCostAllocationAccident;
 import org.jeecg.modules.cost.entity.SyCostAllocationCostpay;
 import org.jeecg.modules.cost.entity.SyCostAllocationFabric;
@@ -25,7 +27,7 @@ public interface ISyCostAllocationService extends IService<SyCostAllocation> {
      *
      */
     //public void saveMain(SyCostAllocation syCostAllocation, List<SyCostAllocationAccident> syCostAllocationAccidentList, List<SyCostAllocationCostpay> syCostAllocationCostpayList, List<SyCostAllocationFabric> syCostAllocationFabricList, List<SyCostAllocationIngredient> syCostAllocationIngredientList, List<SyCostAllocationShipdetail> syCostAllocationShipdetailList) ;
-    public void saveMain(String plannum, JSONObject json);
+    public Result<T> saveMain(String plannum, SyCostAllocation json);
     /**
      * 修改一对多
      *

+ 24 - 48
jeecg-boot-module-system/src/main/java/org/jeecg/modules/cost/service/impl/SyCostAllocationServiceImpl.java

@@ -1,9 +1,13 @@
 package org.jeecg.modules.cost.service.impl;
 
+import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.Wrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.google.gson.JsonObject;
+import org.apache.poi.ss.formula.functions.T;
+import org.jeecg.common.api.vo.Result;
 import org.jeecg.common.exception.JeecgBootException;
 import org.jeecg.modules.cost.entity.*;
 import org.jeecg.modules.cost.mapper.*;
@@ -22,10 +26,7 @@ import springfox.documentation.spring.web.json.Json;
 
 import java.io.Serializable;
 import java.math.BigDecimal;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -67,53 +68,28 @@ public class SyCostAllocationServiceImpl extends ServiceImpl<SyCostAllocationMap
     private static ISenYuDataSourceOne senYuDataSourceOne;
     @Autowired
     private static ISenYuDataSourceThree senYuDataSourceThree;
-//    @Override
-//    @Transactional
-//    public void saveMain(SyCostAllocation syCostAllocation, List<SyCostAllocationAccident> syCostAllocationAccidentList,List<SyCostAllocationCostpay> syCostAllocationCostpayList,List<SyCostAllocationFabric> syCostAllocationFabricList,List<SyCostAllocationIngredient> syCostAllocationIngredientList,List<SyCostAllocationShipdetail> syCostAllocationShipdetailList) {
-//        syCostAllocationMapper.insert(syCostAllocation);
-//        for(SyCostAllocationAccident entity:syCostAllocationAccidentList) {
-//            //外键设置
-//            entity.setSyCostAllocationId(syCostAllocation.getId());
-//            syCostAllocationAccidentMapper.insert(entity);
-//        }
-//        for(SyCostAllocationCostpay entity:syCostAllocationCostpayList) {
-//            //外键设置
-//            entity.setSyCostAllocationId(syCostAllocation.getId());
-//            syCostAllocationCostpayMapper.insert(entity);
-//        }
-//        for(SyCostAllocationFabric entity:syCostAllocationFabricList) {
-//            //外键设置
-//            entity.setSyCostAllocationId(syCostAllocation.getId());
-//            syCostAllocationFabricMapper.insert(entity);
-//        }
-//        for(SyCostAllocationIngredient entity:syCostAllocationIngredientList) {
-//            //外键设置
-//            entity.setSyCostAllocationId(syCostAllocation.getId());
-//            syCostAllocationIngredientMapper.insert(entity);
-//        }
-//        for(SyCostAllocationShipdetail entity:syCostAllocationShipdetailList) {
-//            //外键设置
-//            entity.setSyCostAllocationId(syCostAllocation.getId());
-//            syCostAllocationShipdetailMapper.insert(entity);
-//        }
-//    }
-    //@Scheduled(cron = "0 43 16 * * ?")
-    public void saveMain(String plannum, JSONObject json) {
-        //方法1:后台使用string接受数据,数据库用json接受数据,但是这个添加字符串也会添加成功
-/*        String string = "{\"accidentUsdamount\": null,\"accidentcnyAmount\": null,\"actualShipquantity\": 25990,\"billstatus\": null,\"createBy\": null,\"createTime\": null,\"customerShortame\": \"PMK\",\"delFlag\": null,\"department\": \"业务四部\",\"excipiencostIncludestax\": 6654511.49,\"excipiencostNotincludestax\": 0,\"exportSales\": \"兰春梅\",\"fabriccostIncludestax\": null,\"fabriccostNotincludestax\": null,\"fabricshortcost\": null,\"garmentContractno\": \"AW22-PRIMARK-24583a\",\"id\": null,\"outdata\": \"2022-02-25 00:00:00\",\"pkOrg\": null,\"planNum\": \"\",\"planQuantity\": 25990,\"poStyleNum\": \"秋冬男童2B拼块网眼布polo衫\",\"preparedBy\": \"兰春梅\",\"processUnit\": \"FASHIONTEX APPAREL CO LTD\",\"processUnitList\": [1,2,3],\"remarks\": null,\"remarksTwo\": null,\"rmbExpense\": 1607.79,\"rmbExportamount\": 406950.35,\"rmbProcesscost\": 0,\"salesordersLocaltotal\": 387513.66,\"salesrrdersOriginaltotal\": 61045,\"shortseveral\": 0,\"shortvalue\": null,\"syCostAllocationAccidentList\": null,\"syCostAllocationCostpayList\": [{\"id\": null, \"syCostAllocationId\": null, \"createBy\": null, \"createTime\": null, \"updateBy\": null}],\"taxrate\": null,\"updateBy\": null,\"updateTime\": null,\"usdExpense\": 10754.34,\"usdProcesscost\": null,\"usdTotalexportprice\": 61045,\"success\": true,\"timestamp\": 1665641607070}";
-        JSONObject object = JSONObject
-                .parseObject(string);
-        String json = object.toJSONString();
-        SyCostJson cost = new SyCostJson();
-        cost.setPlanNum("测试");
-        cost.setCostInfo(json);
-        syCostJsonMapper.insert(cost);*/
 
-        String info = json.toJSONString();
+    public Result<T> saveMain(String plannum, SyCostAllocation json) {
+        Result<T> result = new Result<>();
+        //查询保存表中有没有当前单据 如果有 更新操作:删除旧单据并重新添加新单据
+        Map<String,Object> queryMap = new HashMap();
+        queryMap.put("plan_num",plannum);
+        List<SyCostJson> list = syCostJsonMapper.selectByMap(queryMap);
+        if(list.size()>0){
+            syCostJsonMapper.deleteByMap(queryMap);
+        }
+
+        JSONObject costJson = JSONObject.parseObject(JSON.toJSONString(json));
         SyCostJson cost = new SyCostJson();
         cost.setPlanNum(plannum);
-        cost.setCostInfo(info);
-        syCostJsonMapper.insert(cost);
+        cost.setCostInfo(costJson);
+        int i = syCostJsonMapper.insert(cost);
+        if(i==1){
+            result.setMessage("保存成功!!!");
+        }else{
+            result.setMessage("保存失败!!!");
+        }
+        return result;
     }
 
     @Override