sgj
5 小时以前 4b2b0ec05306c285cff9f95064cf70b5e6e37516
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
package com.fzzy.igds.service;
 
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fzzy.igds.data.BaseResp;
import com.fzzy.igds.data.IgdsBaseParam;
import com.fzzy.igds.domain.SnapReply;
import com.fzzy.igds.mapper.SnapReplyMapper;
import com.fzzy.igds.utils.ContextUtil;
import com.fzzy.igds.utils.WxUtil;
import com.ruoyi.common.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
 
@Slf4j
@Service
public class SnapReplyService {
 
    @Resource
    private SnapReplyMapper snapReplyMapper;
    @Resource
    private WxUtil weChatUtil;
 
 
    /**
     * 分页查询数据
     *
     * @param page
     * @param param
     */
    public void listPage(Page<SnapReply> page, IgdsBaseParam param) {
        QueryWrapper<SnapReply> queryWrapper = new QueryWrapper<>();
        if (StringUtils.isBlank(param.getCompanyId())) {
            param.setCompanyId(ContextUtil.getCompanyId());
        }
        queryWrapper.eq("company_id", param.getCompanyId());
 
        //库区检索
        if (StringUtils.isNotBlank(param.getDeptId())) {
            queryWrapper.eq("dept_id", param.getDeptId());
        }
 
        //是否处理检索
        if (StringUtils.isNotBlank(param.getKey())) {
            queryWrapper.eq("is_handle", param.getKey());
        }
 
        queryWrapper.orderByDesc("create_time");
        queryWrapper.orderByDesc("id");
        snapReplyMapper.selectPage(page, queryWrapper);
    }
 
    public void listPageByListDept(Page<SnapReply> page, IgdsBaseParam param, List<String> listDept) {
        if (listDept == null || listDept.isEmpty()) {
            return;
        }
 
        QueryWrapper<SnapReply> queryWrapper = new QueryWrapper<>();
        if (StringUtils.isBlank(param.getCompanyId())) {
            param.setCompanyId(ContextUtil.getCompanyId());
        }
        queryWrapper.eq("company_id", param.getCompanyId());
 
        //库区检索
        if (!listDept.isEmpty()) {
            queryWrapper.in("dept_id", listDept);
        }
        //是否处理检索
        if (StringUtils.isNotBlank(param.getKey())) {
            queryWrapper.eq("is_handle", param.getKey());
        }
 
        queryWrapper.orderByDesc("create_time");
        queryWrapper.orderByDesc("id");
        snapReplyMapper.selectPage(page, queryWrapper);
    }
 
    /**
     * 查询所有数据
     *
     * @param param
     * @return
     * @author sgj
     * @date 2026/04/07
     */
    public List<SnapReply> getListByParam(IgdsBaseParam param) {
        if (null == param) {
            param = new IgdsBaseParam();
        }
 
        QueryWrapper<SnapReply> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("company_id", ContextUtil.getCompanyId());
 
        if (StringUtils.isNotBlank(param.getDeptId())) {
            queryWrapper.eq("dept_id", param.getDeptId());
        }
 
        if (StringUtils.isNotBlank(param.getName())) {
            queryWrapper.eq("is_handle", param.getName());
        }
 
        queryWrapper.orderByDesc("create_time");
 
        return snapReplyMapper.selectList(queryWrapper);
    }
 
    /**
     * 根据ID查询详情
     *
     * @param id
     * @return
     * @author sgj
     * @date 2026/04/07
     */
    public SnapReply getById(String id) {
        return snapReplyMapper.selectById(id);
    }
 
    /**
     * 持久化保存
     *
     * @param snapReply
     * @author sgj
     * @date 2026/04/07
     */
    public BaseResp addData(SnapReply snapReply) {
        if (StringUtils.isBlank(snapReply.getId())) {
            snapReply.setId(ContextUtil.generateId());
        }
        if (StringUtils.isBlank(snapReply.getCompanyId())) {
            snapReply.setCompanyId(ContextUtil.getCompanyId());
        }
 
        snapReply.setUpdateBy(ContextUtil.getLoginUserName());
        snapReply.setUpdateTime(new Date());
        snapReply.setCreateBy(ContextUtil.getLoginUserName());
        snapReply.setCreateTime(new Date());
        return snapReplyMapper.insert(snapReply) > 0 ? BaseResp.success() : BaseResp.error("添加失败");
    }
 
    /**
     * 更新数据
     *
     * @param snapReply
     * @return
     * @author sgj
     * @date 2026/04/07
     */
    public BaseResp updateData(SnapReply snapReply) {
        snapReply.setUpdateBy(ContextUtil.getLoginUserName());
        snapReply.setUpdateTime(new Date());
        return snapReplyMapper.updateById(snapReply) > 0 ? BaseResp.success() : BaseResp.error("更新失败");
    }
 
    /**
     * 删除数据
     *
     * @param snapReply
     * @return
     * @author sgj
     * @date 2026/04/07
     */
    public BaseResp deleteData(SnapReply snapReply) {
        return snapReplyMapper.deleteById(snapReply) > 0 ? BaseResp.success() : BaseResp.error("删除失败");
    }
 
 
 
    /**
     * 发送警告到微信
     * @param deptId
     */
    public BaseResp sendNotice(String deptId){
        //todo 未完成
        if(StringUtils.isEmpty(deptId)){
            return BaseResp.error("请选择库区");
        }
 
 
//        //需要推送的用户
//        List<SysUser> users= new ArrayList<>();
//        String res = "";
//        //遍历用户,发送微信消息
//        for (SysUser user : users) {
//            if(StringUtils.isNotEmpty(user.getOpenId())){
//                boolean b = weChatUtil.sendMessage(
//                        user.getOpenId(),
//                        snapReply.getId(),
//                        snapReply.getCompanyId(),
//                        "库区告警批复测试推送",
//                        snapReply.getDeptId(),
//                        snapReply.getContent(),
//                        DateFormatUtils.format(snapReply.getCreateTime(),"yyyy-MM-dd HH:mm:ss"),
//                        "",
//                        "",
//                        user.getUserName());
//                if(!b){
//                    res += user.getUserName() + "用户微信推送失败,";
//                    return BaseResp.error(res);
//
//                }
//            }else{
//                log.debug("------用户openid不存在,不进行推送------");
//                res += user.getUserName() + "用户未绑定,";
//                return BaseResp.error(res);
//
//            }
//        }
//        if(StringUtils.isEmpty(res)){
//            return BaseResp.success("微信:推送成功;");
//        }else{
//            return BaseResp.error("微信:"+res+";");
//        }
        return BaseResp.success("微信:推送成功;");
 
    }
 
}