维修养护-数据统计

master
yangzhe123 2025-08-28 17:38:50 +08:00
parent 54474b63de
commit 9deb5985fa
8 changed files with 253 additions and 5 deletions

View File

@ -0,0 +1,69 @@
package com.gunshi.project.hsz.controller;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gunshi.core.result.R;
import com.gunshi.db.dto.DateTimeRangeSo;
import com.gunshi.db.dto.MonthRangeSo;
import com.gunshi.project.hsz.entity.so.MentenceFarmerRecordPageSo;
import com.gunshi.project.hsz.entity.vo.MentenceInfoCount12Vo;
import com.gunshi.project.hsz.entity.vo.MentenceInfoCountVo;
import com.gunshi.project.hsz.service.FileAssociationsService;
import com.gunshi.project.hsz.service.MentenceFarmerRecordService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;
@Tag(name = "维修养护-维护信息统计分析")
@RestController
@RequestMapping(value="/mic")
public class MentenceInfoCountController extends AbstractCommonFileController {
@Autowired
private MentenceFarmerRecordService mentenceFarmerRecordService;
@Autowired
private FileAssociationsService fileService;
@Operation(summary = "分页")
@PostMapping("/page")
public R<Page<MentenceInfoCountVo>> page(@RequestBody MentenceFarmerRecordPageSo pageSo) {
Page<MentenceInfoCountVo> byPage = mentenceFarmerRecordService.pageInfoCountQuery(pageSo);
if(!CollectionUtils.isEmpty(byPage.getRecords())){
byPage.getRecords().forEach(o -> o.setFiles(
fileService.getFiles(getGroupId(),o.getId().toString())
));
}
return R.ok(byPage);
}
@Operation(summary = "根据时间统计隐患数目")
@PostMapping("/count12")
public List<MentenceInfoCount12Vo> count12(@RequestBody MonthRangeSo monthRangeSo){
List<MentenceInfoCount12Vo> list = mentenceFarmerRecordService.count12(monthRangeSo);
return list;
}
@Operation(summary = "根据时间统计隐患类型数目")
@PostMapping("/countType")
public Map<Integer,Integer> countType(@RequestBody MonthRangeSo monthRangeSo){
Map<Integer,Integer> map = mentenceFarmerRecordService.countType(monthRangeSo);
return map;
}
@Operation(summary = "统计本年的隐患数")
@GetMapping("/countYear/{year}")
public Map<Integer,Integer> countYear(@PathVariable("year") String year){
Map<Integer,Integer> map = mentenceFarmerRecordService.countYear(year);
return map;
}
@Override
public String getGroupId() {
return "mentenceFarmerRecord";
}
}

View File

@ -1,5 +1,6 @@
package com.gunshi.project.hsz.entity.so; package com.gunshi.project.hsz.entity.so;
import com.gunshi.db.dto.DateTimeRangeSo;
import com.gunshi.db.dto.PageSo; import com.gunshi.db.dto.PageSo;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data; import lombok.Data;
@ -15,4 +16,10 @@ public class MentenceFarmerRecordPageSo {
@Schema(description = "维护项目Id") @Schema(description = "维护项目Id")
private Long mentenceStDetailId; private Long mentenceStDetailId;
@Schema(description = "状态")
private Integer status;
@Schema(description = "时间范围")
private DateTimeRangeSo dateTimeSo;
} }

View File

@ -0,0 +1,14 @@
package com.gunshi.project.hsz.entity.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import java.util.Date;
@Data
public class MentenceInfoCount12Vo {
private String month;
private Integer hiddenCount;
}

View File

@ -0,0 +1,28 @@
package com.gunshi.project.hsz.entity.vo;
import com.gunshi.project.hsz.model.FileAssociations;
import com.gunshi.project.hsz.model.HiddenInfo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.util.List;
@Data
@Schema(description = "维护信息统计分析")
public class MentenceInfoCountVo extends HiddenInfo {
@Schema(description = "维护对象名称")
private String mentenceStName;
@Schema(description = "维护项目名称")
private String mentenceStDetailName;
@Schema(description = "维护人Id")
private String mentencePersonId;
@Schema(description = "维护人名称")
private String mentencePersonName;
private List<FileAssociations> files;
}

View File

@ -0,0 +1,9 @@
package com.gunshi.project.hsz.entity.vo;
import lombok.Data;
@Data
public class StatusCountVo {
private Integer status;
private Integer count;
}

View File

