|
|
@@ -0,0 +1,268 @@
|
|
|
+package restcontroller.webmanage.sale.u8prodprice;
|
|
|
+
|
|
|
+import beans.datacontrllog.DataContrlLog;
|
|
|
+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.DataFormat;
|
|
|
+import org.apache.poi.xssf.usermodel.*;
|
|
|
+import restcontroller.R;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+
|
|
|
+public class u8prodpricedatail extends Controller {
|
|
|
+ public u8prodpricedatail(JSONObject content) throws YosException {
|
|
|
+ super(content);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @API(title = "u8产品入库成本导入明细列表", apiversion = R.ID2025082214071703.v1.class)
|
|
|
+ @CACHEING
|
|
|
+ public String queryList_u8prodpricedatail() throws YosException {
|
|
|
+ Long sa_sendplanid = content.getLongValue("sa_u8prodpriceid");
|
|
|
+ /*
|
|
|
+ 过滤条件设置
|
|
|
+ */
|
|
|
+ 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.itemno like'%").append(whereObject.getString("condition")).append("%' ");
|
|
|
+ where.append("or t2.itemname like'%").append(whereObject.getString("condition")).append("%' ");
|
|
|
+ where.append("or t2.model like'%").append(whereObject.getString("condition")).append("%' ");
|
|
|
+ where.append(")");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_u8prodprice_datail","*");
|
|
|
+ querySQL.setTableAlias("t1");
|
|
|
+ querySQL.addJoinTable(JOINTYPE.left, "plm_item", "t2", "t1.siteid = t2.siteid and t1.itemno = t2.itemno","itemname","model","itemid");
|
|
|
+ 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 = "下载u8产品入库成本导入明细模板", apiversion = R.ID2025082214133803.v1.class)
|
|
|
+ public String downloadU8prodpricedatailExcel() throws YosException {
|
|
|
+ ExcelFactory excelFactory = new ExcelFactory("u8产品入库成本导入明细导入模板");
|
|
|
+
|
|
|
+ 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 <= 2; i++) {
|
|
|
+ sheet.setDefaultColumnStyle(i, style);
|
|
|
+ }
|
|
|
+ // 设置工作薄列宽
|
|
|
+ ExportExcel.setBatchDetailSheetColumn1(sheet);// 设置工作薄列宽
|
|
|
+ XSSFCellStyle titleCellStyle1 =ExportExcel.createTitleCellStyle1(xssfFWorkbook);
|
|
|
+ XSSFCellStyle titleCellStyle2 = ExportExcel.createTitleCellStyle2(xssfFWorkbook);
|
|
|
+ XSSFCellStyle titleCellStyle3 = ExportExcel.createTitleCellStyle3(xssfFWorkbook);
|
|
|
+ XSSFCellStyle titleCellStyle4 = ExportExcel.createBodyCellStyle4(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();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 导入u8产品入库成本导入明细
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @API(title = "导入u8产品入库成本导入明细", apiversion = R.ID2025082214133003.v1.class)
|
|
|
+ @CACHEING_CLEAN(apiversions = {R.ID20221215100903.v1.class, R.ID20221215101003.v1.class})
|
|
|
+ public String uploadU8propriceByExcel() throws YosException {
|
|
|
+
|
|
|
+ Long sa_u8prodpriceid = content.getLong("sa_u8prodpriceid");
|
|
|
+ Rows u8prodprice = dbConnect.runSqlQuery("select status from sa_u8prodprice where siteid='" + siteid + "' and sa_u8prodpriceid=" + sa_u8prodpriceid);
|
|
|
+ if (u8prodprice.isEmpty()) {
|
|
|
+ return getErrReturnObject().setErrMsg("该u8产品入库成本单不存在").toString();
|
|
|
+ }
|
|
|
+ if (!u8prodprice.get(0).getString("status").equals("新建")) {
|
|
|
+ return getErrReturnObject().setErrMsg("非新建状态不能导入").toString();
|
|
|
+ }
|
|
|
+ ArrayList<String> sqlList = new ArrayList<>();
|
|
|
+ ExcelFactory e;
|
|
|
+ try {
|
|
|
+
|
|
|
+ // 华为云
|
|
|
+ e = getPostExcelFactory(content.getLong("attachmentid"));
|
|
|
+ // 本地
|
|
|
+ //e = getPostExcelFactory();
|
|
|
+
|
|
|
+ ArrayList<String> keys = new ArrayList<>();
|
|
|
+ keys.add("stockno");
|
|
|
+ keys.add("itemno");
|
|
|
+ keys.add("costprice");
|
|
|
+
|
|
|
+ Rows rows = e.getSheetRows(0, keys, 3);
|
|
|
+ boolean iserr = false;
|
|
|
+ Rows rowserr = new Rows();
|
|
|
+ Rows rowssuc = new Rows();
|
|
|
+
|
|
|
+ RowsMap itemRowsMap = dbConnect.runSqlQuery("select itemid,itemno from plm_item where siteid='" + siteid + "'").toRowsMap("itemno");
|
|
|
+
|
|
|
+ RowsMap imtitemRowsMap = rows.toRowsMap("itemno");
|
|
|
+ for (Row row : rows) {
|
|
|
+ String itemno = row.getString("itemno");
|
|
|
+ String stockno = row.getString("stockno");
|
|
|
+ String costprice = row.getString("costprice");
|
|
|
+ if (StringUtils.isEmpty(itemno)) {
|
|
|
+ iserr = true;
|
|
|
+ row.put("msg", "错误信息:品号不能为空");
|
|
|
+ rowserr.add(row);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if(!isNumeric(costprice)){
|
|
|
+ iserr = true;
|
|
|
+ row.put("msg", "成本单价不为数字格式,请检查");
|
|
|
+ rowserr.add(row);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (imtitemRowsMap.get(itemno).size() > 1) {
|
|
|
+ iserr = true;
|
|
|
+ row.put("msg", "错误信息:本次导入存在重复商品");
|
|
|
+ rowserr.add(row);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (!itemRowsMap.containsKey(itemno)) {
|
|
|
+ iserr = true;
|
|
|
+ row.put("msg", "错误信息:商品不存在");
|
|
|
+ rowserr.add(row);
|
|
|
+ continue;
|
|
|
+ } else {
|
|
|
+ row.put("itemid", itemRowsMap.get(itemno).get(0).getLong("itemid"));
|
|
|
+ }
|
|
|
+ rowssuc.add(row);
|
|
|
+ }
|
|
|
+ if (iserr) {
|
|
|
+ ExcelFactory excelFactory = new ExcelFactory("商品明细导入错误信息");
|
|
|
+ HashMap<String, String> map = new HashMap<String, String>();
|
|
|
+ map.put("stockno", "erp仓库");
|
|
|
+ map.put("itemno", "品号");
|
|
|
+ map.put("costprice", "成本单价");
|
|
|
+ map.put("msg", "错误信息");
|
|
|
+ ArrayList<String> colNameList = new ArrayList<String>();
|
|
|
+ HashMap<String, Class> keytypemap = new HashMap<String, Class>();
|
|
|
+ colNameList.add("stockno");
|
|
|
+ colNameList.add("itemno");
|
|
|
+ colNameList.add("costprice");
|
|
|
+ colNameList.add("msg");
|
|
|
+ keytypemap.put("stockno", String.class);
|
|
|
+ keytypemap.put("itemno", String.class);
|
|
|
+ keytypemap.put("costprice", 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();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!rowssuc.isEmpty()) {
|
|
|
+ for (Row row : rowssuc) {
|
|
|
+ InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sa_u8prodprice_datail");
|
|
|
+ insertSQL.setUniqueid(createTableID("sa_u8prodprice_datail"));
|
|
|
+ insertSQL.setSiteid(siteid);
|
|
|
+ insertSQL.setValue("sa_u8prodpriceid", sa_u8prodpriceid);
|
|
|
+ insertSQL.setValue("itemno", row.getString("itemno"));
|
|
|
+ insertSQL.setValue("stockno", row.getString("stockno"));
|
|
|
+ insertSQL.setValue("costprice", row.getDouble("costprice"));
|
|
|
+ sqlList.add(insertSQL.getSQL());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!sqlList.isEmpty()) {
|
|
|
+ dbConnect.runSqlUpdate(sqlList);
|
|
|
+ }
|
|
|
+ } 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);
|
|
|
+
|
|
|
+ CellStyle style = xssfFWorkbook.createCellStyle();
|
|
|
+ DataFormat format = xssfFWorkbook.createDataFormat();
|
|
|
+ style.setDataFormat(format.getFormat("@"));
|
|
|
+ // 对单独某一列进行样式赋值,第一个参数为列数,第二个参数为样式
|
|
|
+ for (int i = 0; i <= 3; i++) {
|
|
|
+ sheet.setDefaultColumnStyle(i, style);
|
|
|
+ }
|
|
|
+ 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)));
|
|
|
+ } 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+)?");
|
|
|
+ }
|
|
|
+}
|