|
@@ -3,17 +3,137 @@ package cn.com.ctop.alarm.modules.service.impl;
|
|
|
import cn.com.ctop.alarm.modules.entity.RuleAccountThreshold;
|
|
|
import cn.com.ctop.alarm.modules.mapper.RuleAccountThresholdMapper;
|
|
|
import cn.com.ctop.alarm.modules.service.IRuleAccountThresholdService;
|
|
|
+import cn.com.ctop.common.module.utils.Check;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.UUID;
|
|
|
|
|
|
/**
|
|
|
* 规则关联账户 阈值
|
|
|
+ *
|
|
|
* @author jeecg-boot
|
|
|
- * @date 2020-11-15
|
|
|
* @version V1.0
|
|
|
+ * @date 2020-11-15
|
|
|
*/
|
|
|
@Service
|
|
|
public class RuleAccountThresholdServiceImpl extends ServiceImpl<RuleAccountThresholdMapper, RuleAccountThreshold> implements IRuleAccountThresholdService {
|
|
|
+ @Autowired
|
|
|
+ private RuleAccountThresholdMapper ruleAccountThresholdMapper;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 填充阈值
|
|
|
+ *
|
|
|
+ * @param requestJson
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public JSONObject fillThreshold(JSONObject requestJson) throws Exception {
|
|
|
+ Long accountId = requestJson.getLong("accountId");
|
|
|
+ if (Check.isNull(accountId)) {
|
|
|
+ throw new Exception("请传入账户id");
|
|
|
+ }
|
|
|
+ JSONArray ruleList = requestJson.getJSONArray("ruleList");
|
|
|
+ if (Check.isNull(ruleList)) {
|
|
|
+ throw new Exception("请输入具体的规则字段");
|
|
|
+ }
|
|
|
+ Integer updateCount = 0;
|
|
|
+ for (int i = 0; i < ruleList.size(); i++) {
|
|
|
+ JSONObject groupJson = ruleList.getJSONObject(i);
|
|
|
+ if (Check.isNull(groupJson)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ JSONArray ruleDetail = groupJson.getJSONArray("ruleDetail");
|
|
|
+ if (Check.isNull(ruleDetail)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ Long groupId = groupJson.getLong("groupId");
|
|
|
+ Integer isCopy = groupJson.getInteger("isCopy");
|
|
|
+
|
|
|
+ String batchNo = UUID.randomUUID().toString().replace(" ", "");
|
|
|
+
|
|
|
+ for (int j = 0; j < ruleDetail.size(); j++) {
|
|
|
+ if (isCopy == 1) { // 规则组可复制
|
|
|
+ JSONArray ruleDetailArr = ruleDetail.getJSONArray(i);
|
|
|
+ if (Check.isNull(ruleDetailArr)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ Map<String, Object> deleteMap = new HashMap<>();
|
|
|
+ deleteMap.put("account_id", accountId);
|
|
|
+ deleteMap.put("group_id", groupId);
|
|
|
+ ruleAccountThresholdMapper.deleteByMap(deleteMap);
|
|
|
+ for (int k = 0; k < ruleDetailArr.size(); k++) {
|
|
|
+ JSONObject ruleJson = ruleDetailArr.getJSONObject(k);
|
|
|
+ if (Check.isNull(ruleJson)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ Long ruleId = ruleJson.getLong("ruleId");
|
|
|
+ if (Check.isNull(ruleId)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ String threshold = ruleJson.getString("threshold");
|
|
|
+ if (Check.isNull(threshold)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ RuleAccountThreshold addRuleAccountThreshold = new RuleAccountThreshold();
|
|
|
+ addRuleAccountThreshold.setAccountId(accountId);
|
|
|
+ addRuleAccountThreshold.setGroupId(groupId);
|
|
|
+ addRuleAccountThreshold.setThreshold(threshold);
|
|
|
+ addRuleAccountThreshold.setRuleId(ruleId);
|
|
|
+ addRuleAccountThreshold.setBatchNo(batchNo);
|
|
|
+ int insert = ruleAccountThresholdMapper.insert(addRuleAccountThreshold);
|
|
|
+ if (insert > 0) {
|
|
|
+ updateCount += 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (isCopy == 0) {
|
|
|
+
|
|
|
+
|
|
|
+ JSONObject ruleJson = ruleDetail.getJSONObject(j);
|
|
|
+ Long ruleId = ruleJson.getLong("ruleId");
|
|
|
+ if (Check.isNull(ruleId)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ String threshold = ruleJson.getString("threshold");
|
|
|
+ if (Check.isNull(threshold)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ RuleAccountThreshold updateThreshold = new RuleAccountThreshold();
|
|
|
+ /*if (threshold.contains("[") && threshold.contains("]")) {
|
|
|
+ *//* String replace = threshold.replace("[", "").replace("]", "");
|
|
|
+ List<String> strings = Arrays.asList(replace.split(","));
|
|
|
+ JSONArray array = new JSONArray();
|
|
|
+ for (int k = 0; k < strings.size(); k++) {
|
|
|
+ array.add(strings.get(i))
|
|
|
+ JSONArray.parseArray(strings);
|
|
|
+ }*//*
|
|
|
+
|
|
|
+ updateThreshold.setThreshoId(JSONArray.parseArray(threshold).toJSONString());
|
|
|
+ } else {
|
|
|
+
|
|
|
+ }*/
|
|
|
+ updateThreshold.setThreshold(threshold);
|
|
|
+ QueryWrapper<RuleAccountThreshold> updateQueryWrapper = new QueryWrapper();
|
|
|
+ updateQueryWrapper.eq("account_id", accountId);
|
|
|
+ updateQueryWrapper.eq("rule_id", ruleId);
|
|
|
+ int update = ruleAccountThresholdMapper.update(updateThreshold, updateQueryWrapper);
|
|
|
+ if (update > 0) {
|
|
|
+ updateCount += 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ JSONObject returnJson = new JSONObject();
|
|
|
+ returnJson.put("code", 0);
|
|
|
+ returnJson.put("updateCount", updateCount);
|
|
|
+ return returnJson;
|
|
|
+ }
|
|
|
}
|