|
@@ -0,0 +1,105 @@
|
|
|
+package com.fjhx.tenant.service.dict.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.fjhx.tenant.entity.dict.dto.DictTenantDataDto;
|
|
|
+import com.fjhx.tenant.entity.dict.dto.DictTenantDataSelectDto;
|
|
|
+import com.fjhx.tenant.entity.dict.po.DictCommonData;
|
|
|
+import com.fjhx.tenant.entity.dict.po.DictTenantData;
|
|
|
+import com.fjhx.tenant.entity.dict.vo.DictTenantDataVo;
|
|
|
+import com.fjhx.tenant.mapper.dict.DictTenantDataMapper;
|
|
|
+import com.fjhx.tenant.service.dict.DictCommonDataService;
|
|
|
+import com.fjhx.tenant.service.dict.DictTenantDataService;
|
|
|
+import com.ruoyi.common.exception.ServiceException;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.Objects;
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * 租户字典明细 服务实现类
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author
|
|
|
+ * @since 2023-03-30
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class DictTenantDataServiceImpl extends ServiceImpl<DictTenantDataMapper, DictTenantData> implements DictTenantDataService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private DictCommonDataService dictCommonDataService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Page<DictTenantDataVo> getPage(DictTenantDataSelectDto dto) {
|
|
|
+ return this.baseMapper.getPage(dto.getPage(), dto);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public DictTenantDataVo detail(Long id) {
|
|
|
+ DictTenantData DictTenantData = this.getById(id);
|
|
|
+ DictTenantDataVo result = BeanUtil.toBean(DictTenantData, DictTenantDataVo.class);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void add(DictTenantDataDto dictTenantDataDto) {
|
|
|
+
|
|
|
+ long dictTenantDataKeyCount = count(q -> q
|
|
|
+ .eq(DictTenantData::getDictKey, dictTenantDataDto.getDictKey())
|
|
|
+ .eq(DictTenantData::getTenantId, dictTenantDataDto.getTenantId()));
|
|
|
+ if (dictTenantDataKeyCount > 0) {
|
|
|
+ throw new ServiceException("key已存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ long dictTenantDataValueCount = count(q -> q
|
|
|
+ .eq(DictTenantData::getDictValue, dictTenantDataDto.getDictValue())
|
|
|
+ .eq(DictTenantData::getTenantId, dictTenantDataDto.getTenantId()));
|
|
|
+ if (dictTenantDataValueCount > 0) {
|
|
|
+ throw new ServiceException("value已存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ dictCommonDataService.nameDuplication(DictCommonData::getDictKey, dictTenantDataDto.getDictKey(), "key已存在");
|
|
|
+ dictCommonDataService.nameDuplication(DictCommonData::getDictValue, dictTenantDataDto.getDictValue(), "value已存在");
|
|
|
+
|
|
|
+ this.save(dictTenantDataDto);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void edit(DictTenantDataDto dictTenantDataDto) {
|
|
|
+
|
|
|
+ Long id = dictTenantDataDto.getId();
|
|
|
+ if (Objects.isNull(id)) {
|
|
|
+ throw new ServiceException("id不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ long dictTenantDataKeyCount = count(q -> q
|
|
|
+ .eq(DictTenantData::getDictKey, dictTenantDataDto.getDictKey())
|
|
|
+ .eq(DictTenantData::getTenantId, dictTenantDataDto.getTenantId())
|
|
|
+ .ne(DictTenantData::getId, id));
|
|
|
+ if (dictTenantDataKeyCount > 0) {
|
|
|
+ throw new ServiceException("key已存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ long dictTenantDataValueCount = count(q -> q
|
|
|
+ .eq(DictTenantData::getDictValue, dictTenantDataDto.getDictValue())
|
|
|
+ .eq(DictTenantData::getTenantId, dictTenantDataDto.getTenantId())
|
|
|
+ .ne(DictTenantData::getId, id));
|
|
|
+ if (dictTenantDataValueCount > 0) {
|
|
|
+ throw new ServiceException("value已存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ dictCommonDataService.nameDuplication(DictCommonData::getDictKey, dictTenantDataDto.getDictKey(), id, "key已存在");
|
|
|
+ dictCommonDataService.nameDuplication(DictCommonData::getDictValue, dictTenantDataDto.getDictValue(), id, "value已存在");
|
|
|
+
|
|
|
+ this.updateById(dictTenantDataDto);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void delete(Long id) {
|
|
|
+ this.removeById(id);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|