whyclxw
2024-07-30 ed04733e15a5304c68ac16c121fd2989c851a57b
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
package com.whyc.service;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.whyc.dto.Response;
import com.whyc.mapper.UserInfMapper;
import com.whyc.mapper.UserWorkMapper;
import com.whyc.mapper.WorkAlarmMapper;
import com.whyc.pojo.*;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.util.List;
 
@Service
public class WorkAlarmService {
    @Resource
    private WorkAlarmMapper mapper;
    @Resource
    private UserWorkMapper userWorkMapper;
    @Resource
    private UserInfMapper userInfMapper;
 
    public Response searchByUserIdAndStatus(int pageNum,int pageSize,Integer uId,Integer note){
        PageHelper.startPage(pageNum,pageSize);
        Integer status = null;
        //查询全部列表
        if(note==1){
            status = null;
        }
        //查询待处理列表
        else if(note==2){
            status = 1;
        }
        //查询处理中列表
        else if(note==3){
            status = 2;
        }
        //查询已完成列表
        else if(note==4){
            status = 3;
        }
        List<WorkAlarm> list = mapper.searchByUserIdAndStatus(uId,status);
        PageInfo pageInfo = new PageInfo(list);
        return new Response().set(1,pageInfo,"查询成功");
    }
 
    public Response updateWorkAlarm(WorkAlarm workAlarm){
        int flag = mapper.updateById(workAlarm);
        return new Response().set(1,flag>0?true:false);
    }
 
    public Response searchById(int id){
        WorkAlarm result = mapper.selectById(id);
        if (result.getUserId()!=null && result.getUserId()!=0){
            UserInf userInf = userInfMapper.selectById(result.getUserId());
            result.setUserName(userInf.getUName());
        }
        //去告警表查询是否存在
        int flag = 1;
        if (result.getAlarmRecId()==null){
            flag = 0;
        }
        boolean bl = alarmIsExist(result.getAlarmRecId());
        if (!bl){
            flag = 0;
        }
        result.setFlag(flag);
        QueryWrapper<UserWork> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("workId",id);
        queryWrapper.orderByDesc("endTime");
        List<UserWork> list = userWorkMapper.selectList(queryWrapper);
        result.setUserWorkList(list);
        return new Response().set(1,result,"查询成功");
    }
 
    public boolean alarmIsExist(int num){
        boolean bl = false;
        List<BattalarmData> list = mapper.getBattAlarm(num);
        if (list != null && list.size() > 0) {
            bl = true;
        }
        List<BattDevAlarmData> list2 = mapper.getDevAlarm(num);
        if (list2 != null && list2.size() > 0) {
            bl = true;
        }
        return bl;
    }
 
    public Response getTaskListWithFlag(Integer uId,Integer note,int pageNum,int pageSize){
        PageHelper.startPage(pageNum,pageSize);
        Integer status = null;
        Integer checkStatus = null;
        //查询未派单列表
        if (note == 1) {
            status = 0;
            //此时还没生成user_work表记录
            checkStatus = null;
        }
        //查询已派单列表
        else if (note == 2) {
            status = 1;
            checkStatus = null;
        }
        //查询待审核列表
        else if (note == 3) {
            status = 2;
            checkStatus = 2;
        }
        //查询已完成列表
        else if (note == 4) {
            status = 3;
            checkStatus = 3;
        }
        List<WorkAlarm> list = mapper.getTaskListWithFlag(uId, status, checkStatus);
        PageInfo pageInfo = new PageInfo(list);
        return new Response().set(1, pageInfo, "查询成功");
    }
 
    public Response getTaskListWithFlagNew(Integer uId, Integer note, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        Integer status = null;
        Integer checkStatus = null;
        //查询未派单列表
        if (note == 1) {
            status = 0;
            //此时还没生成user_work表记录
            checkStatus = null;
        }
        //查询已派单列表
        else if (note == 2) {
            status = 1;
            checkStatus = null;
        }
        //查询待审核列表
        else if (note == 3) {
            status = 2;
            checkStatus = 2;
        }
        //查询已完成列表
        else if (note == 4) {
            status = 3;
            checkStatus = 3;
        }
        List<WorkAlarm> list = mapper.getTaskListWithFlagNew(uId, status, checkStatus);
        PageInfo pageInfo = new PageInfo(list);
        return new Response().set(1, pageInfo, "查询成功");
    }
 
 
    public Response dispatchTask(List<WorkAlarm> alarmList) {
        for (WorkAlarm alarm : alarmList) {
            mapper.dispatchTask(alarm);
        }
        return new Response().set(1, true, "更新完成");
    }
 
 
}