diff --git a/cloud-common-plugin/src/main/java/com/cm/common/plugin/pojo/dtos/datadictionary/DataDictionaryDTO.java b/cloud-common-plugin/src/main/java/com/cm/common/plugin/pojo/dtos/datadictionary/DataDictionaryDTO.java index 4601605..21f50c0 100644 --- a/cloud-common-plugin/src/main/java/com/cm/common/plugin/pojo/dtos/datadictionary/DataDictionaryDTO.java +++ b/cloud-common-plugin/src/main/java/com/cm/common/plugin/pojo/dtos/datadictionary/DataDictionaryDTO.java @@ -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 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 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('}'); diff --git a/cloud-common-plugin/src/main/java/com/cm/common/plugin/pojo/vos/datadictionary/DataDictionaryVO.java b/cloud-common-plugin/src/main/java/com/cm/common/plugin/pojo/vos/datadictionary/DataDictionaryVO.java index 1af64c0..3a35006 100644 --- a/cloud-common-plugin/src/main/java/com/cm/common/plugin/pojo/vos/datadictionary/DataDictionaryVO.java +++ b/cloud-common-plugin/src/main/java/com/cm/common/plugin/pojo/vos/datadictionary/DataDictionaryVO.java @@ -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(); } diff --git a/cloud-common-plugin/src/main/java/com/cm/common/plugin/service/datadictionary/impl/DataDictionaryServiceImpl.java b/cloud-common-plugin/src/main/java/com/cm/common/plugin/service/datadictionary/impl/DataDictionaryServiceImpl.java new file mode 100644 index 0000000..6d3610b --- /dev/null +++ b/cloud-common-plugin/src/main/java/com/cm/common/plugin/service/datadictionary/impl/DataDictionaryServiceImpl.java @@ -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 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 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 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 params = super.getHashMap(1); + params.put("dictionaryId", dictionaryId); + return dictionaryDao.getDictionary(params); + } + + @Override + public List listDictionaryByParentId(String dictionaryParentId) throws SearchException { + Map params = getHashMap(1); + params.put("dictionaryParentId", dictionaryParentId); + return dictionaryDao.listDictionary(params); + } + + @Override + public List listDictionaryAllByParentId(String dictionaryParentId) throws SearchException { + Map params = getHashMap(1); + params.put("dictionaryParentId", dictionaryParentId); + List dictionaryDTOs = dictionaryDao.listDictionary(params); + listSubDictionarys(dictionaryDTOs, params); + return dictionaryDTOs; + } + + @Override + public SuccessResultList> listPageDictionary(ListPage page) throws SearchException { + PageHelper.startPage(page.getPage(), page.getRows()); + List dictionaryDTOs = dictionaryDao.listDictionary(page.getParams()); + PageInfo pageInfo = new PageInfo<>(dictionaryDTOs); + return new SuccessResultList<>(dictionaryDTOs, pageInfo.getPageNum(), page.getTotal()); + } + + @Override + public List listZTreeDictionary(Map params) throws SearchException { + List 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 dictionaryDTOs, Map params) throws SearchException { + for (DataDictionaryDTO dictionaryDTO : dictionaryDTOs) { + params.put("dictionaryParentId", dictionaryDTO.getDictionaryId()); + List 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); + } +} diff --git a/cloud-common-plugin/src/main/resources/mybatis/mapper/datadictionary/datadictionary-mapper.xml b/cloud-common-plugin/src/main/resources/mybatis/mapper/datadictionary/datadictionary-mapper.xml index 668fd1c..d4cdfa6 100644 --- a/cloud-common-plugin/src/main/resources/mybatis/mapper/datadictionary/datadictionary-mapper.xml +++ b/cloud-common-plugin/src/main/resources/mybatis/mapper/datadictionary/datadictionary-mapper.xml @@ -9,6 +9,7 @@ + @@ -19,12 +20,13 @@ - 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 - sys_dictionary + data_dictionary SET is_delete = 1, modifier = #{modifier}, @@ -62,7 +65,7 @@ UPDATE - sys_dictionary + data_dictionary SET dictionary_name = #{dictionaryName}, @@ -72,6 +75,9 @@ dictionary_summary = #{dictionarySummary}, + + + dictionary_sort = #{dictionarySort}, modifier = #{modifier}, gmt_modified = #{gmtModified} @@ -84,13 +90,15 @@ SELECT * FROM - sys_dictionary + data_dictionary WHERE is_delete = 0 AND dictionary_parent_id = #{dictionaryParentId} + ORDER BY + dictionary_sort, dictionary_code @@ -98,7 +106,7 @@ SELECT * FROM - sys_dictionary + data_dictionary WHERE is_delete = 0 @@ -124,21 +132,8 @@ #{dictionaryIds[${index}]} - - - ORDER BY - - dictionary_name ${order} - - - dictionary_code ${order} - - - - ORDER BY - gmt_create desc - - + ORDER BY + dictionary_sort, dictionary_code @@ -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 diff --git a/cloud-common-plugin/src/main/resources/templates/datadictionary/list.html b/cloud-common-plugin/src/main/resources/templates/datadictionary/list.html index df367c1..83a9910 100644 --- a/cloud-common-plugin/src/main/resources/templates/datadictionary/list.html +++ b/cloud-common-plugin/src/main/resources/templates/datadictionary/list.html @@ -80,13 +80,16 @@ pageName: 'page', limitName: 'rows' }, - cols: [[ - {type:'checkbox', fixed: 'left'}, - {field:'rowNum', width:80, title: '序号', fixed: 'left', align:'center', templet: '{{d.LAY_INDEX}}'}, - {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: '{{d.LAY_INDEX}}'}, + {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 { diff --git a/cloud-common-plugin/src/main/resources/templates/datadictionary/save.html b/cloud-common-plugin/src/main/resources/templates/datadictionary/save.html index fc4d48b..bf7ad13 100644 --- a/cloud-common-plugin/src/main/resources/templates/datadictionary/save.html +++ b/cloud-common-plugin/src/main/resources/templates/datadictionary/save.html @@ -40,6 +40,12 @@ +
+ +
+ +
+
diff --git a/cloud-common-plugin/src/main/resources/templates/datadictionary/update.html b/cloud-common-plugin/src/main/resources/templates/datadictionary/update.html index 8e41bf8..1a2e834 100644 --- a/cloud-common-plugin/src/main/resources/templates/datadictionary/update.html +++ b/cloud-common-plugin/src/main/resources/templates/datadictionary/update.html @@ -40,6 +40,12 @@
+
+ +
+ +
+