|
@@ -19,6 +19,11 @@ import org.apache.poi.hssf.usermodel.HSSFRow;
|
|
|
import org.apache.poi.hssf.usermodel.HSSFSheet;
|
|
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
|
import org.apache.poi.ss.usermodel.CellType;
|
|
|
+import org.apache.poi.xssf.streaming.SXSSFWorkbook;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFCell;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFRow;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFSheet;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.StringUtils;
|
|
@@ -30,7 +35,9 @@ import javax.servlet.http.HttpServletRequest;
|
|
|
import java.io.*;
|
|
|
import java.lang.reflect.InvocationTargetException;
|
|
|
import java.lang.reflect.Method;
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.time.DateTimeException;
|
|
|
+import java.time.LocalDate;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.LocalTime;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
@@ -75,7 +82,7 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
|
|
private AttachmentCenterMapper attachmentCenterMapper;
|
|
|
|
|
|
@Override
|
|
|
- public HttpRespMsg getList(Integer companyId,String userId, String productName, String productCode,Integer productType,Integer status, Integer pageIndex, Integer pageSize) {
|
|
|
+ public HttpRespMsg getList(Integer companyId,String userId, String productName, String productCode,Integer productType,Integer status,String startDate,String endDate, Integer pageIndex, Integer pageSize) {
|
|
|
HttpRespMsg msg=new HttpRespMsg();
|
|
|
User targetUsr = userMapper.selectById(request.getHeader("token"));
|
|
|
List<Department> departments = departmentMapper.selectList(new LambdaQueryWrapper<Department>().eq(Department::getCompanyId, companyId));
|
|
@@ -133,6 +140,12 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
|
|
if(status!=null){
|
|
|
queryWrapper.eq(Product::getStatus,status);
|
|
|
}
|
|
|
+ if(startDate!=null && endDate!=null){
|
|
|
+ DateTimeFormatter df=DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
+ LocalDateTime start = LocalDate.parse(startDate, df).atTime(LocalTime.MIN);
|
|
|
+ LocalDateTime end = LocalDate.parse(endDate, df).atTime(LocalTime.MAX);
|
|
|
+ queryWrapper.between(Product::getCreateTime,start,end);
|
|
|
+ }
|
|
|
if(pageIndex==null&&pageSize==null){
|
|
|
pageIndex=-1;
|
|
|
pageSize=-1;
|
|
@@ -189,9 +202,9 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
|
|
inputStream.close();
|
|
|
outputStream.close();
|
|
|
//解析表格
|
|
|
- HSSFWorkbook workbook = new HSSFWorkbook(new FileInputStream(file));
|
|
|
+ XSSFWorkbook workbook = new XSSFWorkbook(file);
|
|
|
//我们只需要第一个sheet
|
|
|
- HSSFSheet sheet = workbook.getSheetAt(0);
|
|
|
+ XSSFSheet sheet = workbook.getSheetAt(0);
|
|
|
//由于第一行需要指明列对应的标题
|
|
|
int rowNum = sheet.getLastRowNum();
|
|
|
//获取当前表单模板 校验规则
|
|
@@ -207,7 +220,7 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
|
|
List<String> userNameList=new ArrayList<>();
|
|
|
HttpRespMsg respMsg=new HttpRespMsg();
|
|
|
for (int rowIndex = 0; rowIndex <= rowNum; rowIndex++) {
|
|
|
- HSSFRow row = sheet.getRow(rowIndex);
|
|
|
+ XSSFRow row = sheet.getRow(rowIndex);
|
|
|
if (row == null) {
|
|
|
continue;
|
|
|
}
|
|
@@ -220,7 +233,7 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
|
|
for (int i = 0; i < cellNum; i++) {
|
|
|
JSONObject item = configObJSONArray.getJSONObject(i);
|
|
|
String modelName = item.getString("model");
|
|
|
- HSSFCell cell = row.getCell(i);
|
|
|
+ XSSFCell cell = row.getCell(i);
|
|
|
if(cell!=null){
|
|
|
switch (item.getString("type")){
|
|
|
case "time":cell.setCellType(CellType.NUMERIC);
|
|
@@ -245,8 +258,9 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
|
|
}
|
|
|
}
|
|
|
List<User> targetUserList= (List<User>) respMsg.data;
|
|
|
- for (int rowIndex = 0; rowIndex <= rowNum; rowIndex++) {
|
|
|
- HSSFRow row = sheet.getRow(rowIndex);
|
|
|
+ //直接忽略空行 从row1开始
|
|
|
+ for (int rowIndex = 1; rowIndex <= rowNum; rowIndex++) {
|
|
|
+ XSSFRow row = sheet.getRow(rowIndex);
|
|
|
if (row == null) {
|
|
|
continue;
|
|
|
}
|
|
@@ -265,7 +279,7 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
|
|
String className = modelName.substring(0, 1).toUpperCase() + modelName.substring(1);
|
|
|
String getter="get"+className;
|
|
|
String setter="set"+className;
|
|
|
- HSSFCell cell = row.getCell(i);
|
|
|
+ XSSFCell cell = row.getCell(i);
|
|
|
if(cell!=null){
|
|
|
switch (item.getString("type")){
|
|
|
case "time":cell.setCellType(CellType.NUMERIC);
|
|
@@ -274,8 +288,6 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
|
|
}
|
|
|
}
|
|
|
// Class<?> productClass = Class.forName("com.management.platform.entity.Product");
|
|
|
- Class<Product> productClass = Product.class;
|
|
|
- Method method = productClass.getMethod(setter, String.class);
|
|
|
//校验当前列是否为必填
|
|
|
JSONObject options = item.getJSONObject("options");
|
|
|
JSONObject rules = options.getJSONObject("rules");
|
|
@@ -293,9 +305,9 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
|
|
if(first.isPresent()){
|
|
|
product.setId(first.get().getId());
|
|
|
}
|
|
|
+ product.setProductCode(cell.getStringCellValue());
|
|
|
}
|
|
|
- }
|
|
|
- if(modelName.equals("inchargerId")){
|
|
|
+ }else if(modelName.equals("inchargerId")){
|
|
|
if(!StringUtils.isEmpty(cell.getStringCellValue())){
|
|
|
String userName = cell.getStringCellValue();
|
|
|
Optional<User> first;
|
|
@@ -308,11 +320,11 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
|
|
if (first.isPresent()) {
|
|
|
product.setInchargerId(first.get().getId());
|
|
|
} else {
|
|
|
- throw new Exception("["+userName+"]在系统中不存在");
|
|
|
+ msg.setError("["+userName+"]在系统中不存在");
|
|
|
+ return msg;
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
- if(modelName.equals("status")){
|
|
|
+ }else if(modelName.equals("status")){
|
|
|
if(!StringUtils.isEmpty(cell.getStringCellValue())){
|
|
|
switch (cell.getStringCellValue()){
|
|
|
case "下架":product.setStatus(0);
|
|
@@ -321,18 +333,25 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
- if(modelName.equals("type")){
|
|
|
+ }else if(modelName.equals("price")){
|
|
|
+ if(!StringUtils.isEmpty(cell.getStringCellValue())){
|
|
|
+ product.setPrice(new BigDecimal(cell.getStringCellValue()));
|
|
|
+ }
|
|
|
+ }else if(modelName.equals("inventory")){
|
|
|
+ if(!StringUtils.isEmpty(cell.getStringCellValue())){
|
|
|
+ product.setInventory(new BigDecimal(cell.getStringCellValue()).intValue());
|
|
|
+ }
|
|
|
+ }else if(modelName.equals("type")){
|
|
|
if(!StringUtils.isEmpty(cell.getStringCellValue())){
|
|
|
Optional<SysDict> first = sysDictOfProductType.stream().filter(s -> s.getName().equals(cell.getStringCellValue())).findFirst();
|
|
|
if(first.isPresent()){
|
|
|
product.setType(first.get().getId());
|
|
|
}else {
|
|
|
- throw new Exception("产品类型["+cell.getStringCellValue()+"不存在,请在系统字典中增加");
|
|
|
+ msg.setError("产品类型["+cell.getStringCellValue()+"]不存在,请在系统字典中增加");
|
|
|
+ return msg;
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
- if(modelName.equals("unit")){
|
|
|
+ } else if(modelName.equals("unit")){
|
|
|
if(!StringUtils.isEmpty(cell.getStringCellValue())){
|
|
|
Optional<SysDict> first = sysDictOfProductUnit.stream().filter(s -> s.getName().equals(cell.getStringCellValue())).findFirst();
|
|
|
if(first.isPresent()){
|
|
@@ -341,10 +360,14 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
|
|
throw new Exception("产品单位["+cell.getStringCellValue()+"不存在,请在系统字典中增加");
|
|
|
}
|
|
|
}
|
|
|
+ }else {
|
|
|
+ if(!StringUtils.isEmpty(cell.getStringCellValue())){
|
|
|
+ Class<Product> productClass = Product.class;
|
|
|
+ Method method = productClass.getMethod(setter,String.class);
|
|
|
+ method.invoke(product,cell.getStringCellValue());
|
|
|
+ }
|
|
|
}
|
|
|
- if(!StringUtils.isEmpty(cell.getStringCellValue())){
|
|
|
- method.invoke(product,cell.getStringCellValue());
|
|
|
- }
|
|
|
+
|
|
|
}
|
|
|
importProductList.add(product);
|
|
|
}
|
|
@@ -362,12 +385,14 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
|
|
e.printStackTrace();
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
+ msg.setError("验证失败");
|
|
|
+ return msg;
|
|
|
}
|
|
|
return msg;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public HttpRespMsg exportData(String userId, String productName, String productCode,Integer productType,Integer status) throws Exception {
|
|
|
+ public HttpRespMsg exportData(String userId, String productName, String productCode,Integer productType,Integer status,String startDate,String endDate) throws Exception {
|
|
|
User user = userMapper.selectById(request.getHeader("token"));
|
|
|
SysForm sysForm = sysFormMapper.selectOne(new LambdaQueryWrapper<SysForm>().eq(SysForm::getCompanyId, user.getCompanyId()).eq(SysForm::getCode, "Product").eq(SysForm::getIsCurrent, 1));
|
|
|
WxCorpInfo wxCorpInfo = wxCorpInfoService.getOne(new LambdaQueryWrapper<WxCorpInfo>().eq(WxCorpInfo::getCompanyId, user.getCompanyId()));
|
|
@@ -381,7 +406,7 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
|
|
titleList.add(item.getString("label"));
|
|
|
}
|
|
|
dataList.add(titleList);
|
|
|
- HttpRespMsg respMsg = getList(user.getCompanyId(), userId, productName, productCode,productType,status, null, null);
|
|
|
+ HttpRespMsg respMsg = getList(user.getCompanyId(), userId, productName, productCode,productType,status,startDate,endDate, null, null);
|
|
|
Map<String, Object> msgData = (Map<String, Object>) respMsg.getData();
|
|
|
List<Product> productList = (List<Product>) msgData.get("record");
|
|
|
for (Product product : productList) {
|