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("微信:推送成功;");
|
|
}
|
|
}
|