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.HzWarehouseRecord;
|
import com.gkhy.hazmat.system.mapper.HzWarehouseRecordMapper;
|
import com.gkhy.hazmat.system.service.HzWarehouseRecordService;
|
import org.springframework.stereotype.Service;
|
|
import java.util.List;
|
import java.util.Objects;
|
|
/**
|
* <p>
|
* 仓库变动记录表 服务实现类
|
* </p>
|
*
|
* @author kzy
|
* @since 2024-08-05 14:41:40
|
*/
|
@Service
|
public class HzWarehouseRecordServiceImpl extends ServiceImpl<HzWarehouseRecordMapper, HzWarehouseRecord> implements HzWarehouseRecordService {
|
|
@Override
|
public CommonPage selectWarehouseRecordList(HzWarehouseRecord warehouseRecord) {
|
if(warehouseRecord.getWarehouseId()==null||warehouseRecord.getBasicId()==null){
|
throw new ApiException("仓库id或者基础数据id不能为空");
|
}
|
SysUser currentUser = SecurityUtils.getLoginUser().getUser();
|
if (!currentUser.getUserType().equals(UserTypeEnum.SYSTEM_USER.getCode())) {
|
warehouseRecord.setCompanyId(currentUser.getCompanyId());
|
}
|
PageUtils.startPage();
|
List<HzWarehouseRecord> studentList =baseMapper.selectWarehouseRecordList(warehouseRecord);
|
return CommonPage.restPage(studentList);
|
}
|
|
@Override
|
public HzWarehouseRecord selectWarehouseRecordById(Long warehouseRecordId) {
|
HzWarehouseRecord warehouseRecord = baseMapper.selectById(warehouseRecordId);
|
SysUser currentUser = SecurityUtils.getLoginUser().getUser();
|
if (currentUser.getUserType().equals(UserTypeEnum.SYSTEM_USER.getCode())) {
|
return warehouseRecord;
|
} else if (!warehouseRecord.getCompanyId().equals(currentUser.getCompanyId())) {
|
throw new ApiException("无权限查看其它企业危化品基础信息");
|
}
|
return warehouseRecord;
|
}
|
|
@Override
|
public int insertWarehouseRecord(HzWarehouseRecord warehouseRecord) {
|
SysUser currentUser = SecurityUtils.getLoginUser().getUser();
|
warehouseRecord.setCreateBy(currentUser.getUsername());
|
warehouseRecord.setCompanyId(currentUser.getCompanyId());
|
checkUserAllowed(null,currentUser);
|
int row = baseMapper.insert(warehouseRecord);
|
if (row < 1) {
|
throw new ApiException("新增仓库变动记录失败");
|
}
|
return row;
|
}
|
|
@Override
|
public int deleteWarehouseRecordById(Long warehouseRecordId) {
|
HzWarehouseRecord warehouseRecord=baseMapper.selectById(warehouseRecordId);
|
if(warehouseRecord==null){
|
throw new ApiException("仓库记录不存在");
|
}
|
SysUser currentUser = SecurityUtils.getLoginUser().getUser();
|
checkUserAllowed(warehouseRecord,currentUser);
|
baseMapper.deleteById(warehouseRecordId);
|
return 0;
|
}
|
|
public void checkUserAllowed(HzWarehouseRecord warehouseRecord,SysUser user) {
|
if (user.getUserType().equals(UserTypeEnum.SYSTEM_USER.getCode())) {
|
throw new ApiException("管理员不能操作");
|
}
|
if(warehouseRecord!=null){
|
if(!Objects.equals(user.getCompanyId(), warehouseRecord.getCompanyId())){
|
throw new ApiException("无权限操作其他企业数据");
|
}
|
}
|
}
|
|
}
|