Browse Source

新网格分类统计

dev_shibei_match
zxc 4 years ago
parent
commit
66cf45470d
  1. 69
      epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/dto/screen/result/GridAndOrgCategoryCountResultDTO.java
  2. 3
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/constant/ProjectConstant.java
  3. 5
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/evaluationindex/screen/ScreenProjectDataDao.java
  4. 34
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/screen/ScreenProjectCategoryGridAndOrgDailyService.java
  5. 123
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/screen/impl/ScreenProjectCategoryGridAndOrgDailyServiceImpl.java
  6. 58
      epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/evaluationindex/screen/ScreenProjectDataDao.xml

69
epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/dto/screen/result/GridAndOrgCategoryCountResultDTO.java

@ -0,0 +1,69 @@
package com.epmet.dto.screen.result;
import com.epmet.commons.tools.constant.NumConstant;
import lombok.Data;
import java.io.Serializable;
/**
* @Author zxc
* @DateTime 2021/11/10 10:36 上午
* @DESC
*/
@Data
public class GridAndOrgCategoryCountResultDTO implements Serializable {
private static final long serialVersionUID = -5167964547464983118L;
/**
* 组织ID
*/
private String orgId;
/**
* 网格ID
*/
private String gridId;
/**
* 上级组织ID
*/
private String pid;
/**
* 所有上级组织ID
*/
private String pids;
private String dateId;
private String customerId;
/**
* 分类CODE
*/
private String categoryCode;
/**
* 分类CODE级别
*/
private Integer level;
/**
* 项目总数
*/
private Integer projectTotal;
/**
* 关闭结案项目总数
*/
private Integer closedProjectTotal;
public GridAndOrgCategoryCountResultDTO() {
this.orgId = "";
this.categoryCode = "";
this.level = NumConstant.ZERO;
this.projectTotal = NumConstant.ZERO;
this.closedProjectTotal = NumConstant.ZERO;
}
}

3
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/constant/ProjectConstant.java

@ -90,4 +90,7 @@ public interface ProjectConstant {
* 上报
*/
String PROJECT_REPORT="02";
String PROJECT_STATUS_CLOSED = "closed";
String PROJECT_STATUS_ALL = "all";
}

5
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/evaluationindex/screen/ScreenProjectDataDao.java

@ -19,6 +19,7 @@ package com.epmet.dao.evaluationindex.screen;
import com.epmet.commons.mybatis.dao.BaseDao;
import com.epmet.dto.screen.ScreenProjectDataDTO;
import com.epmet.dto.screen.result.GridAndOrgCategoryCountResultDTO;
import com.epmet.entity.evaluationindex.screen.ScreenProjectDataEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
@ -68,4 +69,8 @@ public interface ScreenProjectDataDao extends BaseDao<ScreenProjectDataEntity> {
int updateProjectSatisfactionScore(@Param("projectId")String projectId, @Param("score")BigDecimal score);
List<ScreenProjectDataDTO> selectProjectList(@Param("customerId") String customerId, @Param("projectId") String projectId);
List<GridAndOrgCategoryCountResultDTO> selectGridCategoryProjectCount(@Param("customerIds") List<String> customerIds,@Param("dateId") String dateId,
@Param("status")String status,@Param("customerId") String customerId,
@Param("subCount")Integer subCount);
}

34
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/screen/ScreenProjectCategoryGridAndOrgDailyService.java

@ -0,0 +1,34 @@
package com.epmet.service.evaluationindex.screen;
import com.epmet.commons.mybatis.service.BaseService;
import com.epmet.commons.tools.page.PageData;
import com.epmet.dto.screen.ScreenProjectCategoryOrgDailyDTO;
import com.epmet.dto.screencoll.ScreenCollFormDTO;
import com.epmet.entity.evaluationindex.screen.ScreenProjectCategoryOrgDailyEntity;
import java.util.List;
import java.util.Map;
/**
* 项目(事件)分类按 组织组织按天统计
*/
public interface ScreenProjectCategoryGridAndOrgDailyService {
/**
* @Description 分类下的项目数grid
* @param customerId
* @param dateId
* @author zxc
* @date 2021/11/10 10:23 上午
*/
void extractCategoryProjectGridData(String customerId, String dateId);
/**
* @Description 分类下的项目数org
* @param customerId
* @param dateId
* @author zxc
* @date 2021/11/10 10:23 上午
*/
void extractCategoryProjectOrgData(String customerId, String dateId);
}

