|
|
@@ -1,26 +1,369 @@
|
|
|
package org.jeecg.modules.system.util;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.fasterxml.jackson.core.io.JsonStringEncoder;
|
|
|
+import com.google.gson.Gson;
|
|
|
+import com.google.gson.GsonBuilder;
|
|
|
+import org.apache.commons.lang.StringEscapeUtils;
|
|
|
+import org.jeecg.modules.openApi.service.ISenYuDataSourceOne;
|
|
|
+import org.jeecg.modules.openApi.service.ISenYuDataSourceThree;
|
|
|
+import org.jeecg.modules.openApi.service.ISenYuDataSourceTwo;
|
|
|
+import org.jeecg.modules.openApi.service.impl.SenYuDataSourceOneServiceImpl;
|
|
|
+import org.springframework.beans.BeansException;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.context.ApplicationContext;
|
|
|
+import org.springframework.context.ApplicationContextAware;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Set;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/***
|
|
|
* json转换类
|
|
|
* 赵万发
|
|
|
*/
|
|
|
-public class JsonChangeUtils{
|
|
|
+@Component
|
|
|
+public class JsonChangeUtils implements ApplicationContextAware{
|
|
|
+
|
|
|
+ private static ISenYuDataSourceOne senYuDataSourceOne;
|
|
|
+
|
|
|
+ private static ISenYuDataSourceTwo senYuDataSourceTwo;
|
|
|
+
|
|
|
+ private static ISenYuDataSourceThree iSenYuDataSourceThree;
|
|
|
|
|
|
/**
|
|
|
- * 数据库查询返回集合转换为json对象集合
|
|
|
+ * 原始通用转JSON方法
|
|
|
+ * @param result
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static List<JSONObject> toJSONObject (List<Map<String, Object>> result){
|
|
|
+ List<JSONObject> pljf = new ArrayList<JSONObject>();// 表数据json集合
|
|
|
+ JSONObject jf = new JSONObject();
|
|
|
+ for (int i = 0; i < result.size(); i++) {
|
|
|
+ Map<String, Object> map = result.get(i);
|
|
|
+ Set<String> keys = map.keySet();
|
|
|
+ jf = new JSONObject();
|
|
|
+ for (String key : keys) {
|
|
|
+ if(null==map.get(key)){
|
|
|
+ jf.put(key, "");
|
|
|
+ }else{
|
|
|
+ jf.put(key, map.get(key));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ pljf.add(jf);
|
|
|
+ }
|
|
|
+ return pljf;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 委外订单转JSON
|
|
|
+ * @param result
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static List<JSONObject> toMoMainJson(Map<String, Object> result) {
|
|
|
+ List<JSONObject> pljf = new ArrayList<JSONObject>();// 表数据json集合
|
|
|
+ SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ JSONObject jf = new JSONObject();
|
|
|
+ // for (int i = 0; i < result.size(); i++) {
|
|
|
+ Map<String, Object> map = result;//.get(i);
|
|
|
+ Set<String> keys = map.keySet();
|
|
|
+ jf = new JSONObject();
|
|
|
+ for (String key : keys) {
|
|
|
+ if(null==map.get(key)){
|
|
|
+ jf.put(key, "");
|
|
|
+ }else{
|
|
|
+ jf.put(key, map.get(key));
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(oConvertUtils.isNotEmpty(map.get("customerDemandDate"))){
|
|
|
+ String customerDemandDate = sf.format(map.get("customerDemandDate"));
|
|
|
+ jf.put("customerDemandDate",customerDemandDate+" 00:00:00");
|
|
|
+ }
|
|
|
+ if(oConvertUtils.isNotEmpty(map.get("publishDate"))){
|
|
|
+ String publishDate = sf.format(map.get("publishDate"));
|
|
|
+ jf.put("publishDate",publishDate+" 00:00:00");
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ //查询子表信息
|
|
|
+ if(map.get("pkorg").equals("one")){
|
|
|
+ BigDecimal totalAmount = BigDecimal.ZERO; //总金额
|
|
|
+ BigDecimal exTaxAmount = BigDecimal.ZERO;//总无税金额
|
|
|
+ String sql = "select mo.iVouchRowNo as 'poLineNum',mo.MODetailsID as MODetailsID,mo.MODetailsID as 'moDetailId','"+map.get("pkorg")+"' as pkorg," +
|
|
|
+ "'' as receivingInventoryOrgCode,'"+map.get("moId")+"' as MOID,'"+map.get("accId")+"' as 'accId'," +
|
|
|
+ "'"+map.get("poNum")+"' as poNum,mo.cInvCode as 'customerItemCode',inv.cInvName as 'itemName',mo.dArriveDate as 'customerDemandDate', " +
|
|
|
+ "'' as 'poLineStatus',mo.cFree1 as cFree1,mo.cFree2 as cFree2,mo.cFree3 as cFree3,mo.cFree4 as cFree4," +
|
|
|
+ "mo.cFree5 as cFree5,mo.cFree6 as cFree6,mo.cFree7 as cFree7,mo.cFree8 as cFree8,mo.cFree9 as cFree9,mo.cFree10 as cFree10,mo.iQuantity as 'customerDemandQty',mo.cUnitID as 'customerUomCode'," +
|
|
|
+ "mo.iMoney as 'iMoney'," +
|
|
|
+ "mo.iTax as lineAttributeDecimal1,mo.dbCloseDate as lineAttributeDatetime1,mo.cDefine24 as lineAttributeString9," +
|
|
|
+ "mo.iTaxPrice as 'customerPrice',(mo.iPerTaxRate/100) as 'lineTaxRate',mo.iSum as 'amount',ex.cbdefine2 as lineAttributeString7,ex.cbdefine3 as lineAttributeString8," +
|
|
|
+ "mo.cDefine28 as 'lineAttributeString1',mo.cDefine32 as 'lineAttributeString2',mo.cDefine29 as 'lineAttributeString3'," +
|
|
|
+ "mo.cDefine30 as 'lineAttributeString4',mo.cbMemo as 'lineAttributeString5',mo.cDefine22 as lineAttributeString6,'' as lineAttributeString7,'' as lineAttributeString8," +
|
|
|
+ "cFree1 as 'color','' as 'customerNumber',mo.iUnitPrice as supplierExTaxPrice,'"+map.get("dVerifyDate")+"' as lineAttributeDatetime2," +
|
|
|
+ "'' as externalLineNum,'' as itemAttrId,'"+map.get("moId")+"' as poId from OM_MODetails mo " +
|
|
|
+ "left join Inventory inv on mo.cInvCode = inv.cInvCode "+
|
|
|
+ "left join OM_MOdetails_extradefine ex on mo.MODetailsID = ex.MODetailsID "+
|
|
|
+ " where mo.MOID = "+map.get("moId");
|
|
|
+ List<Map<String, Object>> list = senYuDataSourceOne.queryForList(sql);
|
|
|
+ for(Map<String, Object> mapList:list){
|
|
|
+ totalAmount = totalAmount.add(new BigDecimal(mapList.get("amount").toString()));
|
|
|
+ exTaxAmount = exTaxAmount.add(new BigDecimal(mapList.get("iMoney").toString()));
|
|
|
+ }
|
|
|
+ //子表转JSON
|
|
|
+ List<JSONObject> json = toMOListJson(list);
|
|
|
+ jf.put("poLineList",json);
|
|
|
+ jf.put("totalAmount",totalAmount);
|
|
|
+ jf.put("exTaxAmount",exTaxAmount);
|
|
|
+ }else if(map.get("pkorg").equals("two")){
|
|
|
+ BigDecimal totalAmount = BigDecimal.ZERO; //总金额
|
|
|
+ BigDecimal exTaxAmount = BigDecimal.ZERO;//总无税金额
|
|
|
+ String sql = "select mo.iVouchRowNo as 'poLineNum',mo.MODetailsID as MODetailsID,mo.MODetailsID as 'moDetailId','"+map.get("pkorg")+"' as pkorg," +
|
|
|
+ "'' as receivingInventoryOrgCode,'"+map.get("moId")+"' as MOID,'"+map.get("accId")+"' as 'accId'," +
|
|
|
+ "'"+map.get("poNum")+"' as poNum,mo.cInvCode as 'customerItemCode',inv.cInvName as 'itemName',mo.dArriveDate as 'customerDemandDate', " +
|
|
|
+ "'' as 'poLineStatus',mo.cFree1 as cFree1,mo.cFree2 as cFree2,mo.cFree3 as cFree3,mo.cFree4 as cFree4," +
|
|
|
+ "mo.cFree5 as cFree5,mo.cFree6 as cFree6,mo.cFree7 as cFree7,mo.cFree8 as cFree8,mo.cFree9 as cFree9,mo.cFree10 as cFree10,mo.iQuantity as 'customerDemandQty',mo.cUnitID as 'customerUomCode'," +
|
|
|
+ "mo.iMoney as 'iMoney'," +
|
|
|
+ "mo.iTax as lineAttributeDecimal1,mo.dbCloseDate as lineAttributeDatetime1,mo.cDefine24 as lineAttributeString9," +
|
|
|
+ "mo.iTaxPrice as 'customerPrice',(mo.iPerTaxRate/100) as 'lineTaxRate',mo.iSum as 'amount',ex.cbdefine2 as lineAttributeString7,ex.cbdefine3 as lineAttributeString8," +
|
|
|
+ "mo.cDefine28 as 'lineAttributeString1',mo.cDefine32 as 'lineAttributeString2',mo.cDefine29 as 'lineAttributeString3'," +
|
|
|
+ "mo.cDefine30 as 'lineAttributeString4',mo.cbMemo as 'lineAttributeString5',mo.cDefine22 as lineAttributeString6,'' as lineAttributeString7,'' as lineAttributeString8," +
|
|
|
+ "cFree1 as 'color','' as 'customerNumber',mo.iUnitPrice as supplierExTaxPrice,'"+map.get("dVerifyDate")+"' as lineAttributeDatetime2," +
|
|
|
+ "'' as externalLineNum,'' as itemAttrId,'"+map.get("moId")+"' as poId from OM_MODetails mo " +
|
|
|
+ "left join Inventory inv on mo.cInvCode = inv.cInvCode "+
|
|
|
+ "left join OM_MOdetails_extradefine ex on mo.MODetailsID = ex.MODetailsID "+
|
|
|
+ " where mo.MOID = "+map.get("moId");
|
|
|
+ List<Map<String, Object>> list = senYuDataSourceTwo.queryForList(sql);
|
|
|
+ for(Map<String, Object> mapList:list){
|
|
|
+ totalAmount = totalAmount.add(new BigDecimal(mapList.get("amount").toString()));
|
|
|
+ exTaxAmount = exTaxAmount.add(new BigDecimal(mapList.get("iMoney").toString()));
|
|
|
+ }
|
|
|
+ //子表转JSON
|
|
|
+ List<JSONObject> json = toMOListJson(list);
|
|
|
+ jf.put("poLineList",json);
|
|
|
+ jf.put("totalAmount",totalAmount);
|
|
|
+ jf.put("exTaxAmount",exTaxAmount);
|
|
|
+ }else if(map.get("pkorg").equals("three")){
|
|
|
+ BigDecimal totalAmount = BigDecimal.ZERO; //总金额
|
|
|
+ BigDecimal exTaxAmount = BigDecimal.ZERO;//总无税金额
|
|
|
+ String sql = "select mo.iVouchRowNo as 'poLineNum',mo.MODetailsID as MODetailsID,mo.MODetailsID as 'moDetailId','"+map.get("pkorg")+"' as pkorg," +
|
|
|
+ "'' as receivingInventoryOrgCode,'"+map.get("moId")+"' as MOID,'"+map.get("accId")+"' as 'accId'," +
|
|
|
+ "'"+map.get("poNum")+"' as poNum,mo.cInvCode as 'customerItemCode',inv.cInvName as 'itemName',mo.dArriveDate as 'customerDemandDate', " +
|
|
|
+ "'' as 'poLineStatus',mo.cFree1 as cFree1,mo.cFree2 as cFree2,mo.cFree3 as cFree3,mo.cFree4 as cFree4," +
|
|
|
+ "mo.cFree5 as cFree5,mo.cFree6 as cFree6,mo.cFree7 as cFree7,mo.cFree8 as cFree8,mo.cFree9 as cFree9,mo.cFree10 as cFree10,mo.iQuantity as 'customerDemandQty',mo.cUnitID as 'customerUomCode'," +
|
|
|
+ "mo.iMoney as 'iMoney'," +
|
|
|
+ "mo.iTax as lineAttributeDecimal1,mo.dbCloseDate as lineAttributeDatetime1,mo.cDefine24 as lineAttributeString9," +
|
|
|
+ "mo.iTaxPrice as 'customerPrice',(mo.iPerTaxRate/100) as 'lineTaxRate',mo.iSum as 'amount',ex.cbdefine2 as lineAttributeString7,ex.cbdefine3 as lineAttributeString8," +
|
|
|
+ "mo.cDefine28 as 'lineAttributeString1',mo.cDefine32 as 'lineAttributeString2',mo.cDefine29 as 'lineAttributeString3'," +
|
|
|
+ "mo.cDefine30 as 'lineAttributeString4',mo.cbMemo as 'lineAttributeString5',mo.cDefine22 as lineAttributeString6,'' as lineAttributeString7,'' as lineAttributeString8," +
|
|
|
+ "cFree1 as 'color','' as 'customerNumber',mo.iUnitPrice as supplierExTaxPrice,'"+map.get("dVerifyDate")+"' as lineAttributeDatetime2," +
|
|
|
+ "'' as externalLineNum,'' as itemAttrId,'"+map.get("moId")+"' as poId from OM_MODetails mo " +
|
|
|
+ "left join Inventory inv on mo.cInvCode = inv.cInvCode "+
|
|
|
+ "left join OM_MOdetails_extradefine ex on mo.MODetailsID = ex.MODetailsID "+
|
|
|
+ " where mo.MOID = "+map.get("moId");
|
|
|
+ List<Map<String, Object>> list = iSenYuDataSourceThree.queryForList(sql);
|
|
|
+ for(Map<String, Object> mapList:list){
|
|
|
+ totalAmount = totalAmount.add(new BigDecimal(mapList.get("amount").toString()));
|
|
|
+ exTaxAmount = exTaxAmount.add(new BigDecimal(mapList.get("iMoney").toString()));
|
|
|
+ }
|
|
|
+ //子表转JSON
|
|
|
+ List<JSONObject> json = toMOListJson(list);
|
|
|
+ jf.put("poLineList",json);
|
|
|
+ jf.put("totalAmount",totalAmount);
|
|
|
+ jf.put("exTaxAmount",exTaxAmount);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ jf.remove("MODetailsID");
|
|
|
+ jf.remove("MOID");
|
|
|
+ jf.remove("pkorg");
|
|
|
+ jf.remove("dVerifyDate");
|
|
|
+ pljf.add(jf);
|
|
|
+
|
|
|
+ return pljf;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 普通采购订单转JSON
|
|
|
+ * @param result
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static List<JSONObject> toPoMainJson(Map<String, Object> result) {
|
|
|
+ List<JSONObject> pljf = new ArrayList<JSONObject>();// 表数据json集合
|
|
|
+ SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+
|
|
|
+ JSONObject jf = new JSONObject();
|
|
|
+ //for (int i = 0; i < result.size(); i++) {
|
|
|
+ Map<String, Object> map = result;//.get(i);
|
|
|
+ Set<String> keys = map.keySet();
|
|
|
+ jf = new JSONObject();
|
|
|
+ for (String key : keys) {
|
|
|
+ if(null==map.get(key)){
|
|
|
+ jf.put(key, "");
|
|
|
+ }else{
|
|
|
+ jf.put(key, map.get(key));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(oConvertUtils.isNotEmpty(map.get("customerDemandDate"))){
|
|
|
+ String customerDemandDate = sf.format(map.get("customerDemandDate"));
|
|
|
+ jf.put("customerDemandDate",customerDemandDate+" 00:00:00");
|
|
|
+ }
|
|
|
+ if(oConvertUtils.isNotEmpty(map.get("publishDate"))){
|
|
|
+ String publishDate = sf.format(map.get("publishDate"));
|
|
|
+ jf.put("publishDate",publishDate+" 00:00:00");
|
|
|
+
|
|
|
+ }
|
|
|
+// String cAuditDate = sf.format(map.get("cAuditDate"));
|
|
|
+// jf.put("cAuditDate",cAuditDate+" 00:00:00");
|
|
|
+ //查询子表信息
|
|
|
+ if(map.get("pkorg").equals("one")){
|
|
|
+ BigDecimal totalAmount = BigDecimal.ZERO; //总金额
|
|
|
+ BigDecimal exTaxAmount = BigDecimal.ZERO;//总无税金额
|
|
|
+
|
|
|
+ String sql ="select '"+map.get("accId")+"' as 'accId',mo.iVouchRowNo as 'poLineNum',mo.ID as 'moDetailId','"+map.get("poNum")+"' as poNum," +
|
|
|
+ "mo.cInvCode as 'customerItemCode',inv.cInvName as 'itemName','' as 'poLineStatus',mo.dArriveDate as 'customerDemandDate'," +
|
|
|
+ "'' as receivingInventoryOrgCode,mo.cFree1 as cFree1,mo.cFree2 as cFree2,mo.cFree3 as cFree3,mo.cFree4 as cFree4," +
|
|
|
+ "mo.cFree5 as cFree5,mo.cFree6 as cFree6,mo.cFree7 as cFree7,mo.cFree8 as cFree8,mo.cFree9 as cFree9,mo.cFree10 as cFree10,mo.iQuantity as 'customerDemandQty',mo.cUnitID as 'customerUomCode'," +
|
|
|
+ "mo.iMoney as 'iMoney',mo.iUnitPrice as supplierExTaxPrice,'"+map.get("cAuditDate")+"' as lineAttributeDatetime2," +
|
|
|
+ "mo.iTax as lineAttributeDecimal1,mo.cbCloseDate as lineAttributeDatetime1,mo.cDefine24 as lineAttributeString9,ex.cbdefine2 as lineAttributeString7,ex.cbdefine3 as lineAttributeString8," +
|
|
|
+ "mo.iTaxPrice as 'customerPrice',(mo.iPerTaxRate/100) as 'lineTaxRate',mo.iSum as 'amount',mo.cDefine28 as 'lineAttributeString1'," +
|
|
|
+ "mo.cDefine32 as 'lineAttributeString2',mo.cDefine29 as 'lineAttributeString3','' as 'attributeString1',mo.cDefine30 as 'lineAttributeString4'," +
|
|
|
+ "mo.cbMemo as 'lineAttributeString5',mo.cDefine22 as lineAttributeString6,'' as lineAttributeString7,'' as lineAttributeString8,'' as 'color'," +
|
|
|
+ "'' as 'externalLineNum',0 as 'itemAttrId' from PO_Podetails mo left join Inventory inv on mo.cInvCode = inv.cInvCode " +
|
|
|
+ "left join PO_Podetails_extradefine ex on mo.ID = ex.ID"+
|
|
|
+ " where mo.POID = '"+map.get("moId")+"'";
|
|
|
+ List<Map<String, Object>> list = senYuDataSourceOne.queryForList(sql);
|
|
|
+ for(Map<String, Object> mapList:list){
|
|
|
+ totalAmount = totalAmount.add(new BigDecimal(mapList.get("amount").toString()));
|
|
|
+ exTaxAmount = exTaxAmount.add(new BigDecimal(mapList.get("iMoney").toString()));
|
|
|
+ }
|
|
|
+ //子表转JSON
|
|
|
+ List<JSONObject> json = toListJson(list);
|
|
|
+ jf.put("poLineList",json);
|
|
|
+ jf.put("totalAmount",totalAmount);
|
|
|
+ jf.put("exTaxAmount",exTaxAmount);
|
|
|
+ }
|
|
|
+ else if(map.get("pkorg").equals("two")){
|
|
|
+ BigDecimal totalAmount = BigDecimal.ZERO; //总金额
|
|
|
+ BigDecimal exTaxAmount = BigDecimal.ZERO;//总无税金额
|
|
|
+ String sql ="select '"+map.get("accId")+"' as 'accId',mo.iVouchRowNo as 'poLineNum',mo.ID as 'moDetailId','"+map.get("poNum")+"' as poNum," +
|
|
|
+ "mo.cInvCode as 'customerItemCode',inv.cInvName as 'itemName','' as 'poLineStatus',mo.dArriveDate as 'customerDemandDate'," +
|
|
|
+ "'' as receivingInventoryOrgCode,mo.cFree1 as cFree1,mo.cFree2 as cFree2,mo.cFree3 as cFree3,mo.cFree4 as cFree4," +
|
|
|
+ "mo.cFree5 as cFree5,mo.cFree6 as cFree6,mo.cFree7 as cFree7,mo.cFree8 as cFree8,mo.cFree9 as cFree9,mo.cFree10 as cFree10,mo.iQuantity as 'customerDemandQty',mo.cUnitID as 'customerUomCode'," +
|
|
|
+ "mo.iMoney as 'iMoney',mo.iUnitPrice as supplierExTaxPrice,'"+map.get("cAuditDate")+"' as lineAttributeDatetime2," +
|
|
|
+ "mo.iTax as lineAttributeDecimal1,mo.cbCloseDate as lineAttributeDatetime1,mo.cDefine24 as lineAttributeString9,ex.cbdefine2 as lineAttributeString7,ex.cbdefine3 as lineAttributeString8," +
|
|
|
+ "mo.iTaxPrice as 'customerPrice',(mo.iPerTaxRate/100) as 'lineTaxRate',mo.iSum as 'amount',mo.cDefine28 as 'lineAttributeString1'," +
|
|
|
+ "mo.cDefine32 as 'lineAttributeString2',mo.cDefine29 as 'lineAttributeString3','' as 'attributeString1',mo.cDefine30 as 'lineAttributeString4'," +
|
|
|
+ "mo.cbMemo as 'lineAttributeString5',mo.cDefine22 as lineAttributeString6,'' as lineAttributeString7,'' as lineAttributeString8,'' as 'color'," +
|
|
|
+ "'' as 'externalLineNum',0 as 'itemAttrId' from PO_Podetails mo left join Inventory inv on mo.cInvCode = inv.cInvCode " +
|
|
|
+ "left join PO_Podetails_extradefine ex on mo.ID = ex.ID"+
|
|
|
+ " where mo.POID = '"+map.get("moId")+"'";
|
|
|
+ List<Map<String, Object>> list = senYuDataSourceTwo.queryForList(sql);
|
|
|
+ for(Map<String, Object> mapList:list){
|
|
|
+ totalAmount = totalAmount.add(new BigDecimal(mapList.get("amount").toString()));
|
|
|
+ exTaxAmount = exTaxAmount.add(new BigDecimal(mapList.get("iMoney").toString()));
|
|
|
+ }
|
|
|
+ //子表转JSON
|
|
|
+ List<JSONObject> json = toListJson(list);
|
|
|
+ jf.put("poLineList",json);
|
|
|
+ jf.put("totalAmount",totalAmount);
|
|
|
+ jf.put("exTaxAmount",exTaxAmount);
|
|
|
+ }else if(map.get("pkorg").equals("three")){
|
|
|
+ BigDecimal totalAmount = BigDecimal.ZERO; //总金额
|
|
|
+ BigDecimal exTaxAmount = BigDecimal.ZERO;//总无税金额
|
|
|
+ String sql ="select '"+map.get("accId")+"' as 'accId',mo.iVouchRowNo as 'poLineNum',mo.ID as 'moDetailId','"+map.get("poNum")+"' as poNum," +
|
|
|
+ "mo.cInvCode as 'customerItemCode',inv.cInvName as 'itemName','' as 'poLineStatus',mo.dArriveDate as 'customerDemandDate'," +
|
|
|
+ "'' as receivingInventoryOrgCode,mo.cFree1 as cFree1,mo.cFree2 as cFree2,mo.cFree3 as cFree3,mo.cFree4 as cFree4," +
|
|
|
+ "mo.cFree5 as cFree5,mo.cFree6 as cFree6,mo.cFree7 as cFree7,mo.cFree8 as cFree8,mo.cFree9 as cFree9,mo.cFree10 as cFree10,mo.iQuantity as 'customerDemandQty',mo.cUnitID as 'customerUomCode'," +
|
|
|
+ "mo.iMoney as 'iMoney',mo.iUnitPrice as supplierExTaxPrice,'"+map.get("cAuditDate")+"' as lineAttributeDatetime2," +
|
|
|
+ "mo.iTax as lineAttributeDecimal1,mo.cbCloseDate as lineAttributeDatetime1,mo.cDefine24 as lineAttributeString9,ex.cbdefine2 as lineAttributeString7,ex.cbdefine3 as lineAttributeString8," +
|
|
|
+ "mo.iTaxPrice as 'customerPrice',(mo.iPerTaxRate/100) as 'lineTaxRate',mo.iSum as 'amount',mo.cDefine28 as 'lineAttributeString1'," +
|
|
|
+ "mo.cDefine32 as 'lineAttributeString2',mo.cDefine29 as 'lineAttributeString3','' as 'attributeString1',mo.cDefine30 as 'lineAttributeString4'," +
|
|
|
+ "mo.cbMemo as 'lineAttributeString5',mo.cDefine22 as lineAttributeString6,'' as lineAttributeString7,'' as lineAttributeString8,'' as 'color'," +
|
|
|
+ "'' as 'externalLineNum',0 as 'itemAttrId' from PO_Podetails mo left join Inventory inv on mo.cInvCode = inv.cInvCode " +
|
|
|
+ "left join PO_Podetails_extradefine ex on mo.ID = ex.ID "+
|
|
|
+ " where mo.POID = '"+map.get("moId")+"'";
|
|
|
+ List<Map<String, Object>> list = iSenYuDataSourceThree.queryForList(sql);
|
|
|
+ for(Map<String, Object> mapList:list){
|
|
|
+ totalAmount = totalAmount.add(new BigDecimal(mapList.get("amount").toString()));
|
|
|
+ exTaxAmount = exTaxAmount.add(new BigDecimal(mapList.get("iMoney").toString()));
|
|
|
+ }
|
|
|
+ //子表转JSON
|
|
|
+ List<JSONObject> json = toListJson(list);
|
|
|
+ jf.put("poLineList",json);
|
|
|
+ jf.put("totalAmount",totalAmount);
|
|
|
+ jf.put("exTaxAmount",exTaxAmount);
|
|
|
+ }
|
|
|
+
|
|
|
+ jf.remove("pkorg");
|
|
|
+ jf.remove("cAuditDate");
|
|
|
+
|
|
|
+ pljf.add(jf);
|
|
|
+ //}
|
|
|
+ return pljf;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 材料出库单转JSON
|
|
|
+ * @param result
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static List<JSONObject> toRdrecordJson(List<Map<String, Object>> result) {
|
|
|
+ List<JSONObject> pljf = new ArrayList<JSONObject>();// 表数据json集合
|
|
|
+ SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ JSONObject jf = new JSONObject();
|
|
|
+ for (int i = 0; i < result.size(); i++) {
|
|
|
+ Map<String, Object> map = result.get(i);
|
|
|
+ Set<String> keys = map.keySet();
|
|
|
+ jf = new JSONObject();
|
|
|
+ for (String key : keys) {
|
|
|
+ if(null==map.get(key)){
|
|
|
+ jf.put(key, "");
|
|
|
+ }else{
|
|
|
+ jf.put(key, map.get(key));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(oConvertUtils.isNotEmpty(map.get("customerDemandDate"))){
|
|
|
+ String customerDemandDate = sf.format(map.get("customerDemandDate"));
|
|
|
+ jf.put("customerDemandDate",customerDemandDate+" 00:00:00");
|
|
|
+ }
|
|
|
+ if(oConvertUtils.isNotEmpty(map.get("publishDate"))){
|
|
|
+ String publishDate = sf.format(map.get("publishDate"));
|
|
|
+ jf.put("publishDate",publishDate+" 00:00:00");
|
|
|
+
|
|
|
+ }
|
|
|
+ //查询子表信息
|
|
|
+ if(map.get("accId").equals("903")){
|
|
|
+ String sql = "select '903' as cAccId,'' as '发货单号',AutoID as '发货单行ID',ID as '发货单ID', irowno as '发货单行号'," +
|
|
|
+ "'' as '发货单行状态',cInVoucherType as '发货单来源类型','' as '来源单据ID','' as '来源单据编号'," +
|
|
|
+ "'' as '来源单据行ID',cInvCode as '供应商物料编码',cBVencode as '供应商单位ID','' as '单位'," +
|
|
|
+ "iQuantity as '采购数量',iSOutQuantity as '出库数量',cBatch as '批号' from rdrecords11 " +
|
|
|
+ "where ID = '"+map.get("ID")+"'";
|
|
|
+
|
|
|
+ List<Map<String, Object>> list = senYuDataSourceOne.queryForList(sql);
|
|
|
+ //子表转JSON
|
|
|
+ List<JSONObject> json = toListJson(list);
|
|
|
+ jf.put("poLineList",json);
|
|
|
+ }
|
|
|
+
|
|
|
+ pljf.add(jf);
|
|
|
+ }
|
|
|
+ return pljf;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 采购订单子表转json集合
|
|
|
* @param result
|
|
|
* @return
|
|
|
*/
|
|
|
public static List<JSONObject> toListJson(List<Map<String, Object>> result) {
|
|
|
List<JSONObject> pljf = new ArrayList<JSONObject>();// 表数据json集合
|
|
|
+ Map<String, Object> mapCfree = new HashMap<>();//处理物料属性
|
|
|
+ int ii = 1;
|
|
|
+ SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
JSONObject jf = new JSONObject();
|
|
|
for (int i = 0; i < result.size(); i++) {
|
|
|
Map<String, Object> map = result.get(i);
|
|
|
@@ -30,11 +373,187 @@ public class JsonChangeUtils{
|
|
|
if(null==map.get(key)){
|
|
|
jf.put(key, "");
|
|
|
}else{
|
|
|
+ if(key.equals("cFree1")&&oConvertUtils.isNotEmpty(map.get(key))){
|
|
|
+ mapCfree.put(key,map.get(key));
|
|
|
+ }else if(key.equals("cFree2")&&oConvertUtils.isNotEmpty(map.get(key))){
|
|
|
+ mapCfree.put(key,map.get(key));
|
|
|
+ }else if(key.equals("cFree3")&&oConvertUtils.isNotEmpty(map.get(key))){
|
|
|
+ mapCfree.put(key,map.get(key));
|
|
|
+ }else if(key.equals("cFree4")&&oConvertUtils.isNotEmpty(map.get(key))){
|
|
|
+ mapCfree.put(key,map.get(key));
|
|
|
+ }else if(key.equals("cFree5")&&oConvertUtils.isNotEmpty(map.get(key))){
|
|
|
+ mapCfree.put(key,map.get(key));
|
|
|
+ }else if(key.equals("cFree6")&&oConvertUtils.isNotEmpty(map.get(key))){
|
|
|
+ mapCfree.put(key,map.get(key));
|
|
|
+ }else if(key.equals("cFree7")&&oConvertUtils.isNotEmpty(map.get(key))){
|
|
|
+ mapCfree.put(key,map.get(key));
|
|
|
+ }else if(key.equals("cFree8")&&oConvertUtils.isNotEmpty(map.get(key))){
|
|
|
+ mapCfree.put(key,map.get(key));
|
|
|
+ }else if(key.equals("cFree9")&&oConvertUtils.isNotEmpty(map.get(key))){
|
|
|
+ mapCfree.put(key,map.get(key));
|
|
|
+ }else if(key.equals("cFree10")&&oConvertUtils.isNotEmpty(map.get(key))){
|
|
|
+ mapCfree.put(key,map.get(key));
|
|
|
+ }
|
|
|
jf.put(key, map.get(key));
|
|
|
}
|
|
|
}
|
|
|
+ if(oConvertUtils.isNotEmpty(map.get("customerDemandDate"))){
|
|
|
+ String customerDemandDate = sf.format(map.get("customerDemandDate"));
|
|
|
+ jf.put("customerDemandDate",customerDemandDate+" 00:00:00");
|
|
|
+ }
|
|
|
+
|
|
|
+ if(oConvertUtils.isNotEmpty(map.get("lineAttributeDatetime1"))){
|
|
|
+ String lineAttributeDatetime1 = sf.format(map.get("lineAttributeDatetime1"));
|
|
|
+ jf.put("lineAttributeDatetime1",lineAttributeDatetime1+" 00:00:00");
|
|
|
+ }
|
|
|
+
|
|
|
+ Set<String> keysCfree = mapCfree.keySet();
|
|
|
+ for (String key : keysCfree) {
|
|
|
+ jf.put("attributeCode"+ii, key);
|
|
|
+ jf.put("attributeValue"+ii, map.get(key));
|
|
|
+ ii++;
|
|
|
+ }
|
|
|
+ ii = 1;
|
|
|
+ jf.remove("iMoney");
|
|
|
+ jf.remove("cFree1");
|
|
|
+ jf.remove("cFree2");
|
|
|
+ jf.remove("cFree3");
|
|
|
+ jf.remove("cFree4");
|
|
|
+ jf.remove("cFree5");
|
|
|
+ jf.remove("cFree6");
|
|
|
+ jf.remove("cFree7");
|
|
|
+ jf.remove("cFree8");
|
|
|
+ jf.remove("cFree9");
|
|
|
+ jf.remove("cFree10");
|
|
|
pljf.add(jf);
|
|
|
}
|
|
|
return pljf;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 委外专用JSON
|
|
|
+ * @param result
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static List<JSONObject> toMOListJson(List<Map<String, Object>> result) {
|
|
|
+ List<JSONObject> pljf = new ArrayList<JSONObject>();// 表数据json集合
|
|
|
+ Map<String, Object> mapCfree = new HashMap<>();//处理物料属性
|
|
|
+ int ii = 1;
|
|
|
+ SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ JSONObject jf = new JSONObject();
|
|
|
+ for (int i = 0; i < result.size(); i++) {
|
|
|
+ Map<String, Object> map = result.get(i);
|
|
|
+ Set<String> keys = map.keySet();
|
|
|
+ jf = new JSONObject();
|
|
|
+ for (String key : keys) {
|
|
|
+ if(null==map.get(key)){
|
|
|
+ jf.put(key, "");
|
|
|
+ }else{
|
|
|
+ if(key.equals("cFree1")&&oConvertUtils.isNotEmpty(map.get(key))){
|
|
|
+ mapCfree.put(key,map.get(key));
|
|
|
+ }else if(key.equals("cFree2")&&oConvertUtils.isNotEmpty(map.get(key))){
|
|
|
+ mapCfree.put(key,map.get(key));
|
|
|
+ }else if(key.equals("cFree3")&&oConvertUtils.isNotEmpty(map.get(key))){
|
|
|
+ mapCfree.put(key,map.get(key));
|
|
|
+ }else if(key.equals("cFree4")&&oConvertUtils.isNotEmpty(map.get(key))){
|
|
|
+ mapCfree.put(key,map.get(key));
|
|
|
+ }else if(key.equals("cFree5")&&oConvertUtils.isNotEmpty(map.get(key))){
|
|
|
+ mapCfree.put(key,map.get(key));
|
|
|
+ }else if(key.equals("cFree6")&&oConvertUtils.isNotEmpty(map.get(key))){
|
|
|
+ mapCfree.put(key,map.get(key));
|
|
|
+ }else if(key.equals("cFree7")&&oConvertUtils.isNotEmpty(map.get(key))){
|
|
|
+ mapCfree.put(key,map.get(key));
|
|
|
+ }else if(key.equals("cFree8")&&oConvertUtils.isNotEmpty(map.get(key))){
|
|
|
+ mapCfree.put(key,map.get(key));
|
|
|
+ }else if(key.equals("cFree9")&&oConvertUtils.isNotEmpty(map.get(key))){
|
|
|
+ mapCfree.put(key,map.get(key));
|
|
|
+ }else if(key.equals("cFree10")&&oConvertUtils.isNotEmpty(map.get(key))){
|
|
|
+ mapCfree.put(key,map.get(key));
|
|
|
+ }
|
|
|
+ jf.put(key, map.get(key));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(oConvertUtils.isNotEmpty(map.get("customerDemandDate"))){
|
|
|
+ String customerDemandDate = sf.format(map.get("customerDemandDate"));
|
|
|
+ jf.put("customerDemandDate",customerDemandDate+" 00:00:00");
|
|
|
+ }
|
|
|
+ if(oConvertUtils.isNotEmpty(map.get("lineAttributeDatetime1"))){
|
|
|
+ String lineAttributeDatetime1 = sf.format(map.get("lineAttributeDatetime1"));
|
|
|
+ jf.put("lineAttributeDatetime1",lineAttributeDatetime1+" 00:00:00");
|
|
|
+ }
|
|
|
+ //查询委外用料子表数据
|
|
|
+ if(map.get("pkorg").equals("one")){
|
|
|
+
|
|
|
+ String sql1 = "select '"+map.get("accId")+"' as accId,'"+map.get("MOID")+"' as poId,'"+map.get("poNum")+"' as poNum," +
|
|
|
+ "mo.cInvCode as 'customerItemCode','' as 'itemAttrId','' as customerItemId," +
|
|
|
+ "mo.cFree1 as cFree1,mo.cFree2 as cFree2,mo.cFree3 as cFree3,mo.cFree4 as cFree4," +
|
|
|
+ "mo.cFree5 as cFree5,mo.cFree6 as cFree6,mo.cFree7 as cFree7,mo.cFree8 as cFree8,mo.cFree9 as cFree9,mo.cFree10 as cFree10," +
|
|
|
+ "'' as poOutsourceId,''as poOutsourceNum,'' as 'customerUomId','' as customerUomCode,0 as customerPromiseQty, " +
|
|
|
+ "mo.cDefine25 as outsourceAttributeString1,mo.cDefine24 as 'outsourceAttributeString2',mo.cDefine27 as 'outsourceAttributeString3'" +
|
|
|
+ " from OM_MOMaterials mo where MODetailsID = '"+map.get("MODetailsID")+"'";
|
|
|
+ List<Map<String, Object>> list = senYuDataSourceOne.queryForList(sql1);
|
|
|
+ //子表转JSON
|
|
|
+ List<JSONObject> json = toListJson(list);
|
|
|
+ jf.put("outSourceList",json);
|
|
|
+ }else if(map.get("pkorg").equals("two")){
|
|
|
+
|
|
|
+ String sql1 = "select '"+map.get("accId")+"' as accId,'"+map.get("MOID")+"' as poId,'"+map.get("poNum")+"' as poNum," +
|
|
|
+ "mo.cInvCode as 'customerItemCode','' as 'itemAttrId','' as customerItemId," +
|
|
|
+ "mo.cFree1 as cFree1,mo.cFree2 as cFree2,mo.cFree3 as cFree3,mo.cFree4 as cFree4," +
|
|
|
+ "mo.cFree5 as cFree5,mo.cFree6 as cFree6,mo.cFree7 as cFree7,mo.cFree8 as cFree8,mo.cFree9 as cFree9,mo.cFree10 as cFree10," +
|
|
|
+ "'' as poOutsourceId,''as poOutsourceNum,'' as 'customerUomId','' as customerUomCode,0 as customerPromiseQty, " +
|
|
|
+ "mo.cDefine25 as outsourceAttributeString1,mo.cDefine24 as 'outsourceAttributeString2',mo.cDefine27 as 'outsourceAttributeString3'" +
|
|
|
+ " from OM_MOMaterials mo where MODetailsID = '"+map.get("MODetailsID")+"'";
|
|
|
+ List<Map<String, Object>> list = senYuDataSourceTwo.queryForList(sql1);
|
|
|
+ //子表转JSON
|
|
|
+ List<JSONObject> json = toListJson(list);
|
|
|
+ jf.put("outSourceList",json);
|
|
|
+ }else if(map.get("pkorg").equals("three")){
|
|
|
+
|
|
|
+ String sql1 = "select '"+map.get("accId")+"' as accId,'"+map.get("MOID")+"' as poId,'"+map.get("poNum")+"' as poNum," +
|
|
|
+ "mo.cInvCode as 'customerItemCode','' as 'itemAttrId','' as customerItemId," +
|
|
|
+ "mo.cFree1 as cFree1,mo.cFree2 as cFree2,mo.cFree3 as cFree3,mo.cFree4 as cFree4," +
|
|
|
+ "mo.cFree5 as cFree5,mo.cFree6 as cFree6,mo.cFree7 as cFree7,mo.cFree8 as cFree8,mo.cFree9 as cFree9,mo.cFree10 as cFree10," +
|
|
|
+ "'' as poOutsourceId,''as poOutsourceNum,'' as 'customerUomId','' as customerUomCode,0 as customerPromiseQty, " +
|
|
|
+ "mo.cDefine25 as outsourceAttributeString1,mo.cDefine24 as 'outsourceAttributeString2',mo.cDefine27 as 'outsourceAttributeString3'" +
|
|
|
+ " from OM_MOMaterials mo where MODetailsID = '"+map.get("MODetailsID")+"'";
|
|
|
+ List<Map<String, Object>> list = iSenYuDataSourceThree.queryForList(sql1);
|
|
|
+ //子表转JSON
|
|
|
+ List<JSONObject> json = toListJson(list);
|
|
|
+ jf.put("outSourceList",json);
|
|
|
+ }
|
|
|
+ Set<String> keysCfree = mapCfree.keySet();
|
|
|
+ for (String key : keysCfree) {
|
|
|
+ jf.put("attributeCode"+ii, key);
|
|
|
+ jf.put("attributeValue"+ii, map.get(key));
|
|
|
+ ii++;
|
|
|
+ }
|
|
|
+ ii = 1;
|
|
|
+ jf.remove("cFree1");
|
|
|
+ jf.remove("cFree2");
|
|
|
+ jf.remove("cFree3");
|
|
|
+ jf.remove("cFree4");
|
|
|
+ jf.remove("cFree5");
|
|
|
+ jf.remove("cFree6");
|
|
|
+ jf.remove("cFree7");
|
|
|
+ jf.remove("cFree8");
|
|
|
+ jf.remove("cFree9");
|
|
|
+ jf.remove("cFree10");
|
|
|
+ jf.remove("MODetailsID");
|
|
|
+ jf.remove("MOID");
|
|
|
+ jf.remove("pkorg");
|
|
|
+ jf.remove("iMoney");
|
|
|
+ pljf.add(jf);
|
|
|
+ }
|
|
|
+ return pljf;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
|
|
+
|
|
|
+ this.senYuDataSourceOne = applicationContext.getBean(ISenYuDataSourceOne.class);
|
|
|
+ this.senYuDataSourceTwo = applicationContext.getBean(ISenYuDataSourceTwo.class);
|
|
|
+ this.iSenYuDataSourceThree = applicationContext.getBean(ISenYuDataSourceThree.class);
|
|
|
+ }
|
|
|
}
|