|
@@ -1077,6 +1077,38 @@ public class Item extends Controller {
|
|
|
return getSucReturnObject().setData(url).toString();
|
|
|
}
|
|
|
|
|
|
+ @API(title = "货品档案更新模板", apiversion = R.ID2025061614370103.v1.class)
|
|
|
+ public String downloadUpdateExcel() 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("@"));
|
|
|
+ // 对单独某一列进行样式赋值,第一个参数为列数,第二个参数为样式
|
|
|
+ for (int i = 0; i <= 31; i++) {
|
|
|
+ sheet.setDefaultColumnStyle(i, style);
|
|
|
+ }
|
|
|
+ // 设置工作薄列宽
|
|
|
+ ExportExcel_Update.setBatchDetailSheetColumn1(sheet);// 设置工作薄列宽
|
|
|
+ XSSFCellStyle titleCellStyle1 = ExportExcel_Update.createTitleCellStyle1(xssfFWorkbook);
|
|
|
+ XSSFCellStyle titleCellStyle2 = ExportExcel_Update.createTitleCellStyle2(xssfFWorkbook);
|
|
|
+ XSSFCellStyle titleCellStyle3 = ExportExcel_Update.createTitleCellStyle3(xssfFWorkbook);
|
|
|
+ XSSFCellStyle titleCellStyle4 = ExportExcel_Update.createBodyCellStyle4(xssfFWorkbook);
|
|
|
+
|
|
|
+ ExportExcel_Update.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.ID20230311111404.v1.class)
|
|
|
@CACHEING_CLEAN(apiversions = {R.ID20220923140602.class})
|
|
|
public String importItems() throws YosException {
|
|
@@ -1433,6 +1465,218 @@ public class Item extends Controller {
|
|
|
return getSucReturnObject().toString();
|
|
|
}
|
|
|
|
|
|
+ @API(title = "商品档案更新", apiversion = R.ID2025061614392903.v1.class)
|
|
|
+ public String updateItems() throws YosException {
|
|
|
+ ArrayList<String> sqlList = new ArrayList<>();
|
|
|
+ ExcelFactory e;
|
|
|
+ try {
|
|
|
+
|
|
|
+ // 华为云
|
|
|
+ e = getPostExcelFactory(content.getLong("attachmentid"));
|
|
|
+ // 本地
|
|
|
+ //e = getPostExcelFactory();
|
|
|
+
|
|
|
+ ArrayList<String> keys = new ArrayList<>();
|
|
|
+ keys.add("itemno");
|
|
|
+ keys.add("standards");
|
|
|
+ keys.add("model");
|
|
|
+ keys.add("financeclasstype");
|
|
|
+ keys.add("tradefield");
|
|
|
+ keys.add("brandname");
|
|
|
+ keys.add("itemclassnum");
|
|
|
+
|
|
|
+ Rows rows = e.getSheetRows(0, keys, 3);
|
|
|
+ boolean iserr = false;
|
|
|
+ Rows rowserr = new Rows();
|
|
|
+ Rows rowssuc = new Rows();
|
|
|
+ RowsMap itemnoRowsMap = dbConnect.runSqlQuery("select itemno,itemid from plm_item t1 where siteid='" + siteid + "'").toRowsMap("itemno");
|
|
|
+ ArrayList<String> tradefieldList = dbConnect.runSqlQuery("select sys_optiontypemx.value from sys_optiontypemx where (1=1) and (sys_optiontypemx.isused='1') and (sys_optiontypemx.optiontypeid in(select optiontypeid from sys_optiontype where typename='tradefield')) and ((ifnull(siteid,'')='' or siteid='"+siteid+"')) order by sequence").toArrayList("value");
|
|
|
+ RowsMap imitemnoRowsMap = rows.toRowsMap("itemno");
|
|
|
+ Rows itemcalss = dbConnect.runSqlQuery("select t1.sa_brandid,t1.brandname,t2.itemclassid,t2.itemclassnum from sa_brand t1 inner join plm_itemclass t2 on t1.siteid=t2.siteid and t1.sa_brandid=t2.sa_brandid where t1.siteid='" + siteid + "'");
|
|
|
+
|
|
|
+ RowsMap itemclassRowsMap = itemcalss.toRowsMap("brandname");
|
|
|
+
|
|
|
+ for (Row row : rows) {
|
|
|
+
|
|
|
+ String brandname = row.getString("brandname");
|
|
|
+ String itemclassnum = row.getString("itemclassnum");
|
|
|
+ String itemno = row.getString("itemno");
|
|
|
+ if (StringUtils.isEmpty(itemno)) {
|
|
|
+ iserr = true;
|
|
|
+ row.put("msg", "错误信息:产品编号不能为空");
|
|
|
+ rowserr.add(row);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if ((StringUtils.isEmpty(brandname) && StringUtils.isNotEmpty(itemclassnum)) || (StringUtils.isNotEmpty(brandname) && StringUtils.isEmpty(itemclassnum))) {
|
|
|
+ iserr = true;
|
|
|
+ row.put("msg", "错误信息:不能单独填写品牌和营销类别");
|
|
|
+ rowserr.add(row);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (imitemnoRowsMap.containsKey(itemno) && imitemnoRowsMap.get(itemno).size() > 1) {
|
|
|
+ iserr = true;
|
|
|
+ row.put("msg", "错误信息:本次导入商品中存在重复的商品编号");
|
|
|
+ rowserr.add(row);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (!itemnoRowsMap.containsKey(itemno)) {
|
|
|
+ iserr = true;
|
|
|
+ row.put("msg", "错误信息:商品编号在系统中不存在,无法更新数据");
|
|
|
+ rowserr.add(row);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if(!StringUtils.isBlank(row.getString("tradefield"))){
|
|
|
+ if (!tradefieldList.contains(row.getString("tradefield"))) {
|
|
|
+ iserr = true;
|
|
|
+ row.put("msg", "错误信息:领域不存在");
|
|
|
+ rowserr.add(row);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(!StringUtils.isBlank(brandname) && !StringUtils.isBlank(itemclassnum)){
|
|
|
+ if (!itemclassRowsMap.containsKey(brandname) || !itemclassRowsMap.get(brandname).toArrayList("itemclassnum").contains(itemclassnum)) {
|
|
|
+ iserr = true;
|
|
|
+ row.put("msg", "错误信息:品牌不存在或该品牌下没有对应的营销类别");
|
|
|
+ rowserr.add(row);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ row.put("itemid", itemnoRowsMap.get(itemno).get(0).getLong("itemid"));
|
|
|
+ for (Row row1 : itemclassRowsMap.get(brandname)) {
|
|
|
+ if (row1.getString("itemclassnum").equals(itemclassnum)) {
|
|
|
+ row.put("sa_brandid", row1.getLong("sa_brandid"));
|
|
|
+ row.put("itemclassid", row1.getLong("itemclassid"));
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ rowssuc.add(row);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!rowssuc.isEmpty()) {
|
|
|
+ for (Row row : rowssuc) {
|
|
|
+ UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "plm_item");
|
|
|
+ updateSQL.setUniqueid(row.getLong("itemid"));
|
|
|
+ updateSQL.setSiteid(siteid);
|
|
|
+ if(!StringUtils.isBlank(row.getString("standards"))){
|
|
|
+ updateSQL.setValue("standards", row.getString("standards"));
|
|
|
+ }
|
|
|
+ if(!StringUtils.isBlank(row.getString("model"))){
|
|
|
+ updateSQL.setValue("model", row.getString("model"));
|
|
|
+ }
|
|
|
+ if(!StringUtils.isBlank(row.getString("financeclasstype"))){
|
|
|
+ updateSQL.setValue("financeclasstype", row.getString("financeclasstype"));
|
|
|
+ }
|
|
|
+ updateSQL.setValue("changeby", username);
|
|
|
+ updateSQL.setDateValue("changedate");
|
|
|
+ sqlList.add(updateSQL.getSQL());
|
|
|
+
|
|
|
+ Rows itemtradefieldRows =dbConnect.runSqlQuery("select * from plm_item_tradefield where itemid="+row.getLong("itemid")+" and siteid='"+siteid+"'");
|
|
|
+ if(StringUtils.isNotBlank(row.getString("tradefield"))){
|
|
|
+ if(itemtradefieldRows.isEmpty()){
|
|
|
+ Long plm_item_tradefieldid = createTableID("plm_item_tradefield");
|
|
|
+ SQLFactory sqlFactory = new SQLFactory(this, "新增领域");
|
|
|
+ sqlFactory.addParameter("siteid", siteid);
|
|
|
+ sqlFactory.addParameter("plm_item_tradefieldid", plm_item_tradefieldid);
|
|
|
+ sqlFactory.addParameter("tradefield", row.getString("tradefield"));
|
|
|
+ sqlFactory.addParameter("userid", userid);
|
|
|
+ sqlFactory.addParameter("itemid", row.getLong("itemid"));
|
|
|
+ sqlList.add(sqlFactory.getSQL());
|
|
|
+ sqlList.add(DataContrlLog.createLog(this, "plm_item_tradefield", plm_item_tradefieldid, "新增", "货品档案更新导入").getSQL());
|
|
|
+ }else{
|
|
|
+ UpdateSQL item_tradefieldidupdateSQL = SQLFactory.createUpdateSQL(this, "plm_item_tradefield");
|
|
|
+ item_tradefieldidupdateSQL.setUniqueid(itemtradefieldRows.get(0).getLong("plm_item_tradefieldid"));
|
|
|
+ item_tradefieldidupdateSQL.setSiteid(siteid);
|
|
|
+ item_tradefieldidupdateSQL.setValue("tradefield",row.getString("tradefield"));
|
|
|
+ sqlList.add(item_tradefieldidupdateSQL.getSQL());
|
|
|
+ sqlList.add(DataContrlLog.createLog(this, "plm_item_tradefield", itemtradefieldRows.get(0).getLong("plm_item_tradefieldid"), "更新", "货品档案更新导入").getSQL());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ Rows itemsaleclassRows =dbConnect.runSqlQuery("select * from sa_itemsaleclass where itemid="+row.getLong("itemid")+" and siteid='"+siteid+"'");
|
|
|
+
|
|
|
+ if(StringUtils.isNotBlank(row.getString("brandname"))){
|
|
|
+ if(itemsaleclassRows.isEmpty()){
|
|
|
+ Long sa_itemsaleclassid = createTableID("sa_itemsaleclass");
|
|
|
+ SQLFactory sqlFactory = new SQLFactory(this, "新增营销类别");
|
|
|
+ sqlFactory.addParameter("siteid", siteid);
|
|
|
+ sqlFactory.addParameter("sa_itemsaleclassid", sa_itemsaleclassid);
|
|
|
+ sqlFactory.addParameter("itemclassid", row.getString("itemclassid"));
|
|
|
+ sqlFactory.addParameter("itemno", row.getString("itemno"));
|
|
|
+ sqlFactory.addParameter("itemid", row.getLong("itemid"));
|
|
|
+ sqlList.add(sqlFactory.getSQL());
|
|
|
+ sqlList.add(DataContrlLog.createLog(this, "sa_itemsaleclass", sa_itemsaleclassid, "新增", "货品档案更新导入").getSQL());
|
|
|
+ }else{
|
|
|
+ UpdateSQL itemsaleclassupdateSQL = SQLFactory.createUpdateSQL(this, "sa_itemsaleclass");
|
|
|
+ itemsaleclassupdateSQL.setUniqueid(itemsaleclassRows.get(0).getLong("sa_itemsaleclassid"));
|
|
|
+ itemsaleclassupdateSQL.setSiteid(siteid);
|
|
|
+ itemsaleclassupdateSQL.setValue("itemno","itemno");
|
|
|
+ itemsaleclassupdateSQL.setValue("itemclassid",row.getString("itemclassid"));
|
|
|
+ sqlList.add(itemsaleclassupdateSQL.getSQL());
|
|
|
+ sqlList.add(DataContrlLog.createLog(this, "sa_itemsaleclass", itemsaleclassRows.get(0).getLong("sa_itemsaleclassid"), "更新", "货品档案更新导入").getSQL());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ sqlList.add(DataContrlLog.createLog(this, "plm_item", row.getLong("itemid"), "更新", "货品档案更新导入").getSQL());
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!sqlList.isEmpty()) {
|
|
|
+ dbConnect.runSqlUpdate(sqlList);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (iserr) {
|
|
|
+ ExcelFactory excelFactory = new ExcelFactory("货品档案导入错误信息");
|
|
|
+ HashMap<String, String> map = new HashMap<String, String>();
|
|
|
+ map.put("itemno", "产品编码");
|
|
|
+ map.put("standards", "规格");
|
|
|
+ map.put("model", "型号");
|
|
|
+ map.put("financeclasstype", "财务分类");
|
|
|
+ map.put("tradefield", "领域");
|
|
|
+ map.put("brandname", "品牌");
|
|
|
+ map.put("itemclassnum", "营销类别编码");
|
|
|
+ map.put("msg", "错误信息");
|
|
|
+ ArrayList<String> colNameList = new ArrayList<String>();
|
|
|
+ HashMap<String, Class> keytypemap = new HashMap<String, Class>();
|
|
|
+ colNameList.add("itemno");
|
|
|
+ colNameList.add("standards");
|
|
|
+ colNameList.add("model");
|
|
|
+ colNameList.add("financeclasstype");
|
|
|
+ colNameList.add("tradefield");
|
|
|
+ colNameList.add("brandname");
|
|
|
+ colNameList.add("itemclassnum");
|
|
|
+ colNameList.add("msg");
|
|
|
+ keytypemap.put("itemno", String.class);
|
|
|
+ keytypemap.put("standards", String.class);
|
|
|
+ keytypemap.put("model", String.class);
|
|
|
+ keytypemap.put("financeclasstype", String.class);
|
|
|
+ keytypemap.put("tradefield", String.class);
|
|
|
+ keytypemap.put("brandname", String.class);
|
|
|
+ keytypemap.put("itemclassnum", String.class);
|
|
|
+ keytypemap.put("msg", String.class);
|
|
|
+ rowserr.setFieldList(colNameList);
|
|
|
+ rowserr.setFieldTypeMap(keytypemap);
|
|
|
+ addUpdateSheet(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();
|
|
@@ -1485,4 +1729,57 @@ public class Item extends Controller {
|
|
|
return sheet;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ public XSSFSheet addUpdateSheet(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);
|
|
|
+
|
|
|
+ CellStyle style = xssfFWorkbook.createCellStyle();
|
|
|
+ DataFormat format = xssfFWorkbook.createDataFormat();
|
|
|
+ style.setDataFormat(format.getFormat("@"));
|
|
|
+ // 对单独某一列进行样式赋值,第一个参数为列数,第二个参数为样式
|
|
|
+ for (int i = 0; i <= 8; i++) {
|
|
|
+ sheet.setDefaultColumnStyle(i, style);
|
|
|
+ }
|
|
|
+
|
|
|
+ ExportExcel_Update.setBatchDetailSheetColumn2(sheet);// 设置工作薄列宽
|
|
|
+ XSSFCellStyle titleCellStyle1 = ExportExcel_Update.createTitleCellStyle1(xssfFWorkbook);
|
|
|
+ XSSFCellStyle titleCellStyle2 = ExportExcel_Update.createTitleCellStyle2(xssfFWorkbook);
|
|
|
+ XSSFCellStyle titleCellStyle3 = ExportExcel_Update.createTitleCellStyle3(xssfFWorkbook);
|
|
|
+ ExportExcel_Update.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 == 7) {
|
|
|
+ datarow.getCell(i1).setCellStyle(xssfCellStyle1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return sheet;
|
|
|
+ }
|
|
|
+
|
|
|
}
|