Sfoglia il codice sorgente

业绩目标导入

hu 1 anno fa
parent
commit
7fef2bd870

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

@@ -5293,6 +5293,14 @@ public class R {
         public static class v1 {
         }
     }
+    public static class ID20231020111203 {
+        public static class v1 {
+        }
+    }
+    public static class ID20231020111303 {
+        public static class v1 {
+        }
+    }
 
 }
 

+ 0 - 1
src/custom/restcontroller/webmanage/lsak3/item/SQL/货品档案更新.sql

@@ -41,7 +41,6 @@ SET changeuserid=$userid$,
     sa_customschemeid=$sa_customschemeid$,
     financeclasstype=$financeclasstype$,
     stockno=$stockno$,
-    marketingcategory=$marketingcategory$,
     volume=$volume$,
     widthschemeid=$widthschemeid$,
     lengthschemeid=$lengthschemeid$,

+ 5 - 0
src/custom/restcontroller/webmanage/sale/salestarget/SQL/人员-查询可导入区域信息.sql

@@ -0,0 +1,5 @@
+SELECT sa_saleareaid,areaname
+FROM  sa_salearea
+WHERE areaname IN $areaname$
+  AND areaname not in('来斯奥','销售部')
+  AND siteid = $siteid$

+ 0 - 8
src/custom/restcontroller/webmanage/sale/salestarget/SQL/人员-查询可导入用户信息.sql

@@ -1,8 +0,0 @@
-SELECT t1.hrid, t1.phonenumber, t1.name, t1.departmentid, t1.position, t2.depname, t4.areaname
-FROM sys_hr t1
-         INNER JOIN sys_department t2 on t1.departmentid = t2.departmentid
-         INNER JOIN sa_salearea_hr t3 on t1.hrid = t3.hrid
-         INNER JOIN sa_salearea t4 on t3.sa_saleareaid = t4.sa_saleareaid
-WHERE phonenumber IN $phonenumber$
-  AND t1.hrid not in (SELECt hrid from sa_salestargethr WHERE sa_salestargetbillid = $sa_salestargetbillid$ AND siteid = $siteid$)
-  AND t1.siteid = $siteid$

+ 5 - 0
src/custom/restcontroller/webmanage/sale/salestarget/SQL/企业-查询可导入经销商信息.sql

@@ -0,0 +1,5 @@
+SELECT agentnum,sys_enterpriseid
+FROM  sa_agents
+WHERE agentnum IN $agentnum$
+  AND sys_enterpriseid not in (SELECt sys_enterpriseid from sa_salestargethr WHERE sa_salestargetbillid = $sa_salestargetbillid$ AND siteid = $siteid$)
+  AND siteid = $siteid$

+ 419 - 0
src/custom/restcontroller/webmanage/sale/salestarget/enterpriseexcel.java

