2018-03-17 17:09:19 +08:00
|
|
|
package com.nis.web.service.specific;
|
|
|
|
|
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
2018-03-28 18:24:09 +08:00
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
2018-03-17 17:09:19 +08:00
|
|
|
|
|
|
|
|
import com.beust.jcommander.internal.Lists;
|
|
|
|
|
import com.nis.domain.Page;
|
2018-04-03 11:12:49 +08:00
|
|
|
import com.nis.domain.specific.ConfigGroupInfo;
|
2018-03-17 17:09:19 +08:00
|
|
|
import com.nis.domain.specific.SpecificServiceCfg;
|
2018-06-21 09:12:25 +08:00
|
|
|
import com.nis.util.ConfigServiceUtil;
|
2018-08-24 11:54:21 +08:00
|
|
|
import com.nis.util.Constants;
|
2018-03-17 17:09:19 +08:00
|
|
|
import com.nis.web.dao.specific.SpecificServiceCfgDao;
|
|
|
|
|
import com.nis.web.service.BaseService;
|
|
|
|
|
|
|
|
|
|
@Service
|
|
|
|
|
public class SpecificServiceCfgService extends BaseService{
|
|
|
|
|
|
|
|
|
|
@Autowired
|
2018-10-25 12:51:29 +08:00
|
|
|
private SpecificServiceCfgDao specificServiceCfgDao;
|
2018-03-17 17:09:19 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据id查询对象
|
|
|
|
|
* @param specServiceId
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public SpecificServiceCfg getBySpecServiceId(Integer specServiceId) {
|
|
|
|
|
return specificServiceCfgDao.getBySpecServiceId(specServiceId);
|
|
|
|
|
}
|
2018-10-25 12:51:29 +08:00
|
|
|
public List<SpecificServiceCfg> getBySpecServiceCodes(String specServiceCodes) {
|
|
|
|
|
for(String specServiceId:specServiceCodes.split(",")) {
|
|
|
|
|
Integer.parseInt(specServiceId);
|
|
|
|
|
}
|
|
|
|
|
return specificServiceCfgDao.getBySpecServiceCodes(specServiceCodes);
|
|
|
|
|
}
|
2018-03-17 17:09:19 +08:00
|
|
|
/**
|
|
|
|
|
* 查询所有符合条件的顶层分页
|
|
|
|
|
* @param page
|
|
|
|
|
* @param specificServiceCfg
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public Page<SpecificServiceCfg> findTopPage(Page<SpecificServiceCfg> page, SpecificServiceCfg specificServiceCfg){
|
|
|
|
|
// 设置分页参数
|
|
|
|
|
specificServiceCfg.setPage(page);
|
|
|
|
|
// 执行分页查询
|
|
|
|
|
List<SpecificServiceCfg> list = Lists.newArrayList();
|
|
|
|
|
list = specificServiceCfgDao.findTopPage(specificServiceCfg);
|
|
|
|
|
SpecificServiceCfg ss = new SpecificServiceCfg();
|
|
|
|
|
ss.setSpecServiceId(0);
|
|
|
|
|
for(SpecificServiceCfg ssc:list){
|
|
|
|
|
ssc.setParent(ss);
|
|
|
|
|
}
|
|
|
|
|
page.setList(list);
|
|
|
|
|
return page;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 查询所有符合条件的数据
|
|
|
|
|
* @param specificServiceCfg
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
2018-03-21 13:43:43 +08:00
|
|
|
public List<SpecificServiceCfg> findAllSpecificServiceCfg(SpecificServiceCfg specificServiceCfg, String orderBy) {
|
|
|
|
|
return specificServiceCfgDao.findAllSpecificServiceCfg(specificServiceCfg,orderBy);
|
2018-03-17 17:09:19 +08:00
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 保存或修改
|
|
|
|
|
* @param specificServiceCfg
|
2018-04-03 11:12:49 +08:00
|
|
|
* @throws Exception
|
2018-03-17 17:09:19 +08:00
|
|
|
*/
|
2018-03-28 18:24:09 +08:00
|
|
|
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
|
2018-06-21 09:12:25 +08:00
|
|
|
public void saveOrUpdate(SpecificServiceCfg specificServiceCfg) throws Exception {
|
2018-04-03 11:12:49 +08:00
|
|
|
if(specificServiceCfg.getGroupId()==null || specificServiceCfg.getGroupId()==0){
|
2018-06-21 09:12:25 +08:00
|
|
|
Integer groupId = ConfigServiceUtil.getId(2, 1).get(0);
|
|
|
|
|
specificServiceCfg.setGroupId(groupId);
|
2018-04-03 11:12:49 +08:00
|
|
|
}
|
|
|
|
|
//新增协议分组
|
|
|
|
|
ConfigGroupInfo group = specificServiceCfgDao.getConfigGroupInfoByGroupId(specificServiceCfg.getGroupId());
|
|
|
|
|
if(group==null){
|
|
|
|
|
group = new ConfigGroupInfo();
|
|
|
|
|
group.setGroupId(specificServiceCfg.getGroupId());
|
|
|
|
|
group.setGroupName(specificServiceCfg.getSpecServiceName());
|
|
|
|
|
group.setIsIssued(0);
|
|
|
|
|
group.setGroupType(1);
|
|
|
|
|
specificServiceCfgDao.insertConfigGroupInfo(group);
|
2018-03-21 13:43:43 +08:00
|
|
|
}
|
2018-06-21 09:12:25 +08:00
|
|
|
if(specificServiceCfg.getSpecServiceId()==null){//新增
|
2018-06-21 18:10:07 +08:00
|
|
|
if(specificServiceCfg.getIsLeaf()==null){
|
|
|
|
|
if(specificServiceCfg.getParent().getSpecServiceId().equals(0)){
|
|
|
|
|
specificServiceCfg.setIsLeaf(0);
|
|
|
|
|
}else{
|
|
|
|
|
specificServiceCfg.setIsLeaf(1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-17 17:09:19 +08:00
|
|
|
specificServiceCfg.setIsValid(1);
|
|
|
|
|
specificServiceCfg.setOpTime(new Date());
|
2018-08-24 11:54:21 +08:00
|
|
|
//用户添加的需要自增
|
|
|
|
|
if(specificServiceCfg.getAddFlag()!=null) {
|
|
|
|
|
Integer serviceCode=specificServiceCfgDao.getMaxServiceCode(Constants.APP_SPEC_SERVICE_CODE_MAX_VAL,specificServiceCfg.getCfgType(),specificServiceCfg.getAddFlag());
|
|
|
|
|
if(serviceCode==null) {//用户没有添加标签,获取最大的
|
|
|
|
|
serviceCode=specificServiceCfgDao.getMaxServiceCode(Constants.APP_SPEC_SERVICE_CODE_MAX_VAL,specificServiceCfg.getCfgType(),null);
|
|
|
|
|
}
|
|
|
|
|
if(serviceCode==null) {//没有标签,取开始值
|
|
|
|
|
serviceCode=Constants.APP_SPEC_SERVICE_CODE_MIN_VAL;
|
|
|
|
|
}else if(serviceCode>Constants.APP_SPEC_SERVICE_CODE_MAX_VAL){
|
|
|
|
|
throw new RuntimeException("Get specific service code failed,specific service code is beyond the scope of application");
|
|
|
|
|
}else if(serviceCode<Constants.APP_SPEC_SERVICE_CODE_MIN_VAL) {
|
|
|
|
|
serviceCode=Constants.APP_SPEC_SERVICE_CODE_MIN_VAL;
|
|
|
|
|
}
|
|
|
|
|
specificServiceCfg.setSpecServiceCode(serviceCode.intValue()+1);
|
|
|
|
|
}
|
2018-03-17 17:09:19 +08:00
|
|
|
specificServiceCfgDao.insert(specificServiceCfg);
|
|
|
|
|
}else{//修改
|
2018-06-21 18:10:07 +08:00
|
|
|
if(specificServiceCfg.getIsLeaf()==null){
|
|
|
|
|
if(specificServiceCfg.getParent().getSpecServiceId().equals(0)){
|
|
|
|
|
specificServiceCfg.setIsLeaf(0);
|
|
|
|
|
}else{
|
|
|
|
|
specificServiceCfg.setIsLeaf(1);
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-03-17 17:09:19 +08:00
|
|
|
specificServiceCfg.setOpTime(new Date());
|
2018-06-21 09:12:25 +08:00
|
|
|
specificServiceCfgDao.update(specificServiceCfg);
|
2018-03-17 17:09:19 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 删除
|
|
|
|
|
* @param specificServiceCfg
|
2018-03-28 18:24:09 +08:00
|
|
|
* @throws Exception
|
2018-03-17 17:09:19 +08:00
|
|
|
*/
|
2018-03-28 18:24:09 +08:00
|
|
|
@Transactional(readOnly=false,rollbackFor=RuntimeException.class)
|
|
|
|
|
public void delete(String mulitId){
|
2018-03-17 17:09:19 +08:00
|
|
|
String[] ids = mulitId.split(",");
|
|
|
|
|
for(String id:ids){
|
|
|
|
|
if (!id.equals("")) {
|
|
|
|
|
SpecificServiceCfg specificServiceCfg = specificServiceCfgDao.getBySpecServiceId(Integer.valueOf(id));
|
|
|
|
|
List<SpecificServiceCfg> list = Lists.newArrayList();
|
|
|
|
|
//找出所有下级
|
|
|
|
|
if(specificServiceCfg!=null){
|
2018-03-21 13:43:43 +08:00
|
|
|
SpecificServiceCfg.sortList(list, specificServiceCfgDao.findAllSpecificServiceCfg(new SpecificServiceCfg(),""), specificServiceCfg.getSpecServiceId(), true);
|
2018-03-17 17:09:19 +08:00
|
|
|
list.add(specificServiceCfg);
|
|
|
|
|
for(SpecificServiceCfg ss:list){
|
|
|
|
|
ss.setIsValid(0);
|
|
|
|
|
specificServiceCfgDao.delete(ss);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据specServiceId查询所有下级
|
|
|
|
|
* @param specServiceId
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public List<SpecificServiceCfg> getChildrenById(Integer specServiceId) {
|
|
|
|
|
return specificServiceCfgDao.getChildrenById(specServiceId);
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-25 15:19:24 +08:00
|
|
|
public Integer getParentType(Integer specServiceId) {
|
|
|
|
|
return specificServiceCfgDao.getParentType(specServiceId);
|
|
|
|
|
}
|
2018-07-30 09:15:36 +08:00
|
|
|
public Integer getParentCode(Integer specServiceId) {
|
|
|
|
|
return specificServiceCfgDao.getParentCode(specServiceId);
|
|
|
|
|
}
|
|
|
|
|
public SpecificServiceCfg getRepeat (Integer code,Integer cfgType,Integer parentId) {
|
|
|
|
|
return specificServiceCfgDao.getRepeat(code,cfgType,parentId);
|
|
|
|
|
}
|
2018-08-24 11:54:21 +08:00
|
|
|
public Integer getMaxServiceCode (Integer code, Integer cfgType,Integer addFlag) {
|
|
|
|
|
return specificServiceCfgDao.getMaxServiceCode(code,cfgType,addFlag);
|
|
|
|
|
}
|
2018-07-30 09:15:36 +08:00
|
|
|
|
2018-03-17 17:09:19 +08:00
|
|
|
}
|