【dict】更新字典的方法

pull/3/head
fengshuonan 2021-02-08 16:38:43 +08:00
parent 6b7837ff53
commit afa215faa4
11 changed files with 175 additions and 335 deletions

View File

@ -12,14 +12,6 @@ import java.util.List;
*/
public interface DictApi {
/**
* code
*
* @author fengshuonan
* @date 2020/12/25 14:14
*/
String getDictNameByDictCode(String dictCode);
/**
*
*

View File

@ -23,7 +23,6 @@ public interface DictConstants {
*/
Long DEFAULT_DICT_PARENT_ID = -1L;
/**
* code
*/
@ -34,4 +33,4 @@ public interface DictConstants {
*/
String LANGUAGES_DICT_TYPE_CODE = "languages";
}
}

View File

@ -1,6 +1,7 @@
package cn.stylefeng.roses.kernel.dict.modular.controller;
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
import cn.stylefeng.roses.kernel.dict.api.constants.DictConstants;
import cn.stylefeng.roses.kernel.dict.modular.entity.SysDict;
import cn.stylefeng.roses.kernel.dict.modular.pojo.TreeDictInfo;
import cn.stylefeng.roses.kernel.dict.modular.pojo.request.DictRequest;
@ -8,10 +9,8 @@ import cn.stylefeng.roses.kernel.dict.modular.service.DictService;
import cn.stylefeng.roses.kernel.resource.api.annotation.ApiResource;
import cn.stylefeng.roses.kernel.resource.api.annotation.GetResource;
import cn.stylefeng.roses.kernel.resource.api.annotation.PostResource;
import cn.stylefeng.roses.kernel.rule.pojo.request.BaseRequest;
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
import cn.stylefeng.roses.kernel.rule.tree.ztree.ZTreeNode;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
@ -20,9 +19,6 @@ import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;
import static cn.stylefeng.roses.kernel.dict.api.constants.DictConstants.CONFIG_GROUP_DICT_TYPE_CODE;
import static cn.stylefeng.roses.kernel.dict.api.constants.DictConstants.LANGUAGES_DICT_TYPE_CODE;
/**
*
*
@ -44,31 +40,7 @@ public class DictController {
*/
@PostResource(name = "添加字典", path = "/dict/addDict", requiredPermission = false)
public ResponseData addDict(@RequestBody @Validated(DictRequest.add.class) DictRequest dictRequest) {
this.dictService.addDict(dictRequest);
return new SuccessResponseData();
}
/**
*
*
* @author fengshuonan
* @date 2020/10/29 16:35
*/
@PostResource(name = "修改字典", path = "/dict/updateDict", requiredPermission = false)
public ResponseData updateDict(@RequestBody @Validated(DictRequest.edit.class) DictRequest dictRequest) {
this.dictService.updateDict(dictRequest);
return new SuccessResponseData();
}
/**
*
*
* @author fengshuonan
* @date 2020/10/29 16:35
*/
@PostResource(name = "更新字典状态", path = "/dict/updateDictStatus", requiredPermission = false)
public ResponseData updateDictStatus(@RequestBody @Validated(BaseRequest.updateStatus.class) DictRequest dictRequest) {
this.dictService.updateDictStatus(dictRequest);
this.dictService.add(dictRequest);
return new SuccessResponseData();
}
@ -80,7 +52,19 @@ public class DictController {
*/
@PostResource(name = "删除字典", path = "/dict/deleteDict", requiredPermission = false)
public ResponseData deleteDict(@RequestBody @Validated(DictRequest.delete.class) DictRequest dictRequest) {
this.dictService.deleteDict(dictRequest);
this.dictService.del(dictRequest);
return new SuccessResponseData();
}
/**
*
*
* @author fengshuonan
* @date 2020/10/29 16:35
*/
@PostResource(name = "修改字典", path = "/dict/updateDict", requiredPermission = false)
public ResponseData updateDict(@RequestBody @Validated(DictRequest.edit.class) DictRequest dictRequest) {
this.dictService.edit(dictRequest);
return new SuccessResponseData();
}
@ -92,7 +76,7 @@ public class DictController {
*/
@GetResource(name = "获取字典详情", path = "/dict/getDictDetail", requiredPermission = false)
public ResponseData getDictDetail(@RequestParam("dictId") Long dictId) {
SysDict detail = this.dictService.findDetail(dictId);
SysDict detail = this.dictService.detail(dictId);
return new SuccessResponseData(detail);
}
@ -108,6 +92,18 @@ public class DictController {
return new SuccessResponseData(sysDictList);
}
/**
* ()
*
* @author fengshuonan
* @date 2020/10/29 16:35
*/
@GetResource(name = "获取字典列表", path = "/dict/getDictListPage", requiredPermission = false)
public ResponseData getDictListPage(DictRequest dictRequest) {
PageResult<SysDict> page = this.dictService.findPage(dictRequest);
return new SuccessResponseData(page);
}
/**
*
* <p>
@ -123,45 +119,7 @@ public class DictController {
}
/**
* ()
*
* @author fengshuonan
* @date 2020/10/29 16:35
*/
@GetResource(name = "获取字典列表", path = "/dict/getDictListPage", requiredPermission = false)
public ResponseData getDictListPage(DictRequest dictRequest) {
PageResult<SysDict> page = this.dictService.findPageList(dictRequest);
return new SuccessResponseData(page);
}
/**
* ()
*
* @author chenjinlong
* @date 2021/1/25 11:47
*/
@GetResource(name = "获取系统配置分组字典列表", path = "/dict/getConfigGroupPage", requiredPermission = false)
public ResponseData getConfigGroupPage(DictRequest dictRequest) {
dictRequest.setDictTypeCode(CONFIG_GROUP_DICT_TYPE_CODE);
PageResult<SysDict> page = this.dictService.findPageList(dictRequest);
return new SuccessResponseData(page);
}
/**
* ()
*
* @author chenjinlong
* @date 2021/1/25 11:47
*/
@GetResource(name = "获取多语言字典列表", path = "/dict/getLanguagesPage", requiredPermission = false)
public ResponseData getLanguagesPage(DictRequest dictRequest) {
dictRequest.setDictTypeCode(LANGUAGES_DICT_TYPE_CODE);
PageResult<SysDict> page = this.dictService.findPageList(dictRequest);
return new SuccessResponseData(page);
}
/**
*
* antdv
*
* @author fengshuonan
* @date 2020/10/29 16:36
@ -173,7 +131,7 @@ public class DictController {
}
/**
* code
* codecode
*
* @author fengshuonan
* @date 2020/10/29 16:36
@ -185,25 +143,29 @@ public class DictController {
}
/**
*
* ()
*
* @author huangyao
* @date 2021/1/10 17:31
* @author chenjinlong
* @date 2021/1/25 11:47
*/
@GetResource(name = "获取zTree形式的字典树layui版本", path = "/dict/zTree")
public List<ZTreeNode> layuiSelectParentMenuTreeList(@Validated(DictRequest.dictZTree.class) DictRequest dictRequest) {
return this.dictService.dictZTree(dictRequest);
@GetResource(name = "获取系统配置分组字典列表", path = "/dict/getConfigGroupPage", requiredPermission = false)
public ResponseData getConfigGroupPage(DictRequest dictRequest) {
dictRequest.setDictTypeCode(DictConstants.CONFIG_GROUP_DICT_TYPE_CODE);
PageResult<SysDict> page = this.dictService.findPage(dictRequest);
return new SuccessResponseData(page);
}
/**
*
* ()
*
* @author chenjinlong
* @date 2021/1/13 17:51
* @date 2021/1/25 11:47
*/
@GetResource(name = "分页查询字典", path = "/dict/page")
public ResponseData page(DictRequest dictRequest) {
return new SuccessResponseData(this.dictService.page(dictRequest));
@GetResource(name = "获取多语言字典列表", path = "/dict/getLanguagesPage", requiredPermission = false)
public ResponseData getLanguagesPage(DictRequest dictRequest) {
dictRequest.setDictTypeCode(DictConstants.LANGUAGES_DICT_TYPE_CODE);
PageResult<SysDict> page = this.dictService.findPage(dictRequest);
return new SuccessResponseData(page);
}
}

View File

@ -1,6 +1,7 @@
package cn.stylefeng.roses.kernel.dict.modular.controller;
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
import cn.stylefeng.roses.kernel.dict.api.constants.DictConstants;
import cn.stylefeng.roses.kernel.dict.modular.entity.SysDictType;
import cn.stylefeng.roses.kernel.dict.modular.pojo.request.DictTypeRequest;
import cn.stylefeng.roses.kernel.dict.modular.service.DictTypeService;
@ -18,10 +19,6 @@ import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;
import static cn.stylefeng.roses.kernel.dict.api.constants.DictConstants.CONFIG_GROUP_DICT_TYPE_CODE;
import static cn.stylefeng.roses.kernel.dict.api.constants.DictConstants.LANGUAGES_DICT_TYPE_CODE;
/**
*
*
@ -43,7 +40,7 @@ public class DictTypeController {
*/
@PostResource(name = "添加字典类型", path = "/dictType/addDictType", requiredPermission = false)
public ResponseData addDictType(@RequestBody @Validated(DictTypeRequest.add.class) DictTypeRequest dictTypeRequest) {
this.dictTypeService.addDictType(dictTypeRequest);
this.dictTypeService.add(dictTypeRequest);
return new SuccessResponseData();
}
@ -55,7 +52,7 @@ public class DictTypeController {
*/
@PostResource(name = "修改字典类型", path = "/dictType/updateDictType", requiredPermission = false)
public ResponseData updateDictType(@RequestBody @Validated(DictTypeRequest.edit.class) DictTypeRequest dictTypeRequest) {
this.dictTypeService.updateDictType(dictTypeRequest);
this.dictTypeService.edit(dictTypeRequest);
return new SuccessResponseData();
}
@ -67,7 +64,7 @@ public class DictTypeController {
*/
@PostResource(name = "修改字典类型状态", path = "/dictType/updateStatus", requiredPermission = false)
public ResponseData updateStatus(@RequestBody @Validated(BaseRequest.updateStatus.class) DictTypeRequest dictTypeRequest) {
this.dictTypeService.updateDictTypeStatus(dictTypeRequest);
this.dictTypeService.editStatus(dictTypeRequest);
return new SuccessResponseData();
}
@ -79,7 +76,7 @@ public class DictTypeController {
*/
@PostResource(name = "删除字典类型", path = "/dictType/deleteDictType", requiredPermission = false)
public ResponseData deleteDictType(@RequestBody @Validated(DictTypeRequest.delete.class) DictTypeRequest dictTypeRequest) {
this.dictTypeService.deleteDictType(dictTypeRequest);
this.dictTypeService.del(dictTypeRequest);
return new SuccessResponseData();
}
@ -95,7 +92,6 @@ public class DictTypeController {
return new SuccessResponseData(detail);
}
/**
*
*
@ -104,7 +100,7 @@ public class DictTypeController {
*/
@GetResource(name = "获取系统配置字典类型详情", path = "/dictType/getConfigDictTypeDetail", requiredPermission = false)
public ResponseData getConfigDictTypeDetail(DictTypeRequest dictTypeRequest) {
dictTypeRequest.setDictTypeCode(CONFIG_GROUP_DICT_TYPE_CODE);
dictTypeRequest.setDictTypeCode(DictConstants.CONFIG_GROUP_DICT_TYPE_CODE);
SysDictType detail = this.dictTypeService.detailBy(dictTypeRequest);
return new SuccessResponseData(detail);
}
@ -117,12 +113,11 @@ public class DictTypeController {
*/
@GetResource(name = "获取语种字典类型型详情", path = "/dictType/getTranslationDetail", requiredPermission = false)
public ResponseData getTranslationDetail(DictTypeRequest dictTypeRequest) {
dictTypeRequest.setDictTypeCode(LANGUAGES_DICT_TYPE_CODE);
dictTypeRequest.setDictTypeCode(DictConstants.LANGUAGES_DICT_TYPE_CODE);
SysDictType detail = this.dictTypeService.detailBy(dictTypeRequest);
return new SuccessResponseData(detail);
}
/**
*
*
@ -131,7 +126,7 @@ public class DictTypeController {
*/
@GetResource(name = "获取字典类型列表", path = "/dictType/getDictTypeList", requiredPermission = false)
public ResponseData getDictTypeList(DictTypeRequest dictTypeRequest) {
List<SysDictType> sysDictTypeList = dictTypeService.getDictTypeList(dictTypeRequest);
List<SysDictType> sysDictTypeList = dictTypeService.findList(dictTypeRequest);
return new SuccessResponseData(sysDictTypeList);
}
@ -143,7 +138,7 @@ public class DictTypeController {
*/
@GetResource(name = "获取字典类型列表(分页)", path = "/dictType/getDictTypePageList", requiredPermission = false)
public ResponseData getDictTypePageList(DictTypeRequest dictTypeRequest) {
PageResult<SysDictType> dictTypePageList = dictTypeService.getDictTypePageList(dictTypeRequest);
PageResult<SysDictType> dictTypePageList = dictTypeService.findPage(dictTypeRequest);
return new SuccessResponseData(dictTypePageList);
}

View File

@ -104,7 +104,7 @@ public class SysDict extends BaseEntity {
private transient String dictTypeName;
/**
*
*
*/
private transient String parentName;

View File

@ -25,7 +25,7 @@ public interface DictMapper extends BaseMapper<SysDict> {
* @author fengshuonan
* @date 2020/10/29 17:21
*/
SysDict findDetail(@Param("dictId") Long dictId);
SysDict detail(@Param("dictId") Long dictId);
/**
*
@ -36,7 +36,7 @@ public interface DictMapper extends BaseMapper<SysDict> {
* @author fengshuonan
* @date 2020/10/29 17:21
*/
List<SysDict> findList(@Param("page") Page<SysDict> page, @Param("dictRequest") DictRequest dictRequest);
List<SysDict> findPage(@Param("page") Page<SysDict> page, @Param("dictRequest") DictRequest dictRequest);
/**
*

View File

@ -2,7 +2,7 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.stylefeng.roses.kernel.dict.modular.mapper.DictMapper">
<select id="findDetail" resultType="cn.stylefeng.roses.kernel.dict.modular.entity.SysDict" parameterType="long">
<select id="detail" resultType="cn.stylefeng.roses.kernel.dict.modular.entity.SysDict" parameterType="long">
SELECT dict.dict_id AS dictId,
dict.dict_code AS dictCode,
dict.dict_name as dictName,
@ -22,8 +22,8 @@
AND dict.dict_id = #{dictId}
</select>
<select id="findList" resultType="cn.stylefeng.roses.kernel.dict.modular.entity.SysDict">
SELECT type.dict_type_name as dictTypeName,
<select id="findPage" resultType="cn.stylefeng.roses.kernel.dict.modular.entity.SysDict">
SELECT dictType.dict_type_name as dictTypeName,
dict.dict_id AS dictId,
dict.dict_code AS dictCode,
dict.dict_encode as dictEncode,
@ -36,14 +36,11 @@
dict.dict_parent_id AS dictParentId,
dict.status_flag AS statusFlag,
dict.create_time AS createTime,
pDict.dict_name AS parentName
parentDict.dict_name AS parentName
FROM sys_dict dict
INNER JOIN sys_dict_type type ON dict.dict_type_code = type.dict_type_code
LEFT JOIN sys_dict pDict ON pDict.dict_id = dict.dict_parent_id
INNER JOIN sys_dict_type dictType ON dict.dict_type_code = dictType.dict_type_code
LEFT JOIN sys_dict parentDict ON parentDict.dict_id = dict.dict_parent_id
WHERE dict.del_flag = 'N'
<if test="dictRequest.statusFlag != null and dictRequest.statusFlag != ''">
AND dict.status_flag = #{dictRequest.statusFlag}
</if>
<if test="dictRequest.dictTypeCode != null and dictRequest.dictTypeCode != ''">
AND dict.dict_type_code = #{dictRequest.dictTypeCode}
</if>
@ -51,11 +48,10 @@
AND dict.dict_code LIKE CONCAT('%',#{dictRequest.dictCode},'%')
</if>
<if test="dictRequest.dictName != null and dictRequest.dictName != ''">
AND
(
dict.dict_name LIKE CONCAT('%',#{dictRequest.dictName},'%')
OR
dict.dict_name_pinyin LIKE CONCAT('%',#{dictRequest.dictName},'%')
AND (
dict.dict_name LIKE CONCAT('%',#{dictRequest.dictName},'%')
OR
dict.dict_name_pinyin LIKE CONCAT('%',#{dictRequest.dictName},'%')
)
</if>
<if test="dictRequest.dictParentId != null and dictRequest.dictParentId != ''">
@ -65,7 +61,18 @@
</select>
<select id="getDictListExcludeSub" resultType="cn.stylefeng.roses.kernel.dict.modular.entity.SysDict" parameterType="long">
SELECT *
SELECT dict.dict_id AS dictId,
dict.dict_code AS dictCode,
dict.dict_encode as dictEncode,
dict.dict_sort as dictSort,
dict.dict_name as dictName,
dict.dict_name_pinyin as dictNamePinyin,
dict.dict_type_code AS dictTypeCode,
dict.dict_short_name AS dictShortName,
dict.dict_short_code AS dictShortCode,
dict.dict_parent_id AS dictParentId,
dict.status_flag AS statusFlag,
dict.create_time AS createTime
FROM sys_dict
WHERE del_flag = 'N'
AND dict_pids NOT LIKE CONCAT('%', #{dictId}, '%')
@ -78,8 +85,8 @@
<update id="updateSubPids" parameterType="cn.stylefeng.roses.kernel.dict.api.pojo.dict.request.ParentIdsUpdateRequest">
UPDATE
sys_dict
SET dict_pids = replace(dict_pids, #{paramCondition.oldParentIds}, #{paramCondition.newParentIds}),
update_time = #{paramCondition.updateTime},
SET dict_pids = replace(dict_pids, #{paramCondition.oldParentIds}, #{paramCondition.newParentIds}),
update_time = #{paramCondition.updateTime},
update_user = #{paramCondition.updateUser}
WHERE dict_pids LIKE CONCAT('%', #{paramCondition.oldParentIds}, '%')
</update>

View File

@ -5,7 +5,6 @@ import cn.stylefeng.roses.kernel.dict.api.DictApi;
import cn.stylefeng.roses.kernel.dict.modular.entity.SysDict;
import cn.stylefeng.roses.kernel.dict.modular.pojo.TreeDictInfo;
import cn.stylefeng.roses.kernel.dict.modular.pojo.request.DictRequest;
import cn.stylefeng.roses.kernel.rule.tree.ztree.ZTreeNode;
import com.baomidou.mybatisplus.extension.service.IService;
import java.util.List;
@ -25,25 +24,7 @@ public interface DictService extends IService<SysDict>, DictApi {
* @author fengshuonan
* @date 2020/10/29 17:43
*/
void addDict(DictRequest dictRequest);
/**
*
*
* @param dictRequest
* @author fengshuonan
* @date 2020/10/29 17:43
*/
void updateDict(DictRequest dictRequest);
/**
*
*
* @param dictRequest
* @author fengshuonan
* @date 2020/10/29 18:47
*/
void updateDictStatus(DictRequest dictRequest);
void add(DictRequest dictRequest);
/**
*
@ -52,7 +33,16 @@ public interface DictService extends IService<SysDict>, DictApi {
* @author fengshuonan
* @date 2020/10/29 17:43
*/
void deleteDict(DictRequest dictRequest);
void del(DictRequest dictRequest);
/**
*
*
* @param dictRequest
* @author fengshuonan
* @date 2020/10/29 17:43
*/
void edit(DictRequest dictRequest);
/**
*
@ -62,7 +52,7 @@ public interface DictService extends IService<SysDict>, DictApi {
* @author fengshuonan
* @date 2020/10/30 16:15
*/
SysDict findDetail(Long dictId);
SysDict detail(Long dictId);
/**
*
@ -82,10 +72,20 @@ public interface DictService extends IService<SysDict>, DictApi {
* @author fengshuonan
* @date 2020/10/29 18:48
*/
PageResult<SysDict> findPageList(DictRequest dictRequest);
PageResult<SysDict> findPage(DictRequest dictRequest);
/**
*
*
* <p>
* dictIddictIddictId
*
* @author fengshuonan
* @date 2020/12/11 16:35
*/
List<SysDict> getDictListExcludeSub(Long dictId);
/**
* antdv
*
* @param dictRequest
* @return
@ -104,31 +104,4 @@ public interface DictService extends IService<SysDict>, DictApi {
*/
boolean validateCodeAvailable(DictRequest dictRequest);
/**
*
* <p>
* dictIddictIddictId
*
* @author fengshuonan
* @date 2020/12/11 16:35
*/
List<SysDict> getDictListExcludeSub(Long dictId);
/**
* ztree
*
* @author huangyao
* @date 2021/1/12 14:27
*/
List<ZTreeNode> dictZTree(DictRequest dictRequest);
/**
*
*
* @param dictRequest
* @author chenjinlong
* @date 2021/1/13 10:57
*/
PageResult<SysDict> page(DictRequest dictRequest);
}

View File

@ -23,7 +23,7 @@ public interface DictTypeService extends IService<SysDictType> {
* @author fengshuonan
* @date 2020/10/29 18:55
*/
void addDictType(DictTypeRequest dictTypeRequest);
void add(DictTypeRequest dictTypeRequest);
/**
*
@ -32,7 +32,7 @@ public interface DictTypeService extends IService<SysDictType> {
* @author fengshuonan
* @date 2020/10/29 18:55
*/
void updateDictType(DictTypeRequest dictTypeRequest);
void edit(DictTypeRequest dictTypeRequest);
/**
*
@ -41,7 +41,7 @@ public interface DictTypeService extends IService<SysDictType> {
* @author fengshuonan
* @date 2020/10/29 18:56
*/
void updateDictTypeStatus(DictTypeRequest dictTypeRequest);
void editStatus(DictTypeRequest dictTypeRequest);
/**
*
@ -50,7 +50,7 @@ public interface DictTypeService extends IService<SysDictType> {
* @author fengshuonan
* @date 2020/10/29 18:55
*/
void deleteDictType(DictTypeRequest dictTypeRequest);
void del(DictTypeRequest dictTypeRequest);
/**
*
@ -60,7 +60,7 @@ public interface DictTypeService extends IService<SysDictType> {
* @author fengshuonan
* @date 2020/10/29 18:55
*/
List<SysDictType> getDictTypeList(DictTypeRequest dictTypeRequest);
List<SysDictType> findList(DictTypeRequest dictTypeRequest);
/**
*
@ -70,7 +70,7 @@ public interface DictTypeService extends IService<SysDictType> {
* @author fengshuonan
* @date 2020/10/29 18:55
*/
PageResult<SysDictType> getDictTypePageList(DictTypeRequest dictTypeRequest);
PageResult<SysDictType> findPage(DictTypeRequest dictTypeRequest);
/**
* code

View File

@ -8,6 +8,7 @@ import cn.stylefeng.roses.kernel.auth.api.context.LoginContext;
import cn.stylefeng.roses.kernel.db.api.factory.PageFactory;
import cn.stylefeng.roses.kernel.db.api.factory.PageResultFactory;
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
import cn.stylefeng.roses.kernel.dict.api.constants.DictConstants;
import cn.stylefeng.roses.kernel.dict.api.exception.DictException;
import cn.stylefeng.roses.kernel.dict.api.exception.enums.DictExceptionEnum;
import cn.stylefeng.roses.kernel.dict.api.pojo.dict.request.ParentIdsUpdateRequest;
@ -17,16 +18,13 @@ import cn.stylefeng.roses.kernel.dict.modular.pojo.TreeDictInfo;
import cn.stylefeng.roses.kernel.dict.modular.pojo.request.DictRequest;
import cn.stylefeng.roses.kernel.dict.modular.service.DictService;
import cn.stylefeng.roses.kernel.pinyin.api.PinYinApi;
import cn.stylefeng.roses.kernel.rule.constants.RuleConstants;
import cn.stylefeng.roses.kernel.rule.constants.SymbolConstant;
import cn.stylefeng.roses.kernel.rule.constants.TreeConstants;
import cn.stylefeng.roses.kernel.rule.enums.StatusEnum;
import cn.stylefeng.roses.kernel.rule.enums.YesOrNotEnum;
import cn.stylefeng.roses.kernel.rule.exception.base.ServiceException;
import cn.stylefeng.roses.kernel.rule.pojo.dict.SimpleDict;
import cn.stylefeng.roses.kernel.rule.tree.factory.DefaultTreeBuildFactory;
import cn.stylefeng.roses.kernel.rule.tree.ztree.ZTreeNode;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
@ -38,8 +36,6 @@ import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import static cn.stylefeng.roses.kernel.dict.api.constants.DictConstants.DEFAULT_DICT_PARENT_ID;
import static cn.stylefeng.roses.kernel.dict.api.exception.enums.DictExceptionEnum.DICT_CODE_REPEAT;
/**
*
@ -59,20 +55,19 @@ public class DictServiceImpl extends ServiceImpl<DictMapper, SysDict> implements
@Override
@Transactional(rollbackFor = Exception.class)
public void addDict(DictRequest dictRequest) {
public void add(DictRequest dictRequest) {
// 如果父节点为空则填充为默认的父节点id
if (dictRequest.getDictParentId() == null) {
dictRequest.setDictParentId(DEFAULT_DICT_PARENT_ID);
dictRequest.setDictParentId(DictConstants.DEFAULT_DICT_PARENT_ID);
}
// 如果父节点不为空,并且不是-1则判断父节点存不存在防止脏数据
else {
if (!DEFAULT_DICT_PARENT_ID.equals(dictRequest.getDictParentId())) {
SysDict parentSysDict = this.getById(dictRequest.getDictParentId());
if (parentSysDict == null) {
throw new DictException(DictExceptionEnum.PARENT_DICT_NOT_EXISTED, dictRequest.getDictParentId());
}
if (!DictConstants.DEFAULT_DICT_PARENT_ID.equals(dictRequest.getDictParentId())) {
DictRequest tempParam = new DictRequest();
tempParam.setDictId(dictRequest.getDictParentId());
this.querySysDict(tempParam);
}
}
@ -97,23 +92,25 @@ public class DictServiceImpl extends ServiceImpl<DictMapper, SysDict> implements
}
@Override
@Transactional(rollbackFor = Exception.class)
public void updateDict(DictRequest dictRequest) {
public void del(DictRequest dictRequest) {
//删除自己和下级
dictMapper.deleteSub(dictRequest.getDictId());
}
// 查询字典是否存在
SysDict oldSysDict = this.getById(dictRequest.getDictId());
if (oldSysDict == null) {
throw new DictException(DictExceptionEnum.DICT_NOT_EXISTED, dictRequest.getDictId());
}
@Override
@Transactional(rollbackFor = Exception.class)
public void edit(DictRequest dictRequest) {
SysDict oldSysDict = this.querySysDict(dictRequest);
// 不能修改字典类型和编码
dictRequest.setDictTypeCode(null);
dictRequest.setDictCode(null);
// 赋值pids
// 赋值pids如果更新了pid则字典的子pid都要更新
setPids(dictRequest);
if (!oldSysDict.getDictParentId().equals(dictRequest.getDictParentId())) {
updatePids(dictRequest, oldSysDict);
updateSubPids(dictRequest, oldSysDict);
}
// model转化为entity
@ -126,38 +123,8 @@ public class DictServiceImpl extends ServiceImpl<DictMapper, SysDict> implements
}
@Override
@Transactional(rollbackFor = Exception.class)
public void updateDictStatus(DictRequest dictRequest) {
// 查询对应的字典信息
SysDict sysDict = this.baseMapper.selectById(dictRequest.getDictId());
if (sysDict == null) {
throw new DictException(DictExceptionEnum.DICT_NOT_EXISTED, dictRequest.getDictId());
}
// 如果是禁用 禁用所有下级状态
if (StatusEnum.DISABLE.getCode().equals(dictRequest.getStatusFlag())) {
LambdaUpdateWrapper<SysDict> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
lambdaUpdateWrapper.like(SysDict::getDictPids, sysDict.getDictId());
lambdaUpdateWrapper.set(SysDict::getStatusFlag, dictRequest.getStatusFlag());
this.update(lambdaUpdateWrapper);
}
// 修改状态
sysDict.setStatusFlag(dictRequest.getStatusFlag());
this.updateById(sysDict);
}
@Override
public void deleteDict(DictRequest dictRequest) {
//删除自己和下级
dictMapper.deleteSub(dictRequest.getDictId());
}
@Override
public SysDict findDetail(Long dictId) {
SysDict dict = this.baseMapper.findDetail(dictId);
public SysDict detail(Long dictId) {
SysDict dict = this.baseMapper.detail(dictId);
// 获取父节点字典名称
if (dict.getDictParentId().equals(TreeConstants.DEFAULT_PARENT_ID)) {
dict.setParentName("顶级");
@ -174,21 +141,29 @@ public class DictServiceImpl extends ServiceImpl<DictMapper, SysDict> implements
dictRequest = new DictRequest();
}
return baseMapper.findList(null, dictRequest);
return baseMapper.findPage(null, dictRequest);
}
@Override
public PageResult<SysDict> findPageList(DictRequest dictRequest) {
public PageResult<SysDict> findPage(DictRequest dictRequest) {
if (dictRequest == null) {
dictRequest = new DictRequest();
}
Page<SysDict> page = PageFactory.defaultPage();
List<SysDict> list = baseMapper.findList(page, dictRequest);
List<SysDict> list = baseMapper.findPage(page, dictRequest);
page.setRecords(list);
return PageResultFactory.createPageResult(page);
}
@Override
public List<SysDict> getDictListExcludeSub(Long dictId) {
if (dictId != null) {
return dictMapper.getDictListExcludeSub(dictId);
}
return this.list();
}
@Override
public List<TreeDictInfo> getTreeDictList(DictRequest dictRequest) {
@ -232,80 +207,6 @@ public class DictServiceImpl extends ServiceImpl<DictMapper, SysDict> implements
return codeCount <= 0;
}
@Override
public List<SysDict> getDictListExcludeSub(Long dictId) {
if (dictId != null) {
return dictMapper.getDictListExcludeSub(dictId);
}
return baseMapper.findList(null, new DictRequest());
}
@Override
public List<ZTreeNode> dictZTree(DictRequest dictRequest) {
// 根据字典类型编码获取字典
LambdaQueryWrapper<SysDict> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(SysDict::getDictTypeCode, dictRequest.getDictTypeCode());
List<SysDict> dictList = this.list(queryWrapper);
// 构建ztree
ArrayList<ZTreeNode> zTreeNodes = new ArrayList<>();
for (SysDict dict : dictList) {
ZTreeNode zTreeNode = new ZTreeNode();
zTreeNode.setId(dict.getDictId());
zTreeNode.setpId(dict.getDictParentId());
zTreeNode.setName(dict.getDictName());
zTreeNode.setOpen(true);
zTreeNodes.add(zTreeNode);
}
// 创建顶级节点
zTreeNodes.add(ZTreeNode.createParent());
// 构建已选中的状态
if (ObjectUtil.isNotEmpty(dictRequest.getDictId())) {
for (ZTreeNode zTreeNode : zTreeNodes) {
if (zTreeNode.getId().equals(dictRequest.getDictId())) {
zTreeNode.setChecked(true);
}
}
}
return zTreeNodes;
}
@Override
public PageResult<SysDict> page(DictRequest dictRequest) {
LambdaQueryWrapper<SysDict> wrapper = createWrapper(dictRequest);
Page<SysDict> page = this.page(PageFactory.defaultPage(), wrapper);
return PageResultFactory.createPageResult(page);
}
@Override
public String getDictNameByDictCode(String dictCode) {
LambdaQueryWrapper<SysDict> sysDictLambdaQueryWrapper = new LambdaQueryWrapper<>();
sysDictLambdaQueryWrapper.eq(SysDict::getDictCode, dictCode);
sysDictLambdaQueryWrapper.ne(SysDict::getDelFlag, YesOrNotEnum.Y.getCode());
List<SysDict> list = this.list(sysDictLambdaQueryWrapper);
// 如果查询不到字典,则返回空串
if (list.isEmpty()) {
return StrUtil.EMPTY;
}
// 字典code存在多个重复的返回空串并打印错误日志
if (list.size() > 1) {
log.error(DICT_CODE_REPEAT.getUserTip(), "", dictCode);
return StrUtil.EMPTY;
}
String dictName = list.get(0).getDictName();
if (dictName != null) {
return dictName;
} else {
return StrUtil.EMPTY;
}
}
@Override
public String getDictName(String dictTypeCode, String dictCode) {
LambdaQueryWrapper<SysDict> sysDictLambdaQueryWrapper = new LambdaQueryWrapper<>();
@ -322,7 +223,7 @@ public class DictServiceImpl extends ServiceImpl<DictMapper, SysDict> implements
// 字典code存在多个重复的返回空串并打印错误日志
if (list.size() > 1) {
log.error(DICT_CODE_REPEAT.getUserTip(), "", dictCode);
log.error(DictExceptionEnum.DICT_CODE_REPEAT.getUserTip(), "", dictCode);
return StrUtil.EMPTY;
}
@ -374,38 +275,49 @@ public class DictServiceImpl extends ServiceImpl<DictMapper, SysDict> implements
}
/**
* pids
* pidspidspids
*
* @author fengshuonan
* @date 2020/12/11 9:48
*/
private void updatePids(DictRequest dictRequest, SysDict oldSysDict) {
String oldPids = oldSysDict.getDictPids();
oldPids = oldPids + StrUtil.COMMA + oldSysDict.getDictId();
ParentIdsUpdateRequest parentIdsUpdateRequest = createParenIdsUpdateRequest(
dictRequest.getDictPids() + StrUtil.COMMA + dictRequest.getDictId(), oldPids);
private void updateSubPids(DictRequest dictRequest, SysDict oldSysDict) {
// 被替换的表达式,也就是通过这个条件匹配当前修改的字典的所有子字典,包含子字典的字典( pids + [pid] + ,
String beReplacedRegex = oldSysDict.getDictPids()
+ SymbolConstant.LEFT_SQUARE_BRACKETS + oldSysDict.getDictId() + SymbolConstant.RIGHT_SQUARE_BRACKETS + SymbolConstant.COMMA;
// 新的表达式
String newReplace = dictRequest.getDictPids();
// 更新所有子字典的pids字段
ParentIdsUpdateRequest parentIdsUpdateRequest = createParenIdsUpdateRequest(newReplace, beReplacedRegex);
dictMapper.updateSubPids(parentIdsUpdateRequest);
}
/**
* pids
* pids
* <p>
* pidpids [-1],
* <p>
* pidpidspids + [pid] + ,
*
* @author fengshuonan
* @date 2020/12/11 9:48
*/
private void setPids(DictRequest dictRequest) {
Long dictParentId = dictRequest.getDictParentId();
if (RuleConstants.TREE_ROOT_ID.equals(dictParentId)) {
dictRequest.setDictPids(RuleConstants.TREE_ROOT_ID.toString());
if (DictConstants.DEFAULT_DICT_PARENT_ID.equals(dictParentId)) {
String pids = SymbolConstant.LEFT_SQUARE_BRACKETS + DictConstants.DEFAULT_DICT_PARENT_ID + SymbolConstant.RIGHT_SQUARE_BRACKETS + SymbolConstant.COMMA;
dictRequest.setDictPids(pids);
} else {
SysDict parentSysDict = dictMapper.selectById(dictParentId);
if (parentSysDict != null) {
dictRequest.setDictPids(parentSysDict.getDictPids() + StrUtil.COMMA + dictParentId);
String pids = parentSysDict.getDictPids() + SymbolConstant.LEFT_SQUARE_BRACKETS + dictRequest.getDictParentId() + SymbolConstant.RIGHT_SQUARE_BRACKETS + SymbolConstant.COMMA;
dictRequest.setDictPids(pids);
}
}
}
/**
*
*
@ -415,7 +327,7 @@ public class DictServiceImpl extends ServiceImpl<DictMapper, SysDict> implements
private SysDict querySysDict(DictRequest dictRequest) {
SysDict sysDict = this.getById(dictRequest.getDictId());
if (ObjectUtil.isNull(sysDict)) {
throw new ServiceException(DictExceptionEnum.DICT_TYPE_NOT_EXISTED);
throw new DictException(DictExceptionEnum.DICT_NOT_EXISTED, dictRequest.getDictId());
}
return sysDict;
}
@ -431,7 +343,7 @@ public class DictServiceImpl extends ServiceImpl<DictMapper, SysDict> implements
queryWrapper.eq(StrUtil.isNotBlank(dictRequest.getDictTypeCode()), SysDict::getDictTypeCode, dictRequest.getDictTypeCode());
queryWrapper.eq(StrUtil.isNotBlank(dictRequest.getDictCode()), SysDict::getDictCode, dictRequest.getDictCode());
queryWrapper.like(StrUtil.isNotBlank(dictRequest.getDictName()), SysDict::getDictName, dictRequest.getDictName());
queryWrapper.eq(StrUtil.isNotBlank(dictRequest.getDictTypeCode()), SysDict::getDictTypeCode, dictRequest.getDictTypeCode());
queryWrapper.ne(SysDict::getDelFlag, YesOrNotEnum.Y.getCode());
return queryWrapper;
}

View File

@ -44,7 +44,7 @@ public class DictTypeServiceImpl extends ServiceImpl<DictTypeMapper, SysDictType
private PinYinApi pinYinApi;
@Override
public void addDictType(DictTypeRequest dictTypeRequest) {
public void add(DictTypeRequest dictTypeRequest) {
// 如果是系统级字典,只允许管理员操作
validateSystemTypeClassOperate(dictTypeRequest);
@ -63,7 +63,7 @@ public class DictTypeServiceImpl extends ServiceImpl<DictTypeMapper, SysDictType
}
@Override
public void updateDictType(DictTypeRequest dictTypeRequest) {
public void edit(DictTypeRequest dictTypeRequest) {
// 如果是系统级字典,只允许管理员操作
validateSystemTypeClassOperate(dictTypeRequest);
@ -87,7 +87,7 @@ public class DictTypeServiceImpl extends ServiceImpl<DictTypeMapper, SysDictType
@Override
@Transactional(rollbackFor = Exception.class)
public void updateDictTypeStatus(DictTypeRequest dictTypeRequest) {
public void editStatus(DictTypeRequest dictTypeRequest) {
// 如果是系统级字典,只允许管理员操作
validateSystemTypeClassOperate(dictTypeRequest);
@ -114,7 +114,7 @@ public class DictTypeServiceImpl extends ServiceImpl<DictTypeMapper, SysDictType
@Override
@Transactional(rollbackFor = Exception.class)
public void deleteDictType(DictTypeRequest dictTypeRequest) {
public void del(DictTypeRequest dictTypeRequest) {
// 如果是系统级字典,只允许管理员操作
validateSystemTypeClassOperate(dictTypeRequest);
@ -137,12 +137,12 @@ public class DictTypeServiceImpl extends ServiceImpl<DictTypeMapper, SysDictType
}
@Override
public List<SysDictType> getDictTypeList(DictTypeRequest dictTypeRequest) {
public List<SysDictType> findList(DictTypeRequest dictTypeRequest) {
return this.baseMapper.findList(null, dictTypeRequest);
}
@Override
public PageResult<SysDictType> getDictTypePageList(DictTypeRequest dictTypeRequest) {
public PageResult<SysDictType> findPage(DictTypeRequest dictTypeRequest) {
Page<SysDictType> page = PageFactory.defaultPage();