123
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/screen/impl/ScreenProjectCategoryGridAndOrgDailyServiceImpl.java

@ -0,0 +1,123 @@
package com.epmet.service.evaluationindex.screen.impl;
import com.alibaba.fastjson.JSON;
import com.epmet.commons.dynamic.datasource.annotation.DataSource;
import com.epmet.commons.tools.constant.NumConstant;
import com.epmet.commons.tools.utils.ConvertUtils;
import com.epmet.constant.DataSourceConstant;
import com.epmet.constant.ProjectConstant;
import com.epmet.dao.evaluationindex.screen.ScreenProjectCategoryGridDailyDao;
import com.epmet.dao.evaluationindex.screen.ScreenProjectCategoryOrgDailyDao;
import com.epmet.dao.evaluationindex.screen.ScreenProjectDataDao;
import com.epmet.dto.screen.result.GridAndOrgCategoryCountResultDTO;
import com.epmet.entity.crm.CustomerRelationEntity;
import com.epmet.entity.evaluationindex.screen.ScreenProjectCategoryGridDailyEntity;
import com.epmet.service.crm.CustomerRelationService;
import com.epmet.service.evaluationindex.screen.ScreenProjectCategoryGridAndOrgDailyService;
import com.epmet.service.evaluationindex.screen.ScreenProjectCategoryGridDailyService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.ListUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/**
* @Author zxc
* @DateTime 2021/11/10 10:25 上午
* @DESC
*/
@Service
@DataSource(DataSourceConstant.EVALUATION_INDEX)
@Slf4j
public class ScreenProjectCategoryGridAndOrgDailyServiceImpl implements ScreenProjectCategoryGridAndOrgDailyService{
@Autowired
private ScreenProjectDataDao screenProjectDataDao;
@Autowired
private CustomerRelationService relationService;
@Autowired
private ScreenProjectCategoryGridDailyDao gridDailyDao;
@Autowired
private ScreenProjectCategoryGridDailyService gridDailyService;
@Autowired
private ScreenProjectCategoryOrgDailyDao orgDailyDao;
/**
* @Description 分类下的项目数grid
* @param customerId
* @param dateId
* @author zxc
* @date 2021/11/10 10:23 上午
*/
@Override
public void extractCategoryProjectGridData(String customerId, String dateId) {
List<CustomerRelationEntity> relationInfo = relationService.selectSubCustomer(customerId);
List<String> customerIds = new ArrayList<>();
customerIds.add(customerId);
List<GridAndOrgCategoryCountResultDTO> allList = new ArrayList<>();
List<GridAndOrgCategoryCountResultDTO> closedList = new ArrayList<>();
if (CollectionUtils.isNotEmpty(relationInfo)){
// 单客户
allList = screenProjectDataDao.selectGridCategoryProjectCount(customerIds, dateId, ProjectConstant.PROJECT_STATUS_ALL,customerId, NumConstant.FOUR);
closedList = screenProjectDataDao.selectGridCategoryProjectCount(customerIds, dateId, ProjectConstant.PROJECT_STATUS_CLOSED,customerId, NumConstant.FOUR);
}else {
// 多客户
List<String> subCustomerIds = relationInfo.stream().map(CustomerRelationEntity::getCustomerId).collect(Collectors.toList());
customerIds.addAll(subCustomerIds);
allList = screenProjectDataDao.selectGridCategoryProjectCount(customerIds, dateId, ProjectConstant.PROJECT_STATUS_ALL,customerId, NumConstant.TWO);
closedList = screenProjectDataDao.selectGridCategoryProjectCount(customerIds, dateId, ProjectConstant.PROJECT_STATUS_CLOSED,customerId, NumConstant.TWO);
}
List<GridAndOrgCategoryCountResultDTO> finalClosedList = closedList;
allList.forEach(a -> finalClosedList.stream().filter(c -> c.getOrgId().equals(a.getOrgId()) && c.getCategoryCode().equals(a.getCategoryCode())).forEach(c -> a.setClosedProjectTotal(c.getClosedProjectTotal())));
gridDel(customerId,dateId);
gridInsert(allList);
}
/**
* @Description 项目分类网格删除
* @param customerId
* @param dateId
* @author zxc
* @date 2021/11/10 1:55 下午
*/
@Transactional(rollbackFor = Exception.class)
public void gridDel(String customerId,String dateId){
Integer num = NumConstant.ZERO;
do {
num = gridDailyDao.deleteByDateIdAndCustomerId(customerId, dateId);
}while (num > NumConstant.ZERO && num == NumConstant.ONE_THOUSAND);
}
/**
* @Description 项目分类网格添加
* @param needInsert
* @author zxc
* @date 2021/11/10 1:55 下午
*/
@Transactional(rollbackFor = Exception.class)
public void gridInsert(List<GridAndOrgCategoryCountResultDTO> needInsert){
List<List<GridAndOrgCategoryCountResultDTO>> partition = ListUtils.partition(needInsert, NumConstant.ONE_HUNDRED);
partition.forEach(p -> {
gridDailyService.insertBatch(ConvertUtils.sourceToTarget(p,ScreenProjectCategoryGridDailyEntity.class));
log.info("插入的网格项目分类为" + JSON.toJSONString(p));
});
}
/**
* @Description 分类下的项目数org
* @param customerId
* @param dateId
* @author zxc
* @date 2021/11/10 10:23 上午
*/
@Override
public void extractCategoryProjectOrgData(String customerId, String dateId) {
}
}

