feat:견문통계 초기저장(작업중)

TaehunPark 2022-10-21 16:26:02 +09:00
parent bf06615c2f
commit feac42f5c2
7 changed files with 620 additions and 0 deletions

View File

@ -4,6 +4,7 @@ import com.dbnt.faisp.authMgt.service.AuthMgtService;
import com.dbnt.faisp.codeMgt.service.CodeMgtService;
import com.dbnt.faisp.fpiMgt.affair.model.AffairBoard;
import com.dbnt.faisp.fpiMgt.affair.model.AffairRating;
import com.dbnt.faisp.fpiMgt.affair.model.TypeStatistics;
import com.dbnt.faisp.fpiMgt.affair.service.AffairService;
import com.dbnt.faisp.userInfo.model.UserInfo;
import lombok.RequiredArgsConstructor;
@ -16,6 +17,7 @@ import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@ -228,4 +230,68 @@ public class AffairController { // 첩보수집활동 > 외사경찰 견문관
public Integer affairStateChange(@AuthenticationPrincipal UserInfo loginUser, @RequestBody List<AffairRating> ratingList){
return affairService.affairStateChange(loginUser, ratingList);
}
@GetMapping("/statistics")
public ModelAndView statistics(@AuthenticationPrincipal UserInfo loginUser, TypeStatistics typeStatistics){
ModelAndView mav = new ModelAndView("igActivities/fpiMgt/affair/affairStatistics");
List<TypeStatistics> type1 = affairService.selectType1List(typeStatistics);
List<TypeStatistics> type2 = affairService.selectType2List(typeStatistics);
List<TypeStatistics> type3 = affairService.selectType3List(typeStatistics);
List<TypeStatistics> type4 = affairService.selectType4List(typeStatistics);
List<TypeStatistics> type1List = affairService.selecType1ListCnt(typeStatistics);
List<TypeStatistics> type2List = affairService.selecType2ListCnt(typeStatistics);
List<TypeStatistics> type3List = affairService.selecType3ListCnt(typeStatistics);
List<TypeStatistics> type4List = affairService.selecType4ListCnt(typeStatistics);
List<TypeStatistics> totalList = affairService.selectStatusTotal(typeStatistics);
TypeStatistics total = new TypeStatistics();
total.setItemValue("누계");
total.setWrtOrgan("total");
total.setCnt(0);
for(TypeStatistics stat: totalList) {
total.setCnt(total.getCnt()+stat.getCnt());
}
totalList.add(total);
mav.addObject("totalList", totalList);
type1List = addTotalRow(type1, type1List);
type2List = addTotalRow(type2, type2List);
type3List = addTotalRow(type3, type3List);
type4List = addTotalRow(type4, type4List);
mav.addObject("type1", type1);
mav.addObject("type2", type2);
mav.addObject("type3", type3);
mav.addObject("type4", type4);
mav.addObject("type1List", type1List);
mav.addObject("type2List", type2List);
mav.addObject("type3List", type3List);
mav.addObject("type4List", type4List);
mav.addObject("searchParams", typeStatistics);
//메뉴권한 확인
String accessAuth = authMgtService.selectAccessConfigList(loginUser.getUserSeq(), "/translator/info").get(0).getAccessAuth();
mav.addObject("accessAuth", accessAuth);
mav.addObject("mgtOrganList", loginUser.getDownOrganCdList());
return mav;
}
private List<TypeStatistics> addTotalRow(List<TypeStatistics> type, List<TypeStatistics> typeList){
Map<String, Integer> totalMap = new HashMap<>();
for(TypeStatistics t: type) {
totalMap.put(t.getAffairType(), 0);
}
for(TypeStatistics t: typeList) {
totalMap.put(t.getAffairType(), totalMap.get(t.getAffairType())+t.getCnt());
}
Iterator<String> keys = totalMap.keySet().iterator();
while(keys.hasNext()) {
String affairType = keys.next();
Integer cnt = totalMap.get(affairType);
TypeStatistics total = new TypeStatistics();
total.setWrtOrgan("total");
total.setAffairType(affairType);
total.setCnt(cnt);
typeList.add(total);
}
return typeList;
}
}

