| @@ -2,41 +2,42 @@ package com.iformall.print.data; | |||
| import java.util.Iterator; | |||
| import java.util.List; | |||
| import java.util.Map; | |||
| import org.jsoup.Jsoup; | |||
| import org.jsoup.nodes.Document; | |||
| import org.jsoup.nodes.Element; | |||
| import org.jsoup.nodes.Node; | |||
| import org.springframework.stereotype.Service; | |||
| import com.alibaba.fastjson.JSONArray; | |||
| import com.alibaba.fastjson.JSON; | |||
| import com.alibaba.fastjson.JSONObject; | |||
| import com.aliyun.openservices.shade.org.apache.commons.lang3.StringUtils; | |||
| import com.iformall.domain.po.WxEnergyFees; | |||
| import com.iformall.domain.po.WxMerchant; | |||
| @Service | |||
| public class PrintCustomedTableDataHandler{ | |||
| public String getTableContent(PrintDataParser parser,String componentContent,JSONArray datas,JSONObject entity,Map<Long,WxMerchant> merchantMap,Map<Long,WxEnergyFees> feesMap,Map<Long,String> shopNumber) { | |||
| if (null != entity) { | |||
| public String getTableContent(String componentContent,PrintDataParser objectParser,Object object,PrintDataParser listParser,List listdata,Object... params) { | |||
| if (null != object) { | |||
| JSONObject entity = JSON.parseObject(JSON.toJSONString(object)); | |||
| for (Iterator<String> it = entity.keySet().iterator(); it.hasNext();) { | |||
| String fieldName = it.next(); | |||
| //Object o = entity.get(fieldName); | |||
| Object o = parser.getObjectValue(fieldName, entity, merchantMap, feesMap, shopNumber); | |||
| if (null == o) { | |||
| componentContent = componentContent.replaceAll("\\{"+fieldName+"\\}", ""); | |||
| if (StringUtils.isBlank(fieldName)) { | |||
| }else { | |||
| componentContent = componentContent.replaceAll("\\{"+fieldName+"\\}", String.valueOf(o)); | |||
| Object o = objectParser.getObjectValue(fieldName, object,params); | |||
| if (null == o) { | |||
| componentContent = componentContent.replaceAll("\\{"+fieldName+"\\}", ""); | |||
| }else { | |||
| componentContent = componentContent.replaceAll("\\{"+fieldName+"\\}", String.valueOf(o)); | |||
| } | |||
| } | |||
| } | |||
| } | |||
| componentContent = getTableListContent(parser,componentContent,datas,merchantMap,feesMap,shopNumber); | |||
| componentContent = getTableListContent(listParser,componentContent,listdata,params); | |||
| return componentContent; | |||
| } | |||
| private String getTableListContent(PrintDataParser parser,String componentContent,JSONArray datas,Map<Long,WxMerchant> merchantMap,Map<Long,WxEnergyFees> feesMap,Map<Long,String> shopNumber) { | |||
| if (null == datas || datas.size() <= 0) { | |||
| private String getTableListContent(PrintDataParser parser,String componentContent,List listdata,Object... params) { | |||
| if (null == listdata || listdata.size() <= 0) { | |||
| return componentContent; | |||
| } | |||
| Document doc = Jsoup.parse(componentContent); | |||
| @@ -45,8 +46,9 @@ public class PrintCustomedTableDataHandler{ | |||
| String trclass = titleTr.attr("class"); | |||
| String trstyle = titleTr.attr("style"); | |||
| StringBuffer sb = new StringBuffer(); | |||
| for (int i = 0 ; i < datas.size(); i ++) { | |||
| JSONObject o = datas.getJSONObject(i); | |||
| for (int i = 0 ; i < listdata.size(); i ++) { | |||
| Object object = listdata.get(i); | |||
| JSONObject o = JSON.parseObject(JSON.toJSONString(object)); | |||
| Element tr = titleTr.parent().appendElement("tr"); | |||
| sb.append("<tr "); | |||
| if (StringUtils.isNotBlank(trclass)) { | |||
| @@ -88,7 +90,7 @@ public class PrintCustomedTableDataHandler{ | |||
| if (null != fs) { | |||
| for (int k = 0 ; k<fs.length; k++) { | |||
| //Object v = o.get(fs[k]); | |||
| Object v = parser.getObjectValue(fs[k], o, merchantMap, feesMap, shopNumber); | |||
| Object v = parser.getObjectValue(fs[k], object, params); | |||
| if (k == fs.length-1) { | |||
| sep = ""; | |||
| } | |||
| @@ -103,7 +105,7 @@ public class PrintCustomedTableDataHandler{ | |||
| }else { | |||
| //Object v = o.get(fieldName); | |||
| Object v = parser.getObjectValue(fieldName, o, merchantMap, feesMap, shopNumber); | |||
| Object v = parser.getObjectValue(fieldName, object, params); | |||
| if (null != v) { | |||
| tdcontent.append(v); | |||
| }else { | |||
| @@ -1,11 +1,6 @@ | |||
| package com.iformall.print.data; | |||
| import java.util.Map; | |||
| import com.iformall.domain.po.WxEnergyFees; | |||
| import com.iformall.domain.po.WxMerchant; | |||
| public interface PrintDataParser { | |||
| public Object getObjectValue(String name, Object o,Map<Long,WxMerchant> merchantMap,Map<Long,WxEnergyFees> feesMap,Map<Long,String> shopNumber); | |||
| public Object getObjectValue(String name, Object o,Object... params); | |||
| } | |||
| @@ -6,7 +6,6 @@ import org.springframework.stereotype.Service; | |||
| import com.iformall.domain.po.WxAllBill; | |||
| import com.iformall.domain.po.WxEnergyFees; | |||
| import com.iformall.domain.po.WxFinanceReceive; | |||
| import com.iformall.domain.po.WxMerchant; | |||
| import com.iformall.print.data.PrintDataParser; | |||
| import com.iformall.utils.DateUtils; | |||
| @@ -16,7 +15,10 @@ public class PrintBillDataHandler implements PrintDataParser{ | |||
| @Override | |||
| public Object getObjectValue(String name, Object o,Map<Long,WxMerchant> merchantMap,Map<Long,WxEnergyFees> feesMap,Map<Long,String> shopNumber) { | |||
| public Object getObjectValue(String name, Object o,Object... params) { | |||
| Map<Long, WxMerchant> merchantMap = (Map<Long, WxMerchant>) params[0]; | |||
| Map<Long, WxEnergyFees> feesMap = (Map<Long, WxEnergyFees>) params[1]; | |||
| Map<Long,String> shopNumber = (Map<Long, String>) params[2]; | |||
| WxAllBill receive = (WxAllBill) o; | |||
| if (name.equals("id")) { | |||
| return receive.getId(); | |||
| @@ -25,8 +25,10 @@ import com.iformall.utils.DateUtils; | |||
| public class PrintFinanceReceiveDataHandler implements PrintDataParser{ | |||
| @Override | |||
| public Object getObjectValue(String name, Object o, Map<Long, WxMerchant> merchantMap, | |||
| Map<Long, WxEnergyFees> feesMap,Map<Long,String> shopNumber) { | |||
| public Object getObjectValue(String name, Object o, Object... params) { | |||
| Map<Long, WxMerchant> merchantMap = (Map<Long, WxMerchant>) params[0]; | |||
| Map<Long, WxEnergyFees> feesMap = (Map<Long, WxEnergyFees>) params[1]; | |||
| Map<Long,String> shopNumber = (Map<Long, String>) params[2]; | |||
| WxFinanceReceive receive = (WxFinanceReceive) o; | |||
| if (name.equals("id")) { | |||
| return receive.getId(); | |||
| @@ -8,6 +8,7 @@ import com.iformall.domain.po.WxAllBill; | |||
| import com.iformall.domain.po.WxEnergyFees; | |||
| import com.iformall.domain.po.WxFinanceReceive; | |||
| import com.iformall.domain.po.WxMerchant; | |||
| import com.iformall.domain.vo.WxMerchantBillVo; | |||
| import com.iformall.print.data.PrintDataParser; | |||
| import com.iformall.utils.DateUtils; | |||
| @@ -15,7 +16,11 @@ import com.iformall.utils.DateUtils; | |||
| public class PrintMerchantSettleDataHandler implements PrintDataParser{ | |||
| @Override | |||
| public Object getObjectValue(String name, Object o,Map<Long,WxMerchant> merchantMap,Map<Long,WxEnergyFees> feesMap,Map<Long,String> shopNumber) { | |||
| public Object getObjectValue(String name, Object o,Object... params) { | |||
| Map<Long, WxMerchant> merchantMap = (Map<Long, WxMerchant>) params[0]; | |||
| Map<Long, WxEnergyFees> feesMap = (Map<Long, WxEnergyFees>) params[1]; | |||
| Map<Long,String> shopNumber = (Map<Long, String>) params[2]; | |||
| WxMerchantBillVo receive = (WxMerchantBillVo) o; | |||
| //根据科目来查询对应的信息 | |||
| // if (name.equals("id")) { | |||
| // return receive.getId(); | |||
| @@ -30,6 +30,7 @@ import com.iformall.mapper.WxFinancePrintDataMapper; | |||
| import com.iformall.mapper.WxFinancePrintTemplateMapper; | |||
| import com.iformall.print.PrintComponentHandler; | |||
| import com.iformall.print.data.PrintCustomedTableDataHandler; | |||
| import com.iformall.print.data.PrintDataParser; | |||
| import com.iformall.print.data.impl.PrintBillDataHandler; | |||
| import com.iformall.print.data.impl.PrintFinanceReceiveDataHandler; | |||
| import com.iformall.print.data.impl.PrintMerchantSettleDataHandler; | |||
| @@ -191,6 +192,38 @@ public class WxFinancePrintServiceImpl implements WxFinancePrintService { | |||
| return isSetDefaultValue; | |||
| } | |||
| private void handleComponentData(JSONArray items,PrintDataParser objectParser,Object object,PrintDataParser listParser,List listdata,Object... params) { | |||
| if (null != items) { | |||
| for (int j = 0 ; j < items.size() ; j ++) { | |||
| JSONObject ov = items.getJSONObject(j); | |||
| //是否是定制化的表格 | |||
| Integer isCustomedTable = ov.getInteger("isFmCustomizedTable"); | |||
| boolean isSetDefaultValue = isSetDefaultValue(ov); | |||
| if (null != isCustomedTable && EnumYesOrNo.YES.getCode().intValue() == isCustomedTable.intValue()) { | |||
| //表格解析 | |||
| String componentContent = ov.getString("value"); | |||
| if (null != listdata) { | |||
| ov.put("defaultValue",printCustomedTableDataHandler.getTableContent(componentContent, objectParser,object,listParser,listdata,params)); | |||
| ov.put("value", ""); | |||
| } | |||
| }else { | |||
| String fieldName = ov.getString("name"); | |||
| if (StringUtils.isBlank(fieldName)) { | |||
| }else { | |||
| if (isSetDefaultValue) { | |||
| ov.put("defaultValue", objectParser.getObjectValue(fieldName,object,params)); | |||
| ov.put("value", ""); | |||
| }else { | |||
| ov.put("value", objectParser.getObjectValue(fieldName,object,params)); | |||
| } | |||
| } | |||
| } | |||
| } | |||
| } | |||
| } | |||
| @Override | |||
| public List<PrintVo> parseTemplateData(String tenantId, Long templateId, List<Long> dataIds,Object entity) { | |||
| WxFinancePrintTemplate template = this.getTemplateById(templateId); | |||
| @@ -239,31 +272,7 @@ public class WxFinancePrintServiceImpl implements WxFinancePrintService { | |||
| billq.setIds(billIdList); | |||
| billList = wxAllBillService.list(billq); | |||
| } | |||
| if (null != items) { | |||
| for (int j = 0 ; j < items.size() ; j ++) { | |||
| JSONObject ov = items.getJSONObject(j); | |||
| //是否是定制化的表格 | |||
| Integer isCustomedTable = ov.getInteger("isFmCustomizedTable"); | |||
| boolean isSetDefaultValue = isSetDefaultValue(ov); | |||
| if (null != isCustomedTable && EnumYesOrNo.YES.getCode().intValue() == isCustomedTable.intValue()) { | |||
| //表格解析 | |||
| String componentContent = ov.getString("value"); | |||
| if (null != billList) { | |||
| ov.put("defaultValue",printCustomedTableDataHandler.getTableContent(printFinanceReceiveDataHandler,componentContent, JSON.parseArray(JSON.toJSONString(billList)), | |||
| JSON.parseObject(JSON.toJSONString(re)),merchantMap,feesMap,shopNumber)); | |||
| ov.put("value", ""); | |||
| } | |||
| }else { | |||
| if (isSetDefaultValue) { | |||
| ov.put("defaultValue", printFinanceReceiveDataHandler.getObjectValue(ov.getString("name"),re,merchantMap,feesMap,shopNumber)); | |||
| ov.put("value", ""); | |||
| }else { | |||
| ov.put("value", printFinanceReceiveDataHandler.getObjectValue(ov.getString("name"),re,merchantMap,feesMap,shopNumber)); | |||
| } | |||
| } | |||
| } | |||
| } | |||
| handleComponentData(items, printFinanceReceiveDataHandler,re,printBillDataHandler, billList,merchantMap,feesMap,feesMap); | |||
| vo.setTemplate(o); | |||
| voList.add(vo); | |||
| } | |||
| @@ -358,7 +367,8 @@ public class WxFinancePrintServiceImpl implements WxFinancePrintService { | |||
| String componentContent = ov.getString("value"); | |||
| if (null != sumlist && sumlist.size() > 0 ) { | |||
| ov.put("defaultValue",printCustomedTableDataHandler.getTableContent(printMerchantSettleDataHandler,componentContent, JSON.parseArray(JSON.toJSONString(sumlist)),JSON.parseObject(JSON.toJSONString(bq)),merchantMap,feesMap,shopNumber)); | |||
| ov.put("defaultValue",printCustomedTableDataHandler.getTableContent(componentContent, printMerchantSettleDataHandler,bq, | |||
| printMerchantSettleDataHandler,sumlist,merchantMap,feesMap,shopNumber)); | |||
| ov.put("value", ""); | |||
| } | |||
| }else { | |||