删除自己的实训数据,出现共享数据不能删除的错误

This commit is contained in:
tiger_zhou 2023-09-27 17:53:59 +08:00
parent 813d13d768
commit f6021e9a2d
1 changed files with 393 additions and 387 deletions

View File

@ -35,162 +35,163 @@ import java.util.stream.Collectors;
@Service
@Slf4j
public class Training2PublishService {
@Autowired
private PublishedTraining2DAO publishedDao;
@Autowired
private IMapService mapService;
@Transactional(readOnly = true)
public PublishedTraining2 findById(Long id) {
PublishedTraining2Example example = new PublishedTraining2Example();
example.createCriteria().andIdEqualTo(id);
List<PublishedTraining2> find = this.publishedDao.selectByExample(example);
return null != find && find.size() > 0 ? find.get(0) : null;
@Autowired
private PublishedTraining2DAO publishedDao;
@Autowired
private IMapService mapService;
@Transactional(readOnly = true)
public PublishedTraining2 findById(Long id) {
PublishedTraining2Example example = new PublishedTraining2Example();
example.createCriteria().andIdEqualTo(id);
List<PublishedTraining2> find = this.publishedDao.selectByExample(example);
return null != find && find.size() > 0 ? find.get(0) : null;
}
/**
* 根据组织类型单操作实操标签获取对应的数量
*/
public Long queryCountForLabel(FindCountForQuestionReqVo reqVo) {
if (Objects.isNull(reqVo.getTrainingClient())) {
//单操没有选定客户端不查询数量
return 0L;
}
PublishedTraining2Example example = new PublishedTraining2Example();
PublishedTraining2Example.Criteria c = this.basicQueryCriteria(example, reqVo.getMapId(), reqVo.getOrgId(), reqVo.getSubType().name().toUpperCase(), Arrays.asList(reqVo.getTags()),
reqVo.getTrainingClient());
return this.publishedDao.countByExample(example);
}
/**
* 根据组织类型单操作实操标签获取对应的数量
*/
public Long queryCountForLabel(FindCountForQuestionReqVo reqVo){
if(Objects.isNull(reqVo.getTrainingClient())){
//单操没有选定客户端不查询数量
return 0L;
}
PublishedTraining2Example example = new PublishedTraining2Example();
PublishedTraining2Example.Criteria c = this.basicQueryCriteria(example,reqVo.getMapId(),reqVo.getOrgId(),reqVo.getSubType().name().toUpperCase(),Arrays.asList(reqVo.getTags()),reqVo.getTrainingClient());
return this.publishedDao.countByExample(example);
/**
* 根据 组织类型单操作实操 获取标签
*/
public Collection<String> findAllLabel(Long mapId, Long orgId, String type, PaperQType.TrainingClient client) {
PublishedTraining2Example example = new PublishedTraining2Example();
PublishedTraining2Example.Criteria c = this.basicQueryCriteria(example, mapId, orgId, type, null, client);
List<PublishedTraining2> dataList = this.publishedDao.selectByExample(example);
if (CollectionUtils.isEmpty(dataList)) {
return Collections.emptyList();
}
return dataList.stream().map(PublishedTraining2::getLabelJson).filter(StringUtils::hasText).map(d -> {
List<String> l = JsonUtils.readCollection(d, List.class, String.class);
return l;
}).flatMap(Collection::stream).collect(Collectors.toSet());
}
/**
* 根据 组织类型单操作实操 获取标签
*/
public Collection<String> findAllLabel(Long mapId, Long orgId, String type, PaperQType.TrainingClient client){
PublishedTraining2Example example = new PublishedTraining2Example();
PublishedTraining2Example.Criteria c = this.basicQueryCriteria(example,mapId,orgId,type,null,client);
List<PublishedTraining2> dataList = this.publishedDao.selectByExample(example);
if(CollectionUtils.isEmpty(dataList)){
return Collections.emptyList();
}
return dataList.stream().map(PublishedTraining2::getLabelJson).filter(StringUtils::hasText).map(d->{
List<String> l = JsonUtils.readCollection(d,List.class,String.class);
return l;
}).flatMap(Collection::stream).collect(Collectors.toSet());
public PublishedTraining2Example.Criteria basicQueryCriteria(PublishedTraining2Example example, Long mapId, Long orgId, String type, List<String> lables, PaperQType.TrainingClient client) {
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(Objects.nonNull(mapId), "请关联对应的线路");
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(Objects.nonNull(orgId), "组织信息不能为空");
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(Objects.nonNull(type), "查询类型信息不能为空");
PublishedTraining2Example.Criteria criteria = example.createCriteria();
criteria.andMapIdEqualTo(mapId);
criteria.andOrgIdEqualTo(orgId);
criteria.andTypeEqualTo(type);
criteria.andStateEqualTo(BusinessConsts.STATUS_USE_INT);//上架
//查询共享的数据
PublishedTraining2Example.Criteria or = example.or();
or.andSharedEqualTo(BusinessConsts.STATUS_USE_INT);
or.andMapIdEqualTo(mapId);
or.andTypeEqualTo(type);
or.andStateEqualTo(BusinessConsts.STATUS_USE_INT);
if (Objects.nonNull(client)) {
criteria.andClientEqualTo(client.name());
or.andClientEqualTo(client.name());
}
public PublishedTraining2Example.Criteria basicQueryCriteria(PublishedTraining2Example example, Long mapId, Long orgId, String type, List<String> lables, PaperQType.TrainingClient client){
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(Objects.nonNull(mapId),"请关联对应的线路");
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(Objects.nonNull(orgId),"组织信息不能为空");
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(Objects.nonNull(type),"查询类型信息不能为空");
PublishedTraining2Example.Criteria criteria = example.createCriteria();
criteria.andMapIdEqualTo(mapId);
criteria.andOrgIdEqualTo(orgId);
criteria.andTypeEqualTo(type);
criteria.andStateEqualTo(BusinessConsts.STATUS_USE_INT);//上架
//查询共享的数据
PublishedTraining2Example.Criteria or = example.or();
or.andSharedEqualTo(BusinessConsts.STATUS_USE_INT);
or.andMapIdEqualTo(mapId);
or.andTypeEqualTo(type);
or.andStateEqualTo(BusinessConsts.STATUS_USE_INT);
if(Objects.nonNull(client)){
criteria.andClientEqualTo(client.name());
or.andClientEqualTo(client.name());
}
// or.andOrgIdNotEqualTo(orgId);
if(!CollectionUtils.isEmpty(lables)){
for (String tag : lables) {
if(StringUtils.hasText(tag)){
criteria.andLabelJsonLike(String.format("%%%s%%", tag));
or.andLabelJsonLike(String.format("%%%s%%", tag));
}
}
if (!CollectionUtils.isEmpty(lables)) {
for (String tag : lables) {
if (StringUtils.hasText(tag)) {
criteria.andLabelJsonLike(String.format("%%%s%%", tag));
or.andLabelJsonLike(String.format("%%%s%%", tag));
}
return criteria;
}
}
return criteria;
}
/**
* 已发布实训分页列表
*/
@Transactional(readOnly = true)
public PageVO<PublishedTraining2InfoRspVo> publishedTrainingsPage(PublishedTraining2InfoPageReqVo req) {
PageHelper.startPage(req.getPageNum(), req.getPageSize());
PublishedTraining2Example example = new PublishedTraining2Example();
PublishedTraining2Example.Criteria c = example.createCriteria();
if (Objects.nonNull(req.getState())) {
c.andStateEqualTo(req.getState());
}
if (Objects.nonNull(req.getOrgId())) {
c.andOrgIdEqualTo(req.getOrgId());
}
if (Objects.nonNull(req.getMapId())) {
c.andMapIdEqualTo(req.getMapId());
}
if (Objects.nonNull(req.getMapId())) {
c.andMapIdEqualTo(req.getMapId());
}
if (Objects.nonNull(req.getType())) {
c.andTypeEqualTo(req.getType());
}
if (StringUtils.hasText(req.getName())) {
c.andNameLike(String.format("%%%s%%", req.getName()));
}
if (Objects.equals(false, CollectionUtils.isEmpty(req.getLabelLikes()))) {
for (String ll : req.getLabelLikes()) {
c.andLabelJsonLike(String.format("%%%s%%", ll));
}
}
String orderBy = "create_time";
switch (req.getOrderBy()) {
/**
* 已发布实训分页列表
*/
@Transactional(readOnly = true)
public PageVO<PublishedTraining2InfoRspVo> publishedTrainingsPage(PublishedTraining2InfoPageReqVo req) {
PageHelper.startPage(req.getPageNum(), req.getPageSize());
PublishedTraining2Example example = new PublishedTraining2Example();
PublishedTraining2Example.Criteria c = example.createCriteria();
if (Objects.nonNull(req.getState())) {
c.andStateEqualTo(req.getState());
}
if (Objects.nonNull(req.getOrgId())) {
c.andOrgIdEqualTo(req.getOrgId());
}
if (Objects.nonNull(req.getMapId())) {
c.andMapIdEqualTo(req.getMapId());
}
if (Objects.nonNull(req.getMapId())) {
c.andMapIdEqualTo(req.getMapId());
}
if (Objects.nonNull(req.getType())) {
c.andTypeEqualTo(req.getType());
}
if (StringUtils.hasText(req.getName())) {
c.andNameLike(String.format("%%%s%%", req.getName()));
}
if (Objects.equals(false, CollectionUtils.isEmpty(req.getLabelLikes()))) {
for (String ll : req.getLabelLikes()) {
c.andLabelJsonLike(String.format("%%%s%%", ll));
}
}
String orderBy = "create_time";
switch (req.getOrderBy()) {
// case 1:orderBy="create_time";break;
case 2:
orderBy = "update_time";
break;
case 3:
orderBy = "name";
break;
case 4:
orderBy = "state";
break;
}
if (req.getDesc()) {
example.setOrderByClause(String.format(" %s desc", orderBy));
}
Page<PublishedTraining2> page = (Page<PublishedTraining2>) this.publishedDao.selectByExample(example);
List<PublishedTraining2InfoRspVo> tmpList = Training2Convertor.convertFrom(page.getResult());
return PageVO.convert(page, tmpList);
case 2:
orderBy = "update_time";
break;
case 3:
orderBy = "name";
break;
case 4:
orderBy = "state";
break;
}
if (req.getDesc()) {
example.setOrderByClause(String.format(" %s desc", orderBy));
}
Page<PublishedTraining2> page = (Page<PublishedTraining2>) this.publishedDao.selectByExample(example);
List<PublishedTraining2InfoRspVo> tmpList = Training2Convertor.convertFrom(page.getResult());
/**
* 已发布实训上架
*/
@Transactional(rollbackFor = Exception.class)
public PutOnPublishedTraining2RspVo putOnPublishedTrainings(PutOnPublishedTraining2ReqVo req,LoginUserInfoVO userInfoVO) {
final PutOnPublishedTraining2RspVo rsp = new PutOnPublishedTraining2RspVo();
rsp.setIds(new ArrayList<>());
if(CollectionUtils.isEmpty(req.getIds())){
return rsp;
}
List<Long> newIds = this.pretreatmentFindData(req.getIds(),userInfoVO);
for (Long newId : newIds) {
PublishedTraining2WithBLOBs pub = new PublishedTraining2WithBLOBs();
pub.setId(newId);
pub.setState(PublishedTraining2StateEnum.PutOn.getState());
pub.setUpdateTime(LocalDateTime.now());
//
PublishedTraining2Example example = new PublishedTraining2Example();
example.createCriteria().andIdEqualTo(pub.getId());
//
int urt = this.publishedDao.updateByExampleSelective(pub, example);
if (urt > 0) {//记录更新成功的
rsp.getIds().add(newId.toString());
}
}
return PageVO.convert(page, tmpList);
}
/**
* 已发布实训上架
*/
@Transactional(rollbackFor = Exception.class)
public PutOnPublishedTraining2RspVo putOnPublishedTrainings(PutOnPublishedTraining2ReqVo req, LoginUserInfoVO userInfoVO) {
final PutOnPublishedTraining2RspVo rsp = new PutOnPublishedTraining2RspVo();
rsp.setIds(new ArrayList<>());
if (CollectionUtils.isEmpty(req.getIds())) {
return rsp;
}
List<Long> newIds = this.pretreatmentFindData(req.getIds(), userInfoVO);
for (Long newId : newIds) {
PublishedTraining2WithBLOBs pub = new PublishedTraining2WithBLOBs();
pub.setId(newId);
pub.setState(PublishedTraining2StateEnum.PutOn.getState());
pub.setUpdateTime(LocalDateTime.now());
//
PublishedTraining2Example example = new PublishedTraining2Example();
example.createCriteria().andIdEqualTo(pub.getId());
//
int urt = this.publishedDao.updateByExampleSelective(pub, example);
if (urt > 0) {//记录更新成功的
rsp.getIds().add(newId.toString());
}
}
/* req.getIds().forEach(id -> {
PublishedTraining2WithBLOBs pub = new PublishedTraining2WithBLOBs();
pub.setId(Long.valueOf(id));
@ -205,116 +206,119 @@ public class Training2PublishService {
rsp.getIds().add(id);
}
});*/
return rsp;
return rsp;
}
public void changeSharedStatus(Long id, Integer shared, LoginUserInfoVO userInfoVO) {
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(Objects.nonNull(id), "id信息不能为空");
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(Objects.nonNull(shared), "未知共享类型");
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(shared == BusinessConsts.STATUS_USE_INT || shared == BusinessConsts.STATUS_NOT_USE_INT, "未知共享类型");
}
/**
* 已发布实训下架
*/
@Transactional(rollbackFor = Exception.class)
public PullOffPublishedTraining2RspVo pullOffPublishedTrainings(PullOffPublishedTraining2ReqVo req, LoginUserInfoVO userInfoVO) {
final PullOffPublishedTraining2RspVo rsp = new PullOffPublishedTraining2RspVo();
rsp.setIds(new ArrayList<>());
if (CollectionUtils.isEmpty(req.getIds())) {
return rsp;
}
List<Long> newIds = this.pretreatmentFindData(req.getIds(), userInfoVO);
for (Long newId : newIds) {
PublishedTraining2WithBLOBs pub = new PublishedTraining2WithBLOBs();
pub.setId(newId);
pub.setState(PublishedTraining2StateEnum.PullOff.getState());
pub.setUpdateTime(LocalDateTime.now());
//
PublishedTraining2Example example = new PublishedTraining2Example();
example.createCriteria().andIdEqualTo(pub.getId());
//
int urt = this.publishedDao.updateByExampleSelective(pub, example);
if (urt > 0) {//记录更新成功的
rsp.getIds().add(newId.toString());
}
}
public void changeSharedStatus(Long id ,Integer shared,LoginUserInfoVO userInfoVO){
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(Objects.nonNull(id),"id信息不能为空");
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(Objects.nonNull(shared),"未知共享类型");
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(shared == BusinessConsts.STATUS_USE_INT || shared == BusinessConsts.STATUS_NOT_USE_INT,"未知共享类型");
return rsp;
}
/**
* 删除已发布实训
*/
@Transactional(rollbackFor = Exception.class)
public DeletePublishedTraining2RspVo deletePublishedTrainings(DeletePublishedTraining2ReqVo req, LoginUserInfoVO userInfoVO) {
DeletePublishedTraining2RspVo rsp = new DeletePublishedTraining2RspVo();
rsp.setIds(new ArrayList<>());
if (CollectionUtils.isEmpty(req.getIds())) {
return rsp;
}
/**
* 已发布实训下架
*/
@Transactional(rollbackFor = Exception.class)
public PullOffPublishedTraining2RspVo pullOffPublishedTrainings(PullOffPublishedTraining2ReqVo req,LoginUserInfoVO userInfoVO) {
final PullOffPublishedTraining2RspVo rsp = new PullOffPublishedTraining2RspVo();
rsp.setIds(new ArrayList<>());
if(CollectionUtils.isEmpty(req.getIds())){
return rsp;
}
List<Long> newIds = this.pretreatmentFindData(req.getIds(),userInfoVO);
for (Long newId : newIds) {
PublishedTraining2WithBLOBs pub = new PublishedTraining2WithBLOBs();
pub.setId(newId);
pub.setState(PublishedTraining2StateEnum.PullOff.getState());
pub.setUpdateTime(LocalDateTime.now());
//
PublishedTraining2Example example = new PublishedTraining2Example();
example.createCriteria().andIdEqualTo(pub.getId());
//
int urt = this.publishedDao.updateByExampleSelective(pub, example);
if (urt > 0) {//记录更新成功的
rsp.getIds().add(newId.toString());
}
}
return rsp;
List<Long> newIds = this.pretreatmentFindData(req.getIds(), userInfoVO);
for (Long newId : newIds) {
int drt = this.publishedDao.deleteByPrimaryKey(newId);
if (drt > 0) {
rsp.getIds().add(newId.toString());
}
}
/**
* 删除已发布实训
*/
@Transactional(rollbackFor = Exception.class)
public DeletePublishedTraining2RspVo deletePublishedTrainings(DeletePublishedTraining2ReqVo req, LoginUserInfoVO userInfoVO) {
DeletePublishedTraining2RspVo rsp = new DeletePublishedTraining2RspVo();
rsp.setIds(new ArrayList<>());
if(CollectionUtils.isEmpty(req.getIds())){
return rsp;
}
List<Long> newIds = this.pretreatmentFindData(req.getIds(),userInfoVO);
for (Long newId : newIds) {
int drt = this.publishedDao.deleteByPrimaryKey(newId);
if (drt > 0) {
rsp.getIds().add(newId.toString());
}
}
/*req.getIds().forEach(id -> {
int drt = this.publishedDao.deleteByPrimaryKey(Long.valueOf(id));
if (drt > 0) {
rsp.getIds().add(id);
}
});*/
//
return rsp;
}
//
return rsp;
}
private List<Long> pretreatmentFindData(List<String> ids, LoginUserInfoVO userInfoVO){
PublishedTraining2Example example = new PublishedTraining2Example();
PublishedTraining2Example.Criteria criteria = example.createCriteria();
List<Long> idLong = ids.stream().map(Long::valueOf).collect(Collectors.toList());
criteria.andIdIn(idLong);
List<PublishedTraining2> t2 = this.publishedDao.selectByExample(example);
List<PublishedTraining2> notExeList = t2.stream().filter(d->Objects.equals(d.getOrgId(),userInfoVO.getTopOrgId())).collect(Collectors.toList());
if(!CollectionUtils.isEmpty(notExeList)){
String names = notExeList.stream().map(d->d.getName()).collect(Collectors.joining(","));
BusinessExceptionAssertEnum.DATA_ERROR.assertTrue(false,String.format("共享数据[%s]不能删除",names));
}
List<Long> findIds = t2.stream()
.filter(d->Objects.equals(d.getOrgId(),userInfoVO.getTopOrgId()))
.map(d->d.getId()).collect(Collectors.toList());
return findIds;
private List<Long> pretreatmentFindData(List<String> ids, LoginUserInfoVO userInfoVO) {
PublishedTraining2Example example = new PublishedTraining2Example();
PublishedTraining2Example.Criteria criteria = example.createCriteria();
List<Long> idLong = ids.stream().map(Long::valueOf).collect(Collectors.toList());
criteria.andIdIn(idLong);
List<PublishedTraining2> t2 = this.publishedDao.selectByExample(example);
List<PublishedTraining2> notExeList = t2.stream().filter(d -> Objects.equals(d.getOrgId(), userInfoVO.getTopOrgId()) && d.getCreatorId() != userInfoVO.getAccountVO().getId())
.collect(Collectors.toList());
if (!CollectionUtils.isEmpty(notExeList)) {
String names = notExeList.stream().map(d -> d.getName()).collect(Collectors.joining(","));
BusinessExceptionAssertEnum.DATA_ERROR.assertTrue(false, String.format("共享数据[%s]不能删除", names));
}
private PublishedTraining2Example.Criteria createQueryOrExample(PublishedTraining2Example example , PublishedTrainingListRspVo reqVO,List<Long> mapIdList){
List<Long> findIds = t2.stream()
.filter(d -> Objects.equals(d.getOrgId(), userInfoVO.getTopOrgId()))
.map(d -> d.getId()).collect(Collectors.toList());
return findIds;
}
PublishedTraining2Example.Criteria criteria = example.createCriteria();
private PublishedTraining2Example.Criteria createQueryOrExample(PublishedTraining2Example example, PublishedTrainingListRspVo reqVO, List<Long> mapIdList) {
PublishedTraining2Example.Criteria criteria = example.createCriteria();
// PublishedTraining2Example.Criteria or = example.or();
if (reqVO.getMapId() != null) {
criteria.andMapIdEqualTo(reqVO.getMapId());
}else{
criteria.andMapIdIn(mapIdList);
}
if (reqVO.getType() != null) {
criteria.andTypeEqualTo(reqVO.getType().value());
}
if(StringUtils.hasText(reqVO.getName())){
criteria.andNameLike(String.format("%%%s%%", reqVO.getName()));
}
if(Objects.nonNull(reqVO.getState())){
criteria.andStateEqualTo(reqVO.getState());
}
if(!CollectionUtils.isEmpty(reqVO.getLabels())){
for (String label : reqVO.getLabels()) {
criteria.andLabelJsonLike(String.format("%%%s%%", label));
}
}
if (reqVO.getOrgId() != null) {
criteria.andOrgIdEqualTo(reqVO.getOrgId());
}
return criteria;
if (reqVO.getMapId() != null) {
criteria.andMapIdEqualTo(reqVO.getMapId());
} else {
criteria.andMapIdIn(mapIdList);
}
if (reqVO.getType() != null) {
criteria.andTypeEqualTo(reqVO.getType().value());
}
if (StringUtils.hasText(reqVO.getName())) {
criteria.andNameLike(String.format("%%%s%%", reqVO.getName()));
}
if (Objects.nonNull(reqVO.getState())) {
criteria.andStateEqualTo(reqVO.getState());
}
if (!CollectionUtils.isEmpty(reqVO.getLabels())) {
for (String label : reqVO.getLabels()) {
criteria.andLabelJsonLike(String.format("%%%s%%", label));
}
}
if (reqVO.getOrgId() != null) {
criteria.andOrgIdEqualTo(reqVO.getOrgId());
}
return criteria;
}
/* private PublishedTraining2Example.Criteria createQueryExample(PublishedTraining2Example example ,PublishedTrainingListRspVo reqVO){
PublishedTraining2Example.Criteria criteria = example.createCriteria();
@ -341,175 +345,177 @@ public class Training2PublishService {
return criteria;
}*/
public PageVO<PublishedTraining2InfoRspVo> findTrainingInfoForPage(PublishedTrainingListRspVo reqVO,LoginUserInfoVO userInfoVO,boolean findSharedData){
List<MapVO> mapVOS = this.mapService.listMapsOfUser(userInfoVO);
List<Long> mapIdList = mapVOS.stream().map(d->d.getId()).collect(Collectors.toList());
public PageVO<PublishedTraining2InfoRspVo> findTrainingInfoForPage(PublishedTrainingListRspVo reqVO, LoginUserInfoVO userInfoVO, boolean findSharedData) {
List<MapVO> mapVOS = this.mapService.listMapsOfUser(userInfoVO);
List<Long> mapIdList = mapVOS.stream().map(d -> d.getId()).collect(Collectors.toList());
PublishedTraining2Example example = new PublishedTraining2Example();
PublishedTraining2Example.Criteria criteria = this.createQueryOrExample(example,reqVO,mapIdList);
if(findSharedData){
PublishedTraining2Example.Criteria or = example.or();
or.andStateEqualTo(BusinessConsts.STATUS_USE_INT).andSharedEqualTo(BusinessConsts.STATUS_USE_INT);
if (reqVO.getType() != null) {
or.andTypeEqualTo(reqVO.getType().value());
}
if(Objects.isNull(reqVO.getMapId())){
or.andMapIdIn(mapIdList);
}else{
or.andMapIdEqualTo(reqVO.getMapId());
}
PublishedTraining2Example example = new PublishedTraining2Example();
PublishedTraining2Example.Criteria criteria = this.createQueryOrExample(example, reqVO, mapIdList);
if (findSharedData) {
PublishedTraining2Example.Criteria or = example.or();
or.andStateEqualTo(BusinessConsts.STATUS_USE_INT).andSharedEqualTo(BusinessConsts.STATUS_USE_INT);
if (reqVO.getType() != null) {
or.andTypeEqualTo(reqVO.getType().value());
}
if (Objects.isNull(reqVO.getMapId())) {
or.andMapIdIn(mapIdList);
} else {
or.andMapIdEqualTo(reqVO.getMapId());
}
// if(Objects.nonNull(reqVO.getOrgId())){
// or.andOrgIdNotEqualTo(reqVO.getOrgId());
// }
}
PageHelper.startPage(reqVO.getPageNum(), reqVO.getPageSize());
Page<PublishedTraining2> page = (Page<PublishedTraining2>)this.publishedDao.selectByExample(example);
if(page.isEmpty()){
return PageVO.convert(page,Collections.emptyList());
}
return PageVO.convert(page,Training2Convertor.convertFrom(page.getResult()));
}
PageHelper.startPage(reqVO.getPageNum(), reqVO.getPageSize());
Page<PublishedTraining2> page = (Page<PublishedTraining2>) this.publishedDao.selectByExample(example);
if (page.isEmpty()) {
return PageVO.convert(page, Collections.emptyList());
}
return PageVO.convert(page, Training2Convertor.convertFrom(page.getResult()));
}
/**
* 根据地图ID和类型查询实训列表
*/
public List<PublishedTraining2InfoRspVo> findTrainingInfo(PublishedTrainingListRspVo reqVO,LoginUserInfoVO userInfoVO) {
List<MapVO> mapVOS = this.mapService.listMapsOfUser(userInfoVO);
List<Long> mapIdList = mapVOS.stream().map(d->d.getId()).collect(Collectors.toList());
/**
* 根据地图ID和类型查询实训列表
*/
public List<PublishedTraining2InfoRspVo> findTrainingInfo(PublishedTrainingListRspVo reqVO, LoginUserInfoVO userInfoVO) {
List<MapVO> mapVOS = this.mapService.listMapsOfUser(userInfoVO);
List<Long> mapIdList = mapVOS.stream().map(d -> d.getId()).collect(Collectors.toList());
PublishedTraining2Example example = new PublishedTraining2Example();
this.createQueryOrExample(example,reqVO,mapIdList);
PublishedTraining2Example.Criteria or = example.or();
or.andStateEqualTo(BusinessConsts.STATUS_USE_INT).andSharedEqualTo(BusinessConsts.STATUS_USE_INT);
or.andMapIdEqualTo(reqVO.getMapId());
if (reqVO.getType() != null) {
or.andTypeEqualTo(reqVO.getType().value());
}
PublishedTraining2Example example = new PublishedTraining2Example();
this.createQueryOrExample(example, reqVO, mapIdList);
PublishedTraining2Example.Criteria or = example.or();
or.andStateEqualTo(BusinessConsts.STATUS_USE_INT).andSharedEqualTo(BusinessConsts.STATUS_USE_INT);
or.andMapIdEqualTo(reqVO.getMapId());
if (reqVO.getType() != null) {
or.andTypeEqualTo(reqVO.getType().value());
}
// if(reqVO.getOrgId() !=null){
// or.andOrgIdNotEqualTo(reqVO.getOrgId());
// }
List<PublishedTraining2> list = this.publishedDao.selectByExample(example);
if (CollectionUtils.isEmpty(list)) {
return List.of();
} else {
return list.stream().map(Training2Convertor::convertFrom).collect(Collectors.toList());
}
List<PublishedTraining2> list = this.publishedDao.selectByExample(example);
if (CollectionUtils.isEmpty(list)) {
return List.of();
} else {
return list.stream().map(Training2Convertor::convertFrom).collect(Collectors.toList());
}
}
/**
* 根据已发布实训的id来查询实现的所有信息
*/
@Transactional(readOnly = true)
public PublishedTraining2DetailRspVo findTrainingAllInfoById(Long trainingId) {
PublishedTraining2WithBLOBs b = this.publishedDao.selectByPrimaryKey(trainingId);
if (null != b) {
PublishedTraining2DetailRspVo rsp = new PublishedTraining2DetailRspVo();
//
rsp.setDescription(b.getDescription());
rsp.setFailureConditionJson(b.getFailureConditionJson());
rsp.setCreateTime(b.getCreateTime());
rsp.setCreatorId(b.getCreatorId());
rsp.setLabelJson(b.getLabelJson());
rsp.setMapId(b.getMapId());
rsp.setName(b.getName());
rsp.setId(b.getId());
rsp.setType(b.getType());
rsp.setBgSceneJson(b.getBgSceneJson());
rsp.setMemberJson(b.getMemberJson());
rsp.setOperaJson(b.getOperaJson());
rsp.setStepJson(b.getStepJson());
rsp.setUpdateTime(b.getUpdateTime());
rsp.setPlayerIdJson(b.getPlayerIdJson());
rsp.setMapLocationJson(b.getMapLocationJson());
rsp.setRunPlanId(b.getRunPlanId());
rsp.setScoringRuleJson(b.getScoringRuleJson());
rsp.setState(b.getState());
rsp.setClient(b.getClient());
//
return rsp;
}
return null;
/**
* 根据已发布实训的id来查询实现的所有信息
*/
@Transactional(readOnly = true)
public PublishedTraining2DetailRspVo findTrainingAllInfoById(Long trainingId) {
PublishedTraining2WithBLOBs b = this.publishedDao.selectByPrimaryKey(trainingId);
if (null != b) {
PublishedTraining2DetailRspVo rsp = new PublishedTraining2DetailRspVo();
//
rsp.setDescription(b.getDescription());
rsp.setFailureConditionJson(b.getFailureConditionJson());
rsp.setCreateTime(b.getCreateTime());
rsp.setCreatorId(b.getCreatorId());
rsp.setLabelJson(b.getLabelJson());
rsp.setMapId(b.getMapId());
rsp.setName(b.getName());
rsp.setId(b.getId());
rsp.setType(b.getType());
rsp.setBgSceneJson(b.getBgSceneJson());
rsp.setMemberJson(b.getMemberJson());
rsp.setOperaJson(b.getOperaJson());
rsp.setStepJson(b.getStepJson());
rsp.setUpdateTime(b.getUpdateTime());
rsp.setPlayerIdJson(b.getPlayerIdJson());
rsp.setMapLocationJson(b.getMapLocationJson());
rsp.setRunPlanId(b.getRunPlanId());
rsp.setScoringRuleJson(b.getScoringRuleJson());
rsp.setState(b.getState());
rsp.setClient(b.getClient());
//
return rsp;
}
return null;
}
/**
* 根据地图ID列表修改生成实训的组织ID
*/
public void updatePublishTrainingOrgIdByMapId(Long orgId, List<Long> mapIdList) {
if (!CollectionUtils.isEmpty(mapIdList)) {
publishedDao.updateTrainingOrgByMapIdList(orgId, mapIdList);
}
/**
* 根据地图ID列表修改生成实训的组织ID
*/
public void updatePublishTrainingOrgIdByMapId(Long orgId, List<Long> mapIdList) {
if (!CollectionUtils.isEmpty(mapIdList)) {
publishedDao.updateTrainingOrgByMapIdList(orgId, mapIdList);
}
}
/**
* 批量更新实训label
*/
public void updateTrainingLabelList(List<PublishedTraining2> publishedTraining2List) {
List<PublishedTraining2> training2List = publishedTraining2List.stream().filter(t -> t.getId() != null).collect(Collectors.toList());
if (CollectionUtils.isEmpty(training2List)) {
return;
}
publishedDao.updateTrainingLabelList(training2List);
/**
* 批量更新实训label
*/
public void updateTrainingLabelList(List<PublishedTraining2> publishedTraining2List) {
List<PublishedTraining2> training2List = publishedTraining2List.stream().filter(t -> t.getId() != null).collect(Collectors.toList());
if (CollectionUtils.isEmpty(training2List)) {
return;
}
publishedDao.updateTrainingLabelList(training2List);
}
/**
* 更新实训label
*/
public void updateTrainingLabel(PublishedTraining2 training2) {
PublishedTraining2WithBLOBs blobs = new PublishedTraining2WithBLOBs();
blobs.setId(training2.getId());
blobs.setLabelJson(training2.getLabelJson());
publishedDao.updateByPrimaryKeySelective(blobs);
}
/**
* 更新实训label
*/
public void updateTrainingLabel(PublishedTraining2 training2) {
PublishedTraining2WithBLOBs blobs = new PublishedTraining2WithBLOBs();
blobs.setId(training2.getId());
blobs.setLabelJson(training2.getLabelJson());
publishedDao.updateByPrimaryKeySelective(blobs);
}
/**
* 导出实训信息
* @param tidList 实训列表
* @return 实训列表
*/
public List<ExportTraining2> exportTraining(List<Long> tidList) {
PublishedTraining2Example example = new PublishedTraining2Example();
example.createCriteria().andIdIn(tidList);
List<PublishedTraining2WithBLOBs> training2WithBLOBsList = publishedDao.selectByExampleWithBLOBs(example);
Map<Long, List<PublishedTraining2WithBLOBs>> mapTrainingMap = training2WithBLOBsList.stream().peek(t -> {
t.setId(null);
t.setUpdateTime(null);
t.setCreateTime(null);
}).collect(Collectors.groupingBy(PublishedTraining2WithBLOBs::getMapId));
// 地图基本信息列表
List<MapInfo> mapInfoList = mapService.queryMapInfoList(new ArrayList<>(mapTrainingMap.keySet()));
Map<Long, MapInfo> mapInfoMap = mapInfoList.stream().collect(Collectors.toMap(MapInfo::getId, m -> m, (o,n) -> n));
List<ExportTraining2> exportTraining2List = new ArrayList<>(mapTrainingMap.size());
mapInfoMap.forEach((k, v) -> {
ExportTraining2 exportData = new ExportTraining2();
exportData.setName(v.getName());
exportData.setLineCode(v.getLineCode());
exportData.setList(mapTrainingMap.get(k));
exportTraining2List.add(exportData);
/**
* 导出实训信息
*
* @param tidList 实训列表
* @return 实训列表
*/
public List<ExportTraining2> exportTraining(List<Long> tidList) {
PublishedTraining2Example example = new PublishedTraining2Example();
example.createCriteria().andIdIn(tidList);
List<PublishedTraining2WithBLOBs> training2WithBLOBsList = publishedDao.selectByExampleWithBLOBs(example);
Map<Long, List<PublishedTraining2WithBLOBs>> mapTrainingMap = training2WithBLOBsList.stream().peek(t -> {
t.setId(null);
t.setUpdateTime(null);
t.setCreateTime(null);
}).collect(Collectors.groupingBy(PublishedTraining2WithBLOBs::getMapId));
// 地图基本信息列表
List<MapInfo> mapInfoList = mapService.queryMapInfoList(new ArrayList<>(mapTrainingMap.keySet()));
Map<Long, MapInfo> mapInfoMap = mapInfoList.stream().collect(Collectors.toMap(MapInfo::getId, m -> m, (o, n) -> n));
List<ExportTraining2> exportTraining2List = new ArrayList<>(mapTrainingMap.size());
mapInfoMap.forEach((k, v) -> {
ExportTraining2 exportData = new ExportTraining2();
exportData.setName(v.getName());
exportData.setLineCode(v.getLineCode());
exportData.setList(mapTrainingMap.get(k));
exportTraining2List.add(exportData);
});
return exportTraining2List;
}
/**
* 导入实训接口
*
* @param trainingList 实训列表
*/
public List<String> importTraining(List<ExportTraining2> trainingList, LoginUserInfoVO userInfoVO) {
List<String> msgList = new ArrayList<>();
trainingList.forEach(t -> {
List<MapInfo> mapInfoList = mapService.queryMapInfo(t.getName(), t.getLineCode());
if (mapInfoList.size() == 1) {
Long mapId = mapInfoList.get(0).getId();
t.getList().forEach(training -> {
training.setMapId(mapId);
training.setCreatorId(userInfoVO.getAccountVO().getId());
training.setCreateTime(LocalDateTime.now());
});
return exportTraining2List;
}
/**
* 导入实训接口
* @param trainingList 实训列表
*/
public List<String> importTraining(List<ExportTraining2> trainingList, LoginUserInfoVO userInfoVO) {
List<String> msgList = new ArrayList<>();
trainingList.forEach(t -> {
List<MapInfo> mapInfoList = mapService.queryMapInfo(t.getName(), t.getLineCode());
if (mapInfoList.size() == 1) {
Long mapId = mapInfoList.get(0).getId();
t.getList().forEach(training -> {
training.setMapId(mapId);
training.setCreatorId(userInfoVO.getAccountVO().getId());
training.setCreateTime(LocalDateTime.now());
});
publishedDao.insertList(t.getList());
msgList.add(String.format("地图【%s】实训信息导入成功", t.getName()));
} else {
msgList.add(String.format("地图【%s】实训信息导入失败", t.getName()));
}
});
return msgList;
}
publishedDao.insertList(t.getList());
msgList.add(String.format("地图【%s】实训信息导入成功", t.getName()));
} else {
msgList.add(String.format("地图【%s】实训信息导入失败", t.getName()));
}
});
return msgList;
}
}