Sfoglia il codice sorgente

虚拟账号导入

hu 3 mesi fa
parent
commit
bc60c06a40

+ 15 - 0
src/custom/restcontroller/R.java

@@ -5702,6 +5702,21 @@ public class R {
         public static class v1 {
         }
     }
+
+    public static class ID2025031110015803 {
+        public static class v1 {
+        }
+    }
+
+    public static class ID2025031110143103 {
+        public static class v1 {
+        }
+    }
+
+    public static class ID2025031110143903 {
+        public static class v1 {
+        }
+    }
 }
 
 

+ 239 - 0
src/custom/restcontroller/webmanage/sale/bankabcxccard/ExportExcel.java

@@ -0,0 +1,239 @@
+package restcontroller.webmanage.sale.bankabcxccard;
+
+
+import org.apache.poi.ss.usermodel.*;
+import org.apache.poi.ss.util.CellRangeAddress;
+import org.apache.poi.xssf.usermodel.*;
+
+import java.awt.*;
+import java.awt.Color;
+
+public class ExportExcel {
+    /**
+     * 设置标题单元样式
+     *
+     * @param workbook
+     * @return
+     */
+    public static XSSFCellStyle createTitleCellStyle1(XSSFWorkbook workbook) {
+        XSSFCellStyle cellStyle = workbook.createCellStyle();
+        XSSFFont font = workbook.createFont();
+        font.setFontHeightInPoints((short) 12);
+        font.setColor(IndexedColors.RED.getIndex());
+        font.setFontName("微软雅黑");// 设置标题字体
+        cellStyle.setFont(font);
+        cellStyle.setWrapText(true);  //自动换行
+        cellStyle = workbook.createCellStyle();
+        cellStyle.setFont(font);// 设置列标题样式
+        XSSFColor colorGrey = new XSSFColor(new Color(217, 225, 242));
+        cellStyle.setFillForegroundColor(colorGrey);
+        cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
+        cellStyle.setAlignment(HorizontalAlignment.LEFT); // 居左
+        return cellStyle;
+    }
+
+    /**
+     * 设置中文提示信息样式
+     *
+     * @param workbook
+     * @return
+     */
+    public static XSSFCellStyle createTitleCellStyle2(XSSFWorkbook workbook) {
+        XSSFCellStyle cellStyle = workbook.createCellStyle();
+        XSSFFont font = workbook.createFont();
+        font.setFontHeightInPoints((short) 12);
+        font.setColor(IndexedColors.WHITE.getIndex());
+        font.setFontName("微软雅黑");// 设置标题字体
+        cellStyle.setFont(font);
+        cellStyle.setWrapText(true);  //自动换行
+        cellStyle = workbook.createCellStyle();
+        cellStyle.setFont(font);// 设置列标题样式
+        XSSFColor colorBlue = new XSSFColor(new Color(48, 84, 150));
+        cellStyle.setFillForegroundColor(colorBlue);
+        cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
+        cellStyle.setAlignment(HorizontalAlignment.LEFT); // 居左
+        return cellStyle;
+    }
+
+    /**
+     * 设置中文提示信息样式
+     *
+     * @param workbook
+     * @return
+     */
+    public static XSSFCellStyle createTitleCellStyle3(XSSFWorkbook workbook) {
+        XSSFCellStyle cellStyle = workbook.createCellStyle();
+        XSSFFont font = workbook.createFont();
+        font.setFontHeightInPoints((short) 12);
+        font.setColor(IndexedColors.WHITE.getIndex());
+        font.setFontName("微软雅黑");// 设置标题字体
+        cellStyle.setFont(font);
+        cellStyle.setWrapText(true);  //自动换行
+        cellStyle = workbook.createCellStyle();
+        cellStyle.setFont(font);// 设置列标题样式
+        XSSFColor colorBlue = new XSSFColor(new Color(48, 84, 150));
+        cellStyle.setFillForegroundColor(colorBlue);
+        cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
+        cellStyle.setAlignment(HorizontalAlignment.CENTER); // 居左
+        return cellStyle;
+    }
+
+    /**
+     * 设置正文单元样式
+     *
+     * @param workbook
+     * @return
+     */
+    public static XSSFCellStyle createBodyCellStyle(XSSFWorkbook workbook) {
+        XSSFCellStyle cellStyle = workbook.createCellStyle();
+        XSSFFont font = workbook.createFont();
+        font.setFontHeightInPoints((short) 12);
+        font.setFontName("微软雅黑");// 设置标题字体
+        // font.setFontName(HSSFFont.FONT_ARIAL);// 设置标题字体
+        cellStyle.setFont(font);
+        cellStyle = workbook.createCellStyle();
+        cellStyle.setAlignment(HorizontalAlignment.LEFT); // 居左
+        return cellStyle;
+    }
+
+    /**
+     * 2022-07-14 17:41:39
+     * 设置表格宽度(导入模板)
+     **/
+    public static void setBatchDetailSheetColumn1(XSSFSheet sheet) {
+        sheet.setDefaultRowHeight((short) 600);
+        sheet.setColumnWidth((short) 0, (short) 8500);
+    }
+
+
+    /**
+     * 2022-07-14 17:41:39
+     * 设置表格宽度(返回错误Excel的样式)
+     **/
+    public static void setBatchDetailSheetColumn2(XSSFSheet sheet) {
+        sheet.setDefaultRowHeight((short) 600);
+        sheet.setColumnWidth((short) 0, (short) 8500);
+        sheet.setColumnWidth((short) 1, (short) 8500);
+    }
+
+    /**
+     * 2022-07-14 17:42:03
+     * 设置表头
+     * cellStyle1 中文提示信息样式
+     * cellStyle2 标题提示信息样式
+     * cellStyle3 正文提示信息样式
+     **/
+    public static void batchDetail(XSSFSheet sheet, XSSFCellStyle cellStyle1, XSSFCellStyle cellStyle2, XSSFCellStyle cellStyle3, XSSFCellStyle cellStyle4, XSSFWorkbook workbook) {
+//        HSSFCellStyle bcs = ExportExcel.createTitleCellStyle1(workbook);
+//        bcs.setBorderBottom(BorderStyle.THIN); //下边框
+//        bcs.setBorderLeft(BorderStyle.THIN);//左边框
+//        bcs.setBorderTop(BorderStyle.THIN);//上边框
+//        bcs.setBorderRight(BorderStyle.THIN);//右边框
+//        bcs.setWrapText(true);
+
+
+        XSSFRow row = null;
+        XSSFCell cell = null;
+
+        cellStyle1.setBorderBottom(BorderStyle.THIN); //下边框
+        cellStyle1.setBorderLeft(BorderStyle.THIN);//左边框
+        cellStyle1.setBorderTop(BorderStyle.THIN);//上边框
+        cellStyle1.setBorderRight(BorderStyle.THIN);//右边框
+        cellStyle1.setWrapText(true);
+
+        cellStyle2.setBorderBottom(BorderStyle.THIN); //下边框
+        cellStyle2.setBorderLeft(BorderStyle.THIN);//左边框
+        cellStyle2.setBorderTop(BorderStyle.THIN);//上边框
+        cellStyle2.setBorderRight(BorderStyle.THIN);//右边框
+        cellStyle2.setWrapText(true);
+        DataFormat format = workbook.createDataFormat();
+        cellStyle1.setDataFormat(format.getFormat("@"));
+        cellStyle2.setDataFormat(format.getFormat("@"));
+        cellStyle3.setDataFormat(format.getFormat("@"));
+        /*第一行*/
+        //sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 0));
+
+        /*第一行塞值*/
+        row = sheet.createRow(0);
+        cell = row.createCell(0);// ID
+        cell.setCellStyle(cellStyle4);
+        cell.setCellValue("虚拟账号导入");
+        /*第二行*/
+        //sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, 0));
+        /*第二行塞值*/
+        row = sheet.createRow(1);
+        cell = row.createCell(0);// ID
+        cell.setCellStyle(cellStyle1);
+        cell.setCellValue("注意:①请按照以下示例填写虚拟账号;②虚拟账号最多不超过5000行;③虚拟账号导入前,请记得删除示例行!");
+        /*第三行塞值*/
+        row = sheet.createRow(2);
+
+        cell = row.createCell(0);
+        cell.setCellStyle(cellStyle2);
+        cell.setCellValue("虚拟账号(必填)");
+
+
+
+        /*第四行塞值*/
+        row = sheet.createRow(3);
+
+        cell = row.createCell(0);
+        cell.setCellStyle(cellStyle3);
+        cell.setCellValue("1234567891011");
+
+
+    }
+
+
+    /**
+     * 2022-07-14 17:42:03
+     * 设置表头
+     **/
+    public static void batchDetailErr(XSSFSheet sheet, XSSFCellStyle cellStyle1, XSSFCellStyle cellStyle2, XSSFCellStyle cellStyle3, XSSFWorkbook workbook) {
+//        HSSFCellStyle bcs = ExportExcel.createTitleCellStyle1(workbook);
+//        bcs.setBorderBottom(BorderStyle.THIN); //下边框
+//        bcs.setBorderLeft(BorderStyle.THIN);//左边框
+//        bcs.setBorderTop(BorderStyle.THIN);//上边框
+//        bcs.setBorderRight(BorderStyle.THIN);//右边框
+//        bcs.setWrapText(true);
+
+
+        XSSFRow row = null;
+        XSSFCell cell = null;
+
+        cellStyle1.setBorderBottom(BorderStyle.THIN); //下边框
+        cellStyle1.setBorderLeft(BorderStyle.THIN);//左边框
+        cellStyle1.setBorderTop(BorderStyle.THIN);//上边框
+        cellStyle1.setBorderRight(BorderStyle.THIN);//右边框
+        cellStyle1.setWrapText(true);
+
+
+
+        /*第一行*/
+        sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 1));
+
+        /*第一行塞值*/
+        row = sheet.createRow(0);
+        cell = row.createCell(0);// ID
+        cell.setCellStyle(cellStyle3);
+        cell.setCellValue("虚拟账号导入");
+        /*第二行*/
+        sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, 1));
+        /*第二行塞值*/
+        row = sheet.createRow(1);
+        cell = row.createCell(0);// ID
+        cell.setCellStyle(cellStyle1);
+        cell.setCellValue("注意:①请按照以下示例填写虚拟账号;②虚拟账号最多不超过5000行;③虚拟账号导入前,请记得删除示例行!");
+        /*第三行塞值*/
+        row = sheet.createRow(2);
+
+        cell = row.createCell(0);
+        cell.setCellStyle(cellStyle2);
+        cell.setCellValue("虚拟账号(必填)");
+
+        cell = row.createCell(1);
+        cell.setCellStyle(cellStyle2);
+        cell.setCellValue("错误信息");
+
+    }
+}

+ 247 - 0
src/custom/restcontroller/webmanage/sale/bankabcxccard/bankabcxccard.java

@@ -0,0 +1,247 @@
+package restcontroller.webmanage.sale.bankabcxccard;
+
+import com.alibaba.fastjson.JSONObject;
+import common.Controller;
+import common.YosException;
+import common.annotation.API;
+import common.annotation.CACHEING;
+import common.annotation.CACHEING_CLEAN;
+import common.data.*;
+import org.apache.commons.lang.StringUtils;
+import org.apache.poi.ss.usermodel.CellStyle;
+import org.apache.poi.ss.usermodel.CellType;
+import org.apache.poi.ss.usermodel.DataFormat;
+import org.apache.poi.xssf.usermodel.*;
+import restcontroller.R;
+import restcontroller.webmanage.sale.rebatescheme.ExportExcel;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+
+public class bankabcxccard extends Controller {
+    public bankabcxccard(JSONObject content) throws YosException {
+        super(content);
+    }
+
+    @API(title = "虚拟账号列表", apiversion = R.ID2025031110015803.v1.class)
+    @CACHEING
+    public String queryList() throws YosException {
+        StringBuffer where = new StringBuffer(" 1=1 ");
+        if (content.containsKey("where")) {
+            JSONObject whereObject = content.getJSONObject("where");
+            if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
+                where.append(" and(");
+                where.append("t1.xncardnoabc like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append("or t2.agentnum like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append(")");
+            }
+            if (whereObject.containsKey("isused") && !"".equals(whereObject.getString("isused"))) {
+                where.append(" and t1.isused ='").append(whereObject.getString("isused")).append("' ");
+            }
+        }
+        QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_bankabcxccard", "*");
+        querySQL.setTableAlias("t1");
+        querySQL.addJoinTable(JOINTYPE.left, "sa_agents", "t2", "t2.sa_agentsid = t1.sa_agentsid AND t2.siteid = t1.siteid","agentnum");
+        querySQL.addJoinTable(JOINTYPE.left, "sys_enterprise", "t3", "t2.sys_enterpriseid = t3.sys_enterpriseid AND t2.siteid = t3.siteid","enterprisename","abbreviation");
+        querySQL.setSiteid(siteid);
+        querySQL.setWhere(where.toString());
+        querySQL.setPage(pageSize, pageNumber);
+        querySQL.setOrderBy(pageSorting);
+        Rows rows = querySQL.query();
+        return getSucReturnObject().setData(rows).toString();
+    }
+
+
+
+    @API(title = "导入虚拟账号", apiversion = R.ID2025031110143103.v1.class)
+    @CACHEING_CLEAN(apiClass = {bankabcxccard.class})
+    public String importXnCard() throws YosException {
+        ArrayList<String> sqlList = new ArrayList<>();
+
+
+        ExcelFactory e;
+        try {
+
+            // 华为云
+            e = getPostExcelFactory(content.getLong("attachmentid"));
+            // 本地
+            //e = getPostExcelFactory();
+
+            ArrayList<String> keys = new ArrayList<>();
+            keys.add("xncardnoabc");
+            HashMap<String, CellType> cellMap = new HashMap<>();
+            cellMap.put("xncardnoabc", CellType.STRING);
+            Rows rows = e.getSheetRows(0, keys, cellMap, 3);
+
+            ArrayList<String> xncardnoabcList = rows.toArrayList("xncardnoabc",false);
+            xncardnoabcList.add("-1");
+
+            boolean iserr = false;
+            Rows rowserr = new Rows();
+            Rows rowssuc = new Rows();
+            QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_bankabcxccard", "xncardnoabc");
+            querySQL.setSiteid(siteid);
+            querySQL.setWhere("xncardnoabc", xncardnoabcList);
+            RowsMap xncardnoabcRowsMap = querySQL.query().toRowsMap("xncardnoabc");
+            for (Row row : rows) {
+                if (StringUtils.isEmpty(row.getString("xncardnoabc"))) {
+                    iserr = true;
+                    row.put("msg", "错误信息:虚拟账号不能为空");
+                    rowserr.add(row);
+                    continue;
+                } else {
+                    String xncardnoabc = row.getString("xncardnoabc");
+                    System.out.println(xncardnoabc);
+                    System.out.println(xncardnoabcList.indexOf(xncardnoabc));
+                    System.out.println( xncardnoabcList.lastIndexOf(xncardnoabc));
+
+                    if (xncardnoabcList.indexOf(xncardnoabc) != xncardnoabcList.lastIndexOf(xncardnoabc)) {
+                        iserr = true;
+                        row.put("msg", "错误信息:导入文件存在相同编码的虚拟账号");
+                        rowserr.add(row);
+                        continue;
+                    }
+                    if (xncardnoabcRowsMap.containsKey(xncardnoabc)) {
+                        iserr = true;
+                        row.put("msg", "错误信息:已存在" + xncardnoabc + "的虚拟账号");
+                        rowserr.add(row);
+                        continue;
+                    }
+
+                }
+                rowssuc.add(row);
+
+            }
+
+            if (!rowssuc.isEmpty()) {
+                for (Row row : rowssuc) {
+                    Long sa_bankabcxccardid = createTableID("sa_bankabcxccard");
+                    InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sa_bankabcxccard");
+                    insertSQL.setValue("sa_bankabcxccardid", sa_bankabcxccardid);
+                    insertSQL.setValue("siteid", siteid);
+                    insertSQL.setValue("xncardnoabc", row.getString("xncardnoabc"));
+                    insertSQL.setValue("sa_agentsid", 0);
+                    insertSQL.setValue("isused", 0);
+                    insertSQL.setValue("createby", username);
+                    insertSQL.setDateValue("createdate");
+                    insertSQL.setValue("changeby", username);
+                    insertSQL.setDateValue("changedate");
+                    System.err.println(insertSQL.getSQL());
+                    sqlList.add(insertSQL.getSQL());
+                }
+            }
+            if (!sqlList.isEmpty()) {
+                dbConnect.runSqlUpdate(sqlList);
+            }
+
+            if (iserr) {
+                ExcelFactory excelFactory = new ExcelFactory("虚拟账号导入错误信息");
+                HashMap<String, String> map = new HashMap<String, String>();
+                map.put("xncardnoabc", "虚拟账号");
+                map.put("msg", "错误信息");
+                ArrayList<String> colNameList = new ArrayList<String>();
+                HashMap<String, Class> keytypemap = new HashMap<String, Class>();
+                colNameList.add("xncardnoabc");
+                colNameList.add("msg");
+                keytypemap.put("xncardnoabc", String.class);
+                keytypemap.put("msg", String.class);
+                rowserr.setFieldList(colNameList);
+                rowserr.setFieldTypeMap(keytypemap);
+                addSheet(excelFactory, "Sheet1", rowserr, map);
+
+                Rows aa = uploadExcelToObs(excelFactory);
+                String url = "";
+                if (!aa.isEmpty()) {
+                    url = aa.get(0).getString("url");
+                }
+                return getErrReturnObject().setErrMsg(url).toString();
+            }
+        } catch (Exception e1) {
+            e1.printStackTrace();
+            return getErrReturnObject().setErrMsg(e1.getMessage()).toString();
+        }
+        return getSucReturnObject().toString();
+    }
+
+    /**
+     * 下载虚拟账号导入模板
+     *
+     * @return
+     */
+    @API(title = "下载虚拟账号导入模板", apiversion = R.ID2025031110143903.v1.class)
+    public String downloadXnCardExcel() throws YosException {
+        ExcelFactory excelFactory = new ExcelFactory("虚拟账号导入模板");
+
+        XSSFSheet sheet = excelFactory.getXssfWorkbook().createSheet("Sheet1");
+        XSSFWorkbook xssfFWorkbook = excelFactory.getXssfWorkbook();
+
+        CellStyle style = xssfFWorkbook.createCellStyle();
+        // 设置为文本格式,防止身份证号变成科学计数法
+        DataFormat format = xssfFWorkbook.createDataFormat();
+        style.setDataFormat(format.getFormat("@"));
+        // 对单独某一列进行样式赋值,第一个参数为列数,第二个参数为样式
+        sheet.setDefaultColumnStyle(0, style);
+
+
+        restcontroller.webmanage.sale.bankabcxccard.ExportExcel.setBatchDetailSheetColumn1(sheet);// 设置工作薄列宽
+        XSSFCellStyle titleCellStyle1 = restcontroller.webmanage.sale.bankabcxccard.ExportExcel.createTitleCellStyle1(xssfFWorkbook);
+        XSSFCellStyle titleCellStyle2 = restcontroller.webmanage.sale.bankabcxccard.ExportExcel.createTitleCellStyle2(xssfFWorkbook);
+        XSSFCellStyle titleCellStyle3 = restcontroller.webmanage.sale.bankabcxccard.ExportExcel.createBodyCellStyle(xssfFWorkbook);
+        XSSFCellStyle titleCellStyle4 = restcontroller.webmanage.sale.bankabcxccard.ExportExcel.createTitleCellStyle3(xssfFWorkbook);
+        restcontroller.webmanage.sale.bankabcxccard.ExportExcel.batchDetail(sheet, titleCellStyle1, titleCellStyle2, titleCellStyle3, titleCellStyle4,
+                xssfFWorkbook);// 写入标题
+
+        Rows aa = uploadExcelToObs(excelFactory);
+        String url = "";
+        if (!aa.isEmpty()) {
+            url = aa.get(0).getString("url");
+        }
+        return getSucReturnObject().setData(url).toString();
+
+    }
+
+    public XSSFSheet addSheet(ExcelFactory excelFactory, String sheetname, Rows datarows,
+                              HashMap<String, String> titlemap) {
+        ArrayList<String> keylist = datarows.getFieldList();
+        XSSFSheet sheet = excelFactory.getXssfWorkbook().createSheet(sheetname);
+        XSSFWorkbook xssfFWorkbook = excelFactory.getXssfWorkbook();
+
+        XSSFCellStyle xssfCellStyle1 = xssfFWorkbook.createCellStyle();
+        XSSFFont font = xssfFWorkbook.createFont();
+
+        font.setColor((short) 0xa);
+        font.setFontHeightInPoints((short) 12);
+        font.setBold(true);
+        xssfCellStyle1.setFont(font);
+
+        restcontroller.webmanage.sale.bankabcxccard.ExportExcel.setBatchDetailSheetColumn2(sheet);// 设置工作薄列宽
+        XSSFCellStyle titleCellStyle1 = restcontroller.webmanage.sale.bankabcxccard.ExportExcel.createTitleCellStyle1(xssfFWorkbook);
+        XSSFCellStyle titleCellStyle2 = restcontroller.webmanage.sale.bankabcxccard.ExportExcel.createTitleCellStyle2(xssfFWorkbook);
+        XSSFCellStyle titleCellStyle3 = restcontroller.webmanage.sale.bankabcxccard.ExportExcel.createTitleCellStyle3(xssfFWorkbook);
+        ExportExcel.batchDetailErr(sheet, titleCellStyle1, titleCellStyle2, titleCellStyle3, xssfFWorkbook);// 写入标题
+
+        for (int n = 0; n < datarows.size(); n++) {
+            Row row = datarows.get(n);
+            XSSFRow datarow = sheet.createRow(n + 3);
+            for (int i1 = 0; i1 < keylist.size(); i1++) {
+                Class fieldclazztype = datarows.getFieldMeta(keylist.get(i1)).getFieldtype();
+                if (fieldclazztype == Integer.class) {
+                    datarow.createCell(i1).setCellValue(row.getInteger((String) keylist.get(i1)));
+                } else if (fieldclazztype == Long.class) {
+                    datarow.createCell(i1).setCellValue(row.getLong((String) keylist.get(i1)));
+                } else if (fieldclazztype == Float.class) {
+                    datarow.createCell(i1).setCellValue(row.getFloat((String) keylist.get(i1)));
+                } else if (fieldclazztype == Double.class) {
+                    datarow.createCell(i1).setCellValue(row.getDouble((String) keylist.get(i1)));
+                } else {
+                    datarow.createCell(i1).setCellValue(row.getString((String) keylist.get(i1)));
+                }
+                if (i1 == 1) {
+                    datarow.getCell(i1).setCellStyle(xssfCellStyle1);
+                }
+            }
+        }
+        return sheet;
+    }
+
+}