@@ -0,0 +1,419 @@
+package restcontroller.webmanage.sale.salestarget;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import common.YosException;
+import org.apache.poi.ss.usermodel.BorderStyle;
+import org.apache.poi.ss.usermodel.HorizontalAlignment;
+import org.apache.poi.ss.usermodel.VerticalAlignment;
+import org.apache.poi.ss.util.CellRangeAddress;
+import org.apache.poi.xssf.usermodel.*;
+
+public class enterpriseexcel {
+
+    /**
+     * 2022-07-14 17:41:39
+     * 设置表格宽度(导入模板)
+     **/
+    public static void setBatchDetailSheetColumn1(XSSFSheet sheet) {
+        sheet.setDefaultRowHeight((short) 600);
+        short width = 3500;
+        sheet.setColumnWidth((short) 0, 4000);
+        sheet.setColumnWidth((short) 1, 4000);
+        for (int i = 1; i < 20; i++) {
+            sheet.setColumnWidth((short) i, width);
+        }
+
+    }
+
+
+    /**
+     * 2022-07-14 17:41:39
+     * 设置表格宽度(返回错误Excel的样式)
+     **/
+    public static void setBatchDetailSheetColumn2(XSSFSheet sheet) {
+        sheet.setDefaultRowHeight((short) 600);
+        short width = 3000;
+        sheet.setColumnWidth((short) 0, 4000);
+        sheet.setColumnWidth((short) 1, 4000);
+        for (int i = 1; i < 18; i++) {
+            sheet.setColumnWidth((short) i, width);
+        }
+        sheet.setColumnWidth((short) 20, width * 2);
+
+    }
+
+    /**
+     * 2022-07-14 17:42:03
+     * 设置表头
+     * cellStyle1 中文提示信息样式
+     * cellStyle2 标题提示信息样式
+     * cellStyle3 正文提示信息样式
+     **/
+    public static void batchDetail(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);
+
+        cellStyle2.setBorderBottom(BorderStyle.THIN); //下边框
+        cellStyle2.setBorderLeft(BorderStyle.THIN);//左边框
+        cellStyle2.setBorderTop(BorderStyle.THIN);//上边框
+        cellStyle2.setBorderRight(BorderStyle.THIN);//右边框
+        cellStyle2.setWrapText(true);
+        /*第一行*/
+        sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 17));//2.申请年度单位
+
+        /*第一行塞值*/
+        row = sheet.createRow(0);
+        cell = row.createCell(0);// ID
+        cell.setCellStyle(cellStyle1);
+        cell.setCellValue("注意:①请按照以下示例填写信息;②最多不超过5000行;③导入前,请记得删除示例行!");
+
+        /*第二行塞值*/
+        row = sheet.createRow(1);
+
+        cell = row.createCell(0);
+        cell.setCellStyle(cellStyle2);
+        cell.setCellValue("经销商编码");
+
+        cell = row.createCell(1);
+        cell.setCellStyle(cellStyle2);
+        cell.setCellValue("年度(基本)");
+
+
+        cell = row.createCell(2);
+        cell.setCellStyle(cellStyle2);
+        cell.setCellValue("1季度(基本)");
+
+
+        cell = row.createCell(3);
+        cell.setCellStyle(cellStyle2);
+        cell.setCellValue("2季度(基本)");
+
+
+        cell = row.createCell(4);
+        cell.setCellStyle(cellStyle2);
+        cell.setCellValue("3季度(基本)");
+
+
+        cell = row.createCell(5);
+        cell.setCellStyle(cellStyle2);
+        cell.setCellValue("4季度(基本)");
+
+
+        for (int i = 1; i < 13; i++) {
+            cell = row.createCell(i + 5);
+            cell.setCellStyle(cellStyle2);
+            cell.setCellValue(i + "月(基本)");
+
+        }
+
+
+
+
+
+        /*第三行塞值*/
+        row = sheet.createRow(2);
+
+        cell = row.createCell(0);
+        cell.setCellStyle(cellStyle3);
+        cell.setCellValue("名称");
+
+        for (int i = 1; i < 18; i++) {
+            cell = row.createCell(i);
+            cell.setCellStyle(cellStyle3);
+            cell.setCellValue("0");
+
+        }
+
+
+    }
+
+
+    /**
+     * 2022-07-14 17:42:03
+     * 设置表头
+     **/
+    public static void batchDetailErr(XSSFSheet sheet, XSSFCellStyle cellStyle1, XSSFCellStyle cellStyle2, 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, 18));//2.提示信息
+
+        /*第一行塞值*/
+        row = sheet.createRow(0);
+        cell = row.createCell(0);// ID
+        cell.setCellStyle(cellStyle1);
+        cell.setCellValue("注意:①请按照以下示例填写信息;②最多不超过5000行;③导入前,请记得删除示例行!");
+
+
+        /*第二行塞值*/
+        row = sheet.createRow(1);
+
+        cell = row.createCell(0);
+        cell.setCellStyle(cellStyle2);
+        cell.setCellValue("经销商编码(必填)");
+
+
+
+        cell = row.createCell(1);
+        cell.setCellStyle(cellStyle2);
+        cell.setCellValue("年度(基本)");
+
+
+        cell = row.createCell(2);
+        cell.setCellStyle(cellStyle2);
+        cell.setCellValue("1季度(基本)");
+
+
+        cell = row.createCell(3);
+        cell.setCellStyle(cellStyle2);
+        cell.setCellValue("2季度(基本)");
+
+
+        cell = row.createCell(4);
+        cell.setCellStyle(cellStyle2);
+        cell.setCellValue("3季度(基本)");
+
+        cell = row.createCell(5);
+        cell.setCellStyle(cellStyle2);
+        cell.setCellValue("4季度(基本)");
+
+
+        for (int i = 1; i < 13; i++) {
+            cell = row.createCell( i + 5);
+            cell.setCellStyle(cellStyle2);
+            cell.setCellValue(i + "月(基本)");
+        }
+
+        cell = row.createCell(18);
+        cell.setCellStyle(cellStyle2);
+        cell.setCellValue("错误信息");
+
+
+    }
+
+    public static void setBatchDetailSheetColumn3(XSSFSheet sheet) {
+        sheet.setDefaultRowHeight((short) 700);
+        short width = 3500;
+        sheet.setColumnWidth((short) 0, 4000);
+        sheet.setColumnWidth((short) 1, 4000);
+        for (int i = 1; i < 19; i++) {
+            sheet.setColumnWidth((short) i, width);
+        }
+
+    }
+
+    public static void batchDetailExport(XSSFSheet sheet, XSSFCellStyle cellStyle1, XSSFCellStyle cellStyle2, XSSFCellStyle cellStyle3, XSSFWorkbook workbook, JSONArray dataArrays) throws YosException {
+
+        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.setAlignment(HorizontalAlignment.CENTER);
+        cellStyle2.setVerticalAlignment(VerticalAlignment.CENTER);
+        cellStyle2.setWrapText(true);
+
+        cellStyle3.setAlignment(HorizontalAlignment.CENTER);
+        cellStyle3.setVerticalAlignment(VerticalAlignment.CENTER);
+        cellStyle3.setWrapText(true);
+
+        XSSFCellStyle cellStyle = workbook.createCellStyle();
+        // 创建一个字体
+        XSSFFont fontRed = workbook.createFont();
+        fontRed.setColor((short) 0xa); // 字体颜色
+        XSSFFont fontGreen = workbook.createFont();
+        fontGreen.setColor((short) 0xb); // 字体颜色
+        cellStyle.setAlignment(HorizontalAlignment.CENTER);
+        cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
+        cellStyle.setWrapText(true);
+
+
+        //第一行
+        row = sheet.createRow(0);
+        String[] title = {"部门", "人员", "职位", "目标/实际"};
+        for (int i = 0; i < title.length; i++) {
+            sheet.addMergedRegion(new CellRangeAddress(0, 1, i, i));
+            cell = row.createCell(i);
+            cell.setCellStyle(cellStyle2);
+            cell.setCellValue(title[i]);
+        }
+        String[] title2 =
+                {
+                        "年度(万元)",
+                        "第一季度(万元)", "一月(万元)", "二月(万元)", "三月(万元)",
+                        "第二季度(万元)", "四月(万元)", "五月(万元)", "六月(万元)",
+                        "第三季度(万元)", "七月(万元)", "八月(万元)", "九月(万元)",
+                        "第四季度(万元)", "十月(万元)", "十一月(万元)", "十二月(万元)"
+                };
+        for (int i = 0; i < title2.length; i++) {
+            sheet.addMergedRegion(new CellRangeAddress(0, 0, 2 * i + 4, 2 * i + 5));
+            cell = row.createCell(2 * i + 4);
+            cell.setCellStyle(cellStyle2);
+            cell.setCellValue(title2[i]);
+        }
+
+        //第二行
+        row = sheet.createRow(1);
+        for (int i = 0; i < 38; i++) {
+            cell = row.createCell(i);
+            cell.setCellStyle(cellStyle2);
+            if (i >= 4) {
+                cell.setCellValue("基本");
+                if (i % 2 == 1) {
+                    cell.setCellValue("挑战");
+                }
+            }
+        }
+
+        int rownum = 2;
+        for (Object data : dataArrays) {
+            JSONObject dataRow = (JSONObject) data;
+            //目标
+            row = sheet.createRow(rownum);
+            sheet.addMergedRegion(new CellRangeAddress(rownum, rownum + 1, 0, 0));
+            cell = row.createCell(0);
+            cell.setCellStyle(cellStyle3);
+            cell.setCellValue(dataRow.getString("depfullname"));
+
+            sheet.addMergedRegion(new CellRangeAddress(rownum, rownum + 1, 1, 1));
+            cell = row.createCell(1);
+            cell.setCellStyle(cellStyle3);
+            cell.setCellValue(dataRow.containsKey("name") ? dataRow.getString("name") : "");
+
+            sheet.addMergedRegion(new CellRangeAddress(rownum, rownum + 1, 2, 2));
+            cell = row.createCell(2);
+            cell.setCellStyle(cellStyle3);
+            cell.setCellValue(dataRow.containsKey("position") ? dataRow.getString("position") : "");
+
+            cell = row.createCell(3);
+            cell.setCellStyle(cellStyle3);
+            cell.setCellValue("目标");
+
+            String[] keys =
+                    {
+                            "y1l", "y1h",
+                            "s1l", "s1h",
+                            "m1l", "m1h", "m2l", "m2h", "m3l", "m3h",
+                            "s2l", "s2h",
+                            "m4l", "m4h", "m5l", "m5h", "m6l", "m6h",
+                            "s3l", "s3h",
+                            "m7l", "m7h", "m8l", "m8h", "m9l", "m9h",
+                            "s4l", "s4h",
+                            "m10l", "m10h", "m11l", "m11h", "m12l", "m12h",
+                    };
+
+            for (int i = 4; i < 38; i++) {
+                cell = row.createCell(i);
+                cell.setCellStyle(cellStyle3);
+                cell.setCellValue(dataRow.getString(keys[i - 4]));
+
+            }
+            /*第三行塞值*/
+            row = sheet.createRow(rownum + 1);
+
+            cell = row.createCell(0);
+            cell.setCellStyle(cellStyle3);
+
+            cell = row.createCell(1);
+            cell.setCellStyle(cellStyle3);
+
+            cell = row.createCell(2);
+            cell.setCellStyle(cellStyle3);
+
+            cell = row.createCell(3);
+            cell.setCellStyle(cellStyle3);
+            cell.setCellValue("实际");
+
+            String[] keys2 =
+                    {
+                            "y1a", "y1a",
+                            "s1a", "s1a",
+                            "m1a", "m1a", "m2a", "m2a", "m3a", "m3a",
+                            "s2a", "s2a",
+                            "m4a", "m4a", "m5a", "m5a", "m6a", "m6a",
+                            "s3a", "s3a",
+                            "m7a", "m7a", "m8a", "m8a", "m9a", "m9a",
+                            "s4a", "s4a",
+                            "m10a", "m10a", "m11a", "m11a", "m12a", "m12a",
+                    };
+            String[] keys3 =
+                    {
+                            "y1pl", "y1ph",
+                            "s1pl", "s1ph",
+                            "m1pl", "m1ph", "m2pl", "m2ph", "m3pl", "m3ph",
+                            "s2pl", "s2ph",
+                            "m4pl", "m4ph", "m5pl", "m5ph", "m6pl", "m6ph",
+                            "s3pl", "s3ph",
+                            "m7pl", "m7ph", "m8pl", "m8ph", "m9pl", "m9ph",
+                            "s4pl", "s4ph",
+                            "m10pl", "m10ph", "m11pl", "m11ph", "m12pl", "m12ph",
+                    };
+
+            for (int i = 4; i < 38; i++) {
+                cell = row.createCell(i);
+                String text1 = dataRow.getString(keys2[i - 4]);
+                String text2 = dataRow.getString(keys3[i - 4]);
+                String text = text1 + "\r\n" + "(" + text2 + "%)";
+                XSSFRichTextString hrt = workbook.getCreationHelper().createRichTextString(text);
+                if (text2.contains("-")) {
+                    hrt.applyFont(text1.length() + 2, text.length(), fontGreen);
+                } else if (text2.equals("0")) {
+
+                } else {
+                    hrt.applyFont(text1.length() + 2, text.length(), fontRed);
+                }
+
+                cell.setCellStyle(cellStyle);
+                cell.setCellValue(hrt);
+
+            }
+            rownum = rownum + 2;
+
+        }
+
+
+    }
+
+
+}

