zhanghua
2023-04-14 e8a0f05f99f33fa05085536541da6bc27e66a644
ycl-platform/src/main/java/com/ycl/service/unlawful/impl/UnlawfulServiceImpl.java
@@ -1,18 +1,22 @@
package com.ycl.service.unlawful.impl;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
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;
import com.ycl.utils.StringUtils;
import org.springframework.stereotype.Service;
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;
import java.util.function.Consumer;
@Service
public class UnlawfulServiceImpl implements UnlawfulService {
@@ -21,61 +25,61 @@
    private UnlawfulMapper unlawfuldao;
    /**
     * 按类型
     */
    @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 -> {
            Double checkedRatio; //审核率
            Double registerRatio; //立案率
            StatusDto statusData = unlawfuldao.getStatusDataByType(startTime, endTime, categoryDto.getId());
            UnlawfulDto build = new UnlawfulDto().builder().name(categoryDto.getName())     //类型名称
                    .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);
        });
        return res;
    public IPage<UnlawfulDto> getUnlawfulByType(Integer currentPage, Integer pageSize, String startTime, String endTime) {
        Page<UnlawfulDto> page = new Page<>(currentPage, pageSize);
        Double total = unlawfuldao.getTotal(startTime, endTime, true, false, false).doubleValue();
        IPage<UnlawfulDto> page1 = unlawfuldao.getDataByType(page, startTime, endTime);
        return getUnlawfulDtoIPage(total, page1);
    }
    @Override
    public List<UnlawfulDto> getUnlawfulByTypeExport() {
        List<UnlawfulDto> res = new ArrayList<>();
        Double total = unlawfuldao.getTotal().doubleValue();
        List<CategoryDto> data = unlawfuldao.getDataByTypeExp();
        data.forEach(categoryDto -> {
            Double checkedRatio; //审核率
            Double registerRatio; //立案率
            StatusDto statusData = unlawfuldao.getStatusDataByType(null, null, categoryDto.getId());
            UnlawfulDto build = new UnlawfulDto().builder().name(categoryDto.getName())     //类型名称
                    .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 IPage<UnlawfulDto> getUnlawfulDtoIPage(Double total, IPage<UnlawfulDto> page1) {
        page1.getRecords().forEach(dto -> {
            dto.setRatio(StringUtils.doubleTwo((double) dto.getCount() / total));
            dto.setRegisterRatio(StringUtils.doubleTwo((double) dto.getRegister() / (double) dto.getCount()));
            dto.setCheckedRatio(StringUtils.doubleTwo((double) dto.getChecked() / (double) dto.getCount()));
            dto.setAccuracyRatio(StringUtils.doubleTwo(1.0 - (double) dto.getRelearn() / (double) dto.getCount()));
        });
        return res;
        return page1;
    }
    private Double changeFormat(Double previous){
        NumberFormat numberInstance = NumberFormat.getNumberInstance();
        numberInstance.setMaximumFractionDigits(2);
        numberInstance.setRoundingMode(RoundingMode.HALF_UP);
        String format = numberInstance.format(previous);
        return Double.parseDouble(format);
    /**
     * 按区域
     */
    @Override
    public IPage<UnlawfulDto> getUnlawfulByStreet(Integer currentPage, Integer pageSize, String startTime, String endTime) {
        Page<UnlawfulDto> page = new Page<>(currentPage, pageSize);
        Double total = unlawfuldao.getTotal(startTime, endTime, false, true, false).doubleValue();
        IPage<UnlawfulDto> page1 = unlawfuldao.getDataByStreet(page, startTime, endTime);
        return getUnlawfulDtoIPage(total, page1);
    }
    @Override
    public IPage<UnlawfulDto> getUnlawfulByTime(Integer currentPage, Integer pageSize, String startTime, String endTime) {
        Page<UnlawfulDto> page = new Page<>(currentPage, pageSize);
        Double total = unlawfuldao.getTotal(startTime, endTime, false, false, false).doubleValue();
        IPage<UnlawfulDto> page1 = unlawfuldao.getDataByTime(page, startTime, endTime);
        return getUnlawfulDtoIPage(total, page1);
    }
    @Override
    public IPage<UnlawfulDto> getUnlawfulByPoint(Integer currentPage, Integer pageSize, String startTime, String endTime) {
        Page<UnlawfulDto> page = new Page<>(currentPage, pageSize);
        Double total = unlawfuldao.getTotal(startTime, endTime, false, false, true).doubleValue();
        IPage<UnlawfulDto> page1 = unlawfuldao.getDataByPoint(page, startTime, endTime);
        return getUnlawfulDtoIPage(total, page1);
    }
}