Kaynağa Gözat

作者:张哲
时间:2023/05/24
类型:需求变更
描述:里程碑(3) 搜索统计

zizg 1 yıl önce
ebeveyn
işleme
5e26bfd130

+ 2 - 2
src/main/java/com/redxun/knowledge/analysis/controller/AnalysisCommonController.java

@@ -256,7 +256,7 @@ public class AnalysisCommonController {
                                          @RequestParam("organizationId") String organizationId,
                                          @RequestParam(value = "createTime",required = false) String createTime,
                                          @RequestParam(value = "endTime",required = false) String  endTime) {
-        OrganizationSearchVo result = analysisSearchService.organizationSearch(type, organizationId,createTime,endTime,null);
+        OrganizationSearchVo result = analysisSearchService.organizationSearch(type, organizationId,createTime,endTime);
         return JsonResult.getSuccessResult(result);
     }
 
@@ -267,7 +267,7 @@ public class AnalysisCommonController {
         if (validResult.hasErrors()) {
             return jsonResult.setMessage("组织Id不能为空");
         }
-        OrganizationSearchVo result = analysisSearchService.personSearch(personVisitDto);
+        List<OrganizationSearchVo> result = analysisSearchService.personSearch(personVisitDto);
         return JsonResult.getSuccessResult(result);
     }
 

+ 12 - 2
src/main/java/com/redxun/knowledge/analysis/mapper/AnalysisSearchMapper.java

@@ -1,5 +1,6 @@
 package com.redxun.knowledge.analysis.mapper;
 
+import com.redxun.knowledge.analysis.entity.vo.MapCompanyVo;
 import com.redxun.knowledge.analysis.entity.vo.OrganizationSearchVo;
 import com.redxun.knowledge.analysis.entity.vo.SystemCompanyVo;
 import com.redxun.knowledge.analysis.entity.vo.SystemDetailVisitsVo;
@@ -50,6 +51,15 @@ public interface AnalysisSearchMapper {
      * @return
      */
     List<Map<String, Object>> organizationSearch(@Param("firstDay") String firstDay, @Param("lastDay") String lastDay,
-                                                 @Param("organizationId") String organizationId,
-                                                 @Param("personList") List<String> personId);
+                                                 @Param("organizationId") String organizationId);
+
+    /**
+     * 人员访问量
+     * @param id
+     * @param createTime
+     * @param endTime
+     * @param round
+     * @return
+     */
+    List<Map<String, Object>> personSearchValue(@Param("id") String id, @Param("firstDay")String createTime, @Param("lastDay")String endTime, @Param("round") Integer round);
 }

+ 76 - 29
src/main/java/com/redxun/knowledge/analysis/service/AnalysisSearchServiceImpl.java

