潘志宝
2024-10-09 c0b8cf32504dd1a42780bb1ee06ae8a7b0d7b120
提交 | 用户 | 时间
e41062 1 package com.iailab.module.data.ind.item.service.impl;
2
68413a 3 import com.baomidou.dynamic.datasource.annotation.DSTransactional;
cf757d 4 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
e41062 5 import com.iailab.framework.common.pojo.PageResult;
6 import com.iailab.framework.common.service.impl.BaseServiceImpl;
7 import com.iailab.framework.common.util.object.BeanUtils;
68413a 8 import com.iailab.module.data.common.enums.ItemTypeEnum;
e41062 9 import com.iailab.module.data.ind.item.dao.IndItemDao;
68413a 10 import com.iailab.module.data.ind.item.entity.IndItemAtomEntity;
J 11 import com.iailab.module.data.ind.item.entity.IndItemCalEntity;
12 import com.iailab.module.data.ind.item.entity.IndItemDerEntity;
e41062 13 import com.iailab.module.data.ind.item.entity.IndItemEntity;
68413a 14 import com.iailab.module.data.ind.item.service.IndItemAtomService;
e41062 15 import com.iailab.module.data.ind.item.service.IndItemService;
16 import com.iailab.module.data.ind.item.vo.IndItemPageReqVO;
68413a 17 import com.iailab.module.data.ind.item.vo.IndItemRespVO;
e41062 18 import com.iailab.module.data.ind.item.vo.IndItemSaveReqVO;
68413a 19 import com.iailab.module.data.point.common.IncreaseCodeEnum;
J 20 import com.iailab.module.data.point.service.DaSequenceNumService;
21 import org.springframework.beans.factory.annotation.Autowired;
e41062 22 import org.springframework.stereotype.Service;
68413a 23 import org.springframework.transaction.annotation.Transactional;
e41062 24
25 import java.util.Date;
68413a 26 import java.util.List;
e41062 27 import java.util.UUID;
28
29 /**
30  * @author PanZhibao
31  * @Description
32  * @createTime 2024年09月11日
33  */
34 @Service
35 public class IndItemServiceImpl extends BaseServiceImpl<IndItemDao, IndItemEntity> implements IndItemService {
36
68413a 37     @Autowired
J 38     private IndItemAtomService indItemAtomService;
39
40     @Autowired
41     private IndItemDerServiceImpl indItemDerServiceImpl;
42
43     @Autowired
44     private IndItemCalServiceImpl indItemCalServiceImpl;
45
46     @Autowired
47     private DaSequenceNumService daSequenceNumService;
cf757d 48
e41062 49     @Override
50     public PageResult<IndItemEntity> page(IndItemPageReqVO reqVO) {
51         return baseDao.selectPage(reqVO);
52     }
53
54     @Override
cf757d 55     @DSTransactional(rollbackFor = Exception.class)
e41062 56     public void create(IndItemSaveReqVO createReqVO) {
57         IndItemEntity entity = BeanUtils.toBean(createReqVO, IndItemEntity.class);
58         entity.setId(UUID.randomUUID().toString());
68413a 59
cf757d 60         if (ItemTypeEnum.ATOM.getCode().equals(createReqVO.getItemType())) {
68413a 61             IndItemAtomEntity atomEntity = BeanUtils.toBean(createReqVO.getAtomItem(), IndItemAtomEntity.class);
J 62             atomEntity.setId(UUID.randomUUID().toString());
63             atomEntity.setItemId(entity.getId());
64             indItemAtomService.insert(atomEntity);
65             entity.setItemNo(daSequenceNumService.getAndIncreaseByCode(IncreaseCodeEnum.IND_A.name()));
cf757d 66         } else if (ItemTypeEnum.DER.getCode().equals(createReqVO.getItemType())) {
68413a 67             IndItemDerEntity derEntity = BeanUtils.toBean(createReqVO.getDerItem(), IndItemDerEntity.class);
J 68             derEntity.setId(UUID.randomUUID().toString());
69             derEntity.setItemId(entity.getId());
70             indItemDerServiceImpl.insert(derEntity);
71             entity.setItemNo(daSequenceNumService.getAndIncreaseByCode(IncreaseCodeEnum.IND_D.name()));
cf757d 72         } else if (ItemTypeEnum.CAL.getCode().equals(createReqVO.getItemType())) {
68413a 73             IndItemCalEntity calEntity = BeanUtils.toBean(createReqVO.getCalItem(), IndItemCalEntity.class);
J 74             calEntity.setId(UUID.randomUUID().toString());
75             calEntity.setItemId(entity.getId());
76             indItemCalServiceImpl.insert(calEntity);
77             entity.setItemNo(daSequenceNumService.getAndIncreaseByCode(IncreaseCodeEnum.IND_C.name()));
78         }
e41062 79         entity.setCreateTime(new Date());
80         baseDao.insert(entity);
81     }
82
83     @Override
cf757d 84     @DSTransactional(rollbackFor = Exception.class)
e41062 85     public void update(IndItemSaveReqVO updateReqVO) {
86         IndItemEntity entity = BeanUtils.toBean(updateReqVO, IndItemEntity.class);
87         entity.setUpdateTime(new Date());
88         baseDao.updateById(entity);
89     }
90
91     @Override
92     public IndItemEntity get(String id) {
93         return baseDao.selectById(id);
94     }
95
96     @Override
cf757d 97     public IndItemEntity getInfoByNo(String no) {
98         QueryWrapper<IndItemEntity> queryWrapper = new QueryWrapper<>();
99         queryWrapper.eq("item_no", no);
100         return baseDao.selectOne(queryWrapper);
101     }
102
103     @Override
104     @DSTransactional(rollbackFor = Exception.class)
e41062 105     public void delete(String id) {
68413a 106         IndItemEntity entity = get(id);
cf757d 107         if (ItemTypeEnum.ATOM.getCode().equals(entity.getItemType())) {
68413a 108             indItemAtomService.deleteByItemId(id);
cf757d 109         } else if (ItemTypeEnum.DER.getCode().equals(entity.getItemType())) {
68413a 110             indItemDerServiceImpl.deleteByItemId(id);
cf757d 111         } else if (ItemTypeEnum.CAL.getCode().equals(entity.getItemType())) {
68413a 112             indItemCalServiceImpl.deleteByItemId(id);
J 113         }
e41062 114         baseDao.deleteById(id);
115     }
68413a 116
J 117     @Override
118     public List<IndItemRespVO> getList(IndItemPageReqVO reqVO) {
119         return baseDao.getItemList(reqVO);
120     }
e41062 121 }