|
|
@@ -1,6 +1,7 @@
|
|
|
package restcontroller.webmanage.sale.rebatescheme;
|
|
|
|
|
|
import beans.data.BatchDeleteErr;
|
|
|
+import beans.datacontrllog.DataContrlLog;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import common.Controller;
|
|
|
@@ -8,11 +9,18 @@ import common.YosException;
|
|
|
import common.annotation.API;
|
|
|
import common.annotation.CACHEING;
|
|
|
import common.annotation.CACHEING_CLEAN;
|
|
|
-import common.data.Rows;
|
|
|
-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 restcontroller.system.attachment.Attachment;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
|
|
|
public class rebateunproducts extends Controller {
|
|
|
/**
|
|
|
@@ -129,4 +137,198 @@ public class rebateunproducts extends Controller {
|
|
|
return batchDeleteErr.getReturnObject().toString();
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+ @API(title = "导入不参与返利商品", apiversion = R.ID2024062609542003.v1.class)
|
|
|
+ @CACHEING_CLEAN(apiClass = {rebateunproducts.class})
|
|
|
+ public String importItem() throws YosException {
|
|
|
+ ArrayList<String> sqlList = new ArrayList<>();
|
|
|
+
|
|
|
+ JSONArray jsonArray = new JSONArray();
|
|
|
+ jsonArray.add(content.getLong("attachmentid"));
|
|
|
+
|
|
|
+ content.put("ownertable", "sa_rebatescheme");
|
|
|
+ content.put("ownerid", content.getLongValue("sa_rebateschemeid"));
|
|
|
+ content.put("usetype", "default");
|
|
|
+ content.put("attachmentids", jsonArray);
|
|
|
+ Attachment attachment = new Attachment(content);
|
|
|
+ attachment.createFileLink();
|
|
|
+
|
|
|
+ ExcelFactory e;
|
|
|
+ try {
|
|
|
+
|
|
|
+ // 华为云
|
|
|
+ //e = getPostExcelFactory(content.getLong("attachmentid"));
|
|
|
+ // 本地
|
|
|
+ e = getPostExcelFactory();
|
|
|
+
|
|
|
+ ArrayList<String> keys = new ArrayList<>();
|
|
|
+ ArrayList<String> sqllist = new ArrayList<>();
|
|
|
+ keys.add("itemno");
|
|
|
+ HashMap<String, CellType> cellMap = new HashMap<>();
|
|
|
+ cellMap.put("itemno", CellType.STRING);
|
|
|
+ Rows rows = e.getSheetRows(0, keys, cellMap, 3);
|
|
|
+
|
|
|
+ ArrayList<String> itemnoList = rows.toArrayList("itemno");
|
|
|
+ itemnoList.add("-1");
|
|
|
+
|
|
|
+ boolean iserr = false;
|
|
|
+ Rows rowserr = new Rows();
|
|
|
+ Rows rowssuc = new Rows();
|
|
|
+ QuerySQL querySQL = SQLFactory.createQuerySQL(this, "plm_item", "itemid", "itemno", "marketprice");
|
|
|
+ querySQL.setSiteid(siteid);
|
|
|
+ querySQL.setWhere("itemno", itemnoList);
|
|
|
+ RowsMap itemnoRowsMap = querySQL.query().toRowsMap("itemno");
|
|
|
+ for (Row row : rows) {
|
|
|
+ if (StringUtils.isEmpty(row.getString("itemno"))) {
|
|
|
+ iserr = true;
|
|
|
+ row.put("msg", "错误信息:商品编号不能为空");
|
|
|
+ rowserr.add(row);
|
|
|
+ continue;
|
|
|
+ } else {
|
|
|
+ String itemno = row.getString("itemno");
|
|
|
+ if (itemnoRowsMap.containsKey(itemno)) {
|
|
|
+ row.put("itemid", itemnoRowsMap.get(itemno).get(0).getLong("itemid"));
|
|
|
+ } else {
|
|
|
+ iserr = true;
|
|
|
+ row.put("msg", "错误信息:不存在商品编号为" + itemno + "的商品");
|
|
|
+ rowserr.add(row);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ rowssuc.add(row);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!rowssuc.isEmpty()) {
|
|
|
+ for (Row row : rowssuc) {
|
|
|
+ Long sa_rebateunproductsid = createTableID("sa_rebateunproducts");
|
|
|
+ SQLFactory sqlFactoryupload = new SQLFactory(this, "装修返利方案不参与返利商品新增");
|
|
|
+ sqlFactoryupload.addParameter("sa_rebateunproductsid", sa_rebateunproductsid);
|
|
|
+ sqlFactoryupload.addParameter("sa_rebateschemeid", content.getLongValue("sa_rebateschemeid"));
|
|
|
+ sqlFactoryupload.addParameter("siteid", siteid);
|
|
|
+ sqlFactoryupload.addParameter("itemid", row.getString("itemid"));
|
|
|
+ sqllist.add(sqlFactoryupload.getSQL());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!sqllist.isEmpty()) {
|
|
|
+ String sql = DataContrlLog.createLog(this, "sa_rebatescheme", content.getLongValue("sa_rebateschemeid"), "新增", "装修返利方案不参与返利商品导入:" + content.getLongValue("sa_rebateschemeid")).getSQL();
|
|
|
+ sqlList.add(sql);
|
|
|
+ dbConnect.runSqlUpdate(sqllist);
|
|
|
+ } else {
|
|
|
+ dbConnect.runSqlUpdate("delete from sa_rebateunproducts where sa_rebateschemeid=" + content.getLongValue("sa_rebateschemeid"));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (iserr) {
|
|
|
+ ExcelFactory excelFactory = new ExcelFactory("不参与返利商品导入错误信息");
|
|
|
+ HashMap<String, String> map = new HashMap<String, String>();
|
|
|
+ map.put("itemno", "商品编号");
|
|
|
+ map.put("msg", "错误信息");
|
|
|
+ ArrayList<String> colNameList = new ArrayList<String>();
|
|
|
+ HashMap<String, Class> keytypemap = new HashMap<String, Class>();
|
|
|
+ colNameList.add("itemno");
|
|
|
+ colNameList.add("msg");
|
|
|
+ keytypemap.put("itemno", 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) {
|
|
|
+ dbConnect.runSqlUpdate("delete from sa_rebateunproducts where sa_rebateschemeid=" + content.getLongValue("sa_rebateschemeid"));
|
|
|
+ e1.printStackTrace();
|
|
|
+ return getErrReturnObject().setErrMsg(e1.getMessage()).toString();
|
|
|
+ }
|
|
|
+ return getSucReturnObject().toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 下载不参与返利商品导入模板
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @API(title = "下载不参与返利商品导入模板", apiversion = R.ID2024062609542503.v1.class)
|
|
|
+ public String downloadItemExcel() 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.rebatescheme.ExportExcel.setBatchDetailSheetColumn1(sheet);// 设置工作薄列宽
|
|
|
+ XSSFCellStyle titleCellStyle1 = restcontroller.webmanage.sale.rebatescheme.ExportExcel.createTitleCellStyle1(xssfFWorkbook);
|
|
|
+ XSSFCellStyle titleCellStyle2 = restcontroller.webmanage.sale.rebatescheme.ExportExcel.createTitleCellStyle2(xssfFWorkbook);
|
|
|
+ XSSFCellStyle titleCellStyle3 = restcontroller.webmanage.sale.rebatescheme.ExportExcel.createBodyCellStyle(xssfFWorkbook);
|
|
|
+ XSSFCellStyle titleCellStyle4 = restcontroller.webmanage.sale.rebatescheme.ExportExcel.createTitleCellStyle3(xssfFWorkbook);
|
|
|
+ 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);
|
|
|
+
|
|
|
+ ExportExcel.setBatchDetailSheetColumn2(sheet);// 设置工作薄列宽
|
|
|
+ XSSFCellStyle titleCellStyle1 = ExportExcel.createTitleCellStyle1(xssfFWorkbook);
|
|
|
+ XSSFCellStyle titleCellStyle2 = ExportExcel.createTitleCellStyle2(xssfFWorkbook);
|
|
|
+ XSSFCellStyle titleCellStyle3 = 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)).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 == 1) {
|
|
|
+ datarow.getCell(i1).setCellStyle(xssfCellStyle1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return sheet;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|