+ 270 - 3
src/custom/restcontroller/webmanage/sale/salestarget/enterprisetarget.java

@@ -8,12 +8,14 @@ import common.YosException;
 import common.annotation.API;
 import common.annotation.CACHEING_CLEAN;
 import common.annotation.cm;
-import common.data.Row;
-import common.data.Rows;
-import common.data.SQLFactory;
+import common.data.*;
+import org.apache.commons.lang.StringUtils;
+import org.apache.poi.xssf.usermodel.*;
 import restcontroller.R;
+import restcontroller.webmanage.saletool.orderclue.ExportExcel;
 
 import java.util.ArrayList;
+import java.util.HashMap;
 
 public class enterprisetarget extends Controller {
     /**
@@ -229,4 +231,269 @@ public class enterprisetarget extends Controller {
         return getSucReturnObject().setData(rows).toString();
 
     }
+
+    @API(title = "企业目标导入模板", apiversion = R.ID20231020111203.v1.class)
+    public String downloadExcel() throws YosException {
+
+        ExcelFactory excelFactory = new ExcelFactory("企业目标导入模板");
+
+        XSSFSheet sheet = excelFactory.getXssfWorkbook().createSheet("Sheet1");
+        XSSFWorkbook xssfFWorkbook = excelFactory.getXssfWorkbook();
+        enterpriseexcel.setBatchDetailSheetColumn1(sheet);// 设置工作薄列宽
+        XSSFCellStyle titleCellStyle1 = ExportExcel.createTitleCellStyle1(xssfFWorkbook);
+        XSSFCellStyle titleCellStyle2 = ExportExcel.createTitleCellStyle2(xssfFWorkbook);
+        XSSFCellStyle titleCellStyle3 = ExportExcel.createBodyCellStyle(xssfFWorkbook);
+        enterpriseexcel.batchDetail(sheet, titleCellStyle1, titleCellStyle2, titleCellStyle3, xssfFWorkbook);// 写入标题
+
+        Rows aa = uploadExcelToObs(excelFactory);
+        String url = "";
+        if (!aa.isEmpty()) {
+            url = aa.get(0).getString("url");
+        }
+        return getSucReturnObject().setData(url).toString();
+
+    }
+
+    @API(title = "企业目标导入", apiversion = R.ID20231020111303.v1.class)
+    @CACHEING_CLEAN(apiClass = {enterprisetarget.class,restcontroller.sale.salestarget.enterprise.class})
+    public String enterpriseTargetImport() throws YosException {
+
+        Long sa_salestargetbillid = content.getLong("sa_salestargetbillid");
+        Long year = content.getLong("year");
+        ExcelFactory e;
+
+        try {
+            if (content.getLong("attachmentid") > 0) {
+                e = getPostExcelFactory(content.getLong("attachmentid"));
+                // 本地
+                //e = getPostExcelFactory();
+            } else {
+                e = getPostExcelFactory();
+                // 本地
+                //e = getPostExcelFactory();
+            }
+
+
+            ArrayList<String> keys = new ArrayList<>();
+            ArrayList<String> sqllist = new ArrayList<>();
+
+            keys.add("name");
+            String keyl = "y1l";
+            keys.add(keyl);
+            for (int i = 1; i < 5; i++) {
+                keyl = "s" + i + "l";
+                keys.add(keyl);
+            }
+
+            for (int i = 1; i < 13; i++) {
+                keyl = "m" + i + "l";
+                keys.add(keyl);
+            }
+            Rows rows = e.getSheetRows(0, keys, 2);
+            ArrayList<String> agentnumList = new ArrayList<>();
+            for (Row row : rows) {
+                agentnumList.add(row.getString("name"));
+            }
+            //查询可导入的用户信息
+            SQLFactory sqlFactory = new SQLFactory(this, "企业-查询可导入经销商信息");
+            sqlFactory.addParameter("siteid", siteid);
+            sqlFactory.addParameter_in("agentnum", agentnumList);
+            sqlFactory.addParameter("sa_salestargetbillid", sa_salestargetbillid);
+            String sql = sqlFactory.getSQL();
+             System.out.println(sql);
+            RowsMap agentRowsMap = dbConnect.runSqlQuery(sql).toRowsMap("agentnum");
+
+            boolean iserr = false;
+            Rows rowserr = new Rows();
+            Rows rowssuc = new Rows();
+            for (Row row : rows) {
+                if (StringUtils.isEmpty(row.getString("name"))) {
+                    iserr = true;
+                    row.put("msg", "错误信息:必填项不能为空");
+                    rowserr.add(row);
+                } else {
+                    Rows userRows = agentRowsMap.get(row.getString("name"));
+                    if (userRows.isNotEmpty()) {
+                        row.putAll(userRows.get(0));
+                        rowssuc.add(row);
+                    } else {
+                        iserr = true;
+                        row.put("msg", "错误信息:数据已导入或经销商不在数据库中");
+                        rowserr.add(row);
+                    }
+                }
+
+
+            }
+
+            String[] types = {"年", "季", "月"};
+
+            long[] ids = createTableID("sa_salestarget", rowssuc.size() * 17);
+            int index = 1;
+
+            if (!rowssuc.isEmpty()) {
+                for (Row row : rowssuc) {
+                    SQLFactory saleFactory = new SQLFactory(this, "企业范围新增");
+                    saleFactory.addParameter("siteid", siteid);
+                    saleFactory.addParameter("sa_salestargethrid", createTableID("sa_salestargethr"));
+                    saleFactory.addParameter("sys_enterpriseid", row.getLong("sys_enterpriseid"));
+                    saleFactory.addParameter("sa_salestargetbillid", sa_salestargetbillid);
+
+                    sqllist.add(saleFactory.getSQL());
+
+                    for (String type : types) {
+                        int point;
+                        if (type.equals("年")) {
+                            point = 1;
+                        } else if (type.equals("季")) {
+                            point = 4;
+                        } else if (type.equals("月")) {
+                            point = 12;
+                        } else {
+                            point = 0;
+                        }
+
+                        for (int i = 0; i < point; i++) {
+                            double target_l = 0L;
+                            double target_h = 0L;
+                            if (type.equals("年")) {
+                                target_l = row.getDouble("y1l");
+                                target_h = row.getDouble("y1h");
+                            }
+                            if (type.equals("季")) {
+                                target_l = row.getDouble("s" + (i + 1) + "l");
+                                target_h = row.getDouble("s" + (i + 1) + "h");
+                            }
+                            if (type.equals("月")) {
+                                target_l = row.getDouble("m" + (i + 1) + "l");
+                                target_h = row.getDouble("m" + (i + 1) + "h");
+                            }
+
+
+                            SQLFactory targetFactory = new SQLFactory(this, "企业-目标明细新增");
+                            targetFactory.addParameter("siteid", siteid);
+                            targetFactory.addParameter("sa_salestargetid", ids[index - 1]);
+                            targetFactory.addParameter("type", type);
+                            targetFactory.addParameter("point", i + 1);
+                            targetFactory.addParameter("targettype", "企业目标");
+                            targetFactory.addParameter("sys_enterpriseid", row.getLong("sys_enterpriseid"));
+                            targetFactory.addParameter("sa_salestargetbillid", sa_salestargetbillid);
+                            targetFactory.addParameter("year", year);
+                            targetFactory.addParameter("sa_contractid", 0);
+                            targetFactory.addParameter("createby", username);
+                            targetFactory.addParameter("target_l", target_l);
+                            targetFactory.addParameter("target_h", target_h);
+                            targetFactory.addParameter("tradefield", "");
+
+
+                            sqllist.add(targetFactory.getSQL());
+                            index++;
+                        }
+                    }
+
+
+                }
+            }
+            for (String s:sqllist) {
+                System.out.println(s);
+            }
+            if (sqllist != null && !sqllist.isEmpty()) {
+                sqllist.add(DataContrlLog.createLog(this, "sa_salestargetbill", sa_salestargetbillid, "导入", "导入人员目标").getSQL());
+                dbConnect.runSqlUpdate(sqllist);
+            }
+
+            if (iserr) {
+                ExcelFactory excelFactory = new ExcelFactory("企业目标导入错误信息");
+                ArrayList<String> colNameList = new ArrayList<String>();
+                HashMap<String, Class> keytypemap = new HashMap<String, Class>();
+                colNameList.add("name");
+                String key_l = "y1l";
+                colNameList.add(key_l);
+                for (int a = 1; a < 5; a++) {
+                    key_l = "s" + a + "l";
+                    colNameList.add(key_l);
+                }
+                for (int a = 1; a < 13; a++) {
+                    key_l = "m" + a + "l";
+                    colNameList.add(key_l);
+                }
+                colNameList.add("msg");
+
+
+                keytypemap.put("name", String.class);
+                keytypemap.put("phonenumber", String.class);
+                key_l = "y1l";
+                keytypemap.put(key_l, String.class);
+                for (int a = 1; a < 5; a++) {
+                    key_l = "s" + a + "l";
+                    keytypemap.put(key_l, String.class);
+                }
+                for (int a = 1; a < 13; a++) {
+                    key_l = "m" + a + "l";
+                    keytypemap.put(key_l, String.class);
+                }
+
+
+                keytypemap.put("msg", String.class);
+                rowserr.setFieldList(colNameList);
+                rowserr.setFieldTypeMap(keytypemap);
+                addSheet(excelFactory, "Sheet1", rowserr);
+
+                Rows aa = uploadExcelToObs(excelFactory);
+                String url = "";
+                if (!aa.isEmpty()) {
+                    url = aa.get(0).getString("url");
+                }
+                return getSucReturnObject().setData(url).toString();
+            }
+        } catch (Exception e1) {
+            // TODO Auto-generated catch block
+            e1.printStackTrace();
+            return getErrReturnObject().setErrMsg(e1.getMessage()).toString();
+        }
+        return getSucReturnObject().toString();
+    }
+
+    public XSSFSheet addSheet(ExcelFactory excelFactory, String sheetname, Rows datarows) {
+        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);
+
+        personnelexcel.setBatchDetailSheetColumn2(sheet);// 设置工作薄列宽
+        XSSFCellStyle titleCellStyle1 = ExportExcel.createTitleCellStyle1(xssfFWorkbook);
+        XSSFCellStyle titleCellStyle2 = ExportExcel.createTitleCellStyle2(xssfFWorkbook);
+        personnelexcel.batchDetailErr(sheet, titleCellStyle1, titleCellStyle2, xssfFWorkbook);// 写入标题
+
+        for (int n = 0; n < datarows.size(); n++) {
+            Row row = datarows.get(n);
+            XSSFRow datarow = sheet.createRow(n + 2);
+            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(keylist.get(i1)).intValue());
+                } else if (fieldclazztype == Long.class) {
+                    datarow.createCell(i1).setCellValue(row.getLong(keylist.get(i1)));
+                } else if (fieldclazztype == Float.class) {
+                    datarow.createCell(i1).setCellValue(row.getFloat(keylist.get(i1)));
+                } else if (fieldclazztype == Double.class) {
+                    datarow.createCell(i1).setCellValue(row.getDouble(keylist.get(i1)));
+                } else {
+                    datarow.createCell(i1).setCellValue(row.getString(keylist.get(i1)));
+                }
+                if (i1 == 18) {
+                    datarow.getCell(i1).setCellStyle(xssfCellStyle1);
+                }
+            }
+        }
+        return sheet;
+    }
+
 }

+ 24 - 43
src/custom/restcontroller/webmanage/sale/salestarget/personnel.java

@@ -378,8 +378,12 @@ public class personnel extends Controller {
         try {
             if (content.getLong("attachmentid") > 0) {
                 e = getPostExcelFactory(content.getLong("attachmentid"));
+                // 本地
+                //e = getPostExcelFactory();
             } else {
                 e = getPostExcelFactory();
+                // 本地
+                //e = getPostExcelFactory();
             }
 
 
@@ -387,36 +391,29 @@ public class personnel extends Controller {
             ArrayList<String> sqllist = new ArrayList<>();
 
             keys.add("name");
-            keys.add("phonenumber");
             String keyl = "y1l";
-            String keyh = "y1h";
             keys.add(keyl);
-            keys.add(keyh);
             for (int i = 1; i < 5; i++) {
                 keyl = "s" + i + "l";
-                keyh = "s" + i + "h";
                 keys.add(keyl);
-                keys.add(keyh);
             }
 
             for (int i = 1; i < 13; i++) {
                 keyl = "m" + i + "l";
-                keyh = "m" + i + "h";
                 keys.add(keyl);
-                keys.add(keyh);
             }
             Rows rows = e.getSheetRows(0, keys, 2);
-            ArrayList<String> phoneNumberList = new ArrayList<>();
+            ArrayList<String> areanameList = new ArrayList<>();
             for (Row row : rows) {
-                phoneNumberList.add(row.getString("phonenumber"));
+                areanameList.add(row.getString("name"));
             }
             //查询可导入的用户信息
-            SQLFactory sqlFactory = new SQLFactory(this, "人员-查询可导入用户信息");
+            SQLFactory sqlFactory = new SQLFactory(this, "人员-查询可导入区域信息");
             sqlFactory.addParameter("siteid", siteid);
-            sqlFactory.addParameter_in("phonenumber", phoneNumberList);
+            sqlFactory.addParameter_in("areaname", areanameList);
             sqlFactory.addParameter("sa_salestargetbillid", sa_salestargetbillid);
             String sql = sqlFactory.getSQL();
-            RowsMap userRowsMap = dbConnect.runSqlQuery(sql).toRowsMap("phonenumber");
+            RowsMap areaRowsMap = dbConnect.runSqlQuery(sql).toRowsMap("areaname");
 
             boolean iserr = false;
             Rows rowserr = new Rows();
@@ -424,28 +421,20 @@ public class personnel extends Controller {
             // 手机号码的格式:第一位只能为1,第二位可以是3,4,5,7,8,第三位到第十一位可以为0-9中任意一个数字
             String regex = "^((13[0-9])|(14[5,7,9])|(15[0-3,5-9])|(166)|(17[3,5,6,7,8])|(18[0-9])|(19[1,8,9]))\\d{8}$";
             for (Row row : rows) {
-                if (StringUtils.isEmpty(row.getString("name"))
-                        || StringUtils.isEmpty(row.getString("phonenumber"))) {
+                if (StringUtils.isEmpty(row.getString("name"))) {
                     iserr = true;
                     row.put("msg", "错误信息:必填项不能为空");
                     rowserr.add(row);
                 } else {
-                    if (!row.getString("phonenumber").matches(regex)) {
-                        iserr = true;
-                        row.put("msg", "错误信息:手机号格式不正确");
-                        rowserr.add(row);
-                    } else {
-                        Rows userRows = userRowsMap.get(row.getString("phonenumber"));
+                        Rows userRows = areaRowsMap.get(row.getString("name"));
                         if (userRows.isNotEmpty()) {
                             row.putAll(userRows.get(0));
                             rowssuc.add(row);
                         } else {
                             iserr = true;
-                            row.put("msg", "错误信息:数据已导入或人员手机号不在数据库中");
+                            row.put("msg", "错误信息:数据已导入或区域不在数据库中");
                             rowserr.add(row);
                         }
-
-                    }
                 }
 
 
@@ -461,13 +450,14 @@ public class personnel extends Controller {
                     SQLFactory saleFactory = new SQLFactory(this, "人员范围新增");
                     saleFactory.addParameter("siteid", siteid);
                     saleFactory.addParameter("sa_salestargethrid", createTableID("sa_salestargethr"));
-                    saleFactory.addParameter("hrid", row.getString("hrid"));
-                    saleFactory.addParameter("position", row.getString("position"));
+                    saleFactory.addParameter("hrid", 0);
+                    saleFactory.addParameter("position", "");
+                    saleFactory.addParameter("sa_saleareaid", row.getString("sa_saleareaid"));
                     saleFactory.addParameter("areaname", row.getString("areaname"));
                     saleFactory.addParameter("sa_salestargetbillid", sa_salestargetbillid);
-                    saleFactory.addParameter("depname", row.getString("depname"));
-                    saleFactory.addParameter("departmentid", row.getString("departmentid"));
-                    saleFactory.addParameter("name", row.getString("name"));
+                    saleFactory.addParameter("depname", "");
+                    saleFactory.addParameter("departmentid",0);
+                    saleFactory.addParameter("name","");
 
                     sqllist.add(saleFactory.getSQL());
 
@@ -506,13 +496,14 @@ public class personnel extends Controller {
                             targetFactory.addParameter("type", type);
                             targetFactory.addParameter("point", i + 1);
                             targetFactory.addParameter("targettype", "人员目标");
-                            targetFactory.addParameter("hrid", row.getString("hrid"));
+                            targetFactory.addParameter("sa_saleareaid", row.getString("sa_saleareaid"));
                             targetFactory.addParameter("sa_salestargetbillid", sa_salestargetbillid);
                             targetFactory.addParameter("year", year);
                             targetFactory.addParameter("sa_projectid", "null");
                             targetFactory.addParameter("createby", username);
                             targetFactory.addParameter("target_l", target_l);
                             targetFactory.addParameter("target_h", target_h);
+
                             sqllist.add(targetFactory.getSQL());
                             index++;
                         }
@@ -523,6 +514,9 @@ public class personnel extends Controller {
             }
 
             if (sqllist != null && !sqllist.isEmpty()) {
+                dbConnect.runSqlUpdate("delete from sa_salestargethr where siteid='"+siteid+"' and sa_salestargetbillid="+sa_salestargetbillid);
+                dbConnect.runSqlUpdate("delete from sa_salestarget where siteid='"+siteid+"' and sa_salestargetbillid="+sa_salestargetbillid);
+
                 sqllist.add(DataContrlLog.createLog(this, "sa_salestargetbill", sa_salestargetbillid, "导入", "导入人员目标").getSQL());
                 dbConnect.runSqlUpdate(sqllist);
             }
@@ -532,22 +526,15 @@ public class personnel extends Controller {
                 ArrayList<String> colNameList = new ArrayList<String>();
                 HashMap<String, Class> keytypemap = new HashMap<String, Class>();
                 colNameList.add("name");
-                colNameList.add("phonenumber");
                 String key_l = "y1l";
-                String key_h = "y1h";
                 colNameList.add(key_l);
-                colNameList.add(key_h);
                 for (int a = 1; a < 5; a++) {
                     key_l = "s" + a + "l";
-                    key_h = "s" + a + "h";
                     colNameList.add(key_l);
-                    colNameList.add(key_h);
                 }
                 for (int a = 1; a < 13; a++) {
                     key_l = "m" + a + "l";
-                    key_h = "m" + a + "h";
                     colNameList.add(key_l);
-                    colNameList.add(key_h);
                 }
                 colNameList.add("msg");
 
@@ -555,20 +542,14 @@ public class personnel extends Controller {
                 keytypemap.put("name", String.class);
                 keytypemap.put("phonenumber", String.class);
                 key_l = "y1l";
-                key_h = "y1h";
                 keytypemap.put(key_l, String.class);
-                keytypemap.put(key_h, String.class);
                 for (int a = 1; a < 5; a++) {
                     key_l = "s" + a + "l";
-                    key_h = "s" + a + "h";
                     keytypemap.put(key_l, String.class);
-                    keytypemap.put(key_h, String.class);
                 }
                 for (int a = 1; a < 13; a++) {
                     key_l = "m" + a + "l";
-                    key_h = "m" + a + "h";
                     keytypemap.put(key_l, String.class);
-                    keytypemap.put(key_h, String.class);
                 }
 
 
@@ -626,7 +607,7 @@ public class personnel extends Controller {
                 } else {
                     datarow.createCell(i1).setCellValue(row.getString(keylist.get(i1)));
                 }
-                if (i1 == 36) {
+                if (i1 == 18) {
                     datarow.getCell(i1).setCellStyle(xssfCellStyle1);
                 }
             }

+ 30 - 68
src/custom/restcontroller/webmanage/sale/salestarget/personnelexcel.java

@@ -25,7 +25,7 @@ public class personnelexcel {
         short width = 3500;
         sheet.setColumnWidth((short) 0, 4000);
         sheet.setColumnWidth((short) 1, 4000);
-        for (int i = 2; i < 37; i++) {
+        for (int i = 1; i < 20; i++) {
             sheet.setColumnWidth((short) i, width);
         }
 
@@ -41,10 +41,10 @@ public class personnelexcel {
         short width = 3000;
         sheet.setColumnWidth((short) 0, 4000);
         sheet.setColumnWidth((short) 1, 4000);
-        for (int i = 2; i < 37; i++) {
+        for (int i = 1; i < 18; i++) {
             sheet.setColumnWidth((short) i, width);
         }
-        sheet.setColumnWidth((short) 37, width * 2);
+        sheet.setColumnWidth((short) 20, width * 2);
 
     }
 
@@ -79,7 +79,7 @@ public class personnelexcel {
         cellStyle2.setBorderRight(BorderStyle.THIN);//右边框
         cellStyle2.setWrapText(true);
         /*第一行*/
-        sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 35));//2.申请年度单位
+        sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 17));//2.申请年度单位
 
         /*第一行塞值*/
         row = sheet.createRow(0);
@@ -92,55 +92,38 @@ public class personnelexcel {
 
         cell = row.createCell(0);
         cell.setCellStyle(cellStyle2);
-        cell.setCellValue("姓名(必填)");
+        cell.setCellValue("区域名称");
 
         cell = row.createCell(1);
         cell.setCellStyle(cellStyle2);
-        cell.setCellValue("手机号(必填)");
-
-        cell = row.createCell(2);
-        cell.setCellStyle(cellStyle2);
         cell.setCellValue("年度(基本)");
-        cell = row.createCell(3);
-        cell.setCellStyle(cellStyle2);
-        cell.setCellValue("年度(挑战)");
 
-        cell = row.createCell(4);
+
+        cell = row.createCell(2);
         cell.setCellStyle(cellStyle2);
         cell.setCellValue("1季度(基本)");
-        cell = row.createCell(5);
-        cell.setCellStyle(cellStyle2);
-        cell.setCellValue("1季度(挑战)");
 
-        cell = row.createCell(6);
+
+        cell = row.createCell(3);
         cell.setCellStyle(cellStyle2);
         cell.setCellValue("2季度(基本)");
-        cell = row.createCell(7);
-        cell.setCellStyle(cellStyle2);
-        cell.setCellValue("2季度(挑战)");
 
-        cell = row.createCell(8);
+
+        cell = row.createCell(4);
         cell.setCellStyle(cellStyle2);
         cell.setCellValue("3季度(基本)");
-        cell = row.createCell(9);
-        cell.setCellStyle(cellStyle2);
-        cell.setCellValue("3季度(挑战)");
 
-        cell = row.createCell(10);
+
+        cell = row.createCell(5);
         cell.setCellStyle(cellStyle2);
         cell.setCellValue("4季度(基本)");
-        cell = row.createCell(11);
-        cell.setCellStyle(cellStyle2);
-        cell.setCellValue("4季度(挑战)");
+
 
         for (int i = 1; i < 13; i++) {
-            cell = row.createCell(2 * i + 10);
+            cell = row.createCell(i + 5);
             cell.setCellStyle(cellStyle2);
             cell.setCellValue(i + "月(基本)");
 
-            cell = row.createCell(2 * i + 11);
-            cell.setCellStyle(cellStyle2);
-            cell.setCellValue(i + "月(挑战)");
         }
 
 
@@ -154,11 +137,7 @@ public class personnelexcel {
         cell.setCellStyle(cellStyle3);
         cell.setCellValue("名称");
 
-        cell = row.createCell(1);
-        cell.setCellStyle(cellStyle3);
-        cell.setCellValue("15112345678");
-
-        for (int i = 2; i < 36; i++) {
+        for (int i = 1; i < 18; i++) {
             cell = row.createCell(i);
             cell.setCellStyle(cellStyle3);
             cell.setCellValue("0");
@@ -192,7 +171,7 @@ public class personnelexcel {
         cellStyle1.setWrapText(true);
 
         /*第一行*/
-        sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 36));//2.提示信息
+        sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 18));//2.提示信息
 
         /*第一行塞值*/
         row = sheet.createRow(0);
@@ -208,56 +187,39 @@ public class personnelexcel {
         cell.setCellStyle(cellStyle2);
         cell.setCellValue("姓名(必填)");
 
-        cell = row.createCell(1);
-        cell.setCellStyle(cellStyle2);
-        cell.setCellValue("手机号(必填)");
 
-        cell = row.createCell(2);
+
+        cell = row.createCell(1);
         cell.setCellStyle(cellStyle2);
         cell.setCellValue("年度(基本)");
-        cell = row.createCell(3);
-        cell.setCellStyle(cellStyle2);
-        cell.setCellValue("年度(挑战)");
 
-        cell = row.createCell(4);
+
+        cell = row.createCell(2);
         cell.setCellStyle(cellStyle2);
         cell.setCellValue("1季度(基本)");
-        cell = row.createCell(5);
-        cell.setCellStyle(cellStyle2);
-        cell.setCellValue("1季度(挑战)");
 
-        cell = row.createCell(6);
+
+        cell = row.createCell(3);
         cell.setCellStyle(cellStyle2);
         cell.setCellValue("2季度(基本)");
-        cell = row.createCell(7);
-        cell.setCellStyle(cellStyle2);
-        cell.setCellValue("2季度(挑战)");
 
-        cell = row.createCell(8);
+
+        cell = row.createCell(4);
         cell.setCellStyle(cellStyle2);
         cell.setCellValue("3季度(基本)");
-        cell = row.createCell(9);
-        cell.setCellStyle(cellStyle2);
-        cell.setCellValue("3季度(挑战)");
 
-        cell = row.createCell(10);
+        cell = row.createCell(5);
         cell.setCellStyle(cellStyle2);
         cell.setCellValue("4季度(基本)");
-        cell = row.createCell(11);
-        cell.setCellStyle(cellStyle2);
-        cell.setCellValue("4季度(挑战)");
+
 
         for (int i = 1; i < 13; i++) {
-            cell = row.createCell(2 * i + 10);
+            cell = row.createCell( i + 5);
             cell.setCellStyle(cellStyle2);
             cell.setCellValue(i + "月(基本)");
-
-            cell = row.createCell(2 * i + 11);
-            cell.setCellStyle(cellStyle2);
-            cell.setCellValue(i + "月(挑战)");
         }
 
-        cell = row.createCell(36);
+        cell = row.createCell(18);
         cell.setCellStyle(cellStyle2);
         cell.setCellValue("错误信息");
 
@@ -269,7 +231,7 @@ public class personnelexcel {
         short width = 3500;
         sheet.setColumnWidth((short) 0, 4000);
         sheet.setColumnWidth((short) 1, 4000);
-        for (int i = 2; i < 38; i++) {
+        for (int i = 1; i < 19; i++) {
             sheet.setColumnWidth((short) i, width);
         }