diff --git a/src/main/java/digital/laboratory/platform/imr/controller/DrugDepotsController.java b/src/main/java/digital/laboratory/platform/imr/controller/DrugDepotsController.java index 791c20e..3fe286c 100644 --- a/src/main/java/digital/laboratory/platform/imr/controller/DrugDepotsController.java +++ b/src/main/java/digital/laboratory/platform/imr/controller/DrugDepotsController.java @@ -1,10 +1,46 @@ package digital.laboratory.platform.imr.controller; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.StrUtil; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import digital.laboratory.platform.common.core.constant.CommonConstants; +import digital.laboratory.platform.common.core.util.R; +import digital.laboratory.platform.common.feign.RemoteTemplate2htmlService; +import digital.laboratory.platform.common.mybatis.security.service.DLPUser; +import digital.laboratory.platform.imr.convert.DrugCaseInfoConvert; +import digital.laboratory.platform.imr.dto.DrugDepotsDTO; +import digital.laboratory.platform.imr.dto.InRepositoryDTO; +import digital.laboratory.platform.imr.entity.DrugCaseInfo; +import digital.laboratory.platform.imr.entity.DrugMaterialInfo; +import digital.laboratory.platform.imr.query.DrugDepotsQuery; +import digital.laboratory.platform.imr.service.CommonFeignService; +import digital.laboratory.platform.imr.service.DrugCaseInfoService; +import digital.laboratory.platform.imr.service.DrugMaterialInfoService; +import digital.laboratory.platform.imr.vo.DrugCaseInfoVO; +import digital.laboratory.platform.imr.vo.DrugMaterialInfoVO; +import digital.laboratory.platform.imr.vo.OutSampleVO; +import digital.laboratory.platform.sys.entity.Drug; +import digital.laboratory.platform.sys.feign.RemoteOrgService; import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.beans.BeanUtils; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.security.oauth2.provider.OAuth2Authentication; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; +import javax.validation.Valid; +import java.security.Principal; +import java.util.HashMap; +import java.util.List; +import java.util.Map; @RestController @RequiredArgsConstructor @@ -12,4 +48,72 @@ import org.springframework.web.bind.annotation.RestController; @Api(value = "DrugDepotsController", tags = "毒品库信息管理接口") public class DrugDepotsController { + @Resource + private DrugCaseInfoService drugCaseInfoService; + + @Resource + private DrugMaterialInfoService drugMaterialInfoService; + + + @ApiOperation(value = "新增毒品案件信息") + @PostMapping("/drugCase/save") + public R drugCaseSave(@RequestBody @Valid DrugDepotsDTO dto) { + DrugCaseInfo save = drugCaseInfoService.drugCaseSave(dto); + return R.ok(save); + } + + @ApiOperation(value = "新增毒品案件信息和毒品检材信息") + @PostMapping("/save") + public R save(@RequestBody @Valid DrugDepotsDTO dto) { + List save = drugCaseInfoService.save(dto); + return R.ok(save); + } + + @ApiOperation(value = "毒品案件信息和毒品检材信息分页接口") + @PostMapping("/drugMaterial/page") + public R> drugMaterialPage(@RequestBody DrugDepotsQuery query) { + IPage page = drugMaterialInfoService.page(query); + return R.ok(page); + } + + @ApiOperation(value = "毒品案件信息分页接口") + @PostMapping("/drugCase/page") + public R> drugCasePage(@RequestBody DrugDepotsQuery query) { + Page drugCaseInfoVOPage = drugCaseInfoService.getDrugCaseInfoVOPage(query); + return R.ok(drugCaseInfoVOPage); + } + + @ApiOperation("删除毒品检材信息") + @PostMapping("/delete/drugMaterial") + public R deleteDrugMaterial(@RequestBody List ids) { + boolean removeBatchByIds = drugMaterialInfoService.removeBatchByIds(ids); + return removeBatchByIds ? R.ok(true, "删除成功!") : R.failed(false, "删除失败!"); + } + + @ApiOperation(value = "根据模板生成样本标签的 html, 供 qz 打印使用", notes = "根据模板生成样本标签的 html, 供 qz 打印使用") + @ApiImplicitParams({ + @ApiImplicitParam(name = "id", value = "检材标识", required = true, paramType = "path") + }) + @GetMapping("/drug_label/{id}") + public String getDrugLabelHtml(@PathVariable(value = "id") String id) { + return drugMaterialInfoService.buildDrugLabelHtml(id); + } + + @ApiOperation(value = "根据毒品编号录入仓库(入库)", notes = "根据样本编号录入仓库(入库)") + @PostMapping("/drugMaterialPutInRepository") + public R drugMaterialPutInRepository(@RequestBody List sample, HttpServletRequest theHttpServletRequest) { + Principal principal = theHttpServletRequest.getUserPrincipal(); + DLPUser dlpUser = (DLPUser) ((OAuth2Authentication) principal).getUserAuthentication().getPrincipal(); + + if (CollUtil.isEmpty(sample)) { + throw new RuntimeException("入库样本编号不能为空"); + } + + List vo = drugMaterialInfoService.drugMaterialPutInRepository(sample, dlpUser); + if (vo != null) { + return R.ok(vo, "样本入库成功,本次入库样本数为" + sample.size() + "份"); + } else { + return R.failed("入库失败"); + } + } } diff --git a/src/main/java/digital/laboratory/platform/imr/convert/DrugCaseInfoConvert.java b/src/main/java/digital/laboratory/platform/imr/convert/DrugCaseInfoConvert.java new file mode 100644 index 0000000..36eb9fb --- /dev/null +++ b/src/main/java/digital/laboratory/platform/imr/convert/DrugCaseInfoConvert.java @@ -0,0 +1,50 @@ +package digital.laboratory.platform.imr.convert; + +import cn.hutool.core.collection.CollUtil; +import digital.laboratory.platform.imr.dto.DrugDepotsDTO; +import digital.laboratory.platform.imr.entity.DrugCaseInfo; +import digital.laboratory.platform.imr.vo.DrugCaseInfoVO; + +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + +/** + * 毒品案件转换类 + */ +public class DrugCaseInfoConvert { + + public static DrugCaseInfo dtoTOEntity(DrugDepotsDTO dto) { + if (dto == null) { + return null; + } + DrugCaseInfo drugCaseInfo = new DrugCaseInfo(); + drugCaseInfo.setId(dto.getId()); + drugCaseInfo.setCaseName(dto.getCaseName()); + drugCaseInfo.setCaseNo(dto.getCaseNo()); + drugCaseInfo.setHandingOverOrg(dto.getHandingOverOrg()); + drugCaseInfo.setHandingOverDate(dto.getHandingOverDate()); + return drugCaseInfo; + } + + public static DrugCaseInfoVO entityToVO(DrugCaseInfo entity) { + if (entity == null) { + return null; + } + + DrugCaseInfoVO drugCaseInfoVO = new DrugCaseInfoVO(); + drugCaseInfoVO.setId(entity.getId()); + drugCaseInfoVO.setCaseName(entity.getCaseName()); + drugCaseInfoVO.setCaseNo(entity.getCaseNo()); + drugCaseInfoVO.setHandingOverOrg(entity.getHandingOverOrg()); + drugCaseInfoVO.setHandingOverDate(entity.getHandingOverDate()); + return drugCaseInfoVO; + } + + public static List entityToVOList(List entityList) { + if (CollUtil.isEmpty(entityList)) { + return Collections.emptyList(); + } + return entityList.stream().map(entity -> entityToVO(entity)).collect(Collectors.toList()); + } +} diff --git a/src/main/java/digital/laboratory/platform/imr/convert/DrugMaterialInfoConvert.java b/src/main/java/digital/laboratory/platform/imr/convert/DrugMaterialInfoConvert.java new file mode 100644 index 0000000..3d95034 --- /dev/null +++ b/src/main/java/digital/laboratory/platform/imr/convert/DrugMaterialInfoConvert.java @@ -0,0 +1,37 @@ +package digital.laboratory.platform.imr.convert; + +import cn.hutool.core.collection.CollUtil; +import digital.laboratory.platform.imr.dto.DrugMaterialInfoDTO; +import digital.laboratory.platform.imr.entity.DrugMaterialInfo; + +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + +/** + * 毒品检材信息转换类 + */ +public class DrugMaterialInfoConvert { + + public static DrugMaterialInfo dtoToEntity(DrugMaterialInfoDTO dto) { + if (dto == null) { + return null; + } + DrugMaterialInfo drugMaterialInfo = new DrugMaterialInfo(); + drugMaterialInfo.setId(dto.getId()); + drugMaterialInfo.setCaseId(dto.getCaseId()); + drugMaterialInfo.setDrugName(dto.getDrugName()); + drugMaterialInfo.setMassVolume(dto.getMassVolume()); + drugMaterialInfo.setUnit(dto.getUnit()); + drugMaterialInfo.setPackageComplete(dto.getPackageComplete()); + return drugMaterialInfo; + } + + public static List dtoToEntityList(List dtos) { + if (CollUtil.isEmpty(dtos)) { + return Collections.emptyList(); + } + return dtos.stream().map(dto -> dtoToEntity(dto)).collect(Collectors.toList()); + } + +} diff --git a/src/main/java/digital/laboratory/platform/imr/dto/DepositDTO.java b/src/main/java/digital/laboratory/platform/imr/dto/DepositDTO.java index 8730cf9..1e4c7e2 100644 --- a/src/main/java/digital/laboratory/platform/imr/dto/DepositDTO.java +++ b/src/main/java/digital/laboratory/platform/imr/dto/DepositDTO.java @@ -58,4 +58,7 @@ public class DepositDTO { @ApiModelProperty(value="格子状态") private String cellStatus; + + @ApiModelProperty(value="存放类型,0 系统检材存放 | 1 毒品检材存放") + private Integer type = 0; } diff --git a/src/main/java/digital/laboratory/platform/imr/dto/DrugDepotsDTO.java b/src/main/java/digital/laboratory/platform/imr/dto/DrugDepotsDTO.java new file mode 100644 index 0000000..0a7e57b --- /dev/null +++ b/src/main/java/digital/laboratory/platform/imr/dto/DrugDepotsDTO.java @@ -0,0 +1,55 @@ +package digital.laboratory.platform.imr.dto; + +import com.fasterxml.jackson.annotation.JsonFormat; +import digital.laboratory.platform.imr.entity.DrugMaterialInfo; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.util.List; + +/** + * 保存毒品库信息中的案件和检材信息DTO类 + */ +@Data +@ApiModel(value = "DrugDepotsDTO", description = "保存毒品库信息中的案件和检材信息DTO类") +public class DrugDepotsDTO { + + @ApiModelProperty("案件id") + private String id; + + /** + * 案事件名称 + */ + @ApiModelProperty("案事件名称") + @NotBlank(message = "案事件名称不能为空!") + private String caseName; + + /** + * 案件编号 + */ + @ApiModelProperty("案件编号") + private String caseNo; + + /** + * 送缴单位 + */ + @ApiModelProperty("送缴单位") + @NotBlank(message = "送缴单位不能为空!") + private String handingOverOrg; + + /** + * 送缴日期 + */ + @ApiModelProperty("送缴日期") + @NotNull(message = "送缴日期不能为空!") + @JsonFormat(pattern = "yyyy-MM-dd") + private LocalDate handingOverDate; + + @ApiModelProperty("关联的检材列表") + private List drugMaterialInfoDTOList; +} diff --git a/src/main/java/digital/laboratory/platform/imr/dto/DrugMaterialInfoDTO.java b/src/main/java/digital/laboratory/platform/imr/dto/DrugMaterialInfoDTO.java new file mode 100644 index 0000000..228630e --- /dev/null +++ b/src/main/java/digital/laboratory/platform/imr/dto/DrugMaterialInfoDTO.java @@ -0,0 +1,49 @@ +package digital.laboratory.platform.imr.dto; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * 毒品库中的毒品检材信息 保存DTO类 + * @TableName b_drug_material_info + */ +@Data +@ApiModel(value = "DrugMaterialInfoDTO", description = "毒品库中的毒品检材信息 保存DTO类") +public class DrugMaterialInfoDTO { + + @ApiModelProperty("毒品检材id") + private String id; + + /** + * 关联的案件id + */ + @ApiModelProperty("关联的案件id") + private String caseId; + + /** + * 毒品检材名称 + */ + @ApiModelProperty("毒品检材名称") + private String drugName; + + /** + * 质量/体积 + */ + @ApiModelProperty("质量/体积") + private String massVolume; + + /** + * 质量/体积 单位 + */ + @ApiModelProperty("质量/体积 单位") + private String unit; + + + /** + * 包装是否完整, 1 完整 | 0 不完整 + */ + @ApiModelProperty("包装是否完整, 1 完整 | 0 不完整") + private Boolean packageComplete; + +} \ No newline at end of file diff --git a/src/main/java/digital/laboratory/platform/imr/entity/DrugCaseInfo.java b/src/main/java/digital/laboratory/platform/imr/entity/DrugCaseInfo.java index b70d84e..8c8b548 100644 --- a/src/main/java/digital/laboratory/platform/imr/entity/DrugCaseInfo.java +++ b/src/main/java/digital/laboratory/platform/imr/entity/DrugCaseInfo.java @@ -1,5 +1,6 @@ package digital.laboratory.platform.imr.entity; +import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; @@ -7,6 +8,7 @@ import digital.laboratory.platform.common.mybatis.base.BaseEntity; import lombok.Data; import java.io.Serializable; +import java.time.LocalDate; import java.time.LocalDateTime; import java.util.Date; @@ -16,11 +18,11 @@ import java.util.Date; */ @TableName(value ="b_drug_case_info") @Data -public class DrugCaseInfo extends BaseEntity implements Serializable { +public class DrugCaseInfo extends BaseEntity{ /** * 主键标识 */ - @TableId + @TableId(value = "id", type = IdType.ASSIGN_ID) private String id; /** @@ -41,7 +43,7 @@ public class DrugCaseInfo extends BaseEntity implements Serializable { /** * 送缴日期 */ - private LocalDateTime handingOverDate; + private LocalDate handingOverDate; @TableField(exist = false) private static final long serialVersionUID = 1L; diff --git a/src/main/java/digital/laboratory/platform/imr/entity/DrugMaterialInfo.java b/src/main/java/digital/laboratory/platform/imr/entity/DrugMaterialInfo.java index 5cf42f0..e1890e2 100644 --- a/src/main/java/digital/laboratory/platform/imr/entity/DrugMaterialInfo.java +++ b/src/main/java/digital/laboratory/platform/imr/entity/DrugMaterialInfo.java @@ -1,5 +1,6 @@ package digital.laboratory.platform.imr.entity; +import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; @@ -14,11 +15,11 @@ import java.io.Serializable; */ @TableName(value ="b_drug_material_info") @Data -public class DrugMaterialInfo extends BaseEntity implements Serializable { +public class DrugMaterialInfo extends BaseEntity { /** * 主键标识 */ - @TableId + @TableId(value = "id", type = IdType.ASSIGN_ID) private String id; /** @@ -41,10 +42,20 @@ public class DrugMaterialInfo extends BaseEntity implements Serializable { */ private String massVolume; + /** + * 质量/体积 单位 + */ + private String unit; + /** * 包装是否完整, 1 完整 | 0 不完整 */ - private Integer packageComplete; + private Boolean packageComplete; + + /** + * 毒品检材状态, 0 未入库 | 1 已入库 + */ + private Integer status; @TableField(exist = false) private static final long serialVersionUID = 1L; diff --git a/src/main/java/digital/laboratory/platform/imr/mapper/DrugCaseInfoMapper.java b/src/main/java/digital/laboratory/platform/imr/mapper/DrugCaseInfoMapper.java index 5b8bb0d..1b0fd2f 100644 --- a/src/main/java/digital/laboratory/platform/imr/mapper/DrugCaseInfoMapper.java +++ b/src/main/java/digital/laboratory/platform/imr/mapper/DrugCaseInfoMapper.java @@ -2,6 +2,7 @@ package digital.laboratory.platform.imr.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import digital.laboratory.platform.imr.entity.DrugCaseInfo; +import org.apache.ibatis.annotations.Mapper; /** * @author ChenJiangBao @@ -9,6 +10,7 @@ import digital.laboratory.platform.imr.entity.DrugCaseInfo; * @createDate 2024-11-07 12:04:42 * @Entity generator.entity.DrugCaseInfo */ +@Mapper public interface DrugCaseInfoMapper extends BaseMapper { } diff --git a/src/main/java/digital/laboratory/platform/imr/mapper/DrugMaterialInfoMapper.java b/src/main/java/digital/laboratory/platform/imr/mapper/DrugMaterialInfoMapper.java index 29b11e3..17dfc04 100644 --- a/src/main/java/digital/laboratory/platform/imr/mapper/DrugMaterialInfoMapper.java +++ b/src/main/java/digital/laboratory/platform/imr/mapper/DrugMaterialInfoMapper.java @@ -1,7 +1,16 @@ package digital.laboratory.platform.imr.mapper; +import com.baomidou.mybatisplus.core.conditions.Wrapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.core.toolkit.Constants; import digital.laboratory.platform.imr.entity.DrugMaterialInfo; +import digital.laboratory.platform.imr.query.DrugDepotsQuery; +import digital.laboratory.platform.imr.vo.DrugMaterialInfoVO; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; /** * @author ChenJiangBao @@ -9,7 +18,18 @@ import digital.laboratory.platform.imr.entity.DrugMaterialInfo; * @createDate 2024-11-07 12:04:42 * @Entity generator.entity.DrugMaterialInfo */ +@Mapper public interface DrugMaterialInfoMapper extends BaseMapper { + /** + * 分页查询毒品库中的毒品检材信息VO列表 + * @param page + * @param query + * @return + */ + IPage getDrugMaterialVOPage(IPage page, @Param("query") DrugDepotsQuery query); + + + List getDrugMaterialVO(@Param(Constants.WRAPPER) Wrapper qw); } diff --git a/src/main/java/digital/laboratory/platform/imr/query/DrugDepotsQuery.java b/src/main/java/digital/laboratory/platform/imr/query/DrugDepotsQuery.java new file mode 100644 index 0000000..d39b8b9 --- /dev/null +++ b/src/main/java/digital/laboratory/platform/imr/query/DrugDepotsQuery.java @@ -0,0 +1,39 @@ +package digital.laboratory.platform.imr.query; + +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.time.LocalDate; + +/** + * 毒品库信息查询对象 Query + */ +@Data +@ApiModel(value = "DrugDepotsQuery", description = "毒品库信息查询对象 Query") +public class DrugDepotsQuery { + + @ApiModelProperty(value = "分页参数,每页多少条, 默认10") + private Long size = 10L; + + @ApiModelProperty(value = "分页参数, 当前页, 默认1") + private Long current = 1L; + + @ApiModelProperty(value = "关键字,支持 案件名称, 毒品名称") + private String keywords; + + @ApiModelProperty(value = "送缴单位id查询") + private String orgId; + + @ApiModelProperty(value = "案件id查询") + private String caseId; + + @ApiModelProperty(value = "开始日期") + @JsonFormat(pattern = "yyyy-MM-dd") + private LocalDate startDate; + + @ApiModelProperty(value = "结束日期") + @JsonFormat(pattern = "yyyy-MM-dd") + private LocalDate endDate; +} diff --git a/src/main/java/digital/laboratory/platform/imr/service/CommonFeignService.java b/src/main/java/digital/laboratory/platform/imr/service/CommonFeignService.java new file mode 100644 index 0000000..6bc337e --- /dev/null +++ b/src/main/java/digital/laboratory/platform/imr/service/CommonFeignService.java @@ -0,0 +1,80 @@ +package digital.laboratory.platform.imr.service; + +import com.deepoove.poi.XWPFTemplate; +import digital.laboratory.platform.sys.entity.SysOrg; +import digital.laboratory.platform.sys.entity.SysUser; +import org.springframework.web.multipart.MultipartFile; + +import javax.servlet.http.HttpServletResponse; +import java.io.ByteArrayInputStream; +import java.util.List; +import java.util.Map; + +/** + * 通用的feign请求封装接口服务层接口 + */ +public interface CommonFeignService { + + /** + * 远程调用获取用户机构 + * @param orgId + * @return + */ + SysOrg remoteGetSysOrg(String orgId); + + /** + * 远程调用获取用户信息 + * @param username + * @return + */ + SysUser remoteGetUserByUsername(String username); + + /** + * 远程调用获取用户信息 + * @param userId + * @return + */ + SysUser remoteGetUserById(String userId); + + /** + * 远程调用生成word,并转成pdf + * + * @param template + * @param originalFilename 文件名 + * @param savePath 保存到minio路径 + * @return + * @throws Exception + */ + boolean remoteGenerateWord2PDF(XWPFTemplate template, String originalFilename, String savePath) throws Exception; + + /** + * 远程调用根据文件路径获取文件 + * @param filePath minio上的文件路径 + * @return + * @throws Exception + */ + ByteArrayInputStream remoteGetFile(String filePath) throws Exception; + + /** + * 远程调用根据文件路径获取文件 + * @param filePath minio上的文件路径 + * @param fileName 名称 + * @param httpServletResponse + * @throws Exception + */ + void remoteGetFile(String filePath, String fileName, HttpServletResponse httpServletResponse) throws Exception; + + /** + * 远程调用根据文件路径获取文件列表 + * @param filePath minio上的文件路径 + */ + List remoteGetFileList(String filePath); + + /** + * 远程调用-上传文件 + * @param file 上传的文件对象 + * @param path 上传到minio的位置 + * @return + */ + Map remoteUploadFile(MultipartFile file, String path); +} diff --git a/src/main/java/digital/laboratory/platform/imr/service/DrugCaseInfoService.java b/src/main/java/digital/laboratory/platform/imr/service/DrugCaseInfoService.java index e6b7217..1325799 100644 --- a/src/main/java/digital/laboratory/platform/imr/service/DrugCaseInfoService.java +++ b/src/main/java/digital/laboratory/platform/imr/service/DrugCaseInfoService.java @@ -1,7 +1,14 @@ package digital.laboratory.platform.imr.service; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.IService; +import digital.laboratory.platform.imr.dto.DrugDepotsDTO; import digital.laboratory.platform.imr.entity.DrugCaseInfo; +import digital.laboratory.platform.imr.query.DrugDepotsQuery; +import digital.laboratory.platform.imr.vo.DrugCaseInfoVO; +import digital.laboratory.platform.imr.vo.DrugMaterialInfoVO; + +import java.util.List; /** * @author ChenJiangBao @@ -10,4 +17,20 @@ import digital.laboratory.platform.imr.entity.DrugCaseInfo; */ public interface DrugCaseInfoService extends IService { + /** + * 保存案件实体信息和毒品检材信息 + * + * @param dto + * @return + */ + List save(DrugDepotsDTO dto); + + /** + * 分页接口 + * @param query + * @return + */ + Page getDrugCaseInfoVOPage(DrugDepotsQuery query); + + DrugCaseInfo drugCaseSave(DrugDepotsDTO dto); } diff --git a/src/main/java/digital/laboratory/platform/imr/service/DrugMaterialInfoService.java b/src/main/java/digital/laboratory/platform/imr/service/DrugMaterialInfoService.java index a8eac62..dd2ad0e 100644 --- a/src/main/java/digital/laboratory/platform/imr/service/DrugMaterialInfoService.java +++ b/src/main/java/digital/laboratory/platform/imr/service/DrugMaterialInfoService.java @@ -1,7 +1,18 @@ package digital.laboratory.platform.imr.service; +import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.service.IService; +import digital.laboratory.platform.common.mybatis.security.service.DLPUser; +import digital.laboratory.platform.imr.dto.InRepositoryDTO; +import digital.laboratory.platform.imr.entity.DrugCaseInfo; import digital.laboratory.platform.imr.entity.DrugMaterialInfo; +import digital.laboratory.platform.imr.entity.SampleStorage; +import digital.laboratory.platform.imr.query.DrugDepotsQuery; +import digital.laboratory.platform.imr.vo.DrugMaterialInfoVO; +import digital.laboratory.platform.imr.vo.OutSampleVO; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; /** * @author ChenJiangBao @@ -10,4 +21,52 @@ import digital.laboratory.platform.imr.entity.DrugMaterialInfo; */ public interface DrugMaterialInfoService extends IService { + /** + * 批量生成毒品检材编号 + * JC5201010020240001 + * JC 标识是检材 520100 地市行政编码 00 预留给派出所 2024 年份 0001 流水号 + * @param drugCaseInfo 案件信息 + * @param number + * @return + */ + List batchBuildDrugMaterialNO(DrugCaseInfo drugCaseInfo, Integer number); + + /** + * 批量保存毒品检材信息 + * + * @param drugMaterialInfos + * @param drugCaseInfo + * @return + */ + boolean saveDrugMaterialBatch(List drugMaterialInfos, DrugCaseInfo drugCaseInfo); + + /** + * 分页查询毒品库中的毒品检材信息VO列表 + * @param query + * @return + */ + IPage page(DrugDepotsQuery query); + + /** + * 打印标签 + * @param id + * @return + */ + String buildDrugLabelHtml(String id); + + /*** + * 毒品检材入库 + * @param sample + * @param dlpUser + * @return + */ + List drugMaterialPutInRepository(List sample, DLPUser dlpUser); + + /** + * 毒品检材封装 + * @param sampleStorage + * @param drugId + * @return + */ + OutSampleVO drugMaterialToOutSampleVO(SampleStorage sampleStorage, String drugId); } diff --git a/src/main/java/digital/laboratory/platform/imr/service/SampleInboundRecordService.java b/src/main/java/digital/laboratory/platform/imr/service/SampleInboundRecordService.java new file mode 100644 index 0000000..46a8f54 --- /dev/null +++ b/src/main/java/digital/laboratory/platform/imr/service/SampleInboundRecordService.java @@ -0,0 +1,7 @@ +package digital.laboratory.platform.imr.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import digital.laboratory.platform.imr.entity.SampleInboundRecord; + +public interface SampleInboundRecordService extends IService { +} diff --git a/src/main/java/digital/laboratory/platform/imr/service/SampleStorageService.java b/src/main/java/digital/laboratory/platform/imr/service/SampleStorageService.java new file mode 100644 index 0000000..c290298 --- /dev/null +++ b/src/main/java/digital/laboratory/platform/imr/service/SampleStorageService.java @@ -0,0 +1,7 @@ +package digital.laboratory.platform.imr.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import digital.laboratory.platform.imr.entity.SampleStorage; + +public interface SampleStorageService extends IService { +} diff --git a/src/main/java/digital/laboratory/platform/imr/service/impl/CommonFeignServiceImpl.java b/src/main/java/digital/laboratory/platform/imr/service/impl/CommonFeignServiceImpl.java new file mode 100644 index 0000000..ed728aa --- /dev/null +++ b/src/main/java/digital/laboratory/platform/imr/service/impl/CommonFeignServiceImpl.java @@ -0,0 +1,206 @@ +package digital.laboratory.platform.imr.service.impl; + +import cn.hutool.core.io.IoUtil; +import cn.hutool.core.io.file.FileNameUtil; +import cn.hutool.core.util.StrUtil; +import com.deepoove.poi.XWPFTemplate; +import digital.laboratory.platform.common.core.constant.CommonConstants; +import digital.laboratory.platform.common.core.util.R; +import digital.laboratory.platform.common.feign.RemoteWord2PDFService; +import digital.laboratory.platform.common.oss.service.OssFile; +import digital.laboratory.platform.imr.service.CommonFeignService; +import digital.laboratory.platform.sys.dto.UserInfo; +import digital.laboratory.platform.sys.entity.SysOrg; +import digital.laboratory.platform.sys.entity.SysUser; +import digital.laboratory.platform.sys.feign.RemoteOrgService; +import digital.laboratory.platform.sys.feign.RemoteUserService; +import feign.Response; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.io.output.ByteArrayOutputStream; +import org.springframework.mock.web.MockMultipartFile; +import org.springframework.stereotype.Service; +import org.springframework.web.multipart.MultipartFile; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletResponse; +import java.io.ByteArrayInputStream; +import java.util.Base64; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +/** + * 通用的feign请求封装接口服务层接口 实现类 + */ +@Slf4j +@Service +public class CommonFeignServiceImpl implements CommonFeignService { + + @Resource + private RemoteOrgService remoteOrgService; + + @Resource + private RemoteUserService remoteUserService; + + @Resource + private RemoteWord2PDFService remoteWord2PDFService; + + @Resource + private OssFile ossFile; + + /** + * 根据用户获取远程系统机构信息 + * + * @param orgId 用户信息 + * @return 对应的远程系统机构信息 + * @throws RuntimeException 如果未找到对应的机构信息,则抛出运行时异常 + */ + @Override + public SysOrg remoteGetSysOrg(String orgId) { + SysOrg sysOrg = null; + R r = remoteOrgService.getById(orgId); + if (r != null && r.getCode() == CommonConstants.SUCCESS) { + sysOrg = r.getData(); + } else { + throw new RuntimeException(String.format("没有找到 orgId 为 %s 的机构, 请确认用户所属机构的正确性!", orgId)); + } + return sysOrg; + } + + /** + * 远程调用或者用户信息 + * @param username + * @return + */ + @Override + public SysUser remoteGetUserByUsername(String username){ + R info = remoteUserService.innerGetUserInfoByUsername(username); + if (info != null && info.getCode() == CommonConstants.FAIL) { + throw new RuntimeException(String.format("获取用户名为 %s 的用户信息失败!", username)); + } + return info.getData().getSysUser(); + } + + /** + * 远程调用获取用户信息 + * @param userId + * @return + */ + @Override + public SysUser remoteGetUserById(String userId){ + R info = remoteUserService.innerGetById(userId); + if (info != null && info.getCode() == CommonConstants.FAIL) { + throw new RuntimeException(String.format("获取用户名id为 %s 的用户信息失败!", userId)); + } + return info.getData(); + } + + @Override + public boolean remoteGenerateWord2PDF(XWPFTemplate template, String originalFilename, String savePath) throws Exception{ + ByteArrayOutputStream fosWord = new ByteArrayOutputStream(); + template.write(fosWord); + template.close(); + + //------------ + ByteArrayInputStream fisWord = new ByteArrayInputStream(fosWord.toByteArray()); + fosWord.close(); + + MockMultipartFile mockMultipartFile = new MockMultipartFile("file", originalFilename + ".docx", "image/jpg", fisWord); + Response response = remoteWord2PDFService.word2pdf(mockMultipartFile); + fisWord.close(); + + + ByteArrayOutputStream outPDF = new ByteArrayOutputStream(); + IoUtil.copy(response.body().asInputStream(), outPDF, IoUtil.DEFAULT_MIDDLE_BUFFER_SIZE); + ByteArrayInputStream isPDF = new ByteArrayInputStream(outPDF.toByteArray()); + outPDF.close(); + + boolean b = ossFile.fileSave(savePath, isPDF); + + isPDF.close(); + + log.info("转换为 PDF 结束"); + return b; + } + + /** + * 远程调用根据文件路径获取文件 + * @param filePath minio上的文件路径 + * @return + * @throws Exception + */ + @Override + public ByteArrayInputStream remoteGetFile(String filePath) throws Exception { + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + ossFile.fileGet(filePath, bos); + + byte[] templateArray = bos.toByteArray(); + + ByteArrayInputStream bis = new ByteArrayInputStream(templateArray); + bos.close(); + return bis; + } + + /** + * 远程调用根据文件路径获取文件 + * @param filePath minio上的文件路径 + * @param fileName 名称 + * @param httpServletResponse + * @throws Exception + */ + @Override + public void remoteGetFile(String filePath, String fileName, HttpServletResponse httpServletResponse) throws Exception { + ossFile.fileGet(filePath, httpServletResponse.getOutputStream()); + if (StrUtil.isNotBlank(fileName)) { + httpServletResponse.setContentType(fileName); + } + } + + /** + * 远程调用根据文件路径获取文件列表 + * @param filePath minio上的文件路径 + */ + @Override + public List remoteGetFileList(String filePath) { + if (StrUtil.isNotBlank(filePath)) { + List fileNameList = ossFile.fileList(filePath); + List fileList = fileNameList.stream().map(fileName -> { + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + try { + ossFile.fileGet(filePath + "/" + fileName, byteArrayOutputStream); + return Base64.getEncoder().encodeToString(byteArrayOutputStream.toByteArray()); + } catch (Exception e) { + e.printStackTrace(); + log.error("文件获取失败, 文件路径为: {}", filePath + "/" + fileName); + } + return null; + }).collect(Collectors.toList()); + return fileList; + } else { + throw new RuntimeException("文件路径不能为空!"); + } + } + + /** + * 远程调用-上传文件 + * @param file 上传的文件对象 + * @param path 上传到minio的位置 + * @return + */ + @Override + public Map remoteUploadFile(MultipartFile file, String path) { + boolean r = ossFile.fileUpload(file, path); + if (r) { + HashMap resultData = new HashMap<>(); + resultData.put("fileName", FileNameUtil.getName(file.getOriginalFilename())); + resultData.put("path", path); + log.info("文件上传成功!"); + return resultData; + } else { + String failMsg = String.format("文件名为 %s 的文件上传失败!", file.getOriginalFilename()); + log.error(failMsg); + throw new RuntimeException(failMsg); + } + } +} diff --git a/src/main/java/digital/laboratory/platform/imr/service/impl/DrugCaseInfoServiceImpl.java b/src/main/java/digital/laboratory/platform/imr/service/impl/DrugCaseInfoServiceImpl.java index 6774414..2ec0aae 100644 --- a/src/main/java/digital/laboratory/platform/imr/service/impl/DrugCaseInfoServiceImpl.java +++ b/src/main/java/digital/laboratory/platform/imr/service/impl/DrugCaseInfoServiceImpl.java @@ -1,10 +1,30 @@ package digital.laboratory.platform.imr.service.impl; +import cn.hutool.core.util.StrUtil; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import digital.laboratory.platform.imr.convert.DrugCaseInfoConvert; +import digital.laboratory.platform.imr.convert.DrugMaterialInfoConvert; +import digital.laboratory.platform.imr.dto.DrugDepotsDTO; import digital.laboratory.platform.imr.entity.DrugCaseInfo; +import digital.laboratory.platform.imr.entity.DrugMaterialInfo; import digital.laboratory.platform.imr.mapper.DrugCaseInfoMapper; +import digital.laboratory.platform.imr.mapper.DrugMaterialInfoMapper; +import digital.laboratory.platform.imr.query.DrugDepotsQuery; +import digital.laboratory.platform.imr.service.CommonFeignService; import digital.laboratory.platform.imr.service.DrugCaseInfoService; +import digital.laboratory.platform.imr.service.DrugMaterialInfoService; +import digital.laboratory.platform.imr.vo.DrugCaseInfoVO; +import digital.laboratory.platform.imr.vo.DrugMaterialInfoVO; +import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.util.List; +import java.util.stream.Collectors; /** * @author ChenJiangBao @@ -15,6 +35,76 @@ import org.springframework.stereotype.Service; public class DrugCaseInfoServiceImpl extends ServiceImpl implements DrugCaseInfoService { + @Resource + private DrugMaterialInfoService drugMaterialInfoService; + + @Resource + private DrugMaterialInfoMapper drugMaterialInfoMapper; + + @Resource + private CommonFeignService commonFeignService; + + /** + * 保存案件实体信息和毒品检材信息 + * + * @param dto + * @return + */ + @Override + @Transactional(rollbackFor = Exception.class) + public List save(DrugDepotsDTO dto) { + DrugCaseInfo drugCaseInfo = DrugCaseInfoConvert.dtoTOEntity(dto); + boolean flag = false; + if (StrUtil.isBlank(drugCaseInfo.getId())) { + if (super.save(drugCaseInfo)) { + // 保存毒品检材 + List drugMaterialInfos = DrugMaterialInfoConvert.dtoToEntityList(dto.getDrugMaterialInfoDTOList()); + flag = drugMaterialInfoService.saveDrugMaterialBatch(drugMaterialInfos, drugCaseInfo); + } + } else { + if (this.updateById(drugCaseInfo)) { + // 转换成毒品检材实体 + List drugMaterialInfos = DrugMaterialInfoConvert.dtoToEntityList(dto.getDrugMaterialInfoDTOList()); + // 根据id 是否存在判断调用更新还是新增 + List saveList = drugMaterialInfos.stream().filter(o -> StrUtil.isBlank(o.getId())).collect(Collectors.toList()); + List updateList = drugMaterialInfos.stream().filter(o -> StrUtil.isNotBlank(o.getId())).collect(Collectors.toList()); + // 直接更新 + flag = drugMaterialInfoService.updateBatchById(updateList); + flag = drugMaterialInfoService.saveDrugMaterialBatch(saveList, drugCaseInfo); + } + } + if (flag) { + return drugMaterialInfoMapper.getDrugMaterialVO(Wrappers.lambdaQuery().eq(DrugMaterialInfo::getCaseId, dto.getId())); + } + return null; + } + + @Override + public Page getDrugCaseInfoVOPage(DrugDepotsQuery query) { + String keywords = query.getKeywords(); + IPage page = super.page( + new Page<>(query.getCurrent(), query.getSize()), + Wrappers.lambdaQuery().and( + StrUtil.isNotBlank(keywords), + wrapper -> wrapper + .like(DrugCaseInfo::getCaseNo, keywords) + .or() + .like(DrugCaseInfo::getCaseName, keywords)) + .orderByDesc(DrugCaseInfo::getUpdateTime)); + Page drugCaseInfoVOPage = new Page<>(); + BeanUtils.copyProperties(page, drugCaseInfoVOPage, "records"); + List drugCaseInfoVOS = DrugCaseInfoConvert.entityToVOList(page.getRecords()); + drugCaseInfoVOS.parallelStream().forEach(item -> item.setHandingOverOrgName(commonFeignService.remoteGetSysOrg(item.getHandingOverOrg()).getName())); + drugCaseInfoVOPage.setRecords(drugCaseInfoVOS); + return drugCaseInfoVOPage; + } + + @Override + public DrugCaseInfo drugCaseSave(DrugDepotsDTO dto) { + DrugCaseInfo drugCaseInfo = DrugCaseInfoConvert.dtoTOEntity(dto); + super.save(drugCaseInfo); + return drugCaseInfo; + } } diff --git a/src/main/java/digital/laboratory/platform/imr/service/impl/DrugMaterialInfoServiceImpl.java b/src/main/java/digital/laboratory/platform/imr/service/impl/DrugMaterialInfoServiceImpl.java index d00cc3f..019ddef 100644 --- a/src/main/java/digital/laboratory/platform/imr/service/impl/DrugMaterialInfoServiceImpl.java +++ b/src/main/java/digital/laboratory/platform/imr/service/impl/DrugMaterialInfoServiceImpl.java @@ -1,20 +1,274 @@ package digital.laboratory.platform.imr.service.impl; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.StrUtil; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.core.toolkit.IdWorker; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import digital.laboratory.platform.imr.entity.DrugMaterialInfo; +import digital.laboratory.platform.common.core.constant.CommonConstants; +import digital.laboratory.platform.common.core.exception.ValidateCodeException; +import digital.laboratory.platform.common.feign.RemoteTemplate2htmlService; +import digital.laboratory.platform.common.mybatis.security.service.DLPUser; +import digital.laboratory.platform.imr.dto.InRepositoryDTO; +import digital.laboratory.platform.imr.entity.*; import digital.laboratory.platform.imr.mapper.DrugMaterialInfoMapper; +import digital.laboratory.platform.imr.mapper.SampleStorageMapper; +import digital.laboratory.platform.imr.query.DrugDepotsQuery; import digital.laboratory.platform.imr.service.DrugMaterialInfoService; +import digital.laboratory.platform.imr.service.SampleInboundAndOutboundTableService; +import digital.laboratory.platform.imr.service.SampleInboundRecordService; +import digital.laboratory.platform.imr.service.SampleStorageService; +import digital.laboratory.platform.imr.vo.DrugMaterialInfoVO; +import digital.laboratory.platform.imr.vo.OutSampleVO; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.time.LocalDateTime; +import java.util.*; +import java.util.function.Function; +import java.util.stream.Collectors; /** -* @author ChenJiangBao -* @description 针对表【b_drug_material_info(毒品库中的毒品检材信息)】的数据库操作Service实现 -* @createDate 2024-11-07 12:04:42 -*/ + * @author ChenJiangBao + * @description 针对表【b_drug_material_info(毒品库中的毒品检材信息)】的数据库操作Service实现 + * @createDate 2024-11-07 12:04:42 + */ @Service public class DrugMaterialInfoServiceImpl extends ServiceImpl - implements DrugMaterialInfoService { + implements DrugMaterialInfoService { + + @Resource + private RemoteTemplate2htmlService remoteTemplate2htmlService; + + @Resource + private SampleStorageMapper sampleStorageMapper; + + @Resource + private SampleStorageService sampleStorageService; + + @Resource + private SampleInboundAndOutboundTableService sampleInboundAndOutboundTableService; + + @Resource + private SampleInboundRecordService sampleInboundRecordService; + + + /** + * 批量生成毒品检材编号 + * JC5201010020240001 + * JC 标识是检材 520100 地市行政编码 00 预留给派出所 2024 年份 0001 流水号 + * + * @param drugCaseInfo 案件信息 + * @param number + * @return + */ + @Override + public List batchBuildDrugMaterialNO(DrugCaseInfo drugCaseInfo, Integer number) { + ; + Calendar calendar = Calendar.getInstance(); + String prefixNO = CommonConstants.CODE_PREFIX_IDENTIFICATION_MATERIAL + drugCaseInfo.getHandingOverOrg() + "00" + calendar.get(Calendar.YEAR); + List drugMaterialInfos = this.list(Wrappers.lambdaQuery() + .likeRight(DrugMaterialInfo::getDrugNo, prefixNO) + .orderByDesc(DrugMaterialInfo::getDrugNo)); + Integer startNO = 0; + if (CollUtil.isNotEmpty(drugMaterialInfos)) { + DrugMaterialInfo drugMaterialInfo = drugMaterialInfos.get(0); + startNO = Integer.parseUnsignedInt(StrUtil.removePrefixIgnoreCase(drugMaterialInfo.getDrugNo(), prefixNO)); + } + + List drugNoList = new ArrayList<>(); + for (int i = 0; i < number; i++) { + drugNoList.add(prefixNO + String.format("%04d", ++startNO)); + } + return drugNoList; + } + + /** + * 批量保存毒品检材信息 + * + * @param drugMaterialInfos + * @param drugCaseInfo + * @return + */ + @Override + public boolean saveDrugMaterialBatch(List drugMaterialInfos, DrugCaseInfo drugCaseInfo) { + int size = drugMaterialInfos.size(); + // 获取编号 + List drugMaterialNOList = this.batchBuildDrugMaterialNO(drugCaseInfo, size); + for (int i = 0; i < size; i++) { + DrugMaterialInfo drugMaterialInfo = drugMaterialInfos.get(i); + drugMaterialInfo.setDrugNo(drugMaterialNOList.get(i)); + drugMaterialInfo.setCaseId(drugCaseInfo.getId()); + } + return super.saveBatch(drugMaterialInfos); + } + + /** + * 分页查询毒品库中的毒品检材信息VO列表 + * + * @param query + * @return + */ + @Override + public IPage page(DrugDepotsQuery query) { + return baseMapper.getDrugMaterialVOPage(new Page<>(query.getCurrent(), query.getSize()), query); + } + + @Override + public String buildDrugLabelHtml(String id) { + List drugMaterialInfoVOList = baseMapper.getDrugMaterialVO(Wrappers.query().eq("dm.id", id)); + if (CollUtil.isEmpty(drugMaterialInfoVOList)) { + throw new RuntimeException(String.format("没有找到 id 为 %s 的毒品检材", id)); + } + + Map data = new HashMap<>(); + data.put("drugInfo", drugMaterialInfoVOList.get(0)); + + String templateFileName = "毒品库毒品检材条码模板.vm"; + return remoteTemplate2htmlService.getHtml(templateFileName, data); + } + + /*** + * 毒品检材入库 + * @param sample + * @param dlpUser + * @return + */ + @Override + @Transactional + public List drugMaterialPutInRepository(List sample, DLPUser dlpUser) { + // 一次性获取到所有的入库毒品检材信息,并根据编号转成map + List drugMaterialInfoVOS = baseMapper + .getDrugMaterialVO(Wrappers.query() + .in("drug_no", + sample.stream().map(InRepositoryDTO::getSampleNo).collect(Collectors.toList()))); + Map drugMaterialInfoVOMap = drugMaterialInfoVOS.stream() + .collect(Collectors.toMap(DrugMaterialInfoVO::getDrugNo, Function.identity())); + + Map sampleStorageMap = sampleStorageMapper + .selectList(Wrappers.lambdaQuery() + .in(SampleStorage::getSampleId, + drugMaterialInfoVOS.stream().map(DrugMaterialInfoVO::getId).collect(Collectors.toList()))) + .stream().collect(Collectors.toMap(SampleStorage::getSampleId, Function.identity())); + // 存储需要批量保存的实体信息 + List updateSampleStorageList = new ArrayList<>(); + List saveSampleStorageList = new ArrayList<>(); + List saveSampleInboundAndOutboundTableList = new ArrayList<>(); + List saveSampleInboundRecordList = new ArrayList<>(); + ArrayList sampleVOS = new ArrayList<>(); + for (InRepositoryDTO dto : sample) { + //先通过样本编号查询出这个样本的基本信息(重点是获取到id) + DrugMaterialInfoVO drugMaterialInfoVO = drugMaterialInfoVOMap.get(dto.getSampleNo()); + if (drugMaterialInfoVO == null) { + throw new ValidateCodeException(String.format("毒品检材编号为 %s 的毒品信息不存在请重试!", dto.getSampleNo())); + } + if (drugMaterialInfoVO.getStatus() != 0) {// 判断检材是否是未入库状态 + throw new ValidateCodeException(String.format("编号为 %s 的样本当前状态不是入库状态!", dto.getSampleNo())); + } + // 查询当前毒品检材是否已经录入过 + SampleStorage sampleStorage = sampleStorageMap.get(drugMaterialInfoVO.getId()); + //已经录入到关联表;待存放状态 + if (sampleStorage != null) { + if (sampleStorage.getStatus() == 1 || sampleStorage.getStatus() == 2) { + throw new RuntimeException(String.format("编号为" + dto.getSampleNo() + "的样本已录入")); + } else if (sampleStorage.getStatus() == 3) {//已出库;现在是重新入库 + //重新入库是更新(二次入库) + sampleStorage.setInRepositoryDate(LocalDateTime.now()); + sampleStorage.setRecipientId(null); + sampleStorage.setDepositorId(dlpUser.getId()); + sampleStorage.setStatus(1); + sampleStorage.setOutRepositoryDate(null); +// sampleStorageMapper.updateById(sampleStorage); + updateSampleStorageList.add(sampleStorage); + } + } else { + //新录入仓库样本(添加操作) + sampleStorage = new SampleStorage(); + sampleStorage.setId(IdWorker.get32UUID().toUpperCase()); + sampleStorage.setStatus(1);//入库待存放 + sampleStorage.setDepositorId(dlpUser.getId());//当前持有人变成入库人 + sampleStorage.setInRepositoryDate(LocalDateTime.now());//入库时间 + + //毒品和其他存储时间为长期(100年) + sampleStorage.setStorageDate(LocalDateTime.now().plusYears(100)); + + sampleStorage.setSampleId(drugMaterialInfoVO.getId()); //毒品检材id + sampleStorage.setEarlyWarning(0);//创建默认未到"销毁" + sampleStorage.setUnit(dto.getUnit());//单位 + sampleStorage.setQuality(dto.getQuality());//入库时的质量 + sampleStorage.setName(drugMaterialInfoVO.getDrugName()); + sampleStorage.setSampleType("A");//样本类型 + //数据存储 +// sampleStorageMapper.insert(sampleStorage); + saveSampleStorageList.add(sampleStorage); + } + + //更新出入库登记表(这里因为只有入库,所以就创建部分数据;入库一定是添加数据) + SampleInboundAndOutboundTable table = new SampleInboundAndOutboundTable(); + table.setId(IdWorker.get32UUID().toUpperCase()); + table.setImAdministrators(dlpUser.getId()); + table.setRecipient(dlpUser.getId());//持有人变入库人 + table.setRemarks("检材入库"); + table.setWarehousingDate(LocalDateTime.now());//入库时间 + table.setSampleId(drugMaterialInfoVO.getId()); + table.setInboundSupervisor(dto.getSupervisor());//入库监督人 +// tableMapper.insert(table); + saveSampleInboundAndOutboundTableList.add(table); + //新出入库登记表 + + //入库记录 + SampleInboundRecord record = new SampleInboundRecord(); + record.setId(IdWorker.get32UUID().toUpperCase()); + record.setWarehousingPersonId(dlpUser.getId());//入库人 + record.setWarehousingDate(LocalDateTime.now()); + record.setImAdministrators(dlpUser.getId()); + record.setSampleId(drugMaterialInfoVO.getId()); + record.setName(drugMaterialInfoVO.getDrugName()); + record.setRemarks("检材入库"); +// recordMapper.insert(record); + saveSampleInboundRecordList.add(record); + + OutSampleVO outSampleVO = getOutSampleVO(sampleStorage, drugMaterialInfoVO); + sampleVOS.add(outSampleVO); + } + + sampleStorageService.updateBatchById(updateSampleStorageList); + sampleStorageService.saveBatch(saveSampleStorageList); + sampleInboundAndOutboundTableService.saveBatch(saveSampleInboundAndOutboundTableList); + sampleInboundRecordService.saveBatch(saveSampleInboundRecordList); + return sampleVOS; + } + + /** + * 毒品检材封装 + * @param sampleStorage + * @param drugId + * @return + */ + @Override + public OutSampleVO drugMaterialToOutSampleVO(SampleStorage sampleStorage, String drugId) { + List drugMaterialVOs = baseMapper.getDrugMaterialVO(Wrappers.query().eq("dm.id", drugId)); + if (CollUtil.isEmpty(drugMaterialVOs)) { + return null; + } + return getOutSampleVO(sampleStorage, drugMaterialVOs.get(0)); + } + private OutSampleVO getOutSampleVO(SampleStorage sampleStorage, DrugMaterialInfoVO drugMaterialInfoVO) { + OutSampleVO outSampleVO = new OutSampleVO(); + outSampleVO.setId(sampleStorage.getId()); + outSampleVO.setSampleId(drugMaterialInfoVO.getId()); + outSampleVO.setName(drugMaterialInfoVO.getDrugName()); + outSampleVO.setCategory("常规毒品"); + outSampleVO.setSampleNo(drugMaterialInfoVO.getDrugNo()); + outSampleVO.setStorageMethod("常规"); + outSampleVO.setStorageLocation(drugMaterialInfoVO.getStorageLocation()); + outSampleVO.setSampleStatus(1); + return outSampleVO; + } } diff --git a/src/main/java/digital/laboratory/platform/imr/service/impl/SampleInboundRecordServiceImpl.java b/src/main/java/digital/laboratory/platform/imr/service/impl/SampleInboundRecordServiceImpl.java new file mode 100644 index 0000000..76412b1 --- /dev/null +++ b/src/main/java/digital/laboratory/platform/imr/service/impl/SampleInboundRecordServiceImpl.java @@ -0,0 +1,11 @@ +package digital.laboratory.platform.imr.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import digital.laboratory.platform.imr.entity.SampleInboundRecord; +import digital.laboratory.platform.imr.mapper.SampleInboundRecordMapper; +import digital.laboratory.platform.imr.service.SampleInboundRecordService; +import org.springframework.stereotype.Service; + +@Service +public class SampleInboundRecordServiceImpl extends ServiceImpl implements SampleInboundRecordService { +} diff --git a/src/main/java/digital/laboratory/platform/imr/service/impl/SamplePutInStorageServiceImpl.java b/src/main/java/digital/laboratory/platform/imr/service/impl/SamplePutInStorageServiceImpl.java index 932987d..7de565a 100644 --- a/src/main/java/digital/laboratory/platform/imr/service/impl/SamplePutInStorageServiceImpl.java +++ b/src/main/java/digital/laboratory/platform/imr/service/impl/SamplePutInStorageServiceImpl.java @@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.toolkit.IdWorker; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import digital.laboratory.platform.common.mybatis.security.service.DLPUser; import digital.laboratory.platform.imr.dto.DepositDTO; @@ -15,6 +16,7 @@ import digital.laboratory.platform.imr.entity.*; import digital.laboratory.platform.imr.feign.TransferFeignService; import digital.laboratory.platform.imr.feign.dto.UpdateHolderDTO; import digital.laboratory.platform.imr.mapper.*; +import digital.laboratory.platform.imr.service.DrugMaterialInfoService; import digital.laboratory.platform.imr.service.SamplePutInStorageService; import digital.laboratory.platform.imr.vo.InboundRecordVO; import digital.laboratory.platform.imr.vo.OutSampleVO; @@ -51,6 +53,8 @@ public class SamplePutInStorageServiceImpl implements SamplePutInStorageService private final CabinetOpeningRecordMapper openingRecordMapper; + private final DrugMaterialInfoService drugMaterialInfoService; + private static Map> tempSampleInMap = new ConcurrentHashMap<>(); @@ -412,31 +416,6 @@ public class SamplePutInStorageServiceImpl implements SamplePutInStorageService table.setInboundSupervisor(dto.getSupervisor());//入库监督人 tableMapper.insert(table); //新出入库登记表 - /* - 存在分析样本和留存样本两种 - */ -// if("A".equals(sampleVO.getSampleType())){//分析样 -// IdentificationMaterialTransferAnalysisAnnex analysisSample = new IdentificationMaterialTransferAnalysisAnnex(); -// analysisSample.setId(IdWorker.get32UUID().toUpperCase()); -// analysisSample.setAnalysisSampleInboundQuality(sampleVO.getExistingQuality());//现有质量 -// analysisSample.setInboundAdminId(dlpUser.getId()); -// analysisSample.setInboundHandledBy(sampleVO.getHolder());//经手人 -// analysisSample.setSampleId(sampleVO.getId());//样本id -// analysisSample.setAnalysisSampleInboundDate(LocalDateTime.now());//日期 -// analysisSample.setInboundAppraiserId(dto.getSupervisor());//入库监督人 -// analysisAnnexMapper.insert(analysisSample); -// }else { -// //留存样本 -// IdentificationMaterialTransferRetainedAnnex retainedAnnex = new IdentificationMaterialTransferRetainedAnnex(); -// retainedAnnex.setId(IdWorker.get32UUID().toUpperCase()); -// retainedAnnex.setRetainedSampleInboundQuality(sampleVO.getExistingQuality());//现有质量 -// retainedAnnex.setInboundAdminId(dlpUser.getId()); -// retainedAnnex.setInboundHandledBy(sampleVO.getHolder());//经手人 -// retainedAnnex.setSampleId(sampleVO.getId());//样本id -// retainedAnnex.setRetainedSampleInboundDate(LocalDateTime.now());//日期 -// retainedAnnex.setInboundAppraiserId(dto.getSupervisor());//入库监督人 -// retainedAnnexMapper.insert(retainedAnnex); -// } //入库记录 SampleInboundRecord record = new SampleInboundRecord(); @@ -492,8 +471,14 @@ public class SamplePutInStorageServiceImpl implements SamplePutInStorageService //添加样本id sampleIds.add(sampleStorage.getSampleId()); - - OutSampleVO sampleVO = storageMapper.getSampleById(sampleStorage.getSampleId()); + OutSampleVO sampleVO; + if (dto.getType() == 0) { + sampleVO = storageMapper.getSampleById(sampleStorage.getSampleId()); + } else { + sampleVO = drugMaterialInfoService.drugMaterialToOutSampleVO(sampleStorage, sampleStorage.getSampleId()); + //3.毒品库中的毒品检材信息样本状态为已入库 + drugMaterialInfoService.update(Wrappers.lambdaUpdate().eq(DrugMaterialInfo::getId, sampleStorage.getSampleId()).set(DrugMaterialInfo::getStatus, 1)); + } sampleVO.setStorageLocation(dto.getStorageLocation()); outSampleVOS.add(sampleVO); } diff --git a/src/main/java/digital/laboratory/platform/imr/service/impl/SampleStorageServiceImpl.java b/src/main/java/digital/laboratory/platform/imr/service/impl/SampleStorageServiceImpl.java new file mode 100644 index 0000000..8227fe0 --- /dev/null +++ b/src/main/java/digital/laboratory/platform/imr/service/impl/SampleStorageServiceImpl.java @@ -0,0 +1,11 @@ +package digital.laboratory.platform.imr.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import digital.laboratory.platform.imr.entity.SampleStorage; +import digital.laboratory.platform.imr.mapper.SampleStorageMapper; +import digital.laboratory.platform.imr.service.SampleStorageService; +import org.springframework.stereotype.Service; + +@Service +public class SampleStorageServiceImpl extends ServiceImpl implements SampleStorageService { +} diff --git a/src/main/java/digital/laboratory/platform/imr/vo/DrugCaseInfoVO.java b/src/main/java/digital/laboratory/platform/imr/vo/DrugCaseInfoVO.java new file mode 100644 index 0000000..0cd664a --- /dev/null +++ b/src/main/java/digital/laboratory/platform/imr/vo/DrugCaseInfoVO.java @@ -0,0 +1,55 @@ +package digital.laboratory.platform.imr.vo; + +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.time.LocalDate; +import java.time.LocalDateTime; + +/** + * 毒品库中关联的案事件信息 VO 返回前台显示类 + * @TableName b_drug_case_info + */ +@Data +@ApiModel(value = "DrugCaseInfoVO", description = "毒品库中关联的案事件信息 VO 返回前台显示类") +public class DrugCaseInfoVO{ + /** + * 主键标识 + */ + @ApiModelProperty("id") + private String id; + + /** + * 案事件名称 + */ + @ApiModelProperty("案事件名称") + private String caseName; + + /** + * 案件编号 + */ + @ApiModelProperty("案件编号") + private String caseNo; + + /** + * 送缴单位 + */ + @ApiModelProperty("送缴单位") + private String handingOverOrg; + + /** + * 送缴单位 + */ + @ApiModelProperty("送缴单位") + private String handingOverOrgName; + + /** + * 送缴日期 + */ + @ApiModelProperty("送缴日期") + @JsonFormat(pattern = "yyyy-MM-dd") + private LocalDate handingOverDate; + +} \ No newline at end of file diff --git a/src/main/java/digital/laboratory/platform/imr/vo/DrugMaterialInfoVO.java b/src/main/java/digital/laboratory/platform/imr/vo/DrugMaterialInfoVO.java new file mode 100644 index 0000000..5a1113b --- /dev/null +++ b/src/main/java/digital/laboratory/platform/imr/vo/DrugMaterialInfoVO.java @@ -0,0 +1,106 @@ +package digital.laboratory.platform.imr.vo; + +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.time.LocalDate; +import java.time.LocalDateTime; + +/** + * 毒品库中的毒品检材信息 VO 返回前台显示类 + * @TableName b_drug_material_info + */ +@Data +@ApiModel(value = "DrugMaterialInfoVO", description = "毒品库中的毒品检材信息 VO 返回前台显示类") +public class DrugMaterialInfoVO { + /** + * 主键标识 + */ + @ApiModelProperty("主键标识") + private String id; + + /** + * 关联的案件id + */ + @ApiModelProperty("关联的案件id") + private String caseId; + + /** + * 关联的入库记录id + */ + @ApiModelProperty("关联的入库记录id") + private String sampleStorageId; + + @ApiModelProperty("存放位置") + private String storageLocation; + + /** + * 毒品检材编号 + */ + @ApiModelProperty("毒品检材编号") + private String drugNo; + + /** + * 毒品检材名称 + */ + @ApiModelProperty("毒品检材名称") + private String drugName; + + /** + * 质量/体积 + */ + @ApiModelProperty("质量/体积") + private String massVolume; + + /** + * 质量/体积 单位 + */ + @ApiModelProperty("质量/体积 单位") + private String unit; + + /** + * 包装是否完整, 1 完整 | 0 不完整 + */ + @ApiModelProperty("包装是否完整, 1 完整 | 0 不完整") + private Boolean packageComplete; + + /** + * 毒品检材状态, 0 未入库 | 1 已入库 + */ + @ApiModelProperty("毒品检材状态, 0 未入库 | 1 已入库") + private Integer status; + + /** + * 案事件名称 + */ + @ApiModelProperty("案事件名称") + private String caseName; + + /** + * 案件编号 + */ + @ApiModelProperty("案件编号") + private String caseNo; + + /** + * 送缴单位 + */ + @ApiModelProperty("送缴单位") + private String handingOverOrg; + + /** + * 送缴单位 + */ + @ApiModelProperty("送缴单位") + private String handingOverOrgName; + + /** + * 送缴日期 + */ + @ApiModelProperty("送缴日期") + @JsonFormat(pattern = "yyyy-MM-dd") + private LocalDate handingOverDate; + +} \ No newline at end of file diff --git a/src/main/resources/bootstrap.yml b/src/main/resources/bootstrap.yml index ecb2eb4..b5c974a 100644 --- a/src/main/resources/bootstrap.yml +++ b/src/main/resources/bootstrap.yml @@ -10,6 +10,8 @@ mybatis-plus: type-aliases-package: digital.laboratory.platform.imr.entity mapper-locations: classpath:mapper/*Mapper.xml typeEnumsPackage: digital.laboratory.platform.imr.entity.enums # 支持统配符 * 或者 ; 分割 + configuration: + log-impl: org.apache.ibatis.logging.stdout.StdOutImpl spring: application: @@ -30,7 +32,7 @@ spring: driver-class-name: com.mysql.cj.jdbc.Driver username: root password: 7990016 - url: jdbc:mysql://dlp-mysql:3306/dlp_identification_material_repository?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowMultiQueries=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true&allowPublicKeyRetrieval=true + url: jdbc:mysql://dlp-mysql:3306/dlp_identification_material_repository?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowMultiQueries=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true&allowPublicKeyRetrieval=true&rewriteBatchedStatements=true servlet: multipart: # 根据实际需求作调整 diff --git a/src/main/resources/mapper/DrugMaterialInfoMapper.xml b/src/main/resources/mapper/DrugMaterialInfoMapper.xml index 91945db..f851e6b 100644 --- a/src/main/resources/mapper/DrugMaterialInfoMapper.xml +++ b/src/main/resources/mapper/DrugMaterialInfoMapper.xml @@ -10,6 +10,7 @@ + @@ -19,8 +20,51 @@ id,case_id,drug_no, - drug_name,mass_volume,package_complete, + drug_name,mass_volume,unit,package_complete, create_time,update_time,create_by, update_by + + + SELECT + dm.*, + dc.case_name, + dc.case_no, + dc.handing_over_org, + dc.handing_over_date, + ss.id as sampleStorageId, + ss.storage_location + FROM b_drug_material_info dm + LEFT JOIN b_drug_case_info dc ON dm.case_id = dc.id + LEFT JOIN b_sample_storage ss ON dm.id = ss.sample_id + + + + +