diff --git a/hxhq-common/hxhq-common-core/src/main/java/com/hxhq/common/core/utils/DateUtils.java b/hxhq-common/hxhq-common-core/src/main/java/com/hxhq/common/core/utils/DateUtils.java index 3461a14..a2b95e4 100644 --- a/hxhq-common/hxhq-common-core/src/main/java/com/hxhq/common/core/utils/DateUtils.java +++ b/hxhq-common/hxhq-common-core/src/main/java/com/hxhq/common/core/utils/DateUtils.java @@ -27,8 +27,9 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils public static String YYYYMMDDHHMMSS = "yyyyMMddHHmmss"; public static String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss"; + public static String YYYY_MM_DD_HH_MM = "yyyy-MM-dd HH:mm"; - private static String[] parsePatterns = { + public static String[] parsePatterns = { "yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "yyyy-MM", "yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd HH:mm", "yyyy/MM", "yyyy.MM.dd", "yyyy.MM.dd HH:mm:ss", "yyyy.MM.dd HH:mm", "yyyy.MM"}; @@ -188,4 +189,32 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils ZonedDateTime zdt = localDateTime.atZone(ZoneId.systemDefault()); return Date.from(zdt.toInstant()); } + + /** + * 校验是否是正确的时间格式 + * @param dateStr 时间字符串 + * @param format 时间格式 + * @return + */ + public static boolean isValidTimeFormat(String dateStr, String format) { + SimpleDateFormat sdf = new SimpleDateFormat(format); + sdf.setLenient(false); // 设置为非宽容模式,这样解析失败会抛出异常 + try { + Date date = sdf.parse(dateStr); // 尝试解析字符串 + sdf.format(date); // 再次格式化日期,确保格式正确 + return true; + } catch (ParseException e) { + return false; // 解析失败,返回false + } + } + + public static boolean isValidTimeFormat(String dateStr, String[] formats) { + for (String format : formats) { + boolean validTimeFormat = isValidTimeFormat(dateStr, format); + if(!validTimeFormat) { + return false; + } + } + return true; + } } diff --git a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/controller/GspRkjlController.java b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/controller/GspRkjlController.java index 60f59b5..1476be6 100644 --- a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/controller/GspRkjlController.java +++ b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/controller/GspRkjlController.java @@ -18,6 +18,8 @@ import com.hxhq.common.core.utils.poi.ExcelUtil; import com.hxhq.common.security.annotation.RequiresPermissions; import com.hxhq.common.security.utils.SecurityUtils; import com.hxhq.system.api.domain.SysUser; +import com.hxhq.system.service.ISysUserService; +import org.apache.commons.collections4.CollectionUtils; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.validation.annotation.Validated; @@ -48,6 +50,9 @@ public class GspRkjlController extends BaseController @Autowired private IGspRkjlJcgjService gspRkjlJcgjService; + @Autowired + private ISysUserService sysUserService; + /** * 查询供试品入库记录列表 */ @@ -218,13 +223,19 @@ public class GspRkjlController extends BaseController @PostMapping("/importData") - public void importData(MultipartFile file, GspRkjlForm form, HttpServletResponse response) throws IOException + public AjaxResult importData(MultipartFile file, GspRkjlForm form, HttpServletResponse response) throws IOException { + form.setQmrId(SecurityUtils.getUserId()); + sysUserService.checkPassword(SecurityUtils.getUserId(), form.getQmrmm(), false); ExcelUtil util = new ExcelUtil(ImportGspRkjlDto.class); List gspRkjlDtoList = util.importExcel(file.getInputStream()); + if(CollectionUtils.isEmpty(gspRkjlDtoList)) { + throw new ServiceException("导入数据表格为空"); + } int i = 2; List importList = new ArrayList<>(); + List importDataList = new ArrayList<>(); for (ImportGspRkjlDto importGspRkjlDto : gspRkjlDtoList) { if(StringUtils.isEmpty(importGspRkjlDto.getMc())) { throw new ServiceException("第【" + i + "】行名称不能为空"); @@ -235,8 +246,8 @@ public class GspRkjlController extends BaseController if(StringUtils.isEmpty(importGspRkjlDto.getGg())) { throw new ServiceException("第【" + i + "】行规格不能为空"); } - if(StringUtils.isEmpty(importGspRkjlDto.getRksj())) { - throw new ServiceException("第【" + i + "】行入库时间不能为空"); + if(importGspRkjlDto.getRksj() == null) { + throw new ServiceException("第【" + i + "】行入库时间为空或时间格式错误"); } if(StringUtils.isEmpty(importGspRkjlDto.getRkl())) { throw new ServiceException("第【" + i + "】行入库量不能为空"); @@ -247,8 +258,8 @@ public class GspRkjlController extends BaseController if(StringUtils.isEmpty(importGspRkjlDto.getCctj())) { throw new ServiceException("第【" + i + "】行保存条件不能为空"); } - if(StringUtils.isEmpty(importGspRkjlDto.getYxq())) { - throw new ServiceException("第【" + i + "】行有效期不能为空"); + if(importGspRkjlDto.getYxq() == null) { + throw new ServiceException("第【" + i + "】行有效期为空或时间格式错误"); } if(StringUtils.isEmpty(importGspRkjlDto.getZysx())) { throw new ServiceException("第【" + i + "】行注意事项不能为空"); @@ -264,12 +275,11 @@ public class GspRkjlController extends BaseController if(gspRkjl != null) { throw new ServiceException("第【" + i + "】行系统已有记录"); } - Date rksj = DateUtils.parseDate(importGspRkjlDto.getRksj()); - gspRkjlForm.setRksj(rksj); - Date yxq = DateUtils.parseDate(importGspRkjlDto.getYxq()); - gspRkjlForm.setYxq(yxq); - + importDataList.add(gspRkjlForm); } + gspRkjlService.addBatch(importDataList, form); + + return success(); } } diff --git a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/controller/StorageLocationController.java b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/controller/StorageLocationController.java index 63e6933..b227ee3 100644 --- a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/controller/StorageLocationController.java +++ b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/controller/StorageLocationController.java @@ -1,17 +1,32 @@ package com.hxhq.business.controller; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; +import java.io.IOException; +import java.util.*; +import java.util.function.Function; +import java.util.stream.Collectors; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.hxhq.business.domain.GspRkjl; import com.hxhq.business.domain.StorageLocationJcgj; import com.hxhq.business.domain.YqJcgj; +import com.hxhq.business.dto.gsp.ImportGspRkjlDto; +import com.hxhq.business.dto.storage.ImportStorageLocationDto; +import com.hxhq.business.form.gsp.GspRkjlForm; import com.hxhq.business.form.yq.StorageLocationForm; import com.hxhq.business.form.yq.StorageLocationSearchForm; import com.hxhq.business.service.IStorageLocationJcgjService; +import com.hxhq.common.core.exception.ServiceException; +import com.hxhq.common.core.utils.StringUtils; +import com.hxhq.common.core.utils.poi.ExcelUtil; import com.hxhq.common.security.annotation.RequiresPermissions; import com.hxhq.common.security.utils.SecurityUtils; +import com.hxhq.system.api.domain.SysDept; +import com.hxhq.system.api.domain.SysDictData; +import com.hxhq.system.service.ISysDeptService; +import com.hxhq.system.service.ISysDictDataService; +import com.hxhq.system.service.ISysUserService; +import org.apache.commons.collections4.CollectionUtils; +import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import com.hxhq.business.domain.StorageLocation; @@ -19,6 +34,9 @@ import com.hxhq.business.service.IStorageLocationService; import com.hxhq.common.core.web.controller.BaseController; import com.hxhq.common.core.web.domain.AjaxResult; import com.hxhq.common.core.web.page.TableDataInfo; +import org.springframework.web.multipart.MultipartFile; + +import javax.servlet.http.HttpServletResponse; /** @@ -37,6 +55,13 @@ public class StorageLocationController extends BaseController @Autowired private IStorageLocationJcgjService storageLocationJcgjService; + @Autowired + private ISysUserService sysUserService; + + @Autowired + private ISysDeptService sysDeptService; + + /** * 查询仪器稽查轨迹列表 */ @@ -110,4 +135,76 @@ public class StorageLocationController extends BaseController storageLocationService.updateStorageLocation(form); return success(); } + + @PostMapping("/importTemplate") + @RequiresPermissions("business:storageLocation:import") + public void importTemplate(HttpServletResponse response) throws IOException + { + ExcelUtil util = new ExcelUtil(ImportStorageLocationDto.class); + util.importTemplateExcel(response, "【模板】存储位置"); + } + + + @PostMapping("/importData") + @RequiresPermissions("business:storageLocation:import") + public AjaxResult importData(MultipartFile file, StorageLocationForm form, HttpServletResponse response) throws IOException + { + form.setQmrId(SecurityUtils.getUserId()); + sysUserService.checkPassword(SecurityUtils.getUserId(), form.getQmrmm(), false); + + List sysDepts = sysDeptService.selectDeptList(new SysDept()); + Map sysDeptMap = new HashMap<>(); + for (SysDept sysDept : sysDepts) { + sysDeptMap.put(sysDept.getDeptName(), sysDept.getDeptId()); + } + + List list = storageLocationService.list(); + List storageLocationNameList = list.stream().map(StorageLocation::getName).collect(Collectors.toList()); + + + ExcelUtil util = new ExcelUtil(ImportStorageLocationDto.class); + List storageLocationDtos = util.importExcel(file.getInputStream()); + if(CollectionUtils.isEmpty(storageLocationDtos)) { + throw new ServiceException("导入数据表格为空"); + } + int i = 2; + List importList = new ArrayList<>(); + List importDataList = new ArrayList<>(); + for (ImportStorageLocationDto importStorageLocationDto : storageLocationDtos) { + if(StringUtils.isEmpty(importStorageLocationDto.getLocation())) { + throw new ServiceException("第【" + i + "】行放置地点不能为空"); + } + if(StringUtils.isEmpty(importStorageLocationDto.getName())) { + throw new ServiceException("第【" + i + "】行设备名称或编号不能为空"); + } + if(storageLocationNameList.contains(importStorageLocationDto.getName())) { + throw new ServiceException("第【" + i + "】行设备名称或编号【" + importStorageLocationDto.getName() + "】已存在"); + } + if(StringUtils.isEmpty(importStorageLocationDto.getShelfPlacement())) { + throw new ServiceException("第【" + i + "】行放置货架不能为空"); + } + if(StringUtils.isEmpty(importStorageLocationDto.getCompartment())) { + throw new ServiceException("第【" + i + "】行温层不能为空"); + } + if(StringUtils.isEmpty(importStorageLocationDto.getDeptName())) { + throw new ServiceException("第【" + i + "】行所属部门不能为空"); + } + Long deptId = sysDeptMap.get(importStorageLocationDto.getDeptName()); + if(deptId == null) { + throw new ServiceException("第【" + i + "】行所属部门【" + importStorageLocationDto.getDeptName() + "】名称有误,无法匹配对应数据"); + } + if(importList.contains(importStorageLocationDto.getName())) { + throw new ServiceException("第【" + i + "】行存在重复数据【" + importStorageLocationDto.getName() + "】"); + } + importList.add(importStorageLocationDto.getName()); + StorageLocation storageLocationForm = new StorageLocation(); + BeanUtils.copyProperties(importStorageLocationDto, storageLocationForm); + storageLocationForm.setDeptId(deptId); + storageLocationForm.setStatus(10); + importDataList.add(storageLocationForm); + } + storageLocationService.addBatch(importDataList, form); + + return success(); + } } diff --git a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/dto/gsp/ImportGspRkjlDto.java b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/dto/gsp/ImportGspRkjlDto.java index 6c8b13b..de9f38b 100644 --- a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/dto/gsp/ImportGspRkjlDto.java +++ b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/dto/gsp/ImportGspRkjlDto.java @@ -1,6 +1,10 @@ package com.hxhq.business.dto.gsp; import com.hxhq.common.core.annotation.Excel; +import com.hxhq.common.core.utils.DateUtils; + +import java.text.DateFormat; +import java.util.Date; public class ImportGspRkjlDto { @@ -14,7 +18,7 @@ public class ImportGspRkjlDto { private String gg; @Excel(name = "入库时间") - private String rksj; + private Date rksj; @Excel(name = "入库量") private String rkl; @@ -26,7 +30,7 @@ public class ImportGspRkjlDto { private String cctj; @Excel(name = "有效期") - private String yxq; + private Date yxq; @Excel(name = "注意事项") private String zysx; @@ -55,11 +59,11 @@ public class ImportGspRkjlDto { this.gg = gg; } - public String getRksj() { + public Date getRksj() { return rksj; } - public void setRksj(String rksj) { + public void setRksj(Date rksj) { this.rksj = rksj; } @@ -87,11 +91,11 @@ public class ImportGspRkjlDto { this.cctj = cctj; } - public String getYxq() { + public Date getYxq() { return yxq; } - public void setYxq(String yxq) { + public void setYxq(Date yxq) { this.yxq = yxq; } diff --git a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/dto/storage/ImportStorageLocationDto.java b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/dto/storage/ImportStorageLocationDto.java new file mode 100644 index 0000000..a3b92c5 --- /dev/null +++ b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/dto/storage/ImportStorageLocationDto.java @@ -0,0 +1,68 @@ +package com.hxhq.business.dto.storage; + +import com.baomidou.mybatisplus.annotation.TableField; +import com.hxhq.common.core.annotation.Compare; +import com.hxhq.common.core.annotation.Excel; + +import java.util.Date; + +public class ImportStorageLocationDto { + + @Excel(name = "放置地点") + private String location; + + /** 设备名称或编号 */ + @Excel(name = "设备名称或编号") + private String name; + + /** 放置货架 */ + @Excel(name = "放置货架") + private String shelfPlacement; + + /** 温层 */ + @Excel(name = "温层") + private String compartment; + + @Excel(name = "所属部门") + private String deptName; + + public String getLocation() { + return location; + } + + public void setLocation(String location) { + this.location = location; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getShelfPlacement() { + return shelfPlacement; + } + + public void setShelfPlacement(String shelfPlacement) { + this.shelfPlacement = shelfPlacement; + } + + public String getCompartment() { + return compartment; + } + + public void setCompartment(String compartment) { + this.compartment = compartment; + } + + public String getDeptName() { + return deptName; + } + + public void setDeptName(String deptName) { + this.deptName = deptName; + } +} diff --git a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/form/gsp/GspRkjlForm.java b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/form/gsp/GspRkjlForm.java index ec1ca39..b4d6730 100644 --- a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/form/gsp/GspRkjlForm.java +++ b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/form/gsp/GspRkjlForm.java @@ -35,7 +35,7 @@ public class GspRkjlForm { @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") private Date rksj; - @JsonFormat(pattern = "yyyy-MM-dd") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") private Date yxq; /** 存储条件 */ diff --git a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/service/IStorageLocationService.java b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/service/IStorageLocationService.java index b2ffb5b..a3f1c2f 100644 --- a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/service/IStorageLocationService.java +++ b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/service/IStorageLocationService.java @@ -42,4 +42,11 @@ public interface IStorageLocationService extends IService * @param form */ void updateStorageLocation(StorageLocationForm form); + + /** + * 批量添加存储位置 + * @param importDataList + * @param form + */ + void addBatch(List importDataList, StorageLocationForm form); } diff --git a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/service/impl/GspRkjlServiceImpl.java b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/service/impl/GspRkjlServiceImpl.java index c0b8418..31dadc8 100644 --- a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/service/impl/GspRkjlServiceImpl.java +++ b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/service/impl/GspRkjlServiceImpl.java @@ -139,7 +139,7 @@ public class GspRkjlServiceImpl extends ServiceImpl impl queryWrapper.eq(GspRkjl::getMc, form.getMc()) .eq(GspRkjl::getPh, form.getPh()) .eq(GspRkjl::getGg, form.getGg()) - .eq(GspRkjl::getGgdw, form.getGgdw()) +// .eq(GspRkjl::getGgdw, form.getGgdw()) .eq(GspRkjl::getRksj, form.getRksj()); return getOne(queryWrapper); } diff --git a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/service/impl/StorageLocationServiceImpl.java b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/service/impl/StorageLocationServiceImpl.java index 7af158f..6d46ea6 100644 --- a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/service/impl/StorageLocationServiceImpl.java +++ b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/service/impl/StorageLocationServiceImpl.java @@ -148,4 +148,13 @@ public class StorageLocationServiceImpl extends ServiceImpl importDataList, StorageLocationForm form) { + this.saveBatch(importDataList); + for (StorageLocation storageLocation : importDataList) { + storageLocationJcgjService.saveJcgj(storageLocation, JcgjlxEnum.bj.getValue(), + "新增存储位置", "Add Storage Location", JcmcysEnum.blue.getValue(), null, null); + } + } + }