排产规则

parent 9284edf3
package com.aps.config;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
@Configuration
public class JacksonConfig {
public static final String FRONTEND_DATE_TIME_PATTERN = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
public static final DateTimeFormatter FRONTEND_DATE_TIME_FORMATTER =
DateTimeFormatter.ofPattern(FRONTEND_DATE_TIME_PATTERN);
@Bean
public Jackson2ObjectMapperBuilderCustomizer jackson2ObjectMapperBuilderCustomizer() {
return builder -> builder
.featuresToDisable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
.serializerByType(LocalDateTime.class, new LocalDateTimeSerializer(FRONTEND_DATE_TIME_FORMATTER));
}
}
package com.aps.controller;
import com.aps.common.util.R;
import com.aps.service.UserStrategyRuleService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.ExampleObject;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping("/userStrategyRule")
@Tag(name = "用户策略规则", description = "用户策略规则")
public class UserStrategyRuleController {
@Autowired
private UserStrategyRuleService userStrategyRuleService;
@PostMapping("/effective")
@Operation(
summary = "获取策略详情",
requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(
description = "根据下拉选项 id 获取策略详情,也兼容 source + ruleId。",
required = true,
content = @Content(
mediaType = "application/json",
examples = {
@ExampleObject(
name = "选择全局策略",
value = "{\n" +
" \"userId\": 10001,\n" +
" \"id\": \"GLOBAL:1\"\n" +
"}"
),
@ExampleObject(
name = "选择用户策略",
value = "{\n" +
" \"userId\": 10001,\n" +
" \"id\": \"USER:f3d7e0f0-3b8a-4d0c-8f2a-7d4e64f4c901\"\n" +
"}"
)
}
)
),
responses = @ApiResponse(
responseCode = "200",
description = "查询成功",
content = @Content(
mediaType = "application/json",
examples = @ExampleObject(
name = "策略详情响应",
value = "{\n" +
" \"code\": 200,\n" +
" \"msg\": \"success\",\n" +
" \"data\": {\n" +
" \"source\": \"USER\",\n" +
" \"userRuleId\": \"f3d7e0f0-3b8a-4d0c-8f2a-7d4e64f4c901\",\n" +
" \"baseRuleId\": 1,\n" +
" \"sceneId\": null,\n" +
" \"name\": \"交期优先-用户规则\",\n" +
" \"forwardScheduling\": [\n" +
" {\n" +
" \"name\": \"deliveryDate\",\n" +
" \"title\": \"交期优先\",\n" +
" \"content\": \"按订单交期排序\",\n" +
" \"amplitude\": 80,\n" +
" \"value\": true,\n" +
" \"sort\": 1\n" +
" }\n" +
" ],\n" +
" \"kpiConfig\": [\n" +
" {\n" +
" \"name\": \"makespan\",\n" +
" \"title\": \"最早完工时间\",\n" +
" \"enabled\": true,\n" +
" \"isMinimize\": true,\n" +
" \"level\": 1,\n" +
" \"weight\": 0.4,\n" +
" \"val\": 0,\n" +
" \"sort\": 1\n" +
" }\n" +
" ]\n" +
" },\n" +
" \"timestamp\": \"2026-04-30T10:00:00.000Z\"\n" +
"}"
)
)
)
)
public R<Map<String, Object>> effective(@RequestBody Map<String, Object> params) {
return R.ok(userStrategyRuleService.getEffectiveRule(params));
}
@PostMapping("/save")
@Operation(
summary = "保存用户策略",
requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(
description = "保存当前用户策略。传下拉选项 id;如果是 GLOBAL:id,后端会创建/更新该用户对应全局策略的用户规则。",
required = true,
content = @Content(
mediaType = "application/json",
examples = {
@ExampleObject(
name = "从全局策略保存用户规则",
value = "{\n" +
" \"userId\": 10001,\n" +
" \"id\": \"GLOBAL:1\",\n" +
" \"forwardScheduling\": [\n" +
" {\n" +
" \"name\": \"deliveryDate\",\n" +
" \"title\": \"交期优先\",\n" +
" \"content\": \"按订单交期排序\",\n" +
" \"amplitude\": 80,\n" +
" \"value\": true,\n" +
" \"sort\": 1\n" +
" }\n" +
" ],\n" +
" \"kpiConfig\": [\n" +
" {\n" +
" \"name\": \"makespan\",\n" +
" \"title\": \"最早完工时间\",\n" +
" \"enabled\": true,\n" +
" \"isMinimize\": true,\n" +
" \"level\": 1,\n" +
" \"weight\": 0.4,\n" +
" \"val\": 0,\n" +
" \"sort\": 1\n" +
" }\n" +
" ]\n" +
"}"
),
@ExampleObject(
name = "更新已有用户规则",
value = "{\n" +
" \"userId\": 10001,\n" +
" \"id\": \"USER:f3d7e0f0-3b8a-4d0c-8f2a-7d4e64f4c901\",\n" +
" \"forwardScheduling\": [],\n" +
" \"kpiConfig\": []\n" +
"}"
)
}
)
)
)
public R<Map<String, Object>> save(@RequestBody Map<String, Object> params) {
return R.ok(userStrategyRuleService.saveUserRule(params));
}
@PostMapping("/reset")
@Operation(
summary = "恢复全局策略",
requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(
description = "删除用户自定义策略,恢复使用全局策略。",
required = true,
content = @Content(
mediaType = "application/json",
examples = {
@ExampleObject(
name = "按全局策略恢复",
value = "{\n" +
" \"userId\": 10001,\n" +
" \"id\": \"GLOBAL:1\"\n" +
"}"
),
@ExampleObject(
name = "按用户策略恢复",
value = "{\n" +
" \"userId\": 10001,\n" +
" \"id\": \"USER:f3d7e0f0-3b8a-4d0c-8f2a-7d4e64f4c901\"\n" +
"}"
)
}
)
)
)
public R<Boolean> reset(@RequestBody Map<String, Object> params) {
return R.ok(userStrategyRuleService.resetUserRule(params));
}
@GetMapping("/globalList")
@Operation(
summary = "获取策略下拉选项",
description = "按全局策略生成下拉。全局有几条就返回几条;当前用户已保存过的全局策略返回 USER,否则返回 GLOBAL。",
responses = @ApiResponse(
responseCode = "200",
description = "查询成功",
content = @Content(
mediaType = "application/json",
examples = @ExampleObject(
name = "四个策略下拉示例",
value = "{\n" +
" \"code\": 200,\n" +
" \"msg\": \"success\",\n" +
" \"data\": [\n" +
" {\n" +
" \"id\": \"USER:f3d7e0f0-3b8a-4d0c-8f2a-7d4e64f4c901\",\n" +
" \"source\": \"USER\",\n" +
" \"ruleId\": \"f3d7e0f0-3b8a-4d0c-8f2a-7d4e64f4c901\",\n" +
" \"name\": \"交期优先-用户规则\",\n" +
" \"globalRuleId\": 1,\n" +
" \"globalRuleName\": \"交期优先\",\n" +
" \"forwardScheduling\": [\n" +
" {\n" +
" \"name\": \"deliveryDate\",\n" +
" \"title\": \"交期优先\",\n" +
" \"content\": \"按订单交期排序\",\n" +
" \"amplitude\": 80,\n" +
" \"value\": true,\n" +
" \"sort\": 1\n" +
" }\n" +
" ],\n" +
" \"isDefault\": 1\n" +
" },\n" +
" {\n" +
" \"id\": \"GLOBAL:2\",\n" +
" \"source\": \"GLOBAL\",\n" +
" \"ruleId\": 2,\n" +
" \"name\": \"齐套优先\",\n" +
" \"globalRuleId\": 2,\n" +
" \"globalRuleName\": \"齐套优先\",\n" +
" \"forwardScheduling\": []\n" +
" },\n" +
" {\n" +
" \"id\": \"GLOBAL:3\",\n" +
" \"source\": \"GLOBAL\",\n" +
" \"ruleId\": 3,\n" +
" \"name\": \"换型最少\",\n" +
" \"globalRuleId\": 3,\n" +
" \"globalRuleName\": \"换型最少\",\n" +
" \"forwardScheduling\": []\n" +
" },\n" +
" {\n" +
" \"id\": \"GLOBAL:4\",\n" +
" \"source\": \"GLOBAL\",\n" +
" \"ruleId\": 4,\n" +
" \"name\": \"设备负载均衡\",\n" +
" \"globalRuleId\": 4,\n" +
" \"globalRuleName\": \"设备负载均衡\",\n" +
" \"forwardScheduling\": []\n" +
" }\n" +
" ],\n" +
" \"timestamp\": \"2026-04-30T10:00:00.000Z\"\n" +
"}"
)
)
)
)
public R<List<Map<String, Object>>> globalList(
@Parameter(description = "当前用户ID")
@RequestParam(value = "userId", required = false) Long userId) {
return R.ok(userStrategyRuleService.getStrategyOptions(userId));
}
}
package com.aps.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Getter;
import lombok.Setter;
import java.io.Serializable;
import java.time.LocalDateTime;
@Getter
@Setter
@TableName("USER_STRATEGY_RULE")
public class UserStrategyRule implements Serializable {
private static final long serialVersionUID = 1L;
private String id;
private LocalDateTime creationtime;
private Long creatoruserid;
private LocalDateTime lastmodificationtime;
private Long lastmodifieruserid;
private Long isdeleted;
private LocalDateTime deletiontime;
private Long deleteruserid;
private Long userid;
private Long baseRuleId;
private String sceneId;
private String name;
private String forwardScheduling;
private String kpiConfig;
private Long isDefault;
private String sourceType;
}
package com.aps.mapper;
import com.aps.entity.UserStrategyRule;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
public interface UserStrategyRuleMapper extends BaseMapper<UserStrategyRule> {
}
package com.aps.service;
import com.aps.entity.UserStrategyRule;
import com.baomidou.mybatisplus.extension.service.IService;
import java.util.List;
import java.util.Map;
import com.aps.entity.StrategyScheduling;
public interface UserStrategyRuleService extends IService<UserStrategyRule> {
Map<String, Object> getEffectiveRule(Map<String, Object> params);
Map<String, Object> saveUserRule(Map<String, Object> params);
boolean resetUserRule(Map<String, Object> params);
List<Map<String, Object>> getGlobalRules();
List<Map<String, Object>> getStrategyOptions(Long userId);
List<StrategyScheduling> getEffectiveForwardScheduling(Long userId, Long baseRuleId, String sceneId);
}
package com.aps.service.impl;
import com.aps.common.util.EnhancedJsonConversionUtil;
import com.aps.entity.StrategyRule;
import com.aps.entity.StrategyScheduling;
import com.aps.entity.UserStrategyRule;
import com.aps.mapper.UserStrategyRuleMapper;
import com.aps.service.StrategyRuleService;
import com.aps.service.UserStrategyRuleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
@Service
public class UserStrategyRuleServiceImpl extends ServiceImpl<UserStrategyRuleMapper, UserStrategyRule> implements UserStrategyRuleService {
@Autowired
private StrategyRuleService strategyRuleService;
private final ObjectMapper objectMapper = new ObjectMapper()
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
@Override
public Map<String, Object> getEffectiveRule(Map<String, Object> params) {
Long userId = getLong(params, "userId");
String source = getSource(params);
String ruleId = getRuleId(params);
String userRuleId = "USER".equalsIgnoreCase(source) ? ruleId : getString(params, "userRuleId");
Long baseRuleId = "GLOBAL".equalsIgnoreCase(source) ? toLong(ruleId) : getLong(params, "baseRuleId");
UserStrategyRule selectedUserRule = findUserRuleById(userRuleId, userId);
if (selectedUserRule != null) {
return buildUserResult(selectedUserRule);
}
UserStrategyRule userRule = findUserRule(userId, baseRuleId);
if (userRule != null) {
return buildUserResult(userRule);
}
StrategyRule globalRule = findGlobalRule(baseRuleId);
return buildGlobalResult(globalRule);
}
@Override
public Map<String, Object> saveUserRule(Map<String, Object> params) {
Long userId = getLong(params, "userId");
if (userId == null) {
throw new RuntimeException("userId不能为空");
}
String source = getSource(params);
String ruleId = getRuleId(params);
String userRuleId = "USER".equalsIgnoreCase(source) ? ruleId : getString(params, "userRuleId");
Long baseRuleId = "GLOBAL".equalsIgnoreCase(source) ? toLong(ruleId) : getLong(params, "baseRuleId");
UserStrategyRule userRule = null;
if (StringUtils.hasText(userRuleId)) {
userRule = this.getById(userRuleId);
if (userRule == null || !userId.equals(userRule.getUserid()) || isDeleted(userRule.getIsdeleted())) {
throw new RuntimeException("用户策略不存在");
}
}
if (userRule == null) {
userRule = findUserRule(userId, baseRuleId);
}
if (baseRuleId == null && userRule != null) {
baseRuleId = userRule.getBaseRuleId();
}
StrategyRule globalRule = findGlobalRule(baseRuleId);
if (baseRuleId == null && globalRule != null) {
baseRuleId = globalRule.getId();
}
boolean newUserRule = userRule == null;
LocalDateTime now = LocalDateTime.now();
if (userRule == null) {
userRule = new UserStrategyRule();
userRule.setId(UUID.randomUUID().toString());
userRule.setCreationtime(now);
userRule.setCreatoruserid(userId);
userRule.setIsdeleted(0L);
userRule.setUserid(userId);
userRule.setSourceType("USER");
}
userRule.setLastmodificationtime(now);
userRule.setLastmodifieruserid(userId);
userRule.setBaseRuleId(baseRuleId);
userRule.setSceneId(null);
userRule.setName(resolveName(params, globalRule, newUserRule));
userRule.setForwardScheduling(toJson(params.get("forwardScheduling"), globalRule == null ? null : globalRule.getForwardScheduling()));
userRule.setKpiConfig(toJson(params.get("kpiConfig"), null));
userRule.setIsDefault(getLong(params, "isDefault") == null ? 0L : getLong(params, "isDefault"));
this.saveOrUpdate(userRule);
return buildUserResult(userRule);
}
@Override
public boolean resetUserRule(Map<String, Object> params) {
Long userId = getLong(params, "userId");
String source = getSource(params);
String ruleId = getRuleId(params);
String userRuleId = "USER".equalsIgnoreCase(source) ? ruleId : getString(params, "userRuleId");
Long baseRuleId = "GLOBAL".equalsIgnoreCase(source) ? toLong(ruleId) : getLong(params, "baseRuleId");
UserStrategyRule userRule = null;
if (StringUtils.hasText(userRuleId)) {
userRule = this.getById(userRuleId);
if (userRule == null || userId == null || !userId.equals(userRule.getUserid())) {
return false;
}
return deleteUserRule(userRule, userId, LocalDateTime.now());
}
if (userId == null) {
return false;
}
List<UserStrategyRule> rules = findUserRules(userId, baseRuleId);
if (rules == null || rules.isEmpty()) {
return false;
}
LocalDateTime now = LocalDateTime.now();
boolean success = true;
for (UserStrategyRule rule : rules) {
success = deleteUserRule(rule, userId, now) && success;
}
return success;
}
@Override
public List<Map<String, Object>> getGlobalRules() {
return getGlobalRuleOptions();
}
@Override
public List<Map<String, Object>> getStrategyOptions(Long userId) {
return getMergedStrategyOptions(userId);
}
private List<Map<String, Object>> getMergedStrategyOptions(Long userId) {
List<StrategyRule> globalRules = findGlobalRules();
Map<Long, UserStrategyRule> userRuleMap = findUserRuleMapByBaseRuleId(userId);
List<Map<String, Object>> result = new ArrayList<>();
for (StrategyRule globalRule : globalRules) {
UserStrategyRule userRule = userRuleMap.get(globalRule.getId());
result.add(userRule == null ? buildGlobalOption(globalRule) : buildUserOption(userRule, globalRule));
}
return result;
}
private List<Map<String, Object>> getGlobalRuleOptions() {
List<StrategyRule> rules = findGlobalRules();
List<Map<String, Object>> result = new ArrayList<>();
for (StrategyRule rule : rules) {
result.add(buildGlobalOption(rule));
}
return result;
}
private Map<Long, UserStrategyRule> findUserRuleMapByBaseRuleId(Long userId) {
List<UserStrategyRule> rules = findUserRules(userId, null);
Map<Long, UserStrategyRule> result = new HashMap<>();
if (rules == null || rules.isEmpty()) {
return result;
}
rules.sort(Comparator
.comparing((UserStrategyRule rule) -> rule.getIsDefault() == null ? 0L : rule.getIsDefault(), Comparator.reverseOrder())
.thenComparing(rule -> rule.getLastmodificationtime() == null ? LocalDateTime.MIN : rule.getLastmodificationtime(), Comparator.reverseOrder()));
for (UserStrategyRule rule : rules) {
if (rule.getBaseRuleId() != null && !result.containsKey(rule.getBaseRuleId())) {
result.put(rule.getBaseRuleId(), rule);
}
}
return result;
}
private List<StrategyRule> findGlobalRules() {
return strategyRuleService.lambdaQuery()
.eq(StrategyRule::getIsDeleted, 0)
.list();
}
private Map<String, Object> buildGlobalOption(StrategyRule rule) {
Map<String, Object> item = new HashMap<>();
item.put("id", "GLOBAL:" + rule.getId());
item.put("source", "GLOBAL");
item.put("ruleId", rule.getId());
item.put("name", rule.getName());
item.put("globalRuleId", rule.getId());
item.put("globalRuleName", rule.getName());
item.put("forwardScheduling", parseForwardScheduling(rule.getForwardScheduling()));
return item;
}
private Map<String, Object> buildUserOption(UserStrategyRule rule, StrategyRule globalRule) {
Map<String, Object> item = new HashMap<>();
item.put("id", "USER:" + rule.getId());
item.put("source", "USER");
item.put("ruleId", rule.getId());
item.put("name", rule.getName());
item.put("isDefault", rule.getIsDefault());
item.put("globalRuleId", globalRule.getId());
item.put("globalRuleName", globalRule.getName());
item.put("forwardScheduling", parseForwardScheduling(rule.getForwardScheduling()));
return item;
}
@Override
public List<StrategyScheduling> getEffectiveForwardScheduling(Long userId, Long baseRuleId, String sceneId) {
UserStrategyRule userRule = findUserRule(userId, baseRuleId);
if (userRule != null) {
return parseForwardScheduling(userRule.getForwardScheduling());
}
StrategyRule globalRule = findGlobalRule(baseRuleId);
return globalRule == null ? new ArrayList<StrategyScheduling>() : parseForwardScheduling(globalRule.getForwardScheduling());
}
private UserStrategyRule findUserRule(Long userId, Long baseRuleId) {
List<UserStrategyRule> rules = findUserRules(userId, baseRuleId);
if (rules == null || rules.isEmpty()) {
return null;
}
rules.sort(Comparator
.comparing((UserStrategyRule rule) -> rule.getIsDefault() == null ? 0L : rule.getIsDefault(), Comparator.reverseOrder())
.thenComparing(rule -> rule.getLastmodificationtime() == null ? LocalDateTime.MIN : rule.getLastmodificationtime(), Comparator.reverseOrder()));
return rules.get(0);
}
private UserStrategyRule findUserRuleById(String userRuleId, Long userId) {
if (!StringUtils.hasText(userRuleId) || userId == null) {
return null;
}
UserStrategyRule rule = this.getById(userRuleId);
if (rule == null || !userId.equals(rule.getUserid()) || isDeleted(rule.getIsdeleted())) {
return null;
}
return rule;
}
private List<UserStrategyRule> findUserRules(Long userId, Long baseRuleId) {
if (userId == null) {
return null;
}
return this.lambdaQuery()
.eq(UserStrategyRule::getUserid, userId)
.eq(UserStrategyRule::getIsdeleted, 0)
.eq(baseRuleId != null, UserStrategyRule::getBaseRuleId, baseRuleId)
.list();
}
private StrategyRule findGlobalRule(Long baseRuleId) {
if (baseRuleId != null) {
StrategyRule rule = strategyRuleService.getById(baseRuleId);
if (rule != null && !isDeleted(rule.getIsDeleted())) {
return rule;
}
}
List<StrategyRule> rules = strategyRuleService.lambdaQuery()
.eq(StrategyRule::getIsDeleted, 0)
.list();
return rules == null || rules.isEmpty() ? null : rules.get(0);
}
private Map<String, Object> buildUserResult(UserStrategyRule rule) {
Map<String, Object> result = new HashMap<>();
result.put("source", "USER");
result.put("userRuleId", rule.getId());
result.put("baseRuleId", rule.getBaseRuleId());
result.put("sceneId", null);
result.put("name", rule.getName());
result.put("forwardScheduling", parseForwardScheduling(rule.getForwardScheduling()));
result.put("kpiConfig", parseJson(rule.getKpiConfig()));
return result;
}
private Map<String, Object> buildGlobalResult(StrategyRule rule) {
Map<String, Object> result = new HashMap<>();
result.put("source", "GLOBAL");
result.put("userRuleId", null);
result.put("baseRuleId", rule == null ? null : rule.getId());
result.put("sceneId", null);
result.put("name", rule == null ? null : rule.getName());
result.put("forwardScheduling", rule == null ? new ArrayList<StrategyScheduling>() : parseForwardScheduling(rule.getForwardScheduling()));
result.put("kpiConfig", new ArrayList<>());
return result;
}
private boolean deleteUserRule(UserStrategyRule userRule, Long userId, LocalDateTime now) {
userRule.setIsdeleted(1L);
userRule.setDeletiontime(now);
userRule.setDeleteruserid(userId);
userRule.setLastmodificationtime(now);
userRule.setLastmodifieruserid(userId);
return this.updateById(userRule);
}
private List<StrategyScheduling> parseForwardScheduling(String json) {
return EnhancedJsonConversionUtil.convertJsonToEntities(json, null, StrategyScheduling.class);
}
private Object parseJson(String json) {
if (!StringUtils.hasText(json)) {
return new ArrayList<>();
}
try {
return objectMapper.readValue(json, Object.class);
} catch (Exception e) {
return new ArrayList<>();
}
}
private String toJson(Object value, String defaultValue) {
if (value == null) {
return defaultValue;
}
if (value instanceof String) {
return (String) value;
}
try {
return objectMapper.writeValueAsString(value);
} catch (Exception e) {
throw new RuntimeException("JSON转换失败", e);
}
}
private String resolveName(Map<String, Object> params, StrategyRule globalRule, boolean newUserRule) {
String name = getString(params, "name");
if (StringUtils.hasText(name)) {
return name;
}
if (globalRule == null) {
return null;
}
return newUserRule ? globalRule.getName() + "-用户规则" : globalRule.getName();
}
private Long getLong(Map<String, Object> params, String key) {
if (params == null || params.get(key) == null || !StringUtils.hasText(String.valueOf(params.get(key)))) {
return null;
}
return toLong(String.valueOf(params.get(key)));
}
private String getString(Map<String, Object> params, String key) {
if (params == null || params.get(key) == null) {
return null;
}
String value = String.valueOf(params.get(key));
return StringUtils.hasText(value) ? value : null;
}
private String getSource(Map<String, Object> params) {
String source = getString(params, "source");
if (StringUtils.hasText(source)) {
return source;
}
String id = getString(params, "id");
int index = id == null ? -1 : id.indexOf(":");
return index > 0 ? id.substring(0, index) : null;
}
private String getRuleId(Map<String, Object> params) {
String ruleId = getString(params, "ruleId");
if (StringUtils.hasText(ruleId)) {
return ruleId;
}
String id = getString(params, "id");
int index = id == null ? -1 : id.indexOf(":");
return index > -1 && index < id.length() - 1 ? id.substring(index + 1) : null;
}
private Long toLong(String value) {
if (!StringUtils.hasText(value)) {
return null;
}
return Long.valueOf(value);
}
private boolean isDeleted(Number value) {
return value != null && value.longValue() != 0L;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.aps.mapper.UserStrategyRuleMapper">
<resultMap id="BaseResultMap" type="com.aps.entity.UserStrategyRule">
<id column="ID" property="id" />
<result column="CREATIONTIME" property="creationtime" />
<result column="CREATORUSERID" property="creatoruserid" />
<result column="LASTMODIFICATIONTIME" property="lastmodificationtime" />
<result column="LASTMODIFIERUSERID" property="lastmodifieruserid" />
<result column="ISDELETED" property="isdeleted" />
<result column="DELETIONTIME" property="deletiontime" />
<result column="DELETERUSERID" property="deleteruserid" />
<result column="USERID" property="userid" />
<result column="BASE_RULE_ID" property="baseRuleId" />
<result column="SCENE_ID" property="sceneId" />
<result column="NAME" property="name" />
<result column="FORWARD_SCHEDULING" property="forwardScheduling" />
<result column="KPI_CONFIG" property="kpiConfig" />
<result column="IS_DEFAULT" property="isDefault" />
<result column="SOURCE_TYPE" property="sourceType" />
</resultMap>
<sql id="Base_Column_List">
ID, CREATIONTIME, CREATORUSERID, LASTMODIFICATIONTIME, LASTMODIFIERUSERID, ISDELETED,
DELETIONTIME, DELETERUSERID, USERID, BASE_RULE_ID, SCENE_ID, NAME, FORWARD_SCHEDULING,
KPI_CONFIG, IS_DEFAULT, SOURCE_TYPE
</sql>
</mapper>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment