Browse Source

拆分sql

master
zxc 4 years ago
parent
commit
a7c4bd9031
  1. 5
      epmet-module/gov-issue/gov-issue-client/src/main/java/com/epmet/dto/result/ResiBuzzLeftPieChartResultDTO.java
  2. 3
      epmet-module/gov-issue/gov-issue-server/src/main/java/com/epmet/dao/IssueDao.java
  3. 26
      epmet-module/gov-issue/gov-issue-server/src/main/java/com/epmet/service/impl/IssueServiceImpl.java
  4. 69
      epmet-module/gov-issue/gov-issue-server/src/main/resources/mapper/IssueDao.xml

5
epmet-module/gov-issue/gov-issue-client/src/main/java/com/epmet/dto/result/ResiBuzzLeftPieChartResultDTO.java

@ -37,10 +37,13 @@ public class ResiBuzzLeftPieChartResultDTO implements Serializable {
*/
private String color;
@JsonIgnore
private String issueId;
public ResiBuzzLeftPieChartResultDTO() {
this.count = NumConstant.ZERO;
this.categoryCode = "";
this.categoryName = "";
this.color = "#0091ed";
this.color = "";
}
}

3
epmet-module/gov-issue/gov-issue-server/src/main/java/com/epmet/dao/IssueDao.java

