|
@@ -1,18 +1,194 @@
|
|
|
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.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.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/***
|
|
|
* json转换类
|
|
|
* 赵万发
|
|
|
*/
|
|
|
-public class JsonChangeUtils{
|
|
|
+@Component
|
|
|
+public class JsonChangeUtils implements ApplicationContextAware{
|
|
|
+
|
|
|
+ private static ISenYuDataSourceOne senYuDataSourceOne;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 委外订单转JSON
|
|
|
+ * @param result
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static List<JSONObject> toMoMainJson(List<Map<String, Object>> result) {
|
|
|
+ List<JSONObject> pljf = new ArrayList<JSONObject>();// 表数据json集合
|
|
|
+ SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ // String lasttimeSf = sf.format(lastTiem);
|
|
|
+ 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));
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String customerDemandDate = sf.format(map.get("customerDemandDate"));
|
|
|
+ jf.put("customerDemandDate",customerDemandDate+" 00:00:00");
|
|
|
+ String publishDate = sf.format(map.get("publishDate"));
|
|
|
+ jf.put("publishDate",publishDate+" 00:00:00");
|
|
|
+ //查询子表信息
|
|
|
+ if(map.get("accId").equals("903")){
|
|
|
+// String sql = "select MODetailsID as MODetailsID,"+map.get("accId")+" as cAccId,"+map.get("MOID")+" as MOID,'' as cCode," +
|
|
|
+// "'N0201001237' as customerItemCode,'门幅120 颜色 为深色' as cInvName,'lineStatus' as lineStatus," +
|
|
|
+// "'' as attributeCode1,'' as attributeCode2,'' as attributeCode3,'' as attributeCode4,'' as attributeValue1,'' as attributeValue2," +
|
|
|
+// "'' as attributeValue3,'' as attributeValue4," +
|
|
|
+// "'materialKeyAttribute' as materialKeyAttribute,iQuantity as customerDemandQty,cUnitID as customerUomCode,'demandDate' as customerDemandDate," +
|
|
|
+// "iTaxPrice as customerPrice,(iPerTaxRate/100) as lineTaxRate,iMoney as amount,'12' as lineAttributeString1,'34' as lineAttributeString2," +
|
|
|
+// "'56' as lineAttributeString3,'78' as lineAttributeString4,cbMemo as lineAttributeString5 " +
|
|
|
+// "from OM_MODetails where MOID = "+map.get("MOID");
|
|
|
+ //mo.cInvCode,inv.cInvName
|
|
|
+ String sql = "select mo.iVouchRowNo as 'poLineNum',mo.MODetailsID as MODetailsID,mo.MODetailsID as ' moDetailId','"+map.get("headerAttributeString6")+"' as MOID,'"+map.get("accId")+"' as 'accId'" +
|
|
|
+ ",'"+map.get("poNum")+"' as poNum,'N0201002142' as 'customerItemCode','35%棉65%涤 平纹汗布' as 'itemName','' as 'poLineStatus', " +
|
|
|
+ "mo.cFree1 as 'attributeValue1',mo.cFree2 as 'attributeValue2',mo.cFree3 as 'attributeValue3'," +
|
|
|
+ "mo.cFree4 as 'attributeValue4','cfree1' as 'attributeCode1','cfree2' as 'attributeCode2'," +
|
|
|
+ "'cfree3' as 'attributeCode3','cfree4' as 'attributeCode4'," +
|
|
|
+ "mo.iQuantity as 'customerDemandQty',mo.cUnitID as 'customerUomCode','"+map.get("customerDemandDate")+"' as 'customerDemandDate'," +
|
|
|
+ "mo.iUnitPrice as 'customerPrice',(mo.iPerTaxRate/100) as 'lineTaxRate',mo.iMoney as 'amount'," +
|
|
|
+ "mo.cDefine28 as 'lineAttributeString1',mo.cDefine32 as 'lineAttributeString2',mo.cDefine29 as 'lineAttributeString3'," +
|
|
|
+ "mo.cDefine30 as 'lineAttributeString4',mo.cbMemo as 'lineAttributeString5',cFree1 as 'color','' as 'customerNumber','' as externalLineNum," +
|
|
|
+ "'' as itemAttrId,'"+map.get("headerAttributeString6")+"' as poId " +
|
|
|
+ " from OM_MODetails mo " +
|
|
|
+ " left join Inventory inv " +
|
|
|
+ " on mo.cInvCode = inv.cInvCode " +
|
|
|
+ " where mo.MOID = "+map.get("headerAttributeString6");
|
|
|
+ List<Map<String, Object>> list = senYuDataSourceOne.queryForList(sql);
|
|
|
+ //子表转JSON
|
|
|
+ List<JSONObject> json = toMOListJson(list);
|
|
|
+ jf.put("poLineList",json);
|
|
|
+ }
|
|
|
+
|
|
|
+ jf.remove("MODetailsID");
|
|
|
+ jf.remove("MOID");
|
|
|
+ pljf.add(jf);
|
|
|
+ }
|
|
|
+ return pljf;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 普通采购订单转JSON
|
|
|
+ * @param result
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static List<JSONObject> toPoMainJson(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));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String customerDemandDate = sf.format(map.get("customerDemandDate"));
|
|
|
+ jf.put("customerDemandDate",customerDemandDate+" 00:00:00");
|
|
|
+ String publishDate = sf.format(map.get("publishDate"));
|
|
|
+ jf.put("publishDate",publishDate+" 00:00:00");
|
|
|
+ //查询子表信息
|
|
|
+ if(map.get("accId").equals("903")){
|
|
|
+// String sql = "select '666' as cAccId,cPOID as cCode,cInvCode,'' as cInvName,'1' as lineStatus,'' as materialKeyAttribute," +
|
|
|
+// " iQuantity as purchaseQuantity,cUnitID as cUnitID,'' as demandDate,iTaxPrice as iTaxPrice,iPerTaxRate as iPerTaxRate," +
|
|
|
+// "iSum as lineTotalPrice,'' as smallPo,'' as packId,'' as distributionPoint,'' as dyeFactoryCode,cbMemo as cbMemo " +
|
|
|
+// "from PO_Podetails where POID = '"+map.get("POID")+"'";
|
|
|
+
|
|
|
+ String sql ="select '903' as 'accId',mo.iVouchRowNo as 'poLineNum',ID as 'moDetailId','"+map.get("poNum")+"' as poNum,mo.cInvCode as 'customerItemCode',inv.cInvName as 'itemName'," +
|
|
|
+ "'' as 'poLineStatus',mo.cFree1 as 'attributeValue1',mo.cFree2 as 'attributeValue2'," +
|
|
|
+ "mo.cFree3 as 'attributeValue3',mo.cFree4 as 'attributeValue4','cfree1' as 'attributeCode1'," +
|
|
|
+ "'cfree2' as 'attributeCode2','cfree3' as 'attributeCode3','cfree4' as 'attributeCode4'," +
|
|
|
+ "mo.iQuantity as 'customerDemandQty',mo.cUnitID as 'customerUomCode','"+map.get("customerDemandDate")+"' as 'customerDemandDate'," +
|
|
|
+ "mo.iUnitPrice as 'customerPrice',(mo.iPerTaxRate/100) as 'lineTaxRate',mo.iMoney as 'amount'," +
|
|
|
+ "'' as 'lineAttributeString1','' as 'lineAttributeString2','' as 'lineAttributeString3','' as 'attributeString1'," +
|
|
|
+ "'' as 'lineAttributeString4','' as 'color','' as 'externalLineNum',0 as 'itemAttrId' " +
|
|
|
+ "from PO_Podetails mo " +
|
|
|
+ "left join Inventory inv " +
|
|
|
+ "on mo.cInvCode = inv.cInvCode "+
|
|
|
+ "where mo.POID = '"+map.get("MOID")+"'";
|
|
|
+ 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> 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));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String customerDemandDate = sf.format(map.get("customerDemandDate"));
|
|
|
+ jf.put("customerDemandDate",customerDemandDate+" 00:00:00");
|
|
|
+ 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对象集合
|
|
@@ -37,4 +213,56 @@ public class JsonChangeUtils{
|
|
|
}
|
|
|
return pljf;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 委外专用JSON
|
|
|
+ * @param result
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static List<JSONObject> toMOListJson(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));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //查询委外用料子表数据
|
|
|
+ if(map.get("accId").equals("903")){
|
|
|
+// String sql = "select '' as poOutsourceNum,''as poNum,'903' as cAccId,"+map.get("MOID")+" as MOID,'YU-02' as customerItemCode,'' as itemAttrId," +
|
|
|
+// "'' as attributeCode1,'' as attributeCode2,'' as attributeCode3,'' as attributeCode4,'' as attributeValue1,'' as attributeValue2," +
|
|
|
+// "'' as attributeValue3,'' as attributeValue4," +
|
|
|
+// "'' as customerUnitID,'' as customerUnit,'' as customerPromiseQty,'' as outsourceAttributeString1,'' as outsourceAttributeString2," +
|
|
|
+// "'' as outsourceAttributeString3,'' as iUnitQuantity " +
|
|
|
+// " from OM_MOMaterials where MOMaterialsID = "+map.get("MODetailsID");
|
|
|
+
|
|
|
+ String sql1 = "select '903' as accId,'"+map.get("MOID")+"' as poId,'"+map.get("poNum")+"' as poNum,'N0201002142' as 'customerItemCode','' as 'itemAttrId','cfree1' as attributeCode1," +
|
|
|
+ "'cfree2' as attributeCode2,'cfree3' as attributeCode3,'cfree4' as attributeCode4,cFree1 as attributeValue1,cFree2 as attributeValue2," +
|
|
|
+ "cFree3 as attributeValue3,cFree4 as attributeValue4,'' as 'customerUomId','' as customerUomCode,0 as customerPromiseQty," +
|
|
|
+ " cDefine25 as outsourceAttributeString1,cDefine24 as 'outsourceAttributeString2'," +
|
|
|
+ "cDefine27 as 'outsourceAttributeString3' from OM_MOMaterials " +
|
|
|
+ "where MODetailsID = '"+map.get("MODetailsID")+"'";
|
|
|
+ List<Map<String, Object>> list = senYuDataSourceOne.queryForList(sql1);
|
|
|
+ //子表转JSON
|
|
|
+ List<JSONObject> json = toListJson(list);
|
|
|
+ jf.put("outSourceList",json);
|
|
|
+ }
|
|
|
+
|
|
|
+ pljf.add(jf);
|
|
|
+ }
|
|
|
+ return pljf;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
|
|
+
|
|
|
+ this.senYuDataSourceOne = applicationContext.getBean(ISenYuDataSourceOne.class);
|
|
|
+ }
|
|
|
}
|