| @@ -1,45 +1,43 @@ | |||
| package com.iformall.print.data; | |||
| import java.io.ByteArrayInputStream; | |||
| import java.io.IOException; | |||
| import java.io.StringReader; | |||
| import java.util.ArrayList; | |||
| import java.util.Iterator; | |||
| import java.util.List; | |||
| import javax.xml.parsers.DocumentBuilderFactory; | |||
| import javax.xml.parsers.ParserConfigurationException; | |||
| import javax.xml.xpath.XPath; | |||
| import javax.xml.xpath.XPathFactory; | |||
| 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.JSON; | |||
| import com.alibaba.fastjson.JSONArray; | |||
| import com.alibaba.fastjson.JSONObject; | |||
| import com.aliyun.openservices.shade.org.apache.commons.lang3.StringUtils; | |||
| import com.iformall.domain.po.WxFinanceReceive; | |||
| @Service | |||
| public class PrintCustomedTableDataHandler{ | |||
| public String getTableContent(String componentContent,JSONArray datas,JSONObject entity) { | |||
| 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); | |||
| componentContent = componentContent.replaceAll("\\{"+fieldName+"\\}", String.valueOf(o)); | |||
| //Object o = entity.get(fieldName); | |||
| if (StringUtils.isBlank(fieldName)) { | |||
| }else { | |||
| Object o = objectParser.getObjectValue(fieldName, object,params); | |||
| if (null == o) { | |||
| componentContent = componentContent.replaceAll("\\{"+fieldName+"\\}", ""); | |||
| }else { | |||
| componentContent = componentContent.replaceAll("\\{"+fieldName+"\\}", String.valueOf(o)); | |||
| } | |||
| } | |||
| } | |||
| } | |||
| componentContent = getTableListContent(componentContent,datas); | |||
| componentContent = getTableListContent(listParser,componentContent,listdata,params); | |||
| return componentContent; | |||
| } | |||
| private String getTableListContent(String componentContent,JSONArray datas) { | |||
| 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); | |||
| @@ -48,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)) { | |||
| @@ -90,7 +89,8 @@ public class PrintCustomedTableDataHandler{ | |||
| String[] fs = fieldName.split(","); | |||
| if (null != fs) { | |||
| for (int k = 0 ; k<fs.length; k++) { | |||
| Object v = o.get(fs[k]); | |||
| //Object v = o.get(fs[k]); | |||
| Object v = parser.getObjectValue(fs[k], object, params); | |||
| if (k == fs.length-1) { | |||
| sep = ""; | |||
| } | |||
| @@ -104,7 +104,8 @@ public class PrintCustomedTableDataHandler{ | |||
| } | |||
| }else { | |||
| Object v = o.get(fieldName); | |||
| //Object v = o.get(fieldName); | |||
| Object v = parser.getObjectValue(fieldName, object, params); | |||
| if (null != v) { | |||
| tdcontent.append(v); | |||
| }else { | |||
| @@ -120,19 +121,4 @@ public class PrintCustomedTableDataHandler{ | |||
| } | |||
| return doc.head().html() + doc.body().html(); | |||
| } | |||
| public static void main(String[] args) { | |||
| PrintCustomedTableDataHandler p = new PrintCustomedTableDataHandler(); | |||
| String s = "<style>table,td,th{border:1px solid #000;border-collapse:collapse}table{width:515px;font-size:10px;text-align:center}tr{height:30px}.one{width:10%}.two{width:16%}.three{width:32.5%}.four{width:10%}.five{width:10%}.six{width:10%}.seven{width:10%}</style><table id=\"fmbraidhtmltable\"><tr id=\"titletr\"><td class=\"one\" fieldName=\"shopNumber\">房间名称</td><td class=\"two\" fieldName=\"feesName\">费用科目</td><td class=\"three\" fieldName=\"starttime,endtime\" sep=\"~\">费用区间</td><td class=\"four\" fieldName=\"receivePay\">应收金额</td><td class=\"five\" fieldName=\"setOff\">冲抵金额</td><td class=\"six\" fieldName=\"youhui\">优惠金额</td><td class=\"seven\" fieldName=\"pay\">实收金额</td></tr></table>"; | |||
| List<WxFinanceReceive> rlist = new ArrayList<WxFinanceReceive>(); | |||
| WxFinanceReceive r1 = new WxFinanceReceive(); | |||
| r1.setFeesName("adssasd"); | |||
| WxFinanceReceive r2 = new WxFinanceReceive(); | |||
| r2.setFeesName("11111"); | |||
| rlist.add(r1); | |||
| rlist.add(r2); | |||
| String sss = p.getTableListContent(s, JSON.parseArray(JSON.toJSONString(rlist))); | |||
| System.out.println(sss); | |||
| } | |||
| } | |||
| @@ -0,0 +1,6 @@ | |||
| package com.iformall.print.data; | |||
| public interface PrintDataParser { | |||
| public Object getObjectValue(String name, Object o,Object... params); | |||
| } | |||
| @@ -1,4 +1,4 @@ | |||
| package com.iformall.print.data; | |||
| package com.iformall.print.data.impl; | |||
| import java.util.Map; | |||
| @@ -6,15 +6,19 @@ 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; | |||
| @Service | |||
| public class PrintBillDataHandler{ | |||
| public class PrintBillDataHandler implements PrintDataParser{ | |||
| public Object getObjectValue(String name, Object o,Map<Long,WxMerchant> merchantMap,Map<Long,WxEnergyFees> feesMap) { | |||
| @Override | |||
| 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(); | |||
| @@ -1,4 +1,4 @@ | |||
| package com.iformall.print.data; | |||
| package com.iformall.print.data.impl; | |||
| import java.util.ArrayList; | |||
| import java.util.List; | |||
| @@ -11,6 +11,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.print.data.PrintDataParser; | |||
| import com.iformall.utils.DateUtils; | |||
| /** | |||
| @@ -21,10 +22,14 @@ import com.iformall.utils.DateUtils; | |||
| * | |||
| */ | |||
| @Service | |||
| public class PrintFinanceReceiveDataHandler { | |||
| public class PrintFinanceReceiveDataHandler implements PrintDataParser{ | |||
| public Object getObjectValue(String name, Object o,Map<Long,WxMerchant> merchantMap,Map<Long,WxEnergyFees> feesMap,Map<Long,String> shopNumber) { | |||
| WxFinanceReceive receive = (WxFinanceReceive) o; | |||
| @Override | |||
| 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(); | |||
| }else if (name.equals("createTime")) { | |||
| @@ -60,6 +65,6 @@ public class PrintFinanceReceiveDataHandler { | |||
| return ""; | |||
| } | |||
| return null; | |||
| } | |||
| } | |||
| } | |||
| @@ -1,4 +1,4 @@ | |||
| package com.iformall.print.data; | |||
| package com.iformall.print.data.impl; | |||
| import java.util.Map; | |||
| @@ -8,13 +8,19 @@ 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; | |||
| @Service | |||
| public class PrintMerchantSettleDataHandler{ | |||
| public class PrintMerchantSettleDataHandler implements PrintDataParser{ | |||
| public Object getObjectValue(String name, Object o,Map<Long,WxMerchant> merchantMap,Map<Long,WxEnergyFees> feesMap) { | |||
| @Override | |||
| 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(); | |||
| @@ -29,10 +29,11 @@ import com.iformall.exception.MallinkException; | |||
| import com.iformall.mapper.WxFinancePrintDataMapper; | |||
| import com.iformall.mapper.WxFinancePrintTemplateMapper; | |||
| import com.iformall.print.PrintComponentHandler; | |||
| import com.iformall.print.data.PrintBillDataHandler; | |||
| import com.iformall.print.data.PrintCustomedTableDataHandler; | |||
| import com.iformall.print.data.PrintFinanceReceiveDataHandler; | |||
| import com.iformall.print.data.PrintMerchantSettleDataHandler; | |||
| 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; | |||
| import com.iformall.service.WxAllBillService; | |||
| import com.iformall.service.WxEnergyService; | |||
| import com.iformall.service.WxFinancePrintService; | |||
| @@ -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,30 +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(componentContent, JSON.parseArray(JSON.toJSONString(billList)),JSON.parseObject(JSON.toJSONString(re)))); | |||
| 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); | |||
| } | |||
| @@ -295,10 +305,10 @@ public class WxFinancePrintServiceImpl implements WxFinancePrintService { | |||
| //} | |||
| }else { | |||
| if (isSetDefaultValue) { | |||
| ov.put("defaultValue", printBillDataHandler.getObjectValue(ov.getString("name"),re,merchantMap,feesMap)); | |||
| ov.put("defaultValue", printBillDataHandler.getObjectValue(ov.getString("name"),re,merchantMap,feesMap,shopNumber)); | |||
| ov.put("value", ""); | |||
| }else { | |||
| ov.put("value", printBillDataHandler.getObjectValue(ov.getString("name"),re,merchantMap,feesMap)); | |||
| ov.put("value", printBillDataHandler.getObjectValue(ov.getString("name"),re,merchantMap,feesMap,shopNumber)); | |||
| } | |||
| } | |||
| @@ -357,15 +367,16 @@ public class WxFinancePrintServiceImpl implements WxFinancePrintService { | |||
| String componentContent = ov.getString("value"); | |||
| if (null != sumlist && sumlist.size() > 0 ) { | |||
| ov.put("defaultValue",printCustomedTableDataHandler.getTableContent(componentContent, JSON.parseArray(JSON.toJSONString(sumlist)),JSON.parseObject(JSON.toJSONString(bq)))); | |||
| ov.put("defaultValue",printCustomedTableDataHandler.getTableContent(componentContent, printMerchantSettleDataHandler,bq, | |||
| printMerchantSettleDataHandler,sumlist,merchantMap,feesMap,shopNumber)); | |||
| ov.put("value", ""); | |||
| } | |||
| }else { | |||
| if (isSetDefaultValue) { | |||
| ov.put("defaultValue", printMerchantSettleDataHandler.getObjectValue(ov.getString("name"),bq,merchantMap,feesMap)); | |||
| ov.put("defaultValue", printMerchantSettleDataHandler.getObjectValue(ov.getString("name"),bq,merchantMap,feesMap,shopNumber)); | |||
| ov.put("value", ""); | |||
| }else { | |||
| ov.put("value", printMerchantSettleDataHandler.getObjectValue(ov.getString("name"),bq,merchantMap,feesMap)); | |||
| ov.put("value", printMerchantSettleDataHandler.getObjectValue(ov.getString("name"),bq,merchantMap,feesMap,shopNumber)); | |||
| } | |||
| } | |||