@ -1,10 +1,67 @@
package com.gunshi.project.hsz.mapper; package com.gunshi.project.hsz.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.gunshi.db.dto.DateTimeRangeSo;
import com.gunshi.db.dto.MonthRangeSo;
import com.gunshi.project.hsz.entity.vo.MentenceInfoCount12Vo;
import com.gunshi.project.hsz.entity.vo.StatusCountVo;
import com.gunshi.project.hsz.model.HiddenInfo; import com.gunshi.project.hsz.model.HiddenInfo;
import com.gunshi.project.hsz.model.MentenceFarmerRecord; import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List;
import java.util.Map;
@Mapper @Mapper
public interface HiddenInfoMapper extends BaseMapper<HiddenInfo> { public interface HiddenInfoMapper extends BaseMapper<HiddenInfo> {
@Select("""
<script>
SELECT
TO_CHAR(found_time, 'YYYY-MM') AS month,
COUNT(*) AS hidden_count
FROM hidden_info
WHERE found_time &gt;= DATE_TRUNC('month', #{dto.start}::timestamp)
AND found_time &lt; DATE_TRUNC('month', #{dto.end}::timestamp) + INTERVAL '1 month'
GROUP BY TO_CHAR(found_time, 'YYYY-MM')
ORDER BY month;
</script>
""")
List<MentenceInfoCount12Vo> selectCount12(@Param("dto") MonthRangeSo monthRangeSo);
@Select("""
<script>
SELECT
status,
COUNT(*) AS count
FROM hidden_info
WHERE found_time &gt;= DATE_TRUNC('month', #{dto.start}::timestamp)
AND found_time &lt; DATE_TRUNC('month', #{dto.end}::timestamp) + INTERVAL '1 month'
GROUP BY status
ORDER BY status;
</script>
""")
@MapKey("status")
List<StatusCountVo> selectCountType(@Param("dto") MonthRangeSo monthRangeSo);
@Select("""
WITH all_status AS (
SELECT 0 AS status UNION
SELECT 1 AS status
)
SELECT
a.status,
COALESCE(COUNT(h.id), 0) AS count
FROM all_status a
LEFT JOIN hidden_info h
ON a.status = h.status
AND TO_CHAR(h.found_time, 'YYYY') = #{year}
GROUP BY a.status
ORDER BY a.status;
""")
@MapKey("status")
List<StatusCountVo> countYear(@Param("year") String year);
} }

View File

@ -3,8 +3,10 @@ package com.gunshi.project.hsz.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gunshi.project.hsz.entity.so.MentenceFarmerRecordPageSo; import com.gunshi.project.hsz.entity.so.MentenceFarmerRecordPageSo;
import com.gunshi.project.hsz.entity.vo.MentenceInfoCountVo;
import com.gunshi.project.hsz.model.MentenceFarmerRecord; import com.gunshi.project.hsz.model.MentenceFarmerRecord;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select; import org.apache.ibatis.annotations.Select;
@Mapper @Mapper
@ -12,9 +14,44 @@ public interface MentenceFarmerRecordMapper extends BaseMapper<MentenceFarmerRec
@Select(""" @Select("""
<script>
select t1.*,t2.name as mentenceStDetailName,t3.st_name as mentenceStName from mentence_farmer_record t1 select t1.*,t2.name as mentenceStDetailName,t3.st_name as mentenceStName from mentence_farmer_record t1
join mentence_st_detail t2 on t1.mentence_st_detail_id = t2.id join mentence_st_detail t2 on t1.mentence_st_detail_id = t2.id
join mentence_st t3 on t1.mentence_st_id = t3.id join mentence_st t3 on t1.mentence_st_id = t3.id
where 1=1
<if test="dto.mentenceStId != null">
and t1.mentence_st_id = #{dto.mentenceStId}
</if>
<if test="dto.mentenceStDetailId != null">
and t1.mentence_st_detail_id = #{dto.mentenceStDetailId}
</if>
</script>
""") """)
Page<MentenceFarmerRecord> pageQuery(Page<MentenceFarmerRecord> page, MentenceFarmerRecordPageSo pageSo); Page<MentenceFarmerRecord> pageQuery(Page<MentenceFarmerRecord> page,@Param(value = "dto") MentenceFarmerRecordPageSo pageSo);
@Select("""
<script>
select t1.*,t2.mentence_person_id as mentencePersonId,t2.mentence_person_name as mentencePersonName,
t3.name as mentenceStDetailName,t4.st_name as mentenceStName
from hidden_info t1
join mentence_farmer_record t2 on t1.mentence_farmer_record_id = t2.id
join mentence_st_detail t3 on t2.mentence_st_detail_id = t3.id
join mentence_st t4 on t2.mentence_st_id = t4.id
where 1=1
<if test="dto.mentenceStId != null">
and t2.mentence_st_id = #{dto.mentenceStId}
</if>
<if test="dto.mentenceStDetailId != null">
and t2.mentence_st_detail_id = #{dto.mentenceStDetailId}
</if>
<if test="dto.dateTimeSo !=null">
and t1.found_time between #{dto.dateTimeSo.start} and #{dto.dateTimeSo.end}
</if>
<if test="dto.status != null">
and t1.status = #{dto.status}
</if>
</script>
""")
Page<MentenceInfoCountVo> pageInfoCountQuery(Page<Object> page,@Param("dto") MentenceFarmerRecordPageSo pageSo);
} }

