考勤模块SQL重新写

This commit is contained in:
方亮 2026-02-06 18:27:20 +08:00
parent 63bc317944
commit 7a6ad8b80a
6 changed files with 128 additions and 127 deletions

View File

@ -48,8 +48,7 @@ public class FaceContrastController {
}, new PageTableHandler.ListHandler() {
@Override
public List<FaceContrastBean> list(PageTableRequest request) {
List<FaceContrastBean> list = service.getWorkAttendanceList (request.getParams(), request.getOffset(), request.getLimit());
return list;
return service.getWorkAttendanceList (request.getParams(), request.getOffset(), request.getLimit());
}
}).handle(request);
}

View File

@ -84,9 +84,6 @@ public class FaceContrastNewController {
}
}
return new PageTableHandler(new PageTableHandler.CountHandler() {
@Override
public int count(PageTableRequest request) {
@ -95,8 +92,7 @@ public class FaceContrastNewController {
}, new PageTableHandler.ListHandler() {
@Override
public List<FaceContrastNewBean> list(PageTableRequest request) {
List<FaceContrastNewBean> list = service.getWorkAttendanceList (request.getParams(), request.getOffset(), request.getLimit());
return list;
return service.getWorkAttendanceList (request.getParams(), request.getOffset(), request.getLimit());
}
}).handle(request);
}
@ -124,8 +120,7 @@ public class FaceContrastNewController {
}, new PageTableHandler.ListHandler() {
@Override
public List<FaceContrastNewBean> list(PageTableRequest request) {
List<FaceContrastNewBean> list = service.getAttendanceBySubComList (request.getParams(), request.getOffset(), request.getLimit());
return list;
return service.getAttendanceBySubComList (request.getParams(), request.getOffset(), request.getLimit());
}
}).handle(request);
}

View File

