李林
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
package com.chinaztt.mes.production.controller;
 
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.thread.ThreadUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chinaztt.mes.production.entity.ArtificialInformation;
import com.chinaztt.mes.production.service.ArtificialInformationService;
import com.chinaztt.mes.production.service.DutyRecordService;
import com.chinaztt.mes.production.util.BackUtils;
import com.chinaztt.ztt.common.core.util.R;
import com.chinaztt.ztt.common.log.annotation.SysLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
 
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
 
 
/**
 * 杂工明细
 *
 * @author cxf
 * @date 2021-01-21 13:22:22
 */
@RestController
@AllArgsConstructor
@RequestMapping("/artificialInformation")
@Api(value = "artificialInformation", tags = "杂工明细管理")
public class ArtificialInformationController {
 
    private final ArtificialInformationService artificialInformationService;
    private final DutyRecordService dutyRecordService;
    private final BackUtils backUtils;
 
    /**
     * 分页查询
     *
     * @param page                  分页对象
     * @param artificialInformation 杂工明细
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page")
    public R getProductionArtificialInformationPage(Page page, ArtificialInformation artificialInformation) {
        return R.ok(artificialInformationService.page(page, Wrappers.query(artificialInformation)));
    }
 
    /**
     * 根据上班记录查询杂工记录
     *
     * @param dutyRecordIdList
     * @return
     */
    @ApiOperation(value = "根据上班记录查询杂工记录", notes = "根据上班记录查询杂工记录")
    @GetMapping("/getArtificialInformationByDutyRecordId")
    public R getArtificialInformationByDutyRecordId(@RequestParam("dutyRecordIdList") List<Long> dutyRecordIdList) {
        return R.ok(artificialInformationService.getArtificialInformationByDutyRecordId(dutyRecordIdList));
    }
 
    /**
     * 查询工时计算杂工记录
     *
     * @param artificialInformation
     * @returna
     */
    @ApiOperation(value = "查询工时计算杂工记录", notes = "查询工时计算杂工记录")
    @GetMapping("/getComputationArtificialInformation")
    public R getComputationArtificialInformation(ArtificialInformation artificialInformation) {
        return R.ok(artificialInformationService.getComputationArtificialInformation(artificialInformation));
    }
 
 
    /**
     * 根据班次list,杂工类型查询工时计算杂工记录
     *
     * @param dutyRecordIdList
     * @param handymanTypeId
     * @returna
     */
    @ApiOperation(value = "根据班次list,杂工类型查询工时计算杂工记录", notes = "根据班次list,杂工类型查询工时计算杂工记录")
    @GetMapping("/getComputationArtificialInformationByList")
    public R getComputationArtificialInformationByList(@RequestParam("dutyRecordIdList")List<Long> dutyRecordIdList,@RequestParam("handymanTypeId")Long handymanTypeId) {
        return R.ok(artificialInformationService.getComputationArtificialInformationByList(dutyRecordIdList,handymanTypeId));
    }
 
 
    /**
     * 根据上班记录查询人工项目(前端两处要修改)
     *
     * @param dutyRecordIdList
     * @return
     */
    @ApiOperation(value = "根据上班记录查询人工项目", notes = "根据上班记录查询人工项目")
    @GetMapping("/getHandymanTypeByDutyRecordId")
    public R getHandymanTypeByDutyRecordId(@RequestParam("dutyRecordIdList") List<Long> dutyRecordIdList) {
        return R.ok(artificialInformationService.getHandymanTypeByDutyRecordId(dutyRecordIdList));
    }
 
 
    /**
     * 通过id查询杂工明细
     *
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{id}")
    public R getById(@PathVariable("id") Long id) {
        return R.ok(artificialInformationService.getById(id));
    }
 
    /**
     * 批量新增杂工明细
     *
     * @param artificialInformationList 杂工明细
     * @return R
     */
    @ApiOperation(value = "批量新增杂工明细", notes = "批量新增杂工明细")
    @SysLog("批量新增杂工明细")
    @PostMapping("/batch")
    public R save(@RequestBody List<ArtificialInformation> artificialInformationList) {
        List<Long> ids = artificialInformationService.saveList(artificialInformationList);
        backUtils.backArtificialInformationByIds(ids, "新增");
        if (CollectionUtil.isNotEmpty(artificialInformationList)) {
            Long dutyRecordId = artificialInformationList.get(0).getDutyRecordId();
            ThreadUtil.execute(() -> dutyRecordService.refreshPendingById(dutyRecordId));
        }
        return R.ok(true);
    }
 