@@ -117,11 +117,7 @@ public class AnalysisSearchServiceImpl {
      * @param organizationId
      * @return
      */
-    public OrganizationSearchVo organizationSearch(String type, String organizationId,String createTime,String endTime,List<String> personId) {
-        //存在人员,统计人员
-        if (!CollectionUtils.isEmpty(personId)){
-            organizationId = null;
-        }
+    public OrganizationSearchVo organizationSearch(String type, String organizationId,String createTime,String endTime) {
         //开始时间和结束时间都不为空,按照选中时间过滤,忽略type
         if (!StringUtils.isEmpty(createTime) && !StringUtils.isEmpty(endTime)){
             type = null;
@@ -132,35 +128,31 @@ public class AnalysisSearchServiceImpl {
         OrganizationSearchVo organizationSearchVo = new OrganizationSearchVo();
         List<Map<String, Object>> item = new ArrayList<>();
         if (("total").equals(type)) {
-            item = analysisSearchMapper.organizationSearch(null, null, organizationId,personId);
+            item = analysisSearchMapper.organizationSearch(null, null, organizationId);
         } else if (("year").equals(type)) {
             item = analysisSearchMapper.organizationSearch(DateUtils.format(DateUtils.getFirstOfYear(year)),
-                    DateUtils.format(DateUtils.getLastOfYear(year)), organizationId,personId);
+                    DateUtils.format(DateUtils.getLastOfYear(year)), organizationId);
         } else if (("month").equals(type)) {
             int month = calendar.get(Calendar.MONTH);
             String firstOfMonth = DateUtils.getFirstOfMonth(year, month + 1, 15);
             String lastOfMonth = DateUtils.getLastOfMonth(year, month + 1, 15);
-            item = analysisSearchMapper.organizationSearch(firstOfMonth, lastOfMonth, organizationId,personId);
+            item = analysisSearchMapper.organizationSearch(firstOfMonth, lastOfMonth, organizationId);
         } else {
-            item = analysisSearchMapper.organizationSearch(createTime,endTime, organizationId,personId);
+            item = analysisSearchMapper.organizationSearch(createTime,endTime, organizationId);
         }
         String deptPath = pvLogMapper.findAllDeptIdByDeptId(organizationId);
-        if (CollectionUtils.isEmpty(personId)) {
-            if (StringUtils.isNotEmpty(deptPath)) {
-                deptPath = deptPath.substring(deptPath.indexOf(".") + 1);
-                String[] split = deptPath.split("\\.");
-                if (split.length > 6) {
-                    String first = Arrays.stream(split).limit(3).map(e -> userService.findDeptByDeptId(e).getName()).collect(Collectors.joining(">"));
-                    String end = Arrays.stream(split).skip(split.length - 3).map(e -> userService.findDeptByDeptId(e).getName()).collect(Collectors.joining(">"));
-                    organizationSearchVo.setOrganization(first + ">...>" + end);
-                } else {
-                    String organization = Arrays.stream(split).map(e -> userService.findDeptByDeptId(e).getName()).collect(Collectors.joining(">"));
-                    organizationSearchVo.setOrganization(organization);
-                }
+
+        if (StringUtils.isNotEmpty(deptPath)) {
+            deptPath = deptPath.substring(deptPath.indexOf(".") + 1);
+            String[] split = deptPath.split("\\.");
+            if (split.length > 6) {
+                String first = Arrays.stream(split).limit(3).map(e -> userService.findDeptByDeptId(e).getName()).collect(Collectors.joining(">"));
+                String end = Arrays.stream(split).skip(split.length - 3).map(e -> userService.findDeptByDeptId(e).getName()).collect(Collectors.joining(">"));
+                organizationSearchVo.setOrganization(first + ">...>" + end);
+            } else {
+                String organization = Arrays.stream(split).map(e -> userService.findDeptByDeptId(e).getName()).collect(Collectors.joining(">"));
+                organizationSearchVo.setOrganization(organization);
             }
-        } else {
-            String fullName = personId.parallelStream().map(e -> userService.queryOsUserDto(e).getFullName()).collect(Collectors.joining(","));
-            organizationSearchVo.setOrganization(fullName);
         }
         Optional<BigDecimal> total = item.stream().map(e -> (BigDecimal) e.get("value")).reduce(BigDecimal::add);
         Map<String, Object> map = new HashMap<>();
@@ -176,11 +168,66 @@ public class AnalysisSearchServiceImpl {
      * @param personVisitDto
      * @return
      */
-    public OrganizationSearchVo personSearch(PersonVisitDto personVisitDto) {
-        //如果组织id不为空,人员id为空情况下,显示组织访问量
-        OrganizationSearchVo organizationSearchVo = this.organizationSearch(personVisitDto.getType(), personVisitDto.getOrganizationId(),
-                personVisitDto.getCreateTime(), personVisitDto.getEndTime(), personVisitDto.getPersonId());
-        return organizationSearchVo;
+    public List<OrganizationSearchVo> personSearch(PersonVisitDto personVisitDto) {
+        List<OrganizationSearchVo> searchCompanyVoList = new ArrayList<>();
+        //开始时间和结束时间都不为空,按照选中时间过滤,忽略type
+        if (!StringUtils.isEmpty(personVisitDto.getCreateTime()) && !StringUtils.isEmpty(personVisitDto.getEndTime())){
+            personVisitDto.setType(null);
+        }
+        //查询人员
+        if (!CollectionUtils.isEmpty(personVisitDto.getPersonId())){
+            personVisitDto.setOrganizationId(null);
+            searchCompanyVoList = personSearchValue(personVisitDto.getPersonId(),personVisitDto.getType(),personVisitDto.getCreateTime(),personVisitDto.getEndTime(),1);
+        } else {
+            //查询部门
+            String[] split = personVisitDto.getOrganizationId().split(",");
+            List<String> organizationIdList = Arrays.asList(split);
+            searchCompanyVoList = personSearchValue(organizationIdList,personVisitDto.getType(),personVisitDto.getCreateTime(),personVisitDto.getEndTime(),2);
+        }
+        return searchCompanyVoList;
+    }
+
+    /**
+     * 人员创建地图赋值
+     * @param list
+     * @return
+     */
+    private List<OrganizationSearchVo> personSearchValue(List<String> list,String type,String createTime,String endTime,Integer round){
+
+        List<OrganizationSearchVo> result = list.parallelStream().map(e -> {
+            //获取当前年
+            Calendar calendar = Calendar.getInstance();
+            int year = calendar.get(Calendar.YEAR);
+            OrganizationSearchVo organizationSearchVo = new OrganizationSearchVo();
+            List<Map<String, Object>> item = new ArrayList<>();
+            //查询知识分类下创建的知识数量(纬度:年 最近1个月 全部)
+            if (type.equals("total")) {
+                item = analysisSearchMapper.personSearchValue(e, null, null,round);
+            } else if (type.equals("year")) {
+                item = analysisSearchMapper.personSearchValue(e, DateUtils.format(DateUtils.getFirstOfYear(year)),
+                        DateUtils.format(DateUtils.getLastOfYear(year)),round);
+            } else if (type.equals("month")) {
+                int month = calendar.get(Calendar.MONTH);
+                String firstOfMonth = DateUtils.getFirstOfMonth(year, month + 1, 15);
+                String lastOfMonth = DateUtils.getLastOfMonth(year, month + 1, 15);
+                item = analysisSearchMapper.personSearchValue(e, firstOfMonth, lastOfMonth,round);
+            } else {
+                item = analysisSearchMapper.personSearchValue(e,createTime, endTime, round);
+            }
+            Optional<BigDecimal> total = item.stream().map(h -> (BigDecimal) h.get("value")).reduce(BigDecimal::add);
+            Map<String, Object> map = new HashMap<>();
+            map.put("name", "访问总量");
+            map.put("value", total.get());
+            item.add(0,map);
+            organizationSearchVo.setItem(item);
+            if (round == 1){
+                organizationSearchVo.setOrganization(userService.queryOsUserDto(e).getFullName());
+            } else {
+                organizationSearchVo.setOrganization(userService.findDeptByDeptId(e).getName());
+            }
+            return organizationSearchVo;
+        }).collect(Collectors.toList());
+        return result;
 
     }
 }

+ 4 - 7
src/main/java/com/redxun/knowledge/controller/KnowledgeController.java

@@ -71,7 +71,7 @@ public class KnowledgeController extends BaseController<Knowledge> {
     @ApiOperation(value = "新增知识", httpMethod = "POST")
     @PostMapping("create")
     public JsonResult create(@RequestBody KnowledgeDto knowledgeDto) {
-        JsonResult jsonResult = JsonResult.getSuccessResult("新增知识成功!");
+        JsonResult jsonResult = JsonResult.getSuccessResult("提交成功!");
         if (knowledgeDto.getIsDraft() != null && knowledgeDto.getIsDraft() == 1) {
 
             Set<ConstraintViolation<KnowledgeDto>> violations = validator.validate(knowledgeDto, AddGroup.class);
@@ -81,7 +81,7 @@ public class KnowledgeController extends BaseController<Knowledge> {
             }
         }
         if (knowledgeDto.getIsDraft() != null && knowledgeDto.getIsDraft() == 0) {
-            jsonResult.setMessage("知识暂存成功!");
+            jsonResult.setMessage("提交成功!");
         }
         String pkId = null;
         try {
@@ -104,15 +104,12 @@ public class KnowledgeController extends BaseController<Knowledge> {
         } catch (Exception e) {
             jsonResult.setMessage(e.getMessage());
             jsonResult.setSuccess(false);
+            return jsonResult;
         }
         if (update == -1) {
             return JsonResult.Success("知识正在审核中,无法修改");
         } else {
-            if (entity.getIsDraft() != null && entity.getIsDraft() == 0) {
-                jsonResult.setMessage("知识暂存成功!");
-            } else {
-                jsonResult.setMessage("修改知识成功!");
-            }
+            jsonResult.setMessage("提交成功!");
             return jsonResult;
         }
     }

+ 1 - 1
src/main/java/com/redxun/knowledge/service/KnowledgeServiceImpl.java

@@ -367,7 +367,7 @@ public class KnowledgeServiceImpl extends SuperServiceImpl<KnowledgeMapper, Know
     @Transactional(rollbackFor = Exception.class)
     @Override
     public int update(Knowledge entity) {
-        if (Objects.isNull(knowledgeCategoryMapper.selectById(entity.getCategoryId()))){
+        if (Objects.isNull(knowledgeCategoryMapper.selectById(entity.getCategoryId())) && entity.getIsDraft() == 1){
             throw new RuntimeException("输入的分类不存在,请重新输入");
         }
         Knowledge knowledge = this.get(entity.getPkId());

+ 27 - 5
src/main/resources/mapper/knowledge/analysis/AnalysisSearchMapper.xml

@@ -170,11 +170,33 @@
             )
             )
             </if>
-            <if test="personList != null and personList.size > 0">
-                USER_ID IN
-                <foreach collection="personList" item="id" open="(" close=")" separator=",">
-                    #{id}
-                </foreach>
+            <if test="firstDay != null and lastDay != null">
+                and TO_CHAR(CREATE_TIME_,'yyyy-mm-dd') &gt;= #{firstDay}
+                and TO_CHAR(CREATE_TIME_,'yyyy-mm-dd') &lt;= #{lastDay}
+            </if>
+        </where>
+        group by PLATFORM
+        ) t1
+        right join
+        (SELECT dic.NAME_ legend,
+        dic.VALUE_ legendValue
+        FROM LEARNING_SYSTEM_DEV.SYS_TREE tree
+        INNER JOIN LEARNING_SYSTEM_DEV.SYS_DIC dic ON tree.TREE_ID_ = dic.TREE_ID_
+        WHERE ALIAS_ = 'KNOWLEDGE_PLATFORM') t2
+        on t1.name = t2.legend
+    </select>
+
+    <select id="personSearchValue" resultMap="mapResult">
+        select t2.legend name,nvl(t1.value,0) value from (
+        select PLATFORM name,count(*) value from KM_PV_LOG
+        <where>
+            <if test="round == 2">
+                COMPANY_ID
+                in ( SELECT GROUP_ID_ FROM LEARNING_USER_DEV.OS_GROUP c START WITH c.GROUP_ID_ = #{id} CONNECT
+                BY PRIOR c.GROUP_ID_ = c.PARENT_ID_ )
+            </if>
+            <if test="round == 1">
+                USER_ID  = #{id}
             </if>
             <if test="firstDay != null and lastDay != null">
                 and TO_CHAR(CREATE_TIME_,'yyyy-mm-dd') &gt;= #{firstDay}