Procházet zdrojové kódy

网站考评相关

gt před 3 roky
rodič
revize
6f7ea3d682

+ 6 - 0
nngkxxdp/pom.xml

@@ -184,6 +184,12 @@
 		    <version>3.3.3</version>
 		</dependency>
 
+		<dependency>
+			<groupId>org.jsoup</groupId>
+			<artifactId>jsoup</artifactId>
+			<version>1.12.1</version>
+		</dependency>
+
 	</dependencies>
 
 

+ 8 - 1
nngkxxdp/src/main/java/com/example/nngkxxdp/controller/TjController.java

@@ -36,6 +36,9 @@ public class TjController {
 	@Autowired
 	private TjService tjService;
 
+	@Resource
+	private WzkpRecordUtil wzkpRecordUtil;
+
 	/**
 	 * 门户网站统计
 	 * @return
@@ -143,5 +146,9 @@ public class TjController {
 			    .execute().body();
 		System.err.println("body==========:"+result);
 	}
-	
+
+	@GetMapping("computeRecord")
+	public void computeRecord(String date) {
+		wzkpRecordUtil.generateRecord(date);
+	}
 }

+ 2 - 0
nngkxxdp/src/main/java/com/example/nngkxxdp/dao/ArticleDao.java

@@ -189,6 +189,8 @@ public interface ArticleDao {
 	 */
     List<Map<String, Object>> getNewestOrHotArticle(@Param("articleType") Integer articleType);
 
+    void saveHlwInterfaceData(@Param("list") List<Map> list);
+
 	/**
 	 * 统计按时间查询呢南岸发布文章数量
 	 * @param map

+ 42 - 0
nngkxxdp/src/main/java/com/example/nngkxxdp/dao/HlwInterfaceDao.java

@@ -0,0 +1,42 @@
+package com.example.nngkxxdp.dao;
+
+
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+import java.util.Map;
+
+public interface HlwInterfaceDao {
+
+    /**
+     * 保存栏目column_relation数据
+     * @param map
+     * @return
+     */
+    boolean saveHlwColumnRelation2(Map<String, Object> map);
+
+    /**
+     * 根据chnlid获取columnRelationshuju
+     * @param chnlid
+     */
+    Integer countColumnRelationByChnlid(@Param("chnlid") String chnlid);
+
+    /**
+     * 获取栏目
+     * @param date
+     * @return
+     */
+    List<Map<String, Object>> getAllColumn(@Param("date") String date);
+
+    /**
+     * 统计各栏目文章数量大于1
+     * @return
+     */
+    List<Map<String, Object>> countArticle();
+
+    /**
+     * 更新column_relation的last_update字段
+     * @return
+     */
+    boolean updateLastUpdateTime();
+}

+ 13 - 0
nngkxxdp/src/main/java/com/example/nngkxxdp/dao/TjDao.java