View File

@ -1,6 +1,8 @@
package com.dbnt.faisp.fpiMgt.affair.mapper;
import com.dbnt.faisp.fpiMgt.affair.model.AffairBoard;
import com.dbnt.faisp.fpiMgt.affair.model.TypeStatistics;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
@ -13,4 +15,22 @@ public interface AffairMapper {
Integer selectAffairBoardCnt(AffairBoard affair);
String selectHashTags(Integer affairKey);
List<TypeStatistics> selectType1List(TypeStatistics typeStatistics);
List<TypeStatistics> selectType2List(TypeStatistics typeStatistics);
List<TypeStatistics> selectType3List(TypeStatistics typeStatistics);
List<TypeStatistics> selectType4List(TypeStatistics typeStatistics);
List<TypeStatistics> selectStatusTotal(TypeStatistics typeStatistics);
List<TypeStatistics> selecType1ListCnt(TypeStatistics typeStatistics);
List<TypeStatistics> selecType2ListCnt(TypeStatistics typeStatistics);
List<TypeStatistics> selecType3ListCnt(TypeStatistics typeStatistics);
List<TypeStatistics> selecType4ListCnt(TypeStatistics typeStatistics);
}

View File

@ -0,0 +1,48 @@
package com.dbnt.faisp.fpiMgt.affair.model;
import com.dbnt.faisp.config.BaseModel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import java.util.List;
import javax.persistence.*;
@Getter
@Setter
@NoArgsConstructor
public class TypeStatistics extends BaseModel {
@Transient
private String wrtOrgan;
@Transient
private String itemValue;
@Transient
private String affairType;
@Transient
private Integer cnt;
@Transient
private List<String> category1;
@Transient
private List<String> category2;
@Transient
private List<String> category3;
@Transient
private List<String> category4;
@Transient
private List<String> organList;
@Override
public String toString() {
return "TypeStatistics [wrtOrgan=" + wrtOrgan + ", itemValue=" + itemValue + ", affairType=" + affairType + ", cnt="
+ cnt + ", category1=" + category1 + "]";
}
}

View File

@ -156,4 +156,40 @@ public class AffairService extends BaseService { // 견문보고
public FileInfo selectAffairFile(Integer parentKey, Integer fileSeq) {
return affairFileRepository.findById(new AffairFile.AffairFileId(parentKey, fileSeq)).orElse(null);
}
public List<TypeStatistics> selectType1List(TypeStatistics typeStatistics) {
return affairMapper.selectType1List(typeStatistics);
}
public List<TypeStatistics> selectType2List(TypeStatistics typeStatistics) {
return affairMapper.selectType2List(typeStatistics);
}
public List<TypeStatistics> selectType3List(TypeStatistics typeStatistics) {
return affairMapper.selectType3List(typeStatistics);
}
public List<TypeStatistics> selectType4List(TypeStatistics typeStatistics) {
return affairMapper.selectType4List(typeStatistics);
}
public List<TypeStatistics> selectStatusTotal(TypeStatistics typeStatistics) {
return affairMapper.selectStatusTotal(typeStatistics);
}
public List<TypeStatistics> selecType1ListCnt(TypeStatistics typeStatistics) {
return affairMapper.selecType1ListCnt(typeStatistics);
}
public List<TypeStatistics> selecType2ListCnt(TypeStatistics typeStatistics) {
return affairMapper.selecType2ListCnt(typeStatistics);
}
public List<TypeStatistics> selecType3ListCnt(TypeStatistics typeStatistics) {
return affairMapper.selecType3ListCnt(typeStatistics);
}
public List<TypeStatistics> selecType4ListCnt(TypeStatistics typeStatistics) {
return affairMapper.selecType4ListCnt(typeStatistics);
}
}

View File

