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-09 14:08:27 +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;
|
2018-03-01 19:13:57 +08:00
|
|
|
|
import com.nis.domain.SysMenu;
|
2018-02-22 12:46:50 +08:00
|
|
|
|
import com.nis.domain.SysUser;
|
2018-03-06 10:06:42 +08:00
|
|
|
|
import com.nis.domain.basics.ServiceDictInfo;
|
2018-02-25 18:43:20 +08:00
|
|
|
|
import com.nis.util.Constants;
|
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.ServiceDictInfoDao;
|
2018-02-22 12:46:50 +08:00
|
|
|
|
import com.nis.web.security.UserUtils;
|
|
|
|
|
|
import com.nis.web.service.BaseService;
|
|
|
|
|
|
|
|
|
|
|
|
@Service
|
|
|
|
|
|
public class ServiceDictInfoService extends BaseService{
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
private ServiceDictInfoDao serviceDictInfoDao;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2018-03-21 13:43:43 +08:00
|
|
|
|
* 查询业务字典顶层分页
|
2018-02-22 12:46:50 +08:00
|
|
|
|
* @param page
|
|
|
|
|
|
* @param serviceDictInfo
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
2018-03-04 19:20:32 +08:00
|
|
|
|
public Page<ServiceDictInfo> findTopDictList(Page<ServiceDictInfo> page, ServiceDictInfo serviceDictInfo,Integer[] itType) {
|
2018-02-22 12:46:50 +08:00
|
|
|
|
// 设置分页参数
|
|
|
|
|
|
serviceDictInfo.setPage(page);
|
2018-03-04 19:20:32 +08:00
|
|
|
|
List<ServiceDictInfo> parentList = Lists.newArrayList();
|
|
|
|
|
|
Integer tempType = 0;
|
|
|
|
|
|
if(serviceDictInfo.getItemType()!=null){
|
|
|
|
|
|
tempType = serviceDictInfo.getItemType();
|
|
|
|
|
|
}
|
2018-03-01 19:13:57 +08:00
|
|
|
|
//查出顶层分页查询
|
2018-03-04 19:20:32 +08:00
|
|
|
|
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);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2018-03-21 13:43:43 +08:00
|
|
|
|
ServiceDictInfo sd = new ServiceDictInfo();
|
|
|
|
|
|
sd.setServiceDictId(0);
|
|
|
|
|
|
for(ServiceDictInfo se:parentList){
|
|
|
|
|
|
se.setParent(sd);
|
2018-03-04 19:20:32 +08:00
|
|
|
|
}
|
2018-03-21 13:43:43 +08:00
|
|
|
|
if(tempType!=0){
|
|
|
|
|
|
serviceDictInfo.setItemType(tempType);
|
|
|
|
|
|
}else{
|
|
|
|
|
|
serviceDictInfo.setItemType(null);
|
2018-03-04 19:20:32 +08:00
|
|
|
|
}
|
2018-03-21 13:43:43 +08:00
|
|
|
|
page.setList(parentList);
|
2018-03-01 19:13:57 +08:00
|
|
|
|
return page;
|
2018-02-22 12:46:50 +08:00
|
|
|
|
}
|
2018-03-08 20:30:01 +08:00
|
|
|
|
/**
|
2018-03-21 13:43:43 +08:00
|
|
|
|
* 查询所有数据
|
2018-03-08 20:30:01 +08:00
|
|
|
|
* @param serviceDictInfo
|
|
|
|
|
|
* @param itType
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
2018-03-21 13:43:43 +08:00
|
|
|
|
public List<ServiceDictInfo> findAllServiceDictInfo(ServiceDictInfo serviceDictInfo,Integer[] itType,String orderBy){
|
2018-03-08 20:30:01 +08:00
|
|
|
|
List<ServiceDictInfo> list = Lists.newArrayList();
|
|
|
|
|
|
Integer tempType = 0;
|
|
|
|
|
|
if(serviceDictInfo.getItemType()!=null){
|
|
|
|
|
|
tempType = serviceDictInfo.getItemType();
|
|
|
|
|
|
}
|
|
|
|
|
|
if(itType.length==1){
|
|
|
|
|
|
serviceDictInfo.setItemType(itType[0]);
|
2018-03-21 13:43:43 +08:00
|
|
|
|
list = serviceDictInfoDao.findAllServiceDictInfo(serviceDictInfo,orderBy);
|
2018-03-08 20:30:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
if(itType.length==2){
|
|
|
|
|
|
if(tempType!=0){
|
2018-03-21 13:43:43 +08:00
|
|
|
|
list = serviceDictInfoDao.findAllServiceDictInfo(serviceDictInfo,orderBy);
|
2018-03-08 20:30:01 +08:00
|
|
|
|
}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));
|
2018-03-21 13:43:43 +08:00
|
|
|
|
list = serviceDictInfoDao.findAllServiceDictInfoN(serviceDictInfo,orderBy);
|
2018-03-08 20:30:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if(tempType!=0){
|
|
|
|
|
|
serviceDictInfo.setItemType(tempType);
|
|
|
|
|
|
}else{
|
|
|
|
|
|
serviceDictInfo.setItemType(null);
|
|
|
|
|
|
}
|
|
|
|
|
|
return list;
|
|
|
|
|
|
}
|
2018-02-22 12:46:50 +08:00
|
|
|
|
|
2018-03-01 19:13:57 +08:00
|
|
|
|
|
2018-03-21 13:43:43 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 查询所有有效字典配置
|
|
|
|
|
|
* @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;
|
|
|
|
|
|
}
|
2018-02-22 12:46:50 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 根据主键查询字典详细信息
|
|
|
|
|
|
* @param serviceDictId
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
|
|
|
|
|
public ServiceDictInfo getDictById(Integer serviceDictId) {
|
|
|
|
|
|
return serviceDictInfoDao.getDictById(serviceDictId);
|
|
|
|
|
|
}
|
2018-03-04 19:20:32 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 根据上级id选出所有下级
|
|
|
|
|
|
* @param parentId
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
|
|
|
|
|
public List<ServiceDictInfo> getDictByParentId(Integer parentId) {
|
|
|
|
|
|
|
|
|
|
|
|
return serviceDictInfoDao.getDictByParentId(parentId);
|
|
|
|
|
|
}
|
2018-02-22 12:46:50 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
2018-03-08 20:30:01 +08:00
|
|
|
|
* 新增或修改业务字典表(添加层级改变)
|
2018-02-22 12:46:50 +08:00
|
|
|
|
* @param serviceDictInfo
|
|
|
|
|
|
*/
|
2018-03-09 14:08:27 +08:00
|
|
|
|
@Transactional
|
2018-02-22 12:46:50 +08:00
|
|
|
|
public void saveOrUpdate(ServiceDictInfo serviceDictInfo) {
|
2018-03-04 19:20:32 +08:00
|
|
|
|
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);
|
2018-03-08 20:30:01 +08:00
|
|
|
|
parent.setLevelNo(0);
|
2018-03-04 19:20:32 +08:00
|
|
|
|
serviceDictInfo.setParent(parent);
|
|
|
|
|
|
}
|
2018-03-08 20:30:01 +08:00
|
|
|
|
if(serviceDictInfo.getParent().getServiceDictId()!=0){
|
|
|
|
|
|
ServiceDictInfo parent = serviceDictInfoDao.getDictById(serviceDictInfo.getParent().getServiceDictId());
|
|
|
|
|
|
serviceDictInfo.setParent(parent);
|
|
|
|
|
|
}
|
2018-02-22 12:46:50 +08:00
|
|
|
|
SysUser user = UserUtils.getUser();
|
|
|
|
|
|
if(StringUtil.isEmpty(serviceDictInfo.getServiceDictId())) {//新增
|
2018-03-08 20:30:01 +08:00
|
|
|
|
serviceDictInfo.setLevelNo(serviceDictInfo.getParent().getLevelNo()+1);
|
2018-02-22 12:46:50 +08:00
|
|
|
|
serviceDictInfo.setIsValid(1);
|
|
|
|
|
|
serviceDictInfo.setServiceDictCreator(user);
|
|
|
|
|
|
serviceDictInfo.setCreateTime(new Date());
|
|
|
|
|
|
serviceDictInfo.setServiceDictEditor(user);
|
|
|
|
|
|
serviceDictInfo.setEditTime(serviceDictInfo.getCreateTime());
|
|
|
|
|
|
serviceDictInfoDao.insertDict(serviceDictInfo);
|
|
|
|
|
|
}
|
|
|
|
|
|
else {//修改
|
2018-03-08 20:30:01 +08:00
|
|
|
|
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);
|
|
|
|
|
|
}
|
2018-02-22 12:46:50 +08:00
|
|
|
|
serviceDictInfo.setServiceDictEditor(user);
|
|
|
|
|
|
serviceDictInfo.setEditTime(new Date());
|
2018-03-08 20:30:01 +08:00
|
|
|
|
for(ServiceDictInfo sc:resultList){
|
|
|
|
|
|
serviceDictInfoDao.updateLevelNo(sc);
|
|
|
|
|
|
}
|
2018-02-22 12:46:50 +08:00
|
|
|
|
serviceDictInfoDao.update(serviceDictInfo);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2018-03-08 20:30:01 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//处理子集层级
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2018-02-22 12:46:50 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 删除
|
|
|
|
|
|
* @param serviceDictInfo
|
|
|
|
|
|
*/
|
2018-03-09 14:08:27 +08:00
|
|
|
|
@Transactional(readOnly = false)
|
2018-03-10 18:54:05 +08:00
|
|
|
|
public void deleteDict(String mulitId) {
|
|
|
|
|
|
|
|
|
|
|
|
String[] ids = mulitId.split(",");
|
|
|
|
|
|
for(String id:ids){
|
|
|
|
|
|
if (!id.equals("")) {
|
|
|
|
|
|
ServiceDictInfo serviceDictInfo = serviceDictInfoDao.getDictById(Integer.valueOf(id));
|
|
|
|
|
|
List<ServiceDictInfo> list = Lists.newArrayList();
|
|
|
|
|
|
//找出所有下级
|
|
|
|
|
|
//查出所有节点
|
|
|
|
|
|
if(serviceDictInfo!=null){
|
|
|
|
|
|
ServiceDictInfo.sortList(list, serviceDictInfoDao.findAllDictList(new ServiceDictInfo()), serviceDictInfo.getServiceDictId(), true);
|
|
|
|
|
|
list.add(serviceDictInfo);
|
|
|
|
|
|
for(ServiceDictInfo se:list){
|
|
|
|
|
|
se.setIsValid(0);
|
|
|
|
|
|
serviceDictInfoDao.delete(se);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-03-01 19:13:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-03-10 18:54:05 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-02-22 12:46:50 +08:00
|
|
|
|
}
|
2018-03-01 19:13:57 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
2018-03-04 19:20:32 +08:00
|
|
|
|
* 根据itemCode查出对象集合
|
2018-03-01 19:13:57 +08:00
|
|
|
|
*/
|
2018-03-08 20:30:01 +08:00
|
|
|
|
public List<ServiceDictInfo> findByItemCode(String itemCode){
|
2018-03-04 19:20:32 +08:00
|
|
|
|
return serviceDictInfoDao.findByItemCode(itemCode);
|
2018-03-01 19:13:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-02-25 18:43:20 +08:00
|
|
|
|
/**
|
|
|
|
|
|
*
|
|
|
|
|
|
* 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);
|
|
|
|
|
|
}
|
2018-03-01 19:13:57 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-03-04 19:20:32 +08:00
|
|
|
|
|
|
|
|
|
|
|
2018-03-12 14:47:59 +08:00
|
|
|
|
|
2018-02-22 12:46:50 +08:00
|
|
|
|
|
|
|
|
|
|
}
|