zf
2023-08-30 464fe41610a39c3a06f070d5a01c930134ff0163
检查统计
已修改12个文件
已添加10个文件
791 ■■■■■ 文件已修改
src/main/java/com/gk/hotwork/Controller/SafetyInspectionStatisticCotroller.java 58 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/gk/hotwork/Domain/Do/CompanyInspectionCountDO.java 33 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/gk/hotwork/Domain/Do/CompanyStatisticInspectionDO.java 20 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/gk/hotwork/Domain/Do/StatisticCompanyCount.java 20 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/gk/hotwork/Domain/Do/SubordinateOrganizationInfoDO.java 42 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/gk/hotwork/Domain/dto/resp/AreaInspectionCountRespDTO.java 63 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/gk/hotwork/Domain/dto/resp/CompanyInspectionCountRespDTO.java 43 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/gk/hotwork/Domain/query/CountQuery.java 31 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/gk/hotwork/Mapper/CompanyInfoMapper.java 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/gk/hotwork/Mapper/InspectionHiddenDangerMapper.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/gk/hotwork/Mapper/SafetySelfInspectionMapper.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/gk/hotwork/Mapper/mybatis/CompanyInfoMapper.xml 58 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/gk/hotwork/Mapper/mybatis/InspectionHiddenDangerMapper.xml 51 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/gk/hotwork/Mapper/mybatis/SafetySelfInspectionMapper.xml 58 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/gk/hotwork/Service/CompanyService.java 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/gk/hotwork/Service/InspectionHiddenDangerService.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/gk/hotwork/Service/SafetyInspectionStatisticService.java 18 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/gk/hotwork/Service/SafetySelfInspectionService.java 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/gk/hotwork/Service/ServiceImpl/CompanyServiceImpl.java 27 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/gk/hotwork/Service/ServiceImpl/InspectionHiddenDangerServiceImpl.java 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/gk/hotwork/Service/ServiceImpl/SafetyInspectionStatisticServiceImpl.java 197 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/gk/hotwork/Service/ServiceImpl/SafetySelfInspectionImpl.java 24 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/gk/hotwork/Controller/SafetyInspectionStatisticCotroller.java
对比新文件
@@ -0,0 +1,58 @@
package com.gk.hotwork.Controller;
import com.alibaba.fastjson.JSONObject;
import com.gk.hotwork.Controller.Base.BaseController;
import com.gk.hotwork.Domain.Utils.Msg;
import com.gk.hotwork.Domain.dto.resp.SafetySelfInspectionRespDTO;
import com.gk.hotwork.Domain.query.CountQuery;
import com.gk.hotwork.Service.SafetyInspectionStatisticService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
 * @email 1603559716@qq.com
 * @author: zf
 * @date: 2023/8/22
 * @time: 15:28
 */
@Api(tags = "自查清单_统计")
@RestController
@RequestMapping("/statistic")
public class SafetyInspectionStatisticCotroller extends BaseController {
    @Autowired
    private SafetyInspectionStatisticService statisticService;
    @ApiOperation("/统计")
    @PostMapping("/getCountByArea")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "province",value = "省"),
            @ApiImplicitParam(name = "city",value = "市"),
            @ApiImplicitParam(name = "area",value = "县"),
            @ApiImplicitParam(name = "startTime",value = "开始时间"),
            @ApiImplicitParam(name = "endTime",value = "结束时间")
    })
    public Msg getCountByArea(@RequestBody CountQuery query) {
        Msg msg = statisticService.getCountByArea(query,getUser());
        return msg;
    }
    @ApiOperation("/未检查公司")
    @PostMapping("/getUnCheckCompany")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "province",value = "省"),
            @ApiImplicitParam(name = "city",value = "市"),
            @ApiImplicitParam(name = "area",value = "县"),
            @ApiImplicitParam(name = "startTime",value = "开始时间"),
            @ApiImplicitParam(name = "endTime",value = "结束时间")
    })
    public Msg getUnCheckCompany(@RequestBody CountQuery query) {
        Msg msg = statisticService.getUnCheckCompany(query);
        return msg;
    }
}
src/main/java/com/gk/hotwork/Domain/Do/CompanyInspectionCountDO.java
对比新文件
@@ -0,0 +1,33 @@
package com.gk.hotwork.Domain.Do;
import io.swagger.models.auth.In;
import lombok.Data;
/**
 * @email 1603559716@qq.com
 * @author: zf
 * @date: 2023/8/24
 * @time: 14:27
 */
