需求计划申请导入表格
This commit is contained in:
parent
8e70fd60e0
commit
3a597acbd4
|
|
@ -17,8 +17,10 @@ import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.poi.ss.usermodel.Workbook;
|
import org.apache.poi.ss.usermodel.Workbook;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import javax.servlet.ServletOutputStream;
|
import javax.servlet.ServletOutputStream;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -206,4 +208,14 @@ public class CarTypeController {
|
||||||
return service.getProListSelected(dto.getData());
|
return service.getProListSelected(dto.getData());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 计划车辆类型的方法
|
||||||
|
* @param
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PostMapping("importExcelTools")
|
||||||
|
public ServerResponse importExcelTools(HttpServletRequest request, @RequestParam(value = "file[]",required = false) MultipartFile[] files) {
|
||||||
|
return service.importExcelTools(request,files);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package com.bonus.gzcar.business.backstage.mapper;
|
||||||
import com.bonus.gzcar.business.backstage.entity.CarProVo;
|
import com.bonus.gzcar.business.backstage.entity.CarProVo;
|
||||||
import com.bonus.gzcar.business.backstage.entity.CarTypeVo;
|
import com.bonus.gzcar.business.backstage.entity.CarTypeVo;
|
||||||
import io.swagger.models.auth.In;
|
import io.swagger.models.auth.In;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -82,4 +83,6 @@ public interface CarTypeMapper {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
int getNumByContract(CarTypeVo data);
|
int getNumByContract(CarTypeVo data);
|
||||||
|
|
||||||
|
CarTypeVo getExist(@Param("param") CarTypeVo planDevBean);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,9 @@ package com.bonus.gzcar.business.backstage.service;
|
||||||
import com.bonus.gzcar.business.backstage.entity.CarProVo;
|
import com.bonus.gzcar.business.backstage.entity.CarProVo;
|
||||||
import com.bonus.gzcar.business.backstage.entity.CarTypeVo;
|
import com.bonus.gzcar.business.backstage.entity.CarTypeVo;
|
||||||
import com.bonus.gzcar.manager.webResult.ServerResponse;
|
import com.bonus.gzcar.manager.webResult.ServerResponse;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface CarTypeService {
|
public interface CarTypeService {
|
||||||
|
|
@ -71,4 +73,12 @@ public interface CarTypeService {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
ServerResponse getProListSelected(CarProVo data);
|
ServerResponse getProListSelected(CarProVo data);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 计划车辆类型
|
||||||
|
* @param request
|
||||||
|
* @param files
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
ServerResponse importExcelTools(HttpServletRequest request, MultipartFile[] files);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,10 +9,17 @@ import com.bonus.gzcar.manager.common.util.StringHelper;
|
||||||
import com.bonus.gzcar.manager.common.util.UserUtil;
|
import com.bonus.gzcar.manager.common.util.UserUtil;
|
||||||
import com.bonus.gzcar.manager.webResult.ServerResponse;
|
import com.bonus.gzcar.manager.webResult.ServerResponse;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.poi.ss.usermodel.*;
|
||||||
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -220,4 +227,84 @@ public class CarTypeServiceImpl implements CarTypeService{
|
||||||
}
|
}
|
||||||
return ServerResponse.createSuccess(new ArrayList<CarProVo>());
|
return ServerResponse.createSuccess(new ArrayList<CarProVo>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ServerResponse importExcelTools(HttpServletRequest request, MultipartFile[] files) {
|
||||||
|
List<CarTypeVo> dataList = new ArrayList<>();
|
||||||
|
List<CarTypeVo> nonExistList = new ArrayList<>(); // 用于记录数据库中不存在的数据
|
||||||
|
try {
|
||||||
|
for (MultipartFile file : files) {
|
||||||
|
if (!file.isEmpty()) {
|
||||||
|
InputStream inputStream = file.getInputStream();
|
||||||
|
Workbook workbook = new XSSFWorkbook(inputStream);
|
||||||
|
Sheet sheet = workbook.getSheetAt(0);
|
||||||
|
//先去取数据
|
||||||
|
for (int i = 2; i <= sheet.getLastRowNum(); i++) { // 假设第一行是标题行
|
||||||
|
Row row = sheet.getRow(i);
|
||||||
|
CarTypeVo data = new CarTypeVo();
|
||||||
|
// 获取全部列的值
|
||||||
|
data.setType(row.getCell(1).getStringCellValue()); //物资类型
|
||||||
|
data.setName(row.getCell(2).getStringCellValue()); //物资名称
|
||||||
|
data.setModel(row.getCell(3).getStringCellValue()); //物资型号
|
||||||
|
data.setUnit(row.getCell(4).getStringCellValue()); //单位
|
||||||
|
data.setNeedNum((int)row.getCell(5).getNumericCellValue());//数量
|
||||||
|
data.setTimes((int)row.getCell(6).getNumericCellValue());//数量
|
||||||
|
/* Cell cell = row.getCell(6); // 假设时间是在第7列(0-based index 6)
|
||||||
|
if (cell != null) {
|
||||||
|
String timeValue;
|
||||||
|
switch (cell.getCellType()) {
|
||||||
|
case STRING:
|
||||||
|
// 如果单元格内容是字符串,直接获取其值
|
||||||
|
timeValue = cell.getStringCellValue().trim();
|
||||||
|
break;
|
||||||
|
case NUMERIC:
|
||||||
|
if (DateUtil.isCellDateFormatted(cell)) {
|
||||||
|
// 如果单元格是日期格式
|
||||||
|
Date date = cell.getDateCellValue();
|
||||||
|
// 格式化日期为字符串
|
||||||
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
||||||
|
timeValue = dateFormat.format(date);
|
||||||
|
} else {
|
||||||
|
// 如果不是日期格式,但为数值类型,可能需要其他处理逻辑
|
||||||
|
log.warn("单元格不是日期格式,而是数值: {}", cell.getNumericCellValue());
|
||||||
|
timeValue = String.valueOf(cell.getNumericCellValue());
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
log.warn("不支持的单元格类型: {}", cell.getCellType());
|
||||||
|
timeValue = "";
|
||||||
|
}
|
||||||
|
data.setTimes(Integer.parseInt(timeValue));
|
||||||
|
} else {
|
||||||
|
log.warn("单元格为空");
|
||||||
|
data.setTimes(Integer.parseInt(""));
|
||||||
|
}*/
|
||||||
|
data.setRemarks(row.getCell(7).getStringCellValue()); //备注
|
||||||
|
dataList.add(data);
|
||||||
|
}
|
||||||
|
workbook.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(dataList!=null && !dataList.isEmpty()){
|
||||||
|
for (CarTypeVo planDevBean : dataList) {
|
||||||
|
//根据物资类型,物资名称,物资型号 去数据库查询是否存在
|
||||||
|
CarTypeVo bean = mapper.getExist(planDevBean);
|
||||||
|
if(bean == null){
|
||||||
|
// 在数据库中不存在,则记录下,全部判断完,返回到前段,提示
|
||||||
|
nonExistList.add(planDevBean);
|
||||||
|
}else{
|
||||||
|
planDevBean.setId(bean.getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 如果存在数据库中不存在的数据,返回提示
|
||||||
|
if (!nonExistList.isEmpty()) {
|
||||||
|
return ServerResponse.createError("导入失败,以下数据在数据库中不存在", nonExistList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ServerResponse.createSuccess("导入成功", dataList);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error(e.toString(), e);
|
||||||
|
}
|
||||||
|
return ServerResponse.createError("导入失败,请检查表格数据",dataList);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -116,4 +116,17 @@
|
||||||
where cc.is_active=1 and cct.model_id=#{id}
|
where cc.is_active=1 and cct.model_id=#{id}
|
||||||
|
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<select id="getExist" resultType="com.bonus.gzcar.business.backstage.entity.CarTypeVo">
|
||||||
|
select cmt.id ,cmt.parent_id parentId,cmt.`name` model ,cmt.is_active isActive,
|
||||||
|
cmt.unit_name unit,cmt1.name ,cmt2.name type,cmt.`level`
|
||||||
|
from car_ma_type cmt
|
||||||
|
left join car_ma_type cmt1 on cmt.parent_id=cmt1.id
|
||||||
|
left join car_ma_type cmt2 on cmt1.parent_id=cmt2.id
|
||||||
|
where cmt.`level`=4
|
||||||
|
AND cmt2.name = #{param.type}
|
||||||
|
AND cmt1.name = #{param.name}
|
||||||
|
AND cmt.`name` = #{param.model}
|
||||||
|
and cmt.is_active=1
|
||||||
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
Loading…
Reference in New Issue