Commit 5ac28c56 by 谢海旭

查询SOP模板实例分页列表、重写模板下发接口

1 parent da8154ed
......@@ -90,6 +90,12 @@ public class SopTplNode {
private Byte nodeSkipable;
/**
* '节点是否异步执行。非异步执行则代表对前置节点有依赖
*/
@Column(name = "node_async")
private Byte nodeAsync;
/**
* 获取节点id
*
* @return node_id - 节点id
......@@ -340,4 +346,12 @@ public class SopTplNode {
public void setNodeSkipable(Byte nodeSkipable) {
this.nodeSkipable = nodeSkipable;
}
public Byte getNodeAsync() {
return nodeAsync;
}
public void setNodeAsync(Byte nodeAsync) {
this.nodeAsync = nodeAsync;
}
}
\ No newline at end of file
......@@ -3,6 +3,7 @@ package cn.com.glsx.process.modules.mapper;
import java.util.List;
import java.util.Map;
import cn.com.glsx.process.modules.model.SopInstDTO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
......@@ -41,4 +42,12 @@ public interface SopInstMapper extends CommonBaseMapper<SopInst> {
void updateInstStatus(@Param("instId") String instId, @Param("status") Byte status);
void updateInstBatchNo(@Param("instId") String instId, @Param("batchNo") String batchNo);
/**
* 分页查询模板实例列表
*
* @param search
* @return
*/
List<SopInstDTO> page(SopInstSearch search);
}
\ No newline at end of file
......@@ -2,6 +2,7 @@ package cn.com.glsx.process.modules.model;
import cn.com.glsx.process.modules.entity.SopInstLink;
import cn.com.glsx.process.modules.entity.SopInstNode;
import cn.com.glsx.process.modules.entity.SopTplGrant;
import java.util.Date;
import java.util.List;
......@@ -14,6 +15,11 @@ public class SopInstDTO {
private String instId;
/**
* 模板id
*/
private String tplId;
/**
* 实例分组:当前场景下,分组id就是门店id
*/
private Integer grantId;
......@@ -49,6 +55,11 @@ public class SopInstDTO {
private String instParam;
/**
* 实例快照,每天任务均从快照取数,修改的数据写回快照,与快照表做冗余;
*/
private String instSnapshot;
/**
* sop有效期,每个sop都设置一个有效期,到期自动停止。
*/
private Date expireTime;
......@@ -69,6 +80,15 @@ public class SopInstDTO {
*/
private List<SopInstLink> links;
/**
* 用于下发门店时
*/
private List<SopTplGrant> sopTplGrants;
/**
* 授权关系(关联的门店)
*/
private SopTplGrant sopTplGrant;
/**
* 获取实例id,一般sop只允许一个实例。特殊情况可以根据输入参数来区分不同实例。实例名可以用于在cdp保存状态
......@@ -88,6 +108,14 @@ public class SopInstDTO {
this.instId = instId == null ? null : instId.trim();
}
public String getTplId() {
return tplId;
}
public void setTplId(String tplId) {
this.tplId = tplId;
}
/**
* 获取实例分组:当前场景下,分组id就是门店id
*
......@@ -214,6 +242,14 @@ public class SopInstDTO {
this.instParam = instParam;
}
public String getInstSnapshot() {
return instSnapshot;
}
public void setInstSnapshot(String instSnapshot) {
this.instSnapshot = instSnapshot;
}
/**
* 获取sop有效期,每个sop都设置一个有效期,到期自动停止。
*
......@@ -265,4 +301,20 @@ public class SopInstDTO {
public void setLinks(List<SopInstLink> links) {
this.links = links;
}
public List<SopTplGrant> getSopTplGrants() {
return sopTplGrants;
}
public void setSopTplGrants(List<SopTplGrant> sopTplGrants) {
this.sopTplGrants = sopTplGrants;
}
public SopTplGrant getSopTplGrant() {
return sopTplGrant;
}
public void setSopTplGrant(SopTplGrant sopTplGrant) {
this.sopTplGrant = sopTplGrant;
}
}
\ No newline at end of file
package cn.com.glsx.process.modules.model;
import cn.com.glsx.process.modules.entity.SopTplGrant;
import cn.com.glsx.process.modules.entity.SopTplLink;
import cn.com.glsx.process.modules.entity.SopTplNode;
import lombok.Data;
......@@ -69,6 +70,11 @@ public class SopTplDTO {
*/
private List<SopTplLink> links;
/**
* 下发的门店列表(授权)
*/
private List<SopTplGrant> sopTplGrants;
public String getTplId() {
return tplId;
}
......@@ -172,4 +178,12 @@ public class SopTplDTO {
public void setLinks(List<SopTplLink> links) {
this.links = links;
}
public List<SopTplGrant> getSopTplGrants() {
return sopTplGrants;
}
public void setSopTplGrants(List<SopTplGrant> sopTplGrants) {
this.sopTplGrants = sopTplGrants;
}
}
......@@ -102,25 +102,25 @@
<artifactId>rest-admin-redis</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-client</artifactId>
<version>2.6.11</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.14</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-client</artifactId>
<version>2.6.11</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.14</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
......
package cn.com.glsx.process.modules.controller;
import java.util.Map;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.github.pagehelper.PageInfo;
import com.glsx.plat.core.annotation.ResponseResultBody;
import com.glsx.plat.core.web.Result;
import cn.com.glsx.process.modules.BaseController;
import cn.com.glsx.process.modules.entity.SopInst;
import cn.com.glsx.process.modules.model.SopInstDTO;
import cn.com.glsx.process.modules.model.SopInstSearch;
import cn.com.glsx.process.modules.service.SopInstService;
import com.github.pagehelper.PageInfo;
import com.glsx.plat.core.annotation.ResponseResultBody;
import com.glsx.plat.core.web.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.Map;
@Slf4j
@Tag(name = "SOP门店模板实例开放接口")
......@@ -35,7 +27,13 @@ public class SopInstController extends BaseController {
@Resource
private SopInstService sopInstService;
@Operation(summary = "查询SOP门店模板实例分页列表", description = "查询SOP门店模板实例分页列表")
@Operation(summary = "查询SOP模板实例分页列表", description = "查询SOP模板实例分页列表")
@GetMapping
public PageInfo<SopInstDTO> page(SopInstSearch search) {
return sopInstService.page(search);
}
@Operation(summary = "查询门店下SOP模板实例分页列表(门店下)", description = "查询门店下SOP模板实例分页列表(门店下)")
@GetMapping("/byGroupId")
public PageInfo<SopInst> selectByGroupId(@Validated SopInstSearch search) {
return sopInstService.selectByGroupId(search);
......@@ -59,4 +57,11 @@ public class SopInstController extends BaseController {
return sopInstService.updateInstStatus(instId, status);
}
@Operation(summary = "SOP模板批量下发门店", description = "SOP模板批量下发门店")
@PostMapping
public String add(@RequestBody SopInstDTO sopInstDTO) {
sopInstService.add(sopInstDTO);
return "success";
}
}
......@@ -24,4 +24,11 @@ public interface SopTplConverter {
@Mapping(source = "tplRemark", target = "instRemark"),
@Mapping(source = "tplParamDef", target = "instParam")})
SopInst do2inst(SopTpl sopTpl);
@Mappings({
@Mapping(source = "tplName", target = "instName"),
@Mapping(source = "tplCron", target = "instCron"),
@Mapping(source = "tplRemark", target = "instRemark"),
@Mapping(source = "tplParamDef", target = "instParam")})
SopInst dto2inst(SopTplDTO sopTplDTO);
}
......@@ -14,6 +14,7 @@ public interface SopTplNodeConverter {
SopTplNodeConverter INSTANCE = Mappers.getMapper(SopTplNodeConverter.class);
@Mappings({
@Mapping(source = "nodeAsync", target = "nodeAsync"),
@Mapping(source = "nodeParamDef", target = "nodeParam"),
@Mapping(source = "nodeContentDef", target = "nodeContent")})
SopInstNode tpl2inst(SopTplNode node);
......
package cn.com.glsx.process.modules.service;
import java.util.List;
import java.util.Map;
import cn.com.glsx.process.modules.converter.SopInstConverter;
import cn.com.glsx.process.modules.converter.SopTplConverter;
import cn.com.glsx.process.modules.converter.SopTplLinKConverter;
import cn.com.glsx.process.modules.converter.SopTplNodeConverter;
import cn.com.glsx.process.modules.entity.*;
import cn.com.glsx.process.modules.mapper.*;
import cn.com.glsx.process.modules.model.SopInstDTO;
import cn.com.glsx.process.modules.model.SopInstSearch;
import cn.com.glsx.process.modules.model.SopTplDTO;
import cn.com.glsx.process.modules.model.enums.SopInstStatusEnum;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.glsx.plat.core.web.Result;
import com.glsx.plat.exception.ResultException;
import com.glsx.plat.exception.SystemMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.glsx.plat.core.web.Result;
import cn.com.glsx.process.modules.converter.SopInstConverter;
import cn.com.glsx.process.modules.entity.SopInst;
import cn.com.glsx.process.modules.entity.SopInstLink;
import cn.com.glsx.process.modules.entity.SopInstNode;
import cn.com.glsx.process.modules.mapper.SopInstLinkMapper;
import cn.com.glsx.process.modules.mapper.SopInstMapper;
import cn.com.glsx.process.modules.mapper.SopInstNodeMapper;
import cn.com.glsx.process.modules.model.SopInstDTO;
import cn.com.glsx.process.modules.model.SopInstSearch;
import cn.com.glsx.process.modules.model.enums.SopInstStatusEnum;
import java.util.*;
import java.util.stream.Collectors;
@Service
public class SopInstService {
......@@ -35,6 +35,20 @@ public class SopInstService {
@Autowired
private SopInstNodeMapper sopInstNodeMapper;
@Autowired
private SopTplMapper sopTplMapper;
@Autowired
private SopTplNodeMapper sopTplNodeMapper;
@Autowired
private SopTplLinkMapper sopTplLinkMapper;
@Autowired
private SopTplGrantMapper sopTplGrantMapper;
/**
* 根据id查询
*
......@@ -198,4 +212,99 @@ public class SopInstService {
sopInstMapper.updateInstStatus(instId, status);
return result;
}
/**
* 查询模板实例分页列表
*
* @param search
* @return
*/
public PageInfo<SopInstDTO> page(SopInstSearch search) {
PageHelper.startPage(search.getPageNumber(), search.getPageSize());
List<SopInstDTO> list = sopInstMapper.page(search);
return new PageInfo<>(list);
}
/**
* 模板批量下发门店
*
* @param sopInstDTO
*/
@Transactional
public void add(SopInstDTO sopInstDTO) {
String tplId = sopInstDTO.getTplId();
SopTplDTO sopTplDTO = sopTplMapper.getById(tplId);
Assert.state(sopTplDTO != null, "模板不存在!");
SopTplNode nodeQuery = new SopTplNode();
nodeQuery.setTplId(tplId);
List<SopTplNode> nodes = sopTplNodeMapper.select(nodeQuery);
SopTplLink linkQuery = new SopTplLink();
linkQuery.setTplId(tplId);
List<SopTplLink> links = sopTplLinkMapper.select(linkQuery);
List<SopTplGrant> sopTplGrants = sopInstDTO.getSopTplGrants();
if (CollectionUtils.isEmpty(sopTplGrants)) {
throw ResultException.create(SystemMessage.ARGS_ERROR.getCode(), "请选择门店");
}
List<String> groupIds = sopTplGrants.stream().map(sopTplGrant -> sopTplGrant.getGroupId()).collect(Collectors.toList());
List<SopTplGrant> grants = sopTplGrantMapper.selectByTplIdAndGroupIds(tplId, groupIds);
if (!CollectionUtils.isEmpty(grants)) {
throw ResultException.create(SystemMessage.ARGS_ERROR.getCode(), String.format("%s已存在该旅程,请确认后重新操作", grants.get(0).getGroupName()));
}
//新增派发门店记录
Date date = new Date();
sopTplGrants.forEach(sopTplGrant -> {
sopTplGrant.setTplId(tplId);
sopTplGrant.setGrantStatus(SopTplGrant.GRANT_STATUS_NORMAL);
sopTplGrant.setCreateTime(date);
sopTplGrant.setUpdateTime(date);
});
sopTplGrantMapper.insertList(sopTplGrants);
List<SopInstNode> nodesCustom = sopInstDTO.getNodes();
HashMap<Integer, SopInstNode> customNodesMap = new HashMap<>();
nodesCustom.forEach(sopInstNode -> customNodesMap.put(sopInstNode.getNodeId(), sopInstNode));
SopTplConverter sopTplConverter = SopTplConverter.INSTANCE;
SopTplLinKConverter sopTplLinKConverter = SopTplLinKConverter.INSTANCE;
SopTplNodeConverter sopTplNodeConverter = SopTplNodeConverter.INSTANCE;
for (SopTplGrant sopTplGrant : sopTplGrants) {
Integer grantId = sopTplGrant.getGrantId();
//克隆模板内容
SopInst sopInst = sopTplConverter.dto2inst(sopTplDTO);
sopInst.setInstId(tplId + grantId);
sopInst.setGrantId(grantId);
sopInst.setCreateTime(date);
sopInst.setUpdateTime(date);
sopInst.setInstStatus(SopInstStatusEnum.UNUSED.getValue());
sopInstMapper.insert(sopInst);
//克隆连接
String instId = sopInst.getInstId();
List<SopInstLink> sopInstLinks = new ArrayList<>();
links.forEach(sopTplLink -> {
SopInstLink sopInstLink = sopTplLinKConverter.tpl2inst(sopTplLink);
sopInstLink.setInstId(instId);
sopInstLinks.add(sopInstLink);
});
sopInstLinkMapper.insertList(sopInstLinks);
//克隆节点
List<SopInstNode> sopInstNodes = new ArrayList<>();
nodes.forEach(sopTplNode -> {
SopInstNode sopInstNode = sopTplNodeConverter.tpl2inst(sopTplNode);
sopInstNode.setInstId(instId);
sopInstNode.setNodeStatus(SopInstNode.NODE_STATUS_NORMAL);
SopInstNode sopInstNodeTemp = customNodesMap.get(sopInstNode.getNodeId());
sopInstNode.setNodeSkip(!Objects.isNull(sopInstNodeTemp)?sopInstNodeTemp.getNodeSkip():SopInstNode.NODE_SKIP_FALSE);
sopInstNodes.add(sopInstNode);
});
sopInstNodeMapper.insertList(sopInstNodes);
}
}
}
......@@ -18,6 +18,9 @@
<result column="expire_time" jdbcType="TIMESTAMP" property="expireTime" />
<result column="batch_no" jdbcType="VARCHAR" property="batchNo" />
</resultMap>
<resultMap id="BaseResultDTOMap" extends="BaseResultMap" type="cn.com.glsx.process.modules.model.SopInstDTO">
<association column="grant_id" property="sopTplGrant" select="cn.com.glsx.process.modules.mapper.SopTplGrantMapper.selectByPrimaryKey" />
</resultMap>
<sql id="Base_Column_List">
<!--
WARNING - @mbg.generated
......@@ -58,4 +61,19 @@
<include refid="Base_Column_List"/>
FROM sop_inst WHERE JSON_CONTAINS(inst_param, CAST(#{customData,typeHandler=cn.com.glsx.process.modules.handler.JsonTypeHandler} AS JSON),'$.customData');
</select>
<select id="page" resultMap="BaseResultDTOMap">
SELECT
<include refid="Base_Column_List"/>
FROM sop_inst
<where>
<if test="instId != null and instId != ''">
and inst_id = #{instId}
</if>
<if test="instName != null and instName != ''">
and inst_name like CONCAT('%',#{instName},'%')
</if>
</where>
ORDER BY create_time DESC
</select>
</mapper>
\ No newline at end of file
......@@ -35,7 +35,7 @@
SELECT COUNT(0) FROM sop_tpl_grant WHERE tpl_id = #{tplId}
</select>
<select id="selectByTplIdAndGroupIds" resultType="cn.com.glsx.process.modules.entity.SopTplGrant">
<select id="selectByTplIdAndGroupIds" resultMap="BaseResultMap">
SELECT
<include refid="Base_Column_List"/>
FROM sop_tpl_grant
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!