123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- package cn.com.qmth.mps.service.impl;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import org.apache.commons.collections4.CollectionUtils;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
- import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
- import cn.com.qmth.mps.bean.PaperGroupUnit;
- import cn.com.qmth.mps.dao.PaperGroupUnitDao;
- import cn.com.qmth.mps.entity.PaperGroupEntity;
- import cn.com.qmth.mps.entity.PaperGroupUnitEntity;
- import cn.com.qmth.mps.service.PaperGroupUnitService;
- @Service
- public class PaperGroupUnitServiceImpl extends ServiceImpl<PaperGroupUnitDao, PaperGroupUnitEntity> implements PaperGroupUnitService {
- @Override
- public Map<Long, List<PaperGroupUnit>> getGroupInfo(Long paperId) {
- List<PaperGroupUnitEntity> list=getByPaperId(paperId);
- if(CollectionUtils.isEmpty(list)) {
- return null;
- }
- Map<Long, List<PaperGroupUnit>> ret=new HashMap<>();
- for(PaperGroupUnitEntity e:list) {
- List<PaperGroupUnit> tem=ret.get(e.getGroupId());
- if(tem==null) {
- tem=new ArrayList<>();
- ret.put(e.getGroupId(), tem);
- }
- PaperGroupUnit vo=new PaperGroupUnit();
- vo.setDetailNumber(e.getDetailNumber());
- vo.setDetailUnitNumber(e.getDetailUnitNumber());
- tem.add(vo);
- }
- return ret;
- }
- @Override
- public List<PaperGroupUnitEntity> getByPaperId(Long paperId) {
- QueryWrapper<PaperGroupUnitEntity> wrapper = new QueryWrapper<>();
- LambdaQueryWrapper<PaperGroupUnitEntity> lw = wrapper.lambda();
- lw.eq(PaperGroupUnitEntity::getPaperId, paperId);
- lw.orderByAsc(PaperGroupUnitEntity::getDetailNumber);
- lw.orderByAsc(PaperGroupUnitEntity::getDetailUnitNumber);
- return this.list(wrapper);
- }
- @Transactional
- @Override
- public void removeByGroupId( Long groupId) {
- QueryWrapper<PaperGroupUnitEntity> wrapper = new QueryWrapper<>();
- LambdaQueryWrapper<PaperGroupUnitEntity> lw = wrapper.lambda();
- lw.eq(PaperGroupUnitEntity::getGroupId, groupId);
- this.remove(wrapper);
- }
- @Transactional
- @Override
- public void saveUnit(PaperGroupEntity group, List<PaperGroupUnit> groupUnits) {
- List<PaperGroupUnitEntity> ret=new ArrayList<>();
- for(PaperGroupUnit unit:groupUnits) {
- PaperGroupUnitEntity e=new PaperGroupUnitEntity();
- e.setPaperId(group.getPaperId());
- e.setGroupId(group.getId());
- e.setDetailNumber(unit.getDetailNumber());
- e.setDetailUnitNumber(unit.getDetailUnitNumber());
- ret.add(e);
- }
- this.saveBatch(ret);
- }
-
- @Override
- public Integer countByPaperId(Long paperId) {
- QueryWrapper<PaperGroupUnitEntity> wrapper = new QueryWrapper<>();
- LambdaQueryWrapper<PaperGroupUnitEntity> lw = wrapper.lambda();
- lw.eq(PaperGroupUnitEntity::getPaperId, paperId);
- return this.count(wrapper);
- }
-
- @Transactional
- @Override
- public void clearByPaperId(Long paperId) {
- QueryWrapper<PaperGroupUnitEntity> wrapper = new QueryWrapper<>();
- LambdaQueryWrapper<PaperGroupUnitEntity> lw = wrapper.lambda();
- lw.eq(PaperGroupUnitEntity::getPaperId, paperId);
- this.remove(wrapper);
- }
- }
|