@ -117,4 +117,241 @@
where a.affair_key = #{affairKey}
group by a.affair_key) aa
</select>
<select id="selectType1List" resultType="TypeStatistics" parameterType="TypeStatistics">
select item_cd as affairType,
item_value
from code_mgt
where category_cd = 'DC01'
<if test='category1 != null and category1 != ""'>
and item_cd in
<foreach collection="category1" item="item" index="index" separator="," open="(" close=")">
#{item}
</foreach>
</if>
order by affairType asc
</select>
<select id="selectType2List" resultType="TypeStatistics" parameterType="TypeStatistics">
select item_cd as affairType,
item_value
from code_mgt
where category_cd = 'DC02'
<if test='category2 != null and category2 != ""'>
and item_cd in
<foreach collection="category2" item="item" index="index" separator="," open="(" close=")">
#{item}
</foreach>
</if>
order by affairType asc
</select>
<select id="selectType3List" resultType="TypeStatistics" parameterType="TypeStatistics">
select item_cd as affairType,
item_value
from code_mgt
where category_cd = 'DC03'
<if test='category3 != null and category3 != ""'>
and item_cd in
<foreach collection="category3" item="item" index="index" separator="," open="(" close=")">
#{item}
</foreach>
</if>
order by affairType asc
</select>
<select id="selectType4List" resultType="TypeStatistics" parameterType="TypeStatistics">
select item_cd as affairType,
item_value
from code_mgt
where category_cd = 'DC04'
<if test='category4 != null and category4 != ""'>
and item_cd in
<foreach collection="category4" item="item" index="index" separator="," open="(" close=")">
#{item}
</foreach>
</if>
order by affairType asc
</select>
<select id="selectStatusTotal" resultType="TypeStatistics" parameterType="TypeStatistics">
select item_cd as wrt_organ,
item_value,
coalesce(cnt,0) as cnt
from(
select item_cd,
item_value
from code_mgt
where category_cd = 'OG'
and use_chk = 'T'
<if test='organList != null and organList != ""'>
and item_cd in
<foreach collection="organList" item="item" index="index" separator="," open="(" close=")">
#{item}
</foreach>
</if>
order by item_cd asc) a left outer join
(select wrt_organ,
count(*) as cnt
from affair_board
group by wrt_organ)b on
a.item_cd = b.wrt_organ
order by wrt_organ asc
</select>
<select id="selecType1ListCnt" resultType="TypeStatistics" parameterType="TypeStatistics">
select b.item_cd as wrt_organ ,
b.item_value,
a.item_cd as affair_type,
coalesce(cnt,0) as cnt
from
(select item_cd,
item_value
from code_mgt
where category_cd = 'DC01'
<if test='category1 != null and category1 != ""'>
and item_cd in
<foreach collection="category1" item="item" index="index" separator="," open="(" close=")">
#{item}
</foreach>
</if>
)a left join
(select item_cd,
item_value
from code_mgt
where category_cd = 'OG'
and use_chk = 'T'
<if test='organList != null and organList != ""'>
and item_cd in
<foreach collection="organList" item="item" index="index" separator="," open="(" close=")">
#{item}
</foreach>
</if>
order by item_cd asc) b on 1=1
left outer join
(select wrt_organ,
affair_type1 as affair_type,
count(*) as cnt
from affair_board
group by wrt_organ,affair_type1) c
on a.item_cd = c.affair_type and b.item_cd = c.wrt_organ
order by wrt_organ,affair_type asc
</select>
<select id="selecType2ListCnt" resultType="TypeStatistics" parameterType="TypeStatistics">
select b.item_cd as wrt_organ ,
b.item_value,
a.item_cd as affair_type,
coalesce(cnt,0) as cnt
from
(select item_cd,
item_value
from code_mgt
where category_cd = 'DC02'
<if test='category2 != null and category2 != ""'>
and item_cd in
<foreach collection="category2" item="item" index="index" separator="," open="(" close=")">
#{item}
</foreach>
</if>
)a left join
(select item_cd,
item_value
from code_mgt
where category_cd = 'OG'
and use_chk = 'T'
<if test='organList != null and organList != ""'>
and item_cd in
<foreach collection="organList" item="item" index="index" separator="," open="(" close=")">
#{item}
</foreach>
</if>
order by item_cd asc) b on 1=1
left outer join
(select wrt_organ,
affair_type2 as affair_type,
count(*) as cnt
from affair_board
group by wrt_organ,affair_type2) c
on a.item_cd = c.affair_type and b.item_cd = c.wrt_organ
order by wrt_organ,affair_type asc
</select>
<select id="selecType3ListCnt" resultType="TypeStatistics" parameterType="TypeStatistics">
select b.item_cd as wrt_organ ,
b.item_value,
a.item_cd as affair_type,
coalesce(cnt,0) as cnt
from
(select item_cd,
item_value
from code_mgt
where category_cd = 'DC03'
<if test='category3 != null and category3 != ""'>
and item_cd in
<foreach collection="category3" item="item" index="index" separator="," open="(" close=")">
#{item}
</foreach>
</if>
)a left join
(select item_cd,
item_value
from code_mgt
where category_cd = 'OG'
and use_chk = 'T'
<if test='organList != null and organList != ""'>
and item_cd in
<foreach collection="organList" item="item" index="index" separator="," open="(" close=")">
#{item}
</foreach>
</if>
order by item_cd asc) b on 1=1
left outer join
(select wrt_organ,
affair_type3 as affair_type,
count(*) as cnt
from affair_board
group by wrt_organ,affair_type3) c
on a.item_cd = c.affair_type and b.item_cd = c.wrt_organ
order by wrt_organ,affair_type asc
</select>
<select id="selecType4ListCnt" resultType="TypeStatistics" parameterType="TypeStatistics">
select b.item_cd as wrt_organ ,
b.item_value,
a.item_cd as affair_type,
coalesce(cnt,0) as cnt
from
(select item_cd,
item_value
from code_mgt
where category_cd = 'DC04'
<if test='category4 != null and category4 != ""'>
and item_cd in
<foreach collection="category4" item="item" index="index" separator="," open="(" close=")">
#{item}
</foreach>
</if>
)a left join
(select item_cd,
item_value
from code_mgt
where category_cd = 'OG'
and use_chk = 'T'
<if test='organList != null and organList != ""'>
and item_cd in
<foreach collection="organList" item="item" index="index" separator="," open="(" close=")">
#{item}
</foreach>
</if>
order by item_cd asc) b on 1=1
left outer join
(select wrt_organ,
affair_type4 as affair_type,
count(*) as cnt
from affair_board
group by wrt_organ,affair_type4) c
on a.item_cd = c.affair_type and b.item_cd = c.wrt_organ
order by wrt_organ,affair_type asc
</select>
</mapper>

