|
@@ -0,0 +1,117 @@
|
|
|
|
|
+package com.fs.decoration.service.impl;
|
|
|
|
|
+
|
|
|
|
|
+import com.fs.decoration.domain.DecorationComponent;
|
|
|
|
|
+import com.fs.decoration.dto.DecorationComponentQuery;
|
|
|
|
|
+import com.fs.decoration.dto.DecorationComponentSaveReq;
|
|
|
|
|
+import com.fs.decoration.mapper.DecorationComponentMapper;
|
|
|
|
|
+import com.fs.decoration.service.IDecorationComponentService;
|
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
+
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * 组件定义 Service 实现
|
|
|
|
|
+ */
|
|
|
|
|
+@Service
|
|
|
|
|
+public class DecorationComponentServiceImpl implements IDecorationComponentService {
|
|
|
|
|
+
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private DecorationComponentMapper decorationComponentMapper;
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public List<DecorationComponent> selectList(DecorationComponentQuery query) {
|
|
|
|
|
+ return decorationComponentMapper.selectList(query);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public DecorationComponent selectById(Long id) {
|
|
|
|
|
+ return decorationComponentMapper.selectById(id);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
|
+ public Long saveComponent(DecorationComponentSaveReq req) {
|
|
|
|
|
+ // 基础校验
|
|
|
|
|
+ if (req.getComponentCode() == null || req.getComponentCode().trim().isEmpty()) {
|
|
|
|
|
+ throw new RuntimeException("组件编码不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (req.getComponentName() == null || req.getComponentName().trim().isEmpty()) {
|
|
|
|
|
+ throw new RuntimeException("组件名称不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (req.getComponentTypeCode() == null || req.getComponentTypeCode().trim().isEmpty()) {
|
|
|
|
|
+ throw new RuntimeException("组件类型不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 根据组件编码检查是否已存在
|
|
|
|
|
+ DecorationComponent exist = decorationComponentMapper.selectByComponentCode(req.getComponentCode());
|
|
|
|
|
+
|
|
|
|
|
+ // 新增
|
|
|
|
|
+ if (req.getId() == null) {
|
|
|
|
|
+ if (exist != null) {
|
|
|
|
|
+ throw new RuntimeException("组件编码已存在");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ DecorationComponent entity = new DecorationComponent();
|
|
|
|
|
+ entity.setComponentCode(req.getComponentCode());
|
|
|
|
|
+ entity.setComponentName(req.getComponentName());
|
|
|
|
|
+ entity.setComponentTypeCode(req.getComponentTypeCode());
|
|
|
|
|
+ entity.setIcon(req.getIcon());
|
|
|
|
|
+ entity.setPreviewImage(req.getPreviewImage());
|
|
|
|
|
+ entity.setStatus(req.getStatus() == null ? 1 : req.getStatus());
|
|
|
|
|
+ entity.setRemark(req.getRemark());
|
|
|
|
|
+
|
|
|
|
|
+ decorationComponentMapper.insert(entity);
|
|
|
|
|
+ return entity.getId();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 修改
|
|
|
|
|
+ DecorationComponent old = decorationComponentMapper.selectById(req.getId());
|
|
|
|
|
+ if (old == null) {
|
|
|
|
|
+ throw new RuntimeException("组件不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 如果存在同编码记录,但不是自己,说明编码冲突
|
|
|
|
|
+ if (exist != null && !exist.getId().equals(req.getId())) {
|
|
|
|
|
+ throw new RuntimeException("组件编码已存在");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ DecorationComponent entity = new DecorationComponent();
|
|
|
|
|
+ entity.setId(req.getId());
|
|
|
|
|
+ entity.setComponentCode(req.getComponentCode());
|
|
|
|
|
+ entity.setComponentName(req.getComponentName());
|
|
|
|
|
+ entity.setComponentTypeCode(req.getComponentTypeCode());
|
|
|
|
|
+ entity.setIcon(req.getIcon());
|
|
|
|
|
+ entity.setPreviewImage(req.getPreviewImage());
|
|
|
|
|
+ entity.setStatus(req.getStatus() == null ? old.getStatus() : req.getStatus());
|
|
|
|
|
+ entity.setRemark(req.getRemark());
|
|
|
|
|
+
|
|
|
|
|
+ decorationComponentMapper.updateById(entity);
|
|
|
|
|
+ return entity.getId();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
|
+ public int deleteById(Long id) {
|
|
|
|
|
+ DecorationComponent old = decorationComponentMapper.selectById(id);
|
|
|
|
|
+ if (old == null) {
|
|
|
|
|
+ throw new RuntimeException("组件不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ return decorationComponentMapper.deleteById(id);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
|
+ public int updateStatus(Long id, Integer status) {
|
|
|
|
|
+ DecorationComponent old = decorationComponentMapper.selectById(id);
|
|
|
|
|
+ if (old == null) {
|
|
|
|
|
+ throw new RuntimeException("组件不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ DecorationComponent entity = new DecorationComponent();
|
|
|
|
|
+ entity.setId(id);
|
|
|
|
|
+ entity.setStatus(status);
|
|
|
|
|
+ return decorationComponentMapper.updateById(entity);
|
|
|
|
|
+ }
|
|
|
|
|
+}
|