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.FactorControl; import com.gkhy.exam.system.domain.FactorDiscern; import com.gkhy.exam.system.mapper.FactorContentMapper; import com.gkhy.exam.system.mapper.FactorControlMapper; import com.gkhy.exam.system.mapper.FactorDiscernMapper; import com.gkhy.exam.system.service.FactorControlService; 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 FactorControlServiceImpl extends ServiceImpl implements FactorControlService { @Autowired private FactorControlMapper factorControlMapper; @Autowired private FactorContentMapper factorContentMapper; @Override public CommonPage selectFactorControlList(FactorControl factorControl) { if (!SecurityUtils.adminUser()){ if (factorControl.getCompanyId()==null){ throw new ApiException("非管理员操作,企业id不可为空"); } } PageUtils.startPage(); List factorControls = factorControlMapper.selectFactorControlList(factorControl); for (FactorControl control : factorControls) { List factorContents = factorContentMapper.selectByFactorId(control.getFactorDiscernId()); control.setFactorContents(factorContents); } return CommonPage.restPage(factorControls); } @Override @Transactional public CommonResult insertFactorControl(FactorControl factorControl) { List factorControls = factorControlMapper.selectFactorDiscernId(factorControl.getFactorDiscernId()); if (factorControls.size()>0){ throw new ApiException("当前企业已有数据,请删除后重试"); } factorControl.setCreateBy(SecurityUtils.getUsername()); factorControl.setCreateTime(LocalDateTime.now()); factorControlMapper.insert(factorControl); List factorContents = factorControl.getFactorContents(); for (FactorContent factorContent : factorContents) { factorContentMapper.updateById(factorContent); } return CommonResult.success(); } @Override public CommonResult updateFactorControl(FactorControl factorControl) { factorControl.setUpdateBy(SecurityUtils.getUsername()); factorControl.setUpdateTime(LocalDateTime.now()); factorControlMapper.updateById(factorControl); List factorContents = factorControl.getFactorContents(); for (FactorContent factorContent : factorContents) { factorContentMapper.updateById(factorContent); } return CommonResult.success(); } @Override public CommonResult deletedFactorControl(Integer factorControlId) { FactorControl factorControl = new FactorControl(); factorControl.setId(factorControlId); factorControl.setUpdateTime(LocalDateTime.now()); factorControl.setUpdateBy(SecurityUtils.getUsername()); factorControl.setDelFlag(2); factorControlMapper.updateById(factorControl); return CommonResult.success(); } }