PaperGroupUnitServiceImpl.java 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. package cn.com.qmth.mps.service.impl;
  2. import java.util.ArrayList;
  3. import java.util.HashMap;
  4. import java.util.List;
  5. import java.util.Map;
  6. import org.apache.commons.collections4.CollectionUtils;
  7. import org.springframework.stereotype.Service;
  8. import org.springframework.transaction.annotation.Transactional;
  9. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  10. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  11. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  12. import cn.com.qmth.mps.bean.PaperGroupUnit;
  13. import cn.com.qmth.mps.dao.PaperGroupUnitDao;
  14. import cn.com.qmth.mps.entity.PaperGroupEntity;
  15. import cn.com.qmth.mps.entity.PaperGroupUnitEntity;
  16. import cn.com.qmth.mps.service.PaperGroupUnitService;
  17. @Service
  18. public class PaperGroupUnitServiceImpl extends ServiceImpl<PaperGroupUnitDao, PaperGroupUnitEntity> implements PaperGroupUnitService {
  19. @Override
  20. public Map<Long, List<PaperGroupUnit>> getGroupInfo(Long paperId) {
  21. List<PaperGroupUnitEntity> list=getByPaperId(paperId);
  22. if(CollectionUtils.isEmpty(list)) {
  23. return null;
  24. }
  25. Map<Long, List<PaperGroupUnit>> ret=new HashMap<>();
  26. for(PaperGroupUnitEntity e:list) {
  27. List<PaperGroupUnit> tem=ret.get(e.getGroupId());
  28. if(tem==null) {
  29. tem=new ArrayList<>();
  30. ret.put(e.getGroupId(), tem);
  31. }
  32. PaperGroupUnit vo=new PaperGroupUnit();
  33. vo.setDetailNumber(e.getDetailNumber());
  34. vo.setDetailUnitNumber(e.getDetailUnitNumber());
  35. tem.add(vo);
  36. }
  37. return ret;
  38. }
  39. @Override
  40. public List<PaperGroupUnitEntity> getByPaperId(Long paperId) {
  41. QueryWrapper<PaperGroupUnitEntity> wrapper = new QueryWrapper<>();
  42. LambdaQueryWrapper<PaperGroupUnitEntity> lw = wrapper.lambda();
  43. lw.eq(PaperGroupUnitEntity::getPaperId, paperId);
  44. lw.orderByAsc(PaperGroupUnitEntity::getDetailNumber);
  45. lw.orderByAsc(PaperGroupUnitEntity::getDetailUnitNumber);
  46. return this.list(wrapper);
  47. }
  48. @Transactional
  49. @Override
  50. public void removeByGroupId( Long groupId) {
  51. QueryWrapper<PaperGroupUnitEntity> wrapper = new QueryWrapper<>();
  52. LambdaQueryWrapper<PaperGroupUnitEntity> lw = wrapper.lambda();
  53. lw.eq(PaperGroupUnitEntity::getGroupId, groupId);
  54. this.remove(wrapper);
  55. }
  56. @Transactional
  57. @Override
  58. public void saveUnit(PaperGroupEntity group, List<PaperGroupUnit> groupUnits) {
  59. List<PaperGroupUnitEntity> ret=new ArrayList<>();
  60. for(PaperGroupUnit unit:groupUnits) {
  61. PaperGroupUnitEntity e=new PaperGroupUnitEntity();
  62. e.setPaperId(group.getPaperId());
  63. e.setGroupId(group.getId());
  64. e.setDetailNumber(unit.getDetailNumber());
  65. e.setDetailUnitNumber(unit.getDetailUnitNumber());
  66. ret.add(e);
  67. }
  68. this.saveBatch(ret);
  69. }
  70. @Override
  71. public Integer countByPaperId(Long paperId) {
  72. QueryWrapper<PaperGroupUnitEntity> wrapper = new QueryWrapper<>();
  73. LambdaQueryWrapper<PaperGroupUnitEntity> lw = wrapper.lambda();
  74. lw.eq(PaperGroupUnitEntity::getPaperId, paperId);
  75. return this.count(wrapper);
  76. }
  77. @Transactional
  78. @Override
  79. public void clearByPaperId(Long paperId) {
  80. QueryWrapper<PaperGroupUnitEntity> wrapper = new QueryWrapper<>();
  81. LambdaQueryWrapper<PaperGroupUnitEntity> lw = wrapper.lambda();
  82. lw.eq(PaperGroupUnitEntity::getPaperId, paperId);
  83. this.remove(wrapper);
  84. }
  85. }