package com.gkhy.exam.system.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gkhy.exam.common.api.CommonPage;
import com.gkhy.exam.common.domain.entity.SysUser;
import com.gkhy.exam.common.enums.UserTypeEnum;
import com.gkhy.exam.common.exception.ApiException;
import com.gkhy.exam.common.utils.PageUtils;
import com.gkhy.exam.common.utils.SecurityUtils;
import com.gkhy.exam.system.domain.ExExamRecord;
import com.gkhy.exam.system.mapper.ExExamRecordMapper;
import com.gkhy.exam.system.service.ExExamRecordService;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
/**
*
* 线下教育登记表 服务实现类
*
*
* @author kzy
* @since 2024-06-24 16:16:33
*/
@Service
public class ExExamRecordServiceImpl extends ServiceImpl implements ExExamRecordService {
@Override
public CommonPage selectExamRecordList(ExExamRecord examRecord) {
SysUser user= SecurityUtils.getLoginUser().getUser();
if(!user.getUserType().equals(UserTypeEnum.SYSTEM_USER.getCode())){
examRecord.setCompanyId(user.getCompanyId());
}
PageUtils.startPage();
List recordList=baseMapper.selectExamRecordList(examRecord);
return CommonPage.restPage(recordList);
}
@Override
public ExExamRecord selectExamRecordById(Long recordId) {
return baseMapper.selectExamRecordById(recordId);
}
@Override
public int insertExamRecord(ExExamRecord examRecord) {
checkUserAllowed(examRecord);
examRecord.setCompanyId(SecurityUtils.getLoginUser().getUser().getCompanyId());
examRecord.setCreateBy(SecurityUtils.getUsername());
int row=baseMapper.insert(examRecord);
if(row<1){
throw new ApiException("新增登记记录失败");
}
return row;
}
@Override
public int updateExamRecord(ExExamRecord examRecord) {
checkUserAllowed(examRecord);
examRecord.setUpdateBy(SecurityUtils.getUsername());
int row=baseMapper.updateById(examRecord);
if(row<1){
throw new ApiException("更新登记记录失败");
}
return row;
}
@Override
public int deleteExamRecordById(Long recordId) {
checkUserAllowed(baseMapper.selectById(recordId));
return baseMapper.deleteById(recordId);
}
public void checkUserAllowed(ExExamRecord examRecord) {
SysUser currentUser= SecurityUtils.getLoginUser().getUser();
if(currentUser.getUserType().equals(UserTypeEnum.SYSTEM_USER.getCode())){
throw new ApiException("管理员没有权限操作");
}
if(currentUser.getUserType().equals(UserTypeEnum.STUDENT.getCode())){
throw new ApiException("没有权限操作");
}
if(examRecord.getCompanyId()!=null&&!currentUser.getCompanyId().equals(examRecord.getCompanyId())){
throw new ApiException("没有权限操作其他企业登记记录");
}
}
@Override
public boolean checkRecordUnique(ExExamRecord examRecord) {
return false;
}
@Override
public void importRecord(MultipartFile file) {
}
}