58
epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/evaluationindex/screen/ScreenProjectDataDao.xml

@ -269,4 +269,62 @@
ORDER BY
a.CREATED_TIME ASC
</select>
<select id="selectGridCategoryProjectCount" resultType="com.epmet.dto.screen.result.GridAndOrgCategoryCountResultDTO">
SELECT
#{dateId} AS dateId,
#{customerId} AS customerId,
pc.CATEGORY_CODE,
pd.ORG_ID AS gridId,
pd.PARENT_ID AS pid,
pd.ALL_PARENT_IDS AS pids,
pc.`LEVEL`,
<if test=' status = "closed" '>
COUNT(DISTINCT pc.PROJECT_ID) AS projectTotal
</if>
<if test=' status = "all" '>
COUNT(DISTINCT pc.PROJECT_ID) AS closedProjectTotal
</if>
FROM screen_project_data pd
LEFT JOIN screen_project_category pc ON (pc.PROJECT_ID = pd.PROJECT_ID AND pc.DEL_FLAG = '0')
WHERE pd.DEL_FLAG = '0'
AND pd.CUSTOMER_ID IN
<foreach collection="customerIds" item="c" separator="," open="(" close=")">
#{c}
</foreach>
AND DATE_FORMAT(pd.PROJECT_CREATE_TIME,'%Y%m%d') = #{dateId}
AND pd.ORG_TYPE = 'grid'
<if test=' status = "closed" '>
AND pd.PROJECT_STATUS_CODE IN ('closed','closed_case')
</if>
GROUP BY pd.ORG_ID,pc.CATEGORY_CODE
UNION ALL
SELECT
#{dateId} AS dateId,
#{customerId} AS customerId,
left(pc.CATEGORY_CODE, #{subCount}) AS categoryCode,
pd.ORG_ID AS gridId,
pd.PARENT_ID AS pid,
pd.ALL_PARENT_IDS AS pids,
1 AS level,
<if test=' status = "closed" '>
COUNT(DISTINCT pc.PROJECT_ID) AS projectTotal
</if>
<if test=' status = "all" '>
COUNT(DISTINCT pc.PROJECT_ID) AS closedProjectTotal
</if>
FROM screen_project_data pd
LEFT JOIN screen_project_category pc ON (pc.PROJECT_ID = pd.PROJECT_ID AND pc.DEL_FLAG = '0')
WHERE pd.DEL_FLAG = '0'
AND pd.CUSTOMER_ID IN
<foreach collection="customerIds" item="c" separator="," open="(" close=")">
#{c}
</foreach>
AND DATE_FORMAT(pd.PROJECT_CREATE_TIME,'%Y%m%d') = #{dateId}
AND pd.ORG_TYPE = 'grid'
<if test=' status = "closed" '>
AND pd.PROJECT_STATUS_CODE IN ('closed','closed_case')
</if>
GROUP BY pd.ORG_ID,categoryCode
</select>
</mapper>

Loading…
Cancel
Save