需求计划申请表格导入
This commit is contained in:
parent
f343536e3c
commit
42fac01f76
|
|
@ -17,9 +17,11 @@ import io.swagger.annotations.Api;
|
|||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.List;
|
||||
|
|
@ -253,4 +255,15 @@ public class PlanApplyController {
|
|||
PageInfo<MaTypeVo> pageInfo = new PageInfo<>(list);
|
||||
return pageInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 安全工器具的方法
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("importExcelTools")
|
||||
public ServerResponse importExcelTools(HttpServletRequest request, @RequestParam(value = "file[]",required = false) MultipartFile[] files) {
|
||||
return service.importExcelTools(request,files);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -168,4 +168,11 @@ public interface PlanApplyMapper {
|
|||
* @date 2025/1/23 18:47
|
||||
*/
|
||||
Integer getPlanData(PlanApplyVo data);
|
||||
|
||||
/**
|
||||
* 判断安全工器具是否存在
|
||||
* @param planDevBean
|
||||
* @return
|
||||
*/
|
||||
MaTypeVo getExist(@Param("param") MaTypeVo planDevBean);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,9 @@ import com.bonus.aqgqj.business.backstage.entity.plan.PlanApplyVo;
|
|||
import com.bonus.aqgqj.business.backstage.entity.plan.PlanDetailVo;
|
||||
import com.bonus.aqgqj.manager.webResult.AjaxResult;
|
||||
import com.bonus.aqgqj.manager.webResult.ServerResponse;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
|
@ -96,4 +98,15 @@ public interface PlanApplyService {
|
|||
* @date 2024/12/20 15:28
|
||||
*/
|
||||
ServerResponse editApplyPlan(PlanApplyVo data);
|
||||
|
||||
/**
|
||||
* 导入安全工器具
|
||||
*
|
||||
* @param request
|
||||
* @param files
|
||||
* @return ServerResponse
|
||||
* @author cwchen
|
||||
* @date 2024/12/20 15:28
|
||||
*/
|
||||
ServerResponse importExcelTools(HttpServletRequest request, MultipartFile[] files);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,14 +15,18 @@ import com.bonus.aqgqj.manager.webResult.ServerResponse;
|
|||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.InputStream;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @className:PlanApplyServiceImpl
|
||||
|
|
@ -166,6 +170,85 @@ public class PlanApplyServiceImpl implements PlanApplyService {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerResponse importExcelTools(HttpServletRequest request, MultipartFile[] files) {
|
||||
List<MaTypeVo> dataList = new ArrayList<>();
|
||||
List<MaTypeVo> 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);
|
||||
MaTypeVo data = new MaTypeVo();
|
||||
// 获取全部列的值
|
||||
data.setType(row.getCell(1).getStringCellValue()); //物资类型
|
||||
data.setName(row.getCell(2).getStringCellValue()); //物资名称
|
||||
data.setModel(row.getCell(3).getStringCellValue()); //物资型号
|
||||
data.setUnitName(row.getCell(4).getStringCellValue()); //单位
|
||||
data.setNeedNum(row.getCell(5).getStringCellValue()); //数量
|
||||
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(timeValue);
|
||||
} else {
|
||||
log.warn("单元格为空");
|
||||
data.setTimes("");
|
||||
}
|
||||
data.setRemarks(row.getCell(7).getStringCellValue()); //备注
|
||||
dataList.add(data);
|
||||
}
|
||||
workbook.close();
|
||||
}
|
||||
}
|
||||
if(dataList!=null && !dataList.isEmpty()){
|
||||
for (MaTypeVo planDevBean : dataList) {
|
||||
//根据物资类型,物资名称,物资型号 去数据库查询是否存在
|
||||
MaTypeVo 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);
|
||||
}
|
||||
|
||||
private static String getCode(int num) {
|
||||
num++;
|
||||
String year = DateTimeHelper.getNowYMD();
|
||||
|
|
|
|||
|
|
@ -261,4 +261,28 @@
|
|||
FROM st_plan_apply spa
|
||||
WHERE spa.id = #{id} AND spa.status_type = '2' AND spa.status = '1'
|
||||
</select>
|
||||
|
||||
<select id="getExist" resultType="com.bonus.aqgqj.business.backstage.entity.MaTypeVo">
|
||||
SELECT mt.id AS id,
|
||||
mt.parent_id AS parentId,
|
||||
mt.name AS title,
|
||||
mt.unit_name AS unitName,
|
||||
mt3.name AS type,
|
||||
mt.remark,
|
||||
mt.level,
|
||||
mt2.name,
|
||||
mt.name AS model
|
||||
FROM st_ma_type mt
|
||||
LEFT JOIN st_ma_type mt2 ON mt.parent_id = mt2.id
|
||||
LEFT JOIN st_ma_type mt3 ON mt2.parent_id = mt3.id
|
||||
INNER JOIN (
|
||||
SELECT DISTINCT sct.model_id AS modelId
|
||||
FROM st_contract_type sct
|
||||
INNER JOIN st_contract sc ON sct.contract_id = sc.id AND sc.is_active = '0' AND CURRENT_DATE BETWEEN sc.start_time AND sc.end_time
|
||||
) a ON a.modelId = mt.id
|
||||
WHERE mt.level = '3'
|
||||
and mt3.name = #{type}
|
||||
and mt2.name = #{name}
|
||||
and mt.name = #{model}
|
||||
</select>
|
||||
</mapper>
|
||||
Loading…
Reference in New Issue