【草稿同名检验、发布同名检验】

This commit is contained in:
weizhihong 2022-09-02 16:48:43 +08:00
parent 2486637175
commit 84955a996b
2 changed files with 13 additions and 12 deletions

View File

@ -9,6 +9,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
/**
@ -18,7 +19,7 @@ import java.util.List;
@Slf4j
public class Training2DraftPublishService {
@Autowired
private DraftTraining2DAO trainingDao;
private DraftTraining2DAO trainingDao;
@Autowired
private PublishedTraining2DAO publishedDao;
@ -26,22 +27,22 @@ public class Training2DraftPublishService {
* 草稿发布
*/
@Transactional(rollbackFor = Exception.class)
public void draftPublish(TrainingDraftPublishReqVo req,Long userId){
Long draftId=Long.valueOf(req.getDraftId());
DraftTraining2Example dtExample=new DraftTraining2Example();
public void draftPublish(TrainingDraftPublishReqVo req, Long userId) {
Long draftId = Long.valueOf(req.getDraftId());
DraftTraining2Example dtExample = new DraftTraining2Example();
dtExample.createCriteria().andCreatorIdEqualTo(userId).andIdEqualTo(draftId);
List<DraftTraining2WithBLOBs> dtFinds= this.trainingDao.selectByExampleWithBLOBs(dtExample);
BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertTrue(null!=dtFinds&&!dtFinds.isEmpty(),"实训草稿不存在");
DraftTraining2WithBLOBs draft = dtFinds.get(0);
List<DraftTraining2WithBLOBs> dtFinds = this.trainingDao.selectByExampleWithBLOBs(dtExample);
BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertTrue(null != dtFinds && !dtFinds.isEmpty(), "实训草稿不存在");
DraftTraining2WithBLOBs draft = dtFinds.get(0);
//
PublishedTraining2WithBLOBs pub = Training2Convertor.convertFrom(draft);
//根据要发布的草稿名称来查找已发布的实训
//如果以有同名的则会被覆盖
PublishedTraining2Example ptExample=new PublishedTraining2Example();
ptExample.createCriteria().andNameEqualTo(draft.getName());
List<PublishedTraining2> ptFinds= this.publishedDao.selectByExample(ptExample);
PublishedTraining2Example ptExample = new PublishedTraining2Example();
ptExample.createCriteria().andNameEqualTo(draft.getName()).andMapIdEqualTo(draft.getMapId());
List<PublishedTraining2> ptFinds = this.publishedDao.selectByExample(ptExample);
//
if(null!=ptFinds&&!ptFinds.isEmpty()){//已发布实训存在时则直接删除
if (null != ptFinds && !ptFinds.isEmpty()) {//已发布实训存在时则直接删除
this.publishedDao.deleteByExample(ptExample);
}
//发布

View File

@ -54,7 +54,7 @@ public class Training2DraftService {
public CreateTraining2RspVo createTraining(CreateTraining2ReqVo req, AccountVO user) {
//校验是否已经有同名的实训
DraftTraining2Example example = new DraftTraining2Example();
example.createCriteria().andCreatorIdEqualTo(user.getId()).andNameEqualTo(req.getName());
example.createCriteria().andCreatorIdEqualTo(user.getId()).andNameEqualTo(req.getName()).andMapIdEqualTo(req.getMapId());
List<DraftTraining2> check = this.trainingDao.selectByExample(example);
BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertCollectionEmpty(check, "实训已经存在");
//