package com.gkhy.hazmat.system.service.impl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.gkhy.hazmat.common.api.CommonPage;
|
import com.gkhy.hazmat.common.domain.entity.SysUser;
|
import com.gkhy.hazmat.common.enums.UserTypeEnum;
|
import com.gkhy.hazmat.common.exception.ApiException;
|
import com.gkhy.hazmat.common.utils.PageUtils;
|
import com.gkhy.hazmat.common.utils.SecurityUtils;
|
import com.gkhy.hazmat.system.domain.HzWarning;
|
import com.gkhy.hazmat.system.mapper.HzWarningMapper;
|
import com.gkhy.hazmat.system.service.HzWarningService;
|
import org.springframework.stereotype.Service;
|
|
import java.time.LocalDateTime;
|
import java.util.List;
|
|
/**
|
* <p>
|
* 预警表 服务实现类
|
* </p>
|
*
|
* @author kzy
|
* @since 2024-08-05 14:41:40
|
*/
|
@Service
|
public class HzWarningServiceImpl extends ServiceImpl<HzWarningMapper, HzWarning> implements HzWarningService {
|
|
@Override
|
public CommonPage selectWarningList(HzWarning warning) {
|
SysUser currentUser= SecurityUtils.getLoginUser().getUser();
|
if(!currentUser.getUserType().equals(UserTypeEnum.SYSTEM_USER.getCode()) && !currentUser.getUserType().equals(UserTypeEnum.CHECK_USER.getCode())){
|
warning.setCompanyId(currentUser.getCompanyId());
|
}
|
PageUtils.startPage();
|
List<HzWarning> studentList=baseMapper.selectWarningList(warning);
|
|
return CommonPage.restPage(studentList);
|
}
|
|
@Override
|
public HzWarning selectWarningById(Long warningId) {
|
HzWarning warning= baseMapper.selectById(warningId);
|
SysUser currentUser=SecurityUtils.getLoginUser().getUser();
|
if(currentUser.getUserType().equals(UserTypeEnum.SYSTEM_USER.getCode())){
|
return warning;
|
}else if(!warning.getCompanyId().equals(currentUser.getCompanyId())){
|
throw new ApiException("无权限查看其它企业数据");
|
}
|
return warning;
|
}
|
|
@Override
|
public int markWarning(HzWarning warning) {
|
if(warning.getId()==null||warning.getCompanyId()==null||warning.getState()==null){
|
throw new ApiException("标记预警参数不正确");
|
}
|
SysUser currentUser=SecurityUtils.getLoginUser().getUser();
|
if(!currentUser.getUserType().equals(UserTypeEnum.SYSTEM_USER.getCode())) {
|
if (!warning.getCompanyId().equals(currentUser.getCompanyId())) {
|
throw new ApiException("无权限操作其它企业数据");
|
}
|
}
|
int row=baseMapper.updateById(new HzWarning().setId(warning.getId()).setState(warning.getState()).setHandleTime(LocalDateTime.now()).setUpdateBy(currentUser.getUsername()));
|
if(row<1){
|
throw new ApiException("标记预警信息失败");
|
}
|
return row;
|
}
|
|
@Override
|
public int deleteWarningById(Long warningId) {
|
HzWarning warning=baseMapper.selectById(warningId);
|
if(warning==null){
|
throw new ApiException("预警信息不存在");
|
}
|
SysUser currentUser=SecurityUtils.getLoginUser().getUser();
|
if(!currentUser.getUserType().equals(UserTypeEnum.SYSTEM_USER.getCode())) {
|
if (!warning.getCompanyId().equals(currentUser.getCompanyId())) {
|
throw new ApiException("无权限操作其它企业数据");
|
}
|
}
|
int row=baseMapper.deleteById(warningId);
|
return row;
|
}
|
|
@Override
|
public Integer selectWarningCount(Long companyId) {
|
SysUser currentUser=SecurityUtils.getLoginUser().getUser();
|
if(currentUser.getUserType().equals(UserTypeEnum.SYSTEM_USER.getCode())){
|
throw new ApiException("管理员不能操作");
|
}
|
if (currentUser.getUserType().equals(UserTypeEnum.CHECK_USER.getCode())){
|
return baseMapper.selectWarningCount(companyId);
|
}
|
return baseMapper.selectWarningCount(currentUser.getCompanyId());
|
}
|
}
|