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 c2e7009..00db78e 100644 --- a/src/main/java/digital/laboratory/platform/imr/controller/DrugDepotsController.java +++ b/src/main/java/digital/laboratory/platform/imr/controller/DrugDepotsController.java @@ -7,11 +7,13 @@ 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.exception.ValidateCodeException; 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.DrugMaterialInfoDTO; import digital.laboratory.platform.imr.dto.InRepositoryDTO; import digital.laboratory.platform.imr.entity.DrugCaseInfo; import digital.laboratory.platform.imr.entity.DrugMaterialInfo; @@ -59,7 +61,13 @@ public class DrugDepotsController { @ApiOperation(value = "新增毒品案件信息") @PostMapping("/drugCase/save") public R drugCaseSave(@RequestBody @Valid DrugDepotsDTO dto) { - DrugCaseInfo save = drugCaseInfoService.drugCaseSave(dto); + DrugCaseInfo save = null; + try { + save = drugCaseInfoService.drugCaseSave(dto); + } catch (ValidateCodeException e) { + e.printStackTrace(); + return R.failed(e.getMessage()); + } return R.ok(save); } @@ -70,6 +78,13 @@ public class DrugDepotsController { return R.ok(save); } + @ApiOperation(value = "复制毒品检材信息") + @PostMapping("/copy") + public R copy(@RequestBody DrugMaterialInfoDTO dto) { + DrugMaterialInfoVO copy = drugMaterialInfoService.copy(dto); + return R.ok(copy); + } + @ApiOperation(value = "毒品案件信息和毒品检材信息分页接口") @PostMapping("/drugMaterial/page") public R> drugMaterialPage(@RequestBody DrugDepotsQuery query) { diff --git a/src/main/java/digital/laboratory/platform/imr/controller/DrugUsageRecordController.java b/src/main/java/digital/laboratory/platform/imr/controller/DrugUsageRecordController.java index 2ff88f8..bc1deb0 100644 --- a/src/main/java/digital/laboratory/platform/imr/controller/DrugUsageRecordController.java +++ b/src/main/java/digital/laboratory/platform/imr/controller/DrugUsageRecordController.java @@ -1,13 +1,76 @@ package digital.laboratory.platform.imr.controller; +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.util.R; +import digital.laboratory.platform.imr.convert.DrugUsageRecordConvert; +import digital.laboratory.platform.imr.dto.DrugUsageRecordDTO; +import digital.laboratory.platform.imr.entity.DrugMaterialInfo; +import digital.laboratory.platform.imr.entity.DrugUsageRecord; +import digital.laboratory.platform.imr.mapper.DrugMaterialInfoMapper; +import digital.laboratory.platform.imr.query.DrugUsageRecordQuery; +import digital.laboratory.platform.imr.service.DrugUsageRecordService; +import digital.laboratory.platform.imr.vo.DrugUsageRecordVO; import io.swagger.annotations.Api; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import io.swagger.annotations.ApiModelProperty; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.BeanUtils; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import javax.validation.Valid; @RestController @RequestMapping("/drugUsageRecord") @Api(value = "DrugUsageRecordController", tags = "毒品检材的领用归还记录表相关接口") public class DrugUsageRecordController { + @Resource + private DrugUsageRecordService drugUsageRecordService; + + @Resource + private DrugMaterialInfoMapper drugMaterialInfoMapper; + + @ApiOperation("毒品检材领用出库") + @PostMapping("/outbound") + public R outbound(@RequestBody @Valid DrugUsageRecordDTO dto) { + boolean success = drugUsageRecordService.outbound(dto); + return R.ok(success); + } + + @ApiOperation("毒品检材领用记录分页列表") + @PostMapping("/page") + public R> page(@RequestBody DrugUsageRecordQuery query) { + String keywords = query.getKeywords(); + IPage page = drugUsageRecordService.page( + new Page<>(query.getCurrent(), query.getSize()), + Wrappers.lambdaQuery() + .and(StrUtil.isNotBlank(keywords), + wrapper -> wrapper + .like(DrugUsageRecord::getUsageName, keywords) + .or() + .like(DrugUsageRecord::getApplicantName, keywords) + .or() + .like(DrugUsageRecord::getUsagePurpose, keywords) + ) + .ge(query.getStartDate() != null, DrugUsageRecord::getUsageDate, query.getStartDate()) + .le(query.getEndDate() != null, DrugUsageRecord::getUsageDate, query.getEndDate())); + IPage voiPage = new Page<>(); + BeanUtils.copyProperties(page, voiPage, "records"); + voiPage.setRecords(DrugUsageRecordConvert.entityToVOList(page.getRecords())); + return R.ok(voiPage); + } + + @ApiOperation("毒品检材领用记录详情") + @GetMapping("/details") + public R details(@RequestParam("id") String id) { + DrugUsageRecord drugUsageRecord = drugUsageRecordService.getById(id); + DrugUsageRecordVO drugUsageRecordVO = DrugUsageRecordConvert.entityToVO(drugUsageRecord); + drugUsageRecordVO.setDrugMaterialInfoVOList(drugMaterialInfoMapper.getDrugMaterialVO(Wrappers.query().in("dm.id", drugUsageRecordVO.getDrugIds()))); + return R.ok(drugUsageRecordVO); + } + } diff --git a/src/main/java/digital/laboratory/platform/imr/convert/DrugUsageRecordConvert.java b/src/main/java/digital/laboratory/platform/imr/convert/DrugUsageRecordConvert.java new file mode 100644 index 0000000..1fde29c --- /dev/null +++ b/src/main/java/digital/laboratory/platform/imr/convert/DrugUsageRecordConvert.java @@ -0,0 +1,46 @@ +package digital.laboratory.platform.imr.convert; + +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.StrUtil; +import digital.laboratory.platform.imr.dto.DrugUsageRecordDTO; +import digital.laboratory.platform.imr.entity.DrugUsageRecord; +import digital.laboratory.platform.imr.vo.DrugUsageRecordVO; + +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + +/** + * 毒品检材的领用归还记录表相关 实体类转换 + */ +public class DrugUsageRecordConvert { + + public static DrugUsageRecord dtoToEntity(DrugUsageRecordDTO dto) { + if (dto == null) return null; + + DrugUsageRecord drugUsageRecord = new DrugUsageRecord(); + drugUsageRecord.setDrugId(dto.getDrugIds().stream().collect(Collectors.joining(","))); + drugUsageRecord.setUsageDate(dto.getUsageDate()); + drugUsageRecord.setUsagePurpose(dto.getUsagePurpose()); + return drugUsageRecord; + } + + public static DrugUsageRecordVO entityToVO(DrugUsageRecord entity) { + if (entity == null) return null; + + DrugUsageRecordVO drugUsageRecordVO = new DrugUsageRecordVO(); + drugUsageRecordVO.setId(entity.getId()); + drugUsageRecordVO.setDrugIds(StrUtil.split(entity.getDrugId(), StrUtil.COMMA)); + drugUsageRecordVO.setUsageName(entity.getUsageName()); + drugUsageRecordVO.setUsageDate(entity.getUsageDate()); + drugUsageRecordVO.setUsagePurpose(entity.getUsagePurpose()); + drugUsageRecordVO.setApplicant(entity.getApplicant()); + drugUsageRecordVO.setApplicantName(entity.getApplicantName()); + return drugUsageRecordVO; + } + + 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/dto/DrugUsageRecordDTO.java b/src/main/java/digital/laboratory/platform/imr/dto/DrugUsageRecordDTO.java index 597f13f..80f9a20 100644 --- a/src/main/java/digital/laboratory/platform/imr/dto/DrugUsageRecordDTO.java +++ b/src/main/java/digital/laboratory/platform/imr/dto/DrugUsageRecordDTO.java @@ -7,7 +7,9 @@ import io.swagger.annotations.ApiModelProperty; import lombok.Data; import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotEmpty; import java.time.LocalDateTime; +import java.util.List; /** * 毒品检材的领用归还记录表 保存DTO类 @@ -21,8 +23,8 @@ public class DrugUsageRecordDTO { * 关联领用的毒品id */ @ApiModelProperty("关联领用的毒品id") - @NotBlank(message = "请选择领用的检材!") - private String drugId; + @NotEmpty(message = "请选择领用的检材!") + private List drugIds; /** * 领用时间 diff --git a/src/main/java/digital/laboratory/platform/imr/entity/DrugUsageRecord.java b/src/main/java/digital/laboratory/platform/imr/entity/DrugUsageRecord.java index 4cbd41c..61ee87c 100644 --- a/src/main/java/digital/laboratory/platform/imr/entity/DrugUsageRecord.java +++ b/src/main/java/digital/laboratory/platform/imr/entity/DrugUsageRecord.java @@ -30,29 +30,30 @@ public class DrugUsageRecord extends BaseEntity { private String drugId; /** - * 领用申请人 + * 领用物品名称 */ - private String applicant; + private String usageName; + /** - * 领用时间 + * 领用申请人 */ - private LocalDateTime usageDate; + private String applicant; /** - * 领用目的 + * 领用申请人姓名 */ - private String usagePurpose; + private String applicantName; /** - * 归还时间 + * 领用时间 */ - private LocalDateTime returnDate; + private LocalDateTime usageDate; /** - * 领用状态,1 领用中 | 5 已归还 + * 领用目的 */ - private Integer status; + private String usagePurpose; @TableField(exist = false) private static final long serialVersionUID = 1L; diff --git a/src/main/java/digital/laboratory/platform/imr/enums/DrugMaterialStatus.java b/src/main/java/digital/laboratory/platform/imr/enums/DrugMaterialStatus.java index 1b07e23..26aa58f 100644 --- a/src/main/java/digital/laboratory/platform/imr/enums/DrugMaterialStatus.java +++ b/src/main/java/digital/laboratory/platform/imr/enums/DrugMaterialStatus.java @@ -8,6 +8,7 @@ public enum DrugMaterialStatus { ENTER_DRUG_INFO(0, "录入信息中"), WAIT_INBOUND(3, "待入库"), FINISH_INBOUND(5, "已入库"), + OUTBOUND(7, "已出库") ; private final Integer status; diff --git a/src/main/java/digital/laboratory/platform/imr/enums/DrugUsageStatus.java b/src/main/java/digital/laboratory/platform/imr/enums/DrugUsageStatus.java new file mode 100644 index 0000000..0722280 --- /dev/null +++ b/src/main/java/digital/laboratory/platform/imr/enums/DrugUsageStatus.java @@ -0,0 +1,29 @@ +package digital.laboratory.platform.imr.enums; + +import lombok.Getter; + +@Getter +public enum DrugUsageStatus { + + IN_USAGE(1, "领用中"), + FINISH_USAGE(5, "已归还"), + ; + + private final Integer status; + + private final String desc; + + DrugUsageStatus(Integer status, String desc) { + this.status = status; + this.desc = desc; + } + + public static DrugUsageStatus fromStatus(Integer status) { + for (DrugUsageStatus drugUsageStatus : values()) { + if (drugUsageStatus.getStatus().equals(status)) { + return drugUsageStatus; + } + } + throw new IllegalArgumentException("No enum constant with code: " + status); + } +} diff --git a/src/main/java/digital/laboratory/platform/imr/interceptor/FeignOauth2RequestInterceptor.java b/src/main/java/digital/laboratory/platform/imr/interceptor/FeignOauth2RequestInterceptor.java index a66fddd..aa45435 100644 --- a/src/main/java/digital/laboratory/platform/imr/interceptor/FeignOauth2RequestInterceptor.java +++ b/src/main/java/digital/laboratory/platform/imr/interceptor/FeignOauth2RequestInterceptor.java @@ -2,6 +2,7 @@ package digital.laboratory.platform.imr.interceptor; import feign.RequestInterceptor; import feign.RequestTemplate; +import lombok.extern.slf4j.Slf4j; import org.springframework.context.annotation.Configuration; import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContext; @@ -14,7 +15,7 @@ import org.springframework.security.oauth2.provider.authentication.OAuth2Authent * 目的是在业务系统中识别用户是谁, 允许或禁止用户进行对应的操作。 */ - +@Slf4j @Configuration public class FeignOauth2RequestInterceptor implements RequestInterceptor { @@ -23,12 +24,12 @@ public class FeignOauth2RequestInterceptor implements RequestInterceptor { @Override public void apply(RequestTemplate requestTemplate) { - System.out.println(String.format("dlp-repository, FeignOauth2RequestInterceptor()...")); + log.info(String.format("dlp-repository, FeignOauth2RequestInterceptor()...")); SecurityContext securityContext = SecurityContextHolder.getContext(); Authentication authentication = securityContext.getAuthentication(); if (authentication != null && authentication.getDetails() instanceof OAuth2AuthenticationDetails) { OAuth2AuthenticationDetails details = (OAuth2AuthenticationDetails) authentication.getDetails(); - System.out.println(String.format("FeignOauth2RequestInterceptor() Authorization, token=%s", details.getTokenValue())); + log.info(String.format("FeignOauth2RequestInterceptor() Authorization, token=%s", details.getTokenValue())); requestTemplate.header(AUTHORIZATION_HEADER, String.format("%s %s", BEARER_TOKEN_TYPE, details.getTokenValue())); } diff --git a/src/main/java/digital/laboratory/platform/imr/mapper/DrugUsageRecordMapper.java b/src/main/java/digital/laboratory/platform/imr/mapper/DrugUsageRecordMapper.java index 4aca138..4ddbbbf 100644 --- a/src/main/java/digital/laboratory/platform/imr/mapper/DrugUsageRecordMapper.java +++ b/src/main/java/digital/laboratory/platform/imr/mapper/DrugUsageRecordMapper.java @@ -1,8 +1,12 @@ package digital.laboratory.platform.imr.mapper; +import com.baomidou.mybatisplus.core.metadata.IPage; import digital.laboratory.platform.imr.entity.DrugUsageRecord; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +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; /** * @author ChenJiangBao @@ -13,6 +17,8 @@ import org.apache.ibatis.annotations.Mapper; @Mapper public interface DrugUsageRecordMapper extends BaseMapper { + IPage queryUsageRecordVOPage(IPage page, @Param("query") DrugDepotsQuery query); + } diff --git a/src/main/java/digital/laboratory/platform/imr/query/DrugDepotsQuery.java b/src/main/java/digital/laboratory/platform/imr/query/DrugDepotsQuery.java index 5ad0627..505662f 100644 --- a/src/main/java/digital/laboratory/platform/imr/query/DrugDepotsQuery.java +++ b/src/main/java/digital/laboratory/platform/imr/query/DrugDepotsQuery.java @@ -30,6 +30,9 @@ public class DrugDepotsQuery { @ApiModelProperty(value = "案件id查询") private String caseId; + @ApiModelProperty(value = "状态 0 录入信息 | 3 待入库 | 5 已入库") + private Integer status; + @ApiModelProperty(value = "开始日期") @JsonFormat(pattern = DateUtils.yyyy_MM_dd) private LocalDate startDate; diff --git a/src/main/java/digital/laboratory/platform/imr/query/DrugUsageRecordQuery.java b/src/main/java/digital/laboratory/platform/imr/query/DrugUsageRecordQuery.java new file mode 100644 index 0000000..c09863c --- /dev/null +++ b/src/main/java/digital/laboratory/platform/imr/query/DrugUsageRecordQuery.java @@ -0,0 +1,34 @@ +package digital.laboratory.platform.imr.query; + +import com.fasterxml.jackson.annotation.JsonFormat; +import digital.laboratory.platform.imr.component.DateUtils; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.time.LocalDate; + +/** + * 毒品库领用记录信息查询对象 Query + */ +@Data +@ApiModel(value = "DrugUsageRecordQuery", description = "毒品库领用记录信息查询对象 Query") +public class DrugUsageRecordQuery { + + @ApiModelProperty(value = "分页参数,每页多少条, 默认10") + private Long size = 10L; + + @ApiModelProperty(value = "分页参数, 当前页, 默认1") + private Long current = 1L; + + @ApiModelProperty(value = "关键字,支持 案件名称, 毒品名称") + private String keywords; + + @ApiModelProperty(value = "开始日期") + @JsonFormat(pattern = DateUtils.yyyy_MM_dd) + private LocalDate startDate; + + @ApiModelProperty(value = "结束日期") + @JsonFormat(pattern = DateUtils.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 index 6bc337e..944e928 100644 --- a/src/main/java/digital/laboratory/platform/imr/service/CommonFeignService.java +++ b/src/main/java/digital/laboratory/platform/imr/service/CommonFeignService.java @@ -77,4 +77,11 @@ public interface CommonFeignService { * @return */ Map remoteUploadFile(MultipartFile file, String path); + + /** + * 远程调用,柜子里的检材出库 + * @param cellId 检材存储的格子id + * @param sampleId 存放的检材id + */ + void remoteCabinetOutbound(String cellId, String sampleId); } 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 0efe021..f42b2f6 100644 --- a/src/main/java/digital/laboratory/platform/imr/service/DrugCaseInfoService.java +++ b/src/main/java/digital/laboratory/platform/imr/service/DrugCaseInfoService.java @@ -3,6 +3,7 @@ package digital.laboratory.platform.imr.service; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.service.IService; import digital.laboratory.platform.imr.dto.DrugDepotsDTO; +import digital.laboratory.platform.imr.dto.DrugMaterialInfoDTO; import digital.laboratory.platform.imr.entity.DrugCaseInfo; import digital.laboratory.platform.imr.query.DrugDepotsQuery; import digital.laboratory.platform.imr.vo.DrugCaseInfoVO; 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 4688962..389e750 100644 --- a/src/main/java/digital/laboratory/platform/imr/service/DrugMaterialInfoService.java +++ b/src/main/java/digital/laboratory/platform/imr/service/DrugMaterialInfoService.java @@ -3,6 +3,7 @@ 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.DrugMaterialInfoDTO; import digital.laboratory.platform.imr.dto.InRepositoryDTO; import digital.laboratory.platform.imr.entity.DrugCaseInfo; import digital.laboratory.platform.imr.entity.DrugMaterialInfo; @@ -76,4 +77,11 @@ public interface DrugMaterialInfoService extends IService { * @return */ boolean delete(List ids); + + /** + * 复制检材 + * @param dto + * @return + */ + DrugMaterialInfoVO copy(DrugMaterialInfoDTO dto); } diff --git a/src/main/java/digital/laboratory/platform/imr/service/DrugUsageRecordService.java b/src/main/java/digital/laboratory/platform/imr/service/DrugUsageRecordService.java index 0a9a944..e454b8d 100644 --- a/src/main/java/digital/laboratory/platform/imr/service/DrugUsageRecordService.java +++ b/src/main/java/digital/laboratory/platform/imr/service/DrugUsageRecordService.java @@ -1,5 +1,6 @@ package digital.laboratory.platform.imr.service; +import digital.laboratory.platform.imr.dto.DrugUsageRecordDTO; import digital.laboratory.platform.imr.entity.DrugUsageRecord; import com.baomidou.mybatisplus.extension.service.IService; @@ -10,4 +11,10 @@ import com.baomidou.mybatisplus.extension.service.IService; */ public interface DrugUsageRecordService extends IService { + /** + * 毒品检材领用出库 + * @param dto + * @return + */ + boolean outbound(DrugUsageRecordDTO dto); } diff --git a/src/main/java/digital/laboratory/platform/imr/service/SampleOutboundRecordService.java b/src/main/java/digital/laboratory/platform/imr/service/SampleOutboundRecordService.java new file mode 100644 index 0000000..5043e88 --- /dev/null +++ b/src/main/java/digital/laboratory/platform/imr/service/SampleOutboundRecordService.java @@ -0,0 +1,15 @@ +package digital.laboratory.platform.imr.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import digital.laboratory.platform.imr.entity.SampleInboundAndOutboundTable; +import digital.laboratory.platform.imr.entity.SampleOutboundRecord; + +/** + * 服务类 + * + * @author Zhang Xiaolong created at 2023-03-21 + * @describe 服务类 + */ +public interface SampleOutboundRecordService 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 index ed728aa..882a318 100644 --- a/src/main/java/digital/laboratory/platform/imr/service/impl/CommonFeignServiceImpl.java +++ b/src/main/java/digital/laboratory/platform/imr/service/impl/CommonFeignServiceImpl.java @@ -10,8 +10,10 @@ 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.CellAndStoreSupplyData; import digital.laboratory.platform.sys.entity.SysOrg; import digital.laboratory.platform.sys.entity.SysUser; +import digital.laboratory.platform.sys.feign.RemoteCabinetService; import digital.laboratory.platform.sys.feign.RemoteOrgService; import digital.laboratory.platform.sys.feign.RemoteUserService; import feign.Response; @@ -24,10 +26,7 @@ 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.*; import java.util.stream.Collectors; /** @@ -46,6 +45,9 @@ public class CommonFeignServiceImpl implements CommonFeignService { @Resource private RemoteWord2PDFService remoteWord2PDFService; + @Resource + private RemoteCabinetService remoteCabinetService; + @Resource private OssFile ossFile; @@ -203,4 +205,25 @@ public class CommonFeignServiceImpl implements CommonFeignService { throw new RuntimeException(failMsg); } } + + /** + * 远程调用,柜子里的检材出库 + * @param cellId 检材存储的格子id + * @param sampleId 存放的检材id + */ + @Override + public void remoteCabinetOutbound(String cellId, String sampleId) { + ArrayList sampleIds = new ArrayList<>(); + CellAndStoreSupplyData cellAndStoreSupplyData = new CellAndStoreSupplyData(); + cellAndStoreSupplyData.setCellId(cellId); + cellAndStoreSupplyData.setCellStatus("1"); + sampleIds.add(sampleId); + cellAndStoreSupplyData.setStoreSupplyList(sampleIds); + /* + 柜子新接口 + */ + ArrayList supplyData = new ArrayList<>(); + supplyData.add(cellAndStoreSupplyData); + remoteCabinetService.takeOrSaveGoodsFromCabinet(supplyData, -1); + } } 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 a647583..0fc22a9 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,13 +1,16 @@ 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.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import digital.laboratory.platform.common.core.exception.ValidateCodeException; 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.dto.DrugMaterialInfoDTO; import digital.laboratory.platform.imr.entity.DrugCaseInfo; import digital.laboratory.platform.imr.entity.DrugMaterialInfo; import digital.laboratory.platform.imr.mapper.DrugCaseInfoMapper; @@ -19,10 +22,12 @@ 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.dao.DataIntegrityViolationException; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; +import java.sql.SQLIntegrityConstraintViolationException; import java.util.List; import java.util.stream.Collectors; @@ -54,7 +59,7 @@ public class DrugCaseInfoServiceImpl extends ServiceImpl save(DrugDepotsDTO dto) { DrugCaseInfo drugCaseInfo = DrugCaseInfoConvert.dtoTOEntity(dto); - boolean flag = false; + boolean flag = true; if (StrUtil.isBlank(drugCaseInfo.getId())) { if (super.save(drugCaseInfo)) { // 保存毒品检材 @@ -69,8 +74,12 @@ public class DrugCaseInfoServiceImpl extends ServiceImpl 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 (CollUtil.isNotEmpty(updateList)) { + flag = drugMaterialInfoService.updateBatchById(updateList); + } + if (CollUtil.isNotEmpty(saveList)) { + flag = drugMaterialInfoService.saveDrugMaterialBatch(saveList, drugCaseInfo); + } } } if (flag) { @@ -99,9 +108,20 @@ public class DrugCaseInfoServiceImpl extends ServiceImpllambdaQuery().eq(DrugMaterialInfo::getCaseId, dto.getCaseId())) == 0) { + // 如果当前案件是第一次保存检材,则都保存当前检材和复制的检材 + super.save(drugMaterialInfo); + } +// drugMaterialInfo = DrugMaterialInfoConvert.dtoToEntity(dto); + drugMaterialInfo.setId(null); + super.save(drugMaterialInfo); + List drugMaterialInfoVOS = baseMapper.getDrugMaterialVO(Wrappers.lambdaQuery() + .eq(DrugMaterialInfo::getId, drugMaterialInfo.getId())); + // 检查是否获取到 VO + if (!drugMaterialInfoVOS.isEmpty()) { + return drugMaterialInfoVOS.get(0); + } else { + // 处理未找到 VO 的情况 + throw new RuntimeException("Failed to retrieve the DrugMaterialInfoVO for the saved record."); + } + } + /** * 分页查询毒品库中的毒品检材信息VO列表 * @@ -153,15 +181,17 @@ public class DrugMaterialInfoServiceImpl extends ServiceImpl drugMaterialInfoVOMap = drugMaterialInfoVOS.stream() .collect(Collectors.toMap(DrugMaterialInfoVO::getDrugNo, Function.identity())); // 待操作的毒品检材id列表 List waitOpDrugIds = drugMaterialInfoVOS.stream().map(DrugMaterialInfoVO::getId).collect(Collectors.toList()); - Map sampleStorageMap = sampleStorageMapper - .selectList(Wrappers.lambdaQuery() - .in(SampleStorage::getSampleId, - waitOpDrugIds)) - .stream().collect(Collectors.toMap(SampleStorage::getSampleId, Function.identity())); + List sampleStorages = sampleStorageMapper.selectList(Wrappers.lambdaQuery() + .in(SampleStorage::getSampleId, waitOpDrugIds)); + Map sampleStorageMap = CollUtil.isEmpty(sampleStorages) ? + new HashMap<>() : sampleStorages.stream().collect(Collectors.toMap(SampleStorage::getSampleId, Function.identity())); // 存储需要批量保存的实体信息 List updateSampleStorageList = new ArrayList<>(); List saveSampleStorageList = new ArrayList<>(); @@ -254,7 +284,8 @@ public class DrugMaterialInfoServiceImpl extends ServiceImpl drugMaterialInfos = super.list(Wrappers.lambdaQuery().in(DrugMaterialInfo::getId, ids)); for (DrugMaterialInfo drugMaterialInfo : drugMaterialInfos) { - if (!drugMaterialInfo.getStatus().equals(DrugMaterialStatus.ENTER_DRUG_INFO.getStatus())) { + if (!drugMaterialInfo.getStatus().equals(DrugMaterialStatus.ENTER_DRUG_INFO.getStatus()) + && !drugMaterialInfo.getStatus().equals(DrugMaterialStatus.WAIT_INBOUND.getStatus())) { throw new ValidateCodeException(String.format("检材编号为 %s 的检材不在可删除状态,不能删除!", drugMaterialInfo.getDrugNo())); } } diff --git a/src/main/java/digital/laboratory/platform/imr/service/impl/DrugUsageRecordServiceImpl.java b/src/main/java/digital/laboratory/platform/imr/service/impl/DrugUsageRecordServiceImpl.java index ec51f73..4100df3 100644 --- a/src/main/java/digital/laboratory/platform/imr/service/impl/DrugUsageRecordServiceImpl.java +++ b/src/main/java/digital/laboratory/platform/imr/service/impl/DrugUsageRecordServiceImpl.java @@ -1,10 +1,27 @@ package digital.laboratory.platform.imr.service.impl; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import digital.laboratory.platform.imr.entity.DrugUsageRecord; +import digital.laboratory.platform.common.core.exception.ValidateCodeException; +import digital.laboratory.platform.common.mybatis.security.service.DLPUser; +import digital.laboratory.platform.common.security.util.SecurityUtils; +import digital.laboratory.platform.imr.convert.DrugUsageRecordConvert; +import digital.laboratory.platform.imr.dto.DrugUsageRecordDTO; +import digital.laboratory.platform.imr.entity.*; +import digital.laboratory.platform.imr.enums.DrugMaterialStatus; +import digital.laboratory.platform.imr.enums.DrugUsageStatus; +import digital.laboratory.platform.imr.enums.OutboundType; import digital.laboratory.platform.imr.mapper.DrugUsageRecordMapper; -import digital.laboratory.platform.imr.service.DrugUsageRecordService; +import digital.laboratory.platform.imr.service.*; +import digital.laboratory.platform.imr.vo.DrugMaterialInfoVO; +import digital.laboratory.platform.sys.entity.Drug; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.time.LocalDateTime; +import java.util.List; +import java.util.stream.Collectors; /** * @author ChenJiangBao @@ -15,6 +32,98 @@ import org.springframework.stereotype.Service; public class DrugUsageRecordServiceImpl extends ServiceImpl implements DrugUsageRecordService{ + @Resource + private DrugMaterialInfoService drugMaterialInfoService; + + @Resource + private SampleStorageService sampleStorageService; + + @Resource + private CommonFeignService commonFeignService; + + @Resource + private SampleOutboundRecordService sampleOutboundRecordService; + + @Resource + private SampleInboundAndOutboundTableService sampleInboundAndOutboundTableService; + + /** + * 毒品检材领用出库 + * @param dto + * @return + */ + @Override + @Transactional(rollbackFor = Exception.class) + public boolean outbound(DrugUsageRecordDTO dto) { + List drugIds = dto.getDrugIds(); + String usagePurpose = dto.getUsagePurpose(); + LocalDateTime usageDate = dto.getUsageDate(); + // 判断当前需要领用的检材是否都可以出库 + List drugMaterialInfos = drugMaterialInfoService.list(Wrappers.lambdaQuery().in(DrugMaterialInfo::getId, drugIds)); + for (DrugMaterialInfo drugMaterialInfo : drugMaterialInfos) { + if (!drugMaterialInfo.getStatus().equals(DrugMaterialStatus.FINISH_INBOUND.getStatus())) { + throw new ValidateCodeException(String.format("毒品检材编号为 %s 的检材不在可以出库的状态!", drugMaterialInfo.getDrugNo())); + } + } + // 校验通过,保存领用出库记录 + DLPUser user = SecurityUtils.getUser(); + DrugUsageRecord drugUsageRecord = DrugUsageRecordConvert.dtoToEntity(dto); + drugUsageRecord.setApplicant(user.getId()); + drugUsageRecord.setApplicantName(user.getName()); + drugUsageRecord.setUsageName(drugMaterialInfos.stream().map(DrugMaterialInfo::getDrugName).collect(Collectors.joining(","))); + if (super.save(drugUsageRecord)) { + // 移除柜子系统中关联的id, 获取格子id + List sampleStorageList = sampleStorageService.list(Wrappers.lambdaQuery().in(SampleStorage::getSampleId, drugIds)); + // 更新样本仓库状态为已出库 + sampleStorageService.update(Wrappers.lambdaUpdate() + .in(SampleStorage::getSampleId, drugIds) + .set(SampleStorage::getStatus, 3) + .set(SampleStorage::getReturnTime, null) + .set(SampleStorage::getIsReturn, 1) + .set(SampleStorage::getRecipientId, user.getId()) + .set(SampleStorage::getOutRepositoryDate, usageDate) + .set(SampleStorage::getPurpose, usagePurpose) + ); + // 修改样本出入库登记表 + sampleInboundAndOutboundTableService.update(Wrappers.lambdaUpdate() + .in(SampleInboundAndOutboundTable::getSampleId, drugIds) + .isNull(SampleInboundAndOutboundTable::getAppraiserId) + .set(SampleInboundAndOutboundTable::getAppraiserId, user.getId()) + .set(SampleInboundAndOutboundTable::getOutWarehouseDate, usageDate) + .set(SampleInboundAndOutboundTable::getRemarks, usagePurpose) + .set(SampleInboundAndOutboundTable::getReturnTime, null) + .set(SampleInboundAndOutboundTable::getOutboundSupervisor, null) + ); + + //添加样本出库记录 +// List sampleOutboundRecordList = sampleStorageList.parallelStream().map(sampleStorage -> { +// SampleOutboundRecord sampleOutboundRecord = new SampleOutboundRecord(); +// sampleOutboundRecord.setSampleId(sampleStorage.getSampleId()); +// sampleOutboundRecord.setOutboundType(OutboundType.USE);//领用出库 +// sampleOutboundRecord.setRecipientId(user.getId());//领取人 +// sampleOutboundRecord.setName(sampleStorage.getName());//样本名称--方便搜索 +// sampleOutboundRecord.setReason(usagePurpose);//把出库原因设置为备注 +// sampleOutboundRecord.setOutboundDate(usageDate);//出库时间 +// +// // 从格子中出库 +// commonFeignService.remoteCabinetOutbound(sampleStorage.getStorageCellId(), sampleStorage.getSampleId()); +// return sampleOutboundRecord; +// }).collect(Collectors.toList()); +// sampleOutboundRecordService.saveBatch(sampleOutboundRecordList); + sampleStorageList.parallelStream().forEach(sampleStorage -> { + // 从格子中出库 + commonFeignService.remoteCabinetOutbound(sampleStorage.getStorageCellId(), sampleStorage.getSampleId()); + }); + + // 更新毒品检材状态为已经出库 + drugMaterialInfoService.update(Wrappers.lambdaUpdate() + .in(DrugMaterialInfo::getId, drugIds) + .set(DrugMaterialInfo::getStatus, DrugMaterialStatus.OUTBOUND.getStatus()) + ); + return true; + } + return false; + } } diff --git a/src/main/java/digital/laboratory/platform/imr/service/impl/SampleOutWarehouseApplyServiceImpl.java b/src/main/java/digital/laboratory/platform/imr/service/impl/SampleOutWarehouseApplyServiceImpl.java index 75f635e..005108e 100644 --- a/src/main/java/digital/laboratory/platform/imr/service/impl/SampleOutWarehouseApplyServiceImpl.java +++ b/src/main/java/digital/laboratory/platform/imr/service/impl/SampleOutWarehouseApplyServiceImpl.java @@ -17,6 +17,7 @@ import digital.laboratory.platform.imr.enums.OutboundType; 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.CommonFeignService; import digital.laboratory.platform.imr.service.SampleOutWarehouseApplyService; import digital.laboratory.platform.imr.vo.BaseSampleDetail; import digital.laboratory.platform.imr.vo.CellVO; @@ -48,7 +49,7 @@ public class SampleOutWarehouseApplyServiceImpl extends ServiceImpl sampleIds = new ArrayList<>(); - CellAndStoreSupplyData cellAndStoreSupplyData = new CellAndStoreSupplyData(); - cellAndStoreSupplyData.setCellId(storage.getStorageCellId()); - cellAndStoreSupplyData.setCellStatus("1"); - sampleIds.add(storage.getSampleId()); - cellAndStoreSupplyData.setStoreSupplyList(sampleIds); - /* - 柜子新接口 - */ - ArrayList supplyData = new ArrayList<>(); - supplyData.add(cellAndStoreSupplyData); - cabinetService.takeOrSaveGoodsFromCabinet(supplyData, -1); - + commonFeignService.remoteCabinetOutbound(storage.getStorageCellId(), storage.getSampleId()); } return this.getOutWarehouseDetailedById(selectOne.getId()); } diff --git a/src/main/java/digital/laboratory/platform/imr/service/impl/SampleOutboundRecordServiceImpl.java b/src/main/java/digital/laboratory/platform/imr/service/impl/SampleOutboundRecordServiceImpl.java new file mode 100644 index 0000000..2bb0320 --- /dev/null +++ b/src/main/java/digital/laboratory/platform/imr/service/impl/SampleOutboundRecordServiceImpl.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.SampleOutboundRecord; +import digital.laboratory.platform.imr.mapper.SampleOutboundRecordMapper; +import digital.laboratory.platform.imr.service.SampleOutboundRecordService; +import org.springframework.stereotype.Service; + +@Service +public class SampleOutboundRecordServiceImpl extends ServiceImpl implements SampleOutboundRecordService { +} diff --git a/src/main/java/digital/laboratory/platform/imr/vo/DrugMaterialInfoVO.java b/src/main/java/digital/laboratory/platform/imr/vo/DrugMaterialInfoVO.java index 333290e..93ce01b 100644 --- a/src/main/java/digital/laboratory/platform/imr/vo/DrugMaterialInfoVO.java +++ b/src/main/java/digital/laboratory/platform/imr/vo/DrugMaterialInfoVO.java @@ -34,6 +34,9 @@ public class DrugMaterialInfoVO { @ApiModelProperty("关联的入库记录id") private String sampleStorageId; + @ApiModelProperty("柜子id") + private String canineId; + @ApiModelProperty("存放位置") private String storageLocation; diff --git a/src/main/java/digital/laboratory/platform/imr/vo/DrugUsageRecordVO.java b/src/main/java/digital/laboratory/platform/imr/vo/DrugUsageRecordVO.java new file mode 100644 index 0000000..8cb716d --- /dev/null +++ b/src/main/java/digital/laboratory/platform/imr/vo/DrugUsageRecordVO.java @@ -0,0 +1,63 @@ +package digital.laboratory.platform.imr.vo; + +import com.fasterxml.jackson.annotation.JsonFormat; +import digital.laboratory.platform.imr.component.DateUtils; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import javax.validation.constraints.NotEmpty; +import java.time.LocalDateTime; +import java.util.List; + +/** + * 毒品检材的领用归还记录表 VO类 + * @TableName b_drug_usage_record + */ +@Data +@ApiModel(value = "DrugUsageRecordVO", description = "毒品检材的领用归还记录表 VO类") +public class DrugUsageRecordVO { + + @ApiModelProperty("主键id") + private String id; + + /** + * 关联领用的毒品id + */ + @ApiModelProperty("关联领用的毒品id") + private List drugIds; + + /** + * 领用物品名称 + */ + @ApiModelProperty("领用物品名称") + private String usageName; + + /** + * 领用时间 + */ + @ApiModelProperty("领用时间") + @JsonFormat(pattern = DateUtils.yyyy_MM_dd_HH_mm_ss, timezone = DateUtils.TIME_ZONE) + private LocalDateTime usageDate; + + /** + * 领用目的 + */ + @ApiModelProperty("领用目的") + private String usagePurpose; + + /** + * 领用申请人 + */ + @ApiModelProperty("领用申请人id") + private String applicant; + + /** + * 领用申请人姓名 + */ + @ApiModelProperty("领用申请人姓名") + private String applicantName; + + @ApiModelProperty("领用的毒品检材详情信息列表") + private List drugMaterialInfoVOList; +} \ No newline at end of file diff --git a/src/main/resources/mapper/DrugMaterialInfoMapper.xml b/src/main/resources/mapper/DrugMaterialInfoMapper.xml index 14b95f1..a9aaa91 100644 --- a/src/main/resources/mapper/DrugMaterialInfoMapper.xml +++ b/src/main/resources/mapper/DrugMaterialInfoMapper.xml @@ -34,7 +34,8 @@ dc.handing_over_org, dc.handing_over_date, ss.id as sampleStorageId, - ss.storage_location + ss.storage_location, + ss.box_id as canineId 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 @@ -54,6 +55,9 @@ AND dm.case_id = #{query.caseId} + + AND dm.status = #{query.status} + AND dc.handing_over_date >= #{query.startDate} diff --git a/src/main/resources/mapper/DrugUsageRecordMapper.xml b/src/main/resources/mapper/DrugUsageRecordMapper.xml new file mode 100644 index 0000000..aa49503 --- /dev/null +++ b/src/main/resources/mapper/DrugUsageRecordMapper.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + id,drug_id,applicant,applicant_name, + usage_date,usage_purpose, + create_time,update_time, + create_by,update_by + + + +