2018-03-06 10:06:42 +08:00
|
|
|
|
package com.nis.web.service.basics;
|
2018-02-22 12:46:50 +08:00
|
|
|
|
|
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
|
import org.springframework.stereotype.Service;
|
2018-03-10 18:54:05 +08:00
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
2018-02-22 12:46:50 +08:00
|
|
|
|
|
|
|
|
|
|
import com.google.common.collect.Lists;
|
|
|
|
|
|
import com.nis.domain.Page;
|
|
|
|
|
|
import com.nis.domain.SysUser;
|
2018-03-06 10:06:42 +08:00
|
|
|
|
import com.nis.domain.basics.SysDictInfo;
|
2018-03-31 17:23:11 +08:00
|
|
|
|
import com.nis.util.ConfigDictUtils;
|
|
|
|
|
|
import com.nis.util.Configurations;
|
2018-02-22 12:46:50 +08:00
|
|
|
|
import com.nis.util.StringUtil;
|
2018-03-06 10:06:42 +08:00
|
|
|
|
import com.nis.web.dao.basics.SysDictInfoDao;
|
2018-02-22 12:46:50 +08:00
|
|
|
|
import com.nis.web.security.UserUtils;
|
|
|
|
|
|
import com.nis.web.service.BaseService;
|
|
|
|
|
|
|
|
|
|
|
|
@Service
|
|
|
|
|
|
public class SysDictInfoService extends BaseService{
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
private SysDictInfoDao sysDictInfoDao;
|
|
|
|
|
|
|
2018-03-04 19:20:32 +08:00
|
|
|
|
|
|
|
|
|
|
|
2018-02-22 12:46:50 +08:00
|
|
|
|
/**
|
2018-03-31 17:23:11 +08:00
|
|
|
|
* 查询顶层分页()
|
2018-02-22 12:46:50 +08:00
|
|
|
|
* @param page
|
|
|
|
|
|
* @param sysDictInfo
|
2018-03-10 18:54:05 +08:00
|
|
|
|
* @param itType
|
2018-02-22 12:46:50 +08:00
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
2018-03-31 17:23:11 +08:00
|
|
|
|
public Page<SysDictInfo> findTopDictList(Page<SysDictInfo> page, SysDictInfo sysDictInfo, List<Integer> itType) {
|
2018-02-22 12:46:50 +08:00
|
|
|
|
// 设置分页参数
|
2018-03-21 13:43:43 +08:00
|
|
|
|
sysDictInfo.setPage(page);
|
|
|
|
|
|
//根据条件查询符合数据
|
2018-03-31 17:23:11 +08:00
|
|
|
|
sysDictInfo.setConditionType(itType);
|
|
|
|
|
|
List<SysDictInfo> allList = sysDictInfoDao.findTopDictList(sysDictInfo);
|
|
|
|
|
|
SysDictInfo tempSe = new SysDictInfo();
|
2018-03-21 13:43:43 +08:00
|
|
|
|
tempSe.setSysDictId(0);
|
|
|
|
|
|
for(SysDictInfo se:allList){
|
|
|
|
|
|
se.setParent(tempSe);
|
|
|
|
|
|
}
|
|
|
|
|
|
page.setList(allList);
|
|
|
|
|
|
return page;
|
2018-03-08 20:30:01 +08:00
|
|
|
|
}
|
2018-03-21 13:43:43 +08:00
|
|
|
|
|
|
|
|
|
|
|
2018-03-08 20:30:01 +08:00
|
|
|
|
/**
|
2018-03-31 17:23:11 +08:00
|
|
|
|
* 根据条件查询所有数据
|
2018-03-08 20:30:01 +08:00
|
|
|
|
* @param page
|
|
|
|
|
|
* @param sysDictInfo
|
2018-03-21 13:43:43 +08:00
|
|
|
|
* @param intArr
|
2018-03-08 20:30:01 +08:00
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
2018-03-31 17:23:11 +08:00
|
|
|
|
public List<SysDictInfo> findAllSysDictInfo(SysDictInfo sysDictInfo, List<Integer> itType,String orderBy) {
|
2018-03-21 13:43:43 +08:00
|
|
|
|
|
2018-03-31 17:23:11 +08:00
|
|
|
|
sysDictInfo.setConditionType(itType);
|
|
|
|
|
|
return sysDictInfoDao.findAllSysDictInfo(sysDictInfo,orderBy);
|
2018-03-04 19:20:32 +08:00
|
|
|
|
}
|
2018-03-21 13:43:43 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 查询所有有效字典配置
|
|
|
|
|
|
*/
|
|
|
|
|
|
public List<SysDictInfo> findAllDictList() {
|
|
|
|
|
|
return sysDictInfoDao.findAllDictList(new SysDictInfo());
|
2018-03-04 19:20:32 +08:00
|
|
|
|
|
2018-03-21 13:43:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-02-22 12:46:50 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 根据主键查询生效范围字典详细信息
|
|
|
|
|
|
* @param sysDictId
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
|
|
|
|
|
public SysDictInfo getDictById(Integer sysDictId) {
|
|
|
|
|
|
return sysDictInfoDao.getDictById(sysDictId);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 新增或修改生效范围字典表
|
|
|
|
|
|
* @param sysDictInfo
|
|
|
|
|
|
*/
|
2018-03-28 18:24:09 +08:00
|
|
|
|
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
|
2018-02-22 12:46:50 +08:00
|
|
|
|
public void saveOrUpdate(SysDictInfo sysDictInfo) {
|
2018-03-04 19:20:32 +08:00
|
|
|
|
if(sysDictInfo.getParent()==null
|
|
|
|
|
|
||(sysDictInfo.getParent()!=null&&sysDictInfo.getParent().getSysDictId()==null)
|
|
|
|
|
|
||(sysDictInfo.getParent()!=null&&sysDictInfo.getParent().getSysDictId()==-1)
|
|
|
|
|
|
||(sysDictInfo.getParent()!=null&&sysDictInfo.getParent().getSysDictId()==0)
|
|
|
|
|
|
){
|
|
|
|
|
|
SysDictInfo parent = new SysDictInfo();
|
|
|
|
|
|
parent.setSysDictId(0);
|
2018-03-08 20:30:01 +08:00
|
|
|
|
parent.setLevelNo(0);
|
2018-03-04 19:20:32 +08:00
|
|
|
|
sysDictInfo.setParent(parent);
|
|
|
|
|
|
}
|
2018-03-08 20:30:01 +08:00
|
|
|
|
if(sysDictInfo.getParent().getSysDictId()!=0){
|
|
|
|
|
|
SysDictInfo parent = sysDictInfoDao.getDictById(sysDictInfo.getParent().getSysDictId());
|
|
|
|
|
|
sysDictInfo.setParent(parent);
|
|
|
|
|
|
}
|
2018-02-22 12:46:50 +08:00
|
|
|
|
SysUser user = UserUtils.getUser();
|
|
|
|
|
|
if(StringUtil.isEmpty(sysDictInfo.getSysDictId())) {//新增
|
2018-03-08 20:30:01 +08:00
|
|
|
|
sysDictInfo.setLevelNo(sysDictInfo.getParent().getLevelNo()+1);
|
2018-02-22 12:46:50 +08:00
|
|
|
|
sysDictInfo.setIsValid(1);
|
|
|
|
|
|
sysDictInfo.setSysDictCreator(user);
|
|
|
|
|
|
sysDictInfo.setCreateTime(new Date());
|
|
|
|
|
|
sysDictInfo.setSysDictEditor(user);
|
|
|
|
|
|
sysDictInfo.setEditTime(sysDictInfo.getCreateTime());
|
2018-04-04 18:16:21 +08:00
|
|
|
|
sysDictInfo.setIsInitianlize(0);//是否为初始化数据,默认为0:否
|
2018-02-22 12:46:50 +08:00
|
|
|
|
sysDictInfoDao.insertDict(sysDictInfo);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
else {//修改
|
2018-03-08 20:30:01 +08:00
|
|
|
|
List<SysDictInfo> resultList = Lists.newArrayList();
|
|
|
|
|
|
List<SysDictInfo> list = sysDictInfoDao.getDictByParentId(sysDictInfo.getSysDictId());
|
|
|
|
|
|
|
|
|
|
|
|
//处理层级
|
|
|
|
|
|
if(sysDictInfo.getParent().getSysDictId()==0){
|
|
|
|
|
|
sysDictInfo.setLevelNo(1);
|
|
|
|
|
|
//处理子集
|
|
|
|
|
|
childLevel(sysDictInfo,list,resultList);
|
|
|
|
|
|
}else{
|
|
|
|
|
|
sysDictInfo.setLevelNo(sysDictInfo.getParent().getLevelNo()+1);
|
|
|
|
|
|
//处理子集
|
|
|
|
|
|
childLevel(sysDictInfo,list,resultList);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-02-22 12:46:50 +08:00
|
|
|
|
sysDictInfo.setSysDictEditor(user);
|
|
|
|
|
|
sysDictInfo.setEditTime(new Date());
|
2018-03-08 20:30:01 +08:00
|
|
|
|
for(SysDictInfo sc:resultList){
|
|
|
|
|
|
sysDictInfoDao.updateLevelNo(sc);
|
|
|
|
|
|
}
|
2018-02-22 12:46:50 +08:00
|
|
|
|
sysDictInfoDao.update(sysDictInfo);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2018-03-08 20:30:01 +08:00
|
|
|
|
|
|
|
|
|
|
//处理子集层级
|
|
|
|
|
|
|
|
|
|
|
|
public void childLevel(SysDictInfo sysDictInfo, List<SysDictInfo> list,List<SysDictInfo> resultList){
|
|
|
|
|
|
for(SysDictInfo se:list){
|
|
|
|
|
|
se.setLevelNo(sysDictInfo.getLevelNo()+1);
|
|
|
|
|
|
resultList.add(se);
|
|
|
|
|
|
List<SysDictInfo> newList = sysDictInfoDao.getDictByParentId(se.getSysDictId());
|
|
|
|
|
|
childLevel(se,newList,resultList);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-22 12:46:50 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
2018-03-04 19:20:32 +08:00
|
|
|
|
* 删除
|
|
|
|
|
|
* @param sysDictInfo
|
2018-02-22 12:46:50 +08:00
|
|
|
|
*/
|
2018-03-28 18:24:09 +08:00
|
|
|
|
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
|
2018-03-10 18:54:05 +08:00
|
|
|
|
public void deleteDict(String mulitId) {
|
|
|
|
|
|
String[] ids = mulitId.split(",");
|
|
|
|
|
|
for(String id:ids){
|
|
|
|
|
|
if (!id.equals("")) {
|
|
|
|
|
|
List<SysDictInfo> list = Lists.newArrayList();
|
|
|
|
|
|
SysDictInfo sysDictInfo = sysDictInfoDao.getDictById(Integer.valueOf(id));
|
|
|
|
|
|
if(sysDictInfo!=null){
|
|
|
|
|
|
SysDictInfo.sortList(list, sysDictInfoDao.findAllDictList(new SysDictInfo()), sysDictInfo.getSysDictId(), true);
|
|
|
|
|
|
list.add(sysDictInfo);
|
|
|
|
|
|
for(SysDictInfo se:list){
|
|
|
|
|
|
se.setIsValid(0);
|
|
|
|
|
|
sysDictInfoDao.delete(se);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-03-04 19:20:32 +08:00
|
|
|
|
}
|
2018-02-22 12:46:50 +08:00
|
|
|
|
|
2018-03-10 18:54:05 +08:00
|
|
|
|
|
|
|
|
|
|
|
2018-02-22 12:46:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
/**
|
2018-03-04 19:20:32 +08:00
|
|
|
|
* 查询该类型所有的非叶子配置
|
|
|
|
|
|
* @param itType
|
|
|
|
|
|
* @return
|
2018-02-22 12:46:50 +08:00
|
|
|
|
*/
|
2018-03-04 19:20:32 +08:00
|
|
|
|
public List<SysDictInfo> findAllNoLeafDictList(String itType) {
|
|
|
|
|
|
List<SysDictInfo> list = Lists.newArrayList();
|
2018-03-31 17:23:11 +08:00
|
|
|
|
List<Integer> intArr = ConfigDictUtils.dealTypeCondition(Configurations.getStringProperty("SYS_DICT_ITM_TYPE", ""), itType);
|
|
|
|
|
|
for(Integer intType:intArr){
|
|
|
|
|
|
List<SysDictInfo> tempList = sysDictInfoDao.findAllNoLeafDictList(intType);
|
|
|
|
|
|
list.addAll(tempList);
|
2018-03-04 19:20:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
return list;
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 根据itemCode查出对象集合
|
|
|
|
|
|
* @param itemCode
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
2018-03-08 20:30:01 +08:00
|
|
|
|
public List<SysDictInfo> findByItemCode(String itemCode) {
|
2018-03-04 19:20:32 +08:00
|
|
|
|
return sysDictInfoDao.findByItemCode(itemCode);
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 根据上级id选出所有下级
|
|
|
|
|
|
* @param parent
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
|
|
|
|
|
public List<SysDictInfo> getDictByParentId(Integer parentId) {
|
|
|
|
|
|
|
|
|
|
|
|
return sysDictInfoDao.getDictByParentId(parentId);
|
2018-02-22 12:46:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-03-29 14:56:27 +08:00
|
|
|
|
public List<SysDictInfo> getDistrictDict(String tableName){
|
|
|
|
|
|
return sysDictInfoDao.getDistrictDict(tableName);
|
|
|
|
|
|
}
|
2018-03-04 19:20:32 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-02-22 12:46:50 +08:00
|
|
|
|
|
|
|
|
|
|
}
|