Commit b35436bc authored by 鲁鸿波's avatar 鲁鸿波

首页危险作业统计数据从系统中统计

parent 6bc9d714
......@@ -5,6 +5,8 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.testor.module.hazard.model.domain.THazardWorkPlan;
import com.testor.module.hazard.model.dto.THazardWorkPlanParam;
import com.testor.module.hazard.model.dto.THazardWorkPlanRiverside;
import com.testor.module.partner.model.dto.TJobStatisticsParam;
import com.testor.module.partner.model.vo.RegionalStatisticsVO;
import com.tongtech.tfw.backend.common.models.supers.SuperDao;
import com.tongtech.tfw.workflow.apis.task.model.dto.TodoTask;
import com.tongtech.tfw.workflow.apis.task.model.dto.TodoTaskSqlParam;
......@@ -46,4 +48,29 @@ public interface THazardWorkPlanDao extends SuperDao<THazardWorkPlan>
*/
Page<THazardWorkPlanRiverside> riversideList(Page<THazardWorkPlan> page,@Param("param") THazardWorkPlanParam param);
/**
* 查询已完成的危险作业数量
* @return
*/
Integer completedCount(@Param("orgIds") List<String> orgIds);
/**
* 查询未完成的危险作业数量
* @return
*/
Integer unfinishedCount(@Param("orgIds") List<String> orgIds);
/**
* 获取危险作业数量
* @return
*/
List<RegionalStatisticsVO> selectOrgWorkPlanCount(@Param("tJobStatisticsParam") TJobStatisticsParam tJobStatisticsParam);
/**
* 获取某组织当天的危险作业数(按作业类型分类)
* @param tJobStatisticsParam
* @return
*/
List<RegionalStatisticsVO> selectWorkTypeCount(@Param("tJobStatisticsParam") TJobStatisticsParam tJobStatisticsParam);
}
......@@ -123,4 +123,16 @@ public interface THazardWorkPlanService extends SuperService<THazardWorkPlan> {
*/
Page<THazardWorkPlanRiverside> riversideList(THazardWorkPlanParam param);
/**
* 查询已完成的危险作业数量
* @return
*/
Integer completedCount(List<String> orgIds);
/**
* 查询未完成的危险作业数量
* @return
*/
Integer unfinishedCount(List<String> orgIds);
}
......@@ -2349,6 +2349,16 @@ public class THazardWorkPlanServiceImpl extends SuperServiceImpl<THazardWorkPlan
return baseMapper.riversideList(resultPage, param);
}
@Override
public Integer completedCount(List<String> orgIds) {
return baseMapper.completedCount(orgIds);
}
@Override
public Integer unfinishedCount(List<String> orgIds) {
return baseMapper.unfinishedCount(orgIds);
}
private void deleteDoneRecords(String bizId) {
try {
// 获取流程实例ID
......
......@@ -129,5 +129,8 @@ public class TJobStatisticsParam {
@ApiModelProperty(value = "所有父级机构主键以英文逗号隔开如:一级,二级等")
private String orgAllPath;
@ApiModelProperty(value = "批量ID")
private List<String> orgIds;
}
......@@ -9,6 +9,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.testor.biz.sys.org.model.domain.SysOrg;
import com.testor.biz.sys.org.service.SysOrgService;
import com.testor.module.hazard.dao.THazardWorkPlanDao;
import com.testor.module.partner.controller.TJobStatisticsController;
import com.testor.module.partner.dao.TJobStatisticsDao;
import com.testor.module.partner.model.domain.TJobStatistics;
......@@ -65,6 +66,9 @@ public class TJobStatisticsServiceImpl extends SuperServiceImpl<TJobStatisticsDa
@Value("${tuan.path}")
private String path;
@Autowired
private THazardWorkPlanDao hazardWorkPlanDao;
//@XxlJob("add_JobStatistics")
//@Scheduled(cron = "0 */4 * * * ?")
@Transactional(isolation = Isolation.READ_COMMITTED)
......@@ -351,6 +355,70 @@ public class TJobStatisticsServiceImpl extends SuperServiceImpl<TJobStatisticsDa
@Override
public HazardousWorkStatisticsVo regionalStatistics(String orgId) {
UserInfo loginUser = ContextUtils.getLoginUser();
if (StringHelper.isEmpty(orgId)) {
orgId = loginUser.getOrgId();
}
HazardousWorkStatisticsVo hazardousWorkStatisticsVo = new HazardousWorkStatisticsVo();
List<RegionalStatisticsVO> regionalStatisticsVOList = new ArrayList<>();
TJobStatisticsParam tJobStatisticsParam = new TJobStatisticsParam();
tJobStatisticsParam.setOrgId(orgId);
String today = DateUtil.today();
tJobStatisticsParam.setZykssj(today);
List<String> orgIds = newSysOrgService.getOrgIdListByParentId(orgId);
//如果没有下级查看当前单位数据
if (orgIds == null || orgIds.isEmpty()) {
regionalStatisticsVOList = hazardWorkPlanDao.selectWorkTypeCount(tJobStatisticsParam);
hazardousWorkStatisticsVo.setCount(regionalStatisticsVOList.size());
}else {
tJobStatisticsParam.setOrgId("");
for (String id : orgIds) {
List<String> idsChildrenById = newSysOrgService.getIdsChildrenById(id);
tJobStatisticsParam.setOrgIds(idsChildrenById);
RegionalStatisticsVO regionalStatisticsVO = new RegionalStatisticsVO();
regionalStatisticsVO.setId(id);
SysOrg org = sysOrgService.getById(id);
if(null != org){
regionalStatisticsVO.setName(org.getOrgName());
}
List<RegionalStatisticsVO> regionalStatisticsVOS = hazardWorkPlanDao.selectOrgWorkPlanCount(tJobStatisticsParam);
if(null != regionalStatisticsVOS && !regionalStatisticsVOS.isEmpty()){
regionalStatisticsVO.setDone(regionalStatisticsVOS.get(0).getDone());
regionalStatisticsVO.setUndone(regionalStatisticsVOS.get(0).getUndone());
}else{
regionalStatisticsVO.setDone("0");
regionalStatisticsVO.setUndone("0");
}
regionalStatisticsVOList.add(regionalStatisticsVO);
}
// 计算所有组织的已完成和未完成作业总数
int totalDone = 0;
int totalUndone = 0;
for (RegionalStatisticsVO vo : regionalStatisticsVOList) {
// 将字符串转换为整数,处理可能的空值或非数字情况
try {
totalDone += Integer.parseInt(vo.getDone());
} catch (NumberFormatException e) {
// 如果转换失败,则默认为0
}
try {
totalUndone += Integer.parseInt(vo.getUndone());
} catch (NumberFormatException e) {
// 如果转换失败,则默认为0
}
}
int totalCount = totalDone + totalUndone;
hazardousWorkStatisticsVo.setCount(totalCount);
}
hazardousWorkStatisticsVo.setRegionalStatistics(regionalStatisticsVOList);
return hazardousWorkStatisticsVo;
}
/*public HazardousWorkStatisticsVo regionalStatistics(String orgId) {
UserInfo loginUser = ContextUtils.getLoginUser();
if (StringHelper.isEmpty(orgId)) {
orgId = loginUser.getOrgId();
......@@ -383,7 +451,7 @@ public class TJobStatisticsServiceImpl extends SuperServiceImpl<TJobStatisticsDa
hazardousWorkStatisticsVo.setRegionalStatistics(regionalStatisticsVOList);
hazardousWorkStatisticsVo.setCount(count);
return hazardousWorkStatisticsVo;
}
}*/
@Override
public Long regionalStatisticsCount(String orgId) {
......
......@@ -101,7 +101,84 @@
where parent_ids like concat('%',#{param.orgId},'%')
)
</if>
</select>
<select id="completedCount" resultType="java.lang.Integer">
select count(1) from t_hazard_work_plan
where status = '0' and work_status ='5'
and DATE(create_date) = CURRENT_DATE
<if test="param.orgId != null">
and org_id in
<foreach item="id" collection="orgIds" open="(" separator="," close=")">
#{id}
</foreach>
</if>
</select>
<select id="unfinishedCount" resultType="java.lang.Integer">
select count(1) from t_hazard_work_plan
where status = '0' and work_status not in('0','6','12','5')
and DATE(create_date) = CURRENT_DATE
<if test="param.orgId != null">
and org_id in
<foreach item="id" collection="orgIds" open="(" separator="," close=")">
#{id}
</foreach>
</if>
</select>
<select id="selectOrgWorkPlanCount" resultType="com.testor.module.partner.model.vo.RegionalStatisticsVO">
SELECT
o.org_id id,
o.org_name name,
COALESCE(SUM(CASE WHEN h.work_status = '5' THEN 1 ELSE 0 END), 0) as done,
COALESCE(SUM(CASE WHEN h.work_status NOT IN ('0','6','12','5') THEN 1 ELSE 0 END), 0) as undone
FROM t_sys_org o
LEFT JOIN t_hazard_work_plan h ON o.org_id = h.org_id
AND h.status = '0'
AND CAST(h.create_date AS DATE) = CURRENT_DATE
WHERE 1=1
<if test="tJobStatisticsParam.orgIds != null and tJobStatisticsParam.orgIds.size()>0">
AND h.org_id IN
<foreach item="id" collection="tJobStatisticsParam.orgIds" open="(" separator="," close=")">
#{id}
</foreach>
</if>
<if test="tJobStatisticsParam.orgId != null and tJobStatisticsParam.orgId !=''">
AND h.org_id = #{tJobStatisticsParam.orgId}
</if>
GROUP BY o.org_id, o.org_name
ORDER BY o.org_id
</select>
<select id="selectWorkTypeCount" resultType="com.testor.module.partner.model.vo.RegionalStatisticsVO">
SELECT
CASE thwp.work_status
WHEN '0' THEN '草稿'
WHEN '1' THEN '作业前(风险分析)'
WHEN '2' THEN '作业前(条件确认)'
WHEN '3' THEN '作业前(许可证)'
WHEN '4' THEN '技术交底'
WHEN '5' THEN '已关闭'
WHEN '6' THEN '已取消'
WHEN '7' THEN '已超时'
WHEN '8' THEN '驳回'
WHEN '9' THEN '审批中'
WHEN '10' THEN '进行中'
WHEN '11' THEN '待安全许可证关闭'
WHEN '12' THEN '已超时自动取消'
ELSE '未知状态'
END AS done,
tsdd.dict_value AS name
FROM t_hazard_work_plan thwp
LEFT JOIN t_sys_dict_data tsdd
ON thwp.work_type = tsdd.dict_data_id
WHERE
thwp.status = '0' -- 过滤草稿状态
AND CAST(thwp.create_date AS DATE) = CURRENT_DATE
<if test="tJobStatisticsParam.orgId != null and tJobStatisticsParam.orgId !=''">
AND thwp.org_id = #{tJobStatisticsParam.orgId}
</if>
</select>
</mapper>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment