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;
|
|
|
|
|
|
|
|
|
|
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-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-04 19:20:32 +08:00
|
|
|
* 查询顶层分页(无条件查询)
|
2018-02-22 12:46:50 +08:00
|
|
|
* @param page
|
|
|
|
|
* @param sysDictInfo
|
2018-03-04 19:20:32 +08:00
|
|
|
* @param intArr
|
2018-02-22 12:46:50 +08:00
|
|
|
* @return
|
|
|
|
|
*/
|
2018-03-04 19:20:32 +08:00
|
|
|
public Page<SysDictInfo> findTopDictList(Page<SysDictInfo> page, SysDictInfo sysDictInfo, Integer[] intArr) {
|
2018-02-22 12:46:50 +08:00
|
|
|
// 设置分页参数
|
|
|
|
|
sysDictInfo.setPage(page);
|
2018-03-04 19:20:32 +08:00
|
|
|
List<SysDictInfo> parentList = Lists.newArrayList();
|
|
|
|
|
Integer tempType = 0;
|
|
|
|
|
//预留以后分开用
|
|
|
|
|
if(sysDictInfo.getItemType()!=null){
|
|
|
|
|
tempType = sysDictInfo.getItemType();
|
|
|
|
|
}
|
|
|
|
|
//查出顶层分页查询
|
|
|
|
|
parentList = sysDictInfoDao.findTopDictList(sysDictInfo);
|
|
|
|
|
|
|
|
|
|
page.setList(parentList);
|
2018-02-22 12:46:50 +08:00
|
|
|
return page;
|
|
|
|
|
}
|
2018-03-04 19:20:32 +08:00
|
|
|
/**
|
|
|
|
|
* 查询所有有效字典配置
|
|
|
|
|
*/
|
|
|
|
|
public List<SysDictInfo> findAllDictList() {
|
|
|
|
|
return sysDictInfoDao.findAllDictList(new SysDictInfo());
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 查询字典分页(含条件查询)
|
|
|
|
|
* @param page
|
|
|
|
|
* @param sysDictInfo
|
|
|
|
|
* @param intArr
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public Page<SysDictInfo> findDictSearchList(Page<SysDictInfo> page, SysDictInfo sysDictInfo, Integer[] itType) {
|
|
|
|
|
// 设置分页参数
|
|
|
|
|
sysDictInfo.setPage(page);
|
|
|
|
|
|
|
|
|
|
List<SysDictInfo> list = Lists.newArrayList();
|
|
|
|
|
/*Integer tempType = 0;
|
|
|
|
|
if(sysDictInfo.getItemType()!=null){
|
|
|
|
|
tempType = sysDictInfo.getItemType();
|
|
|
|
|
}*/
|
|
|
|
|
//查出分页
|
|
|
|
|
list = sysDictInfoDao.findDictSearchList(sysDictInfo);
|
|
|
|
|
page.setList(list);
|
|
|
|
|
return page;
|
|
|
|
|
}
|
2018-02-22 12:46:50 +08:00
|
|
|
|
2018-03-04 19:20:32 +08:00
|
|
|
|
|
|
|
|
|
2018-02-22 12:46:50 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据主键查询生效范围字典详细信息
|
|
|
|
|
* @param sysDictId
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public SysDictInfo getDictById(Integer sysDictId) {
|
|
|
|
|
return sysDictInfoDao.getDictById(sysDictId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 新增或修改生效范围字典表
|
|
|
|
|
* @param sysDictInfo
|
|
|
|
|
*/
|
|
|
|
|
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);
|
|
|
|
|
sysDictInfo.setParent(parent);
|
|
|
|
|
}
|
2018-02-22 12:46:50 +08:00
|
|
|
SysUser user = UserUtils.getUser();
|
|
|
|
|
if(StringUtil.isEmpty(sysDictInfo.getSysDictId())) {//新增
|
2018-03-06 10:06:42 +08:00
|
|
|
if(sysDictInfo.getItemCode()==null){
|
|
|
|
|
Integer maxCode = sysDictInfoDao.findMaxItemCode();
|
|
|
|
|
sysDictInfo.setItemCode(maxCode==null?1:(maxCode+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());
|
|
|
|
|
sysDictInfoDao.insertDict(sysDictInfo);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else {//修改
|
|
|
|
|
sysDictInfo.setSysDictEditor(user);
|
|
|
|
|
sysDictInfo.setEditTime(new Date());
|
|
|
|
|
sysDictInfoDao.update(sysDictInfo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2018-03-04 19:20:32 +08:00
|
|
|
* 删除
|
|
|
|
|
* @param sysDictInfo
|
2018-02-22 12:46:50 +08:00
|
|
|
*/
|
2018-03-04 19:20:32 +08:00
|
|
|
public void deleteDict(SysDictInfo sysDictInfo) {
|
|
|
|
|
List<SysDictInfo> list = Lists.newArrayList();
|
|
|
|
|
SysDictInfo.sortList(list, sysDictInfoDao.findAllDictList(new SysDictInfo()), sysDictInfo.getSysDictId(), true);
|
|
|
|
|
list.add(sysDictInfo);
|
|
|
|
|
for(SysDictInfo se:list){
|
|
|
|
|
se.setIsValid(0);
|
|
|
|
|
sysDictInfoDao.delete(sysDictInfo);
|
|
|
|
|
}
|
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();
|
|
|
|
|
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<SysDictInfo> tempList = sysDictInfoDao.findAllNoLeafDictList(intArr[i]);
|
|
|
|
|
for(SysDictInfo sysDictInfo:tempList){
|
|
|
|
|
list.add(sysDictInfo);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 根据itemCode查出对象集合
|
|
|
|
|
* @param itemCode
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public List<SysDictInfo> findByItemCode(Integer itemCode) {
|
|
|
|
|
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-04 19:20:32 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-02-22 12:46:50 +08:00
|
|
|
|
|
|
|
|
}
|