perf(后台管理): 优化字典标签列表

master
wayn 5 years ago
parent 110c98feb7
commit a4bb6696f2

@ -3,18 +3,19 @@ package com.wayn.project.system.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wayn.common.base.BaseController; import com.wayn.common.base.BaseController;
import com.wayn.common.constant.SysConstants;
import com.wayn.common.util.R; import com.wayn.common.util.R;
import com.wayn.common.util.SecurityUtils;
import com.wayn.project.system.domain.SysDict; import com.wayn.project.system.domain.SysDict;
import com.wayn.project.system.service.IDictService; import com.wayn.project.system.service.IDictService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Date;
import java.util.List; import java.util.List;
@ -28,17 +29,67 @@ public class DictDataController extends BaseController {
@PreAuthorize("@ss.hasPermi('system:dict:list')") @PreAuthorize("@ss.hasPermi('system:dict:list')")
@ApiOperation(value = "字典数据列表", notes = "字典数据列表") @ApiOperation(value = "字典数据分页", notes = "字典数据分页")
@GetMapping("/list") @GetMapping("/list")
public R list(SysDict dict) { public R list(SysDict dict) {
Page<SysDict> page = getPage(); Page<SysDict> page = getPage();
return R.success().add("page", iDictService.listDictDataPage(page, dict)); return R.success().add("page", iDictService.listDictDataPage(page, dict));
} }
@PreAuthorize("@ss.hasPermi('system:dict:list')")
@ApiOperation(value = "字典类型列表", notes = "字典类型列表")
@GetMapping("/selectTypeList")
public R selectTypeList() {
List<SysDict> typeList = iDictService.list(new QueryWrapper<SysDict>().eq("type", 1));
return R.success().add("typeList", typeList);
}
@GetMapping("/type/{parentType}") @GetMapping("/type/{parentType}")
public R dictType(@PathVariable String parentType) { public R dictType(@PathVariable String parentType) {
List<SysDict> dicts = iDictService.list(new QueryWrapper<SysDict>().eq("type", 2).eq("parent_type", parentType)); List<SysDict> dicts = iDictService.list(new QueryWrapper<SysDict>().eq("type", 2).eq("parent_type", parentType));
return R.success().add("data", dicts); return R.success().add("data", dicts);
} }
@PreAuthorize("@ss.hasPermi('system:dict:add')")
@ApiOperation(value = "保存字典数据", notes = "保存字典数据")
@PostMapping
public R addDict(@Validated @RequestBody SysDict dict) {
if (SysConstants.NOT_UNIQUE.equals(iDictService.checkDictNameUnique(dict))) {
return R.error("新增标签名'" + dict.getName() + "'失败,标签名已存在");
} else if (SysConstants.NOT_UNIQUE.equals(iDictService.checkDictValueUnique(dict))) {
return R.error("新增标签值'" + dict.getValue() + "'失败,标签值已存在");
}
dict.setCreateBy(SecurityUtils.getUsername());
dict.setCreateTime(new Date());
return R.result(iDictService.save(dict));
}
@PreAuthorize("@ss.hasPermi('system:dict:add')")
@ApiOperation(value = "保存字典数据", notes = "保存字典数据")
@PutMapping
public R updateDict(@Validated @RequestBody SysDict dict) {
if (SysConstants.NOT_UNIQUE.equals(iDictService.checkDictNameUnique(dict))) {
return R.error("更新标签名'" + dict.getName() + "'失败,标签名已存在");
} else if (SysConstants.NOT_UNIQUE.equals(iDictService.checkDictValueUnique(dict))) {
return R.error("更新标签值'" + dict.getValue() + "'失败,标签值已存在");
}
dict.setUpdateBy(SecurityUtils.getUsername());
dict.setUpdateTime(new Date());
return R.result(iDictService.updateById(dict));
}
@PreAuthorize("@ss.hasPermi('system:dict:query')")
@ApiOperation(value = "获取字典数据详细", notes = "获取字典数据详细")
@GetMapping("{dictId}")
public R getDict(@PathVariable Long dictId) {
return R.success().add("data", iDictService.getById(dictId));
}
@PreAuthorize("@ss.hasPermi('system:dict:delete')")
@ApiOperation(value = "删除字典数据", notes = "删除字典数据")
@DeleteMapping("{dictId}")
public R deleteDict(@PathVariable Long dictId) {
return R.result(iDictService.removeById(dictId));
}
} }

