|
@@ -0,0 +1,353 @@
|
|
|
+package com.example.nngkxxdp.util;
|
|
|
+
|
|
|
+import cn.hutool.core.convert.Convert;
|
|
|
+import cn.hutool.core.date.DateField;
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.example.nngkxxdp.dao.HlwInterfaceDao;
|
|
|
+import com.example.nngkxxdp.dao.TjDao;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+@Component
|
|
|
+public class WzkpRecordUtil {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private TjDao tjDao;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private HlwInterfaceDao hlwInterfaceDao;
|
|
|
+
|
|
|
+ public void generateRecord(String date) {
|
|
|
+ // 初始化部门分值
|
|
|
+ List<Map<String, Object>> deptList = initDeptScore();
|
|
|
+ // 获取部门其他栏目
|
|
|
+ Map<String, String> deptOtherColumn = getDeptOtherColumn(deptList);
|
|
|
+ // 获取事项规则
|
|
|
+ List<Map<String, Object>> eventList = initEvent();
|
|
|
+ // 获取事项规则组
|
|
|
+ List<Map<String, Object>> eventGroup = getEventGroup();
|
|
|
+ // 获取各个栏目最新更新时间{deptName-chnlid: isUpdate,...}
|
|
|
+ Map<String, Object> columnInfo = getColumnLastUpdate(deptList, date);
|
|
|
+ // 加分栏目查询
|
|
|
+ Map<String, Integer> addScoreColumn = getAddScoreColumn();
|
|
|
+
|
|
|
+ List<Map<String, Object>> record = new ArrayList<>();
|
|
|
+
|
|
|
+ for (int i = 0; i < deptList.size(); i++) {
|
|
|
+ Map<String, Object> deptItem = deptList.get(i);
|
|
|
+ String deptName = deptItem.get("deptname").toString();
|
|
|
+ Double baseScore = Convert.toDouble(deptItem.get("baseScore"));
|
|
|
+ String[] chnlids = Convert.toStr(deptItem.get("haveChnlid"), "").split(",");
|
|
|
+
|
|
|
+
|
|
|
+ for (int j = 0; j < chnlids.length; j++) {
|
|
|
+ String chnlid = chnlids[j];
|
|
|
+ if (Blank.isEmpty(columnInfo.get(deptName + "-" + chnlid))) {
|
|
|
+ System.out.println(deptName + "-" + chnlid);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ String isExceed = columnInfo.get(deptName + "-" + chnlid).toString();
|
|
|
+ if ("1".equals(isExceed)) {
|
|
|
+ for (int k = 0; k < eventList.size(); k++) {
|
|
|
+ Map<String, Object> eventItem = eventList.get(k);
|
|
|
+ if (!Convert.toBool(eventItem.get("type"))) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ List<String> list = Convert.toList(String.class, Convert.toStr(eventItem.get("chnlid").toString().split(","), ""));
|
|
|
+ if (list.contains(chnlid)) {
|
|
|
+ Map<String, Object> param = new HashMap<>();
|
|
|
+ param.put("pId", eventItem.get("pId"));
|
|
|
+
|
|
|
+ param.put("type", eventItem.get("type"));
|
|
|
+ param.put("cloumnName", eventItem.get("target"));
|
|
|
+ param.put("deptId", deptItem.get("deptid"));
|
|
|
+ param.put("score", eventItem.get("score"));
|
|
|
+ param.put("date", Blank.isEmpty(date) ? cn.hutool.core.date.DateUtil.now() : cn.hutool.core.date.DateUtil.parse(date, "yyyy-MM-dd").offset(DateField.DAY_OF_MONTH, -1).toString("yyyy-MM-dd"));
|
|
|
+// param.put("chnlid", chnlid);
|
|
|
+
|
|
|
+ record.add(param);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ for (int k = 0; k < eventList.size(); k++) {
|
|
|
+ Map<String, Object> eventItem = eventList.get(k);
|
|
|
+ if (Convert.toBool(eventItem.get("type"))) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ List<String> list = Convert.toList(String.class, Convert.toStr(eventItem.get("chnlid").toString().split(","), ""));
|
|
|
+ if (list.contains(chnlid)) {
|
|
|
+ Map<String, Object> param = new HashMap<>();
|
|
|
+ Integer addCount = addScoreColumn.get(chnlid);
|
|
|
+ if (Blank.isEmpty(addCount)){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ Double score = Convert.toDouble(eventItem.get("score"));
|
|
|
+ Double maxScore = Convert.toDouble(eventItem.get("targetScore"));
|
|
|
+ String pId = Convert.toStr(eventItem.get("pId"));
|
|
|
+ if ("26".equals(pId)) {
|
|
|
+ if (addCount > 2) {
|
|
|
+ double scoreS = (addCount - 2) * score;
|
|
|
+ if (scoreS > 0) {
|
|
|
+ if (maxScore > scoreS) {
|
|
|
+ param.put("score", scoreS);
|
|
|
+ } else {
|
|
|
+ param.put("score", maxScore);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (addCount > 1) {
|
|
|
+ double scoreS = (addCount - 1) * score;
|
|
|
+ if (scoreS > 0) {
|
|
|
+ if (maxScore > scoreS) {
|
|
|
+ param.put("score", scoreS);
|
|
|
+ } else {
|
|
|
+ param.put("score", maxScore);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ param.put("pId", eventItem.get("pId"));
|
|
|
+
|
|
|
+ param.put("type", eventItem.get("type"));
|
|
|
+ param.put("cloumnName", eventItem.get("target"));
|
|
|
+ param.put("deptId", deptItem.get("deptid"));
|
|
|
+ param.put("date", Blank.isEmpty(date) ? cn.hutool.core.date.DateUtil.now() : cn.hutool.core.date.DateUtil.parse(date, "yyyy-MM-dd").offset(DateField.DAY_OF_MONTH, -1).toString("yyyy-MM-dd"));
|
|
|
+// param.put("chnlid", chnlid);
|
|
|
+
|
|
|
+ record.add(param);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 其他栏目
|
|
|
+ if (Blank.isEmpty(deptOtherColumn.get(deptName))) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ String[] otherChnlids = deptOtherColumn.get(deptName).split(",");
|
|
|
+ for (int j = 0; j < otherChnlids.length; j++) {
|
|
|
+ String chnlid = otherChnlids[j];
|
|
|
+ if (Blank.isEmpty(columnInfo.get(deptName + "-" + chnlid))) {
|
|
|
+ System.out.println(deptName + "-" + chnlid);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ String isExceed = columnInfo.get(deptName + "-" + chnlid).toString();
|
|
|
+ if ("1".equals(isExceed)) {
|
|
|
+ for (int k = 0; k < eventList.size(); k++) {
|
|
|
+ Map<String, Object> eventItem = eventList.get(k);
|
|
|
+ String pId = eventItem.get("pId").toString();
|
|
|
+ if ("9".equals(pId)) {
|
|
|
+ Map<String, Object> param = new HashMap<>();
|
|
|
+
|
|
|
+ param.put("pId", eventItem.get("pId"));
|
|
|
+ param.put("type", eventItem.get("type"));
|
|
|
+ param.put("cloumnName", eventItem.get("target"));
|
|
|
+ param.put("deptId", deptItem.get("deptid"));
|
|
|
+ param.put("date", Blank.isEmpty(date) ? cn.hutool.core.date.DateUtil.now() : cn.hutool.core.date.DateUtil.parse(date, "yyyy-MM-dd").offset(DateField.DAY_OF_MONTH, -1).toString("yyyy-MM-dd"));
|
|
|
+ record.add(param);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ double scoreS = 0;
|
|
|
+ for (int k = 0; k < eventList.size(); k++) {
|
|
|
+ Map<String, Object> eventItem = eventList.get(k);
|
|
|
+ if (Convert.toBool(eventItem.get("type"))) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ List<String> list = Convert.toList(String.class, Convert.toStr(eventItem.get("chnlid").toString().split(","), ""));
|
|
|
+ if (list.contains(chnlid)) {
|
|
|
+ Map<String, Object> param = new HashMap<>();
|
|
|
+ Integer addCount = addScoreColumn.get(chnlid);
|
|
|
+ if (Blank.isEmpty(addCount)){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ Double score = Convert.toDouble(eventItem.get("score"));
|
|
|
+ Double maxScore = Convert.toDouble(eventItem.get("targetScore"));
|
|
|
+ String pId = Convert.toStr(eventItem.get("pId"));
|
|
|
+ if ("28".equals(pId)) {
|
|
|
+ if (addCount > 1) {
|
|
|
+ scoreS = (addCount - 1) * score;
|
|
|
+ if (scoreS > 0) {
|
|
|
+ if (maxScore > scoreS) {
|
|
|
+ param.put("score", scoreS);
|
|
|
+ } else {
|
|
|
+ param.put("score", maxScore);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ param.put("pId", eventItem.get("pId"));
|
|
|
+ param.put("type", eventItem.get("type"));
|
|
|
+ param.put("cloumnName", eventItem.get("target"));
|
|
|
+ param.put("deptId", deptItem.get("deptid"));
|
|
|
+ param.put("date", Blank.isEmpty(date) ? cn.hutool.core.date.DateUtil.now() : cn.hutool.core.date.DateUtil.parse(date, "yyyy-MM-dd").offset(DateField.DAY_OF_MONTH, -1).toString("yyyy-MM-dd"));
|
|
|
+
|
|
|
+ record.add(param);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ tjDao.saveOnceRecord(filterRecord(record, eventList, eventGroup));
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<Map<String, Object>> filterRecord(List<Map<String, Object>> records, List<Map<String, Object>> events, List<Map<String, Object>> eventGroup) {
|
|
|
+ List<Map<String, Object>> list = new ArrayList<>();
|
|
|
+ JSONObject deptGroup = new JSONObject();
|
|
|
+ for (int i = 0; i < records.size(); i++) {
|
|
|
+ Map<String, Object> record = records.get(i);
|
|
|
+ String pId = Convert.toStr(record.get("pId"));
|
|
|
+ String deptId = Convert.toStr(record.get("deptId"));
|
|
|
+ JSONObject obj = deptGroup.getJSONObject(deptId);
|
|
|
+ if (obj == null) {
|
|
|
+ obj = new JSONObject();
|
|
|
+ }
|
|
|
+ JSONArray arr = obj.getJSONArray(pId);
|
|
|
+ if (arr == null) {
|
|
|
+ arr = new JSONArray();
|
|
|
+ }
|
|
|
+ arr.add(record);
|
|
|
+ obj.put(pId, arr);
|
|
|
+ deptGroup.put(deptId, obj);
|
|
|
+ }
|
|
|
+
|
|
|
+ for (int i = 0; i < eventGroup.size(); i++) {
|
|
|
+ Map<String, Object> map = eventGroup.get(i);
|
|
|
+ JSONArray group = JSONArray.parseArray(map.get("groupId").toString());
|
|
|
+ for (int j = 0; j < group.size(); j++) {
|
|
|
+
|
|
|
+ Double maxScore = Convert.toDouble(map.get("score"), 0.00);
|
|
|
+
|
|
|
+ for (String deptId : deptGroup.keySet()) {
|
|
|
+ JSONObject obj = deptGroup.getJSONObject(deptId);
|
|
|
+
|
|
|
+ JSONArray recordArr = obj.getJSONArray(group.getString(j));
|
|
|
+
|
|
|
+ if (recordArr == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ Double score = 0.00;
|
|
|
+ for (int k = 0; k < recordArr.size(); k++) {
|
|
|
+ JSONObject record = recordArr.getJSONObject(k);
|
|
|
+ score += Convert.toDouble(record.getDouble("score"), 0.00);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (maxScore > 0) {
|
|
|
+ if (maxScore > score) {
|
|
|
+ maxScore -= score;
|
|
|
+ } else {
|
|
|
+ score = maxScore;
|
|
|
+ maxScore = 0.00;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ JSONObject record = recordArr.getJSONObject(0);
|
|
|
+ record.put("score", score);
|
|
|
+ list.add(Convert.toMap(String.class, Object.class, record));
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Map<String, String> getDeptOtherColumn(List<Map<String, Object>> list) {
|
|
|
+ Map<String, String> res = new HashMap<>();
|
|
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
+ Map<String, Object> map = list.get(i);
|
|
|
+ String otherChnlid = Convert.toStr(map.get("otherChnlid"));
|
|
|
+ if (Blank.isEmpty(otherChnlid)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ res.put(map.get("deptname").toString(), otherChnlid);
|
|
|
+ }
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Map<String, Integer> getAddScoreColumn() {
|
|
|
+ List<Map<String, Object>> list = hlwInterfaceDao.countArticle();
|
|
|
+ Map<String, Integer> res = new HashMap<>();
|
|
|
+ for (Map<String, Object> map : list) {
|
|
|
+ String chnlid = Convert.toStr(map.get("chnlid"));
|
|
|
+ Integer count = Convert.toInt(map.get("count"));
|
|
|
+ res.put(chnlid, count);
|
|
|
+ }
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Map<String, Object> getColumnLastUpdate(List<Map<String, Object>> list, String date) {
|
|
|
+ List<Map<String, Object>> columnInfo = hlwInterfaceDao.getAllColumn(date);
|
|
|
+ Map<String, Object> res = new HashMap<>();
|
|
|
+ for (int i = 0; i < columnInfo.size(); i++) {
|
|
|
+ Map<String, Object> map = columnInfo.get(i);
|
|
|
+ String key = getRealDeptName(map.get("unit").toString(), list) + "-" + map.get("chnlid").toString();
|
|
|
+ String value = Convert.toStr(map.get("isExceed"), "-1");
|
|
|
+ res.put(key, value);
|
|
|
+ }
|
|
|
+
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getRealDeptName(String userName, List<Map<String, Object>> list) {
|
|
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
+ Map<String, Object> map = list.get(i);
|
|
|
+ String deptName = map.get("deptname").toString();
|
|
|
+ if (userName.contains(deptName)) {
|
|
|
+ return deptName;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<Map<String, Object>> getEventGroup() {
|
|
|
+ return tjDao.getPartitionGroup();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 处理事项
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<Map<String, Object>> initEvent() {
|
|
|
+ // 获取事项规则
|
|
|
+ List<Map<String, Object>> eventList = tjDao.getPartitionByTypeExcludeAutoCompute();
|
|
|
+
|
|
|
+ return eventList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 初始化部门分值
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<Map<String, Object>> initDeptScore() {
|
|
|
+ String thisMonth = getLastMonth();
|
|
|
+ // 查询是否已初始化
|
|
|
+ Integer count = tjDao.getCountWebsiteRating(null, thisMonth);
|
|
|
+ // 部门基础分值配置
|
|
|
+ List<Map<String, Object>> deptList = tjDao.getAllDept(null);
|
|
|
+ if (count == 0) {
|
|
|
+ // 初始化当月分值
|
|
|
+ tjDao.saveDeptRecord(deptList, thisMonth);
|
|
|
+ }
|
|
|
+ return deptList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取上一月
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private String getLastMonth() {
|
|
|
+ Date now = cn.hutool.core.date.DateUtil.date();
|
|
|
+ now = cn.hutool.core.date.DateUtil.offsetMonth(now, -1);
|
|
|
+ // 当前月份
|
|
|
+ return DateUtil.format(now, "yyyy-MM");
|
|
|
+ }
|
|
|
+}
|