@Data
public class CompanyInspectionCountDO {
    private Long companyId;
    //检查总数
    private int checkTotal;
    //未整改总数
    private int sUnReTotal;
    //整改总数
    private int sReTotal;
    //隐患总数
    private int sHdTotal;
    //一般总数
    private int sSaTotal;
    //重大总数
    private int sMaTotal;
    //一般整改总数
    private int sSaReTotal;
    //重大整改总数
    private int sMaReTotal;
}
src/main/java/com/gk/hotwork/Domain/Do/CompanyStatisticInspectionDO.java
对比新文件
@@ -0,0 +1,20 @@
package com.gk.hotwork.Domain.Do;
import lombok.Data;
/**
 * @email 1603559716@qq.com
 * @author: zf
 * @date: 2023/8/25
 * @time: 15:11
 */
@Data
public class CompanyStatisticInspectionDO {
    private int checkCompanyCount;
    private int endTotal;
    private int toDoTotal;
    private int checkTotal;
    private int hdTotal;
    private int unRectifyTotal;
    private int rectifyTotal;
}
src/main/java/com/gk/hotwork/Domain/Do/StatisticCompanyCount.java
对比新文件
@@ -0,0 +1,20 @@
package com.gk.hotwork.Domain.Do;
import lombok.Data;
/**
 * @email 1603559716@qq.com
 * @author: zf
 * @date: 2023/8/25
 * @time: 11:01
 */
@Data
public class StatisticCompanyCount {
    private String province;
    private String city;
    private String area;
    private Integer count;
}
src/main/java/com/gk/hotwork/Domain/Do/SubordinateOrganizationInfoDO.java
对比新文件
@@ -0,0 +1,42 @@
package com.gk.hotwork.Domain.Do;
/**
 * @email 1603559716@qq.com
 * @author: zf
 * @date: 2023/8/24
 * @time: 16:36
 */
public class SubordinateOrganizationInfoDO {
    //省
    private String Province;
    //市
    private String city;
    //区县
    private String area;
    public String getProvince() {
        return Province;
    }
    public void setProvince(String province) {
        Province = province;
    }
    public String getCity() {
        return city;
    }
    public void setCity(String city) {
        this.city = city;
    }
    public String getArea() {
        return area;
    }
    public void setArea(String area) {
        this.area = area;
    }
}
src/main/java/com/gk/hotwork/Domain/dto/resp/AreaInspectionCountRespDTO.java
对比新文件
@@ -0,0 +1,63 @@
package com.gk.hotwork.Domain.dto.resp;
import lombok.Data;
import java.math.BigDecimal;
/**
 * @email 1603559716@qq.com
 * @author: zf
 * @date: 2023/8/22
 * @time: 15:59
 */
@Data
public class AreaInspectionCountRespDTO {
    /**
     * 地区名称
     */
    private String province;
    private String city;
    private String area;
    /**
     * 企业总数
     */
    private int companyTotal;
    /**
     * 创建自查清单企业数
     */
    private int checkCompanyCount;
    /**
     * 自查清单总数
     */
    private int checkTotal;
    /**
     * 未结单
     */
    private int toDoTotal;
    /**
     * 结单数据
     */
    private int endTotal;
    /**
     * 未自查企业
     */
    private int unCheckCompanyCount;
    /**
     * 隐患总数
     */
    private int hdTotal;
    /**
     * 未整改数量
     */
    private int unRectifyTotal;
    /**
     * 已整改数量
     */
    private int rectifyTotal;
    /**
     * 整改率
     */
    private BigDecimal rectifyRate;
}
src/main/java/com/gk/hotwork/Domain/dto/resp/CompanyInspectionCountRespDTO.java
对比新文件
@@ -0,0 +1,43 @@
package com.gk.hotwork.Domain.dto.resp;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import java.math.BigDecimal;
import java.util.Date;
/**
 * @email 1603559716@qq.com
 * @author: zf
 * @date: 2023/8/24
 * @time: 10:14
 */
@Data
public class CompanyInspectionCountRespDTO {
    private Long companyId;
    private String companyName;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm" , timezone = "GMT+8")
    private Date lastTime;
    //检查总数
    private int checkTotal;
    //未整改总数
    private int sUnReTotal;
    //整改总数
    private int sReTotal;
    //隐患总数
    private int sHdTotal;
    //一般总数
    private int sSaTotal;
    //重大总数
    private int sMaTotal;
    //一般整改总数
    private int sSaReTotal;
    //重大整改总数
    private int sMaReTotal;
    //整改率
    private BigDecimal rectifyRate;
}
src/main/java/com/gk/hotwork/Domain/query/CountQuery.java
对比新文件
@@ -0,0 +1,31 @@
package com.gk.hotwork.Domain.query;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.models.auth.In;
import lombok.Data;
import java.util.Date;
/**
 * @email 1603559716@qq.com
 * @author: zf
 * @date: 2023/8/22
 * @time: 15:42
 */
