| | |
| | | import com.zy.asrs.service.StationPathPolicyService; |
| | | import com.zy.common.model.NavigateNode; |
| | | import com.zy.common.utils.NavigateUtils; |
| | | import com.zy.common.utils.RedisUtil; |
| | | import com.zy.common.web.BaseController; |
| | | import com.zy.core.enums.RedisKeyType; |
| | | import com.zy.system.entity.Config; |
| | | import com.zy.system.service.ConfigService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | |
| | | @RequestMapping("/basStationPathPolicy") |
| | | public class BasStationPathPolicyController extends BaseController { |
| | | |
| | | private static final String CFG_DEFAULT_PROFILE_CODE = "stationPathDefaultProfileCode"; |
| | | |
| | | @Autowired |
| | | private BasStationPathProfileService basStationPathProfileService; |
| | | @Autowired |
| | | private BasStationPathRuleService basStationPathRuleService; |
| | | @Autowired |
| | | private ConfigService configService; |
| | | @Autowired |
| | | private RedisUtil redisUtil; |
| | | @Autowired |
| | | private StationPathPolicyService stationPathPolicyService; |
| | | @Autowired |
| | |
| | | @RequestMapping("/data/auth") |
| | | @ManagerAuth |
| | | public R data() { |
| | | List<BasStationPathProfile> profileList = basStationPathProfileService.list(new QueryWrapper<BasStationPathProfile>() |
| | | .orderByDesc("is_default") |
| | | .orderByAsc("priority", "id")); |
| | | Map<String, Object> data = new HashMap<>(); |
| | | data.put("profiles", basStationPathProfileService.list(new QueryWrapper<BasStationPathProfile>().orderByAsc("priority", "id"))); |
| | | data.put("profiles", profileList); |
| | | data.put("rules", basStationPathRuleService.list(new QueryWrapper<BasStationPathRule>().orderByAsc("priority", "id"))); |
| | | data.put("scoreMode", "twoStage"); |
| | | data.put("defaultProfileCode", getSystemConfig(CFG_DEFAULT_PROFILE_CODE, "default")); |
| | | data.put("defaultProfileCode", resolveDefaultProfileCode(profileList)); |
| | | data.put("stations", buildStationSummaryList()); |
| | | data.put("levList", basMapService.getLevList()); |
| | | return R.ok(data); |
| | |
| | | public R save(@RequestBody JSONObject payload) { |
| | | JSONArray profiles = payload.getJSONArray("profiles"); |
| | | JSONArray rules = payload.getJSONArray("rules"); |
| | | |
| | | upsertSystemConfig("站点路径默认模板编码", CFG_DEFAULT_PROFILE_CODE, defaultIfBlank(payload.getString("defaultProfileCode"), "default"), "String"); |
| | | |
| | | basStationPathProfileService.remove(new QueryWrapper<>()); |
| | | basStationPathRuleService.remove(new QueryWrapper<>()); |
| | | |
| | | List<BasStationPathProfile> profileList = new ArrayList<>(); |
| | | if (profiles != null) { |
| | |
| | | profile.setProfileName(defaultIfBlank(item.getString("profileName"), item.getString("profileCode"))); |
| | | profile.setPriority(item.getInteger("priority") == null ? 100 : item.getInteger("priority")); |
| | | profile.setStatus(item.getShort("status") == null ? (short) 1 : item.getShort("status")); |
| | | profile.setIsDefault((short) 0); |
| | | profile.setMemo(item.getString("memo")); |
| | | Object configObj = item.get("config"); |
| | | if (configObj != null) { |
| | |
| | | profileList.add(profile); |
| | | } |
| | | } |
| | | if (profileList.isEmpty()) { |
| | | return R.error("至少需要保留一个模板"); |
| | | } |
| | | |
| | | String defaultProfileCode = defaultIfBlank(payload.getString("defaultProfileCode"), profileList.get(0).getProfileCode()); |
| | | BasStationPathProfile defaultProfile = null; |
| | | for (BasStationPathProfile profile : profileList) { |
| | | if (profile != null && defaultProfileCode.equals(profile.getProfileCode())) { |
| | | profile.setIsDefault((short) 1); |
| | | defaultProfile = profile; |
| | | break; |
| | | } |
| | | } |
| | | if (defaultProfile == null) { |
| | | return R.error("默认模板编码没有对应模板"); |
| | | } |
| | | if (!Short.valueOf((short) 1).equals(defaultProfile.getStatus())) { |
| | | return R.error("默认模板必须启用"); |
| | | } |
| | | |
| | | basStationPathProfileService.remove(new QueryWrapper<>()); |
| | | basStationPathRuleService.remove(new QueryWrapper<>()); |
| | | |
| | | if (!profileList.isEmpty()) { |
| | | basStationPathProfileService.saveBatch(profileList); |
| | | } |
| | |
| | | if (!ruleList.isEmpty()) { |
| | | basStationPathRuleService.saveBatch(ruleList); |
| | | } |
| | | |
| | | refreshSystemConfigCache(); |
| | | stationPathPolicyService.evictCache(); |
| | | return R.ok(); |
| | | } |
| | |
| | | return result; |
| | | } |
| | | |
| | | private void upsertSystemConfig(String name, String code, String value, String selectType) { |
| | | String finalValue = value == null ? "" : value.trim(); |
| | | Config config = configService.getOne(new QueryWrapper<Config>().eq("code", code)); |
| | | if (config == null) { |
| | | config = new Config(name, code, finalValue, (short) 1, (short) 1); |
| | | config.setSelectType(selectType); |
| | | configService.save(config); |
| | | } else { |
| | | config.setName(name); |
| | | config.setValue(finalValue); |
| | | config.setType((short) 1); |
| | | config.setStatus((short) 1); |
| | | config.setSelectType(selectType); |
| | | configService.updateById(config); |
| | | private String resolveDefaultProfileCode(List<BasStationPathProfile> profileList) { |
| | | if (profileList == null || profileList.isEmpty()) { |
| | | return "default"; |
| | | } |
| | | } |
| | | |
| | | private void refreshSystemConfigCache() { |
| | | HashMap<String, String> systemConfigMap = new HashMap<>(); |
| | | List<Config> configList = configService.list(new QueryWrapper<>()); |
| | | for (Config config : configList) { |
| | | systemConfigMap.put(config.getCode(), config.getValue()); |
| | | } |
| | | redisUtil.set(RedisKeyType.SYSTEM_CONFIG_MAP.key, systemConfigMap); |
| | | } |
| | | |
| | | private String getSystemConfig(String code, String defaultValue) { |
| | | Object mapObj = redisUtil.get(RedisKeyType.SYSTEM_CONFIG_MAP.key); |
| | | if (mapObj instanceof Map) { |
| | | Object value = ((Map<?, ?>) mapObj).get(code); |
| | | if (value != null) { |
| | | String text = String.valueOf(value).trim(); |
| | | if (!text.isEmpty()) { |
| | | return text; |
| | | } |
| | | for (BasStationPathProfile profile : profileList) { |
| | | if (profile != null |
| | | && Short.valueOf((short) 1).equals(profile.getIsDefault()) |
| | | && !isBlank(profile.getProfileCode())) { |
| | | return profile.getProfileCode(); |
| | | } |
| | | } |
| | | return defaultValue; |
| | | for (BasStationPathProfile profile : profileList) { |
| | | if (profile != null && "default".equals(profile.getProfileCode())) { |
| | | return profile.getProfileCode(); |
| | | } |
| | | } |
| | | for (BasStationPathProfile profile : profileList) { |
| | | if (profile != null && !isBlank(profile.getProfileCode())) { |
| | | return profile.getProfileCode(); |
| | | } |
| | | } |
| | | return "default"; |
| | | } |
| | | |
| | | private List<Integer> parseStationIdArray(JSONArray array) { |