package com.gk.hotwork.Service.ServiceImpl;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.gk.hotwork.Domain.Exception.BusinessException;
|
import com.gk.hotwork.Domain.MajorEquipment;
|
import com.gk.hotwork.Domain.MajorEquipmentAlarm;
|
import com.gk.hotwork.Domain.UserInfo;
|
import com.gk.hotwork.Domain.Utils.StringUtils;
|
import com.gk.hotwork.Mapper.MajorEquipmentAlarmMapper;
|
import com.gk.hotwork.Service.*;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import java.text.SimpleDateFormat;
|
import java.util.Date;
|
import java.util.HashMap;
|
import java.util.Map;
|
|
@Service("MajorEquipmentAlarmService")
|
@Transactional
|
public class MajorEquipmentAlarmImpl extends ServiceImpl<MajorEquipmentAlarmMapper,MajorEquipmentAlarm> implements MajorEquipmentAlarmService {
|
|
@Autowired
|
private MajorEquipmentAlarmMapper majorEquipmentAlarmMapper;
|
@Autowired
|
MajorEquipmentService majorEquipmentService;
|
@Autowired
|
private UserService userService;
|
@Autowired
|
private SmsService smsService;
|
|
|
|
/**
|
* @Description: 分页
|
*/
|
@Override
|
public IPage<MajorEquipmentAlarm> selectPage(Page<MajorEquipmentAlarm> page, Map<String, Object> filter, UserInfo user) {
|
return majorEquipmentAlarmMapper.selectPages(page,filter);
|
}
|
|
|
/**
|
* @Description: 新增
|
*/
|
@Override
|
public void addOne(MajorEquipmentAlarm param, UserInfo user) {
|
requiredVerification(param);
|
|
param.setValidFlag(Boolean.TRUE);
|
param.setUpdateBy(user.getRealname());
|
param.setCreateBy(user.getRealname());
|
param.setUpdateTime(new Date());
|
param.setCreateTime(new Date());
|
this.save(param);
|
//短信任务单独跑个线程
|
MajorEquipment equipment = majorEquipmentService.getById(param.getEquipmentId());
|
Long userId = equipment.getUserId();
|
|
Runnable smsTask = () -> {
|
if (userId == null) return;
|
UserInfo userInfo = userService.getById(userId);
|
if (userInfo == null) return;
|
if (StringUtils.isBlank(userInfo.getUsername()) || StringUtils.isBlank(userInfo.getRealname())) return;
|
Map<String, Object> params = new HashMap<>();
|
params.put("name", equipment.getName());
|
params.put("info", param.getAlarmInfo());
|
params.put("date", new SimpleDateFormat("yyyy-MM-dd HH:mm").format(param.getAlarmTime()));
|
smsService.send(userInfo.getUsername(), "245614", userInfo.getRealname(), params);
|
};
|
|
new Thread(smsTask).start();
|
}
|
|
|
/**
|
* @Description: 修改
|
*/
|
@Override
|
public void modOne(MajorEquipmentAlarm param, UserInfo user) {
|
selectVerification(param.getId());
|
requiredVerification(param);
|
|
param.setUpdateTime(new Date());
|
param.setUpdateBy(user.getRealname());
|
this.updateById(param);
|
}
|
|
/**
|
* @Description: 删除
|
*/
|
@Override
|
public void delOne(Long id, UserInfo user) {
|
selectVerification(id);
|
|
MajorEquipmentAlarm delOne = new MajorEquipmentAlarm();
|
delOne.setId(id);
|
delOne.setUpdateTime(new Date());
|
delOne.setUpdateBy(user.getRealname());
|
delOne.setValidFlag(Boolean.FALSE);
|
this.updateById(delOne);
|
|
}
|
|
/**
|
* 查询验证
|
* 验证对象存在
|
*/
|
public void selectVerification(Long id){
|
if (id == null) throw new BusinessException("id传参不能为空");
|
MajorEquipmentAlarm MajorEquipmentAlarm = this.getById(id);
|
if (MajorEquipmentAlarm == null) throw new BusinessException("找不到对应实体");
|
}
|
|
/**
|
* 操作验证
|
* 验证必填项
|
*
|
*/
|
public void requiredVerification(MajorEquipmentAlarm param){
|
if (param.getEquipmentId() == null) throw new BusinessException("请选择设备");
|
if (param.getStatus() == null) throw new BusinessException("请选择状态");
|
if (param.getAlarmTime() == null) throw new BusinessException("请选择报警时间");
|
if(StringUtils.isBlank(param.getAlarmInfo())) throw new BusinessException("请填写报警信息");
|
}
|
|
}
|