李林
2023-10-07 658d4927d468c47208fd012d9128b09249c07eff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<?xml version="1.0" encoding="UTF-8"?>
 
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 
<mapper namespace="com.chinaztt.mes.production.mapper.PersonBoardMapper">
 
    <resultMap id="personBoardMap" type="com.chinaztt.mes.production.dto.PersonBoardDTO">
        <id property="id" column="id"/>
        <result property="workTime" column="work_time"/>
        <result property="workstationId" column="workstation_id"/>
        <result property="staffId" column="staff_id"/>
        <result property="staffName" column="staff_name"/>
        <result property="staffNo" column="staff_no"/>
        <result property="post" column="post"/>
        <result property="mealSubsidy" column="meal_subsidy"/>
        <result property="nightDifferential" column="night_differential"/>
        <result property="overtimePay" column="overtime_pay"/>
        <result property="dutyTime" column="duty_time"/>
        <result property="totalDutyTime" column="total_duty_time"/>
        <result property="salary" column="salary"/>
        <result property="totalSalary" column="total_salary"/>
        <result property="beforeTotalDutyTime" column="before_total_duty_time"/>
        <result property="nowDutyDate" column="now_duty_date"/>
        <result property="workstationName" column="workstation_name"/>
        <result property="divisionName" column="division_name"/>
        <result property="personnelFactor" column="personnel_factor"/>
        <result property="dutyNo" column="duty_no"/>
        <result property="shiftName" column="shift_name"/>
    </resultMap>
    <select id="checkPersonHaveToWork" resultMap="personBoardMap">
        select bs.staff_name,pdr.now_duty_date,bw."name" workstation_name
        from production_person_board ppb
        left join basic_staff bs on bs."id"=ppb.staff_id
        left join production_duty_record pdr on pdr."id"=ppb.duty_record_id
        left join basic_workstation bw on bw."id"=pdr.workstation_id
        where ppb.staff_id=#{personBoard.staffId}
        and exists(select 1 from production_duty_record pdre where pdre.now_duty_date=pdr.now_duty_date and pdre."id"=#{personBoard.dutyRecordId})
    </select>
 
    <select id="selectDtoByParam" resultMap="personBoardMap">
        select opd."id",opd.work_time,opd.staff_id,
        bs.staff_name,bs.staff_no,bs.post
        from production_person_board opd
        left join basic_staff bs on bs."id"=opd.staff_id
        where opd.status='01working'
        <if test="id != null and id != ''">
            and opd.id!=#{id}
        </if>
        <if test="workstationId != null and workstationId != ''">
            and opd.workstation_id=#{workstationId}
        </if>
        <if test="staffId != null and staffId != ''">
            and opd.staff_id=#{staffId}
        </if>
    </select>
 
    <select id="selectDtoById" resultMap="personBoardMap">
        select opd."id",opd.work_time,opd.staff_id,opd.workstation_id,
        bs.staff_name,bs.staff_no,bs.post
        from production_person_board opd
        left join basic_staff bs on bs."id"=opd.staff_id
        where opd.status='01working' and opd.id=#{id}
    </select>
 
    <select id="getPersonByDutyRecordId" resultMap="personBoardMap">
        select opd."id",opd.work_time,bs.staff_name,bs.staff_no,bs.personnel_factor,
        bd.division_name,opd.staff_id,opd.meal_subsidy,opd.night_differential,opd.overtime_pay,
        (select coalesce(sum(pai.working_hours),0) from production_artificial_information pai where pai.production_person_id=opd."id") duty_time,
        (select coalesce(sum(pai2.working_hours),0)
        from production_artificial_information pai2
        left join production_person_board ppd2 on ppd2."id"=pai2.production_person_id
        left join production_duty_record pdr2 on pdr2."id"=ppd2.duty_record_id
        where pdr2.is_confirm=true and ppd2.staff_id=opd.staff_id and pdr2.duty_month=pdr.duty_month and pdr2.now_duty_date <![CDATA[<=]]> pdr.now_duty_date) total_duty_time,
        opd.salary,
        (select coalesce(sum(ppd4.salary)+sum(ppd4.overtime_pay)+sum(ppd4.meal_subsidy)+sum(ppd4.night_differential),0)
        from production_person_board ppd4
        left join production_duty_record pdr4 on pdr4."id"=ppd4.duty_record_id
        where pdr4.is_confirm=true and ppd4.staff_id=opd.staff_id and pdr4.duty_month=pdr.duty_month and pdr4.now_duty_date <![CDATA[<=]]> pdr.now_duty_date) total_salary,
        (select coalesce(sum(pai2.working_hours),0)
        from production_artificial_information pai2
        left join production_person_board ppd2 on ppd2."id"=pai2.production_person_id
        left join production_duty_record pdr2 on pdr2."id"=ppd2.duty_record_id
        where pdr2.is_confirm=true and ppd2.staff_id=opd.staff_id and pdr2.duty_month=pdr.duty_month and pdr2.now_duty_date <![CDATA[<]]> pdr.now_duty_date) before_total_duty_time
        from production_person_board opd
        left join basic_staff bs on bs."id"=opd.staff_id
        left join basic_division bd on bd."id"=bs.division_id
        left join production_duty_record pdr on pdr."id"=opd.duty_record_id
        where opd.duty_record_id=#{dutyRecordId}
        order by opd."id"
    </select>
    <select id="getPersonByDutyRecordIdList" resultMap="personBoardMap">
        select opd."id",opd.work_time,bs.staff_name,bs.staff_no,bs.personnel_factor,pdr.duty_no,pdr.now_duty_date,bst.name as shift_name,pdr.id as duty_record_id,
        bd.division_name,opd.staff_id,opd.meal_subsidy,opd.night_differential,opd.overtime_pay,
        (select coalesce(sum(pai.working_hours),0) from production_artificial_information pai where pai.production_person_id=opd."id") duty_time,
        (select coalesce(sum(pai2.working_hours),0)
        from production_artificial_information pai2
        left join production_person_board ppd2 on ppd2."id"=pai2.production_person_id
        left join production_duty_record pdr2 on pdr2."id"=ppd2.duty_record_id
        where pdr2.is_confirm=true and ppd2.staff_id=opd.staff_id and pdr2.duty_month=pdr.duty_month and pdr2.now_duty_date <![CDATA[<=]]> pdr.now_duty_date) total_duty_time,
        opd.salary,
        (select coalesce(sum(ppd4.salary)+sum(ppd4.overtime_pay)+sum(ppd4.meal_subsidy)+sum(ppd4.night_differential),0)
        from production_person_board ppd4
        left join production_duty_record pdr4 on pdr4."id"=ppd4.duty_record_id
        where pdr4.is_confirm=true and ppd4.staff_id=opd.staff_id and pdr4.duty_month=pdr.duty_month and pdr4.now_duty_date <![CDATA[<=]]> pdr.now_duty_date) total_salary,
        (select coalesce(sum(pai2.working_hours),0)
        from production_artificial_information pai2
        left join production_person_board ppd2 on ppd2."id"=pai2.production_person_id
        left join production_duty_record pdr2 on pdr2."id"=ppd2.duty_record_id
        where pdr2.is_confirm=true and ppd2.staff_id=opd.staff_id and pdr2.duty_month=pdr.duty_month and pdr2.now_duty_date <![CDATA[<]]> pdr.now_duty_date) before_total_duty_time
        from production_person_board opd
        left join basic_staff bs on bs."id"=opd.staff_id
        left join basic_division bd on bd."id"=bs.division_id
        left join production_duty_record pdr on pdr."id"=opd.duty_record_id
        left join basic_shift bst on bst.id = pdr.shift_id
        where opd.duty_record_id  in
        <foreach collection="dutyRecordIdList" item="dutyRecordId" index="index" open="(" close=")" separator=",">
            #{dutyRecordId}
        </foreach>
        order by opd."id"
    </select>
    <select id="getPersonDtoById" resultType="com.chinaztt.mes.production.dto.PersonBoardDTO">
        select opd."id",opd.work_time,bs.staff_name,bs.staff_no,coalesce(opd.duty_time,0) duty_time,opd.staff_id,
        (select sum(coalesce(opd2.duty_time,0)) from production_person_board opd2 left join production_duty_record pdr2 on pdr2."id"=opd2.duty_record_id
        where opd2.staff_id=opd.staff_id and TO_CHAR(pdr2.duty_date, 'yyyy-mm')=TO_CHAR(pdr.duty_date, 'yyyy-mm')) total_duty_time
        from production_person_board opd
        left join basic_staff bs on bs."id"=opd.staff_id
        left join production_duty_record pdr on pdr."id"=opd.duty_record_id
        where opd.id=#{id}
    </select>
    <select id="selectByDutyRecordIdAndStaffId" resultType="com.chinaztt.mes.production.entity.PersonBoard">
        select ppb.*
        from production_person_board ppb
        where ppb.duty_record_id=#{dutyRecordId} and ppb.staff_id=#{staffId}
    </select>
 
    <insert id="backPersonBoardById">
        insert into production_person_board_back(work_time,workstation_id,staff_id,status,closing_time,duty_record_id,
        duty_time,meal_subsidy,night_differential,person_board_id,operator,operating_time,type)
        select work_time,workstation_id,staff_id,status,closing_time,duty_record_id,duty_time,meal_subsidy,night_differential,
        id,update_user,now(),#{type} from production_person_board where id =#{id}
    </insert>
    <insert id="backDeletePersonBoardByIds">
        insert into production_person_board_back(person_board_id,operator,operating_time,type)
        values(#{id},#{operator},now(),'删除')
    </insert>
</mapper>