Commit d5d03470 by zhouhaibao

Merge remote-tracking branch 'origin/v1.0.1' into v1.0.1

2 parents 2f964591 a1dfa159
...@@ -90,6 +90,12 @@ public class SopTplNode { ...@@ -90,6 +90,12 @@ public class SopTplNode {
private Byte nodeSkipable; private Byte nodeSkipable;
/** /**
* '节点是否异步执行。非异步执行则代表对前置节点有依赖
*/
@Column(name = "node_async")
private Byte nodeAsync;
/**
* 获取节点id * 获取节点id
* *
* @return node_id - 节点id * @return node_id - 节点id
...@@ -340,4 +346,12 @@ public class SopTplNode { ...@@ -340,4 +346,12 @@ public class SopTplNode {
public void setNodeSkipable(Byte nodeSkipable) { public void setNodeSkipable(Byte nodeSkipable) {
this.nodeSkipable = nodeSkipable; this.nodeSkipable = nodeSkipable;
} }
public Byte getNodeAsync() {
return nodeAsync;
}
public void setNodeAsync(Byte nodeAsync) {
this.nodeAsync = nodeAsync;
}
} }
\ No newline at end of file \ No newline at end of file
...@@ -3,6 +3,7 @@ package cn.com.glsx.process.modules.mapper; ...@@ -3,6 +3,7 @@ package cn.com.glsx.process.modules.mapper;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import cn.com.glsx.process.modules.model.SopInstDTO;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
...@@ -41,4 +42,12 @@ public interface SopInstMapper extends CommonBaseMapper<SopInst> { ...@@ -41,4 +42,12 @@ public interface SopInstMapper extends CommonBaseMapper<SopInst> {
void updateInstStatus(@Param("instId") String instId, @Param("status") Byte status); void updateInstStatus(@Param("instId") String instId, @Param("status") Byte status);
void updateInstBatchNo(@Param("instId") String instId, @Param("batchNo") String batchNo); void updateInstBatchNo(@Param("instId") String instId, @Param("batchNo") String batchNo);
/**
* 分页查询模板实例列表
*
* @param search
* @return
*/
List<SopInstDTO> page(SopInstSearch search);
} }
\ No newline at end of file \ No newline at end of file
...@@ -2,6 +2,7 @@ package cn.com.glsx.process.modules.model; ...@@ -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.SopInstLink;
import cn.com.glsx.process.modules.entity.SopInstNode; import cn.com.glsx.process.modules.entity.SopInstNode;
import cn.com.glsx.process.modules.entity.SopTplGrant;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
...@@ -14,6 +15,11 @@ public class SopInstDTO { ...@@ -14,6 +15,11 @@ public class SopInstDTO {
private String instId; private String instId;
/** /**
* 模板id
*/
private String tplId;
/**
* 实例分组:当前场景下,分组id就是门店id * 实例分组:当前场景下,分组id就是门店id
*/ */
private Integer grantId; private Integer grantId;
...@@ -49,6 +55,11 @@ public class SopInstDTO { ...@@ -49,6 +55,11 @@ public class SopInstDTO {
private String instParam; private String instParam;
/** /**
* 实例快照,每天任务均从快照取数,修改的数据写回快照,与快照表做冗余;
*/
private String instSnapshot;
/**
* sop有效期,每个sop都设置一个有效期,到期自动停止。 * sop有效期,每个sop都设置一个有效期,到期自动停止。
*/ */
private Date expireTime; private Date expireTime;
...@@ -69,6 +80,15 @@ public class SopInstDTO { ...@@ -69,6 +80,15 @@ public class SopInstDTO {
*/ */
private List<SopInstLink> links; private List<SopInstLink> links;
/**
* 用于下发门店时
*/
private List<SopTplGrant> sopTplGrants;
/**
* 授权关系(关联的门店)
*/
private SopTplGrant sopTplGrant;
/** /**
* 获取实例id,一般sop只允许一个实例。特殊情况可以根据输入参数来区分不同实例。实例名可以用于在cdp保存状态 * 获取实例id,一般sop只允许一个实例。特殊情况可以根据输入参数来区分不同实例。实例名可以用于在cdp保存状态
...@@ -88,6 +108,14 @@ public class SopInstDTO { ...@@ -88,6 +108,14 @@ public class SopInstDTO {
this.instId = instId == null ? null : instId.trim(); this.instId = instId == null ? null : instId.trim();
} }
public String getTplId() {
return tplId;
}
public void setTplId(String tplId) {
this.tplId = tplId;
}
/** /**
* 获取实例分组:当前场景下,分组id就是门店id * 获取实例分组:当前场景下,分组id就是门店id
* *
...@@ -214,6 +242,14 @@ public class SopInstDTO { ...@@ -214,6 +242,14 @@ public class SopInstDTO {
this.instParam = instParam; this.instParam = instParam;
} }
public String getInstSnapshot() {
return instSnapshot;
}
public void setInstSnapshot(String instSnapshot) {
this.instSnapshot = instSnapshot;
}
/** /**
* 获取sop有效期,每个sop都设置一个有效期,到期自动停止。 * 获取sop有效期,每个sop都设置一个有效期,到期自动停止。
* *
...@@ -265,4 +301,20 @@ public class SopInstDTO { ...@@ -265,4 +301,20 @@ public class SopInstDTO {
public void setLinks(List<SopInstLink> links) { public void setLinks(List<SopInstLink> links) {
this.links = 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 \ No newline at end of file
package cn.com.glsx.process.modules.model; 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.SopTplLink;
import cn.com.glsx.process.modules.entity.SopTplNode; import cn.com.glsx.process.modules.entity.SopTplNode;
import lombok.Data; import lombok.Data;
...@@ -69,6 +70,11 @@ public class SopTplDTO { ...@@ -69,6 +70,11 @@ public class SopTplDTO {
*/ */
private List<SopTplLink> links; private List<SopTplLink> links;
/**
* 下发的门店列表(授权)
*/
private List<SopTplGrant> sopTplGrants;
public String getTplId() { public String getTplId() {
return tplId; return tplId;
} }
...@@ -172,4 +178,12 @@ public class SopTplDTO { ...@@ -172,4 +178,12 @@ public class SopTplDTO {
public void setLinks(List<SopTplLink> links) { public void setLinks(List<SopTplLink> links) {
this.links = links; this.links = links;
} }
public List<SopTplGrant> getSopTplGrants() {
return sopTplGrants;
}
public void setSopTplGrants(List<SopTplGrant> sopTplGrants) {
this.sopTplGrants = sopTplGrants;
}
} }
package cn.com.glsx.process.modules.controller; 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.BaseController;
import cn.com.glsx.process.modules.entity.SopInst; import cn.com.glsx.process.modules.entity.SopInst;
import cn.com.glsx.process.modules.model.SopInstDTO; import cn.com.glsx.process.modules.model.SopInstDTO;
import cn.com.glsx.process.modules.model.SopInstSearch; import cn.com.glsx.process.modules.model.SopInstSearch;
import cn.com.glsx.process.modules.service.SopInstService; 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.Operation;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j; 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 @Slf4j
@Tag(name = "SOP门店模板实例开放接口") @Tag(name = "SOP门店模板实例开放接口")
...@@ -35,7 +27,13 @@ public class SopInstController extends BaseController { ...@@ -35,7 +27,13 @@ public class SopInstController extends BaseController {
@Resource @Resource
private SopInstService sopInstService; 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") @GetMapping("/byGroupId")
public PageInfo<SopInst> selectByGroupId(@Validated SopInstSearch search) { public PageInfo<SopInst> selectByGroupId(@Validated SopInstSearch search) {
return sopInstService.selectByGroupId(search); return sopInstService.selectByGroupId(search);
...@@ -59,4 +57,11 @@ public class SopInstController extends BaseController { ...@@ -59,4 +57,11 @@ public class SopInstController extends BaseController {
return sopInstService.updateInstStatus(instId, status); 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 { ...@@ -24,4 +24,11 @@ public interface SopTplConverter {
@Mapping(source = "tplRemark", target = "instRemark"), @Mapping(source = "tplRemark", target = "instRemark"),
@Mapping(source = "tplParamDef", target = "instParam")}) @Mapping(source = "tplParamDef", target = "instParam")})
SopInst do2inst(SopTpl sopTpl); 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 { ...@@ -14,6 +14,7 @@ public interface SopTplNodeConverter {
SopTplNodeConverter INSTANCE = Mappers.getMapper(SopTplNodeConverter.class); SopTplNodeConverter INSTANCE = Mappers.getMapper(SopTplNodeConverter.class);
@Mappings({ @Mappings({
@Mapping(source = "nodeAsync", target = "nodeAsync"),
@Mapping(source = "nodeParamDef", target = "nodeParam"), @Mapping(source = "nodeParamDef", target = "nodeParam"),
@Mapping(source = "nodeContentDef", target = "nodeContent")}) @Mapping(source = "nodeContentDef", target = "nodeContent")})
SopInstNode tpl2inst(SopTplNode node); SopInstNode tpl2inst(SopTplNode node);
......
package cn.com.glsx.process.modules.service; package cn.com.glsx.process.modules.service;
import java.util.List; import cn.com.glsx.process.modules.converter.SopInstConverter;
import java.util.Map; 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.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import com.github.pagehelper.PageHelper; import java.util.*;
import com.github.pagehelper.PageInfo; import java.util.stream.Collectors;
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;
@Service @Service
public class SopInstService { public class SopInstService {
...@@ -35,6 +35,20 @@ public class SopInstService { ...@@ -35,6 +35,20 @@ public class SopInstService {
@Autowired @Autowired
private SopInstNodeMapper sopInstNodeMapper; private SopInstNodeMapper sopInstNodeMapper;
@Autowired
private SopTplMapper sopTplMapper;
@Autowired
private SopTplNodeMapper sopTplNodeMapper;
@Autowired
private SopTplLinkMapper sopTplLinkMapper;
@Autowired
private SopTplGrantMapper sopTplGrantMapper;
/** /**
* 根据id查询 * 根据id查询
* *
...@@ -198,4 +212,99 @@ public class SopInstService { ...@@ -198,4 +212,99 @@ public class SopInstService {
sopInstMapper.updateInstStatus(instId, status); sopInstMapper.updateInstStatus(instId, status);
return result; 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 @@ ...@@ -18,6 +18,9 @@
<result column="expire_time" jdbcType="TIMESTAMP" property="expireTime" /> <result column="expire_time" jdbcType="TIMESTAMP" property="expireTime" />
<result column="batch_no" jdbcType="VARCHAR" property="batchNo" /> <result column="batch_no" jdbcType="VARCHAR" property="batchNo" />
</resultMap> </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"> <sql id="Base_Column_List">
<!-- <!--
WARNING - @mbg.generated WARNING - @mbg.generated
...@@ -38,9 +41,9 @@ ...@@ -38,9 +41,9 @@
UPDATE sop_inst SET batch_no = #{batchNo} WHERE inst_id = #{instId} UPDATE sop_inst SET batch_no = #{batchNo} WHERE inst_id = #{instId}
</update> </update>
<select id="selectByGroupId" resultType="cn.com.glsx.process.modules.entity.SopInst"> <select id="selectByGroupId" resultMap="BaseResultMap">
SELECT si.inst_id, si.grant_id, si.inst_name, si.inst_cron, si.inst_remark, si.create_time, si.update_time, si.inst_status, SELECT si.inst_id, si.grant_id, si.inst_name, si.inst_cron, si.inst_remark, si.create_time, si.update_time, si.inst_status,
si.expire_time, si.batch_no si.inst_param, si.expire_time, si.batch_no
FROM sop_inst AS si FROM sop_inst AS si
INNER JOIN sop_tpl_grant AS stg ON si.grant_id = stg.grant_id INNER JOIN sop_tpl_grant AS stg ON si.grant_id = stg.grant_id
WHERE stg.group_id = #{groupId} WHERE stg.group_id = #{groupId}
...@@ -58,4 +61,19 @@ ...@@ -58,4 +61,19 @@
<include refid="Base_Column_List"/> <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'); FROM sop_inst WHERE JSON_CONTAINS(inst_param, CAST(#{customData,typeHandler=cn.com.glsx.process.modules.handler.JsonTypeHandler} AS JSON),'$.customData');
</select> </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> </mapper>
\ No newline at end of file \ No newline at end of file
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
SELECT COUNT(0) FROM sop_tpl_grant WHERE tpl_id = #{tplId} SELECT COUNT(0) FROM sop_tpl_grant WHERE tpl_id = #{tplId}
</select> </select>
<select id="selectByTplIdAndGroupIds" resultType="cn.com.glsx.process.modules.entity.SopTplGrant"> <select id="selectByTplIdAndGroupIds" resultMap="BaseResultMap">
SELECT SELECT
<include refid="Base_Column_List"/> <include refid="Base_Column_List"/>
FROM sop_tpl_grant 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!