@ -5,6 +5,7 @@ import com.wayn.common.base.BaseController;
import com.wayn.common.constant.SysConstants; import com.wayn.common.constant.SysConstants;
import com.wayn.common.util.R; import com.wayn.common.util.R;
import com.wayn.common.util.SecurityUtils; import com.wayn.common.util.SecurityUtils;
import com.wayn.common.util.excel.ExcelUtil;
import com.wayn.project.system.domain.SysDict; import com.wayn.project.system.domain.SysDict;
import com.wayn.project.system.service.IDictService; import com.wayn.project.system.service.IDictService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
@ -15,6 +16,7 @@ import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.Date; import java.util.Date;
import java.util.List;
@Api("字典类型接口") @Api("字典类型接口")
@ -27,7 +29,7 @@ public class DictTypeController extends BaseController {
@PreAuthorize("@ss.hasPermi('system:dict:list')") @PreAuthorize("@ss.hasPermi('system:dict:list')")
@ApiOperation(value = "字典类型列表", notes = "字典类型列表") @ApiOperation(value = "字典类型分页", notes = "字典类型分页")
@GetMapping("/list") @GetMapping("/list")
public R list(SysDict dict) { public R list(SysDict dict) {
Page<SysDict> page = getPage(); Page<SysDict> page = getPage();
@ -39,9 +41,9 @@ public class DictTypeController extends BaseController {
@ApiOperation(value = "保存字典类型", notes = "保存字典类型") @ApiOperation(value = "保存字典类型", notes = "保存字典类型")
@PostMapping @PostMapping
public R addDict(@Validated @RequestBody SysDict dict) { public R addDict(@Validated @RequestBody SysDict dict) {
if (SysConstants.NOT_UNIQUE.equals(iDictService.checkDictTypeNameUnique(dict))) { if (SysConstants.NOT_UNIQUE.equals(iDictService.checkDictNameUnique(dict))) {
return R.error("新增字典名称'" + dict.getName() + "'失败,字典名称已存在"); return R.error("新增字典名称'" + dict.getName() + "'失败,字典名称已存在");
} else if (SysConstants.NOT_UNIQUE.equals(iDictService.checkDictTypeValueUnique(dict))) { } else if (SysConstants.NOT_UNIQUE.equals(iDictService.checkDictValueUnique(dict))) {
return R.error("新增字典类型'" + dict.getValue() + "'失败,字典类型已存在"); return R.error("新增字典类型'" + dict.getValue() + "'失败,字典类型已存在");
} }
dict.setCreateBy(SecurityUtils.getUsername()); dict.setCreateBy(SecurityUtils.getUsername());
@ -53,9 +55,9 @@ public class DictTypeController extends BaseController {
@ApiOperation(value = "更新字典类型", notes = "更新字典类型") @ApiOperation(value = "更新字典类型", notes = "更新字典类型")
@PutMapping @PutMapping
public R updateDict(@Validated @RequestBody SysDict dict) { public R updateDict(@Validated @RequestBody SysDict dict) {
if (SysConstants.NOT_UNIQUE.equals(iDictService.checkDictTypeNameUnique(dict))) { if (SysConstants.NOT_UNIQUE.equals(iDictService.checkDictNameUnique(dict))) {
return R.error("更新字典名称'" + dict.getName() + "'失败,字典名称已存在"); return R.error("更新字典名称'" + dict.getName() + "'失败,字典名称已存在");
} else if (SysConstants.NOT_UNIQUE.equals(iDictService.checkDictTypeValueUnique(dict))) { } else if (SysConstants.NOT_UNIQUE.equals(iDictService.checkDictValueUnique(dict))) {
return R.error("更新字典类型'" + dict.getValue() + "'失败,字典类型已存在"); return R.error("更新字典类型'" + dict.getValue() + "'失败,字典类型已存在");
} }
dict.setUpdateBy(SecurityUtils.getUsername()); dict.setUpdateBy(SecurityUtils.getUsername());
@ -66,7 +68,7 @@ public class DictTypeController extends BaseController {
@PreAuthorize("@ss.hasPermi('system:dict:query')") @PreAuthorize("@ss.hasPermi('system:dict:query')")
@ApiOperation(value = "获取字典类型详细", notes = "获取字典类型详细") @ApiOperation(value = "获取字典类型详细", notes = "获取字典类型详细")
@GetMapping("{dictId}") @GetMapping("{dictId}")
public R getDept(@PathVariable Long dictId) { public R getDict(@PathVariable Long dictId) {
return R.success().add("data", iDictService.getById(dictId)); return R.success().add("data", iDictService.getById(dictId));
} }
@ -74,6 +76,15 @@ public class DictTypeController extends BaseController {
@ApiOperation(value = "删除字典类型", notes = "删除字典类型") @ApiOperation(value = "删除字典类型", notes = "删除字典类型")
@DeleteMapping("{dictId}") @DeleteMapping("{dictId}")
public R deleteDict(@PathVariable Long dictId) { public R deleteDict(@PathVariable Long dictId) {
return R.success().add("data", iDictService.removeById(dictId)); // return R.result(iDictService.removeById(dictId));
return R.success();
}
@PreAuthorize("@ss.hasPermi('system:dict:export')")
@GetMapping("/export")
public R export(SysDict dict) {
List<SysDict> list = iDictService.list(dict);
return R.success(ExcelUtil.exportExcel(list, SysDict.class, "字典数据.xls"));
} }
} }

@ -105,6 +105,6 @@ public class MenuController extends BaseController {
if (iMenuService.checkMenuExistRole(menuId)) { if (iMenuService.checkMenuExistRole(menuId)) {
return R.error("菜单已分配,不允许删除"); return R.error("菜单已分配,不允许删除");
} }
return R.success().add("data", iMenuService.removeById(menuId)); return R.result(iMenuService.removeById(menuId));
} }
} }

@ -85,8 +85,7 @@ public class RoleController extends BaseController {
@ApiOperation("删除角色") @ApiOperation("删除角色")
@DeleteMapping("/{roleIds}") @DeleteMapping("/{roleIds}")
public R deleteRole(@PathVariable List<Long> roleIds) { public R deleteRole(@PathVariable List<Long> roleIds) {
iRoleService.deleteRoleByIds(roleIds); return R.result(iRoleService.deleteRoleByIds(roleIds));
return R.success();
} }
@PreAuthorize("@ss.hasPermi('system:role:export')") @PreAuthorize("@ss.hasPermi('system:role:export')")

@ -111,8 +111,7 @@ public class UserController extends BaseController {
@ApiOperation("删除用户") @ApiOperation("删除用户")
@DeleteMapping("/{userIds}") @DeleteMapping("/{userIds}")
public R deleteUser(@PathVariable List<Long> userIds) { public R deleteUser(@PathVariable List<Long> userIds) {
iUserService.removeByIds(userIds); return R.result(iUserService.removeByIds(userIds));
return R.success();
} }
@PreAuthorize("@ss.hasPermi('system:user:export')") @PreAuthorize("@ss.hasPermi('system:user:export')")

@ -35,8 +35,8 @@ public class SysDict extends BaseEntity implements Serializable {
/** /**
* *
*/ */
@NotBlank(message = "字典不能为空") @NotBlank(message = "字典类型不能为空")
@Excel(name = "字典") @Excel(name = "字典类型")
private String value; private String value;
/** /**

@ -5,9 +5,13 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wayn.project.system.domain.SysDict; import com.wayn.project.system.domain.SysDict;
import java.util.List;
public interface DictMapper extends BaseMapper<SysDict> { public interface DictMapper extends BaseMapper<SysDict> {
IPage<SysDict> selectDictTypeListPage(Page<SysDict> page, SysDict dict); IPage<SysDict> selectDictTypeListPage(Page<SysDict> page, SysDict dict);
IPage<SysDict> selectDictDataListPage(Page<SysDict> page, SysDict dict); IPage<SysDict> selectDictDataListPage(Page<SysDict> page, SysDict dict);
List<SysDict> selectDictTypeList(SysDict dict);
} }

@ -5,6 +5,8 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.wayn.project.system.domain.SysDict; import com.wayn.project.system.domain.SysDict;
import java.util.List;
public interface IDictService extends IService<SysDict> { public interface IDictService extends IService<SysDict> {
/** /**
@ -26,19 +28,21 @@ public interface IDictService extends IService<SysDict> {
IPage<SysDict> listDictDataPage(Page<SysDict> page, SysDict dict); IPage<SysDict> listDictDataPage(Page<SysDict> page, SysDict dict);
/** /**
* * name
* *
* @param dict * @param dict
* @return * @return
*/ */
String checkDictTypeNameUnique(SysDict dict); String checkDictNameUnique(SysDict dict);
/** /**
* * value
* *
* @param dict * @param dict
* @return * @return
*/ */
String checkDictTypeValueUnique(SysDict dict); String checkDictValueUnique(SysDict dict);
List<SysDict> list(SysDict dict);
} }

@ -11,6 +11,7 @@ import com.wayn.project.system.service.IDictService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Objects; import java.util.Objects;
@Service @Service
@ -30,9 +31,15 @@ public class DictServiceImpl extends ServiceImpl<DictMapper, SysDict> implements
} }
@Override @Override
public String checkDictTypeNameUnique(SysDict dict) { public String checkDictNameUnique(SysDict dict) {
long dictId = Objects.isNull(dict.getDictId()) ? -1L : dict.getDictId(); long dictId = Objects.isNull(dict.getDictId()) ? -1L : dict.getDictId();
SysDict sysDict = getOne(new QueryWrapper<SysDict>().eq("name", dict.getName()).eq("type", 1)); QueryWrapper<SysDict> queryWrapper = new QueryWrapper<>();
if (dict.getType() == 1) {
queryWrapper.eq("name", dict.getName()).eq("type", 1);
} else {
queryWrapper.eq("name", dict.getName()).eq("type", 2).eq("parent_type", dict.getParentType());
}
SysDict sysDict = getOne(queryWrapper);
if (sysDict != null && sysDict.getDictId() != dictId) { if (sysDict != null && sysDict.getDictId() != dictId) {
return SysConstants.NOT_UNIQUE; return SysConstants.NOT_UNIQUE;
} }
@ -40,12 +47,23 @@ public class DictServiceImpl extends ServiceImpl<DictMapper, SysDict> implements
} }
@Override @Override
public String checkDictTypeValueUnique(SysDict dict) { public String checkDictValueUnique(SysDict dict) {
long dictId = Objects.isNull(dict.getDictId()) ? -1L : dict.getDictId(); long dictId = Objects.isNull(dict.getDictId()) ? -1L : dict.getDictId();
SysDict sysDict = getOne(new QueryWrapper<SysDict>().eq("value", dict.getValue()).eq("type", 1)); QueryWrapper<SysDict> queryWrapper = new QueryWrapper<>();
if (dict.getType() == 1) {
queryWrapper.eq("value", dict.getValue()).eq("type", 1);
} else {
queryWrapper.eq("value", dict.getValue()).eq("type", 2).eq("parent_type", dict.getParentType());
}
SysDict sysDict = getOne(queryWrapper);
if (sysDict != null && sysDict.getDictId() != dictId) { if (sysDict != null && sysDict.getDictId() != dictId) {
return SysConstants.NOT_UNIQUE; return SysConstants.NOT_UNIQUE;
} }
return SysConstants.UNIQUE; return SysConstants.UNIQUE;
} }
@Override
public List<SysDict> list(SysDict dict) {
return dictMapper.selectDictTypeList(dict);
}
} }

@ -71,4 +71,26 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
order by d.sort order by d.sort
</select> </select>
<select id="selectDictTypeList" parameterType="com.wayn.project.system.domain.SysDict" resultMap="SysDictResult">
<include refid="selectDictVo"/>
where d.del_flag = 0
and d.type = 1
<if test="name != null and name != ''">
AND d.name like concat('%', #{name}, '%')
</if>
<if test="value != null and value != ''">
AND d.value like concat('%', #{value}, '%')
</if>
<if test="dictStatus != null">
AND dict_status = #{dictStatus}
</if>
<if test="startTime != null and startTime != ''">
and DATE_FORMAT(d.create_time,'%Y-%m-%d') <![CDATA[ >= ]]> DATE_FORMAT(#{startTime},'%Y-%m-%d')
</if>
<if test="endTime != null and endTime != ''">
and DATE_FORMAT(d.create_time,'%Y-%m-%d') <![CDATA[ <= ]]> DATE_FORMAT(#{endTime},'%Y-%m-%d')
</if>
order by d.sort
</select>
</mapper> </mapper>
Loading…
Cancel
Save