①字典列表,配置编码移到配置内容前一列
②系统字典与业务字典的item_code字段int类型改为varchar(64)
③业务字典和系统字典表增加一个字段,level_no,层级(新增、修改已加入)
④完成条件分页查询(折叠逻辑与无条件查询一致,)
⑤优化分页查询代码(预留介入条件排序),
待完善:修改、删除时下层级递归处理待添加事务性及测试(待手动抛异常重点测试)
生效范围测试尚未完毕,待处理
jquery Validate验证层级关系受<sys:treeselect>影响,待处理
样式调整:分页样式(尚未调整),
461 lines
14 KiB
Java
461 lines
14 KiB
Java
package com.nis.web.service.basics;
|
||
|
||
import java.util.Date;
|
||
import java.util.List;
|
||
|
||
import org.springframework.beans.factory.annotation.Autowired;
|
||
import org.springframework.stereotype.Service;
|
||
|
||
import com.google.common.collect.Lists;
|
||
import com.nis.domain.Page;
|
||
import com.nis.domain.SysMenu;
|
||
import com.nis.domain.SysUser;
|
||
import com.nis.domain.basics.ServiceDictInfo;
|
||
import com.nis.util.Constants;
|
||
import com.nis.util.StringUtil;
|
||
import com.nis.web.dao.basics.ServiceDictInfoDao;
|
||
import com.nis.web.security.UserUtils;
|
||
import com.nis.web.service.BaseService;
|
||
|
||
@Service
|
||
public class ServiceDictInfoService extends BaseService{
|
||
|
||
@Autowired
|
||
private ServiceDictInfoDao serviceDictInfoDao;
|
||
|
||
/**
|
||
* 查询业务字典分页(无条件查询)
|
||
* @param page
|
||
* @param serviceDictInfo
|
||
* @return
|
||
*/
|
||
public Page<ServiceDictInfo> findTopDictList(Page<ServiceDictInfo> page, ServiceDictInfo serviceDictInfo,Integer[] itType) {
|
||
// 设置分页参数
|
||
serviceDictInfo.setPage(page);
|
||
List<ServiceDictInfo> parentList = Lists.newArrayList();
|
||
Integer tempType = 0;
|
||
if(serviceDictInfo.getItemType()!=null){
|
||
tempType = serviceDictInfo.getItemType();
|
||
}
|
||
//查出顶层分页查询
|
||
if(itType.length==1){
|
||
serviceDictInfo.setItemType(itType[0]);
|
||
parentList = serviceDictInfoDao.findTopDictList(serviceDictInfo);
|
||
}
|
||
if(itType.length==2){
|
||
if(tempType!=0){
|
||
parentList = serviceDictInfoDao.findTopDictList(serviceDictInfo);
|
||
}else{
|
||
List<Integer> tempList = Lists.newArrayList();
|
||
tempList.add(1);tempList.add(2);tempList.add(3);
|
||
//Map<String,String> map = DictUtils.getDictOption("SERVICE_DICT_ITM_TYPE");
|
||
if(tempList.contains(itType[0])){
|
||
tempList.remove(itType[0]);
|
||
}
|
||
if(tempList.contains(itType[1])){
|
||
tempList.remove(itType[1]);
|
||
}
|
||
serviceDictInfo.setItemType(tempList.get(0));
|
||
parentList = serviceDictInfoDao.findTopDictListN(serviceDictInfo);
|
||
}
|
||
|
||
}
|
||
|
||
|
||
page.setList(parentList);
|
||
return page;
|
||
}
|
||
/**
|
||
* 查询所有有效字典配置
|
||
* @return
|
||
*/
|
||
public List<ServiceDictInfo> findAllDictList() {
|
||
|
||
return serviceDictInfoDao.findAllDictList(new ServiceDictInfo());
|
||
}
|
||
|
||
/**
|
||
* 查询该类型所有的非叶子配置
|
||
*/
|
||
public List<ServiceDictInfo> findAllNoLeafDictList(String itType) {
|
||
List<ServiceDictInfo> list = Lists.newArrayList();
|
||
String[] strArr = itType.split("-");
|
||
Integer[] intArr = new Integer[strArr.length];
|
||
for(int i=0;i<strArr.length;i++){
|
||
intArr[i] = Integer.valueOf(strArr[i]);
|
||
List<ServiceDictInfo> tempList = serviceDictInfoDao.findAllNoLeafDictList(intArr[i]);
|
||
for(ServiceDictInfo serviceDictInfo:tempList){
|
||
list.add(serviceDictInfo);
|
||
}
|
||
}
|
||
return list;
|
||
}
|
||
/**
|
||
* 查询条件查询顶层分页(含条件查询,考虑排序接入可行性)
|
||
* @param page
|
||
* @param serviceDictInfo
|
||
* @param itType
|
||
* @return
|
||
*/
|
||
public Page<ServiceDictInfo> findDictTopSearchList(Page<ServiceDictInfo> page, ServiceDictInfo serviceDictInfo, Integer[] itType) {
|
||
// 设置分页参数
|
||
serviceDictInfo.setPage(page);
|
||
//根据条件查询符合数据
|
||
List<ServiceDictInfo> allList = Lists.newArrayList();
|
||
List<ServiceDictInfo> list = Lists.newArrayList();
|
||
Integer tempType = 0;
|
||
if(serviceDictInfo.getItemType()!=null){
|
||
tempType = serviceDictInfo.getItemType();
|
||
}
|
||
if(itType.length==1){
|
||
serviceDictInfo.setItemType(itType[0]);
|
||
allList = serviceDictInfoDao.findDictTopSearchList(serviceDictInfo);
|
||
}
|
||
if(itType.length==2){
|
||
if(tempType!=0){
|
||
allList = serviceDictInfoDao.findDictTopSearchList(serviceDictInfo);
|
||
}else{
|
||
List<Integer> tempIntegerList = Lists.newArrayList();
|
||
tempIntegerList.add(1);tempIntegerList.add(2);tempIntegerList.add(3);
|
||
//Map<String,String> map = DictUtils.getDictOption("SERVICE_DICT_ITM_TYPE");
|
||
if(tempIntegerList.contains(itType[0])){
|
||
tempIntegerList.remove(itType[0]);
|
||
}
|
||
if(tempIntegerList.contains(itType[1])){
|
||
tempIntegerList.remove(itType[1]);
|
||
}
|
||
serviceDictInfo.setItemType(tempIntegerList.get(0));
|
||
allList = serviceDictInfoDao.findDictTopSearchListN(serviceDictInfo);
|
||
}
|
||
|
||
}
|
||
ServiceDictInfo tempSe = new ServiceDictInfo();
|
||
tempSe.setServiceDictId(0);
|
||
for(ServiceDictInfo se:allList){
|
||
se.setParent(tempSe);
|
||
}
|
||
page.setList(allList);
|
||
|
||
|
||
/*//根据条件查询符合数据
|
||
List<ServiceDictInfo> allList = Lists.newArrayList();
|
||
List<Integer> tempList = Lists.newArrayList();
|
||
List<ServiceDictInfo> list = Lists.newArrayList();
|
||
List<ServiceDictInfo> listChild = Lists.newArrayList();
|
||
List<ServiceDictInfo> listParent = Lists.newArrayList();
|
||
Integer tempType = 0;
|
||
Integer total = 0;
|
||
Integer pageCount = 0;
|
||
Integer lostCount = 0;
|
||
if(serviceDictInfo.getItemType()!=null){
|
||
tempType = serviceDictInfo.getItemType();
|
||
}
|
||
if(itType.length==1){
|
||
serviceDictInfo.setItemType(itType[0]);
|
||
allList = serviceDictInfoDao.findDictSearchList(serviceDictInfo);
|
||
}
|
||
if(itType.length==2){
|
||
if(tempType!=0){
|
||
allList = serviceDictInfoDao.findDictSearchList(serviceDictInfo);
|
||
}else{
|
||
List<Integer> tempIntegerList = Lists.newArrayList();
|
||
tempIntegerList.add(1);tempIntegerList.add(2);tempIntegerList.add(3);
|
||
//Map<String,String> map = DictUtils.getDictOption("SERVICE_DICT_ITM_TYPE");
|
||
if(tempIntegerList.contains(itType[0])){
|
||
tempIntegerList.remove(itType[0]);
|
||
}
|
||
if(tempIntegerList.contains(itType[1])){
|
||
tempIntegerList.remove(itType[1]);
|
||
}
|
||
serviceDictInfo.setItemType(tempIntegerList.get(0));
|
||
allList = serviceDictInfoDao.findDictSearchListN(serviceDictInfo);
|
||
}
|
||
|
||
}
|
||
|
||
//处理数据
|
||
//page.list中有多少个不是page.list中的顶层(其上级在page.list)
|
||
ServiceDictInfo tempSe = new ServiceDictInfo();
|
||
tempSe.setServiceDictId(0);
|
||
//取出主键优化处理
|
||
for(ServiceDictInfo se:allList){
|
||
if(se!=null&&se.getServiceDictId()!=null){
|
||
tempList.add(se.getServiceDictId());
|
||
}
|
||
}
|
||
|
||
for(ServiceDictInfo se:allList){
|
||
if(se!=null&&se.getParent()!=null&&se.getParent().getServiceDictId()!=null){
|
||
//ServiceDictInfo temp = serviceDictInfoDao.getDictById(se.getParent().getServiceDictId());
|
||
if(tempList.contains(se.getParent().getServiceDictId())){
|
||
listChild.add(se);
|
||
lostCount+=lostCount;
|
||
}else{
|
||
se.setParent(tempSe);
|
||
listParent.add(se);
|
||
}
|
||
}
|
||
}
|
||
|
||
//确定总页数
|
||
total = allList.size() - lostCount;
|
||
pageCount = total%page.getPageSize()==0?total%page.getPageSize():(total%page.getPageSize()+1);
|
||
if(pageCount==0){
|
||
pageCount=1;
|
||
}
|
||
//取出所有的顶层
|
||
//获取分页 每页数量pageSize、、当前页数pageNo (排序,,,) 每页第一个(pageNo-1)*pageSize+1 最后一个pageNo*pageSize
|
||
List<ServiceDictInfo> parentShow = Lists.newArrayList();
|
||
for(int i=0;i<listParent.size();i++){
|
||
if(i>=((page.getPageNo()-1)*page.getPageSize())&&i<page.getPageNo()*page.getPageSize()){
|
||
parentShow.add(listParent.get(i));
|
||
}
|
||
}
|
||
parentShow.addAll(listChild);
|
||
|
||
ServiceDictInfo.sortList(list,parentShow,0,true);
|
||
|
||
page.setList(list);*/
|
||
return page;
|
||
}
|
||
/**
|
||
* 条件查询所有数据
|
||
* @param serviceDictInfo
|
||
* @param itType
|
||
* @return
|
||
*/
|
||
public List<ServiceDictInfo> findAllDictSearchList(ServiceDictInfo serviceDictInfo,Integer[] itType){
|
||
List<ServiceDictInfo> list = Lists.newArrayList();
|
||
Integer tempType = 0;
|
||
if(serviceDictInfo.getItemType()!=null){
|
||
tempType = serviceDictInfo.getItemType();
|
||
}
|
||
if(itType.length==1){
|
||
serviceDictInfo.setItemType(itType[0]);
|
||
list = serviceDictInfoDao.findAllDictSearchList(serviceDictInfo);
|
||
}
|
||
if(itType.length==2){
|
||
if(tempType!=0){
|
||
list = serviceDictInfoDao.findAllDictSearchList(serviceDictInfo);
|
||
}else{
|
||
List<Integer> tempIntegerList = Lists.newArrayList();
|
||
tempIntegerList.add(1);tempIntegerList.add(2);tempIntegerList.add(3);
|
||
//Map<String,String> map = DictUtils.getDictOption("SERVICE_DICT_ITM_TYPE");
|
||
if(tempIntegerList.contains(itType[0])){
|
||
tempIntegerList.remove(itType[0]);
|
||
}
|
||
if(tempIntegerList.contains(itType[1])){
|
||
tempIntegerList.remove(itType[1]);
|
||
}
|
||
serviceDictInfo.setItemType(tempIntegerList.get(0));
|
||
list = serviceDictInfoDao.findAllDictSearchListN(serviceDictInfo);
|
||
}
|
||
}
|
||
if(tempType!=0){
|
||
serviceDictInfo.setItemType(tempType);
|
||
}else{
|
||
serviceDictInfo.setItemType(null);
|
||
}
|
||
return list;
|
||
}
|
||
|
||
|
||
|
||
|
||
/**
|
||
* 根据主键查询字典详细信息
|
||
* @param serviceDictId
|
||
* @return
|
||
*/
|
||
public ServiceDictInfo getDictById(Integer serviceDictId) {
|
||
return serviceDictInfoDao.getDictById(serviceDictId);
|
||
}
|
||
|
||
/**
|
||
* 根据上级id选出所有下级
|
||
* @param parentId
|
||
* @return
|
||
*/
|
||
public List<ServiceDictInfo> getDictByParentId(Integer parentId) {
|
||
|
||
return serviceDictInfoDao.getDictByParentId(parentId);
|
||
}
|
||
|
||
/**
|
||
* 新增或修改业务字典表(添加层级改变)
|
||
* @param serviceDictInfo
|
||
*/
|
||
public void saveOrUpdate(ServiceDictInfo serviceDictInfo) {
|
||
if(serviceDictInfo.getParent()==null
|
||
||(serviceDictInfo.getParent()!=null&&serviceDictInfo.getParent().getServiceDictId()==null)
|
||
||(serviceDictInfo.getParent()!=null&&serviceDictInfo.getParent().getServiceDictId()==-1)
|
||
||(serviceDictInfo.getParent()!=null&&serviceDictInfo.getParent().getServiceDictId()==0)
|
||
){
|
||
ServiceDictInfo parent = new ServiceDictInfo();
|
||
parent.setServiceDictId(0);
|
||
parent.setLevelNo(0);
|
||
serviceDictInfo.setParent(parent);
|
||
}
|
||
if(serviceDictInfo.getParent().getServiceDictId()!=0){
|
||
ServiceDictInfo parent = serviceDictInfoDao.getDictById(serviceDictInfo.getParent().getServiceDictId());
|
||
serviceDictInfo.setParent(parent);
|
||
}
|
||
SysUser user = UserUtils.getUser();
|
||
if(StringUtil.isEmpty(serviceDictInfo.getServiceDictId())) {//新增
|
||
serviceDictInfo.setLevelNo(serviceDictInfo.getParent().getLevelNo()+1);
|
||
serviceDictInfo.setIsValid(1);
|
||
serviceDictInfo.setServiceDictCreator(user);
|
||
serviceDictInfo.setCreateTime(new Date());
|
||
serviceDictInfo.setServiceDictEditor(user);
|
||
serviceDictInfo.setEditTime(serviceDictInfo.getCreateTime());
|
||
serviceDictInfoDao.insertDict(serviceDictInfo);
|
||
}
|
||
else {//修改
|
||
List<ServiceDictInfo> resultList = Lists.newArrayList();
|
||
List<ServiceDictInfo> list = serviceDictInfoDao.getDictByParentId(serviceDictInfo.getServiceDictId());
|
||
|
||
//处理层级
|
||
if(serviceDictInfo.getParent().getServiceDictId()==0){
|
||
serviceDictInfo.setLevelNo(1);
|
||
//处理子集
|
||
childLevel(serviceDictInfo,list,resultList);
|
||
}else{
|
||
serviceDictInfo.setLevelNo(serviceDictInfo.getParent().getLevelNo()+1);
|
||
//处理子集
|
||
childLevel(serviceDictInfo,list,resultList);
|
||
}
|
||
serviceDictInfo.setServiceDictEditor(user);
|
||
serviceDictInfo.setEditTime(new Date());
|
||
for(ServiceDictInfo sc:resultList){
|
||
serviceDictInfoDao.updateLevelNo(sc);
|
||
}
|
||
serviceDictInfoDao.update(serviceDictInfo);
|
||
}
|
||
|
||
}
|
||
|
||
|
||
//处理子集层级
|
||
|
||
public void childLevel(ServiceDictInfo serviceDictInfo, List<ServiceDictInfo> list,List<ServiceDictInfo> resultList){
|
||
for(ServiceDictInfo se:list){
|
||
se.setLevelNo(serviceDictInfo.getLevelNo()+1);
|
||
resultList.add(se);
|
||
List<ServiceDictInfo> newList = serviceDictInfoDao.getDictByParentId(se.getServiceDictId());
|
||
childLevel(se,newList,resultList);
|
||
}
|
||
|
||
}
|
||
|
||
/**
|
||
* 删除
|
||
* @param serviceDictInfo
|
||
*/
|
||
public void deleteDict(ServiceDictInfo serviceDictInfo) {
|
||
List<ServiceDictInfo> list = Lists.newArrayList();
|
||
//找出所有下级
|
||
//查出所有节点
|
||
ServiceDictInfo.sortList(list, serviceDictInfoDao.findAllDictList(new ServiceDictInfo()), serviceDictInfo.getServiceDictId(), true);
|
||
list.add(serviceDictInfo);
|
||
for(ServiceDictInfo se:list){
|
||
se.setIsValid(0);
|
||
serviceDictInfoDao.delete(se);
|
||
}
|
||
|
||
}
|
||
|
||
/**
|
||
* 根据itemCode查出对象集合
|
||
*/
|
||
public List<ServiceDictInfo> findByItemCode(String itemCode){
|
||
return serviceDictInfoDao.findByItemCode(itemCode);
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
|
||
/**
|
||
*
|
||
* findFlDict(查找所有有效的分类)
|
||
* (这里描述这个方法适用条件 – 可选)
|
||
* @return
|
||
*List<ServiceDictInfo>
|
||
* @exception
|
||
* @since 1.0.0
|
||
*/
|
||
public List<ServiceDictInfo> findFlDict() {
|
||
return serviceDictInfoDao.findItemDict(Constants.ITEM_TYPE_FL,Constants.VALID_YES);
|
||
}
|
||
/**
|
||
*
|
||
* findFlDict(查找所有有效的分类)
|
||
* (这里描述这个方法适用条件 – 可选)
|
||
* @return
|
||
*List<ServiceDictInfo>
|
||
* @exception
|
||
* @since 1.0.0
|
||
*/
|
||
public List<ServiceDictInfo> findAllFlDict() {
|
||
return serviceDictInfoDao.findAllItemDict(Constants.ITEM_TYPE_FL);
|
||
}
|
||
/**
|
||
*
|
||
* findFlDict(查找所有有效的性质)
|
||
* (这里描述这个方法适用条件 – 可选)
|
||
* @return
|
||
*List<ServiceDictInfo>
|
||
* @exception
|
||
* @since 1.0.0
|
||
*/
|
||
public List<ServiceDictInfo> findXzDict() {
|
||
return serviceDictInfoDao.findItemDict(Constants.ITEM_TYPE_XZ,Constants.VALID_YES);
|
||
}
|
||
/**
|
||
*
|
||
* findFlDict(查找所有有效的性质)
|
||
* (这里描述这个方法适用条件 – 可选)
|
||
* @return
|
||
*List<ServiceDictInfo>
|
||
* @exception
|
||
* @since 1.0.0
|
||
*/
|
||
public List<ServiceDictInfo> findAllXzDict() {
|
||
return serviceDictInfoDao.findAllItemDict(Constants.ITEM_TYPE_XZ);
|
||
}
|
||
/**
|
||
*
|
||
* findFlDict(查找所有有效的标签)
|
||
* (这里描述这个方法适用条件 – 可选)
|
||
* @return
|
||
*List<ServiceDictInfo>
|
||
* @exception
|
||
* @since 1.0.0
|
||
*/
|
||
public List<ServiceDictInfo> findLableDict() {
|
||
return serviceDictInfoDao.findItemDict(Constants.ITEM_TYPE_LABEL,Constants.VALID_YES);
|
||
}
|
||
|
||
/**
|
||
*
|
||
* findFlDict(查找所有有效的标签)
|
||
* (这里描述这个方法适用条件 – 可选)
|
||
* @return
|
||
*List<ServiceDictInfo>
|
||
* @exception
|
||
* @since 1.0.0
|
||
*/
|
||
public List<ServiceDictInfo> findAllLableDict() {
|
||
return serviceDictInfoDao.findAllItemDict(Constants.ITEM_TYPE_LABEL);
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
}
|