新增数据字典
This commit is contained in:
parent
7b1c7929c3
commit
4fb53d60fc
@ -33,6 +33,8 @@ public class DataDictionaryDTO {
|
||||
private String dictionarySummary;
|
||||
@ApiModelProperty(name = "dictionaryCode", value = "字典编码")
|
||||
private String dictionaryCode;
|
||||
@ApiModelProperty(name = "dictionarySort", value = "字典排序")
|
||||
private String dictionarySort;
|
||||
@ApiModelProperty(name = "subDictionary", value = "子字典列表")
|
||||
private List<DataDictionaryDTO> subDictionary;
|
||||
|
||||
@ -92,6 +94,14 @@ public class DataDictionaryDTO {
|
||||
this.dictionaryCode = dictionaryCode;
|
||||
}
|
||||
|
||||
public String getDictionarySort() {
|
||||
return dictionarySort == null ? "" : dictionarySort.trim();
|
||||
}
|
||||
|
||||
public void setDictionarySort(String dictionarySort) {
|
||||
this.dictionarySort = dictionarySort;
|
||||
}
|
||||
|
||||
public List<DataDictionaryDTO> getSubDictionary() {
|
||||
if (subDictionary == null) {
|
||||
return new ArrayList<>();
|
||||
@ -106,20 +116,22 @@ public class DataDictionaryDTO {
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder sb = new StringBuilder("{");
|
||||
sb.append("\"dictionaryId\":\"")
|
||||
.append(dictionaryId).append('\"');
|
||||
sb.append(",\"dictionaryParentId\":\"")
|
||||
.append(dictionaryParentId).append('\"');
|
||||
sb.append(",\"dictionaryParentName\":\"")
|
||||
.append(dictionaryParentName).append('\"');
|
||||
sb.append("\"dictionaryId\":")
|
||||
.append("\"").append(dictionaryId).append("\"");
|
||||
sb.append(",\"dictionaryParentId\":")
|
||||
.append("\"").append(dictionaryParentId).append("\"");
|
||||
sb.append(",\"dictionaryParentName\":")
|
||||
.append("\"").append(dictionaryParentName).append("\"");
|
||||
sb.append(",\"isParent\":")
|
||||
.append(isParent);
|
||||
sb.append(",\"dictionaryName\":\"")
|
||||
.append(dictionaryName).append('\"');
|
||||
sb.append(",\"dictionarySummary\":\"")
|
||||
.append(dictionarySummary).append('\"');
|
||||
sb.append(",\"dictionaryCode\":\"")
|
||||
.append(dictionaryCode).append('\"');
|
||||
sb.append(",\"dictionaryName\":")
|
||||
.append("\"").append(dictionaryName).append("\"");
|
||||
sb.append(",\"dictionarySummary\":")
|
||||
.append("\"").append(dictionarySummary).append("\"");
|
||||
sb.append(",\"dictionaryCode\":")
|
||||
.append("\"").append(dictionaryCode).append("\"");
|
||||
sb.append(",\"dictionarySort\":")
|
||||
.append("\"").append(dictionarySort).append("\"");
|
||||
sb.append(",\"subDictionary\":")
|
||||
.append(subDictionary);
|
||||
sb.append('}');
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.cm.common.plugin.pojo.vos.datadictionary;
|
||||
|
||||
import com.cm.common.annotation.CheckEmptyAnnotation;
|
||||
import com.cm.common.annotation.CheckNumberAnnotation;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
@ -22,6 +23,9 @@ public class DataDictionaryVO {
|
||||
private String dictionaryName;
|
||||
@ApiModelProperty(name = "dictionarySummary", value = "字典说明")
|
||||
private String dictionarySummary;
|
||||
@ApiModelProperty(name = "dictionarySort", value = "字典排序")
|
||||
@CheckNumberAnnotation(name = "字典排序")
|
||||
private Integer dictionarySort;
|
||||
|
||||
public String getDictionaryParentId() {
|
||||
return dictionaryParentId == null ? "" : dictionaryParentId;
|
||||
@ -47,15 +51,25 @@ public class DataDictionaryVO {
|
||||
this.dictionarySummary = dictionarySummary;
|
||||
}
|
||||
|
||||
public Integer getDictionarySort() {
|
||||
return dictionarySort;
|
||||
}
|
||||
|
||||
public void setDictionarySort(Integer dictionarySort) {
|
||||
this.dictionarySort = dictionarySort;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder sb = new StringBuilder("{");
|
||||
sb.append("\"dictionaryParentId\":\"")
|
||||
.append(dictionaryParentId).append('\"');
|
||||
sb.append(",\"dictionaryName\":\"")
|
||||
.append(dictionaryName).append('\"');
|
||||
sb.append(",\"dictionarySummary\":\"")
|
||||
.append(dictionarySummary).append('\"');
|
||||
sb.append("\"dictionaryParentId\":")
|
||||
.append("\"").append(dictionaryParentId).append("\"");
|
||||
sb.append(",\"dictionaryName\":")
|
||||
.append("\"").append(dictionaryName).append("\"");
|
||||
sb.append(",\"dictionarySummary\":")
|
||||
.append("\"").append(dictionarySummary).append("\"");
|
||||
sb.append(",\"dictionarySort\":")
|
||||
.append(dictionarySort);
|
||||
sb.append('}');
|
||||
return sb.toString();
|
||||
}
|
||||
|
@ -0,0 +1,146 @@
|
||||
package com.cm.common.plugin.service.datadictionary.impl;
|
||||
|
||||
import com.cm.common.base.AbstractService;
|
||||
import com.cm.common.constants.ISystemConstant;
|
||||
import com.cm.common.exception.RemoveException;
|
||||
import com.cm.common.exception.SearchException;
|
||||
import com.cm.common.plugin.dao.datadictionary.IDataDictionaryDao;
|
||||
import com.cm.common.plugin.pojo.dtos.datadictionary.DataDictionaryDTO;
|
||||
import com.cm.common.plugin.pojo.vos.datadictionary.DataDictionaryVO;
|
||||
import com.cm.common.plugin.service.datadictionary.IDataDictionaryService;
|
||||
import com.cm.common.pojo.ListPage;
|
||||
import com.cm.common.pojo.dtos.ZTreeDTO;
|
||||
import com.cm.common.result.SuccessResult;
|
||||
import com.cm.common.result.SuccessResultList;
|
||||
import com.cm.common.utils.HashMapUtil;
|
||||
import com.cm.common.utils.UUIDUtil;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* When you feel like quitting. Think about why you started
|
||||
* 当你想要放弃的时候,想想当初你为何开始
|
||||
*
|
||||
* @ClassName: DictionaryServiceImpl
|
||||
* @Description: 字典
|
||||
* @Author: WangGeng
|
||||
* @Date: 2019/11/18 14:09
|
||||
* @Version: 1.0
|
||||
**/
|
||||
@Service
|
||||
public class DataDictionaryServiceImpl extends AbstractService implements IDataDictionaryService {
|
||||
|
||||
@Autowired
|
||||
private IDataDictionaryDao dictionaryDao;
|
||||
|
||||
@Override
|
||||
public SuccessResult saveDictionary(DataDictionaryVO dictionaryVO) throws Exception {
|
||||
String parentCode = null;
|
||||
String dictionaryParentId = dictionaryVO.getDictionaryParentId();
|
||||
if (!StringUtils.equals(dictionaryParentId, ISystemConstant.TREE_BASE_ROOT_ID_VALUE)) {
|
||||
DataDictionaryDTO dictionaryDTO = getDictionaryById(dictionaryParentId);
|
||||
parentCode = dictionaryDTO.getDictionaryCode();
|
||||
}
|
||||
String dictionaryCode = getCode(parentCode, dictionaryParentId);
|
||||
Map<String, Object> params = HashMapUtil.beanToMap(dictionaryVO);
|
||||
params.put("dictionaryCode", dictionaryCode);
|
||||
params.put("dictionaryId", UUIDUtil.getUUID());
|
||||
setSaveInfo(params);
|
||||
dictionaryDao.saveDictionary(params);
|
||||
return new SuccessResult();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SuccessResult removeDictionary(String ids) throws RemoveException {
|
||||
Map<String, Object> params = getHashMap(3);
|
||||
params.put("dictionaryIds", Arrays.asList(ids.split("_")));
|
||||
setUpdateInfo(params);
|
||||
dictionaryDao.removeDictionary(params);
|
||||
return new SuccessResult();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SuccessResult updateDictionary(String dictionaryId, DataDictionaryVO dictionaryVO) throws Exception {
|
||||
Map<String, Object> params = HashMapUtil.beanToMap(dictionaryVO);
|
||||
params.put("dictionaryId", dictionaryId);
|
||||
setUpdateInfo(params);
|
||||
dictionaryDao.updateDictionary(params);
|
||||
return new SuccessResult();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataDictionaryDTO getDictionaryById(String dictionaryId) throws SearchException {
|
||||
Map<String, Object> params = super.getHashMap(1);
|
||||
params.put("dictionaryId", dictionaryId);
|
||||
return dictionaryDao.getDictionary(params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DataDictionaryDTO> listDictionaryByParentId(String dictionaryParentId) throws SearchException {
|
||||
Map<String, Object> params = getHashMap(1);
|
||||
params.put("dictionaryParentId", dictionaryParentId);
|
||||
return dictionaryDao.listDictionary(params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DataDictionaryDTO> listDictionaryAllByParentId(String dictionaryParentId) throws SearchException {
|
||||
Map<String, Object> params = getHashMap(1);
|
||||
params.put("dictionaryParentId", dictionaryParentId);
|
||||
List<DataDictionaryDTO> dictionaryDTOs = dictionaryDao.listDictionary(params);
|
||||
listSubDictionarys(dictionaryDTOs, params);
|
||||
return dictionaryDTOs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SuccessResultList<List<DataDictionaryDTO>> listPageDictionary(ListPage page) throws SearchException {
|
||||
PageHelper.startPage(page.getPage(), page.getRows());
|
||||
List<DataDictionaryDTO> dictionaryDTOs = dictionaryDao.listDictionary(page.getParams());
|
||||
PageInfo<DataDictionaryDTO> pageInfo = new PageInfo<>(dictionaryDTOs);
|
||||
return new SuccessResultList<>(dictionaryDTOs, pageInfo.getPageNum(), page.getTotal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ZTreeDTO> listZTreeDictionary(Map<String, Object> params) throws SearchException {
|
||||
List<ZTreeDTO> zTreeDTOs = dictionaryDao.listZTreeDictionary(params);
|
||||
for (ZTreeDTO zTreeDTO : zTreeDTOs) {
|
||||
Integer subCount = dictionaryDao.countByParentId(zTreeDTO.getId());
|
||||
setZTreeInfo(zTreeDTO, subCount);
|
||||
}
|
||||
return zTreeDTOs;
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归查询子组
|
||||
*
|
||||
* @param dictionaryDTOs
|
||||
* @param params
|
||||
*/
|
||||
private void listSubDictionarys(List<DataDictionaryDTO> dictionaryDTOs, Map<String, Object> params) throws SearchException {
|
||||
for (DataDictionaryDTO dictionaryDTO : dictionaryDTOs) {
|
||||
params.put("dictionaryParentId", dictionaryDTO.getDictionaryId());
|
||||
List<DataDictionaryDTO> subDataDictionaryDTOs = dictionaryDao.listDictionary(params);
|
||||
dictionaryDTO.setSubDictionary(subDataDictionaryDTOs);
|
||||
listSubDictionarys(subDataDictionaryDTOs, params);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取code
|
||||
*
|
||||
* @param parentCode
|
||||
* @param parentId
|
||||
* @return
|
||||
*/
|
||||
private String getCode(String parentCode, String parentId) throws SearchException {
|
||||
DataDictionaryDTO dictionaryDTO = dictionaryDao.getLastByParentId(parentId);
|
||||
String code = dictionaryDTO != null ? dictionaryDTO.getDictionaryCode() : "0000";
|
||||
return super.getNewCode(code, parentCode);
|
||||
}
|
||||
}
|
@ -9,6 +9,7 @@
|
||||
<result property="dictionaryName" column="dictionary_name"/>
|
||||
<result property="dictionarySummary" column="dictionary_summary"/>
|
||||
<result property="dictionaryCode" column="dictionary_code"/>
|
||||
<result property="dictionarySort" column="dictionary_sort"/>
|
||||
</resultMap>
|
||||
|
||||
<resultMap id="dictionaryZTreeDTO" type="com.cm.common.pojo.dtos.ZTreeDTO">
|
||||
@ -19,12 +20,13 @@
|
||||
|
||||
<!-- 新增字典 -->
|
||||
<insert id="saveDictionary" parameterType="map">
|
||||
INSERT INTO sys_dictionary(
|
||||
INSERT INTO data_dictionary(
|
||||
dictionary_id,
|
||||
dictionary_parent_id,
|
||||
dictionary_name,
|
||||
dictionary_summary,
|
||||
dictionary_code,
|
||||
dictionary_sort,
|
||||
creator,
|
||||
gmt_create,
|
||||
modifier,
|
||||
@ -36,6 +38,7 @@
|
||||
#{dictionaryName},
|
||||
#{dictionarySummary},
|
||||
#{dictionaryCode},
|
||||
#{dictionarySort},
|
||||
#{creator},
|
||||
#{gmtCreate},
|
||||
#{modifier},
|
||||
@ -47,7 +50,7 @@
|
||||
<!-- 删除字典 -->
|
||||
<update id="removeDictionary" parameterType="map">
|
||||
UPDATE
|
||||
sys_dictionary
|
||||
data_dictionary
|
||||
SET
|
||||
is_delete = 1,
|
||||
modifier = #{modifier},
|
||||
@ -62,7 +65,7 @@
|
||||
<!-- 修改字典 -->
|
||||
<update id="updateDictionary" parameterType="map">
|
||||
UPDATE
|
||||
sys_dictionary
|
||||
data_dictionary
|
||||
SET
|
||||
<if test="dictionaryName != null and dictionaryName != ''">
|
||||
dictionary_name = #{dictionaryName},
|
||||
@ -72,6 +75,9 @@
|
||||
</if>
|
||||
<if test="dictionarySummary != null">
|
||||
dictionary_summary = #{dictionarySummary},
|
||||
</if>
|
||||
<if test="dictionarySort != null">
|
||||
dictionary_sort = #{dictionarySort},
|
||||
</if>
|
||||
modifier = #{modifier},
|
||||
gmt_modified = #{gmtModified}
|
||||
@ -84,13 +90,15 @@
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
sys_dictionary
|
||||
data_dictionary
|
||||
WHERE
|
||||
is_delete = 0
|
||||
<if test="dictionaryParentId != null and dictionaryParentId != ''">
|
||||
AND
|
||||
dictionary_parent_id = #{dictionaryParentId}
|
||||
</if>
|
||||
ORDER BY
|
||||
dictionary_sort, dictionary_code
|
||||
</select>
|
||||
|
||||
<!-- 字典列表 -->
|
||||
@ -98,7 +106,7 @@
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
sys_dictionary
|
||||
data_dictionary
|
||||
WHERE
|
||||
is_delete = 0
|
||||
<if test="dictionaryParentId != null and dictionaryParentId != ''">
|
||||
@ -124,21 +132,8 @@
|
||||
#{dictionaryIds[${index}]}
|
||||
</foreach>
|
||||
</if>
|
||||
<choose>
|
||||
<when test="sort != null and (sort == 'dictionaryName' or sort == 'dictionaryCode')">
|
||||
ORDER BY
|
||||
<if test="sort == 'dictionaryName'">
|
||||
dictionary_name ${order}
|
||||
</if>
|
||||
<if test="sort == 'dictionaryCode'">
|
||||
dictionary_code ${order}
|
||||
</if>
|
||||
</when>
|
||||
<otherwise>
|
||||
ORDER BY
|
||||
gmt_create desc
|
||||
</otherwise>
|
||||
</choose>
|
||||
ORDER BY
|
||||
dictionary_sort, dictionary_code
|
||||
</select>
|
||||
|
||||
<!-- 字典详情 -->
|
||||
@ -147,9 +142,9 @@
|
||||
t1.*,
|
||||
t2.dictionary_name dictionary_parent_name
|
||||
FROM
|
||||
sys_dictionary t1
|
||||
data_dictionary t1
|
||||
LEFT JOIN
|
||||
sys_dictionary t2
|
||||
data_dictionary t2
|
||||
ON
|
||||
t1.dictionary_parent_id = t2.dictionary_id
|
||||
AND
|
||||
@ -167,7 +162,7 @@
|
||||
SELECT
|
||||
COUNT(*)
|
||||
FROM
|
||||
sys_dictionary
|
||||
data_dictionary
|
||||
WHERE
|
||||
is_delete = 0
|
||||
AND
|
||||
@ -179,7 +174,7 @@
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
sys_dictionary
|
||||
data_dictionary
|
||||
WHERE
|
||||
dictionary_parent_id = #{_parameter}
|
||||
ORDER BY
|
||||
|
@ -80,13 +80,16 @@
|
||||
pageName: 'page',
|
||||
limitName: 'rows'
|
||||
},
|
||||
cols: [[
|
||||
{type:'checkbox', fixed: 'left'},
|
||||
{field:'rowNum', width:80, title: '序号', fixed: 'left', align:'center', templet: '<span>{{d.LAY_INDEX}}</span>'},
|
||||
{field:'dictionaryName', width:170, title: '字典名称', align:'center',},
|
||||
{field:'dictionarySummary', width:170, title: '字典说明', align:'center',},
|
||||
{field:'dictionaryCode', width:170, title: '字典编码', align:'center',},
|
||||
]],
|
||||
cols: [
|
||||
[
|
||||
{type:'checkbox', fixed: 'left'},
|
||||
{field:'rowNum', width:80, title: '序号', fixed: 'left', align:'center', templet: '<span>{{d.LAY_INDEX}}</span>'},
|
||||
{field:'dictionaryName', width:170, title: '字典名称', align:'center',},
|
||||
{field:'dictionarySummary', width:170, title: '字典说明', align:'center',},
|
||||
{field:'dictionaryCode', width:170, title: '字典编码', align:'center',},
|
||||
{field:'dictionarySort', width:100, title: '字典排序', align:'center',},
|
||||
]
|
||||
],
|
||||
page: true,
|
||||
parseData: function(data) {
|
||||
return {
|
||||
|
@ -40,6 +40,12 @@
|
||||
<input type="text" name="dictionarySummary" placeholder="请输入字典说明" class="layui-input">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">排序</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="number" name="dictionarySort" lay-verify="number" placeholder="请输入字典排序" value="0" class="layui-input">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item layui-layout-admin">
|
||||
<div class="layui-input-block">
|
||||
|
@ -40,6 +40,12 @@
|
||||
<input type="text" name="dictionarySummary" placeholder="请输入字典说明" class="layui-input">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">排序</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="number" name="dictionarySort" lay-verify="number" placeholder="请输入字典排序" value="0" class="layui-input">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item layui-layout-admin">
|
||||
<div class="layui-input-block">
|
||||
|
Loading…
Reference in New Issue
Block a user