Merge branch 'susu' into dev
# Conflicts: # admin/src/main/resources/static/assets/styles/style.css # admin/src/main/resources/templates/home.html
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
package app.module.admin.usecase.dashboard.chart.adapters.persistence;
|
||||
|
||||
import app.module.admin.config.application.util.AdminUtil;
|
||||
import app.module.admin.usecase.dashboard.chart.adapters.persistence.model.ChartDto;
|
||||
import app.module.admin.usecase.dashboard.chart.adapters.persistence.model.LocalRegionPercentDto;
|
||||
import app.module.admin.usecase.dashboard.chart.adapters.persistence.model.LocalRegionResearcherPercentDto;
|
||||
import app.module.admin.usecase.dashboard.chart.adapters.persistence.model.TotalPercentDto;
|
||||
import app.module.admin.usecase.dashboard.chart.adapters.web.model.TotalPercentageReqVO;
|
||||
import app.module.admin.usecase.dashboard.chart.ports.ChartPortOut;
|
||||
import app.module.core.config.application.exception.NoMatchingURIException;
|
||||
import app.module.core.usecase.uicode.list.adapters.persistence.UICodeListMapper;
|
||||
import app.module.core.usecase.uicode.list.ports.application.domain.UICodeElement;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class ChartDao implements ChartPortOut {
|
||||
private final ChartMapper chartMapper;
|
||||
private final UICodeListMapper uiCodeListMapper;
|
||||
@Override
|
||||
public ChartDto selectTotalPercentage(String usageType) {
|
||||
TotalPercentageReqVO reqVO = new TotalPercentageReqVO();
|
||||
reqVO.setUsageType(usageType);
|
||||
|
||||
LocalDate today = LocalDate.now();
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMM");
|
||||
String formattedDate = today.format(formatter);
|
||||
reqVO.setRecordMonth(formattedDate);
|
||||
DateTimeFormatter formatterText = DateTimeFormatter.ofPattern("yyyy년 MM월 현황");
|
||||
String recordMonthText = today.format(formatterText);
|
||||
|
||||
if("ROLE_ADMIN".equals(AdminUtil.getLoginUserRole())) {
|
||||
// 관리자 일경우
|
||||
return new ChartDto(
|
||||
recordMonthText,
|
||||
chartMapper.selectTotalPercentage(reqVO),
|
||||
chartMapper.selectLocalRegionPercentage(reqVO),
|
||||
chartMapper.selectLocalRegionResearcherPercentage(reqVO),
|
||||
uiCodeListMapper.findByParentId("code.region.main"));
|
||||
|
||||
} else if("ROLE_LOCAL_INSPECTOR".equals(AdminUtil.getLoginUserRole())) {
|
||||
// 지방 실사 일경우 실사 지역으로만
|
||||
reqVO.setRegionMainCode(AdminUtil.getLoginUserRegionMainCode());
|
||||
|
||||
return new ChartDto(
|
||||
recordMonthText,
|
||||
chartMapper.selectTotalPercentage(reqVO),
|
||||
null,
|
||||
chartMapper.selectLocalRegionResearcherPercentage(reqVO),
|
||||
null);
|
||||
} else if("ROLE_LOCAL_INSPECTOR".equals(AdminUtil.getLoginUserRole())) {
|
||||
// 조사원 일경우
|
||||
reqVO.setAdminSeq(AdminUtil.getLoginUserSeq());;
|
||||
return new ChartDto(recordMonthText, chartMapper.selectTotalPercentageResearcher(reqVO), null,null,null);
|
||||
}
|
||||
|
||||
return new ChartDto(null,null,null,null,null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<LocalRegionResearcherPercentDto> selectRegionMainCodePercentage(String usageType, String regionMainCode) {
|
||||
LocalDate today = LocalDate.now();
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMM");
|
||||
String formattedDate = today.format(formatter);
|
||||
if("ROLE_ADMIN".equals(AdminUtil.getLoginUserRole())) {
|
||||
return chartMapper.selectLocalRegionResearcherPercentage(new TotalPercentageReqVO(usageType,regionMainCode,formattedDate));
|
||||
}else{
|
||||
throw new NoMatchingURIException("잘못된 접근");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package app.module.admin.usecase.dashboard.chart.adapters.persistence;
|
||||
|
||||
import app.module.admin.usecase.dashboard.chart.adapters.persistence.model.LocalRegionPercentDto;
|
||||
import app.module.admin.usecase.dashboard.chart.adapters.persistence.model.LocalRegionResearcherPercentDto;
|
||||
import app.module.admin.usecase.dashboard.chart.adapters.persistence.model.TotalPercentDto;
|
||||
import app.module.admin.usecase.dashboard.chart.adapters.web.model.TotalPercentageReqVO;
|
||||
import app.module.admin.usecase.researcher.adpaters.web.model.ResearchersListReqVO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface ChartMapper {
|
||||
|
||||
TotalPercentDto selectTotalPercentage(TotalPercentageReqVO reqVO);
|
||||
TotalPercentDto selectTotalPercentageResearcher(TotalPercentageReqVO reqVO);
|
||||
List<LocalRegionPercentDto> selectLocalRegionPercentage(TotalPercentageReqVO reqVO);
|
||||
List<LocalRegionResearcherPercentDto> selectLocalRegionResearcherPercentage(TotalPercentageReqVO reqVO);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package app.module.admin.usecase.dashboard.chart.adapters.persistence.model;
|
||||
|
||||
import app.module.core.usecase.uicode.list.ports.application.domain.UICodeElement;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class ChartDto {
|
||||
private String recordMonthText;
|
||||
private TotalPercentDto totalPercentDto;
|
||||
private List<LocalRegionPercentDto> localRegionPercentDtoList;
|
||||
private List<LocalRegionResearcherPercentDto> localRegionResearcherPercentDtoList;
|
||||
private List<UICodeElement> regionMainCodeList;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package app.module.admin.usecase.dashboard.chart.adapters.persistence.model;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class LocalRegionPercentDto {
|
||||
private String regionName;
|
||||
private Double totalHouseholdCount;
|
||||
private Double dailyPercent;
|
||||
private Double visitPercent;
|
||||
private Double totalVisitCount;
|
||||
private Double giftSentPercent;
|
||||
private Double totalGiftSentCount;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package app.module.admin.usecase.dashboard.chart.adapters.persistence.model;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class LocalRegionResearcherPercentDto {
|
||||
private String researcherName;
|
||||
private String regionMainCodeName;
|
||||
private Double totalHouseholdCount;
|
||||
private Double dailyPercent;
|
||||
private Double visitPercent;
|
||||
private Double totalVisitCount;
|
||||
private Double giftSentPercent;
|
||||
private Double totalGiftSentCount;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package app.module.admin.usecase.dashboard.chart.adapters.persistence.model;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class TotalPercentDto {
|
||||
private Double dailyPercent;
|
||||
private Double totalHouseholdCount;
|
||||
private Double visitPercent;
|
||||
private Double totalVisitCount;
|
||||
private Double giftSentPercent;
|
||||
private Double totalGiftSentCount;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package app.module.admin.usecase.dashboard.chart.adapters.web;
|
||||
|
||||
import app.module.admin.usecase.dashboard.chart.adapters.web.model.TotalPercentageReqVO;
|
||||
import app.module.admin.usecase.dashboard.chart.ports.ChartPortIn;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping(path = "/api/dashboard/chart")
|
||||
class ChartApiController {
|
||||
|
||||
private final ChartPortIn chartPortIn;
|
||||
|
||||
@GetMapping(path = "/total")
|
||||
ResponseEntity<?> selectTotalPercentage(@RequestParam("usageType") String usageType) {
|
||||
return ResponseEntity.status(HttpStatus.OK).body(chartPortIn.selectTotalPercentage(usageType));
|
||||
}
|
||||
|
||||
@GetMapping(path = "/researcher")
|
||||
ResponseEntity<?> selectRegionMainCodePercentage(@RequestParam("usageType") String usageType,@RequestParam("regionMainCode") String regionMainCode) {
|
||||
return ResponseEntity.status(HttpStatus.OK).body(chartPortIn.selectRegionMainCodePercentage(usageType,regionMainCode));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package app.module.admin.usecase.dashboard.chart.adapters.web.model;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@RequiredArgsConstructor
|
||||
public class TotalPercentageReqVO {
|
||||
private String usageType;
|
||||
private String regionMainCode;
|
||||
private Long adminSeq;
|
||||
private String recordMonth;
|
||||
|
||||
public TotalPercentageReqVO(String usageType, String regionMainCode,String recordMonth) {
|
||||
this.usageType = usageType;
|
||||
this.regionMainCode = regionMainCode;
|
||||
this.recordMonth = recordMonth;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package app.module.admin.usecase.dashboard.chart.ports;
|
||||
|
||||
import app.module.admin.usecase.dashboard.chart.adapters.persistence.model.ChartDto;
|
||||
import app.module.admin.usecase.dashboard.chart.adapters.persistence.model.LocalRegionResearcherPercentDto;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ChartPortIn {
|
||||
|
||||
ChartDto selectTotalPercentage(String usageType);
|
||||
List<LocalRegionResearcherPercentDto> selectRegionMainCodePercentage(String usageType,String regionMainCode);
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package app.module.admin.usecase.dashboard.chart.ports;
|
||||
|
||||
import app.module.admin.usecase.dashboard.chart.adapters.persistence.model.ChartDto;
|
||||
import app.module.admin.usecase.dashboard.chart.adapters.persistence.model.LocalRegionResearcherPercentDto;
|
||||
import app.module.admin.usecase.dashboard.chart.adapters.web.model.TotalPercentageReqVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ChartPortOut {
|
||||
|
||||
ChartDto selectTotalPercentage(String usageType);
|
||||
List<LocalRegionResearcherPercentDto> selectRegionMainCodePercentage(String usageType,String regionMainCode);
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package app.module.admin.usecase.dashboard.chart.ports.applilcation;
|
||||
|
||||
import app.module.admin.usecase.dashboard.chart.adapters.persistence.model.ChartDto;
|
||||
import app.module.admin.usecase.dashboard.chart.adapters.persistence.model.LocalRegionResearcherPercentDto;
|
||||
import app.module.admin.usecase.dashboard.chart.adapters.web.model.TotalPercentageReqVO;
|
||||
import app.module.admin.usecase.dashboard.chart.ports.ChartPortIn;
|
||||
import app.module.admin.usecase.dashboard.chart.ports.ChartPortOut;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
class ChartService implements ChartPortIn {
|
||||
private final ChartPortOut portOut;
|
||||
|
||||
@Override
|
||||
public ChartDto selectTotalPercentage(String usageType){
|
||||
return portOut.selectTotalPercentage(usageType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<LocalRegionResearcherPercentDto> selectRegionMainCodePercentage(String usageType,String regionMainCode) {
|
||||
return portOut.selectRegionMainCodePercentage(usageType,regionMainCode);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
package app.module.admin.usecase.dashboard.getDashboardUI;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import app.module.admin.usecase.dashboard.getDashboardUI.model.GetDashboardUIReqVO;
|
||||
|
||||
@Controller
|
||||
@RequiredArgsConstructor
|
||||
class GetDashboardUIController {
|
||||
|
||||
@GetMapping(path = "/dashboard")
|
||||
String operate(
|
||||
Model model,
|
||||
@ModelAttribute("reqVO") GetDashboardUIReqVO reqVO) {
|
||||
|
||||
return "dashboard";
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
package app.module.admin.usecase.dashboard.getDashboardUI.model;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode
|
||||
public class GetDashboardUIReqVO {
|
||||
}
|
||||
@@ -82,7 +82,8 @@ class ExcelUploadCreateHouseholdDao implements ExcelUploadCreateHouseholdPortOut
|
||||
household.setIndustryDetail(getCellValue(row.getCell(11))); // 규모 / 세부품목
|
||||
household.setResearcherSeq(getResearcherSeq(row.getCell(12))); // 조사원
|
||||
household.setIsPanel(getIsPanel(row.getCell(13))); // 유지여부
|
||||
household.setMemo(getCellValue(row.getCell(14))); // 비고
|
||||
household.setUsageType(getUsageType(row.getCell(14))); // 구분
|
||||
household.setMemo(getCellValue(row.getCell(15))); // 비고
|
||||
|
||||
CreateHouseholdOutCmd cmd = new CreateHouseholdOutCmd(
|
||||
null,
|
||||
@@ -102,7 +103,7 @@ class ExcelUploadCreateHouseholdDao implements ExcelUploadCreateHouseholdPortOut
|
||||
household.getIndustryDetail(),
|
||||
household.getResearcherSeq(),
|
||||
household.getIsPanel(),
|
||||
null,
|
||||
household.getUsageType(),
|
||||
null,
|
||||
household.getMemo(),
|
||||
List.of("ROLE_GENERAL")
|
||||
@@ -188,4 +189,11 @@ class ExcelUploadCreateHouseholdDao implements ExcelUploadCreateHouseholdPortOut
|
||||
return researcherMapper.selectResearcherId(cell.getStringCellValue());
|
||||
}
|
||||
|
||||
private String getUsageType(Cell cell){
|
||||
if (cell == null) return "MOBILE";
|
||||
String usageType = cell.getStringCellValue().trim();
|
||||
if("모바일".equals(usageType) ) return "MOBILE";
|
||||
if("지류".equals(usageType) ) return "PAPER";
|
||||
return "MOBILE";
|
||||
}
|
||||
}
|
||||
@@ -24,5 +24,6 @@ public class ExcelCreateHouseholdVO {
|
||||
private String industryDetail;
|
||||
private Long researcherSeq;
|
||||
private Boolean isPanel;
|
||||
private String usageType;
|
||||
private String memo;
|
||||
}
|
||||
|
||||
106
admin/src/main/resources/mappers/dashboard/ChartMapper.xml
Normal file
106
admin/src/main/resources/mappers/dashboard/ChartMapper.xml
Normal file
@@ -0,0 +1,106 @@
|
||||
<?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="app.module.admin.usecase.dashboard.chart.adapters.persistence.ChartMapper">
|
||||
|
||||
<select id="selectTotalPercentage">
|
||||
SELECT
|
||||
COUNT(DISTINCT h.seq) as total_household_count,
|
||||
COALESCE(ROUND(AVG(cr.completion_rate), 1), 0) AS daily_percent,
|
||||
COUNT(DISTINCT CASE WHEN hv.id IS NOT NULL THEN hv.household_seq END) AS total_visit_count,
|
||||
COALESCE(ROUND(COUNT(DISTINCT CASE WHEN hv.id IS NOT NULL THEN hv.household_seq end) * 100::numeric / NULLIF(COUNT(DISTINCT h.seq), 0), 1) , 0 ) as visit_percent,
|
||||
COUNT(DISTINCT CASE WHEN hv.is_gift_sent = true THEN hv.household_seq END) AS total_gift_sent_count,
|
||||
COALESCE(ROUND(COUNT(DISTINCT CASE WHEN hv.is_gift_sent = true THEN hv.household_seq END) * 100::numeric / NULLIF(COUNT(DISTINCT h.seq), 0), 1) , 0 ) as gift_sent_percent
|
||||
FROM household h
|
||||
LEFT JOIN v_monthly_completion_rate cr on cr.household_seq = h.seq AND cr.record_month = #{recordMonth}
|
||||
LEFT join household_visit hv on hv.household_seq = h.seq and to_char(hv.visit_date,'YYYYMM') = #{recordMonth} and hv.is_deleted = false
|
||||
WHERE h.is_deleted = false
|
||||
<if test="usageType != null and usageType != ''">
|
||||
and h.usage_type = #{usageType}
|
||||
</if>
|
||||
<if test="regionMainCode != null and regionMainCode != ''">
|
||||
and h.region_main_code = #{regionMainCode}
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<select id="selectTotalPercentageResearcher">
|
||||
SELECT
|
||||
COUNT(DISTINCT rhh.household_seq) as total_household_count,
|
||||
COALESCE(ROUND(AVG(cr.completion_rate), 1), 0) AS daily_percent,
|
||||
COUNT(DISTINCT CASE WHEN hv.id IS NOT NULL THEN hv.household_seq END) AS total_visit_count,
|
||||
COALESCE(ROUND(COUNT(DISTINCT CASE WHEN hv.id IS NOT NULL THEN hv.household_seq end) * 100::numeric / NULLIF(COUNT(DISTINCT rhh.household_seq), 0), 1),0) as visit_percent,
|
||||
COUNT(DISTINCT CASE WHEN hv.is_gift_sent = true THEN hv.household_seq END) AS total_gift_sent_count,
|
||||
COALESCE(ROUND(COUNT(DISTINCT CASE WHEN hv.is_gift_sent = true THEN hv.household_seq END) * 100::numeric / NULLIF(COUNT(DISTINCT rhh.household_seq), 0), 1),0) as gift_sent_percent
|
||||
FROM household h
|
||||
JOIN researcher_has_household rhh on rhh.household_seq = h.seq and rhh.admin_seq = #{adminSeq} and rhh.is_deleted = false
|
||||
LEFT JOIN v_monthly_completion_rate cr on cr.household_seq = h.seq AND cr.record_month = #{recordMonth}
|
||||
LEFT JOIN household_visit hv on hv.household_seq = h.seq and to_char(hv.visit_date,'YYYYMM') = #{recordMonth} and hv.is_deleted = false
|
||||
WHERE h.is_deleted = false
|
||||
<if test="usageType != null and usageType != ''">
|
||||
and h.usage_type = #{usageType}
|
||||
</if>
|
||||
<if test="regionMainCode != null and regionMainCode != ''">
|
||||
and h.region_main_code = #{regionMainCode}
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<select id="selectLocalRegionPercentage">
|
||||
SELECT
|
||||
COALESCE(u.code_text, '전체') AS region_name,
|
||||
COUNT(DISTINCT a.seq) AS researcher_count,
|
||||
COUNT(DISTINCT rhh.household_seq) AS total_household_count,
|
||||
COALESCE(ROUND(AVG(v.completion_rate), 1), 0) AS daily_percent,
|
||||
COUNT(DISTINCT CASE WHEN hv.id IS NOT NULL THEN hv.household_seq END) AS total_visit_count,
|
||||
COALESCE(ROUND(COUNT(DISTINCT CASE WHEN hv.id IS NOT NULL THEN hv.household_seq end) * 100::numeric / NULLIF(COUNT(DISTINCT rhh.household_seq),0), 1),0) as visit_percent,
|
||||
COUNT(DISTINCT CASE WHEN hv.is_gift_sent = true THEN hv.household_seq END) AS total_gift_sent_count,
|
||||
COALESCE(ROUND(COUNT(DISTINCT CASE WHEN hv.is_gift_sent = true THEN hv.household_seq END) * 100::numeric / NULLIF(COUNT(DISTINCT rhh.household_seq),0), 1),0) as gift_sent_percent
|
||||
FROM uicode u
|
||||
LEFT JOIN admin a
|
||||
ON a.region_main_code = u.id AND a.is_deleted = false
|
||||
LEFT JOIN admin_has_role ahr
|
||||
ON a.seq = ahr.admin_seq AND ahr.is_deleted = false AND ahr.role_id = 'ROLE_RESEARCHER'
|
||||
LEFT JOIN researcher_has_household rhh
|
||||
ON rhh.admin_seq = a.seq AND rhh.is_deleted = false
|
||||
LEFT JOIN household h
|
||||
ON h.seq = rhh.household_seq AND h.is_deleted = false AND h.is_panel = true
|
||||
<if test="usageType != null and usageType != ''">
|
||||
and h.usage_type = #{usageType}
|
||||
</if>
|
||||
LEFT JOIN household_visit hv
|
||||
ON hv.household_seq = h.seq AND hv.is_deleted = false
|
||||
LEFT JOIN v_monthly_completion_rate v
|
||||
ON v.household_seq = h.seq AND v.record_month = #{recordMonth}
|
||||
WHERE u.parent_id = 'code.region.main' and u.in_use = true
|
||||
GROUP BY ROLLUP(u.code_text)
|
||||
ORDER BY CASE WHEN COALESCE(u.code_text, '전체') = '전체' THEN 1 ELSE 0 END,
|
||||
MIN(u.order_no) NULLS LAST,
|
||||
u.code_text
|
||||
</select>
|
||||
|
||||
<select id="selectLocalRegionResearcherPercentage">
|
||||
SELECT
|
||||
NULLIF(a.name,'-') AS researcher_name,
|
||||
u.code_text AS region_main_code_name,
|
||||
COUNT(DISTINCT h.seq) AS total_household_count,
|
||||
COALESCE(ROUND(AVG(cr.completion_rate), 1), 0) AS daily_percent,
|
||||
COUNT(DISTINCT CASE WHEN hv.id IS NOT NULL THEN hv.household_seq END) AS total_visit_count,
|
||||
COALESCE(ROUND(COUNT(DISTINCT CASE WHEN hv.id IS NOT NULL THEN hv.household_seq END) * 100::numeric / NULLIF(COUNT(DISTINCT h.seq), 0), 1),0) AS visit_percent,
|
||||
COUNT(DISTINCT CASE WHEN hv.is_gift_sent = true THEN hv.household_seq END) AS total_gift_sent_count,
|
||||
COALESCE(ROUND(COUNT(DISTINCT CASE WHEN hv.is_gift_sent = true THEN hv.household_seq END) * 100::numeric / NULLIF(COUNT(DISTINCT h.seq), 0), 1), 0) AS gift_sent_percent
|
||||
FROM admin a
|
||||
JOIN uicode u ON a.region_main_code = u.id and u.parent_id = 'code.region.main' and u.in_use = true
|
||||
JOIN admin_has_role ahr ON a.seq = ahr.admin_seq AND ahr.is_deleted = false AND ahr.role_id = 'ROLE_RESEARCHER'
|
||||
LEFT JOIN researcher_has_household rhh on rhh.admin_seq = ahr.admin_seq
|
||||
LEFT JOIN household h on h.seq = rhh.household_seq
|
||||
<if test="usageType != null and usageType != ''">
|
||||
and h.usage_type = #{usageType}
|
||||
</if>
|
||||
LEFT JOIN v_monthly_completion_rate cr on cr.household_seq = h.seq AND cr.record_month = #{recordMonth}
|
||||
LEFT JOIN household_visit hv on hv.household_seq = h.seq and to_char(hv.visit_date,'YYYYMM') = #{recordMonth}
|
||||
WHERE a.is_deleted = false and a.account_disabled = false
|
||||
<if test="regionMainCode != null and regionMainCode != ''">
|
||||
and a.region_main_code = #{regionMainCode}
|
||||
</if>
|
||||
GROUP BY a.seq,u.id
|
||||
</select>
|
||||
</mapper>
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user