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.MonthlyInspection;
|
import com.gkhy.exam.system.domain.MonthlyInspectionMess;
|
import com.gkhy.exam.system.mapper.MonthlyInspectionMapper;
|
import com.gkhy.exam.system.mapper.MonthlyInspectionMessMapper;
|
import com.gkhy.exam.system.service.MonthlyInspectionService;
|
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 MonthlyInspectionServiceImpl extends ServiceImpl<MonthlyInspectionMapper, MonthlyInspection> implements MonthlyInspectionService {
|
|
@Autowired
|
private MonthlyInspectionMapper monthlyInspectionMapper;
|
|
@Autowired
|
private MonthlyInspectionMessMapper monthlyInspectionMessMapper;
|
|
|
@Override
|
public CommonPage selectMonthlyInspectionList(MonthlyInspection monthlyInspection) {
|
if (!SecurityUtils.adminUser()){
|
if (monthlyInspection.getCompanyId()==null){
|
throw new ApiException("非管理员操作,查询条件不可为空");
|
}
|
}
|
PageUtils.startPage();
|
List<MonthlyInspection> monthlyInspections = monthlyInspectionMapper.selectInspectionList(monthlyInspection);
|
for (MonthlyInspection inspection : monthlyInspections) {
|
List<MonthlyInspectionMess> monthlyInspectionMesses = monthlyInspectionMessMapper.selectByMonthlyId(inspection.getId());
|
inspection.setInspectionMesses(monthlyInspectionMesses);
|
}
|
return CommonPage.restPage(monthlyInspections);
|
}
|
|
@Override
|
@Transactional
|
public CommonResult insertMonthlyInspection(MonthlyInspection monthlyInspection) {
|
monthlyInspection.setCreateBy(SecurityUtils.getUsername());
|
monthlyInspection.setCreateTime(LocalDateTime.now());
|
int insert = monthlyInspectionMapper.insert(monthlyInspection);
|
if (insert>0){
|
List<MonthlyInspectionMess> inspectionMesses = monthlyInspection.getInspectionMesses();
|
for (MonthlyInspectionMess inspectionMess : inspectionMesses) {
|
inspectionMess.setMonthlyId(monthlyInspection.getId());
|
}
|
monthlyInspectionMessMapper.insertMonthlys(inspectionMesses);
|
}
|
return CommonResult.success();
|
}
|
|
@Override
|
@Transactional
|
public CommonResult updateMonthlyInspection(MonthlyInspection monthlyInspection) {
|
monthlyInspection.setUpdateBy(SecurityUtils.getUsername());
|
monthlyInspection.setUpdateTime(LocalDateTime.now());
|
int i = monthlyInspectionMapper.updateById(monthlyInspection);
|
if (i>0){
|
List<MonthlyInspectionMess> inspectionMesses = monthlyInspection.getInspectionMesses();
|
monthlyInspectionMessMapper.deleteByMonthlyId(monthlyInspection.getId());
|
monthlyInspectionMessMapper.insertMonthlys(inspectionMesses);
|
}
|
return CommonResult.success();
|
}
|
|
@Override
|
public CommonResult deletedMonthlyInspection(Integer monthlyId) {
|
MonthlyInspection monthlyInspection = new MonthlyInspection();
|
monthlyInspection.setId(monthlyId);
|
monthlyInspection.setUpdateBy(SecurityUtils.getUsername());
|
monthlyInspection.setUpdateTime(LocalDateTime.now());
|
monthlyInspection.setDelFlag(2);
|
int i = monthlyInspectionMapper.updateById(monthlyInspection);
|
if (i>0){
|
return CommonResult.success();
|
}
|
return CommonResult.failed();
|
}
|
}
|