|  | @ -1,12 +1,21 @@
 | 
	
		
			
				|  |  | package com.yihu.jw.base.endpoint.saas;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | import com.yihu.jw.base.contant.CommonContant;
 | 
	
		
			
				|  |  | import com.yihu.jw.base.service.module.ModuleService;
 | 
	
		
			
				|  |  | import com.yihu.jw.base.service.module.SaasTypeModuleService;
 | 
	
		
			
				|  |  | import com.yihu.jw.base.service.saas.SaasTypeDictService;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.module.ModuleDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.module.SaasTypeModuleDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.saas.SaasTypeDictDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.restmodel.base.module.ModuleVO;
 | 
	
		
			
				|  |  | import com.yihu.jw.restmodel.base.module.SaasTypeModuleVO;
 | 
	
		
			
				|  |  | import com.yihu.jw.restmodel.base.saas.SaasTypeDictVO;
 | 
	
		
			
				|  |  | import com.yihu.jw.restmodel.web.ListEnvelop;
 | 
	
		
			
				|  |  | import com.yihu.jw.restmodel.web.ObjEnvelop;
 | 
	
		
			
				|  |  | import com.yihu.jw.restmodel.web.PageEnvelop;
 | 
	
		
			
				|  |  | import com.yihu.jw.restmodel.web.*;
 | 
	
		
			
				|  |  | import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
 | 
	
		
			
				|  |  | import com.yihu.jw.restmodel.web.status.EnvelopStatus;
 | 
	
		
			
				|  |  | import com.yihu.jw.rm.base.BaseRequestMapping;
 | 
	
		
			
				|  |  | import io.swagger.annotations.Api;
 | 
	
		
			
				|  |  | import io.swagger.annotations.ApiOperation;
 | 
	
	
		
			
				|  | @ -16,7 +25,8 @@ import org.springframework.beans.factory.annotation.Autowired;
 | 
	
		
			
				|  |  | import org.springframework.http.MediaType;
 | 
	
		
			
				|  |  | import org.springframework.web.bind.annotation.*;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | import java.util.List;
 | 
	
		
			
				|  |  | import java.util.*;
 | 
	
		
			
				|  |  | import java.util.stream.Collectors;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | /**
 | 
	
		
			
				|  |  |  * Endpoint - SaasTypeDict
 | 
	
	
		
			
				|  | @ -29,8 +39,10 @@ public class SaasTypeDictEndpoint extends EnvelopRestEndpoint {
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private SaasTypeDictService saasTypeDictService;
 | 
	
		
			
				|  |  | //    @Autowired
 | 
	
		
			
				|  |  | //    private SaasDefaultModuleFunctionService saasDefaultModuleFunctionService;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private ModuleService moduleService;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private SaasTypeModuleService saasTypeModuleService;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @PostMapping(value = BaseRequestMapping.SaasTypeDict.CREATE, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
 | 
	
		
			
				|  |  |     @ApiOperation(value = "创建")
 | 
	
	
		
			
				|  | @ -50,7 +62,7 @@ public class SaasTypeDictEndpoint extends EnvelopRestEndpoint {
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @PostMapping(value = BaseRequestMapping.Saas.UPDATE, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
 | 
	
		
			
				|  |  |     @PostMapping(value = BaseRequestMapping.SaasTypeDict.UPDATE, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
 | 
	
		
			
				|  |  |     @ApiOperation(value = "更新")
 | 
	
		
			
				|  |  |     public ObjEnvelop<SaasTypeDictVO> update(
 | 
	
		
			
				|  |  |             @ApiParam(name = "saasTypeDictJson", value = "saas类型Json数据")
 | 
	
	
		
			
				|  | @ -61,16 +73,16 @@ public class SaasTypeDictEndpoint extends EnvelopRestEndpoint {
 | 
	
		
			
				|  |  |         if (null == saasTypeDictDO.getId()) {
 | 
	
		
			
				|  |  |             return failed("ID不能为空", ObjEnvelop.class);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if (saasTypeDictService.isSaasTypeDictExistByNameAndId(saasTypeDictDO.getId(),saasTypeDictDO.getName())) {
 | 
	
		
			
				|  |  |         if (saasTypeDictService.isSaasTypeDictExistByNameAndId(saasTypeDictDO.getId(), saasTypeDictDO.getName())) {
 | 
	
		
			
				|  |  |             return failed("租户类型名称重复!", ObjEnvelop.class);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         //删除关联的模块
 | 
	
		
			
				|  |  | //        saasDefaultModuleFunctionService.deleteBySaasType(saasTypeDictDO.getCode());
 | 
	
		
			
				|  |  |         saasTypeModuleService.deleteBySaasTypeId(saasTypeDictDO.getId());
 | 
	
		
			
				|  |  |         saasTypeDictDO = saasTypeDictService.save(saasTypeDictDO, saasTypeDefaultModuleIds);
 | 
	
		
			
				|  |  |         return success("更新成功!", saasTypeDictDO, SaasTypeDictVO.class);
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @GetMapping(value = BaseRequestMapping.Saas.PAGE)
 | 
	
		
			
				|  |  |     @GetMapping(value = BaseRequestMapping.SaasTypeDict.PAGE)
 | 
	
		
			
				|  |  |     @ApiOperation(value = "获取分页")
 | 
	
		
			
				|  |  |     public PageEnvelop<SaasTypeDictVO> page(
 | 
	
		
			
				|  |  |             @ApiParam(name = "name", value = "租户类型名称")
 | 
	
	
		
			
				|  | @ -96,7 +108,7 @@ public class SaasTypeDictEndpoint extends EnvelopRestEndpoint {
 | 
	
		
			
				|  |  |         return success(saasTypeDictDOS, count, page, size, SaasTypeDictVO.class);
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @GetMapping(value = BaseRequestMapping.Saas.LIST)
 | 
	
		
			
				|  |  |     @GetMapping(value = BaseRequestMapping.SaasTypeDict.LIST)
 | 
	
		
			
				|  |  |     @ApiOperation(value = "获取列表")
 | 
	
		
			
				|  |  |     public ListEnvelop<SaasTypeDictVO> list(
 | 
	
		
			
				|  |  |             @ApiParam(name = "fields", value = "返回的字段,为空返回全部字段")
 | 
	
	
		
			
				|  | @ -109,5 +121,89 @@ public class SaasTypeDictEndpoint extends EnvelopRestEndpoint {
 | 
	
		
			
				|  |  |         return success(saasTypeDictDOS, SaasTypeDictVO.class);
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @GetMapping(value = BaseRequestMapping.SaasTypeDict.FINDBYID)
 | 
	
		
			
				|  |  |     @ApiOperation(value = "根据id获取单个租户类型+(右边树:已关联的模块)")
 | 
	
		
			
				|  |  |     public MixEnvelop<SaasTypeDictDO, List<ModuleVO>> findById(
 | 
	
		
			
				|  |  |             @ApiParam(name = "saasTypeDictId", value = "租户类型id")
 | 
	
		
			
				|  |  |             @RequestParam(value = "saasTypeDictId", required = true) String saasTypeDictId) throws Exception {
 | 
	
		
			
				|  |  |         MixEnvelop envelop = new MixEnvelop();
 | 
	
		
			
				|  |  |         //获取租户类型
 | 
	
		
			
				|  |  |         SaasTypeDictDO saasTypeDictDO = saasTypeDictService.findById(saasTypeDictId);
 | 
	
		
			
				|  |  |         envelop.setObj(saasTypeDictDO);
 | 
	
		
			
				|  |  |         if (null != saasTypeDictDO) {
 | 
	
		
			
				|  |  |             //根据租户类型获取关联的模块(右边树)
 | 
	
		
			
				|  |  |             String fis = "status=1;saasTypeId=" + saasTypeDictId;
 | 
	
		
			
				|  |  |             List<SaasTypeModuleDO> saasTypeModuleDOList = saasTypeModuleService.search(fis);
 | 
	
		
			
				|  |  |             //获取租户类型关联的生效中的模块
 | 
	
		
			
				|  |  |             List<SaasTypeModuleVO> saasTypeModuleVOS = convertToModels(saasTypeModuleDOList, new ArrayList<>(saasTypeModuleDOList.size()), SaasTypeModuleVO.class);
 | 
	
		
			
				|  |  |             Map<String, List<SaasTypeModuleVO>> map = saasTypeModuleVOS.stream().collect(Collectors.groupingBy(SaasTypeModuleVO::getParentModuleId));
 | 
	
		
			
				|  |  |             saasTypeModuleVOS.forEach(module -> {
 | 
	
		
			
				|  |  |                 List<SaasTypeModuleVO> tmp = map.get(module.getModuleId());
 | 
	
		
			
				|  |  |                 module.setChildren(tmp);
 | 
	
		
			
				|  |  |             });
 | 
	
		
			
				|  |  |             saasTypeModuleVOS = saasTypeModuleVOS.stream()
 | 
	
		
			
				|  |  |                     .filter(module -> CommonContant.DEFAULT_PARENTID.equals(module.getParentModuleId()))
 | 
	
		
			
				|  |  |                     .collect(Collectors.toList());
 | 
	
		
			
				|  |  |             envelop.setDetailModelList(saasTypeModuleVOS);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         envelop.setStatus(EnvelopStatus.success.code);
 | 
	
		
			
				|  |  |         envelop.setMessage("success");
 | 
	
		
			
				|  |  |         return envelop;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @GetMapping(value = BaseRequestMapping.SaasTypeDict.FIND_ALL_EXIST_CHECKED)
 | 
	
		
			
				|  |  |     @ApiOperation(value = "获取租户类型-模块列表(左边树:全部模块,已关联和必选为选中状态)")
 | 
	
		
			
				|  |  |     public ListEnvelop<ModuleVO> findAllExistChecked(
 | 
	
		
			
				|  |  |             @ApiParam(name = "saasTypeDictId", value = "租户类型id")
 | 
	
		
			
				|  |  |             @RequestParam(value = "saasTypeDictId", required = false) String saasTypeDictId) throws Exception {
 | 
	
		
			
				|  |  |         //根据租户类型获取关联的模块
 | 
	
		
			
				|  |  |         String fis = "status=1;saasTypeId=" + saasTypeDictId;
 | 
	
		
			
				|  |  |         List<SaasTypeModuleDO> saasTypeModuleDOList = saasTypeModuleService.search(fis);
 | 
	
		
			
				|  |  |         Set<String> moduleIdSet = new HashSet<>();
 | 
	
		
			
				|  |  |         for (SaasTypeModuleDO saasTypeModuleDO : saasTypeModuleDOList) {
 | 
	
		
			
				|  |  |             moduleIdSet.add(saasTypeModuleDO.getModuleId());
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         //获取生效中的模块
 | 
	
		
			
				|  |  |         String filters = "status=1";
 | 
	
		
			
				|  |  |         List<ModuleDO> modules = moduleService.search(filters);
 | 
	
		
			
				|  |  |         List<ModuleVO> moduleVOs = convertToModels(modules, new ArrayList<>(modules.size()), ModuleVO.class);
 | 
	
		
			
				|  |  |         moduleVOs = moduleVOs.stream()
 | 
	
		
			
				|  |  |                 .filter(module -> {
 | 
	
		
			
				|  |  |                     if (CommonContant.IS_MUST.equals(module.getIsMust())) {
 | 
	
		
			
				|  |  |                         //是否选中(0-表示未选,1-表示已选)
 | 
	
		
			
				|  |  |                         module.setIsCheck(1);
 | 
	
		
			
				|  |  |                     } else {
 | 
	
		
			
				|  |  |                         module.setIsCheck(0);
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  |                     if (moduleIdSet.contains(module.getId())) {
 | 
	
		
			
				|  |  |                         //是否选中(0-表示未选,1-表示已选)
 | 
	
		
			
				|  |  |                         module.setIsCheck(1);
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  |                     return true;
 | 
	
		
			
				|  |  |                 }).collect(Collectors.toList());
 | 
	
		
			
				|  |  |         Map<String, List<ModuleVO>> map = moduleVOs.stream().collect(Collectors.groupingBy(ModuleVO::getParentId));
 | 
	
		
			
				|  |  |         moduleVOs.forEach(module -> {
 | 
	
		
			
				|  |  |             List<ModuleVO> tmp = map.get(module.getId());
 | 
	
		
			
				|  |  |             module.setChildren(tmp);
 | 
	
		
			
				|  |  |         });
 | 
	
		
			
				|  |  |         moduleVOs = moduleVOs.stream()
 | 
	
		
			
				|  |  |                 .filter(module -> CommonContant.DEFAULT_PARENTID.equals(module.getParentId()))
 | 
	
		
			
				|  |  |                 .collect(Collectors.toList());
 | 
	
		
			
				|  |  |         return success(moduleVOs);
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @PostMapping(value = BaseRequestMapping.SaasTypeDict.STATUS)
 | 
	
		
			
				|  |  |     @ApiOperation(value = "生效/失效")
 | 
	
		
			
				|  |  |     public Envelop status(
 | 
	
		
			
				|  |  |             @ApiParam(name = "id", value = "id", required = true)
 | 
	
		
			
				|  |  |             @RequestParam(value = "id") String id,
 | 
	
		
			
				|  |  |             @ApiParam(name = "status", value = " 失效-invalid,生效- effective", required = true)
 | 
	
		
			
				|  |  |             @RequestParam(value = "status") SaasTypeDictDO.Status status) {
 | 
	
		
			
				|  |  |         SaasTypeDictDO saasTypeDictDO = saasTypeDictService.findById(id);
 | 
	
		
			
				|  |  |         saasTypeDictDO.setStatus(status);
 | 
	
		
			
				|  |  |         saasTypeDictService.save(saasTypeDictDO);
 | 
	
		
			
				|  |  |         return success("修改成功");
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | }
 |