@ -421,8 +421,6 @@ public class FaceContrastNewServiceImp implements FaceContrastNewService {
List<FaceContrastNewBean> attList = dao.getWorkAttListByCom(params, offset, limit);
for (int i = 0; i < attList.size(); i++) {
list.get(i).setAttPersonNum(attList.get(i).getAttPersonNum());
//将临时人员的数量加到班组人员里面
list.get(i).setAllPersonNum(list.get(i).getAllPersonNum() + attList.get(i).getTempWorkerNum());
}
return list;
}
@ -435,7 +433,7 @@ public class FaceContrastNewServiceImp implements FaceContrastNewService {
//考勤数据较慢单独查
//11.30添加无班组考勤人员
if (attendanceByProList.size() > 0) {
if (!attendanceByProList.isEmpty()) {
List<Integer> attList = dao.getWorkAttListByPro(params);
for (int i = 0; i < attList.size(); i++) {
attendanceByProList.get(i).setAttPersonNum(attList.get(i));
@ -469,22 +467,22 @@ public class FaceContrastNewServiceImp implements FaceContrastNewService {
}
}
for (FaceContrastNewBean faceContrastNewBean : attendanceByProList) {
//查出班组人中连续七天未打卡的人数
List<MapBean> currentDayList = dao.getTeamSevenNoAttPersonNum(faceContrastNewBean);
Map<String, List<MapBean>> collect = currentDayList.stream().sorted(Comparator.comparing(MapBean::getName).reversed()).collect(Collectors.groupingBy(MapBean::getId));
AtomicInteger i = new AtomicInteger();
collect.forEach((k, v) -> {
for (MapBean mapBean : v) {
long betweenDay = DateUtil.between(DateUtil.parse(mapBean.getName()), DateUtil.parse(DateUtil.today()), DateUnit.DAY);
if (betweenDay > 6) {
i.getAndIncrement();
}
break;
}
});
faceContrastNewBean.setSevenNoAttPersonNum(i.get());
}
// for (FaceContrastNewBean faceContrastNewBean : attendanceByProList) {
// //查出班组人中连续七天未打卡的人数
// List<MapBean> currentDayList = dao.getTeamSevenNoAttPersonNum(faceContrastNewBean);
// Map<String, List<MapBean>> collect = currentDayList.stream().sorted(Comparator.comparing(MapBean::getName).reversed()).collect(Collectors.groupingBy(MapBean::getId));
// AtomicInteger i = new AtomicInteger();
// collect.forEach((k, v) -> {
// for (MapBean mapBean : v) {
// long betweenDay = DateUtil.between(DateUtil.parse(mapBean.getName()), DateUtil.parse(DateUtil.today()), DateUnit.DAY);
// if (betweenDay > 6) {
// i.getAndIncrement();
// }
// break;
// }
// });
// faceContrastNewBean.setSevenNoAttPersonNum(i.get());
// }
return attendanceByProList;
}
@ -524,9 +522,9 @@ public class FaceContrastNewServiceImp implements FaceContrastNewService {
x = x / 2.0;
double furloughDays = 0.0;
double notWorkDay = 0.0;
if (furloughList.size() > 0) {
if (!furloughList.isEmpty()) {
List<AttDateBean> attDateBeans = furloughList.get(childObj.get(0).getIdNumber());
if (attDateBeans != null && attDateBeans.size() > 0) {
if (attDateBeans != null && !attDateBeans.isEmpty()) {
for (AttDateBean attDateBean : attDateBeans) {
double ofTwoDays = getDiffOfTwoDays(attDateBean.getStartDate(), attDateBean.getStopDate());
furloughDays += ofTwoDays;

View File

@ -25,7 +25,7 @@
COUNT(DISTINCT if(bp.pro_status = 2,bp.id,null)) as makeProNum,
COUNT(DISTINCT if(bp.pro_status = 1,bp.id,null)) as endProNum,
COUNT(DISTINCT bs.id) as subNum,
COUNT(DISTINCT btur.team_id) as teamNum,
COUNT(DISTINCT bst.id) as teamNum,
COUNT(DISTINCT bw.id_number) as allPersonNum
FROM
( SELECT id,`name` FROM bm_project_general WHERE is_active = '1'
@ -39,9 +39,12 @@
<if test="params.subId != null and params.subId !='' ">
AND bs.id = #{params.subId}
</if>
LEFT JOIN bm_sub_relation bsr on bsr.sub_contract_id = bsc.id and bsr.type = '3' and bsr.is_active = '1'
LEFT JOIN bm_team_user_relation btur ON btur.team_id = bsr.`value` and btur.is_active = '1'
LEFT JOIN bm_worker bw ON bw.ID_NUMBER = btur.ID_NUMBER and bw.is_active = '1' and worker_type = '1'
LEFT JOIN bm_sub_team bst on bs.id = bst.sub_id and bs.is_active = '1'
Left Join bm_worker_ein_history bweh on bweh.team_id = bst.id and bweh.project_id = bp.id and bweh.exit_time is null and bweh.exit_status = -1
LEFT JOIN bm_worker bw ON bw.ID_NUMBER = bweh.ID_NUMBER and bw.is_active = '1'
<if test="params.workerType != null and params.workerType !='' ">
AND bw.worker_type = #{params.workerType}
</if>
GROUP BY
pm.id
ORDER BY
@ -62,7 +65,10 @@
AND bp.is_active = '1'
LEFT JOIN (
SELECT fc.id_number, fc.pro_id FROM fc_face_contrast fc
LEFT JOIN bm_worker bw on bw.id_number = fc.ID_NUMBER and bw.worker_type = '1'
LEFT JOIN bm_worker bw on bw.id_number = fc.ID_NUMBER
<if test="params.workerType != null and params.workerType !='' ">
AND bw.worker_type = #{params.workerType}
</if>
WHERE fc.CURRENT_DAY = #{params.startTime} GROUP BY fc.id_number, fc.CURRENT_DAY
) ffc ON ffc.pro_id = bp.id
GROUP BY
@ -237,7 +243,7 @@
bp.NAME AS proName,
bp.pro_status AS proStatus,
COUNT( DISTINCT bs.id ) AS subNum,
COUNT( DISTINCT btur.team_id ) AS teamNum,
COUNT( DISTINCT bst.id ) AS teamNum,
COUNT( DISTINCT bw.id_number ) AS allPersonNum
FROM
( SELECT id, `name` FROM bm_project_general WHERE id = #{params.orgId} ) pm
@ -250,15 +256,13 @@
<if test="params.subId != null and params.subId !='' ">
AND bs.id = #{params.subId}
</if>
LEFT JOIN bm_sub_relation bsr ON bsr.sub_contract_id = bsc.id
AND bsr.type = '3'
AND bsr.is_active = '1'
LEFT JOIN bm_team_user_relation btur ON btur.team_id = bsr.`value`
AND btur.is_active = '1'
LEFT JOIN bm_worker bw ON bw.ID_NUMBER = btur.ID_NUMBER
AND bw.is_active = '1' and bw.worker_type = '1'
LEFT JOIN bm_sub_team bst on bs.id = bst.sub_id and bs.is_active = '1'
Left Join bm_worker_ein_history bweh on bweh.team_id = bst.id and bweh.project_id = bp.id and bweh.exit_time is null and bweh.exit_status = -1
LEFT JOIN bm_worker bw ON bw.ID_NUMBER = bweh.ID_NUMBER and bw.is_active = '1'
<if test="params.workerType != null and params.workerType !='' ">
AND bw.worker_type = #{params.workerType}
</if>
<where>
<if test="params.proId != null and params.proId != '' ">
and bp.id = #{params.proId}
</if>
@ -273,47 +277,8 @@
limit #{offset},#{limit}
</select>
<!-- 分包合同会移除班组 -->
<select id="getAttendanceByProList" resultType="com.bonus.bmw.person.entity.FaceContrastNewBean">
select * from (
SELECT
bp.id AS proId,
bp.NAME AS proName,
bs.id as subId,
bs.sub_name AS subName,
bst.id as teamId,
bst.`team_name` AS teamName,
COUNT( DISTINCT bw.id_number ) AS allPersonNum,
GROUP_CONCAT(bw.id_number) as allIdNumber,
GROUP_CONCAT(bw.name) as allName
FROM
bm_project bp
LEFT JOIN bm_sub_contract bsc ON bsc.pro_id = bp.id and bsc.is_active = '1'
LEFT JOIN bm_subcontractor bs on bs.id = bsc.sub_id and bs.is_active = '1'
<if test="params.subId != null and params.subId !='' ">
AND bs.id = #{params.subId}
</if>
LEFT JOIN bm_sub_relation bsr on bsr.sub_contract_id = bsc.id and bsr.type = '3'
<if test='params.notContractTeam == "" or params.notContractTeam == null'>
AND bsr.is_active = '1'
</if>
LEFT JOIN bm_sub_team bst ON bst.id = bsr.`value`
LEFT JOIN bm_team_user_relation btur ON btur.team_id = bst.id and btur.is_active = '1'
LEFT JOIN bm_worker bw ON bw.ID_NUMBER = btur.ID_NUMBER and bw.is_active = '1' and bw.worker_type = '1'
WHERE
bp.id = #{params.proId} and bst.id is not null
<if test="params.teamName != null and params.teamName != '' ">
and instr(bst.`team_name`,#{params.teamName}) > 0
</if>
<if test="params.subId != null and params.subId !='' ">
AND bs.id is not null
</if>
GROUP BY
bsr.`value`
ORDER BY
bsr.`value` ASC
) aa
union
<!-- union
SELECT
bp.id AS proId,
bp.NAME AS proName,
@ -333,7 +298,45 @@
bp.id = #{params.proId}
<if test="params.teamName != null and params.teamName != ''">
and instr('临时班组',#{params.teamName}) > 0
</if> -->
<select id="getAttendanceByProList" resultType="com.bonus.bmw.person.entity.FaceContrastNewBean">
select * from (
SELECT
bp.id AS proId,
bp.NAME AS proName,
bs.id as subId,
bs.sub_name AS subName,
bst.id as teamId,
bst.`team_name` AS teamName,
COUNT( DISTINCT bw.id_number ) AS allPersonNum,
GROUP_CONCAT(bw.id_number) as allIdNumber,
GROUP_CONCAT(bw.name) as allName
FROM
bm_project bp
LEFT JOIN bm_sub_contract bsc ON bsc.pro_id = bp.id and bsc.is_active = '1'
LEFT JOIN bm_subcontractor bs on bs.id = bsc.sub_id and bs.is_active = '1'
<if test="params.subId != null and params.subId !='' ">
AND bs.id = #{params.subId}
</if>
LEFT JOIN bm_sub_team bst on bs.id = bst.sub_id and bs.is_active = '1'
Left Join bm_worker_ein_history bweh on bweh.team_id = bst.id and bweh.project_id = bp.id and bweh.exit_time is null and bweh.exit_status = -1
LEFT JOIN bm_worker bw ON bw.ID_NUMBER = bweh.ID_NUMBER and bw.is_active = '1'
<if test="params.workerType != null and params.workerType !='' ">
AND bw.worker_type = #{params.workerType}
</if>
WHERE
bp.id = #{params.proId} and bst.id is not null
<if test="params.teamName != null and params.teamName != '' ">
and instr(bst.`team_name`,#{params.teamName}) > 0
</if>
<if test="params.subId != null and params.subId !='' ">
AND bs.id is not null
</if>
GROUP BY
bst.`id`
ORDER BY
bst.`id`
) aa
</select>
<select id="getTeamSevenNoAttPersonNum" resultType="com.bonus.bmw.person.entity.MapBean">
@ -446,7 +449,11 @@
ffc.CURRENT_DAY AS currentDay,
ffc.attendance_type AS attendanceType
FROM
(select `name`,`ID_NUMBER`,post_id FROM bm_worker WHERE ID_NUMBER = #{obj.idNumber} AND is_active = '1' )bw
(select `name`,`ID_NUMBER`,post_id FROM bm_worker WHERE ID_NUMBER = #{obj.idNumber} AND is_active = '1'
<if test="params.workerType != null and params.workerType !='' ">
AND worker_type = #{params.workerType}
</if>
)bw
LEFT JOIN t_dict sdd ON sdd.id = bw.POST_ID
AND sdd.is_active = '1'
LEFT JOIN fc_face_contrast ffc ON ffc.ID_NUMBER = bw.ID_NUMBER
@ -575,7 +582,10 @@
</if>
GROUP BY id_number)bweh ON bweh.project_id = bp.id
LEFT JOIN ( SELECT fc.id_number, fc.pro_id FROM fc_face_contrast fc
LEFT JOIN bm_worker bw on bw.id_number = fc.ID_NUMBER and bw.worker_type = '1'
LEFT JOIN bm_worker bw on bw.id_number = fc.ID_NUMBER
<if test="params.workerType != null and params.workerType !='' ">
AND bw.worker_type = #{params.workerType}
</if>
WHERE fc.CURRENT_DAY = #{params.startTime}
<if test="params.proId != null and params.proId != '' ">
and fc.pro_id = #{params.proId}
@ -595,7 +605,21 @@
bp.id ASC
limit #{offset},#{limit}
</select>
<!-- 分包合同会移除班组 -->
<!-- union all
SELECT
count(DISTINCT ffc.id_number )
FROM
bm_project bp
LEFT JOIN (select id_number,project_id FROM bm_worker_ein_history WHERE (sub_id is null or sub_id = 0)and is_active = '1' AND is_furlough_person = '0' AND exit_status != '1' GROUP BY id_number)bweh ON bweh.project_id = bp.id
LEFT JOIN ( SELECT id_number, pro_id FROM fc_face_contrast WHERE CURRENT_DAY = #{params.startTime} GROUP BY id_number, CURRENT_DAY ) ffc ON ffc.id_number = bweh.id_number
WHERE
bp.id = #{params.proId}
<if test="params.teamName != null and params.teamName != '' ">
and instr('临时班组',#{params.teamName}) > 0
</if> -->
<!-- <if test='params.notContractTeam == "" or params.notContractTeam == null'>-->
<!-- AND bsr.is_active = '1'-->
<!-- </if>-->
<select id="getWorkAttListByPro" resultType="java.lang.Integer">
select * from (
SELECT
@ -607,38 +631,23 @@
AND bsc.sub_id = #{params.subId}
</if>
AND bsc.is_active = '1'
LEFT JOIN bm_sub_relation bsr ON bsr.type = '3'
<if test='params.notContractTeam == "" or params.notContractTeam == null'>
AND bsr.is_active = '1'
LEFT JOIN bm_sub_team bst on bsc.sub_id = bst.sub_id and bst.is_active = '1'
Left Join bm_worker_ein_history bweh on bweh.team_id = bst.id and bweh.project_id = bp.id and bweh.exit_time is null and bweh.exit_status = -1
LEFT JOIN bm_worker bw ON bw.ID_NUMBER = bweh.ID_NUMBER and bw.is_active = '1'
<if test="params.workerType != null and params.workerType !='' ">
AND bw.worker_type = #{params.workerType}
</if>
AND bsr.sub_contract_id = bsc.id
LEFT JOIN bm_team_user_relation btur ON btur.team_id = bsr.`value`
AND btur.is_active = '1'
LEFT JOIN bm_sub_team bst ON bst.id = bsr.`value`
LEFT JOIN ( SELECT id_number, pro_id FROM fc_face_contrast WHERE CURRENT_DAY = #{params.startTime} GROUP BY id_number, CURRENT_DAY ) ffc ON ffc.id_number = btur.id_number
LEFT JOIN ( SELECT id_number, pro_id FROM fc_face_contrast WHERE CURRENT_DAY = #{params.startTime} GROUP BY id_number, CURRENT_DAY ) ffc ON ffc.id_number = bw.ID_NUMBER
WHERE
bp.id = #{params.proId} and bst.id is not null
<if test="params.teamName != null and params.teamName != '' ">
and instr(bst.`team_name`,#{params.teamName}) > 0
</if>
GROUP BY
bsr.`value`
bst.id
ORDER BY
bsr.`value` ASC
bst.id
) aa
union all
SELECT
count(DISTINCT ffc.id_number )
FROM
bm_project bp
LEFT JOIN (select id_number,project_id FROM bm_worker_ein_history WHERE (sub_id is null or sub_id = 0)and is_active = '1' AND is_furlough_person = '0' AND exit_status != '1' GROUP BY id_number)bweh ON bweh.project_id = bp.id
LEFT JOIN ( SELECT id_number, pro_id FROM fc_face_contrast WHERE CURRENT_DAY = #{params.startTime} GROUP BY id_number, CURRENT_DAY ) ffc ON ffc.id_number = bweh.id_number
WHERE
bp.id = #{params.proId}
<if test="params.teamName != null and params.teamName != '' ">
and instr('临时班组',#{params.teamName}) > 0
</if>
</select>
<select id="getTrueEinDate" resultType="com.bonus.bmw.person.entity.AttDateBean">
select
@ -811,4 +820,4 @@
</select>
</mapper>
</mapper>

View File

@ -214,18 +214,18 @@ function init() {
},width: '25%'},
{"data": "allPersonNum",width: '10%'},
{"data": "attPersonNum",width: '10%'},
{"data": "","defaultContent": "",
"orderable": false,
"render": function (data, type, row) {
var sevenNoAttPersonNum = row['sevenNoAttPersonNum'];
var teamId = row['teamId'];
var teamName = row['teamName'];
var proId = row['proId'];
var proName = row['proName'];
var html = '';
html += "<a style = 'color:#09A8F1;cursor: pointer' onclick = 'getAttendanceBySeven(\"" + teamId + "\",\"" + teamName + "\",\"" + proId + "\",\"" + proName + "\")'>" + sevenNoAttPersonNum + "</a>";
return html;
},width: '10%'},
// {"data": "","defaultContent": "",
// "orderable": false,
// "render": function (data, type, row) {
// var sevenNoAttPersonNum = row['sevenNoAttPersonNum'];
// var teamId = row['teamId'];
// var teamName = row['teamName'];
// var proId = row['proId'];
// var proName = row['proName'];
// var html = '';
// html += "<a style = 'color:#09A8F1;cursor: pointer' onclick = 'getAttendanceBySeven(\"" + teamId + "\",\"" + teamName + "\",\"" + proId + "\",\"" + proName + "\")'>" + sevenNoAttPersonNum + "</a>";
// return html;
// },width: '10%'},
],
// "order": [[0, "desc"], [1, "asc"]] //在栏目列上显示排序功能
});
@ -401,4 +401,4 @@ function explainClick(str) {
shadeClose: true, // 点击遮罩关闭层
maxmin: false
})
}
}

View File

@ -77,7 +77,7 @@
<th>班组名称</th>
<th>总人数</th>
<th>考勤人数</th>
<th>连续七天未打卡</th>
<!-- <th>连续七天未打卡</th>-->
</tr>
</thead>
<tbody>
@ -101,4 +101,4 @@
<script type="text/javascript" src="../../../../js/select.js"></script>
<script type="text/javascript" src="../../../../js/work/Person/AttendanceManageNew/AttendanceByProList.js" defer="defer"></script>
<script type="text/javascript">
</script>
</script>