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.InspectionRecord;
|
import com.gkhy.exam.system.domain.InspectionRecordMess;
|
import com.gkhy.exam.system.mapper.InspectionRecordMapper;
|
import com.gkhy.exam.system.mapper.InspectionRecordMessMapper;
|
import com.gkhy.exam.system.service.InspectionRecordService;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import java.time.LocalDateTime;
|
import java.util.List;
|
|
@Service
|
public class InspectionRecordServiceImpl extends ServiceImpl<InspectionRecordMapper, InspectionRecord> implements InspectionRecordService {
|
|
@Autowired
|
private InspectionRecordMapper recordMapper;
|
|
@Autowired
|
private InspectionRecordMessMapper recordMessMapper;
|
@Override
|
public CommonPage selectRecordList(InspectionRecord record) {
|
if (!SecurityUtils.adminUser()){
|
if (record.getCompanyId()==null){
|
throw new ApiException("非管理员操作,企业id不可为空");
|
}
|
}
|
PageUtils.startPage();
|
List<InspectionRecord> inspectionRecords = recordMapper.selectRecordList(record);
|
for (InspectionRecord inspectionRecord : inspectionRecords) {
|
List<InspectionRecordMess> inspectionRecordMesses = recordMessMapper.selectByRecordId(inspectionRecord.getId());
|
inspectionRecord.setRecordMesses(inspectionRecordMesses);
|
}
|
return CommonPage.restPage(inspectionRecords);
|
}
|
|
@Override
|
public CommonResult insertRecord(InspectionRecord record) {
|
record.setCreateBy(SecurityUtils.getUsername());
|
record.setCreateTime(LocalDateTime.now());
|
recordMapper.insert(record);
|
List<InspectionRecordMess> recordMesses = record.getRecordMesses();
|
for (InspectionRecordMess recordMess : recordMesses) {
|
recordMess.setRecordId(record.getId());
|
}
|
recordMessMapper.insertRecordMess(recordMesses);
|
return CommonResult.success();
|
}
|
|
@Override
|
public CommonResult updateRecord(InspectionRecord record) {
|
record.setUpdateBy(SecurityUtils.getUsername());
|
record.setUpdateTime(LocalDateTime.now());
|
recordMapper.updateById(record);
|
List<InspectionRecordMess> recordMesses = record.getRecordMesses();
|
recordMessMapper.deletedByRecordId(record.getId());
|
recordMessMapper.insertRecordMess(recordMesses);
|
return CommonResult.success();
|
}
|
|
@Override
|
public CommonResult deletedRecord(Integer recordId) {
|
InspectionRecord inspectionRecord = new InspectionRecord();
|
inspectionRecord.setId(recordId);
|
inspectionRecord.setUpdateTime(LocalDateTime.now());
|
inspectionRecord.setUpdateBy(SecurityUtils.getUsername());
|
inspectionRecord.setDelFlag(2);
|
recordMapper.updateById(inspectionRecord);
|
return CommonResult.success();
|
}
|
}
|