    /**
     * 新增杂工明细
     *
     * @param artificialInformation 杂工明细
     * @return R
     */
    @ApiOperation(value = "新增杂工明细", notes = "新增杂工明细")
    @SysLog("新增杂工明细")
    @PostMapping
    public R save(@RequestBody ArtificialInformation artificialInformation) {
        artificialInformationService.save(artificialInformation);
        backUtils.backArtificialInformationByIds(Arrays.asList(artificialInformation.getId()), "新增");
        Long dutyRecordId = artificialInformation.getDutyRecordId();
        ThreadUtil.execute(() -> dutyRecordService.refreshPendingById(dutyRecordId));
        return R.ok(artificialInformation.getId());
    }
 
    /**
     * 修改杂工明细
     *
     * @param artificialInformation 杂工明细
     * @return R
     */
    @ApiOperation(value = "修改杂工明细", notes = "修改杂工明细")
    @SysLog("修改杂工明细")
    @PutMapping
    public R updateById(@RequestBody ArtificialInformation artificialInformation) {
        boolean result = artificialInformationService.updateById(artificialInformation);
        backUtils.backArtificialInformationByIds(Arrays.asList(artificialInformation.getId()), "修改");
        return R.ok(result);
    }
 
    /**
     * 检验个人工时
     *
     * @param artificialInformation 杂工明细
     * @return R
     */
    @ApiOperation(value = "检验个人工时", notes = "检验个人工时")
    @SysLog("检验个人工时")
    @PostMapping("checkPersonDutyTimeById")
    public R checkPersonDutyTimeById(@RequestBody ArtificialInformation artificialInformation) {
        return R.ok(null, artificialInformationService.checkPersonDutyTimeById(artificialInformation));
    }
 
    /**
     * 批量修改杂工明细
     *
     * @param artificialInformationList
     * @return R
     */
    @ApiOperation(value = "修改杂工明细", notes = "修改杂工明细")
    @SysLog("修改杂工明细")
    @PostMapping("update")
    public R update(@RequestBody List<ArtificialInformation> artificialInformationList) {
        artificialInformationService.updateBatchById(artificialInformationList);
        List<Long> ids = artificialInformationList.stream().map(ArtificialInformation::getId).collect(Collectors.toList());
        backUtils.backArtificialInformationByIds(ids, "修改");
        return R.ok();
    }
 
    /**
     * 批量检验个人工时
     *
     * @param artificialInformationList 杂工明细
     * @return R
     */
    @ApiOperation(value = "批量检验个人工时", notes = "批量检验个人工时")
    @SysLog("批量检验个人工时")
    @PostMapping("checkPersonDutyTime")
    public R checkPersonDutyTime(@RequestBody List<ArtificialInformation> artificialInformationList) {
        return R.ok(null, artificialInformationService.checkPersonDutyTime(artificialInformationList));
    }
 
    /**
     * 通过id删除杂工明细
     *
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id删除杂工明细", notes = "通过id删除杂工明细")
    @SysLog("通过id删除杂工明细")
    @DeleteMapping("/{id}")
    public R removeById(@PathVariable Long id) {
        ArtificialInformation artificialInformation = artificialInformationService.getById(id);
        backUtils.backDeleteArtificialInformationByIds(Arrays.asList(id));
        artificialInformationService.removeById(id);
        Long dutyRecordId = artificialInformation.getDutyRecordId();
        ThreadUtil.execute(() -> dutyRecordService.refreshPendingById(dutyRecordId));
        return R.ok();
    }
 
    /**
     * 删除杂工明细
     *
     * @param artificialInformation 杂工明细
     * @return R
     */
    @ApiOperation(value = "删除杂工明细", notes = "删除杂工明细")
    @SysLog("删除杂工明细")
    @PostMapping("/delete")
    public R delete(@RequestBody ArtificialInformation artificialInformation) {
        List<ArtificialInformation> list = artificialInformationService.list((Wrappers.<ArtificialInformation>lambdaQuery()
                .eq(ArtificialInformation::getDutyRecordId, artificialInformation.getDutyRecordId())
                .eq(ArtificialInformation::getHandymanTypeId, artificialInformation.getHandymanTypeId())));
        List<Long> ids = list.stream().map(ArtificialInformation::getId).collect(Collectors.toList());
        backUtils.backDeleteArtificialInformationByIds(ids);
        artificialInformationService.removeByIds(ids);
        Long dutyRecordId = artificialInformation.getDutyRecordId();
        ThreadUtil.execute(() -> dutyRecordService.refreshPendingById(dutyRecordId));
        return R.ok();
    }
 
}