From ead388ad45a3a6c4ad5d76c636c2d8ff608df3c8 Mon Sep 17 00:00:00 2001 From: xu_lw Date: Thu, 29 Aug 2019 15:34:00 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E5=A2=9E=E5=8A=A0dict.js=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E7=94=9F=E6=88=90=202.=20=E5=A2=9E=E5=8A=A0table?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E5=9B=BA=E5=AE=9A=E5=88=97=E5=92=8C=E9=AB=98?= =?UTF-8?q?=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../buipubbpc1/BuiHlpGenerateAction.java | 171 ++++++++++++++++++ .../src/test/resources/template/mng.vue.ftl | 4 +- 2 files changed, 174 insertions(+), 1 deletion(-) create mode 100644 ecp-mbu-web/src/main/java/com/murong/ecp/netpay/mbu/web/pub/action/buipubbpc1/BuiHlpGenerateAction.java diff --git a/ecp-mbu-web/src/main/java/com/murong/ecp/netpay/mbu/web/pub/action/buipubbpc1/BuiHlpGenerateAction.java b/ecp-mbu-web/src/main/java/com/murong/ecp/netpay/mbu/web/pub/action/buipubbpc1/BuiHlpGenerateAction.java new file mode 100644 index 00000000..e420731f --- /dev/null +++ b/ecp-mbu-web/src/main/java/com/murong/ecp/netpay/mbu/web/pub/action/buipubbpc1/BuiHlpGenerateAction.java @@ -0,0 +1,171 @@ +package com.murong.ecp.netpay.mbu.web.pub.action.buipubbpc1; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.murong.ecp.netpay.mbu.web.common.utils.BaseAction; +import com.murong.ecp.netpay.mbu.web.common.utils.CommonMessageCode; +import com.murong.ecp.netpay.mbu.web.common.utils.ResultT; +import com.murong.ecp.netpay.mbu.web.common.utils.ValidatorUtil; +import com.murong.ecp.netpay.mbu.web.pub.dal.dao.BuiHlpMapper; +import com.murong.ecp.netpay.mbu.web.pub.dal.entity.BuiHlpDO; +import com.murong.ecp.netpay.mbu.web.pub.model.BuiHlpDeleteReqBO; +import com.yuangou.ecp.biz.transengine.sqlsession.YGSqlSession; +import com.yuangou.ecp.bp.comp.pubatc.bat.YGData; +import com.yuangou.ecp.bp.core.common.exception.YGException; +import com.yuangou.ecp.bp.core.common.message.YGBizMessage; +import com.yuangou.ecp.bp.core.common.message.YGBizMessageContext; +import com.yuangou.ecp.bp.core.common.yglog4j.Logger; +import com.yuangou.ecp.bp.core.common.yglog4j.YGLogger; +import com.yuangou.ecp.bp.database.YGDatabaseUtil; +import com.yuangou.ecp.bp.database.YGResultSet; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.io.FileUtils; +import org.springframework.beans.BeanUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +/** + * 字典枚举值生成服务 + * Created by xu_lw on 2019-08-24 17:26:40. + */ +@Service("buiHlpGenerate") +public class BuiHlpGenerateAction extends BaseAction { + @Autowired + private BuiHlpMapper buiHlpMapper; + + /** + * 删除记录 + * + * @param bizCtx + * @return + * @throws YGException + */ + public ResultT execute(YGBizMessageContext bizCtx) throws YGException { + YGBizMessage bizMsg = bizCtx.getCurrentMsg(); + Logger msgLog = YGLogger.getLogger(bizMsg); + YGDatabaseUtil dbUtil = bizCtx.getDataBaseUtil(); + + Connection connection = dbUtil.getConnection(); + PreparedStatement ps = null; + ResultSet rs = null; + ResultT resultT = new ResultT(); + Map> fldHlps = new HashMap>(); + + try { + ps = connection.prepareStatement("select * from t_pub_hlp order by fld_nm,fld_order"); + rs = ps.executeQuery(); + while (rs.next()) { + String fldNm = rs.getString("fld_nm"); + String fldVal = rs.getString("fld_val"); + String fldExp = rs.getString("fld_exp"); + Map map = (Map) fldHlps.get(fldNm); + if (map == null) { + map = new LinkedHashMap(); + fldHlps.put(name, map); + } + map.put(fldExp, fldVal); + } + } catch (Exception e) { + msgLog.info(e.toString(), e); + resultT.setMsgCod(CommonMessageCode.FAIL); + resultT.setMsgInf(e.toString()); + return resultT; + } finally { + if (rs != null) { + try { + rs.close(); + } catch (SQLException e) { + ; + } + } + if (ps != null) { + try { + ps.close(); + } catch (SQLException e) { + ; + } + } + } + + + + StringBuffer buf = new StringBuffer(); + buf.append("const dict = {\n"); + buf.append(" data: {\n"); + for (String name : fldHlps.keySet()) { + Map map = fldHlps.get(name); + buf.append("{"); + for(String name1: map.keySet() ) { + buf.append("'" + name1 + "'"); + buf.append(":"); + buf.append("'" + map.get(name1) + "'"); + buf.append(","); + } + buf.deleteCharAt(buf.length() - 1); + buf.append("},\n"); + } + buf.deleteCharAt(buf.length() - 1); + buf.append(" },\n"); + buf.append(" formatter: function(row, column, cellValue, index) {\n" + + " if (cellValue == null || cellValue === '') {\n" + + " return ''\n" + + " }\n" + + " var name = column.property\n" + + "\n" + + " if (!dict.data.hasOwnProperty(name)) {\n" + + " return cellValue\n" + + " }\n" + + " if (!dict.data[name].hasOwnProperty(cellValue)) {\n" + + " return cellValue\n" + + " }\n" + + " return dict.data[name][cellValue]\n" + + " },\n" + + " get: function(name) {\n" + + " if (!dict.data.hasOwnProperty(name)) {\n" + + " return {}\n" + + " }\n" + + " let data2 = []\n" + + " for (var key in dict.data[name]) {\n" + + " data2.push({value: key, label: dict.data[name][key]})\n" + + " }\n" + + " return data2\n" + + " }\n" + + "}\n" + + "\n" + + "export default dict"); + + try { + FileUtils.write(new File("dict.js"), buf.toString(), "UTF-8"); + } catch (IOException e) { + msgLog.info(e.toString(), e); + resultT.setMsgCod(CommonMessageCode.FAIL); + resultT.setMsgInf(e.toString()); + return resultT; + } + resultT.setMsgCod(CommonMessageCode.SUCC); + + return resultT; + } + + public static void main(String[] args) { + Map map = new LinkedHashMap(); + map.put("2", "测试2"); + map.put("1", "测试1"); + map.put("4", "测试4"); + map.put("5", "测试5"); + + System.out.println(JSON.toJSONString(map)); + } +} diff --git a/ecp-mbu-web/src/test/resources/template/mng.vue.ftl b/ecp-mbu-web/src/test/resources/template/mng.vue.ftl index 756246d8..e0d181d8 100755 --- a/ecp-mbu-web/src/test/resources/template/mng.vue.ftl +++ b/ecp-mbu-web/src/test/resources/template/mng.vue.ftl @@ -15,8 +15,10 @@ border v-loading="dataListLoading" @selection-change="selectionChangeHandle" - style="width: 100%;"> + style="width: 100%;" + height="400">