增加关于问卷调查的统计

This commit is contained in:
2025-09-16 13:37:46 +08:00
parent 078991cbe7
commit 019e7d7b2c
12 changed files with 947 additions and 700 deletions

View File

@@ -8,10 +8,7 @@ import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.poi.ExcelUtil; import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.dw.domain.CheckQuery; import com.ruoyi.dw.domain.CheckQuery;
import com.ruoyi.dw.domain.DataCheckStatus; import com.ruoyi.dw.domain.DataCheckStatus;
import com.ruoyi.dw.domain.vo.XyCheck; import com.ruoyi.dw.domain.vo.*;
import com.ruoyi.dw.domain.vo.XyCheckBl;
import com.ruoyi.dw.domain.vo.XyCheckExport;
import com.ruoyi.dw.domain.vo.XyDataCheck;
import com.ruoyi.dw.mapper.DataCheckMapper; import com.ruoyi.dw.mapper.DataCheckMapper;
import com.ruoyi.dw.mapper.XyCheckMapper; import com.ruoyi.dw.mapper.XyCheckMapper;
import com.ruoyi.dw.util.SortField; import com.ruoyi.dw.util.SortField;
@@ -32,10 +29,7 @@ import java.time.LocalDateTime;
import java.time.LocalTime; import java.time.LocalTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAdjusters; import java.time.temporal.TemporalAdjusters;
import java.util.ArrayList; import java.util.*;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
@RestController @RestController
@RequestMapping("/xy/check") @RequestMapping("/xy/check")
@@ -53,7 +47,12 @@ public class XyCheckController extends BaseController {
*/ */
@GetMapping("/status") @GetMapping("/status")
public AjaxResult getStatus() { public AjaxResult getStatus() {
return AjaxResult.success(dataCheckMapper.getStatus()); DataCheckStatus cjCheckStatus = dataCheckMapper.getStatus("cj");
DataCheckStatus dwCheckStatus = dataCheckMapper.getStatus("dw");
Map<String, DataCheckStatus> map = new HashMap<>();
map.put("cj", cjCheckStatus);
map.put("dw", dwCheckStatus);
return AjaxResult.success(map);
} }
/** /**
@@ -76,7 +75,31 @@ public class XyCheckController extends BaseController {
endTime.set(Calendar.SECOND, 59); endTime.set(Calendar.SECOND, 59);
endTime.set(Calendar.MILLISECOND, 0); endTime.set(Calendar.MILLISECOND, 0);
Date endDate = endTime.getTime(); Date endDate = endTime.getTime();
dataCheckMapper.updateCheck(startDate, endDate,checkStatus.getWeekCheck(),checkStatus.getWeekTimeCheck()); dataCheckMapper.updateCheck(startDate, endDate,checkStatus.getWeekCheck(),checkStatus.getWeekTimeCheck(),"dw");
return AjaxResult.success("设置成功");
}
/**
* 修改考核状态
* @return
*/
@PutMapping("/dwStatus")
public AjaxResult updateDwStatus(@RequestBody DataCheckStatus checkStatus) {
Calendar startTime = Calendar.getInstance();
startTime.setTime(checkStatus.getBeginDate());
startTime.set(Calendar.HOUR_OF_DAY, 0);
startTime.set(Calendar.MINUTE, 0);
startTime.set(Calendar.SECOND, 0);
startTime.set(Calendar.MILLISECOND, 0);
Date startDate = startTime.getTime();
Calendar endTime = Calendar.getInstance();
endTime.setTime(checkStatus.getEndDate());
endTime.set(Calendar.HOUR_OF_DAY, 23);
endTime.set(Calendar.MINUTE, 59);
endTime.set(Calendar.SECOND, 59);
endTime.set(Calendar.MILLISECOND, 0);
Date endDate = endTime.getTime();
dataCheckMapper.updateCheck(startDate, endDate,checkStatus.getWeekCheck(),checkStatus.getWeekTimeCheck(),"cj");
return AjaxResult.success("设置成功"); return AjaxResult.success("设置成功");
} }
@@ -86,7 +109,7 @@ public class XyCheckController extends BaseController {
*/ */
@GetMapping("/dwCount") @GetMapping("/dwCount")
public AjaxResult dwCount(CheckQuery checkQuery) { public AjaxResult dwCount(CheckQuery checkQuery) {
DataCheckStatus checkStatus = dataCheckMapper.getStatus(); DataCheckStatus checkStatus = dataCheckMapper.getStatus("dw");
Date beginDate = null; Date beginDate = null;
Date endDate = null; Date endDate = null;
if (StringUtils.isNotEmpty(checkQuery.getBeginDate())) { if (StringUtils.isNotEmpty(checkQuery.getBeginDate())) {
@@ -99,7 +122,30 @@ public class XyCheckController extends BaseController {
}else { }else {
endDate = checkStatus.getEndDate(); endDate = checkStatus.getEndDate();
} }
return AjaxResult.success(xyCheckMapper.selectXyCheckDw(beginDate, endDate)); List<XyCheckDw> xyCheckDws = xyCheckMapper.selectXyCheckDw(beginDate, endDate);
List<XyCheckDwOut> result = XyCheckDwConverter.convertPreserveOrder(xyCheckDws);
if (checkQuery.getSort().intValue() == 1){
result = XyCheckSorter.sortDwList(result, SortField.DW_COUNT,SortOrder.DESC);
}
return AjaxResult.success(result);
}
/**
* 根据专业关联表统计各个学院的调查问卷数量
* @return
*/
@GetMapping("/dwBzCount")
public AjaxResult dwBzCount(CheckQuery checkQuery) {
DataCheckStatus checkStatus = dataCheckMapper.getStatus("dw");
String[] dates = getWeekRange(checkStatus.getWeekCheck(), checkStatus.getWeekTimeCheck());
Date date1 = DateUtils.parseDate(dates[0]);
Date date2 = DateUtils.parseDate(dates[1]);
List<XyCheckDw> bzs = xyCheckMapper.selectXyCheckDw(date1, date2);
List<XyCheckDwOut> result = XyCheckDwConverter.convertPreserveOrder(bzs);
if (checkQuery.getSort().intValue() == 1){
result = XyCheckSorter.sortDwList(result, SortField.DW_COUNT,SortOrder.DESC);
}
return AjaxResult.success(result);
} }
/** /**
@@ -109,7 +155,7 @@ public class XyCheckController extends BaseController {
*/ */
@GetMapping("/zzt") @GetMapping("/zzt")
public AjaxResult studentCount(CheckQuery checkQuery) { public AjaxResult studentCount(CheckQuery checkQuery) {
DataCheckStatus checkStatus = dataCheckMapper.getStatus(); DataCheckStatus checkStatus = dataCheckMapper.getStatus("dw");
String[] dates = getWeekRange(checkStatus.getWeekCheck(), checkStatus.getWeekTimeCheck()); String[] dates = getWeekRange(checkStatus.getWeekCheck(), checkStatus.getWeekTimeCheck());
Date date1 = DateUtils.parseDate(dates[0]); Date date1 = DateUtils.parseDate(dates[0]);
Date date2 = DateUtils.parseDate(dates[1]); Date date2 = DateUtils.parseDate(dates[1]);
@@ -170,7 +216,7 @@ public class XyCheckController extends BaseController {
*/ */
@PostMapping("/export/cj") @PostMapping("/export/cj")
public void exportCj(HttpServletResponse response) throws IOException { public void exportCj(HttpServletResponse response) throws IOException {
DataCheckStatus checkStatus = dataCheckMapper.getStatus(); DataCheckStatus checkStatus = dataCheckMapper.getStatus("dw");
String[] dates = getWeekRange(checkStatus.getWeekCheck(), checkStatus.getWeekTimeCheck()); String[] dates = getWeekRange(checkStatus.getWeekCheck(), checkStatus.getWeekTimeCheck());
Date date1 = DateUtils.parseDate(dates[0]); Date date1 = DateUtils.parseDate(dates[0]);
Date date2 = DateUtils.parseDate(dates[1]); Date date2 = DateUtils.parseDate(dates[1]);
@@ -198,7 +244,7 @@ public class XyCheckController extends BaseController {
*/ */
@GetMapping("/zxt") @GetMapping("/zxt")
public AjaxResult studentCount2(CheckQuery checkQuery) { public AjaxResult studentCount2(CheckQuery checkQuery) {
DataCheckStatus checkStatus = dataCheckMapper.getStatus(); DataCheckStatus checkStatus = dataCheckMapper.getStatus("dw");
Date beginDate = null; Date beginDate = null;
Date endDate = null; Date endDate = null;
if (StringUtils.isNotEmpty(checkQuery.getBeginDate())) { if (StringUtils.isNotEmpty(checkQuery.getBeginDate())) {

View File

@@ -23,6 +23,8 @@ public class DataCheckStatus {
private String weekTimeCheck; private String weekTimeCheck;
private String checkType;
public Integer getId() { public Integer getId() {
return id; return id;
} }
@@ -70,4 +72,12 @@ public class DataCheckStatus {
public void setWeekTimeCheck(String weekTimeCheck) { public void setWeekTimeCheck(String weekTimeCheck) {
this.weekTimeCheck = weekTimeCheck; this.weekTimeCheck = weekTimeCheck;
} }
public String getCheckType() {
return checkType;
}
public void setCheckType(String checkType) {
this.checkType = checkType;
}
} }

View File

@@ -4,6 +4,8 @@ public class XyCheckDw {
private String xy; private String xy;
private Integer dwId;
private Integer dwCount; private Integer dwCount;
public String getXy() { public String getXy() {
@@ -14,6 +16,14 @@ public class XyCheckDw {
this.xy = xy; this.xy = xy;
} }
public Integer getDwId() {
return dwId;
}
public void setDwId(Integer dwId) {
this.dwId = dwId;
}
public Integer getDwCount() { public Integer getDwCount() {
return dwCount; return dwCount;
} }

View File

@@ -0,0 +1,34 @@
package com.ruoyi.dw.domain.vo;
import java.util.*;
import java.util.stream.Collectors;
public class XyCheckDwConverter {
public static List<XyCheckDwOut> convertPreserveOrder(List<XyCheckDw> source) {
if (source == null) return Collections.emptyList();
Map<String, XyCheckDwOut> linked = new LinkedHashMap<>(); // 保序
for (XyCheckDw d : source) {
XyCheckDwOut out = linked.computeIfAbsent(d.getXy(), k -> {
XyCheckDwOut o = new XyCheckDwOut();
o.setXy(k);
o.setBy5ynCount(0);
o.setBy5ysCount(0);
o.setLtxCount(0);
o.setYrdwCount(0);
return o;
});
switch (d.getDwId()) {
case 1: out.setBy5ynCount(out.getBy5ynCount() + d.getDwCount()); break;
case 2: out.setBy5ysCount(out.getBy5ysCount() + d.getDwCount()); break;
case 3: out.setLtxCount(out.getLtxCount() + d.getDwCount()); break;
case 4: out.setYrdwCount(out.getYrdwCount() + d.getDwCount()); break;
}
}
return new ArrayList<>(linked.values());
}
}

View File

@@ -0,0 +1,58 @@
package com.ruoyi.dw.domain.vo;
public class XyCheckDwOut {
private String xy;
private Integer by5ynCount;
private Integer by5ysCount;
private Integer ltxCount;
private Integer yrdwCount;
public String getXy() {
return xy;
}
public void setXy(String xy) {
this.xy = xy;
}
public Integer getBy5ynCount() {
return by5ynCount;
}
public void setBy5ynCount(Integer by5ynCount) {
this.by5ynCount = by5ynCount;
}
public Integer getBy5ysCount() {
return by5ysCount;
}
public void setBy5ysCount(Integer by5ysCount) {
this.by5ysCount = by5ysCount;
}
public Integer getLtxCount() {
return ltxCount;
}
public void setLtxCount(Integer ltxCount) {
this.ltxCount = ltxCount;
}
public Integer getYrdwCount() {
return yrdwCount;
}
public void setYrdwCount(Integer yrdwCount) {
this.yrdwCount = yrdwCount;
}
public Integer getAllCount(){
return this.ltxCount + this.by5ynCount + this.by5ysCount + this.yrdwCount;
}
}

View File

@@ -7,7 +7,7 @@ import java.util.Date;
public interface DataCheckMapper { public interface DataCheckMapper {
public DataCheckStatus getStatus(); public DataCheckStatus getStatus(String checkType);
public int startCheck(@Param("checkDate") Date checkDate); public int startCheck(@Param("checkDate") Date checkDate);
@@ -16,5 +16,6 @@ public interface DataCheckMapper {
public int updateCheck(@Param("startCheckDate") Date startCheckDate, public int updateCheck(@Param("startCheckDate") Date startCheckDate,
@Param("endCheckDate") Date endCheckDate, @Param("endCheckDate") Date endCheckDate,
@Param("weekCheck") int weekCheck, @Param("weekCheck") int weekCheck,
@Param("weekTimeCheck") String weekTimeCheck); @Param("weekTimeCheck") String weekTimeCheck,
@Param("checkType") String checkType);
} }

View File

@@ -5,5 +5,6 @@ public enum SortField {
GX_COUNT, GX_COUNT,
YX_COUNT, YX_COUNT,
WX_COUNT, WX_COUNT,
BZ_COUNT BZ_COUNT,
DW_COUNT
} }

View File

@@ -1,6 +1,8 @@
package com.ruoyi.dw.util; package com.ruoyi.dw.util;
import com.ruoyi.dw.domain.vo.XyCheck; import com.ruoyi.dw.domain.vo.XyCheck;
import com.ruoyi.dw.domain.vo.XyCheckDw;
import com.ruoyi.dw.domain.vo.XyCheckDwOut;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Comparator; import java.util.Comparator;
@@ -51,4 +53,36 @@ public class XyCheckSorter{
sortedList.sort(comparator); sortedList.sort(comparator);
return sortedList; return sortedList;
} }
/**
* 根据指定字段和排序方式对 XyCheck 列表进行排序
*
* @param list 原始列表
* @param sortField 排序字段ALL_COUNT、GX_COUNT、YX_COUNT、WX_COUNT
* @param sortOrder 排序方式ASC 升序 / DESC 降序)
* @return 排序后的列表(新列表,不影响原始数据)
*/
public static List<XyCheckDwOut> sortDwList(List<XyCheckDwOut> list, SortField sortField, SortOrder sortOrder) {
if (list == null || list.isEmpty()) {
return new ArrayList<>();
}
Comparator<XyCheckDwOut> comparator = null;
switch (sortField) {
case DW_COUNT:
comparator = Comparator.comparing(XyCheckDwOut::getAllCount);
break;
default:
throw new IllegalArgumentException("无效的排序字段: " + sortField);
}
if (sortOrder == SortOrder.DESC) {
comparator = comparator.reversed();
}
List<XyCheckDwOut> sortedList = new ArrayList<>(list);
sortedList.sort(comparator);
return sortedList;
}
} }

View File

@@ -13,8 +13,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="weekTimeCheck" column="week_time_check" /> <result property="weekTimeCheck" column="week_time_check" />
</resultMap> </resultMap>
<select id="getStatus" resultMap="dataCheckStatus"> <select id="getStatus" resultMap="dataCheckStatus" parameterType="string">
select id,check_status,begin_date,end_date,week_check,week_time_check from data_check_status where id = 1 select id,check_status,begin_date,end_date,week_check,week_time_check
from data_check_status where check_type = #{checkType}
</select> </select>
<update id="startCheck" parameterType="date"> <update id="startCheck" parameterType="date">
@@ -26,7 +27,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</update> </update>
<update id="updateCheck"> <update id="updateCheck">
update data_check_status set begin_date = #{startCheckDate},end_date = #{endCheckDate},week_check = #{weekCheck},week_time_check = #{weekTimeCheck} update data_check_status
set
begin_date = #{startCheckDate},
end_date = #{endCheckDate},
week_check = #{weekCheck},
week_time_check = #{weekTimeCheck}
where check_type = #{checkType}
</update> </update>
</mapper> </mapper>

View File

@@ -97,7 +97,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
select answer, count(0) as answer_count select answer, count(0) as answer_count
from dw_answer from dw_answer
where info_id = #{infoId} where info_id = #{infoId}
and question_id = #{questionId} and question_id = #{questionId} and answer != ''
group by answer group by answer
</select> </select>

View File

@@ -6,6 +6,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<resultMap type="XyCheckDw" id="xyCheckDw"> <resultMap type="XyCheckDw" id="xyCheckDw">
<result property="xy" column="xy" /> <result property="xy" column="xy" />
<result property="dwId" column="dw_id" />
<result property="dwCount" column="dw_count" /> <result property="dwCount" column="dw_count" />
</resultMap> </resultMap>
@@ -14,26 +15,47 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="dataCount" column="data_count" /> <result property="dataCount" column="data_count" />
</resultMap> </resultMap>
<select id="selectXyCheckDw" resultMap="xyCheckDw"> <select id="selectXyCheckDw" resultMap="xyCheckDw">
SELECT SELECT
re.xy,re.order_index, xy.jc as xy,
sum( re.dw_count ) as dw_count dw.id as dw_id,
ifnull(r1.xy_count,0) as dw_count
FROM FROM
( xy xy
INNER JOIN dw_info dw
LEFT JOIN (
SELECT SELECT
xy,order_index, xz.xy,
IFNULL( dw.dw_count, 0 ) AS dw_count zcy.info_id,
xz.order_index,
sum(
IFNULL( zcy.zy_count, 0 )) AS xy_count
FROM FROM
xy_zy xz xy_zy xz
LEFT JOIN ( SELECT answer, count( 0 ) AS dw_count FROM dw_answer LEFT JOIN (
WHERE question_id IN ( 3, 43, 71 ) SELECT
<if test="startDate != null"> and create_time &gt;= #{startDate}</if> info_id,
<if test="endDate != null"> and create_time &lt;= #{endDate} </if> answer AS zy,
GROUP BY answer ) AS dw ON dw.answer = xz.zy count( da.id ) AS zy_count
) AS re FROM
GROUP BY re.xy,re.order_index dw_answer da
order by re.order_index WHERE
da.answer IS NOT NULL
AND da.question_id IN ( 3, 43, 71, 91 )
<if test="startDate != null"> and create_time &gt; #{startDate}</if>
<if test="endDate != null"> and create_time &lt; #{endDate} </if>
GROUP BY
info_id,
answer
) AS zcy ON xz.zy = zcy.zy
GROUP BY
xz.xy,
xz.order_index,
zcy.info_id
ORDER BY
xz.order_index ASC,
zcy.info_id ASC
) as r1 on dw.id = r1.info_id and xy.xy = r1.xy
</select> </select>
<select id="selectAllCount" resultMap="xyDataCheck"> <select id="selectAllCount" resultMap="xyDataCheck">
@@ -70,9 +92,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
WHERE sfqr = 1 WHERE sfqr = 1
<if test="startDate != null"> and update_time &gt; #{startDate}</if> <if test="startDate != null"> and update_time &gt; #{startDate}</if>
<if test="endDate != null"> and update_time &lt; #{endDate} </if> <if test="endDate != null"> and update_time &lt; #{endDate} </if>
and sydshi is not null and dwxz in (SELECT dwxz from dwxz) and xy in (SELECT xy from xy) and bynf is not null and dwxz in (SELECT dwxz from dwxz) and xy in (SELECT xy from xy) and bynf is not null
GROUP BY xy ) AS re ON x.xy = re.xy GROUP BY xy ) AS re ON x.xy = re.xy
ORDER BY x.id ASC ORDER BY x.id ASC
</select> </select>
</mapper> </mapper>