@Data
public class CountQuery {
    private String province;
    private String city;
    private String area;
    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    private Date startTime;
    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    private Date endTime;
    private Integer pageIndex;
    private Integer pageSize;
}
src/main/java/com/gk/hotwork/Mapper/CompanyInfoMapper.java
@@ -3,7 +3,9 @@
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gk.hotwork.Domain.CompanyInfo;
import com.gk.hotwork.Domain.Do.StatisticCompanyCount;
import com.gk.hotwork.Domain.query.CompanyQuery;
import com.gk.hotwork.Domain.query.CountQuery;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
@@ -23,4 +25,9 @@
    List<CompanyInfo> selectCompanyList(@Param("query") CompanyQuery query);
    List<CompanyInfo> selectCompanyList(Page<CompanyInfo> page,@Param("query") CompanyQuery query);
    Integer getCountByArea(@Param("params")Map<String,Object> params);
    List<CompanyInfo> getUncheckCompanyByArea(Page<CompanyInfo> page,@Param("query") CountQuery query);
}
src/main/java/com/gk/hotwork/Mapper/InspectionHiddenDangerMapper.java
@@ -3,9 +3,11 @@
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gk.hotwork.Domain.Do.CompanyInspectionCountDO;
import com.gk.hotwork.Domain.InspectionHiddenDanger;
import com.gk.hotwork.Domain.SafetySelfInspection;
import com.gk.hotwork.Domain.SafetySelfInspectionDO;
import com.gk.hotwork.Domain.query.CountQuery;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
@@ -27,4 +29,6 @@
    IPage<SafetySelfInspectionDO> selectPages(Page<SafetySelfInspection> page, @Param("params") Map<String, Object> params);
    List<InspectionHiddenDanger> inspectionHdangerlist(Long selfInspectionId);
    List<CompanyInspectionCountDO> getStatisticHiddenDanger(@Param("query") CountQuery query);
}
src/main/java/com/gk/hotwork/Mapper/SafetySelfInspectionMapper.java
@@ -3,9 +3,12 @@
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gk.hotwork.Domain.Do.CompanyStatisticInspectionDO;
import com.gk.hotwork.Domain.SafetySelfInspection;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.Map;
@Repository
@@ -14,4 +17,5 @@
    IPage<SafetySelfInspection> selectPages(@Param("page") Page<SafetySelfInspection> page,@Param("params") Map<String, Object> params);
    CompanyStatisticInspectionDO companyStatisticInspection(@Param("params") Map<String, Object> params);
}
src/main/java/com/gk/hotwork/Mapper/mybatis/CompanyInfoMapper.xml
@@ -150,4 +150,62 @@
      </if>
    </where>
  </select>
  <select id="getCountByArea" resultType="java.lang.Integer">
    SELECT count(*) FROM company
    where isdel = 0
    <if test="params.province != null and params.province !=''">
      and province = #{params.province}
    </if>
    <if test="params.city != null and params.city !=''">
      and city = #{params.city}
    </if>
    <if test="params.area != null and params.area !=''">
      and area = #{params.area}
    </if>
  </select>
  <select id="getUncheckCompanyByArea"  resultType="com.gk.hotwork.Domain.CompanyInfo">
    SELECT
      c1.*
    FROM
      company c1
    WHERE
      c1.isdel = 0
      <if test="query.province != null and query.province !=''">
        and c1.province = #{query.province}
      </if>
      <if test="query.city != null and query.city !=''">
        and c1.city = #{query.city}
      </if>
      <if test="query.area != null and query.area !=''">
        and c1.area = #{query.area}
      </if>
      AND c1.id NOT IN (
      SELECT
        s.checked_company_id
      FROM
        safety_self_inspection s
          INNER JOIN company c ON c.id = s.checked_company_id
      WHERE
        s.valid_flag = 1
        AND s.flag = 2
        <if test="query.province != null and query.province !=''">
          and c.province = #{query.province}
        </if>
        <if test="query.city != null and query.city !=''">
          and c.city = #{query.city}
        </if>
        <if test="query.area != null and query.area !=''">
          and c.area = #{query.area}
        </if>
        <if test="query.startTime != null" >
          and s.inspection_time <![CDATA[ >= ]]> #{query.startTime}
        </if>
        <if test="query.endTime != null" >
          and s.inspection_time <![CDATA[ <= ]]> #{query.endTime}
        </if>
      GROUP BY
        s.checked_company_id
    )
  </select>