@@ -141,6 +141,12 @@ public interface TjDao {
 	 * @return
 	 */
 	List<Map<String, Object>> getPartitionByType(@Param("type") Integer type);
+
+	/**
+	 * 获取得分规则,排除自动计算
+	 * @return
+	 */
+	List<Map<String, Object>> getPartitionByTypeExcludeAutoCompute();
 	
 	/**
 	 * 获取南岸更新文章情况
@@ -154,6 +160,13 @@ public interface TjDao {
 	 * @return
 	 */
 	boolean saveRecord(List<Map<String, Object>> list);
+
+	/**
+	 * 保存扣分记录
+	 * @param list
+	 * @return
+	 */
+	boolean saveOnceRecord(List<Map<String, Object>> list);
 	
 	/**
 	 * 获取其他栏目

+ 5 - 1
nngkxxdp/src/main/java/com/example/nngkxxdp/hlw/HlwHttpUtil.java

@@ -43,7 +43,7 @@ public class HlwHttpUtil {
 		return null;
 	}
 	
-	private static JSONObject getArticleList(Integer page, Integer limit, String operTime) {
+	public static JSONObject getArticleList(Integer page, Integer limit, String operTime) {
 		log.info("开始请求华龙网文章列表接口");
 		String token = getToken();
 		if (!Blank.notBlank(token)) {
@@ -74,6 +74,10 @@ public class HlwHttpUtil {
 			return null;
 		}
 		JSONObject data = obj.getJSONObject("data");
+		if (Blank.isEmpty(data)) {
+			log.info("==================================={}============================================", page);
+			return null;
+		}
 		if (!data.getBool("ISSUCCESS", false)) {
 			log.info("华龙网文章列表接口获取数据失败");
 			return null;

+ 1 - 1
nngkxxdp/src/main/java/com/example/nngkxxdp/service/impl/TjServiceImpl.java

@@ -404,7 +404,7 @@ public class TjServiceImpl implements TjService {
 			
 			Map<String, Object> deptMap = change.get(String.valueOf(basic.get("deptid")));
 			
-			Integer bNum = Convert.toInt(deptMap.get("num"));
+			Integer bNum = Convert.toInt(deptMap.get("num"), 0);
 			
 			BigDecimal sbd = new BigDecimal(score);
 			BigDecimal nbd = new BigDecimal(bNum);

+ 201 - 0
nngkxxdp/src/main/java/com/example/nngkxxdp/task/HlwTask.java

@@ -0,0 +1,201 @@
+package com.example.nngkxxdp.task;
+
+import cn.hutool.core.convert.Convert;
+import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.date.LocalDateTimeUtil;
+import cn.hutool.core.io.FileUtil;
+import cn.hutool.core.util.ArrayUtil;
+import cn.hutool.core.util.ReUtil;
+import cn.hutool.core.util.StrUtil;
+import cn.hutool.core.util.URLUtil;
+import cn.hutool.http.HttpResponse;
+import cn.hutool.http.HttpUtil;
+import cn.hutool.json.JSONArray;
+import cn.hutool.json.JSONObject;
+import cn.hutool.json.JSONUtil;
+import cn.hutool.log.Log;
+import cn.hutool.log.LogFactory;
+import cn.hutool.poi.excel.ExcelReader;
+import cn.hutool.poi.excel.ExcelUtil;
+import cn.hutool.poi.excel.ExcelWriter;
+import com.example.nngkxxdp.dao.ArticleDao;
+import com.example.nngkxxdp.dao.DeptDao;
+import com.example.nngkxxdp.dao.HlwInterfaceDao;
+import com.example.nngkxxdp.entity.Article;
+import com.example.nngkxxdp.entity.Dept;
+import com.example.nngkxxdp.hlw.HlwHttpUtil;
+import com.example.nngkxxdp.util.Blank;
+import org.apache.xmlbeans.impl.common.XPath;
+import org.jsoup.Jsoup;
+import org.jsoup.internal.StringUtil;
+import org.jsoup.nodes.Document;
+import org.jsoup.nodes.Element;
+import org.jsoup.select.Elements;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.STSourceType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.scheduling.annotation.EnableScheduling;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.annotation.Resource;
+import javax.servlet.http.HttpServletResponse;
+import javax.xml.transform.Result;
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.text.SimpleDateFormat;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.LocalTime;
+import java.time.ZoneOffset;
+import java.time.format.DateTimeFormatter;
+import java.time.temporal.TemporalField;
+import java.util.*;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+
+@Configuration
+@EnableScheduling
+//@RestController
+public class HlwTask {
+
+    private static final Log log = LogFactory.get();
+
+    @Resource
+    private ArticleDao articleDao;
+
+    @Resource
+    private HlwInterfaceDao hlwInterfaceDao;
+
+    @Scheduled(cron = "0 58 23 * * ?")
+//    @GetMapping("/getTodayData")
+    public void saveAndUpdateColumnRelationData() {
+        JSONArray articleList = HlwHttpUtil.getArticleList("-1");
+        JSONArray todayPubArticleArr = new JSONArray();
+
+        // 当天日期
+        String today = DateUtil.today();
+
+        // 将接口数据转换为本系统中的格式
+        for (int i = 0; i < articleList.size(); i++) {
+            JSONObject obj = articleList.getJSONObject(i);
+            // 获取当前文章发布时间毫秒值
+            String opertime = obj.getStr("OPERTIME");
+            String crtime = obj.getStr("CRTIME");
+            String docpubtime = obj.getStr("DOCPUBTIME");
+            String docreltime = obj.getStr("DOCRELTIME");
+
+            opertime = DateUtil.format(DateUtil.parse(opertime), "yyyy-MM-dd");
+            crtime = DateUtil.format(DateUtil.parse(crtime), "yyyy-MM-dd");
+            docpubtime = DateUtil.format(DateUtil.parse(docpubtime), "yyyy-MM-dd");
+            docreltime = DateUtil.format(DateUtil.parse(docreltime), "yyyy-MM-dd");
+
+            // 是否当天发布
+            if (today.equals(opertime) || today.equals(crtime) || today.equals(docpubtime) || today.equals(docreltime)) {
+                todayPubArticleArr.add(obj);
+            }
+        }
+
+        try {
+            if (todayPubArticleArr.size() > 0) {
+                saveData(todayPubArticleArr);
+                hlwInterfaceDao.updateLastUpdateTime();
+            }
+        } catch (Exception e) {
+            log.error(e.getCause());
+            e.printStackTrace();
+        }
+
+        log.info("get hlw api data end");
+    }
+
+    /**
+     * 保存hlw接口数据
+     * 全量采集华龙网接口数据
+     */
+//    @GetMapping("/test/saveHlwData")
+    public void task() {
+        int page = 1;
+        int limit = 100;
+        JSONArray array = new JSONArray();
+        String operTime = null;
+        boolean status = true;
+        while (status) {
+            JSONObject obj = HlwHttpUtil.getArticleList(page, limit, operTime);
+
+            if (Blank.isEmpty(obj)) {
+                continue;
+            }
+            JSONObject pager = obj.getJSONObject("PAGER");
+
+            Integer count = pager.getInt("PAGECOUNT");
+            Integer countPage = count / limit;
+            if ((count % limit) > 1) {
+                countPage += 1;
+            }
+            if (Blank.isNotEmpty(obj)) {
+                if (Blank.notBlank(operTime)) {
+                    String today = DateUtil.today();
+                    JSONArray data = obj.getJSONArray("DATA");
+                    String docrelTime = data.getJSONObject(data.size() - 1).getStr("DOCPUBTIME");
+                    docrelTime = DateUtil.format(DateUtil.parse(docrelTime), "yyyy-MM-dd");
+//                    if (countPage == page) {
+//                        status = false;
+//                    }
+                }
+//                if (page <= countPage) {
+				if (page <= count) {
+                    page++;
+//                    init(obj.getJSONArray("DATA"));
+                    try {
+                        saveData(obj.getJSONArray("DATA"));
+                    } catch (Exception e) {
+                        e.printStackTrace();
+                    }
+//                    array.addAll(obj.getJSONArray("DATA"));
+                } else {
+                    // 已获取完所有数据
+                    status = false;
+                    break;
+                }
+            }
+
+        }
+        log.info("init end");
+    }
+
+    /**
+     * 保存接口数据并更新column_relation的last_update_date
+     * @param jsonArray
+     */
+    private void saveData(JSONArray jsonArray) throws Exception {
+        List<Map> list = new ArrayList<>();
+        for (int i = 0; i < jsonArray.size(); i++) {
+            JSONObject item = jsonArray.getJSONObject(i);
+            String chnlid = item.getStr("CHNLID");
+            Integer count = hlwInterfaceDao.countColumnRelationByChnlid(chnlid);
+            if (count == 0) {
+                String chnlidname = item.getStr("CHNLIDNAME");
+                String viewname = item.getStr("VIEWNAME");
+                String channelname = item.getStr("CHANNELNAME");
+
+                Map<String, Object> param = new HashMap<>();
+                param.put("dept", Convert.toStr(item.getStr("CRUSER")));
+                param.put("chnlid", chnlid);
+                param.put("position", null);
+                param.put("unionChannel", chnlidname + "-" + viewname + "-" + channelname);
+                param.put("lastTime", null);
+
+                hlwInterfaceDao.saveHlwColumnRelation2(param);
+            }
+            list.add(item.toBean(Map.class));
+        }
+        articleDao.saveHlwInterfaceData(list);
+    }
+
+}

