baizonghao
2023-02-24 bcc6047ef19e2bd7a83c7f6e6abcb2cd1d8107cc
ycl-platform/src/main/java/com/ycl/service/unlawful/impl/UnlawfulServiceImpl.java
@@ -2,6 +2,7 @@
import com.ycl.dto.statistics.CategoryDto;
import com.ycl.dto.statistics.StatusDto;
import com.ycl.dto.statistics.TimeDto;
import com.ycl.dto.statistics.UnlawfulDto;
import com.ycl.mapper.unlawful.UnlawfulMapper;
import com.ycl.service.unlawful.UnlawfulService;
@@ -10,13 +11,12 @@
import javax.annotation.Resource;
import java.math.RoundingMode;
import java.text.NumberFormat;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
@Service
public class UnlawfulServiceImpl implements UnlawfulService {
    private List<UnlawfulDto> res = new ArrayList<>();
    @Resource
    private UnlawfulMapper unlawfuldao;
@@ -27,6 +27,7 @@
     */
    @Override
    public List<UnlawfulDto> getUnlawfulByType(Integer currentPage, Integer pageSize, String startTime, String endTime) {
        List<UnlawfulDto> res = new ArrayList<>();
        Double total = unlawfuldao.getTotal().doubleValue();
        List<CategoryDto> data = unlawfuldao.getDataByType(currentPage, pageSize, startTime, endTime);
        data.forEach(categoryDto -> {
@@ -37,6 +38,7 @@
    }
    @Override
    public List<UnlawfulDto> getUnlawfulByTypeExport() {
        List<UnlawfulDto> res = new ArrayList<>();
        Double total = unlawfuldao.getTotal().doubleValue();
        List<CategoryDto> data = unlawfuldao.getDataByTypeExp();
        data.forEach(categoryDto -> {
@@ -51,6 +53,7 @@
     */
    @Override
    public List<UnlawfulDto> getUnlawfulByStreet(Integer currentPage, Integer pageSize, String startTime, String endTime) {
        List<UnlawfulDto> res = new ArrayList<>();
        Double total = unlawfuldao.getTotal().doubleValue();
        List<CategoryDto> data = unlawfuldao.getDataByStreet(currentPage, pageSize, startTime, endTime);
        data.forEach(categoryDto -> {
@@ -61,6 +64,7 @@
    }
    @Override
    public List<UnlawfulDto> getUnlawfulByStreetExport() {
        List<UnlawfulDto> res = new ArrayList<>();
        Double total = unlawfuldao.getTotal().doubleValue();
        List<CategoryDto> data = unlawfuldao.getDataByStreetExp();
        data.forEach(categoryDto -> {
@@ -75,6 +79,7 @@
     */
    @Override
    public List<UnlawfulDto> getUnlawfulBySite(Integer currentPage, Integer pageSize, String startTime, String endTime) {
        List<UnlawfulDto> res = new ArrayList<>();
        Double total = unlawfuldao.getTotal().doubleValue();
        List<String> data = unlawfuldao.getDataBySite(currentPage, pageSize, startTime, endTime);
        data.forEach(site -> {
@@ -85,11 +90,36 @@
    }
    @Override
    public List<UnlawfulDto> getUnlawfulBySiteExport() {
        List<UnlawfulDto> res = new ArrayList<>();
        Double total = unlawfuldao.getTotal().doubleValue();
        List<String> data = unlawfuldao.getDataBySiteExp();
        data.forEach(site -> {
            StatusDto statusData = unlawfuldao.getStatusDataBySite(null, null, site);
            format1(res, total, site, statusData);
        });
        return res;
    }
    @Override
    public List<UnlawfulDto> getUnlawfulByTime(Integer currentPage, Integer pageSize, String startTime, String endTime) {
        List<UnlawfulDto> res = new ArrayList<>();
        Double total = unlawfuldao.getTotal().doubleValue();
        List<TimeDto> data = unlawfuldao.getDataByTime(currentPage, pageSize, startTime, endTime);
        data.forEach(timeDto -> {
            StatusDto statusData = unlawfuldao.getStatusDataByTime(startTime, endTime, timeDto.getId());
            format2(res, total, timeDto, statusData);
        });
        return res;
    }
    @Override
    public List<UnlawfulDto> getUnlawfulByTimeExport() {
        List<UnlawfulDto> res = new ArrayList<>();
        Double total = unlawfuldao.getTotal().doubleValue();
        List<TimeDto> data = unlawfuldao.getDataByTimeExp();
        data.forEach(timeDto -> {
            StatusDto statusData = unlawfuldao.getStatusDataByTime(null, null, timeDto.getId());
            format2(res, total, timeDto, statusData);
        });
        return res;
    }
@@ -117,6 +147,22 @@
        res.add(build);
    }
    private void format2(List<UnlawfulDto> res, Double total, TimeDto timeDto, StatusDto statusData) {
        DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        UnlawfulDto build = UnlawfulDto.builder().name(timeDto.getTime().format(fmt))     //类型名称
                .count(statusData.getTotal())   //事件总数
                .ratio(changeFormat(statusData.getTotal().doubleValue() / total))     //占比
                .register(statusData.getRegister())     //立案
                .notRegister(statusData.getNotRegister())   //暂不立案
                .closing(statusData.getClosing())   //结案
                .relearn(statusData.getRelearn())   //在学习
                .checked(statusData.getChecked())   //已审核
                .checkedRatio(changeFormat(statusData.getChecked().doubleValue() / statusData.getTotal().doubleValue()))  //审核率
                .registerRatio(changeFormat(statusData.getRegister().doubleValue() / statusData.getTotal().doubleValue()))    //立案率
                .build();
        res.add(build);
    }
    private void format1(List<UnlawfulDto> res, Double total, String site, StatusDto statusData) {
        UnlawfulDto build = UnlawfulDto.builder().name(site)     //类型名称
                .count(statusData.getTotal())   //事件总数