| | |
| | | package com.ruoyi.system.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.common.basic.PageDTO; |
| | | import com.ruoyi.common.enums.FieldInputTypeEnum; |
| | | import com.ruoyi.common.enums.FieldTypeEnum; |
| | | import com.ruoyi.common.enums.ShowStatusEnum; |
| | | import com.ruoyi.common.exception.ServiceException; |
| | | import com.ruoyi.common.utils.BeanUtils; |
| | | import com.ruoyi.common.utils.CollUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.system.domain.TbBasicDataConfig; |
| | | import com.ruoyi.system.domain.TbField; |
| | | import com.ruoyi.system.domain.TbFieldCategory; |
| | | import com.ruoyi.system.dto.FieldDTO; |
| | | import com.ruoyi.system.dto.ShowHideDTO; |
| | | import com.ruoyi.system.dto.update.FieldUpdateDTO; |
| | | import com.ruoyi.system.mapper.TbFieldMapper; |
| | | import com.ruoyi.system.query.FieldQuery; |
| | | import com.ruoyi.system.service.TbBasicDataConfigService; |
| | | import com.ruoyi.system.service.TbFieldCategoryService; |
| | | import com.ruoyi.system.service.TbFieldService; |
| | | import com.ruoyi.system.vo.FieldVO; |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | import java.util.concurrent.CompletableFuture; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | * @author mitao |
| | | * @since 2024-03-13 |
| | | */ |
| | | @Slf4j |
| | | @Service |
| | | @RequiredArgsConstructor |
| | | public class TbFieldServiceImpl extends ServiceImpl<TbFieldMapper, TbField> implements TbFieldService { |
| | | private final TbFieldCategoryService tbFieldCategoryService; |
| | | private final TbBasicDataConfigService tbBasicDataConfigService; |
| | | |
| | | } |
| | | @Override |
| | | public void add(FieldDTO dto) { |
| | | //参数校验 |
| | | Integer fieldType = dto.getFieldType(); |
| | | //1:数字 2:文本 3:百分比 |
| | | if (FieldTypeEnum.TEXT.getCode().equals(fieldType)) { |
| | | if (StringUtils.isNull(dto.getTextInputType())) { |
| | | throw new ServiceException("输入类型不能为空"); |
| | | } else if (FieldInputTypeEnum.FIXED_CONTENT.getCode().equals(dto.getTextInputType()) && StringUtils.isBlank(dto.getTextContent())) { |
| | | throw new ServiceException("内容设置不能为空"); |
| | | } |
| | | } |
| | | TbField tbField = BeanUtils.copyBean(dto, TbField.class); |
| | | TbFieldCategory category1 = tbFieldCategoryService.getById(dto.getLevelOneCategoryId()); |
| | | tbField.setLevelOneCategory(category1.getFieldCategoryName()); |
| | | if (StringUtils.isNotNull(dto.getLevelTwoCategoryId())) { |
| | | TbFieldCategory category2 = tbFieldCategoryService.getById(dto.getLevelTwoCategoryId()); |
| | | tbField.setLevelTwoCategory(category2.getFieldCategoryName()); |
| | | } |
| | | if (StringUtils.isNotNull(dto.getLevelThreeCategoryId())) { |
| | | TbFieldCategory category3 = tbFieldCategoryService.getById(dto.getLevelThreeCategoryId()); |
| | | tbField.setLevelThreeCategory(category3.getFieldCategoryName()); |
| | | } |
| | | this.save(tbField); |
| | | } |
| | | |
| | | @Override |
| | | public void showHide(ShowHideDTO dto) { |
| | | log.info("======主线程执行showHide{}",Thread.currentThread().getName() ); |
| | | TbField field = this.getById(dto.getId()); |
| | | if (StringUtils.isNull(field)) { |
| | | throw new ServiceException("非法参数"); |
| | | } |
| | | //隐藏字段 |
| | | this.lambdaUpdate().set(TbField::getStatus, dto.getStatus()).eq(TbField::getId, dto.getId()).update(); |
| | | //异步隐藏基础数据配置 |
| | | CompletableFuture.runAsync(() -> handleDataConfig(dto, field)); |
| | | } |
| | | private void handleDataConfig(ShowHideDTO dto, TbField field) { |
| | | log.info("======子线程执行handleDataConfig{}",Thread.currentThread().getName() ); |
| | | List<TbBasicDataConfig> list = tbBasicDataConfigService.lambdaQuery().eq(TbBasicDataConfig::getStatus, ShowStatusEnum.SHOW.getCode()).list(); |
| | | if (CollUtils.isNotEmpty(list)) { |
| | | List<Integer> ids = list.stream().map(config -> { |
| | | String fieldIdStr = config.getFieldIdStr(); |
| | | String[] split = fieldIdStr.split(","); |
| | | //字符串数组转为List |
| | | List<String> idList = new ArrayList<>(Arrays.asList(split)); |
| | | if (idList.contains(field.getId().toString())) { |
| | | return config.getId(); |
| | | } |
| | | return null; |
| | | }).collect(Collectors.toList()); |
| | | tbBasicDataConfigService.lambdaUpdate().set(TbBasicDataConfig::getStatus, dto.getStatus()).in(TbBasicDataConfig::getId, ids).update(); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public PageDTO<FieldVO> queryPage(FieldQuery query) { |
| | | Page<TbField> page = this.lambdaQuery() |
| | | .like(StringUtils.isNotEmpty(query.getFieldName()), TbField::getFieldName, query.getFieldName()) |
| | | .like(StringUtils.isNotEmpty(query.getLevelOneCategory()), TbField::getLevelOneCategory, query.getLevelOneCategory()) |
| | | .like(StringUtils.isNotEmpty(query.getLevelTwoCategory()), TbField::getLevelTwoCategory, query.getLevelTwoCategory()) |
| | | .like(StringUtils.isNotEmpty(query.getLevelThreeCategory()), TbField::getLevelThreeCategory, query.getLevelThreeCategory()) |
| | | .eq(StringUtils.isNotNull(query.getStatus()), TbField::getStatus, query.getStatus()) |
| | | .eq(StringUtils.isNotNull(query.getFieldType()), TbField::getFieldType, query.getFieldType()) |
| | | .orderByDesc(TbField::getCreateTime) |
| | | .page(new Page<>(query.getPageNum(), query.getPageSize())); |
| | | if (CollUtils.isEmpty(page.getRecords())) { |
| | | return PageDTO.empty(page); |
| | | } |
| | | return PageDTO.of(page, FieldVO.class); |
| | | } |
| | | |
| | | @Override |
| | | public String influencedData(Integer id) { |
| | | List<TbBasicDataConfig> list = tbBasicDataConfigService.lambdaQuery().eq(TbBasicDataConfig::getStatus, ShowStatusEnum.SHOW).list(); |
| | | if (CollUtils.isEmpty(list)) { |
| | | return ""; |
| | | } |
| | | String collect = list.stream().map(config -> { |
| | | String fieldIdStr = config.getFieldIdStr(); |
| | | String[] split = fieldIdStr.split(","); |
| | | //字符串数组转为List |
| | | List<String> idList = Arrays.asList(split); |
| | | if (idList.contains(id.toString())) { |
| | | return config.getTypeName(); |
| | | } |
| | | return null; |
| | | }).filter(Objects::nonNull).collect(Collectors.joining(",")); |
| | | if (StringUtils.isBlank(collect)) { |
| | | return ""; |
| | | } |
| | | return collect; |
| | | } |
| | | |
| | | @Override |
| | | public void update(FieldUpdateDTO dto) { |
| | | TbField field = this.getById(dto.getId()); |
| | | if (Objects.isNull(field)) { |
| | | throw new ServiceException("参数异常"); |
| | | } |
| | | TbField tbField = BeanUtils.copyBean(dto, TbField.class); |
| | | this.updateById(tbField); |
| | | } |
| | | } |