</mapper>
src/main/java/com/gk/hotwork/Mapper/mybatis/InspectionHiddenDangerMapper.xml
@@ -104,5 +104,56 @@
        and h.self_inspection_id = #{selfInspectionId}
    </select>
    <select id="getStatisticHiddenDanger" resultType="com.gk.hotwork.Domain.Do.CompanyInspectionCountDO">
        select
            l.checked_company_id as companyId,
            count(l.id) as checkTotal,
            sum(l.unRectifyTotal) as sUnReTotal,
            sum(l.reTotal) as sReTotal,
            sum(l.hdTocal) as sHdTotal,
            sum(l.saTotal) as sSaTotal,
            sum(l.maTotal) as sMaTotal,
            sum(l.saReTotal) as sSaReTotal,
            sum(l.maReTotal) as sMaReTotal
        from (
                 SELECT
                     s.id,
                     s.checked_company_id,
                     t.*
                 FROM
                     safety_self_inspection s
                         INner JOIN company c on s.checked_company_id = c.id
                         LEFT JOIN (
                         SELECT
                             h.self_Inspection_id,
                             count( h.`status` = - 1 OR NULL ) unRectifyTotal,
                             count( h.`status` = 1 OR NULL ) reTotal,
                             count( h.`status` ) hdTocal,
                             count( h.LEVEL = 1 OR NULL ) saTotal,
                             count( h.LEVEL = 2 OR NULL ) maTotal,
                             count( h.LEVEL = 1 AND h.`status` = 1 OR NULL ) saReTotal,
                             count( h.LEVEL = 2 AND h.`status` = 1 OR NULL ) maReTotal
                         FROM
                             inspection_hidden_danger h
                         WHERE
                             h.valid_flag = 1
                         GROUP BY
                             h.self_Inspection_id
                     ) t ON t.self_Inspection_id = s.id
                 WHERE
                        s.valid_flag = 1
                        and s.flag = 2
                    <if test="query.startTime != null" >
                        and s.inspection_time <![CDATA[ >= ]]> #{query.startTime}
                    </if>
                    <if test="query.endTime != null" >
                        and s.inspection_time <![CDATA[ <= ]]> #{query.endTime}
                    </if>
                    <if test="query.area != null and query.area != ''" >
                        and c.area = #{query.area}
                    </if>
             ) l
        GROUP BY l.checked_company_id
    </select>
</mapper>
src/main/java/com/gk/hotwork/Mapper/mybatis/SafetySelfInspectionMapper.xml
@@ -62,5 +62,61 @@
    </if>
    order by a.create_time desc
  </select>
  <select id="companyStatisticInspection" resultType="com.gk.hotwork.Domain.Do.CompanyStatisticInspectionDO">
    SELECT
      count( 1 ) checkCompanyCount,
      sum( l.endCount ) endTotal,
      sum( l.toDoCount ) toDoTotal,
      sum( l.checkCount ) checkTotal,
      sum( l.unRectifyCount ) unRectifyTotal,
      sum( l.rectifyCount ) rectifyTotal,
      sum( l.hdCount ) AS hdTotal
    FROM
      (
        SELECT
          s.checked_company_id,
          count( s.`status` = 2 OR NULL ) endCount,
          count( s.`status` = 1 OR NULL ) toDoCount,
          count( 1 ) AS checkCount,
          sum( t.unRectify ) AS unRectifyCount,
          sum( t.rectify ) AS rectifyCount,
          sum( t.hd ) AS hdCount
        FROM
          safety_self_inspection s
            INNER JOIN company c ON c.id = s.checked_company_id
            LEFT JOIN (
            SELECT
              h.self_Inspection_id,
              count( h.`status` = - 1 OR NULL ) unRectify,
              count( h.`status` = 1 OR NULL ) rectify,
              count( 1 ) hd
            FROM
              inspection_hidden_danger h
            WHERE
              h.valid_flag = 1
            GROUP BY
              h.self_Inspection_id
          ) t ON t.self_Inspection_id = s.id
        WHERE
          s.valid_flag = 1
          AND s.flag = 2
          <if test="params.startTime != null" >
            and s.inspection_time <![CDATA[ >= ]]> #{params.startTime}
          </if>
          <if test="params.endTime != null " >
            and s.inspection_time <![CDATA[ <= ]]> #{params.endTime}
          </if>
          <if test="params.province != null and params.province != ''" >
            and c.province = #{params.province}
          </if>
          <if test="params.city != null and params.city != ''" >
            and c.city = #{params.city}
          </if>
          <if test="params.area != null and params.area != ''" >
            and c.area = #{params.area}
          </if>
        GROUP BY
          s.checked_company_id
      ) l
  </select>
