Commit d4a6d3d9 authored by 梁光意's avatar 梁光意

修改初始化的分组和树结构的代码

parent 30d2a863
......@@ -3,23 +3,22 @@ package com.syc.slm.slmbi.controller;
import com.syc.slm.common.core.util.R;
import com.syc.slm.slmbi.service.CompanyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.Set;
/**
* @author: guangyi-liang
* @date: 2021/5/20
*/
@RequestMapping("/company")
@RequestMapping("/{appId}/company")
@RestController
@Api(value = "初始化相关管理接口", tags = "初始化相关管理接口")
public class InitController {
public class InitController extends BaseRestController{
@Autowired
......@@ -27,13 +26,15 @@ public class InitController {
@GetMapping("/app-id")
@ApiOperation("测试")
public R<Set<String>> findAll() {
return R.ok(companyService.findAll());
@ApiImplicitParam(name = "appId", value = "租户id", required = true,dataTypeClass = String.class)
public R<Set<String>> findAll(HttpServletRequest request, @PathVariable String appId) {
return call(()-> companyService.findAll(appId));
}
// @PostMapping("/group/tree/init")
// @ApiOperation("测试顶级分组和蜀兴结构")
// public R<Boolean> initGroupAndTree() {
// return R.ok(companyService.initGroupAndTree());
// }
@PostMapping("/group/tree/init")
@ApiOperation("初始化顶级分组和树结构")
@ApiImplicitParam(name = "appId", value = "租户id", required = true,dataTypeClass = String.class)
public R<Boolean> initGroupAndTree(HttpServletRequest request, @PathVariable String appId) {
return call(()-> companyService.initGroupAndTree(appId));
}
}
......@@ -8,11 +8,17 @@ import java.util.Set;
*/
public interface CompanyService {
Set<String> findAll();
/**
* 测试查询所有
* @param appId 当前租户AppId
* @return 公司全部appId
*/
Set<String> findAll(String appId);
/**
* 初始化顶级分组和树
* @param appId 当前租户AppId
* @return 是否成功
*/
boolean initGroupAndTree();
boolean initGroupAndTree(String appId);
}
......@@ -39,22 +39,21 @@ public class CompanyServiceImpl implements CompanyService {
private InstrumentPanelTreeInitMapper treeInitMapper;
@Override
public Set<String> findAll() {
this.initGroupAndTree();
return this.findAllAppId();
public Set<String> findAll(String appId) {
return this.findAllAppId(appId);
}
@Override
@Transactional(rollbackFor = Exception.class)
public boolean initGroupAndTree() {
public boolean initGroupAndTree(String appId) {
String name = "全部分组";
Set<String> stringSet = this.findAllAppId();
for (String appId:stringSet){
Set<String> stringSet = this.findAllAppId(appId);
for (String companyAppId:stringSet){
LambdaQueryWrapper<InstrumentPanelGroupInit> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(InstrumentPanelGroupInit::getAppId,appId);
wrapper.eq(InstrumentPanelGroupInit::getAppId,companyAppId);
Integer count = groupInitMapper.selectCount(wrapper);
if (count <= 0){
InstrumentPanelGroupInit groupInit = this.initGroup(appId,name);
InstrumentPanelGroupInit groupInit = this.initGroup(companyAppId,name);
groupInitMapper.insert(groupInit);
InstrumentPanelTreeInit treeInit = this.initTree(groupInit);
treeInitMapper.insert(treeInit);
......@@ -63,9 +62,9 @@ public class CompanyServiceImpl implements CompanyService {
return true;
}
private Set<String> findAllAppId(){
private Set<String> findAllAppId(String appId){
Map<String,String> map = Maps.newHashMap();
map.put("test","test");
map.put("appId",appId);
R<Set<String>> result = RestTemplateUtils.get(centerConfig.getHost()+centerConfig.getCompanyAppId(), new TypeToken<R<Set<String>>>() {}.getType(),map);
return result.detach();
}
......
......@@ -72,4 +72,4 @@ dc_client:
# historyCurve : /{appId}/variables/history-curve
permissionCodeUrl : /{appId}/bi/permission/code
variableStatusRealTimeDataList: /{appId}/variables/status/real-time/data
companyAppId: /init/bi/company/app-id
\ No newline at end of file
companyAppId: /{appId}/bi/company/init/app-id
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment