|
@@ -1,6 +1,7 @@
|
|
|
package restcontroller.webmanage.sale.promotion;
|
|
|
|
|
|
import beans.data.BatchDeleteErr;
|
|
|
+import beans.datacontrllog.DataContrlLog;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import common.Controller;
|
|
@@ -8,13 +9,17 @@ import common.YosException;
|
|
|
import common.annotation.API;
|
|
|
import common.annotation.CACHEING;
|
|
|
import common.annotation.CACHEING_CLEAN;
|
|
|
-import common.data.Rows;
|
|
|
-import common.data.RowsMap;
|
|
|
-import common.data.SQLFactory;
|
|
|
+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 java.math.BigDecimal;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
|
|
|
public class promotionAuth extends Controller {
|
|
|
|
|
@@ -161,4 +166,229 @@ public class promotionAuth extends Controller {
|
|
|
return batchDeleteErr.getReturnObject().toString();
|
|
|
}
|
|
|
|
|
|
+ @API(title = "促销经销商导入模板",apiversion = R.ID20240828102803.v1.class)
|
|
|
+ public String downloadPromotionExcel() 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);
|
|
|
+ ExportAuthExcel.setBatchDetailSheetColumn1(sheet);// 设置工作薄列宽
|
|
|
+ XSSFCellStyle titleCellStyle1 = ExportAuthExcel.createTitleCellStyle1(xssfFWorkbook);
|
|
|
+ XSSFCellStyle titleCellStyle2 = ExportAuthExcel.createTitleCellStyle2(xssfFWorkbook);
|
|
|
+ XSSFCellStyle titleCellStyle3 = ExportAuthExcel.createBodyCellStyle(xssfFWorkbook);
|
|
|
+ XSSFCellStyle titleCellStyle4 = ExportAuthExcel.createTitleCellStyle3(xssfFWorkbook);
|
|
|
+ ExportAuthExcel.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();
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "促销活动授权经销商导入",apiversion = R.ID20240828102903.v1.class)
|
|
|
+ @CACHEING_CLEAN(apiversions = {promotionAuth.class})
|
|
|
+ public String uploadPromotionAuth() throws YosException {
|
|
|
+
|
|
|
+ Long sa_promotionid = content.getLong("sa_promotionid");
|
|
|
+ Rows promotion = dbConnect.runSqlQuery("select status from sa_promotion where siteid='" + siteid + "' and sa_promotionid=" + sa_promotionid);
|
|
|
+ if (promotion.isEmpty()) {
|
|
|
+ return getErrReturnObject().setErrMsg("无效促销活动").toString();
|
|
|
+ } else if (!promotion.get(0).getString("status").equals("新建")) {
|
|
|
+ return getErrReturnObject().setErrMsg("非新建状态促销活动无法导入").toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ ExcelFactory e;
|
|
|
+ try {
|
|
|
+
|
|
|
+ // 华为云
|
|
|
+ e = getPostExcelFactory(content.getLong("attachmentid"));
|
|
|
+ // 本地
|
|
|
+ //e = getPostExcelFactory();
|
|
|
+
|
|
|
+ ArrayList<String> keys = new ArrayList<>();
|
|
|
+ ArrayList<String> sqllist = new ArrayList<>();
|
|
|
+ keys.add("agentnum");
|
|
|
+ keys.add("islimit");
|
|
|
+ keys.add("limitamount");
|
|
|
+ HashMap<String, CellType> cellMap = new HashMap<>();
|
|
|
+ cellMap.put("agentnum", CellType.STRING);
|
|
|
+ cellMap.put("islimit", CellType.STRING);
|
|
|
+ cellMap.put("limitamount", CellType.STRING);
|
|
|
+
|
|
|
+ int i = 0;
|
|
|
+ Rows rows = e.getSheetRows(0, keys,cellMap, 3);
|
|
|
+
|
|
|
+ boolean iserr = false;
|
|
|
+ Rows rowserr = new Rows();
|
|
|
+ Rows rowssuc = new Rows();
|
|
|
+ ArrayList<String> agentList = rows.toArrayList("agentnum");
|
|
|
+ SQLFactory sqlFactory = new SQLFactory(this, "经销商合作企业查询");
|
|
|
+ sqlFactory.addParameter("siteid", siteid);
|
|
|
+ sqlFactory.addParameter("sa_promotionid", 0);
|
|
|
+ sqlFactory.addParameter_SQL("where", " 1=1 ");
|
|
|
+ RowsMap agentRowsMap = dbConnect.runSqlQuery(sqlFactory.getSQL()).toRowsMap("agentnum");
|
|
|
+ ArrayList<String> inAgentList = dbConnect.runSqlQuery("select t2.agentnum from sa_promotion_auth t1 inner join sa_agents t2 on t1.siteid=t2.siteid and t1.sys_enterpriseid=t2.sys_enterpriseid where t1.siteid='" + siteid + "' and t1.sa_promotionid=" + sa_promotionid).toArrayList("agentnum");
|
|
|
+ for (Row row : rows) {
|
|
|
+ String agentnum = row.getString("agentnum");
|
|
|
+ String islimit = row.getString("islimit");
|
|
|
+ String limitamount = row.getString("limitamount");
|
|
|
+ if (StringUtils.isEmpty(agentnum)) {
|
|
|
+ iserr = true;
|
|
|
+ row.put("msg", "经销商编码不能为空");
|
|
|
+ rowserr.add(row);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (!agentRowsMap.containsKey(agentnum)) {
|
|
|
+ iserr = true;
|
|
|
+ row.put("msg", "经销商不存在");
|
|
|
+ rowserr.add(row);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if(inAgentList.contains(agentnum)){
|
|
|
+ iserr = true;
|
|
|
+ row.put("msg", "经销商已存在促销活动授权范围内");
|
|
|
+ rowserr.add(row);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if(!isNumeric(limitamount) && StringUtils.isNotBlank(limitamount)){
|
|
|
+ iserr = true;
|
|
|
+ row.put("msg", "限购金额不为数字格式,请检查");
|
|
|
+ rowserr.add(row);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if(!isNumeric(islimit)){
|
|
|
+ iserr = true;
|
|
|
+ row.put("msg", "是否限购不为数字格式,请检查");
|
|
|
+ rowserr.add(row);
|
|
|
+ continue;
|
|
|
+ }else{
|
|
|
+ if(islimit.equals("1")){
|
|
|
+ if(Double.valueOf(StringUtils.isNotBlank(limitamount)?limitamount:"0")<=0){
|
|
|
+ iserr = true;
|
|
|
+ row.put("msg", "限购的情况下限购金额必填,请检查");
|
|
|
+ rowserr.add(row);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Row agent = agentRowsMap.get(agentnum).get(0);
|
|
|
+ row.put("sys_enterpriseid", agent.getLong("sys_enterpriseid"));
|
|
|
+ rowssuc.add(row);
|
|
|
+ }
|
|
|
+ long[] sa_promotion_authids = createTableID("sa_promotion_auth", rowssuc.size());
|
|
|
+ if (!rowssuc.isEmpty()) {
|
|
|
+ for (Row row : rowssuc) {
|
|
|
+ long sa_promotion_authid = sa_promotion_authids[i];
|
|
|
+ SQLFactory saleFactory = new SQLFactory(this, "促销方案参与授权范围新增");
|
|
|
+ saleFactory.addParameter("siteid", siteid);
|
|
|
+ saleFactory.addParameter("sa_promotion_authid", sa_promotion_authid);
|
|
|
+ saleFactory.addParameter("sa_promotionid", sa_promotionid);
|
|
|
+ saleFactory.addParameter("sys_enterpriseid", row.getLong("sys_enterpriseid"));
|
|
|
+ saleFactory.addParameter("islimit", row.getLong("islimit"));
|
|
|
+ saleFactory.addParameter("limitamount", StringUtils.isNotBlank(row.getString("limitamount"))?row.getString("limitamount"):"0");
|
|
|
+ saleFactory.addParameter("limitgroupqty",0);
|
|
|
+ saleFactory.addParameter("limitordercount", 0);
|
|
|
+ saleFactory.addParameter("username", username);
|
|
|
+ sqllist.add(saleFactory.getSQL());
|
|
|
+ i++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!sqllist.isEmpty()) {
|
|
|
+ sqllist.add(DataContrlLog.createLog(this, "sa_promotion", sa_promotionid, "导入", "促销活动授权范围导入成功").getSQL());
|
|
|
+ dbConnect.runSqlUpdate(sqllist);
|
|
|
+ }
|
|
|
+ if (iserr) {
|
|
|
+ ExcelFactory excelFactory = new ExcelFactory("促销活动导入错误信息");
|
|
|
+ HashMap<String, String> map = new HashMap<String, String>();
|
|
|
+ map.put("agentnum", "经销商编码");
|
|
|
+ map.put("islimit", "是否限购");
|
|
|
+ map.put("limitamount", "限购金额");
|
|
|
+ map.put("msg", "错误信息");
|
|
|
+ ArrayList<String> colNameList = new ArrayList<String>();
|
|
|
+ HashMap<String, Class> keytypemap = new HashMap<String, Class>();
|
|
|
+ colNameList.add("agentnum");
|
|
|
+ colNameList.add("islimit");
|
|
|
+ colNameList.add("limitamount");;
|
|
|
+ colNameList.add("msg");
|
|
|
+ keytypemap.put("agentnum", String.class);
|
|
|
+ keytypemap.put("islimit", String.class);
|
|
|
+ keytypemap.put("limitamount", 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 getSucReturnObject().setData(url).toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (Exception e1) {
|
|
|
+ e1.printStackTrace();
|
|
|
+ return getErrReturnObject().setErrMsg(e1.getMessage()).toString();
|
|
|
+ }
|
|
|
+ return getSucReturnObject().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);
|
|
|
+
|
|
|
+ ExportAuthExcel.setBatchDetailSheetColumn2(sheet);// 设置工作薄列宽
|
|
|
+ XSSFCellStyle titleCellStyle1 = ExportAuthExcel.createTitleCellStyle1(xssfFWorkbook);
|
|
|
+ XSSFCellStyle titleCellStyle2 = ExportAuthExcel.createTitleCellStyle2(xssfFWorkbook);
|
|
|
+ XSSFCellStyle titleCellStyle3 = ExportAuthExcel.createTitleCellStyle3(xssfFWorkbook);
|
|
|
+ ExportAuthExcel.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)).intValue());
|
|
|
+ } 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 == 3) {
|
|
|
+ datarow.getCell(i1).setCellStyle(xssfCellStyle1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return sheet;
|
|
|
+ }
|
|
|
+ public static boolean isNumeric(String strNum) {
|
|
|
+ if (strNum == null) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return strNum.matches("-?\\d+(\\.\\d+)?");
|
|
|
+ }
|
|
|
+
|
|
|
}
|