</mapper>
src/main/java/com/gk/hotwork/Service/CompanyService.java
@@ -1,11 +1,16 @@
package com.gk.hotwork.Service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.gk.hotwork.Domain.CompanyInfo;
import com.gk.hotwork.Domain.Do.StatisticCompanyCount;
import com.gk.hotwork.Domain.UserInfo;
import com.gk.hotwork.Domain.Utils.PageInfo;
import com.gk.hotwork.Domain.query.CountQuery;
import io.swagger.models.auth.In;
import java.util.List;
import java.util.Map;
public interface CompanyService extends IService<CompanyInfo> {
@@ -22,4 +27,9 @@
    boolean isMain(String company);
    List<CompanyInfo> selectCompanyList(String companyName, UserInfo user);
    Integer getCountByArea(Map<String,Object> params);
    Page<CompanyInfo> getUncheckCompanyByArea(CountQuery query);
    Page<CompanyInfo> getByArea(CountQuery query);
}
src/main/java/com/gk/hotwork/Service/InspectionHiddenDangerService.java
@@ -3,10 +3,12 @@
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.gk.hotwork.Domain.Do.CompanyInspectionCountDO;
import com.gk.hotwork.Domain.InspectionHiddenDanger;
import com.gk.hotwork.Domain.SafetySelfInspection;
import com.gk.hotwork.Domain.UserInfo;
import com.gk.hotwork.Domain.Utils.PageInfo;
import com.gk.hotwork.Domain.query.CountQuery;
import java.util.List;
import java.util.Map;
@@ -30,4 +32,6 @@
    IPage selectPage(Page<SafetySelfInspection> page, Map<String, Object> filter, UserInfo user);
    List<InspectionHiddenDanger> inspectionHdangerlist(Long selfInspectionId);
    List<CompanyInspectionCountDO> getStatisticHiddenDanger(CountQuery query);
}
src/main/java/com/gk/hotwork/Service/SafetyInspectionStatisticService.java
对比新文件
@@ -0,0 +1,18 @@
package com.gk.hotwork.Service;
import com.gk.hotwork.Domain.UserInfo;
import com.gk.hotwork.Domain.Utils.Msg;
import com.gk.hotwork.Domain.dto.resp.SafetySelfInspectionRespDTO;
import com.gk.hotwork.Domain.query.CountQuery;
/**
 * @email 1603559716@qq.com
 * @author: zf
 * @date: 2023/8/22
 * @time: 15:41
 */
