郑永安
2023-09-19 69185134fcfaf913ea45f1255677225a2cc311a4
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
package com.gk.hotwork.Service.ServiceImpl;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gk.hotwork.Domain.*;
import com.gk.hotwork.Domain.Utils.BeanUtils;
import com.gk.hotwork.Domain.Utils.StringUtils;
import com.gk.hotwork.Domain.Vo.TaskWorkerVo;
import com.gk.hotwork.Mapper.TaskWorkerMapper;
import com.gk.hotwork.Service.EquipmentService;
import com.gk.hotwork.Service.TaskLocationService;
import com.gk.hotwork.Service.TaskWorkerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
 
/**
 * @author : jingjy
 * @date : 2021/8/20 14:15
 */
@Service("TaskWorkerService")
public class TaskWorkerServiceImpl extends ServiceImpl<TaskWorkerMapper, TaskWorker> implements TaskWorkerService {
    @Autowired
    private TaskWorkerMapper taskWorkerMapper;
    @Autowired
    private EquipmentService equipmentService;
    @Autowired
    private TaskWorkerService taskWorkerService;
    @Autowired
    private TaskLocationService taskLocationService;
 
    @Override
    public List<TaskWorker> getListByTaskCode(String code) {
        LambdaQueryWrapper<TaskWorker> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(TaskWorker::getTaskcode,code);
        wrapper.eq(TaskWorker::getFlag,(byte)0);
        return baseMapper.selectList(wrapper);
    }
 
    @Override
    public void deleteByTaskCode(String code) {
        Byte isDeleted = 1;
        List<TaskWorker> workers = getListByTaskCode(code);
        for (TaskWorker worker : workers){
            worker.setFlag(isDeleted);
            baseMapper.updateById(worker);
        }
    }
 
    @Override
    public List<TaskWorkerVo> getVoByTaskCode(String code) {
        LambdaQueryWrapper<TaskWorker> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(TaskWorker::getTaskcode,code);
        wrapper.eq(TaskWorker::getFlag,(byte)0);
        List<TaskWorker> workers = baseMapper.selectList(wrapper);
        List<TaskWorkerVo>workerVos = new ArrayList<>();
        for (TaskWorker worker : workers){
            TaskWorkerVo workerVo = BeanUtils.copy(worker,TaskWorkerVo.class);
            List<EquipmentInfo>equipmentInfos = equipmentService.selectByTaskAndWorker(code,worker.getWorker());
            workerVo.setEquipments(equipmentInfos);
            String photoAddress = "";
            for (EquipmentInfo equipmentInfo: equipmentInfos){
                if (equipmentInfo.getIsphoto().equals((byte)1)){
                    photoAddress = equipmentInfo.getPhotoaddress();
                }
            }
            TaskLocationInfo taskLocationInfo = taskLocationService.getLocationByTaskAndWorker(code,workerVo.getWorker());
            if (taskLocationInfo !=null){
                workerVo.setLongitude(StringUtils.isBlank(taskLocationInfo.getLongitude())?"":taskLocationInfo.getLongitude());
                workerVo.setLatitude(StringUtils.isBlank(taskLocationInfo.getLatitude())?"":taskLocationInfo.getLatitude());
                workerVo.setPhotoAddress(photoAddress);
            }
            workerVos.add(workerVo);
        }
        return workerVos;
    }
 
    @Override
    public void saveBatch(List<TaskWorkerVo> workers, UserInfo userInfo) {
        List<TaskWorker> taskWorkers = new ArrayList<>();
        for (TaskWorkerVo workerVo : workers){
            TaskWorker taskWorker = BeanUtils.copy(workerVo,TaskWorker.class);
            taskWorker.setCreatedat(new Date());
            taskWorker.setCreatedby(userInfo.getRealname());
            taskWorkers.add(taskWorker);
        }
        taskWorkerService.saveBatch(taskWorkers);
    }
}