package com.gkhy.exam.system.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.gkhy.exam.common.api.CommonPage;
import com.gkhy.exam.common.api.CommonResult;
import com.gkhy.exam.common.constant.UserConstant;
import com.gkhy.exam.common.utils.PageUtils;
import com.gkhy.exam.common.utils.SecurityUtils;
import com.gkhy.exam.system.domain.AnnualVerificationPlan;
import com.gkhy.exam.system.domain.DocumentChangesInvalidated;
import com.gkhy.exam.system.domain.DocumentChangesInvalidatedEvaluate;
import com.gkhy.exam.system.domain.DocumentChangesInvalidatedIssue;
import com.gkhy.exam.system.mapper.DocumentChangesInvalidatedEvaluateMapper;
import com.gkhy.exam.system.mapper.DocumentChangesInvalidatedIssueMapper;
import com.gkhy.exam.system.mapper.DocumentChangesInvalidatedMapper;
import com.gkhy.exam.system.service.DocumentChangesInvalidatedService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
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;
/**
*
* 文件更改作废申请主表 服务实现类
*
*
* @author hh
* @since 2025-08-25 15:01:44
*/
@Service
public class DocumentChangesInvalidatedServiceImpl extends ServiceImpl implements DocumentChangesInvalidatedService {
@Autowired
private DocumentChangesInvalidatedMapper documentChangesInvalidatedMapper;
@Autowired
private DocumentChangesInvalidatedIssueMapper documentChangesInvalidatedIssueMapper;
@Autowired
private DocumentChangesInvalidatedEvaluateMapper documentChangesInvalidatedEvaluateMapper;
@Override
public CommonPage selectDocumentChangesInvalidatedList(DocumentChangesInvalidated documentChangesInvalidated) {
PageUtils.startPage();
List documentChangesInvalidated1 = documentChangesInvalidatedMapper.getDocumentChangesInvalidated(documentChangesInvalidated);
return CommonPage.restPage(documentChangesInvalidated1);
}
@Override
@Transactional
public CommonResult saveDocumentChangesInvalidated(DocumentChangesInvalidated documentChangesInvalidated) {
int i = 0;
if (documentChangesInvalidated.getId() == null){
documentChangesInvalidated.setCreateBy(SecurityUtils.getUsername());
documentChangesInvalidated.setCreateTime(LocalDateTime.now());
i = documentChangesInvalidatedMapper.insert(documentChangesInvalidated);
}else {
documentChangesInvalidated.setUpdateTime(LocalDateTime.now());
documentChangesInvalidated.setUpdateBy(SecurityUtils.getUsername());
i = documentChangesInvalidatedMapper.updateById(documentChangesInvalidated);
}
if (i > 0){
batchSave(documentChangesInvalidated.getId(), documentChangesInvalidated.getDocumentChangesInvalidatedEvaluateList()
, documentChangesInvalidated.getDocumentChangesInvalidatedIssueList(),documentChangesInvalidated.getDelEvaluateIds(),documentChangesInvalidated.getDelInvalidatedIssueIds());
}
return i > 0 ? CommonResult.success() : CommonResult.failed();
}
private void batchSave(Long id, List documentChangesInvalidatedEvaluates,
List documentChangesInvalidatedIssues,
List delEvaluateIds, List delInvalidatedIssueIds) {
if (ObjectUtils.isNotEmpty(delEvaluateIds)){
int update = documentChangesInvalidatedEvaluateMapper.update(new DocumentChangesInvalidatedEvaluate(),
new LambdaUpdateWrapper().set(DocumentChangesInvalidatedEvaluate::getDelFlag, UserConstant.DEPT_DISABLE)
.set(DocumentChangesInvalidatedEvaluate::getUpdateTime, LocalDateTime.now()).set(DocumentChangesInvalidatedEvaluate::getUpdateBy, SecurityUtils.getUsername())
.in(DocumentChangesInvalidatedEvaluate::getId, delEvaluateIds)
);
}
if (ObjectUtils.isNotEmpty(delInvalidatedIssueIds)){
int update = documentChangesInvalidatedIssueMapper.update(new DocumentChangesInvalidatedIssue(),
new LambdaUpdateWrapper().set(DocumentChangesInvalidatedIssue::getDelFlag, UserConstant.DEPT_DISABLE)
.set(DocumentChangesInvalidatedIssue::getUpdateTime, LocalDateTime.now()).set(DocumentChangesInvalidatedIssue:: getUpdateBy, SecurityUtils.getUsername())
.in(DocumentChangesInvalidatedIssue::getId, delInvalidatedIssueIds)
);
}
if (ObjectUtils.isNotEmpty(documentChangesInvalidatedIssues)){
documentChangesInvalidatedIssues.forEach(documentChangesInvalidatedIssue -> {
if (documentChangesInvalidatedIssue.getId() == null){
documentChangesInvalidatedIssue.setDocumentChangesId(id);
documentChangesInvalidatedIssue.setCreateTime(LocalDateTime.now());
documentChangesInvalidatedIssue.setCreateBy(SecurityUtils.getUsername());
documentChangesInvalidatedIssueMapper.insert(documentChangesInvalidatedIssue);
}else {
documentChangesInvalidatedIssue.setUpdateTime(LocalDateTime.now());
documentChangesInvalidatedIssue.setUpdateBy(SecurityUtils.getUsername());
documentChangesInvalidatedIssueMapper.updateById(documentChangesInvalidatedIssue);
}
});
}
if (ObjectUtils.isNotEmpty(documentChangesInvalidatedEvaluates)){
documentChangesInvalidatedEvaluates.forEach(documentChangesInvalidatedEvaluate -> {
if (documentChangesInvalidatedEvaluate.getId() == null){
documentChangesInvalidatedEvaluate.setDocumentChangesId(id);
documentChangesInvalidatedEvaluate.setCreateTime(LocalDateTime.now());
documentChangesInvalidatedEvaluate.setCreateBy(SecurityUtils.getUsername());
documentChangesInvalidatedEvaluateMapper.insert(documentChangesInvalidatedEvaluate);
}else {
documentChangesInvalidatedEvaluate.setUpdateTime(LocalDateTime.now());
documentChangesInvalidatedEvaluate.setUpdateBy(SecurityUtils.getUsername());
documentChangesInvalidatedEvaluateMapper.updateById(documentChangesInvalidatedEvaluate);
}
});
}
}
@Override
public CommonResult getDocumentChangesInvalidated(Long id) {
DocumentChangesInvalidated documentChangesInvalidated = documentChangesInvalidatedMapper.selectById(id);
if (documentChangesInvalidated != null){
List documentChangesInvalidatedIssues = documentChangesInvalidatedIssueMapper.selectList(new LambdaQueryWrapper<>(DocumentChangesInvalidatedIssue.class)
.eq(DocumentChangesInvalidatedIssue::getDocumentChangesId, id)
.eq(DocumentChangesInvalidatedIssue::getDelFlag, UserConstant.ENABLE).orderByAsc(DocumentChangesInvalidatedIssue::getSort));
documentChangesInvalidated.setDocumentChangesInvalidatedIssueList(documentChangesInvalidatedIssues);
documentChangesInvalidated.setDocumentChangesInvalidatedEvaluateList(documentChangesInvalidatedEvaluateMapper.selectList(new LambdaQueryWrapper<>(DocumentChangesInvalidatedEvaluate.class).eq(DocumentChangesInvalidatedEvaluate::getDocumentChangesId, id)
.eq(DocumentChangesInvalidatedEvaluate::getDelFlag, UserConstant.ENABLE).orderByAsc(DocumentChangesInvalidatedEvaluate::getSort)));
}
return CommonResult.success(documentChangesInvalidated);
}
@Override
@Transactional
public CommonResult deletedDocumentChangesInvalidated(Long id) {
int i = documentChangesInvalidatedMapper.update(new DocumentChangesInvalidated(),
new LambdaUpdateWrapper().set(DocumentChangesInvalidated::getDelFlag, UserConstant.DEPT_DISABLE)
.set(DocumentChangesInvalidated::getUpdateTime, LocalDateTime.now()).set(DocumentChangesInvalidated::getUpdateBy, SecurityUtils.getUsername())
.eq(DocumentChangesInvalidated::getId, id)
);
if (i > 0){
documentChangesInvalidatedIssueMapper.update(new DocumentChangesInvalidatedIssue(),
new LambdaUpdateWrapper().set(DocumentChangesInvalidatedIssue::getDelFlag, UserConstant.DEPT_DISABLE)
.set(DocumentChangesInvalidatedIssue::getUpdateTime, LocalDateTime.now()).set(DocumentChangesInvalidatedIssue::getUpdateBy, SecurityUtils.getUsername())
.eq(DocumentChangesInvalidatedIssue::getDocumentChangesId, id)
);
documentChangesInvalidatedEvaluateMapper.update(new DocumentChangesInvalidatedEvaluate(),
new LambdaUpdateWrapper().set(DocumentChangesInvalidatedEvaluate::getDelFlag, UserConstant.DEPT_DISABLE)
.set(DocumentChangesInvalidatedEvaluate::getUpdateTime, LocalDateTime.now()).set(DocumentChangesInvalidatedEvaluate::getUpdateBy, SecurityUtils.getUsername())
.eq(DocumentChangesInvalidatedEvaluate::getDocumentChangesId, id)
);
}
return CommonResult.success();
}
}