@ -262,6 +262,9 @@ public interface IssueDao extends BaseDao<IssueEntity> {
*/
List<ResiBuzzLeftPieChartResultDTO> resiBuzzLeftPieChartByIssueIds(@Param("length")Integer length,@Param("issueIds")List<String> issueIds);
List<ResiBuzzLeftPieChartResultDTO> resiBuzzIssueCategoryByIssueIds(@Param("length")Integer length,@Param("issueIds")List<String> issueIds);
List<ResiBuzzLeftPieChartResultDTO> resiBuzzIssueCategoryNameByIssueIds(List<ResiBuzzLeftPieChartResultDTO> categories,@Param("customerId")String customerId);
/**
* @Description 查询前50名的议题ID
* @param orgId

26
epmet-module/gov-issue/gov-issue-server/src/main/java/com/epmet/service/impl/IssueServiceImpl.java

@ -1656,13 +1656,37 @@ public class IssueServiceImpl extends BaseServiceImpl<IssueDao, IssueEntity> imp
if(CollectionUtils.isEmpty(issueIds)){
return new ArrayList<>();
}
List<ResiBuzzLeftPieChartResultDTO> result = baseDao.resiBuzzLeftPieChartByIssueIds(length, issueIds);
List<ResiBuzzLeftPieChartResultDTO> categories = baseDao.resiBuzzIssueCategoryByIssueIds(length, issueIds);
List<ResiBuzzLeftPieChartResultDTO> pieChat = getPieChat(issueIds);
Iterator<ResiBuzzLeftPieChartResultDTO> list = pieChat.iterator();
while (list.hasNext()){
ResiBuzzLeftPieChartResultDTO next = list.next();
for (ResiBuzzLeftPieChartResultDTO category : categories) {
if (next.getIssueId().equals(category.getIssueId())){
list.remove();
continue;
}
}
}
categories.addAll(pieChat);
// List<ResiBuzzLeftPieChartResultDTO> result = baseDao.resiBuzzLeftPieChartByIssueIds(length, issueIds);
List<ResiBuzzLeftPieChartResultDTO> result = baseDao.resiBuzzIssueCategoryNameByIssueIds(categories, tokenDto.getCustomerId());
if (CollectionUtils.isEmpty(result)){
return new ArrayList<>();
}
return result;
}
public List<ResiBuzzLeftPieChartResultDTO> getPieChat(List<String> issueIds){
List<ResiBuzzLeftPieChartResultDTO> resultDTOS = new ArrayList<>();
issueIds.forEach(i -> {
ResiBuzzLeftPieChartResultDTO dto = new ResiBuzzLeftPieChartResultDTO();
dto.setIssueId(i);
resultDTOS.add(dto);
});
return resultDTOS;
}
/**
* @Description 查询组织下每个网格的项目数
* @param formDTO

69
epmet-module/gov-issue/gov-issue-server/src/main/resources/mapper/IssueDao.xml

@ -621,25 +621,25 @@
<!-- 查询居民热议左侧饼图 -->
<select id="resiBuzzLeftPieChart" resultType="com.epmet.dto.result.ResiBuzzLeftPieChartResultDTO">
SELECT COUNT(issueId) AS count,categoryCode,categoryName,color FROM
(SELECT
i.ID AS issueId,
IFNULL(LEFT(ic.CATEGORY_CODE,#{length}),'') AS categoryCode,
IFNULL(cd.CATEGORY_NAME,'其他') AS categoryName,
IFNULL(cd.color,'#0091ed') AS color
FROM issue i
INNER JOIN issue_vote_statistical s ON (s.ISSUE_ID = i.ID AND s.DEL_FLAG = '0')
LEFT JOIN issue_category ic ON (ic.ISSUE_ID = i.ID AND ic.DEL_FLAG = '0' AND ic.CUSTOMER_ID = i.CUSTOMER_ID)
LEFT JOIN issue_project_category_dict cd ON (cd.CATEGORY_CODE = LEFT(ic.CATEGORY_CODE,#{length}) AND cd.DEL_FLAG = '0' AND cd.CUSTOMER_ID = ic.CUSTOMER_ID)
WHERE i.DEL_FLAG = '0'
<if test='orgType == "grid" '>
AND i.GRID_ID = #{orgId}
</if>
<if test='orgType == "agency" '>
AND i.ORG_ID_PATH LIKE CONCAT('%',#{orgId},'%')
</if>
ORDER BY (s.SUPPORT_COUNT + s.OPPOSITION_COUNT) DESC,i.created_time DESC LIMIT 50)temp
GROUP BY categoryName
SELECT COUNT(t2.issueId) AS count,cd.CATEGORY_CODE,IFNULL(cd.CATEGORY_NAME,'其他') AS categoryName, IFNULL(cd.COLOR,'#0091ed') AS color FROM
(SELECT t1.issueId AS issueId,IFNULL(LEFT(ic.CATEGORY_CODE,#{length}),'') AS categoryCode FROM
(SELECT
i.ID AS issueId
FROM issue i
INNER JOIN issue_vote_statistical s ON (s.ISSUE_ID = i.ID AND s.DEL_FLAG = '0')
WHERE i.DEL_FLAG = '0'
<if test='orgType == "grid" '>
AND i.GRID_ID = #{orgId}
</if>
<if test='orgType == "agency" '>
AND i.ORG_ID_PATH LIKE CONCAT('%',#{orgId},'%')
</if>
ORDER BY (s.SUPPORT_COUNT + s.OPPOSITION_COUNT) DESC,i.created_time DESC LIMIT 50)t1
LEFT JOIN issue_category ic ON (t1.issueId = ic.ISSUE_ID AND ic.DEL_FLAG = '0')
GROUP BY t1.issueId,categoryCode)t2
LEFT JOIN issue_project_category_dict cd ON (cd.CATEGORY_CODE = t2.categoryCode AND cd.CUSTOMER_ID = #{customerId} AND cd.DEL_FLAG = '0' )
GROUP BY cd.CATEGORY_NAME
</select>
<!-- 查询组织下每个网格的项目数 -->
@ -700,11 +700,38 @@
IFNULL(cd.CATEGORY_NAME,'其他') AS categoryName,
IFNULL(cd.color,'#0091ed') AS color
FROM issue_category ic
INNER JOIN issue_project_category_dict cd ON (cd.CATEGORY_CODE = LEFT(ic.CATEGORY_CODE,#{length}) AND cd.DEL_FLAG = '0' AND cd.CUSTOMER_ID = ic.CUSTOMER_ID)
LEFT JOIN issue_project_category_dict cd ON (cd.CATEGORY_CODE = LEFT(ic.CATEGORY_CODE,#{length}) AND cd.DEL_FLAG = '0' AND cd.CUSTOMER_ID = ic.CUSTOMER_ID)
AND ic.ISSUE_ID IN (
<foreach collection="issueIds" item="issueId" separator=",">
#{issueId}
</foreach>
) GROUP BY categoryName
) GROUP BY categoryCode
</select>
<select id="resiBuzzIssueCategoryByIssueIds"
resultType="com.epmet.dto.result.ResiBuzzLeftPieChartResultDTO">
SELECT
ISSUE_ID ,
IFNULL(LEFT(CATEGORY_CODE,2),'') AS categoryCode
FROM issue_category
WHERE DEL_FLAG = '0'
AND ISSUE_ID IN(
<foreach collection="issueIds" item="issueId" separator=",">
#{issueId}
</foreach>
)
GROUP BY issue_id,categoryCode
</select>
<select id="resiBuzzIssueCategoryNameByIssueIds"
resultType="com.epmet.dto.result.ResiBuzzLeftPieChartResultDTO">
select count(t2.issueId) as count , t2.categoryCode,t2.categoryName,t2.color from
(<foreach collection="categories" item="c" separator="UNION ALL">
select
t1.issueId as issueId,
cd.CATEGORY_CODE as categoryCode,
IFNULL(cd.CATEGORY_NAME,'其他') AS categoryName,
IFNULL(cd.COLOR,'#0091ed') AS color
from (select #{c.issueId} as issueId,#{c.categoryCode} as categoryCode) t1
LEFT JOIN issue_project_category_dict cd ON (cd.CATEGORY_CODE = t1.categoryCode AND cd.CUSTOMER_ID = #{customerId} AND cd.DEL_FLAG = '0' )
</foreach>)t2
</select>
</mapper>
Loading…
Cancel
Save