View File

@ -0,0 +1,52 @@
$(document).on('click', '#downExcel', function (){
exportExcel();
})
function exportExcel(){
// step 1. workbook 생성
var wb = XLSX.utils.book_new();
// step 2. 시트 만들기
var newWorksheet = excelHandler.getWorksheet();
// step 3. workbook에 새로만든 워크시트에 이름을 주고 붙인다.
XLSX.utils.book_append_sheet(wb, newWorksheet, excelHandler.getSheetName());
// step 4. 엑셀 파일 만들기
var wbout = XLSX.write(wb, {bookType:'xlsx', type: 'binary'});
// step 5. 엑셀 파일 내보내기
saveAs(new Blob([s2ab(wbout)],{type:"application/octet-stream"}), excelHandler.getExcelFileName());
}
var excelHandler = {
getExcelFileName : function(){
return '견문통계'+'_'+getToday()+'.xlsx'; //파일명
},
getSheetName : function(){
return 'Table Test Sheet'; //시트명
},
getExcelData : function(){
return document.getElementById('tableData'); //TABLE id
},
getWorksheet : function(){
return XLSX.utils.table_to_sheet(this.getExcelData());
}
}
function s2ab(s) {
var buf = new ArrayBuffer(s.length); //convert s to arrayBuffer
var view = new Uint8Array(buf); //create uint8array as viewer
for (var i=0; i<s.length; i++) view[i] = s.charCodeAt(i) & 0xFF; //convert to octet
return buf;
}
function getToday(){
var date = new Date();
var year = date.getFullYear();
var month = ("0" + (1 + date.getMonth())).slice(-2);
var day = ("0" + date.getDate()).slice(-2);
return year + "-" + month + "-" + day;
}

