content: package com.company.project.controller;
  
  import cn.dev33.satoken.annotation.SaCheckPermission;
  import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  import com.baomidou.mybatisplus.core.metadata.IPage;
  import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  import com.company.project.common.exception.BusinessException;
  import com.company.project.entity.SysDictDetailEntity;
  import com.company.project.service.SysDictDetailService;
  import io.swagger.annotations.Api;
  import io.swagger.annotations.ApiOperation;
  import io.swagger.annotations.ApiParam;
  import org.springframework.util.StringUtils;
  import org.springframework.web.bind.annotation.*;
  
  import javax.annotation.Resource;
  import java.util.List;
  
  
  /**
   * 字典明细管理
   *
   * @author wenbin
   * @version V1.0
   * @date 2020年3月18日
   */
  @Api(tags = "字典明细管理")
  @RestController
  @RequestMapping("/sysDictDetail")
  public class SysDictDetailController {
      @Resource
      private SysDictDetailService sysDictDetailService;
  
      @ApiOperation(value = "新增")
      @PostMapping("/add")
      @SaCheckPermission("sysDict:add")
      public void add(@RequestBody SysDictDetailEntity sysDictDetail) {
          if (StringUtils.isEmpty(sysDictDetail.getValue())) {
              throw new BusinessException("字典值不能为空");
          }
          LambdaQueryWrapper<SysDictDetailEntity> queryWrapper = Wrappers.lambdaQuery();
          queryWrapper.eq(SysDictDetailEntity::getValue, sysDictDetail.getValue());
          queryWrapper.eq(SysDictDetailEntity::getDictId, sysDictDetail.getDictId());
          SysDictDetailEntity q = sysDictDetailService.getOne(queryWrapper);
          if (q != null) {
              throw new BusinessException("字典名称-字典值已存在");
          }
          sysDictDetailService.save(sysDictDetail);
      }
  
      @ApiOperation(value = "删除")
      @DeleteMapping("/delete")
      @SaCheckPermission("sysDict:delete")
      public void delete(@RequestBody @ApiParam(value = "id集合") List<String> ids) {
          sysDictDetailService.removeByIds(ids);
      }
  
      @ApiOperation(value = "更新")
      @PutMapping("/update")
      @SaCheckPermission("sysDict:update")
      public void update(@RequestBody SysDictDetailEntity sysDictDetail) {
          if (StringUtils.isEmpty(sysDictDetail.getValue())) {
              throw new BusinessException("字典值不能为空");
          }
          LambdaQueryWrapper<SysDictDetailEntity> queryWrapper = Wrappers.lambdaQuery();
          queryWrapper.eq(SysDictDetailEntity::getValue, sysDictDetail.getValue());
          queryWrapper.eq(SysDictDetailEntity::getDictId, sysDictDetail.getDictId());
          SysDictDetailEntity q = sysDictDetailService.getOne(queryWrapper);
          if (q != null && !q.getId().equals(sysDictDetail.getId())) {
              throw new BusinessException("字典名称-字典值已存在");
          }
  
          sysDictDetailService.updateById(sysDictDetail);
      }
  
  
      @ApiOperation(value = "查询列表数据")
      @PostMapping("/listByPage")
      @SaCheckPermission("sysDict:list")
      public IPage<SysDictDetailEntity> findListByPage(@RequestBody SysDictDetailEntity sysDictDetail) {
          if (StringUtils.isEmpty(sysDictDetail.getDictId())) {
              return new Page<>();
          }
          return sysDictDetailService.listByPage(sysDictDetail.getQueryPage(), sysDictDetail.getDictId());
      }
  
  }
  