Commit 5d85b064 by 谢海旭

[+]新增2个接口:门店旅程实例参数更新、门店旅程实例状态更新

1 parent 265d7033
......@@ -9,8 +9,9 @@ public class SopInst {
/**
* 启用状态:0,未启用;1,启用;-1,已删除/过期;
*/
public static final byte INST_STATUS_UNUSED = 0;
public static final byte INST_STATUS_DELETED = -1;
public static final byte INST_STATUS_UNUSED = 0;
public static final byte INST_STATUS_NORMAL = 1;
/**
* 实例id,一般sop只允许一个实例。特殊情况可以根据输入参数来区分不同实例。实例名可以用于在cdp保存状态
......
......@@ -7,6 +7,7 @@ import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;
@Mapper
public interface SopInstMapper extends CommonBaseMapper<SopInst> {
......@@ -20,4 +21,20 @@ public interface SopInstMapper extends CommonBaseMapper<SopInst> {
* @return
*/
List<SopInst> selectByInstParam(@Param("instParamJson") String instParamJson);
/**
* 更新门店模板实例默认参数的自定义参数
*
* @param instId
* @param customData
*/
void updateInstParamCustomData(@Param("instId") String instId, @Param("customData") Map<String, Object> customData);
/**
* 更新门店模板实例的状态
*
* @param instId
* @param status
*/
void updateInstStatus(@Param("instId") String instId, @Param("status") Byte status);
}
\ No newline at end of file
......@@ -7,16 +7,15 @@ 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.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.Map;
@Slf4j
@Tag(name = "SOP门店模板实例开放接口")
......@@ -40,4 +39,16 @@ public class SopInstController extends BaseController {
return sopInstService.findById(instId);
}
@Operation(summary = "更新SOP门店模板实例初始参数里的门店自定义参数", description = "更新SOP门店模板实例初始参数里的门店自定义参数")
@PutMapping("/{instId}/instParam/customData")
public Result<String> updateInstParamCustomData(@PathVariable("instId") String instId, @RequestBody Map<String, Object> customData) {
return sopInstService.updateInstParamCustomData(instId, customData);
}
@Operation(summary = "更新SOP门店模板实例状态", description = "更新SOP门店模板实例状态")
@PutMapping("/{instId}/status")
public Result<String> updateInstStatus(@PathVariable("instId") String instId, @RequestBody Byte status) {
return sopInstService.updateInstStatus(instId, status);
}
}
package cn.com.glsx.process.modules.handler;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.TypeHandler;
import java.io.IOException;
import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class JsonTypeHandler implements TypeHandler<Object> {
private static final ObjectMapper objectMapper = new ObjectMapper();
@Override
public void setParameter(PreparedStatement ps, int i, Object parameter, JdbcType jdbcType) throws SQLException {
try {
String json = objectMapper.writeValueAsString(parameter);
ps.setString(i, json);
} catch (IOException e) {
throw new SQLException(e);
}
}
@Override
public Object getResult(ResultSet rs, String columnName) throws SQLException {
String json = rs.getString(columnName);
return parseJson(json);
}
@Override
public Object getResult(ResultSet rs, int columnIndex) throws SQLException {
String json = rs.getString(columnIndex);
return parseJson(json);
}
@Override
public Object getResult(CallableStatement cs, int columnIndex) throws SQLException {
String json = cs.getString(columnIndex);
return parseJson(json);
}
private Object parseJson(String json) throws SQLException {
try {
return objectMapper.readValue(json, Object.class);
} catch (IOException e) {
throw new SQLException(e);
}
}
}
\ No newline at end of file
......@@ -12,8 +12,10 @@ import cn.com.glsx.process.modules.model.SopInstSearch;
import cn.hutool.json.JSONUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.glsx.plat.core.web.Result;
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;
......@@ -132,4 +134,71 @@ public class SopInstService {
sopInstDTO.setLinks(links);
return sopInstDTO;
}
/**
* 更新门店模板实例默认参数的自定义参数
*
* @param instId 实例id
* @param customData 自定义参数
* @return
*/
@Transactional
public Result<String> updateInstParamCustomData(String instId, Map<String, Object> customData) {
Result<String> result = Result.success("success");
SopInst sopInst = sopInstMapper.selectByPrimaryKey(instId);
if (sopInst == null || sopInst.getInstStatus().equals(SopInst.INST_STATUS_DELETED)) {
result = Result.failure();
result.setMessage("模板实例不存在或已关闭");
return result;
}
if (sopInst.getInstStatus().equals(SopInst.INST_STATUS_NORMAL)) {
result = Result.failure();
result.setMessage("模板实例已开启,此参数不允许再变更");
return result;
}
sopInstMapper.updateInstParamCustomData(instId, customData);
return result;
}
/**
* 更新SOP门店模板实例状态
*
* @param instId
* @param status
* @return
*/
@Transactional
public Result<String> updateInstStatus(String instId, Byte status) {
Result<String> result = Result.success("success");
SopInst sopInst = sopInstMapper.selectByPrimaryKey(instId);
if (sopInst == null || sopInst.getInstStatus().equals(SopInst.INST_STATUS_DELETED)) {
result = Result.failure();
result.setMessage("模板实例不存在或已关闭");
return result;
}
Byte instStatus = sopInst.getInstStatus();
switch (instStatus) {
case SopInst.INST_STATUS_UNUSED:
if (!status.equals(SopInst.INST_STATUS_NORMAL)) {
result = Result.failure();
result.setMessage("参数错误,模板实例未开启,只能开启");
return result;
}
break;
case SopInst.INST_STATUS_NORMAL:
if (!status.equals(SopInst.INST_STATUS_DELETED)) {
result = Result.failure();
result.setMessage("参数错误,模板实例已开启,只能关闭");
return result;
}
break;
default:
}
sopInstMapper.updateInstStatus(instId, status);
return result;
}
}
......@@ -26,6 +26,14 @@
inst_param, inst_snapshot, expire_time, batch_no
</sql>
<update id="updateInstParamCustomData">
UPDATE sop_inst SET inst_param=json_set(inst_param,'$.customData',#{customData,typeHandler=cn.com.glsx.process.modules.handler.JsonTypeHandler}) WHERE inst_id = #{instId}
</update>
<update id="updateInstStatus">
UPDATE sop_inst SET inst_status = #{status} WHERE inst_id = #{instId}
</update>
<select id="selectByGroupId" resultType="cn.com.glsx.process.modules.entity.SopInst">
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
......@@ -44,6 +52,6 @@
<select id="selectByInstParam" resultType="cn.com.glsx.process.modules.entity.SopInst">
SELECT
<include refid="Base_Column_List"/>
FROM sop_inst WHERE JSON_CONTAINS(inst_param, #{instParamJson},'$');
FROM sop_inst WHERE JSON_CONTAINS(inst_param, #{instParamJson},'$.customData');
</select>
</mapper>
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!