View File

@ -0,0 +1,161 @@
<!DOCTYPE html>
<html lang="ko" xmlns:th="http://www.thymeleaf.org"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorate="~{layout/layout}">
<th:block layout:fragment="script">
<script type="text/javascript" th:src="@{/js/igActivities/fpiMgt/affair/statistics.js}"></script>
</th:block>
<div layout:fragment="content">
<main class="pt-3">
<h4>견문통계</h4>
<input type="hidden" name="_csrf_header" th:value="${_csrf.headerName}"/>
<input type="hidden" th:name="${_csrf.parameterName}" th:value="${_csrf.token}"/>
<div class="row mx-0">
<div class="col-12 card text-center">
<div class="card-body">
<div class="col-auto">
<button id="downExcel">엑셀다운</button>
</div>
<div class="tab-content border border-top-0 p-2">
<form id="searchFm" method="get" th:action="@{/affair/statistics}">
<div class="row pe-3 py-1">
<div class="col-auto">
<div class="input-group w-auto input-daterange" id="dateSelectorDiv">
<input type="text" class="form-control form-control-sm" id="startDate" name="startDate" placeholder="시작일" autocomplete="off" readonly th:value="${searchParams.startDate}">
<input type="text" class="form-control form-control-sm" id="endDate" name="endDate" placeholder="종료일" autocomplete="off" readonly th:value="${searchParams.endDate}">
</div>
</div>
<div class="col-auto">
<ul class="select_list" th:each="commonCode:${session.commonCode.get('OG')}">
<th:block th:if="${#lists.contains(mgtOrganList, commonCode.itemCd)}">
<li>
<input id="category11" name="organList" type="checkbox" th:value="${commonCode.itemCd}" th:if="${#lists.isEmpty(searchParams.organList)}">
<input id="category11" name="organList" type="checkbox" th:value="${commonCode.itemCd}" th:checked="${#lists.contains(searchParams.organList, commonCode.itemCd)}" th:unless="${#lists.isEmpty(searchParams.organList)}">
<label th:text="${commonCode.itemValue}"></label>
</li>
</th:block>
</ul>
</th:block>
</div>
<div class="row justify-content-end pb-1">
<div class="col-auto" style="overflow: auto">
<ul class="select_list" th:each="commonCode:${session.commonCode.get('DC01')}">
<li>
<input th:id="|category1${commonCode.itemCd}|" name="category1" type="checkbox" th:value="${commonCode.itemCd}" th:if="${#lists.isEmpty(searchParams.category1)}">
<input th:id="|category1${commonCode.itemCd}|" name="category1" type="checkbox" th:value="${commonCode.itemCd}" th:checked="${#lists.contains(searchParams.category1, commonCode.itemCd)}" th:unless="${#lists.isEmpty(searchParams.category1)}">
<label th:for="|category1${commonCode.itemCd}|" th:text="${commonCode.itemValue}"></label>
</li>
</ul>
</div>
<div class="col-auto">
<ul class="select_list" th:each="commonCode:${session.commonCode.get('DC02')}">
<li>
<input id="category11" name="category2" type="checkbox" th:value="${commonCode.itemCd}" th:if="${#lists.isEmpty(searchParams.category2)}">
<input id="category11" name="category2" type="checkbox" th:value="${commonCode.itemCd}" th:checked="${#lists.contains(searchParams.category2, commonCode.itemCd)}" th:unless="${#lists.isEmpty(searchParams.category2)}">
<label th:text="${commonCode.itemValue}"></label>
</li>
</ul>
</div>
<div class="col-auto">
<ul class="select_list" th:each="commonCode:${session.commonCode.get('DC03')}">
<li>
<input id="category11" name="category3" type="checkbox" th:value="${commonCode.itemCd}" th:if="${#lists.isEmpty(searchParams.category3)}">
<input id="category11" name="category3" type="checkbox" th:value="${commonCode.itemCd}" th:checked="${#lists.contains(searchParams.category3, commonCode.itemCd)}" th:unless="${#lists.isEmpty(searchParams.category3)}">
<label th:text="${commonCode.itemValue}"></label>
</li>
</ul>
</div>
<div class="col-auto">
<ul class="select_list" th:each="commonCode:${session.commonCode.get('DC04')}">
<li>
<input id="category11" name="category4" type="checkbox" th:value="${commonCode.itemCd}" th:if="${#lists.isEmpty(searchParams.category4)}">
<input id="category11" name="category4" type="checkbox" th:value="${commonCode.itemCd}" th:checked="${#lists.contains(searchParams.category4, commonCode.itemCd)}" th:unless="${#lists.isEmpty(searchParams.category4)}">
<label th:text="${commonCode.itemValue}"></label>
</li>
</ul>
</div>
</div>
<div class="col-1 d-grid gap-2">
<input type="submit" class="btn btn-lg btn-primary col-auto" id="searchBtn" value="검색">
</div>
</div>
</form>
<div class="row justify-content-start">
<div class="col-12">
<div class="card">
<div class="card-body">
<div class="row">
<table class="table table-hover" id="tableData">
<thead>
<tr>
<th rowspan="2">구분</th>
<th rowspan="2">누계</th>
<th th:colspan="${type1.size()}">분류1</th>
<th th:colspan="${type2.size()}">분류2</th>
<th th:colspan="${type3.size()}">분류3</th>
<th th:colspan="${type4.size()}">분류4</th>
</tr>
<tr>
<th:block th:each="type1:${type1}">
<th th:text="${type1.itemValue}"></th>
</th:block>
<th:block th:each="type2:${type2}">
<th th:text="${type2.itemValue}"></th>
</th:block>
<th:block th:each="type3:${type3}">
<th th:text="${type3.itemValue}"></th>
</th:block>
<th:block th:each="type4:${type4}">
<th th:text="${type4.itemValue}"></th>
</th:block>
</tr>
</thead>
<tbody>
<th:block th:each="total:${totalList}">
<tr>
<td th:text="${total.itemValue}"></td>
<td th:text="${total.cnt}"></td>
<th:block th:each="commonCode:${type1}">
<th:block th:each="type1:${type1List}">
<th:block th:if="${type1.affairType eq commonCode.affairType} and ${total.wrtOrgan eq type1.wrtOrgan}">
<td th:text="${type1.cnt}"></td>
</th:block>
</th:block>
</th:block>
<th:block th:each="commonCode:${type2}">
<th:block th:each="type2:${type2List}">
<th:block th:if="${type2.affairType eq commonCode.affairType} and ${total.wrtOrgan eq type2.wrtOrgan}">
<td th:text="${type2.cnt}"></td>
</th:block>
</th:block>
</th:block>
<th:block th:each="commonCode:${type3}">
<th:block th:each="type3:${type3List}">
<th:block th:if="${type3.affairType eq commonCode.affairType} and ${total.wrtOrgan eq type3.wrtOrgan}">
<td th:text="${type3.cnt}"></td>
</th:block>
</th:block>
</th:block>
<th:block th:each="commonCode:${type4}">
<th:block th:each="type4:${type4List}">
<th:block th:if="${type4.affairType eq commonCode.affairType} and ${total.wrtOrgan eq type4.wrtOrgan}">
<td th:text="${type4.cnt}"></td>
</th:block>
</th:block>
</th:block>
</tr>
</th:block>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</main>
</div>
</html>