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