View File

@ -5,14 +5,16 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.IdWorker; import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gunshi.db.dto.DateTimeRangeSo;
import com.gunshi.db.dto.MonthRangeSo;
import com.gunshi.project.hsz.entity.so.MentenceFarmerRecordPageSo; import com.gunshi.project.hsz.entity.so.MentenceFarmerRecordPageSo;
import com.gunshi.project.hsz.entity.vo.MentenceInfoCount12Vo;
import com.gunshi.project.hsz.entity.vo.MentenceInfoCountVo;
import com.gunshi.project.hsz.entity.vo.StatusCountVo;
import com.gunshi.project.hsz.mapper.HiddenInfoMapper; import com.gunshi.project.hsz.mapper.HiddenInfoMapper;
import com.gunshi.project.hsz.mapper.MentenceFarmerRecordMapper; import com.gunshi.project.hsz.mapper.MentenceFarmerRecordMapper;
import com.gunshi.project.hsz.mapper.MentencePlanDetailMapper;
import com.gunshi.project.hsz.model.HiddenInfo; import com.gunshi.project.hsz.model.HiddenInfo;
import com.gunshi.project.hsz.model.MentenceFarmerRecord; import com.gunshi.project.hsz.model.MentenceFarmerRecord;
import com.gunshi.project.hsz.model.MentencePlanDetail;
import com.gunshi.project.hsz.model.MentenceTemplate;
import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.usermodel.*; import org.apache.poi.ss.usermodel.*;
@ -28,7 +30,10 @@ import java.net.URLEncoder;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.stream.Collector;
import java.util.stream.Collectors;
@Service @Service
@Slf4j @Slf4j
@ -107,6 +112,12 @@ public class MentenceFarmerRecordService extends ServiceImpl<MentenceFarmerRecor
return pageRecord; return pageRecord;
} }
public Page<MentenceInfoCountVo> pageInfoCountQuery(MentenceFarmerRecordPageSo pageSo) {
Page<MentenceInfoCountVo> voPage = baseMapper.pageInfoCountQuery(pageSo.getPageSo().toPage(),pageSo);
return voPage;
}
public void exportToExcel(List<MentenceFarmerRecord> records, HttpServletResponse response) { public void exportToExcel(List<MentenceFarmerRecord> records, HttpServletResponse response) {
Workbook workbook = new XSSFWorkbook(); Workbook workbook = new XSSFWorkbook();
Sheet sheet = workbook.createSheet("日常养护记录"); Sheet sheet = workbook.createSheet("日常养护记录");
@ -134,6 +145,22 @@ public class MentenceFarmerRecordService extends ServiceImpl<MentenceFarmerRecor
} }
} }
public List<MentenceInfoCount12Vo> count12(MonthRangeSo monthRangeSo) {
List<MentenceInfoCount12Vo> res = hiddenInfoMapper.selectCount12(monthRangeSo);
return res;
}
public Map<Integer, Integer> countType(MonthRangeSo monthRangeSo) {
return hiddenInfoMapper.selectCountType(monthRangeSo).stream()
.collect(Collectors.toMap(StatusCountVo::getStatus, StatusCountVo::getCount));
}
public Map<Integer, Integer> countYear(String year) {
return hiddenInfoMapper.countYear(year).stream()
.collect(Collectors.toMap(StatusCountVo::getStatus, StatusCountVo::getCount));
}
private static class StyleGroup { private static class StyleGroup {
CellStyle headerStyle; CellStyle headerStyle;
CellStyle dataStyle; CellStyle dataStyle;