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.api.CommonResult;
|
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.FactorContent;
|
import com.gkhy.exam.system.domain.FactorDiscern;
|
import com.gkhy.exam.system.mapper.FactorContentMapper;
|
import com.gkhy.exam.system.mapper.FactorDiscernMapper;
|
import com.gkhy.exam.system.service.FactorDiscernService;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import java.time.LocalDateTime;
|
import java.util.List;
|
|
@Service
|
public class FactorDiscernServiceImpl extends ServiceImpl<FactorDiscernMapper, FactorDiscern> implements FactorDiscernService {
|
|
@Autowired
|
private FactorDiscernMapper factorDiscernMapper;
|
|
@Autowired
|
private FactorContentMapper factorContentMapper;
|
|
|
@Override
|
public CommonPage selectFactorDiscernList(FactorDiscern factorDiscern) {
|
if (!SecurityUtils.adminUser()){
|
if (factorDiscern.getCompanyId()==null){
|
throw new ApiException("非管理员操作,企业id不可为空");
|
}
|
}
|
PageUtils.startPage();
|
List<FactorDiscern> factorDiscerns = factorDiscernMapper.selectFactorDiscernList(factorDiscern);
|
for (FactorDiscern discern : factorDiscerns) {
|
List<FactorContent> factorContents = factorContentMapper.selectByFactorId(discern.getId());
|
discern.setFactorContents(factorContents);
|
}
|
return CommonPage.restPage(factorDiscerns);
|
}
|
|
@Override
|
public CommonResult selectFactorDiscernListAll(FactorDiscern factorDiscern) {
|
List<FactorDiscern> factorDiscerns = factorDiscernMapper.selectFactorDiscernList(factorDiscern);
|
for (FactorDiscern discern : factorDiscerns) {
|
List<FactorContent> factorContents = factorContentMapper.selectByFactorId(discern.getId());
|
discern.setFactorContents(factorContents);
|
}
|
return CommonResult.success(factorDiscerns);
|
}
|
|
@Override
|
@Transactional
|
public CommonResult insertFactorDiscern(FactorDiscern factorDiscern) {
|
List<FactorDiscern> factorDiscerns = factorDiscernMapper.selectByCompanyIdAndDeptId(factorDiscern);
|
if (factorDiscerns.size()>0){
|
throw new ApiException("当前企业已有数据,请删除后重试");
|
}
|
factorDiscern.setCreateBy(SecurityUtils.getUsername());
|
factorDiscern.setCreateTime(LocalDateTime.now());
|
factorDiscernMapper.insert(factorDiscern);
|
List<FactorContent> factorContents = factorDiscern.getFactorContents();
|
for (FactorContent factorContent : factorContents) {
|
factorContent.setFactorDiscernId(factorDiscern.getId());
|
}
|
factorContentMapper.insertBatch(factorContents);
|
return CommonResult.success();
|
}
|
|
@Override
|
public CommonResult updateFactorDiscern(FactorDiscern factorDiscern) {
|
factorDiscern.setUpdateBy(SecurityUtils.getUsername());
|
factorDiscern.setUpdateTime(LocalDateTime.now());
|
factorDiscernMapper.updateById(factorDiscern);
|
List<FactorContent> factorContents = factorDiscern.getFactorContents();
|
for (FactorContent factorContent : factorContents) {
|
factorContent.setFactorDiscernId(factorDiscern.getId());
|
}
|
factorContentMapper.deletedByFactorId(factorDiscern.getId());
|
factorContentMapper.insertBatch(factorContents);
|
return CommonResult.success();
|
}
|
|
@Override
|
public CommonResult deletedFactorDiscern(Integer factorDiscrenId) {
|
FactorDiscern factorDiscern = new FactorDiscern();
|
factorDiscern.setId(factorDiscrenId);
|
factorDiscern.setUpdateBy(SecurityUtils.getUsername());
|
factorDiscern.setUpdateTime(LocalDateTime.now());
|
factorDiscern.setDelFlag(2);
|
factorDiscernMapper.updateById(factorDiscern);
|
return CommonResult.success();
|
}
|
|
|
}
|