|
@@ -0,0 +1,141 @@
|
|
|
+package com.github.jfcloud.gene.flow.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.lang.Assert;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.github.jfcloud.common.data.datascope.DataScope;
|
|
|
+import com.github.jfcloud.gene.cache.UserIdNameCache;
|
|
|
+import com.github.jfcloud.gene.common.constant.WhetherEnum;
|
|
|
+import com.github.jfcloud.gene.common.util.CustomIdGenerator;
|
|
|
+import com.github.jfcloud.gene.constants.GeneStatusEnum;
|
|
|
+import com.github.jfcloud.gene.constants.GeneTargetEnum;
|
|
|
+import com.github.jfcloud.gene.flow.dto.FlowDetailDto;
|
|
|
+import com.github.jfcloud.gene.flow.dto.FlowPageDto;
|
|
|
+import com.github.jfcloud.gene.flow.entity.FlowInfo;
|
|
|
+import com.github.jfcloud.gene.flow.mapper.FlowInfoMapper;
|
|
|
+import com.github.jfcloud.gene.flow.service.FlowInfoService;
|
|
|
+import com.github.jfcloud.gene.flow.vo.FlowDetailVo;
|
|
|
+import com.github.jfcloud.gene.flow.vo.FlowPageVo;
|
|
|
+import com.github.jfcloud.gene.form.entity.StrainCustomInfo;
|
|
|
+import com.github.jfcloud.gene.form.entity.StrainPurificationInfo;
|
|
|
+import com.github.jfcloud.gene.form.service.StrainCustomInfoService;
|
|
|
+import com.github.jfcloud.gene.form.service.StrainPurificationInfoService;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+import java.util.Objects;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+@RequiredArgsConstructor
|
|
|
+public class FlowInfoServiceImpl extends ServiceImpl<FlowInfoMapper, FlowInfo> implements FlowInfoService {
|
|
|
+
|
|
|
+ private final UserIdNameCache userIdNameCache;
|
|
|
+ private final StrainCustomInfoService customInfoService;
|
|
|
+ private final StrainPurificationInfoService purificationInfoService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Page<FlowPageDto> getPage(FlowPageVo vo) {
|
|
|
+ Page<FlowInfo> pageQuery = new Page<>(vo.getCurrent(), vo.getSize());
|
|
|
+ LambdaQueryWrapper<FlowInfo> lqw = new LambdaQueryWrapper<>(FlowInfo.class)
|
|
|
+ .like(StrUtil.isNotBlank(vo.getProjectName()), FlowInfo::getProjectName, vo.getProjectName())
|
|
|
+ .like(StrUtil.isNotBlank(vo.getContractNo()), FlowInfo::getContractNo, vo.getContractNo())
|
|
|
+ .like(StrUtil.isNotBlank(vo.getApprovalNo()), FlowInfo::getApprovalNo, vo.getApprovalNo())
|
|
|
+ .eq(Objects.nonNull(vo.getProjectLeaderId()), FlowInfo::getProjectLeaderId, vo.getProjectLeaderId())
|
|
|
+ .eq(Objects.nonNull(vo.getCreateBy()), FlowInfo::getCreateBy, vo.getCreateBy())
|
|
|
+ .eq(StrUtil.isNotBlank(vo.getStatus()), FlowInfo::getStatus, vo.getStatus())
|
|
|
+ .eq(FlowInfo::getDeleted, WhetherEnum.NO.getCode())
|
|
|
+ .orderByDesc(FlowInfo::getCreateTime);
|
|
|
+ Page<FlowInfo> page = baseMapper.selectPageByScope(pageQuery, lqw, DataScope.of());
|
|
|
+ if (page.getTotal() < 1) {
|
|
|
+ return new Page<>();
|
|
|
+ }
|
|
|
+
|
|
|
+ List<FlowPageDto> records = BeanUtil.copyToList(page.getRecords(), FlowPageDto.class);
|
|
|
+ //补充申请人姓名
|
|
|
+ records.forEach(item -> item.setCreateByName(userIdNameCache.getNicknameByUserId(Long.parseLong(item.getCreateBy()))));
|
|
|
+
|
|
|
+ Page<FlowPageDto> pageDto = new Page<>(page.getCurrent(), page.getSize(), page.getTotal());
|
|
|
+ return pageDto.setRecords(records);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public FlowDetailDto getDetail(Long id) {
|
|
|
+ FlowInfo flowInfo = getById(id);
|
|
|
+ Assert.notNull(flowInfo, "基因定制流程不存在");
|
|
|
+
|
|
|
+ FlowDetailDto detail = BeanUtil.copyProperties(flowInfo, FlowDetailDto.class);
|
|
|
+ detail.setStatusLabel(GeneStatusEnum.getLabelByStatus(detail.getStatus()));
|
|
|
+ detail.setCustom(customInfoService.getByFlowId(id));
|
|
|
+ detail.setPurification(purificationInfoService.getByFlowId(id));
|
|
|
+ return detail;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void saveFlow(FlowDetailVo vo) {
|
|
|
+ log.info("保存流程 项目名称:{}", vo.getProjectName());
|
|
|
+ FlowInfo flowInfo = BeanUtil.copyProperties(vo, FlowInfo.class);
|
|
|
+ flowInfo.setId(CustomIdGenerator.nextId());
|
|
|
+
|
|
|
+ if (vo.getCustom() != null) {
|
|
|
+ if (vo.getPurification() != null) {
|
|
|
+ flowInfo.setTarget(GeneTargetEnum.CUSTOM + "," + GeneTargetEnum.PURIFICATION);
|
|
|
+
|
|
|
+ vo.getPurification().setFlowId(flowInfo.getId());
|
|
|
+ purificationInfoService.saveForm(vo.getPurification());
|
|
|
+ } else {
|
|
|
+ flowInfo.setTarget(GeneTargetEnum.CUSTOM.getCode());
|
|
|
+ }
|
|
|
+
|
|
|
+ vo.getCustom().setFlowId(flowInfo.getId());
|
|
|
+ customInfoService.saveForm(vo.getCustom());
|
|
|
+
|
|
|
+ } else if (vo.getPurification() != null) {
|
|
|
+ flowInfo.setTarget(GeneTargetEnum.PURIFICATION.getCode());
|
|
|
+
|
|
|
+ vo.getPurification().setFlowId(flowInfo.getId());
|
|
|
+ purificationInfoService.saveForm(vo.getPurification());
|
|
|
+ }
|
|
|
+ flowInfo.setStatus(GeneStatusEnum.DRAFT.getStatus());
|
|
|
+ flowInfo.insert();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void updateFlow(Long id, FlowDetailVo vo) {
|
|
|
+ log.info("编辑流程 项目名称:{}", vo.getProjectName());
|
|
|
+
|
|
|
+ FlowInfo flowInfo = getById(id);
|
|
|
+ Assert.notNull(flowInfo, "基因定制流程不存在");
|
|
|
+ BeanUtil.copyProperties(vo, flowInfo);
|
|
|
+
|
|
|
+
|
|
|
+ StringBuilder target = new StringBuilder();
|
|
|
+ if (vo.getCustom() == null) {
|
|
|
+ customInfoService.remove(new LambdaQueryWrapper<>(StrainCustomInfo.class).eq(StrainCustomInfo::getFlowId, id));
|
|
|
+ } else {
|
|
|
+ vo.getCustom().setFlowId(id);
|
|
|
+ customInfoService.updateForm(id, vo.getCustom());
|
|
|
+ target.append(GeneTargetEnum.CUSTOM);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (vo.getPurification() == null) {
|
|
|
+ purificationInfoService.remove(new LambdaQueryWrapper<>(StrainPurificationInfo.class).eq(StrainPurificationInfo::getFlowId, id));
|
|
|
+ } else {
|
|
|
+ vo.getPurification().setFlowId(id);
|
|
|
+ purificationInfoService.updateForm(id, vo.getPurification());
|
|
|
+
|
|
|
+ if (target.length() > 0) {
|
|
|
+ target.append(",");
|
|
|
+ }
|
|
|
+ target.append(GeneTargetEnum.PURIFICATION);
|
|
|
+ }
|
|
|
+
|
|
|
+ flowInfo.setTarget(target.toString());
|
|
|
+ flowInfo.updateById();
|
|
|
+ }
|
|
|
+}
|