public interface SafetyInspectionStatisticService {
    Msg getCountByArea(CountQuery query, UserInfo user);
    Msg getUnCheckCompany(CountQuery query);
}
src/main/java/com/gk/hotwork/Service/SafetySelfInspectionService.java
@@ -4,11 +4,13 @@
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.gk.hotwork.Domain.AttachmentInfo;
import com.gk.hotwork.Domain.Do.CompanyStatisticInspectionDO;
import com.gk.hotwork.Domain.SafetySelfInspection;
import com.gk.hotwork.Domain.SafetySelfInspectionItem;
import com.gk.hotwork.Domain.UserInfo;
import com.gk.hotwork.Domain.dto.resp.SafetySelfInspectionRespDTO;
import java.util.Date;
import java.util.List;
import java.util.Map;
@@ -54,4 +56,8 @@
    void addItemExpert(List<SafetySelfInspectionItem> itemList, UserInfo user);
    void addCheckAttachment(List<AttachmentInfo> attachmentList, UserInfo user);
    Date selectLastTimeByCompanyId(Long id,Date startTime,Date endTime);
    CompanyStatisticInspectionDO companyStatisticInspection(Map<String,Object> params);
}
src/main/java/com/gk/hotwork/Service/ServiceImpl/CompanyServiceImpl.java
@@ -5,12 +5,15 @@
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gk.hotwork.Domain.CompanyInfo;
import com.gk.hotwork.Domain.Do.StatisticCompanyCount;
import com.gk.hotwork.Domain.UserInfo;
import com.gk.hotwork.Domain.Utils.PageInfo;
import com.gk.hotwork.Domain.Utils.StringUtils;
import com.gk.hotwork.Domain.query.CompanyQuery;
import com.gk.hotwork.Domain.query.CountQuery;
import com.gk.hotwork.Mapper.CompanyInfoMapper;
import com.gk.hotwork.Service.CompanyService;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -98,5 +101,29 @@
        return companyInfos;
    }
    @Override
    public Integer getCountByArea(Map<String,Object> params) {
        return companyInfoMapper.getCountByArea(params);
    }
    @Override
    public Page<CompanyInfo> getUncheckCompanyByArea(CountQuery query){
        Page<CompanyInfo> page = new Page<>(query.getPageIndex(),query.getPageSize());
        List<CompanyInfo> companyInfos = companyInfoMapper.getUncheckCompanyByArea(page,query);
        page.setRecords(companyInfos);
        return page;
    }
    @Override
    public Page<CompanyInfo> getByArea(CountQuery query){
       Page<CompanyInfo> page = new Page<>(query.getPageIndex(),query.getPageSize());
       CompanyQuery companyQuery = new CompanyQuery();
       companyQuery.setArea(query.getArea());
       List<CompanyInfo> companyInfos = companyInfoMapper.selectCompanyList(page,companyQuery);
       page.setRecords(companyInfos);
       return page;
    }
}
src/main/java/com/gk/hotwork/Service/ServiceImpl/InspectionHiddenDangerServiceImpl.java
@@ -5,11 +5,13 @@
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gk.hotwork.Domain.*;
import com.gk.hotwork.Domain.Do.CompanyInspectionCountDO;
import com.gk.hotwork.Domain.Do.SafetySelfInspectionItemQualifiedCountDO;
import com.gk.hotwork.Domain.Exception.BusinessException;
import com.gk.hotwork.Domain.Utils.PageInfo;
import com.gk.hotwork.Domain.Utils.StringUtils;
import com.gk.hotwork.Domain.dto.resp.InspectionHiddenDangerRespDTO;
import com.gk.hotwork.Domain.query.CountQuery;
import com.gk.hotwork.Mapper.InspectionExpertMapper;
import com.gk.hotwork.Mapper.InspectionHiddenDangerMapper;
import com.gk.hotwork.Service.AttachmentInfoService;
@@ -157,6 +159,17 @@
    }
    /**
     * 统计
     * @param query
     * @return
     */
    @Override
    public List<CompanyInspectionCountDO> getStatisticHiddenDanger(CountQuery query) {
        return inspectionHiddenDangerMapper.getStatisticHiddenDanger(query);
    }
    private void modrequiredVerification(InspectionHiddenDanger inspectionHiddenDanger){
        if(inspectionHiddenDanger.getId() == null){
            throw new BusinessException("隐患主键不可为空");
src/main/java/com/gk/hotwork/Service/ServiceImpl/SafetyInspectionStatisticServiceImpl.java
对比新文件
@@ -0,0 +1,197 @@
package com.gk.hotwork.Service.ServiceImpl;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gk.hotwork.Domain.*;
import com.gk.hotwork.Domain.Do.CompanyInspectionCountDO;
import com.gk.hotwork.Domain.Do.CompanyStatisticInspectionDO;
import com.gk.hotwork.Domain.Do.SubordinateOrganizationInfoDO;
import com.gk.hotwork.Domain.Utils.BeanUtils;
import com.gk.hotwork.Domain.Utils.Msg;
import com.gk.hotwork.Domain.Utils.StringUtils;
import com.gk.hotwork.Domain.dto.resp.AreaInspectionCountRespDTO;
import com.gk.hotwork.Domain.dto.resp.CompanyInspectionCountRespDTO;
import com.gk.hotwork.Domain.query.CountQuery;
import com.gk.hotwork.Service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
 * @email 1603559716@qq.com
 * @author: zf
 * @date: 2023/8/22
 * @time: 15:41
 */
@Service
public class SafetyInspectionStatisticServiceImpl implements SafetyInspectionStatisticService {
    private final static String province = "新疆维吾尔自治区";
    @Autowired
    private DistrictService districtService;
    @Autowired
    private CompanyService companyService;
    @Autowired
    private InspectionHiddenDangerService hiddenDangerService;
    @Autowired
    private SafetySelfInspectionService selfInspectionService;
    @Override
    public Msg getCountByArea(CountQuery query, UserInfo user) {
        List<SubordinateOrganizationInfoDO> organizationInfos = null;
        Integer type = user.getType();
        //如果传来的区县级不为空,则表明是到县级
        if(StringUtils.isNotBlank(query.getArea())){
            return getAreaDataCount(query);
        }
        //如果传来市级不为空
        if(StringUtils.isNotBlank(query.getCity())){
            List<DistrictInfo>  districtInfos = districtService.selectDistrictByName("3", query.getCity(), "2");
            organizationInfos = districtInfos.stream().map((districtInfo)->{
                SubordinateOrganizationInfoDO organizationInfoDO = new SubordinateOrganizationInfoDO();
                organizationInfoDO.setProvince(province);
                organizationInfoDO.setCity(query.getCity());
                organizationInfoDO.setArea(districtInfo.getName());
                return organizationInfoDO;
            }).collect(Collectors.toList());
        }else {
            //管理员
            if(type.equals(1)){
                List<DistrictInfo> districtInfos = districtService.selectDistrictByName("2", province, "1");
                organizationInfos = districtInfos.stream().map((districtInfo)->{
                    SubordinateOrganizationInfoDO organizationInfoDO = new SubordinateOrganizationInfoDO();
                    organizationInfoDO.setProvince(province);
                    organizationInfoDO.setCity(districtInfo.getName());
                    return organizationInfoDO;
                }).collect(Collectors.toList());
            }
            //监护人员
            if(type.equals(2)){
                //属于县级
                if(StringUtils.isNotBlank(user.getCounty())){
                    query.setArea(user.getCounty());
                    return getAreaDataCount(query);
                }
                //属于市级
                if(StringUtils.isNotBlank(user.getCity())){
                    List<DistrictInfo> districtInfos = districtService.selectDistrictByName("3", user.getCity(), "2");
                    organizationInfos = districtInfos.stream().map((districtInfo)->{
                        SubordinateOrganizationInfoDO organizationInfoDO = new SubordinateOrganizationInfoDO();
                        organizationInfoDO.setProvince(user.getProvince());
                        organizationInfoDO.setCity(user.getCity());
                        organizationInfoDO.setArea(districtInfo.getName());
                        return organizationInfoDO;
                    }).collect(Collectors.toList());
                }
                //属于省级
                if(StringUtils.isNotBlank(user.getProvince())){
                    List<DistrictInfo> districtInfos = districtService.selectDistrictByName("2", user.getProvince(), "1");
                    organizationInfos = districtInfos.stream().map((districtInfo)->{
                        SubordinateOrganizationInfoDO organizationInfoDO = new SubordinateOrganizationInfoDO();
                        organizationInfoDO.setProvince(user.getProvince());
                        organizationInfoDO.setCity(districtInfo.getName());
                        return organizationInfoDO;
                    }).collect(Collectors.toList());
                }
            }
        }
        List<AreaInspectionCountRespDTO> list = getDataCountSelfCheckInfo(query,organizationInfos);
        Msg msg = new Msg();
        msg.setCode("200");
        msg.setResult("查询成功");
        msg.setResult(list);
        return msg;
    }
    @Override
    public Msg getUnCheckCompany(CountQuery query) {
        Page<CompanyInfo> uncheckCompanyByArea = companyService.getUncheckCompanyByArea(query);
        Msg msg = new Msg();
        msg.setCode("200");
        msg.setResult("查询成功");
        msg.setResult(uncheckCompanyByArea);
        return msg;
    }
    private List<AreaInspectionCountRespDTO> getDataCountSelfCheckInfo(CountQuery query, List<SubordinateOrganizationInfoDO> organizationInfos) {
        List<AreaInspectionCountRespDTO> respDTOList = new ArrayList<>();
        for (SubordinateOrganizationInfoDO organizationInfo : organizationInfos) {
            AreaInspectionCountRespDTO areaInspectionCountRespDTO = new AreaInspectionCountRespDTO();
            //统计检查企业数量以及清单数量等
            Map<String,Object> map = new HashMap<>();
            map.put("startTime",query.getStartTime());
            map.put("endTime",query.getEndTime());
            map.put("province",organizationInfo.getProvince());
            map.put("city",organizationInfo.getCity());
            map.put("area",organizationInfo.getArea());
            CompanyStatisticInspectionDO companyStatisticInspection = selfInspectionService.companyStatisticInspection(map);
            BeanUtils.copyProperties(companyStatisticInspection,areaInspectionCountRespDTO);
            areaInspectionCountRespDTO.setProvince(organizationInfo.getProvince());
            areaInspectionCountRespDTO.setCity(organizationInfo.getCity());
            areaInspectionCountRespDTO.setArea(organizationInfo.getArea());
            areaInspectionCountRespDTO.setRectifyRate(areaInspectionCountRespDTO.getHdTotal() == 0 ? new BigDecimal(0).setScale(2,BigDecimal.ROUND_HALF_UP) : new BigDecimal(areaInspectionCountRespDTO.getRectifyTotal()).divide(new BigDecimal(areaInspectionCountRespDTO.getHdTotal()), 2, BigDecimal.ROUND_HALF_UP));
            //统计公司总数量
            int companyCount = companyService.getCountByArea(map);
            areaInspectionCountRespDTO.setCompanyTotal(companyService.getCountByArea(map));
            areaInspectionCountRespDTO.setUnCheckCompanyCount(companyCount-areaInspectionCountRespDTO.getCheckCompanyCount());
            respDTOList.add(areaInspectionCountRespDTO);
        }
        return respDTOList;
    }
    private Msg getAreaDataCount(CountQuery query) {
        if(query.getPageIndex() == null){
            query.setPageIndex(1);
        }
        if(query.getPageSize() == null){
            query.setPageSize(10);
        }
        //获取该地区所有企业隐患统计
        List<CompanyInspectionCountDO> statisticHiddenDangerList = hiddenDangerService.getStatisticHiddenDanger(query);
        //获取相关企业
        Page<CompanyInfo> companyInfoPage = companyService.getByArea(query);
        List<CompanyInspectionCountRespDTO> list = new ArrayList<>();
        for (CompanyInfo companyInfo : companyInfoPage.getRecords()) {
            CompanyInspectionCountRespDTO inspectionCountRespDTO = new CompanyInspectionCountRespDTO();
            List<CompanyInspectionCountDO> collect = statisticHiddenDangerList
                    .stream()
                    .filter(statistic -> statistic.getCompanyId().equals(companyInfo.getId()))
                    .collect(Collectors.toList());
            if(collect.size() > 0){
                CompanyInspectionCountDO companyInspectionCountDO = collect.get(0);
                BeanUtils.copyProperties(companyInspectionCountDO,inspectionCountRespDTO);
                inspectionCountRespDTO.setRectifyRate(companyInspectionCountDO.getSHdTotal() == 0 ? new BigDecimal(0).setScale(2,BigDecimal.ROUND_HALF_UP) : new BigDecimal(companyInspectionCountDO.getSReTotal()).divide(new BigDecimal(companyInspectionCountDO.getSHdTotal()), 2, BigDecimal.ROUND_HALF_UP));
            }else {
                inspectionCountRespDTO.setCheckTotal(0);
                inspectionCountRespDTO.setSHdTotal(0);
                inspectionCountRespDTO.setSMaTotal(0);
                inspectionCountRespDTO.setSMaReTotal(0);
                inspectionCountRespDTO.setSReTotal(0);
                inspectionCountRespDTO.setSUnReTotal(0);
                inspectionCountRespDTO.setSSaTotal(0);
                inspectionCountRespDTO.setSSaReTotal(0);
                inspectionCountRespDTO.setRectifyRate(new BigDecimal(0).setScale(2,BigDecimal.ROUND_HALF_UP));
                inspectionCountRespDTO.setCompanyId(companyInfo.getId());
            }
            inspectionCountRespDTO.setCompanyName(companyInfo.getCompany());
            inspectionCountRespDTO.setLastTime(selfInspectionService.selectLastTimeByCompanyId(companyInfo.getId(),query.getStartTime(),query.getEndTime()));
            list.add(inspectionCountRespDTO);
        }
        Page<CompanyInspectionCountRespDTO> page = new Page<>();
        BeanUtils.copyProperties(companyInfoPage,page);
        page.setRecords(list);
        Msg msg = new Msg();
        msg.setCode("200");
        msg.setMessage("查询成功");
        msg.setResult(page);
        return msg;
    }
}
src/main/java/com/gk/hotwork/Service/ServiceImpl/SafetySelfInspectionImpl.java
@@ -5,6 +5,7 @@
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gk.hotwork.Domain.*;
import com.gk.hotwork.Domain.Do.CompanyStatisticInspectionDO;
import com.gk.hotwork.Domain.Do.SafetySelfInspectionItemQualifiedCountDO;
import com.gk.hotwork.Domain.Exception.BusinessException;
import com.gk.hotwork.Domain.Utils.BeanUtils;
@@ -754,6 +755,29 @@
        attachmentInfoService.updateBusinessIdBatch(attachmentList);
    }
    @Override
    public Date selectLastTimeByCompanyId(Long companyId,Date startTime,Date endTime) {
        SafetySelfInspection inspection = safetySelfInspectionMapper.selectOne(new LambdaQueryWrapper<SafetySelfInspection>()
                 .eq(SafetySelfInspection::getValidFlag,1)
                .eq(SafetySelfInspection::getFlag, 2)
                .eq(SafetySelfInspection::getCheckedCompanyId, companyId)
                .ge(startTime != null,SafetySelfInspection::getInspectionTime,startTime)
                .le(endTime != null,SafetySelfInspection::getInspectionTime,endTime)
                .orderByDesc(SafetySelfInspection::getInspectionTime)
                .last("limit 1"));
        if(inspection != null){
            return inspection.getInspectionTime();
        }
       return null;
    }
    @Override
    public CompanyStatisticInspectionDO companyStatisticInspection(Map<String, Object> params) {
        return safetySelfInspectionMapper.companyStatisticInspection(params);
    }
    private void requiredAttachmentVerification(List<AttachmentInfo> attachmentList) {
        if(CollectionUtils.isEmpty(attachmentList)){
            throw new BusinessException("附件信息为空");