Commit 97caded9 by 胡懿

增加物资类型,

parent 22a350e9
...@@ -17,6 +17,7 @@ public class MaterialType extends TreeEntity<MaterialType> { ...@@ -17,6 +17,7 @@ public class MaterialType extends TreeEntity<MaterialType> {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private String code; // 物资类型编码 private String code; // 物资类型编码
private int last;
public MaterialType() { public MaterialType() {
...@@ -48,4 +49,12 @@ public class MaterialType extends TreeEntity<MaterialType> { ...@@ -48,4 +49,12 @@ public class MaterialType extends TreeEntity<MaterialType> {
public String getParentId() { public String getParentId() {
return parent != null && parent.getId() != null ? parent.getId() : "0"; return parent != null && parent.getId() != null ? parent.getId() : "0";
} }
public int getLast() {
return last;
}
public void setLast(int last) {
this.last = last;
}
} }
\ No newline at end of file
...@@ -23,7 +23,8 @@ ...@@ -23,7 +23,8 @@
a.parent_ids AS "parentIds", a.parent_ids AS "parentIds",
a.name AS "name", a.name AS "name",
a.sort AS "sort", a.sort AS "sort",
a.code AS "code" a.code AS "code",
a.last AS "last"
</sql> </sql>
...@@ -117,7 +118,8 @@ ...@@ -117,7 +118,8 @@
parent_ids, parent_ids,
name, name,
sort, sort,
code code,
last
) VALUES ( ) VALUES (
#{id}, #{id},
#{createBy.id}, #{createBy.id},
...@@ -130,7 +132,8 @@ ...@@ -130,7 +132,8 @@
#{parentIds}, #{parentIds},
#{name}, #{name},
#{sort}, #{sort},
#{code} #{code},
#{last}
) )
</insert> </insert>
...@@ -143,7 +146,8 @@ ...@@ -143,7 +146,8 @@
parent_ids = #{parentIds}, parent_ids = #{parentIds},
name = #{name}, name = #{name},
sort = #{sort}, sort = #{sort},
code = #{code} code = #{code},
last = #{last}
WHERE id = #{id} WHERE id = #{id}
</update> </update>
......
...@@ -35,10 +35,32 @@ public class MaterialTypeService extends TreeService<MaterialTypeMapper, Materia ...@@ -35,10 +35,32 @@ public class MaterialTypeService extends TreeService<MaterialTypeMapper, Materia
@Transactional(readOnly = false) @Transactional(readOnly = false)
public void save(MaterialType materialType) { public void save(MaterialType materialType) {
String [] parentIdsArr = materialType.getParentIds().split(",");
if (parentIdsArr.length >= 2) {
materialType.setLast(1);
} else {
materialType.setLast(0);
}
super.save(materialType); super.save(materialType);
} }
@Transactional(readOnly = false) @Transactional(readOnly = false)
public void insert(MaterialType materialType) {
String [] parentIdsArr = materialType.getParentIds().split(",");
if (parentIdsArr.length >= 2) {
materialType.setLast(1);
} else {
materialType.setLast(0);
}
materialType.preInsert();
mapper.insert(materialType);
}
@Transactional(readOnly = false)
public void delete(MaterialType materialType) { public void delete(MaterialType materialType) {
super.delete(materialType); super.delete(materialType);
} }
......
package com.jeeplus.modules.warehouse.materialtype.utils;
import com.jeeplus.common.utils.StringUtils;
import com.jeeplus.modules.warehouse.materialtype.entity.MaterialType;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class InitMaterialType {
public static List<MaterialType> initType(String filePath, String sheetName, String parentId, String parentIds) {
List<MaterialType> resultList = new ArrayList<>();
InputStream fis = null;
try {
fis = new FileInputStream(filePath);
Workbook workbook = null;
if (filePath.endsWith(".xlsx")) {
workbook = new XSSFWorkbook(fis);
} else if (filePath.endsWith(".xls") || filePath.endsWith(".et")) {
workbook = new HSSFWorkbook(fis);
}
fis.close();
/* 读EXCEL文字内容 */
// 获取第一个sheet表,也可使用sheet表名获取
Sheet sheet = workbook.getSheet(sheetName);
// 获取行
Iterator<Row> rows = sheet.rowIterator();
Row row;
Cell cell;
int sort = 1;
while (rows.hasNext()) {
row = rows.next();
cell = row.getCell(0);
String cellValue = POIUtil.getCellValue(cell);
cell = row.getCell(1);
String cellValue1 = POIUtil.getCellValue(cell);
MaterialType type = new MaterialType();
if (StringUtils.isBlank(cellValue)) {
continue;
}
if ("main".equals(sheetName)) {
type.setId(sort + "");
}
type.setCode(cellValue);
type.setName(cellValue1);
type.setParent(new MaterialType(parentId));
type.setParentIds(parentIds);
type.setSort(sort);
resultList.add(type);
sort++;
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (null != fis) {
try {
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return resultList;
}
}
package com.jeeplus.modules.warehouse.materialtype.utils;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFDateUtil;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.FormulaEvaluator;
public class POIUtil {
/**
* 获取cell中的值并返回String类型
*
* @param cell
* @return String类型的cell值
*/
public static String getCellValue(Cell cell) {
String cellValue = "";
if (null != cell) {
// 以下是判断数据的类型
switch (cell.getCellType()) {
case HSSFCell.CELL_TYPE_NUMERIC: // 数字
if (0 == cell.getCellType()) {// 判断单元格的类型是否则NUMERIC类型
if (HSSFDateUtil.isCellDateFormatted(cell)) {// 判断是否为日期类型
Date date = cell.getDateCellValue();
// DateFormat formater = new SimpleDateFormat("yyyy/MM/dd HH:mm");
DateFormat formater = new SimpleDateFormat("yyyy/MM/dd");
cellValue = formater.format(date);
} else {
// 有些数字过大,直接输出使用的是科学计数法: 2.67458622E8 要进行处理
DecimalFormat df = new DecimalFormat("####.####");
cellValue = df.format(cell.getNumericCellValue());
// cellValue = cell.getNumericCellValue() + "";
}
}
break;
case HSSFCell.CELL_TYPE_STRING: // 字符串
cellValue = cell.getStringCellValue();
break;
case HSSFCell.CELL_TYPE_BOOLEAN: // Boolean
cellValue = cell.getBooleanCellValue() + "";
break;
case HSSFCell.CELL_TYPE_FORMULA: // 公式
try {
// 如果公式结果为字符串
cellValue = String.valueOf(cell.getStringCellValue());
} catch (IllegalStateException e) {
if (HSSFDateUtil.isCellDateFormatted(cell)) {// 判断是否为日期类型
Date date = cell.getDateCellValue();
// DateFormat formater = new SimpleDateFormat("yyyy/MM/dd HH:mm");
DateFormat formater = new SimpleDateFormat("yyyy/MM/dd");
cellValue = formater.format(date);
} else {
FormulaEvaluator evaluator = cell.getSheet().getWorkbook().getCreationHelper()
.createFormulaEvaluator();
evaluator.evaluateFormulaCell(cell);
// 有些数字过大,直接输出使用的是科学计数法: 2.67458622E8 要进行处理
DecimalFormat df = new DecimalFormat("####.####");
cellValue = df.format(cell.getNumericCellValue());
// cellValue = cell.getNumericCellValue() + "";
}
}
// //直接获取公式
// cellValue = cell.getCellFormula() + "";
break;
case HSSFCell.CELL_TYPE_BLANK: // 空值
cellValue = "";
break;
case HSSFCell.CELL_TYPE_ERROR: // 故障
cellValue = "非法字符";
break;
default:
cellValue = "未知类型";
break;
}
}
return cellValue;
}
}
...@@ -3,12 +3,14 @@ ...@@ -3,12 +3,14 @@
*/ */
package com.jeeplus.modules.warehouse.materialtype.web; package com.jeeplus.modules.warehouse.materialtype.web;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import com.jeeplus.modules.warehouse.materialtype.utils.InitMaterialType;
import org.apache.shiro.authz.annotation.Logical; import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions; import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -23,7 +25,6 @@ import org.springframework.web.bind.annotation.PathVariable; ...@@ -23,7 +25,6 @@ import org.springframework.web.bind.annotation.PathVariable;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.jeeplus.common.json.AjaxJson; import com.jeeplus.common.json.AjaxJson;
import com.jeeplus.common.config.Global;
import com.jeeplus.core.web.BaseController; import com.jeeplus.core.web.BaseController;
import com.jeeplus.common.utils.StringUtils; import com.jeeplus.common.utils.StringUtils;
import com.jeeplus.modules.warehouse.materialtype.entity.MaterialType; import com.jeeplus.modules.warehouse.materialtype.entity.MaterialType;
...@@ -173,4 +174,51 @@ public class MaterialTypeController extends BaseController { ...@@ -173,4 +174,51 @@ public class MaterialTypeController extends BaseController {
return mapList; return mapList;
} }
@ResponseBody
@RequestMapping(value = "initType")
public AjaxJson initType() throws Exception{
String filePath = "D:\\yqd\\2023\\cangchuguanli\\warehouse\\doc\\PMDM.xlsx";
Map<String, String> codeIdMap = new HashMap<>();
List<MaterialType> materialTypeList = InitMaterialType.initType(filePath, "main", "0", "0,");
for (MaterialType materialType : materialTypeList) {
materialTypeService.insert(materialType);
codeIdMap.put(materialType.getCode(), materialType.getId());
}
String id = codeIdMap.get("001");
List<MaterialType> materialTypeList1 = InitMaterialType.initType(filePath, "07", id, "0," + id + ",");
for (MaterialType materialType : materialTypeList1) {
materialTypeService.save(materialType);
}
id = codeIdMap.get("002");
List<MaterialType> materialTypeList2 = InitMaterialType.initType(filePath, "0206", id, "0," + id + ",");
for (MaterialType materialType : materialTypeList2) {
materialTypeService.save(materialType);
}
id = codeIdMap.get("003");
List<MaterialType> materialTypeList3 = InitMaterialType.initType(filePath, "1821", id, "0," + id + ",");
for (MaterialType materialType : materialTypeList3) {
materialTypeService.save(materialType);
}
id = codeIdMap.get("004");
List<MaterialType> materialTypeList4 = InitMaterialType.initType(filePath, "21", id, "0," + id + ",");
for (MaterialType materialType : materialTypeList4) {
materialTypeService.save(materialType);
}
id = codeIdMap.get("005");
List<MaterialType> materialTypeList5 = InitMaterialType.initType(filePath, "qt", id, "0," + id + ",");
for (MaterialType materialType : materialTypeList5) {
materialTypeService.save(materialType);
}
AjaxJson j = new AjaxJson();
j.setMsg("初始化成功");
return j;
}
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment