|
@@ -1,5 +1,6 @@
|
|
|
package com.jeeplus.test.rank.service;
|
|
|
|
|
|
+import cn.afterturn.easypoi.excel.annotation.Excel;
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
@@ -14,15 +15,19 @@ import com.jeeplus.test.rank.mapper.RankRsOfficeMapper;
|
|
|
import com.jeeplus.test.rank.mapper.RankSequenceMapper;
|
|
|
import com.jeeplus.test.rank.service.dto.RankSequenceDTO;
|
|
|
import com.jeeplus.test.rank.service.mapstruct.RankSequenceWrapper;
|
|
|
-import org.checkerframework.checker.units.qual.A;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.concurrent.atomic.AtomicReference;
|
|
|
|
|
|
@Service
|
|
|
-@Transactional
|
|
|
+@Transactional(rollbackFor = Exception.class)
|
|
|
public class RankSequenceService extends ServiceImpl<RankSequenceMapper,RankSequence> {
|
|
|
|
|
|
@Autowired
|
|
@@ -31,28 +36,83 @@ public class RankSequenceService extends ServiceImpl<RankSequenceMapper,RankSequ
|
|
|
@Autowired
|
|
|
private RankRsOfficeMapper rankRsOfficeMapper;
|
|
|
|
|
|
- public void saveRankSequence(RankSequenceDTO rankSequenceDTO){
|
|
|
- RankSequence rankSequence = RankSequenceWrapper.INSTANCE.toEntity(rankSequenceDTO);
|
|
|
- this.saveOrUpdate(rankSequence);
|
|
|
- if(ObjectUtil.isNotEmpty(rankSequenceDTO)){
|
|
|
- if(StrUtil.isNotEmpty(rankSequenceDTO.getId())){
|
|
|
- rankRsOfficeMapper.delete(new QueryWrapper<RankRsOffice>().eq("rs_id",rankSequenceDTO.getId()));
|
|
|
- if(CollectionUtil.isNotEmpty(rankSequenceDTO.getOfficeIdList())){
|
|
|
- rankRsOfficeMapper.insertListById(rankSequenceDTO.getId(),rankSequenceDTO, UserUtils.getCurrentUserDTO().getId());
|
|
|
+ public ResponseEntity saveRankSequence(List<RankSequenceDTO> rankSequenceDTOList){
|
|
|
+ HashMap<String,Object> hashMap = new HashMap<>();
|
|
|
+ AtomicReference<Integer> listSize = new AtomicReference<>(rankSequenceDTOList.size());
|
|
|
+ List<String> ids = new ArrayList<>();
|
|
|
+ if(CollectionUtil.isNotEmpty(rankSequenceDTOList)){
|
|
|
+ rankSequenceDTOList.stream().forEach(item->{
|
|
|
+ if(StrUtil.isNotEmpty(item.getId())){
|
|
|
+ ids.add(item.getId());
|
|
|
}
|
|
|
- }else{
|
|
|
- rankRsOfficeMapper.insertListById(rankSequence.getId(),rankSequenceDTO, UserUtils.getCurrentUserDTO().getId());
|
|
|
- }
|
|
|
+ if(StrUtil.isNotEmpty(item.getName())){
|
|
|
+ hashMap.put(item.getName(),null);
|
|
|
+ }
|
|
|
+ if(CollectionUtil.isNotEmpty(item.getRankSequenceDTOList())){
|
|
|
+ listSize.set(listSize.get()+item.getRankSequenceDTOList().size());
|
|
|
+ item.getRankSequenceDTOList().stream().forEach(item2->{
|
|
|
+ if(StrUtil.isNotEmpty(item2.getId())){
|
|
|
+ ids.add(item2.getId());
|
|
|
+ }
|
|
|
+ if(StrUtil.isNotEmpty(item2.getName())){
|
|
|
+ hashMap.put(item2.getName(),null);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if(!Integer.valueOf(hashMap.size()).equals(listSize.get())){
|
|
|
+ //事务回滚
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
+ return ResponseEntity.badRequest().body("不可以存在重复的序列");
|
|
|
+ }
|
|
|
+ this.rankSequenceMapper.delete(new QueryWrapper<RankSequence>().notIn("id",ids));
|
|
|
+ if(CollectionUtil.isNotEmpty(rankSequenceDTOList)){
|
|
|
+ rankSequenceDTOList.stream().forEach(item->{
|
|
|
+ RankSequence rankSequence = RankSequenceWrapper.INSTANCE.toEntity(item);
|
|
|
+ rankSequence.setParentId("0");
|
|
|
+ this.saveOrUpdate(rankSequence);
|
|
|
+ if(CollectionUtil.isNotEmpty(item.getRankSequenceDTOList())){
|
|
|
+ item.getRankSequenceDTOList().stream().forEach(item2->{
|
|
|
+ RankSequence rankSequence2 = RankSequenceWrapper.INSTANCE.toEntity(item2);
|
|
|
+ rankSequence2.setParentId(rankSequence.getId());
|
|
|
+ this.saveOrUpdate(rankSequence2);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if(ObjectUtil.isNotEmpty(item)){
|
|
|
+ if(StrUtil.isNotEmpty(item.getId())){
|
|
|
+ rankRsOfficeMapper.delete(new QueryWrapper<RankRsOffice>().eq("rs_id",item.getId()));
|
|
|
+ if(CollectionUtil.isNotEmpty(item.getOfficeIdList())){
|
|
|
+ rankRsOfficeMapper.insertListById(item.getId(),item, UserUtils.getCurrentUserDTO().getId());
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ if(CollectionUtil.isNotEmpty(item.getOfficeIdList())){
|
|
|
+ rankRsOfficeMapper.insertListById(rankSequence.getId(),item, UserUtils.getCurrentUserDTO().getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
+
|
|
|
+ return ResponseEntity.ok("保存序列成功");
|
|
|
}
|
|
|
|
|
|
public IPage<RankSequenceDTO> findList(Page<RankSequenceDTO> page, QueryWrapper<RankSequence> queryWrapper){
|
|
|
- queryWrapper.eq("rs.del_flag","0")
|
|
|
+ queryWrapper.eq("rs.parent_id","0")
|
|
|
+ .eq("rs.del_flag","0")
|
|
|
.orderByAsc("rs.sort")
|
|
|
.orderByDesc("rs.create_date");
|
|
|
return rankSequenceMapper.findList(page,queryWrapper);
|
|
|
}
|
|
|
|
|
|
+ public List<RankSequenceDTO> getList(QueryWrapper<RankSequence> queryWrapper){
|
|
|
+ queryWrapper.eq("rs.parent_id","0")
|
|
|
+ .eq("rs.del_flag","0")
|
|
|
+ .orderByAsc("rs.sort")
|
|
|
+ .orderByDesc("rs.create_date");
|
|
|
+ return rankSequenceMapper.getList(queryWrapper);
|
|
|
+ }
|
|
|
+
|
|
|
public void updateUseFlagById(List<String> ids, String useFlag){
|
|
|
rankSequenceMapper.updateUseFlagById(ids,useFlag);
|
|
|
}
|