+ 45 - 0
nngkxxdp/src/main/java/com/example/nngkxxdp/util/NewDeptTaskUtil3.java

@@ -0,0 +1,45 @@
+package com.example.nngkxxdp.util;
+
+import cn.hutool.core.convert.Convert;
+import cn.hutool.core.date.DateField;
+import cn.hutool.core.date.DateUnit;
+import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.util.StrUtil;
+import cn.hutool.log.StaticLog;
+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.context.annotation.Configuration;
+import org.springframework.scheduling.annotation.EnableScheduling;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.annotation.Resource;
+import java.security.Key;
+import java.text.DateFormat;
+import java.util.*;
+import java.util.stream.Collectors;
+
+/** 
+* @author Mr.wang
+* @version 1.0.0
+* @date 2021年12月8日 下午5:36:36
+* @Description 新计分标准
+*/
+@Configuration
+@EnableScheduling
+public class NewDeptTaskUtil3 {
+
+	@Resource
+	private WzkpRecordUtil wzkpRecordUtil;
+	
+	@Scheduled(cron = "0 30 0 1 * ?")
+	public void task() {
+		wzkpRecordUtil.generateRecord(null);
+	}
+
+}

+ 353 - 0
nngkxxdp/src/main/java/com/example/nngkxxdp/util/WzkpRecordUtil.java

@@ -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");
+    }
+}

+ 12 - 0
nngkxxdp/src/main/resources/mapper/ArticleDao.xml

@@ -684,6 +684,18 @@
 
     </select>
 
+    <insert id="saveHlwInterfaceData">
+        insert into save_hlw_interface_data (DOCTYPE, DOCORDER, RECID, CHNLIDNAME, DOCCHANNEL, TITLEFIELD, CRUSER, OPERUSER
+        , OPERTIME, CRTIME, DOCPUBTIME, DOCSTATUS, VIEWNAME, DOCRELTIME, DOCID, ORIGINRECID, CHNLID, DOCTITLE, DOCPUBURL
+        , CHANNELNAME, SITEID, PUBSTATUS)
+        values
+        <foreach collection="list" item="item" separator=",">
+            (#{item.DOCTYPE}, #{item.DOCORDER}, #{item.RECID}, #{item.CHNLIDNAME}, #{item.DOCCHANNEL}, #{item.TITLEFIELD}, #{item.CRUSER}, #{item.OPERUSER}
+            , #{item.OPERTIME}, #{item.CRTIME}, #{item.DOCPUBTIME}, #{item.DOCSTATUS}, #{item.VIEWNAME}, #{item.DOCRELTIME}, #{item.DOCID}, #{item.ORIGINRECID},
+            #{item.CHNLID}, #{item.DOCTITLE}, #{item.DOCPUBURL}, #{item.CHANNELNAME}, #{item.SITEID}, #{item.PUBSTATUS})
+        </foreach>
+    </insert>
+
     <select id="countNAFBArticleByDate" resultType="integer">
         SELECT
             count(1)

+ 129 - 0
nngkxxdp/src/main/resources/mapper/HlwInterfaceDao.xml

@@ -0,0 +1,129 @@
+<?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.example.nngkxxdp.dao.HlwInterfaceDao">
+
+	<insert id="saveHlwColumnRelation2">
+		insert into column_relation(unit, chnlid, position, union_channel, last_update_date, create_time)
+			values (#{dept}, #{chnlid}, #{position}, #{unionChannel}, #{lastTime}, now())
+	</insert>
+
+	<select id="countColumnRelationByChnlid" resultType="integer">
+		select
+			count(1)
+		from
+			column_relation
+		where
+			chnlid = #{chnlid}
+	</select>
+
+	<!--<select id="getAllColumn" resultType="hashmap">
+		select
+			*,
+		TIMESTAMPDIFF(
+				DAY,
+				DATE_FORMAT( last_update_date, "%Y-%m-%d" ),
+				DATE_FORMAT(
+				    <if test="date != null and date != ''">
+						#{date}
+					</if>
+					<if test="date == null or date == ''">
+						now()
+					</if>
+				    , "%Y-%m-%d" )) > frequency isExceed
+		from
+			column_relation
+	</select>-->
+	<select id="getAllColumn" resultType="hashmap">
+		SELECT
+			b.CHNLID,
+			c.unit,
+			c.frequency,
+			b.DOCRELTIME,
+			TIMESTAMPDIFF(
+				DAY,
+				DATE_FORMAT( b.DOCRELTIME, '%Y-%m-%d' ),
+				DATE_FORMAT(
+				<if test="date != null and date != ''">
+					#{date}
+				</if>
+				<if test="date == null or date == ''">
+					now()
+				</if>
+				, '%Y-%m-%d' )) &gt; frequency isExceed
+		FROM
+			(
+			SELECT
+				a.CHNLID,
+				GREATEST( a.OPERTIME, a.CRTIME, a.DOCPUBTIME, a.DOCRELTIME ) DOCRELTIME
+			FROM
+				(
+					SELECT
+						CHNLID,
+						DOCRELTIME,
+						CRTIME,
+						OPERTIME,
+						DOCPUBTIME
+					FROM
+						save_hlw_interface_data
+						<if test="date != null and date != ''">
+							WHERE
+							DOCRELTIME &lt; #{date}
+							AND OPERTIME &lt; #{date}
+							AND CRTIME &lt; #{date}
+							AND DOCPUBTIME &lt; #{date}
+						</if>
+					GROUP BY
+						CHNLID DESC
+				) a
+				GROUP BY
+					a.CHNLID
+			) b
+			LEFT JOIN column_relation c ON b.CHNLID = c.CHNLID
+		WHERE
+			c.frequency &gt; 0
+	</select>
+
+	<select id="countArticle" resultType="hashmap">
+		SELECT
+			b.CHNLID,
+			COUNT(*) count
+		FROM
+			column_relation a
+				LEFT JOIN save_hlw_interface_data b ON a.CHNLID = b.CHNLID
+		WHERE
+			a.frequency != -1 AND b.DOCRELTIME >= DATE_SUB(now(),INTERVAL a.frequency DAY)
+		GROUP BY
+			b.CHNLID
+		HAVING
+			COUNT(*) > 1
+	</select>
+
+	<update id="updateLastUpdateTime">
+		UPDATE column_relation b,
+			(
+				SELECT
+					a.CHNLID,
+					GREATEST( OPERTIME, CRTIME, DOCPUBTIME, DOCRELTIME ) DOCRELTIME
+				FROM
+					(
+						SELECT
+							CHNLID,
+							DOCRELTIME,
+							CRTIME,
+							OPERTIME,
+							DOCPUBTIME
+						FROM
+							save_hlw_interface_data
+						GROUP BY
+						CHNLID DESC
+					) a
+				GROUP BY
+					CHNLID
+			) c
+		SET b.last_update_date = c.DOCRELTIME
+		WHERE
+			b.chnlid = c.CHNLID
+	</update>
+
+</mapper>
+

+ 1 - 1
nngkxxdp/src/main/resources/mapper/PartitionDao.xml

@@ -48,7 +48,7 @@
     	SELECT * FROM t_partition_group WHERE group_id LIKE CONCAT('[',#{pid},',%') OR group_id LIKE CONCAT('%,',#{pid},',%') OR group_id LIKE CONCAT('%,',#{pid},']')
     </select>
     
-    <select id="getScoreByGroup">
+    <select id="getScoreByGroup" resultType="double">
     	SELECT SUM(score) FROM t_record WHERE DATE_FORMAT(create_time,'%Y-%m') = DATE_FORMAT(#{time},'%Y-%m') AND deptid = #{deptId} AND p_id 
 		in 
 		<foreach collection="array" item="item" index="index" open="(" close=")" separator=",">

+ 25 - 0
nngkxxdp/src/main/resources/mapper/TjDao.xml

@@ -258,6 +258,13 @@
 			</if>
 		</where>
 	</select>
+
+	<!-- 获取得分规则,排除自动计算 -->
+	<select id="getPartitionByTypeExcludeAutoCompute" resultType="java.util.Map">
+		SELECT * FROM t_partition
+		WHERE
+			is_count != 2 AND chnlid IS NOT NULL
+	</select>
 	
 	<!-- 获取南岸更新文章情况 -->
 	<select id="getArticleByUrlId" resultType="java.util.Map">
@@ -277,6 +284,24 @@
    			(#{item.pId}, #{item.deptId}, #{item.score}, #{item.type}, #{item.date}, #{item.cloumnName})
    		</foreach>
 	</insert>
+
+	<!-- 保存一次扣分记录 -->
+	<insert id="saveOnceRecord">
+		<foreach collection="list" item="item" separator=";">
+		INSERT IGNORE INTO t_record(p_id, deptid, score, type, create_time, cloumn_name, zdy_event)
+		SELECT #{item.pId}, #{item.deptId}, #{item.score}, #{item.type}, #{item.date}, #{item.cloumnName}, #{item.chnlid}
+		FROM
+		     dual
+		WHERE
+		    NOT EXISTS(
+		        SELECT p_id, deptid, DATE_FORMAT(create_time, '%Y-%m-%d')
+		        FROM
+					t_record
+		        WHERE
+					p_id = #{item.pId} AND deptid = #{item.deptId} AND DATE_FORMAT(create_time, '%Y-%m-%d') = DATE_FORMAT(#{item.date}, '%Y-%m-%d') AND type = 1
+			)
+		</foreach>
+	</insert>
 	
 	<!-- 获取其他栏目 -->
 	<select id="getColumnByDept" resultType="java.util.Map">