初始代码
This commit is contained in:
27
yunzhupaas-system/yunzhupaas-system-controller/pom.xml
Normal file
27
yunzhupaas-system/yunzhupaas-system-controller/pom.xml
Normal file
@@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>yunzhupaas-system</artifactId>
|
||||
<groupId>com.yunzhupaas</groupId>
|
||||
<version>5.2.0-RELEASE</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>yunzhupaas-system-controller</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.yunzhupaas</groupId>
|
||||
<artifactId>yunzhupaas-system-biz</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.yunzhupaas</groupId>
|
||||
<artifactId>yunzhupaas-visualdev-base-entity</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,139 @@
|
||||
package com.yunzhupaas.base.controller;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import com.yunzhupaas.base.controller.SuperController;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import com.yunzhupaas.base.ActionResult;
|
||||
import com.yunzhupaas.base.UserInfo;
|
||||
import com.yunzhupaas.base.entity.AdvancedQueryEntity;
|
||||
import com.yunzhupaas.base.model.advancedquery.AdvancedQueryListVO;
|
||||
import com.yunzhupaas.base.model.advancedquery.AdvancedQuerySchemeForm;
|
||||
import com.yunzhupaas.base.service.AdvancedQueryService;
|
||||
import com.yunzhupaas.base.vo.ListVO;
|
||||
import com.yunzhupaas.constant.MsgCode;
|
||||
import com.yunzhupaas.exception.DataException;
|
||||
import com.yunzhupaas.util.JsonUtil;
|
||||
import com.yunzhupaas.util.JsonUtilEx;
|
||||
import com.yunzhupaas.util.UserProvider;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 高级查询方案管理
|
||||
*
|
||||
* @author 云筑产品开发平台组
|
||||
* @version V3.4.2
|
||||
* @copyright 深圳市乐程软件有限公司(http://www.szlecheng.cn)
|
||||
* @date 2022/5/30
|
||||
*/
|
||||
@Tag(name = "高级查询方案管理", description = "AdvancedQuery")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/AdvancedQuery")
|
||||
public class AdvancedQueryController extends SuperController<AdvancedQueryService, AdvancedQueryEntity> {
|
||||
|
||||
@Autowired
|
||||
private AdvancedQueryService queryService;
|
||||
|
||||
/**
|
||||
* 新建
|
||||
*
|
||||
* @param advancedQuerySchemeForm 实体对象
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "新建方案")
|
||||
@Parameters({
|
||||
@Parameter(name = "advancedQuerySchemeForm", description = "实体对象", required = true)
|
||||
})
|
||||
@PostMapping
|
||||
public ActionResult create(@RequestBody @Valid AdvancedQuerySchemeForm advancedQuerySchemeForm) {
|
||||
AdvancedQueryEntity entity = JsonUtil.getJsonToBean(advancedQuerySchemeForm, AdvancedQueryEntity.class);
|
||||
queryService.create(entity);
|
||||
return ActionResult.success(MsgCode.SU001.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改方案
|
||||
*
|
||||
* @param id 主键
|
||||
* @param advancedQuerySchemeForm 实体对象
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "修改方案")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true),
|
||||
@Parameter(name = "advancedQuerySchemeForm", description = "实体对象", required = true)
|
||||
})
|
||||
@PutMapping("/{id}")
|
||||
public ActionResult update(@PathVariable("id") String id, @RequestBody @Valid AdvancedQuerySchemeForm advancedQuerySchemeForm) {
|
||||
AdvancedQueryEntity entity = JsonUtil.getJsonToBean(advancedQuerySchemeForm, AdvancedQueryEntity.class);
|
||||
entity.setId(id);
|
||||
queryService.updateById(entity);
|
||||
return ActionResult.success(MsgCode.SU004.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*
|
||||
* @param id 主键值
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "删除方案")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true)
|
||||
})
|
||||
@DeleteMapping("/{id}")
|
||||
public ActionResult delete(@PathVariable("id") String id) {
|
||||
UserInfo userInfo = UserProvider.getUser();
|
||||
AdvancedQueryEntity entity = queryService.getInfo(id,userInfo.getUserId());
|
||||
if (entity != null) {
|
||||
queryService.removeById(entity);
|
||||
return ActionResult.success(MsgCode.SU003.get());
|
||||
}
|
||||
return ActionResult.fail(MsgCode.FA003.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*
|
||||
* @param moduleId 功能主键
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "方案列表")
|
||||
@Parameters({
|
||||
@Parameter(name = "moduleId", description = "功能主键", required = true)
|
||||
})
|
||||
@GetMapping("/{moduleId}/List")
|
||||
public ActionResult<ListVO<AdvancedQueryListVO>> list(@PathVariable("moduleId") String moduleId) {
|
||||
UserInfo userInfo = UserProvider.getUser();
|
||||
List<AdvancedQueryEntity> data = queryService.getList(moduleId,userInfo);
|
||||
List<AdvancedQueryListVO> list = JsonUtil.getJsonToList(data, AdvancedQueryListVO.class);
|
||||
ListVO<AdvancedQueryListVO> vo = new ListVO<>();
|
||||
vo.setList(list);
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
/**
|
||||
* 信息
|
||||
*
|
||||
* @param id 主键值
|
||||
* @return ignore
|
||||
* @throws DataException ignore
|
||||
*/
|
||||
@Operation(summary = "获取方案信息")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键值", required = true)
|
||||
})
|
||||
@GetMapping("/{id}")
|
||||
public ActionResult<AdvancedQuerySchemeForm> info(@PathVariable("id") String id) throws DataException {
|
||||
UserInfo userInfo = UserProvider.getUser();
|
||||
AdvancedQueryEntity entity = queryService.getInfo(id,userInfo.getUserId());
|
||||
AdvancedQuerySchemeForm vo = JsonUtilEx.getJsonToBeanEx(entity, AdvancedQuerySchemeForm.class);
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
package com.yunzhupaas.base.controller;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import com.yunzhupaas.base.ActionResult;
|
||||
import com.yunzhupaas.base.entity.AiChatEntity;
|
||||
import com.yunzhupaas.base.model.ai.AiChatVo;
|
||||
import com.yunzhupaas.base.model.ai.AiForm;
|
||||
import com.yunzhupaas.base.model.ai.AiHisVo;
|
||||
import com.yunzhupaas.base.model.ai.AiParam;
|
||||
import com.yunzhupaas.base.service.AiChatService;
|
||||
import com.yunzhupaas.constant.MsgCode;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Tag(name = "AI助手", description = "Aichat")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/Aichat")
|
||||
public class AiChatController {
|
||||
@Autowired
|
||||
private AiChatService aiChatService;
|
||||
|
||||
//ai助手接口
|
||||
@Operation(summary = "发送对话")
|
||||
@Parameters({
|
||||
@Parameter(name = "param", description = "对话内容参数"),
|
||||
})
|
||||
@PostMapping("/send")
|
||||
public ActionResult send(@RequestBody AiParam param) {
|
||||
String content = aiChatService.send(param.getKeyword());
|
||||
return ActionResult.success(MsgCode.SU000.get(), content);
|
||||
}
|
||||
|
||||
@Operation(summary = "ai会话列表")
|
||||
@GetMapping("/history/list")
|
||||
public ActionResult historyList() {
|
||||
List<AiChatVo> listVo = aiChatService.historyList();
|
||||
return ActionResult.success(listVo);
|
||||
}
|
||||
|
||||
@Operation(summary = "ai会话记录")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "会话id"),
|
||||
})
|
||||
@GetMapping("/history/get/{id}")
|
||||
public ActionResult historyGet(@PathVariable("id") String id) {
|
||||
List<AiHisVo> listVo = aiChatService.historyGet(id);
|
||||
return ActionResult.success(listVo);
|
||||
}
|
||||
|
||||
@Operation(summary = "保存历史记录")
|
||||
@Parameters({
|
||||
@Parameter(name = "form", description = "会话信息表单"),
|
||||
})
|
||||
@PostMapping("/history/save")
|
||||
public ActionResult historySave(@RequestBody AiForm form) {
|
||||
String chatId = aiChatService.historySave(form);
|
||||
return ActionResult.success(MsgCode.SU002.get(), chatId);
|
||||
}
|
||||
|
||||
@Operation(summary = "删除ai会话")
|
||||
@Parameters({
|
||||
@Parameter(name = "form", description = "删除ai会话"),
|
||||
})
|
||||
@DeleteMapping("/history/delete/{id}")
|
||||
public ActionResult historyDelete(@PathVariable("id") String id) {
|
||||
AiChatEntity byId = aiChatService.getById(id);
|
||||
if (byId != null) {
|
||||
aiChatService.delete(id);
|
||||
return ActionResult.success(MsgCode.SU003.get());
|
||||
}
|
||||
return ActionResult.fail(MsgCode.FA003.get());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,286 @@
|
||||
package com.yunzhupaas.base.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import com.yunzhupaas.base.ActionResult;
|
||||
import com.yunzhupaas.base.Page;
|
||||
import com.yunzhupaas.base.service.ProvinceService;
|
||||
import com.yunzhupaas.base.vo.ListVO;
|
||||
import com.yunzhupaas.base.entity.ProvinceEntity;
|
||||
import com.yunzhupaas.constant.MsgCode;
|
||||
import com.yunzhupaas.exception.DataException;
|
||||
import com.yunzhupaas.base.model.province.*;
|
||||
import com.yunzhupaas.util.JsonUtil;
|
||||
import com.yunzhupaas.util.JsonUtilEx;
|
||||
import com.yunzhupaas.util.StringUtil;
|
||||
import com.yunzhupaas.util.treeutil.ListToTreeUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 行政区划
|
||||
*
|
||||
* @author 云筑产品开发平台组
|
||||
* @version V3.1.0
|
||||
* @copyright 深圳市乐程软件有限公司
|
||||
* @date 2023/09/27
|
||||
*/
|
||||
@Tag(name = "行政区划", description = "Area")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/Area")
|
||||
public class AreaController extends SuperController<ProvinceService, ProvinceEntity> {
|
||||
|
||||
@Autowired
|
||||
private ProvinceService provinceService;
|
||||
|
||||
/**
|
||||
* 列表(异步加载)
|
||||
*
|
||||
* @param nodeId 节点主键
|
||||
* @param page 关键字
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "列表(异步加载)")
|
||||
@Parameters({
|
||||
@Parameter(name = "nodeId", description = "节点主键", required = true)
|
||||
})
|
||||
@SaCheckPermission("system.area")
|
||||
@GetMapping("/{nodeId}")
|
||||
public ActionResult<ListVO<ProvinceListVO>> list(@PathVariable("nodeId") String nodeId, PaginationProvince page) {
|
||||
List<ProvinceEntity> data = provinceService.getList(nodeId, page);
|
||||
List<ProvinceEntity> dataAll = data;
|
||||
List<ProvinceEntity> result = JsonUtil.getJsonToList(ListToTreeUtil.treeWhere(data, dataAll), ProvinceEntity.class);
|
||||
List<ProvinceListVO> treeList = JsonUtil.getJsonToList(result, ProvinceListVO.class);
|
||||
int i = 0;
|
||||
for (ProvinceListVO entity : treeList) {
|
||||
boolean childNode = provinceService.getList(entity.getId()).size() <= 0;
|
||||
ProvinceListVO provinceListVO = JsonUtil.getJsonToBean(entity, ProvinceListVO.class);
|
||||
provinceListVO.setIsLeaf(childNode);
|
||||
provinceListVO.setHasChildren(!childNode);
|
||||
treeList.set(i, provinceListVO);
|
||||
i++;
|
||||
}
|
||||
ListVO<ProvinceListVO> vo = new ListVO<>();
|
||||
vo.setList(treeList);
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取行政区划下拉框数据
|
||||
*
|
||||
* @param id 主键
|
||||
* @param ids 主键集合
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "获取行政区划下拉框数据")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true),
|
||||
@Parameter(name = "ids", description = "主键集合", required = true)
|
||||
})
|
||||
@GetMapping("/{id}/Selector/{ids}")
|
||||
public ActionResult<ListVO<ProvinceSelectListVO>> selectList(@PathVariable("id") String id, @PathVariable("ids") String ids) {
|
||||
List<ProvinceEntity> data = provinceService.getList(id);
|
||||
data = data.stream().filter(t -> t.getEnabledMark() == 1).collect(Collectors.toList());
|
||||
if (!"0".equals(ids)) {
|
||||
//排除子集
|
||||
filterData(data, new ArrayList<>(Arrays.asList(new String[]{ids})));
|
||||
}
|
||||
List<ProvinceSelectListVO> treeList = JsonUtil.getJsonToList(data, ProvinceSelectListVO.class);
|
||||
int i = 0;
|
||||
for (ProvinceSelectListVO entity : treeList) {
|
||||
// boolean childNode = provinceService.getList(entity.getId()).size() <= 0;
|
||||
ProvinceSelectListVO provinceListVO = JsonUtil.getJsonToBean(entity, ProvinceSelectListVO.class);
|
||||
provinceListVO.setIsLeaf(false);
|
||||
treeList.set(i, provinceListVO);
|
||||
i++;
|
||||
}
|
||||
ListVO<ProvinceSelectListVO> vo = new ListVO<>();
|
||||
vo.setList(treeList);
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归排除子集
|
||||
*
|
||||
* @param data 普通列表
|
||||
* @param id ignore
|
||||
*/
|
||||
private void filterData(List<ProvinceEntity> data, List<String> id) {
|
||||
List<ProvinceEntity> collect = null;
|
||||
//获取子集信息
|
||||
for (String ids : id) {
|
||||
collect = data.stream().filter(t -> ids.equals(t.getParentId())).collect(Collectors.toList());
|
||||
data.removeAll(collect);
|
||||
}
|
||||
//递归移除子集的子集
|
||||
if(collect != null){
|
||||
if (collect.size() > 0) {
|
||||
filterData(data, collect.stream().map(t -> t.getId()).collect(Collectors.toList()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 信息
|
||||
*
|
||||
* @param id 主键值
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "获取行政区划信息")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true)
|
||||
})
|
||||
@SaCheckPermission("system.area")
|
||||
@GetMapping("/{id}/Info")
|
||||
public ActionResult<ProvinceInfoVO> info(@PathVariable("id") String id) throws DataException {
|
||||
ProvinceEntity entity = provinceService.getInfo(id);
|
||||
ProvinceInfoVO vo = JsonUtilEx.getJsonToBeanEx(entity, ProvinceInfoVO.class);
|
||||
if (!"-1".equals(entity.getParentId())) {
|
||||
ProvinceEntity parent = provinceService.getInfo(entity.getParentId());
|
||||
vo.setParentName(parent.getFullName());
|
||||
}
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新建
|
||||
*
|
||||
* @param provinceCrForm 实体对象
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "添加行政区划")
|
||||
@Parameters({
|
||||
@Parameter(name = "provinceCrForm", description = "实体对象", required = true)
|
||||
})
|
||||
@SaCheckPermission("system.area")
|
||||
@PostMapping
|
||||
public ActionResult create(@RequestBody @Valid ProvinceCrForm provinceCrForm) {
|
||||
ProvinceEntity entity = JsonUtil.getJsonToBean(provinceCrForm, ProvinceEntity.class);
|
||||
if (provinceService.isExistByEnCode(provinceCrForm.getEnCode(), entity.getId())) {
|
||||
return ActionResult.fail(MsgCode.SYS001.get());
|
||||
}
|
||||
if (StringUtil.isEmpty(provinceCrForm.getParentId())) {
|
||||
entity.setParentId("-1");
|
||||
}
|
||||
if (entity.getParentId().equals("-1")) {
|
||||
entity.setType("1");
|
||||
} else {
|
||||
ProvinceEntity info = provinceService.getInfo(entity.getParentId());
|
||||
int type = info!=null? Integer.valueOf(info.getType()) + 1 : 1;
|
||||
entity.setType(String.valueOf(type));
|
||||
}
|
||||
provinceService.create(entity);
|
||||
return ActionResult.success(MsgCode.SU001.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新
|
||||
*
|
||||
* @param id 主键值
|
||||
* @param provinceUpForm ignore
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "修改行政区划")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键值", required = true),
|
||||
@Parameter(name = "provinceUpForm", description = "实体对象", required = true)
|
||||
})
|
||||
@SaCheckPermission("system.area")
|
||||
@PutMapping("/{id}")
|
||||
public ActionResult update(@PathVariable("id") String id, @RequestBody @Valid ProvinceUpForm provinceUpForm) {
|
||||
ProvinceEntity entity = JsonUtil.getJsonToBean(provinceUpForm, ProvinceEntity.class);
|
||||
if (provinceService.isExistByEnCode(provinceUpForm.getEnCode(), id)) {
|
||||
return ActionResult.fail(MsgCode.SYS001.get());
|
||||
}
|
||||
boolean flag = provinceService.update(id, entity);
|
||||
if (!flag) {
|
||||
return ActionResult.fail(MsgCode.FA002.get());
|
||||
}
|
||||
return ActionResult.success(MsgCode.SU004.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*
|
||||
* @param id 主键值
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "删除")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键值", required = true)
|
||||
})
|
||||
@SaCheckPermission("system.area")
|
||||
@DeleteMapping("/{id}")
|
||||
public ActionResult delete(@PathVariable("id") String id) {
|
||||
if (provinceService.getList(id).size() == 0) {
|
||||
ProvinceEntity entity = provinceService.getInfo(id);
|
||||
if (entity != null) {
|
||||
provinceService.delete(entity);
|
||||
return ActionResult.success(MsgCode.SU003.get());
|
||||
}
|
||||
return ActionResult.fail(MsgCode.FA003.get());
|
||||
} else {
|
||||
return ActionResult.fail(MsgCode.SYS002.get());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新行政区划状态
|
||||
*
|
||||
* @param id 主键值
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "更新行政区划状态")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键值", required = true)
|
||||
})
|
||||
@SaCheckPermission("system.area")
|
||||
@PutMapping("/{id}/Actions/State")
|
||||
public ActionResult upState(@PathVariable("id") String id) {
|
||||
ProvinceEntity entity = provinceService.getInfo(id);
|
||||
if (entity.getEnabledMark() == null || "1".equals(String.valueOf(entity.getEnabledMark()))) {
|
||||
entity.setEnabledMark(0);
|
||||
} else {
|
||||
entity.setEnabledMark(1);
|
||||
}
|
||||
boolean flag = provinceService.update(id, entity);
|
||||
if (!flag) {
|
||||
return ActionResult.fail(MsgCode.FA002.get());
|
||||
}
|
||||
return ActionResult.success(MsgCode.SU004.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 行政区划id转名称
|
||||
*
|
||||
* @param model 二维数组
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "行政区划id转名称")
|
||||
@Parameters({
|
||||
@Parameter(name = "model", description = "二维数组", required = true)
|
||||
})
|
||||
@PostMapping("/GetAreaByIds")
|
||||
public ActionResult getAreaByIds(@RequestBody AreaModel model) {
|
||||
// 返回给前端的list
|
||||
List<List<String>> list = new LinkedList<>();
|
||||
for (List<String> idList : model.getIdsList()) {
|
||||
List<ProvinceEntity> proList = provinceService.getProList(idList);
|
||||
List<String> collect = proList.stream().map(ProvinceEntity::getFullName).collect(Collectors.toList());
|
||||
list.add(collect);
|
||||
}
|
||||
return ActionResult.success(list);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,253 @@
|
||||
package com.yunzhupaas.base.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import cn.dev33.satoken.annotation.SaMode;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.Valid;
|
||||
import com.yunzhupaas.base.ActionResult;
|
||||
import com.yunzhupaas.base.Pagination;
|
||||
import com.yunzhupaas.base.entity.BaseLangEntity;
|
||||
import com.yunzhupaas.base.entity.DictionaryDataEntity;
|
||||
import com.yunzhupaas.base.model.language.*;
|
||||
import com.yunzhupaas.base.service.BaseLangService;
|
||||
import com.yunzhupaas.base.service.DictionaryDataService;
|
||||
import com.yunzhupaas.base.util.ExcelTool;
|
||||
import com.yunzhupaas.base.vo.DownloadVO;
|
||||
import com.yunzhupaas.config.ConfigValueUtil;
|
||||
import com.yunzhupaas.constant.ConfigConst;
|
||||
import com.yunzhupaas.constant.MsgCode;
|
||||
import com.yunzhupaas.model.ExcelColumnAttr;
|
||||
import com.yunzhupaas.model.ExcelImportVO;
|
||||
import com.yunzhupaas.model.ExcelModel;
|
||||
import com.yunzhupaas.util.JsonUtil;
|
||||
import com.yunzhupaas.util.RegexUtils;
|
||||
import com.yunzhupaas.util.StringUtil;
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 多语言管理
|
||||
*
|
||||
* @author 云筑产品开发平台组
|
||||
* @version v5.0.0
|
||||
* @copyright 深圳市乐程软件有限公司
|
||||
* @date 2024/4/28 11:26:57
|
||||
*/
|
||||
@Tag(name = "多语言配置", description = "BaseLang")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/BaseLang")
|
||||
public class BaseLangController {
|
||||
|
||||
@Autowired
|
||||
private BaseLangService baseLangService;
|
||||
|
||||
@Autowired
|
||||
private ConfigValueUtil configValueUtil;
|
||||
|
||||
@Autowired
|
||||
private DictionaryDataService dictionaryDataApi;
|
||||
|
||||
@Operation(summary = "标记翻译列表")
|
||||
@GetMapping("/List")
|
||||
public ActionResult getList(Pagination pagination) {
|
||||
// pagination.setPageSize(100000);
|
||||
BaseLangListVO list = baseLangService.getList(pagination);
|
||||
// List list1 = list.getList();
|
||||
// for(Object o : list1) {
|
||||
// Map<String, Object> stringObjectMap = JsonUtil.entityToMap(o);
|
||||
// LinkedHashMap<String, String> map = new LinkedHashMap<>();
|
||||
// map.put("zh-CN",stringObjectMap.get("zh_CN").toString());
|
||||
// map.put("zh-TW",stringObjectMap.get("zh_TW").toString());
|
||||
// map.put("en",stringObjectMap.get("en").toString());
|
||||
// BaseLangForm form =new BaseLangForm();
|
||||
// form.setType(0);
|
||||
// form.setEnCode(stringObjectMap.get("code").toString());
|
||||
// form.setMap(map);
|
||||
// baseLangService.create(form);
|
||||
// }
|
||||
return ActionResult.success(list);
|
||||
}
|
||||
|
||||
@Operation(summary = "标记翻译列表")
|
||||
@SaCheckPermission("system.language")
|
||||
@GetMapping()
|
||||
public ActionResult list(BaseLangPage pagination) {
|
||||
BaseLangListVO list = baseLangService.list(pagination);
|
||||
return ActionResult.success(list);
|
||||
}
|
||||
|
||||
@Operation(summary = "创建")
|
||||
@Parameters({
|
||||
@Parameter(name = "form", description = "多语言表单对象", required = true)
|
||||
})
|
||||
@SaCheckPermission(value = {"system.language", "onlineDev.webDesign"}, mode = SaMode.OR)
|
||||
@PostMapping()
|
||||
public ActionResult create(@RequestBody @Valid BaseLangForm form) {
|
||||
if (RegexUtils.checkEnCode2(form.getEnCode())) {
|
||||
ActionResult.fail(MsgCode.SYS050.get());
|
||||
}
|
||||
baseLangService.create(form);
|
||||
return ActionResult.success(MsgCode.SU001.get());
|
||||
}
|
||||
|
||||
@Operation(summary = "修改")
|
||||
@Parameters({
|
||||
@Parameter(name = "form", description = "多语言表单对象", required = true)
|
||||
})
|
||||
@SaCheckPermission("system.language")
|
||||
@PutMapping("/{id}")
|
||||
public ActionResult update(@PathVariable("id") String id, @RequestBody @Valid BaseLangForm form) {
|
||||
if (RegexUtils.checkEnCode2(form.getEnCode())) {
|
||||
ActionResult.fail(MsgCode.SYS050.get());
|
||||
}
|
||||
form.setId(id);
|
||||
baseLangService.update(form);
|
||||
return ActionResult.success(MsgCode.SU004.get());
|
||||
}
|
||||
|
||||
@Operation(summary = "详情")
|
||||
@Parameters({
|
||||
@Parameter(name = "enCode", description = "翻译标记", required = true)
|
||||
})
|
||||
@SaCheckPermission("system.language")
|
||||
@GetMapping("/{id}")
|
||||
public ActionResult info(@PathVariable("id") String id) {
|
||||
BaseLangForm info = baseLangService.getInfo(id);
|
||||
return ActionResult.success(info);
|
||||
}
|
||||
|
||||
@Operation(summary = "删除")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "翻译标记", required = true)
|
||||
})
|
||||
@SaCheckPermission("system.language")
|
||||
@DeleteMapping("/{id}")
|
||||
public ActionResult delete(@PathVariable("id") String id) {
|
||||
baseLangService.delete(id);
|
||||
return ActionResult.success();
|
||||
}
|
||||
|
||||
@Operation(summary = "获取语种json")
|
||||
@Parameters({
|
||||
@Parameter(name = "language", description = "语种编码", required = true)
|
||||
})
|
||||
@GetMapping("/LangJson")
|
||||
public ActionResult LangJson(Locale locale) {
|
||||
if (locale == null || StringUtil.isEmpty(locale.toLanguageTag()) || "und".equals(locale.toLanguageTag())) {
|
||||
locale = Locale.SIMPLIFIED_CHINESE;
|
||||
}
|
||||
String languageJson = baseLangService.getLanguageJson(locale);
|
||||
return ActionResult.success(MsgCode.SU000.get(), languageJson);
|
||||
}
|
||||
|
||||
@Operation(summary = "获取语种json")
|
||||
@Parameters({
|
||||
@Parameter(name = "language", description = "语种编码", required = true)
|
||||
})
|
||||
@GetMapping("/ServerLang")
|
||||
public ActionResult<List<BaseLangVo>> getServerLang(Locale locale) {
|
||||
List<BaseLangEntity> serverLang = baseLangService.getServerLang(locale);
|
||||
List<BaseLangVo> list = JsonUtil.getJsonToList(serverLang, BaseLangVo.class);
|
||||
return ActionResult.success(list);
|
||||
}
|
||||
|
||||
//++++++++++++++++++++++++++++++++++以下导入导出接口++++++++++++++++++++++++++++++++++++++++++
|
||||
|
||||
@Operation(summary = "模板下载")
|
||||
@SaCheckPermission("system.language")
|
||||
@GetMapping("/TemplateDownload")
|
||||
public ActionResult<DownloadVO> TemplateDownload() {
|
||||
BaseLangColumn columnMap = new BaseLangColumn(getDicLangMap());
|
||||
String excelName = columnMap.getExcelName();
|
||||
Map<String, String> keyMap = columnMap.getColumnByType(0);
|
||||
List<ExcelColumnAttr> models = columnMap.getFieldsModel(false);
|
||||
List<Map<String, Object>> list = columnMap.getDefaultList();
|
||||
Map<String, String[]> optionMap = new HashMap<>();
|
||||
optionMap.put("type", new String[]{"客户端", "服务端"});
|
||||
|
||||
ExcelModel excelModel = ExcelModel.builder().models(models).selectKey(new ArrayList<>(keyMap.keySet())).optionMap(optionMap).hasHeader(true).build();
|
||||
DownloadVO vo = ExcelTool.getImportTemplate(configValueUtil.getTemporaryFilePath(), excelName, keyMap, list, excelModel);
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 从字典获取语言map
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private Map<String, String> getDicLangMap() {
|
||||
List<DictionaryDataEntity> langTypeList = dictionaryDataApi.getListByTypeDataCode(ConfigConst.BASE_LANGUAGE);
|
||||
Map<String, String> collect = new LinkedHashMap<>();
|
||||
langTypeList.forEach(t -> collect.put(t.getEnCode(), t.getFullName()));
|
||||
return collect;
|
||||
}
|
||||
|
||||
@Operation(summary = "上传导入Excel")
|
||||
@SaCheckPermission("system.language")
|
||||
@PostMapping("/Uploader")
|
||||
public ActionResult<Object> Uploader() {
|
||||
return ExcelTool.uploader();
|
||||
}
|
||||
|
||||
@Operation(summary = "导入数据")
|
||||
@SaCheckPermission("system.language")
|
||||
@PostMapping("/ImportData")
|
||||
public ActionResult<ExcelImportVO> ImportData(@RequestBody BaseLangModel model) {
|
||||
// 导入字段
|
||||
BaseLangColumn columnMap = new BaseLangColumn(getDicLangMap());
|
||||
Map<String, String> keyMap = columnMap.getColumnByType(0);
|
||||
Map<String, Object> headAndDataMap = ExcelTool.importPreview(configValueUtil.getTemporaryFilePath(), model.getFileName(), keyMap,1,1);
|
||||
List<Map<String, Object>> listData = (List<Map<String, Object>>) headAndDataMap.get("dataRow");
|
||||
List<BaseLangEntity> addList = new ArrayList<>();
|
||||
List<Map<String, Object>> failList = new ArrayList<>();
|
||||
// 对数据做校验 (处理)
|
||||
this.validateImportData(listData, addList, failList);
|
||||
//写入数据
|
||||
baseLangService.importSaveOrUpdate(addList);
|
||||
return ActionResult.success(MsgCode.IMP001.get());
|
||||
}
|
||||
|
||||
public void validateImportData(List<Map<String, Object>> listData, List<BaseLangEntity> addList, List<Map<String, Object>> failList) {
|
||||
List<DictionaryDataEntity> langTypeList = dictionaryDataApi.getListByTypeDataCode(ConfigConst.BASE_LANGUAGE);
|
||||
for (Map<String, Object> map : listData) {
|
||||
if (MapUtils.isNotEmpty(map) && map.get("enCode")!=null && StringUtil.isNotBlank(map.get("enCode").toString()) && RegexUtils.checkEnCode2(map.get("enCode").toString())) {
|
||||
BaseLangEntity baseLangEntity = new BaseLangEntity();
|
||||
baseLangEntity.setEnCode(map.get("enCode").toString());
|
||||
Integer type = 0;
|
||||
if (map.get("type") != null && StringUtil.isNotBlank(map.get("type").toString())) {
|
||||
type = "服务端".equals(map.get("type").toString()) ? 1 : 0;
|
||||
}
|
||||
baseLangEntity.setType(type);
|
||||
boolean allNull = true;
|
||||
List<BaseLangEntity> thisList =new ArrayList<>();
|
||||
for (DictionaryDataEntity item : langTypeList) {
|
||||
String enCode = item.getEnCode();
|
||||
String fullName = "";
|
||||
if (map.get(enCode) != null) {
|
||||
fullName = map.get(enCode).toString();
|
||||
}
|
||||
if(StringUtil.isNotBlank(fullName)){
|
||||
allNull = false;
|
||||
}
|
||||
baseLangEntity.setLanguage(enCode);
|
||||
baseLangEntity.setFullName(fullName);
|
||||
BaseLangEntity entity = BeanUtil.copyProperties(baseLangEntity, BaseLangEntity.class);
|
||||
thisList.add(entity);
|
||||
}
|
||||
if(!allNull){
|
||||
addList.addAll(thisList);
|
||||
}
|
||||
} else {
|
||||
failList.add(map);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,327 @@
|
||||
package com.yunzhupaas.base.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import com.yunzhupaas.annotation.HandleLog;
|
||||
import com.yunzhupaas.base.ActionResult;
|
||||
import com.yunzhupaas.base.entity.DictionaryDataEntity;
|
||||
import com.yunzhupaas.base.model.billrule.*;
|
||||
import com.yunzhupaas.base.service.DictionaryDataService;
|
||||
import com.yunzhupaas.base.vo.DownloadVO;
|
||||
import com.yunzhupaas.base.vo.PageListVO;
|
||||
import com.yunzhupaas.base.vo.PaginationVO;
|
||||
import com.yunzhupaas.base.service.BillRuleService;
|
||||
import com.yunzhupaas.base.entity.BillRuleEntity;
|
||||
import com.yunzhupaas.config.ConfigValueUtil;
|
||||
import com.yunzhupaas.constant.MsgCode;
|
||||
import com.yunzhupaas.exception.DataException;
|
||||
import com.yunzhupaas.permission.entity.UserEntity;
|
||||
import com.yunzhupaas.permission.service.UserService;
|
||||
import com.yunzhupaas.util.*;
|
||||
import com.yunzhupaas.emnus.ModuleTypeEnum;
|
||||
import com.yunzhupaas.util.DataFileExport;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 单据规则
|
||||
*
|
||||
* @author 云筑产品开发平台组
|
||||
* @version V3.1.0
|
||||
* @copyright 深圳市乐程软件有限公司
|
||||
* @date 2023/09/27
|
||||
*/
|
||||
@Tag(name = "单据规则", description = "BillRule")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/BillRule")
|
||||
public class BillRuleController extends SuperController<BillRuleService, BillRuleEntity> {
|
||||
|
||||
@Autowired
|
||||
private DataFileExport fileExport;
|
||||
@Autowired
|
||||
private ConfigValueUtil configValueUtil;
|
||||
@Autowired
|
||||
private BillRuleService billRuleService;
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
@Autowired
|
||||
private DictionaryDataService dictionaryDataService;
|
||||
/**
|
||||
* 列表
|
||||
*
|
||||
* @param pagination 分页参数
|
||||
* @return ignore
|
||||
*/
|
||||
@HandleLog(moduleName = "单据规则", requestMethod = "查询")
|
||||
@Operation(summary = "获取单据规则列表(带分页)")
|
||||
@SaCheckPermission("system.billRule")
|
||||
@GetMapping
|
||||
public ActionResult<PageListVO<BillRuleListVO>> list(BillRulePagination pagination) {
|
||||
List<BillRuleEntity> list = billRuleService.getList(pagination);
|
||||
List<BillRuleListVO> listVO = new ArrayList<>();
|
||||
list.forEach(entity->{
|
||||
BillRuleListVO vo = JsonUtil.getJsonToBean(entity, BillRuleListVO.class);
|
||||
if(StringUtil.isNotEmpty(entity.getCategory())){
|
||||
DictionaryDataEntity dataEntity = dictionaryDataService.getInfo(entity.getCategory());
|
||||
vo.setCategory(dataEntity != null ? dataEntity.getFullName() : null);
|
||||
}
|
||||
|
||||
UserEntity userEntity = userService.getInfo(entity.getCreatorUserId());
|
||||
if(userEntity != null){
|
||||
vo.setCreatorUser(userEntity.getRealName() + "/" + userEntity.getAccount());
|
||||
}
|
||||
listVO.add(vo);
|
||||
});
|
||||
PaginationVO paginationVO = JsonUtil.getJsonToBean(pagination, PaginationVO.class);
|
||||
return ActionResult.page(listVO, paginationVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*
|
||||
* @return ignore
|
||||
*/
|
||||
@HandleLog(moduleName = "单据规则", requestMethod = "查询")
|
||||
@Operation(summary = "获取单据规则下拉框")
|
||||
@GetMapping("/Selector")
|
||||
public ActionResult selectList(BillRulePagination pagination) {
|
||||
List<BillRuleEntity> list = billRuleService.getListByCategory(pagination.getCategoryId(),pagination);
|
||||
List<BillRuleListVO> listVO = new ArrayList<>();
|
||||
list.forEach(entity->{
|
||||
BillRuleListVO vo = JsonUtil.getJsonToBean(entity, BillRuleListVO.class);
|
||||
if(StringUtil.isNotEmpty(entity.getCategory())){
|
||||
DictionaryDataEntity dataEntity = dictionaryDataService.getInfo(entity.getCategory());
|
||||
vo.setCategory(dataEntity != null ? dataEntity.getFullName() : null);
|
||||
}
|
||||
|
||||
UserEntity userEntity = userService.getInfo(entity.getCreatorUserId());
|
||||
if(userEntity != null){
|
||||
vo.setCreatorUser(userEntity.getRealName() + "/" + userEntity.getAccount());
|
||||
}
|
||||
listVO.add(vo);
|
||||
});
|
||||
PaginationVO paginationVO = JsonUtil.getJsonToBean(pagination, PaginationVO.class);
|
||||
return ActionResult.page(listVO, paginationVO);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 更新组织状态
|
||||
*
|
||||
* @param id 主键值
|
||||
* @return ignore
|
||||
*/
|
||||
@HandleLog(moduleName = "单据规则", requestMethod = "修改")
|
||||
@Operation(summary = "更新单据规则状态")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键值", required = true)
|
||||
})
|
||||
@SaCheckPermission("system.billRule")
|
||||
@PutMapping("/{id}/Actions/State")
|
||||
public ActionResult update(@PathVariable("id") String id) {
|
||||
BillRuleEntity entity = billRuleService.getInfo(id);
|
||||
if (entity != null) {
|
||||
if ("1".equals(String.valueOf(entity.getEnabledMark()))) {
|
||||
entity.setEnabledMark(0);
|
||||
} else {
|
||||
entity.setEnabledMark(1);
|
||||
}
|
||||
billRuleService.update(entity.getId(), entity);
|
||||
return ActionResult.success(MsgCode.SU004.get());
|
||||
}
|
||||
return ActionResult.fail(MsgCode.FA002.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 信息
|
||||
*
|
||||
* @param id 主键值
|
||||
* @return ignore
|
||||
*/
|
||||
@HandleLog(moduleName = "单据规则", requestMethod = "查询")
|
||||
@Operation(summary = "获取单据规则信息")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键值", required = true)
|
||||
})
|
||||
@SaCheckPermission("system.billRule")
|
||||
@GetMapping("/{id}")
|
||||
public ActionResult<BillRuleInfoVO> info(@PathVariable("id") String id) throws DataException {
|
||||
BillRuleEntity entity = billRuleService.getInfo(id);
|
||||
BillRuleInfoVO vo = JsonUtilEx.getJsonToBeanEx(entity, BillRuleInfoVO.class);
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取单据流水号
|
||||
*
|
||||
* @param enCode 参数编码
|
||||
* @return ignore
|
||||
*/
|
||||
@HandleLog(moduleName = "单据规则", requestMethod = "查询")
|
||||
@Operation(summary = "获取单据流水号(工作流调用)")
|
||||
@Parameters({
|
||||
@Parameter(name = "enCode", description = "参数编码", required = true)
|
||||
})
|
||||
@GetMapping("/BillNumber/{enCode}")
|
||||
public ActionResult getBillNumber(@PathVariable("enCode") String enCode) throws DataException {
|
||||
String data = billRuleService.getBillNumber(enCode, false);
|
||||
return ActionResult.success(MsgCode.SU019.get(), data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新建
|
||||
*
|
||||
* @param billRuleCrForm 实体对象
|
||||
* @return ignore
|
||||
*/
|
||||
@HandleLog(moduleName = "单据规则", requestMethod = "新增")
|
||||
@Operation(summary = "添加单据规则")
|
||||
@Parameters({
|
||||
@Parameter(name = "billRuleCrForm", description = "实体对象", required = true)
|
||||
})
|
||||
@SaCheckPermission("system.billRule")
|
||||
@PostMapping
|
||||
public ActionResult create(@RequestBody @Valid BillRuleCrForm billRuleCrForm) {
|
||||
|
||||
BillRuleEntity entity = JsonUtil.getJsonToBean(billRuleCrForm, BillRuleEntity.class);
|
||||
if (billRuleService.isExistByFullName(entity.getFullName(), entity.getId())) {
|
||||
return ActionResult.fail(MsgCode.EXIST001.get());
|
||||
}
|
||||
if (billRuleService.isExistByEnCode(entity.getEnCode(), entity.getId())) {
|
||||
return ActionResult.fail(MsgCode.EXIST002.get());
|
||||
}
|
||||
billRuleService.create(entity);
|
||||
return ActionResult.success(MsgCode.SU001.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新
|
||||
*
|
||||
* @param billRuleUpForm 实体对象
|
||||
* @param id 主键值
|
||||
* @return ignore
|
||||
*/
|
||||
@HandleLog(moduleName = "单据规则", requestMethod = "修改")
|
||||
@Operation(summary = "修改单据规则")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键值", required = true),
|
||||
@Parameter(name = "billRuleUpForm", description = "实体对象", required = true)
|
||||
})
|
||||
@SaCheckPermission("system.billRule")
|
||||
@PutMapping("/{id}")
|
||||
public ActionResult update(@PathVariable("id") String id, @RequestBody BillRuleUpForm billRuleUpForm) {
|
||||
BillRuleEntity entity = JsonUtil.getJsonToBean(billRuleUpForm, BillRuleEntity.class);
|
||||
if (billRuleService.isExistByFullName(entity.getFullName(), id)) {
|
||||
return ActionResult.fail(MsgCode.EXIST001.get());
|
||||
}
|
||||
if (billRuleService.isExistByEnCode(entity.getEnCode(), id)) {
|
||||
return ActionResult.fail(MsgCode.EXIST002.get());
|
||||
}
|
||||
// 单据生成规则有改变则重新生成流水
|
||||
BillRuleEntity billRuleEntity = billRuleService.getInfo(id);
|
||||
if (entity.getType() == 1 && (
|
||||
(StringUtil.isNotEmpty(billRuleEntity.getPrefix()) && StringUtil.isNotEmpty(entity.getPrefix()) &&
|
||||
!ObjectUtil.equal(billRuleEntity.getPrefix().length(), entity.getPrefix().length())) ||
|
||||
(StringUtil.isNotEmpty(billRuleEntity.getSuffix()) && StringUtil.isNotEmpty(entity.getSuffix()) &&
|
||||
!ObjectUtil.equal(billRuleEntity.getSuffix().length(), entity.getSuffix().length())) ||
|
||||
!ObjectUtil.equal(billRuleEntity.getDigit(), entity.getDigit()) ||
|
||||
!ObjectUtil.equal(billRuleEntity.getDateFormat(), entity.getDateFormat())
|
||||
)
|
||||
) {
|
||||
entity.setOutputNumber(null);
|
||||
entity.setThisNumber(null);
|
||||
}else {
|
||||
entity.setOutputNumber(billRuleEntity.getOutputNumber());
|
||||
entity.setThisNumber(billRuleEntity.getThisNumber());
|
||||
}
|
||||
boolean flag = billRuleService.update(id, entity);
|
||||
if (!flag) {
|
||||
return ActionResult.fail(MsgCode.FA002.get());
|
||||
}
|
||||
return ActionResult.success(MsgCode.SU004.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*
|
||||
* @param id 主键值
|
||||
* @return ignore
|
||||
*/
|
||||
@HandleLog(moduleName = "单据规则", requestMethod = "删除")
|
||||
@Operation(summary = "删除单据规则")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键值", required = true)
|
||||
})
|
||||
@SaCheckPermission("system.billRule")
|
||||
@DeleteMapping("/{id}")
|
||||
public ActionResult delete(@PathVariable("id") String id) {
|
||||
BillRuleEntity entity = billRuleService.getInfo(id);
|
||||
if (entity != null) {
|
||||
if (!StringUtil.isEmpty(entity.getOutputNumber())) {
|
||||
return ActionResult.fail(MsgCode.SYS003.get());
|
||||
} else {
|
||||
billRuleService.delete(entity);
|
||||
return ActionResult.success(MsgCode.SU003.get());
|
||||
}
|
||||
}
|
||||
return ActionResult.fail(MsgCode.FA003.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出单据规则
|
||||
*
|
||||
* @param id 打印模板id
|
||||
* @return ignore
|
||||
*/
|
||||
@HandleLog(moduleName = "单据规则", requestMethod = "导出")
|
||||
@Operation(summary = "导出")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键值", required = true)
|
||||
})
|
||||
@SaCheckPermission("system.billRule")
|
||||
@GetMapping("/{id}/Actions/Export")
|
||||
public ActionResult<DownloadVO> export(@PathVariable String id) {
|
||||
BillRuleEntity entity = billRuleService.getInfo(id);
|
||||
//导出文件
|
||||
DownloadVO downloadVO = fileExport.exportFile(entity, configValueUtil.getTemporaryFilePath(), entity.getFullName(), ModuleTypeEnum.SYSTEM_BILLRULE.getTableName());
|
||||
return ActionResult.success(downloadVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导入单据规则
|
||||
*
|
||||
* @param multipartFile 备份json文件
|
||||
* @param type 0/1 跳过/追加
|
||||
* @return 执行结果标识
|
||||
*/
|
||||
@HandleLog(moduleName = "单据规则", requestMethod = "导入")
|
||||
@Operation(summary = "导入")
|
||||
@SaCheckPermission("system.billRule")
|
||||
@PostMapping(value = "/Actions/Import", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
public ActionResult importData(@RequestPart("file") MultipartFile multipartFile,
|
||||
@RequestParam("type") Integer type) throws DataException {
|
||||
//判断是否为.json结尾
|
||||
if (FileUtil.existsSuffix(multipartFile, ModuleTypeEnum.SYSTEM_BILLRULE.getTableName())) {
|
||||
return ActionResult.fail(MsgCode.IMP002.get());
|
||||
}
|
||||
try {
|
||||
String fileContent = FileUtil.getFileContent(multipartFile);
|
||||
BillRuleEntity entity = JsonUtil.getJsonToBean(fileContent, BillRuleEntity.class);
|
||||
return billRuleService.ImportData(entity, type);
|
||||
} catch (Exception e) {
|
||||
throw new DataException(MsgCode.IMP004.get());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,144 @@
|
||||
package com.yunzhupaas.base.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import com.yunzhupaas.base.ActionResult;
|
||||
import com.yunzhupaas.base.Page;
|
||||
import com.yunzhupaas.base.model.cachemanage.PaginationCacheManage;
|
||||
import com.yunzhupaas.base.vo.ListVO;
|
||||
import com.yunzhupaas.base.model.cachemanage.CacheManageInfoVO;
|
||||
import com.yunzhupaas.base.model.cachemanage.CacheManageListVO;
|
||||
import com.yunzhupaas.constant.MsgCode;
|
||||
import com.yunzhupaas.util.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 缓存管理
|
||||
*
|
||||
* @author 云筑产品开发平台组
|
||||
* @version V3.1.0
|
||||
* @copyright 深圳市乐程软件有限公司
|
||||
* @date 2023/09/27
|
||||
*/
|
||||
@Tag(name = "缓存管理", description = "CacheManage")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/CacheManage")
|
||||
public class CacheManageController {
|
||||
|
||||
@Autowired
|
||||
private RedisUtil redisUtil;
|
||||
|
||||
|
||||
/**
|
||||
* 获取缓存列表
|
||||
*
|
||||
* @param page 分页参数
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "获取缓存列表")
|
||||
@SaCheckPermission("system.cache")
|
||||
@GetMapping
|
||||
public ActionResult<ListVO<CacheManageListVO>> getList(PaginationCacheManage page) {
|
||||
String tenantId = UserProvider.getUser().getTenantId();
|
||||
List<CacheManageListVO> list = new ArrayList<>();
|
||||
Set<String> data = redisUtil.getAllKeys();
|
||||
for (String key : data) {
|
||||
try {
|
||||
if (!StringUtil.isEmpty(tenantId) && key.contains(tenantId)) {
|
||||
CacheManageListVO model = new CacheManageListVO();
|
||||
model.setName(key);
|
||||
model.setCacheSize(String.valueOf(redisUtil.getString(key)).getBytes().length);
|
||||
model.setOverdueTime(new Date((DateUtil.getTime(new Date()) + redisUtil.getLiveTime(key)) * 1000).getTime());
|
||||
list.add(model);
|
||||
} else if (StringUtil.isEmpty(tenantId)) {
|
||||
CacheManageListVO model = new CacheManageListVO();
|
||||
model.setName(key);
|
||||
model.setCacheSize(String.valueOf(redisUtil.getString(key)).getBytes().length);
|
||||
model.setOverdueTime(new Date((DateUtil.getTime(new Date()) + redisUtil.getLiveTime(key)) * 1000).getTime());
|
||||
list.add(model);
|
||||
}
|
||||
}catch (Exception e){
|
||||
}
|
||||
}
|
||||
list = list.stream().sorted(Comparator.comparing(CacheManageListVO::getOverdueTime)).collect(Collectors.toList());
|
||||
if (StringUtil.isNotEmpty(page.getKeyword())) {
|
||||
list = list.stream().filter(t -> t.getName().contains(page.getKeyword())).collect(Collectors.toList());
|
||||
}
|
||||
if (ObjectUtil.isNotNull(page.getOverdueStartTime()) && ObjectUtil.isNotNull(page.getOverdueEndTime())) {
|
||||
list = list.stream().filter(t -> t.getOverdueTime() >= page.getOverdueStartTime() && t.getOverdueTime() <= page.getOverdueEndTime()).collect(Collectors.toList());
|
||||
}
|
||||
ListVO<CacheManageListVO> vo = new ListVO<>();
|
||||
vo.setList(list);
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取缓存信息
|
||||
*
|
||||
* @param name 主键值
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "获取缓存信息")
|
||||
@Parameter(name = "name", description = "主键值", required = true)
|
||||
@SaCheckPermission("system.cache")
|
||||
@GetMapping("/{name}")
|
||||
public ActionResult<CacheManageInfoVO> info(@PathVariable("name") String name) {
|
||||
name = XSSEscape.escape(name);
|
||||
String json = String.valueOf(redisUtil.getString(name));
|
||||
CacheManageInfoVO vo = new CacheManageInfoVO();
|
||||
vo.setName(name);
|
||||
vo.setValue(json);
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 清空所有缓存
|
||||
*
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "清空所有缓存")
|
||||
@SaCheckPermission("system.cache")
|
||||
@PostMapping("/Actions/ClearAll")
|
||||
public ActionResult clearAll() {
|
||||
String tenantId = UserProvider.getUser().getTenantId();
|
||||
if ("".equals(tenantId)) {
|
||||
Set<String> keys = redisUtil.getAllKeys();
|
||||
for (String key : keys) {
|
||||
redisUtil.remove(key);
|
||||
}
|
||||
} else {
|
||||
Set<String> data = redisUtil.getAllKeys();
|
||||
String clientKey = UserProvider.getToken();
|
||||
System.out.println(clientKey);
|
||||
for (String key : data) {
|
||||
if (key.contains(tenantId)) {
|
||||
redisUtil.remove(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
return ActionResult.success(MsgCode.SYS004.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 清空单个缓存
|
||||
*
|
||||
* @param name 主键值
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "清空单个缓存")
|
||||
@Parameter(name = "name", description = "主键值", required = true)
|
||||
@SaCheckPermission("system.cache")
|
||||
@DeleteMapping("/{name}")
|
||||
public ActionResult clear(@PathVariable("name") String name) {
|
||||
redisUtil.remove(name);
|
||||
return ActionResult.success(MsgCode.SYS004.get());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,155 @@
|
||||
package com.yunzhupaas.base.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import com.yunzhupaas.base.controller.SuperController;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import com.yunzhupaas.base.ActionResult;
|
||||
import com.yunzhupaas.base.service.ComFieldsService;
|
||||
import com.yunzhupaas.base.vo.ListVO;
|
||||
import com.yunzhupaas.base.entity.ComFieldsEntity;
|
||||
import com.yunzhupaas.constant.GenerateConstant;
|
||||
import com.yunzhupaas.constant.MsgCode;
|
||||
import com.yunzhupaas.exception.DataException;
|
||||
import com.yunzhupaas.base.model.comfields.ComFieldsCrForm;
|
||||
import com.yunzhupaas.base.model.comfields.ComFieldsInfoVO;
|
||||
import com.yunzhupaas.base.model.comfields.ComFieldsListVO;
|
||||
import com.yunzhupaas.base.model.comfields.ComFieldsUpForm;
|
||||
import com.yunzhupaas.util.JsonUtil;
|
||||
import com.yunzhupaas.util.JsonUtilEx;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 常用字段
|
||||
*
|
||||
* @author 云筑产品开发平台组
|
||||
* @version V3.1.0
|
||||
* @copyright 深圳市乐程软件有限公司
|
||||
* @date 2024/3/12 15:31
|
||||
*/
|
||||
@Tag(name = "常用字段", description = "CommonFields")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/CommonFields")
|
||||
public class ComFieldsController extends SuperController<ComFieldsService, ComFieldsEntity> {
|
||||
|
||||
@Autowired
|
||||
private ComFieldsService comFieldsService;
|
||||
|
||||
/**
|
||||
* 获取常用字段列表
|
||||
*
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "获取常用字段列表")
|
||||
@SaCheckPermission("systemData.dataModel")
|
||||
@GetMapping
|
||||
public ActionResult<ListVO<ComFieldsListVO>> list() {
|
||||
List<ComFieldsEntity> data = comFieldsService.getList();
|
||||
List<ComFieldsListVO> list = JsonUtil.getJsonToList(data, ComFieldsListVO.class);
|
||||
ListVO<ComFieldsListVO> vo = new ListVO<>();
|
||||
vo.setList(list);
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取常用字段
|
||||
*
|
||||
* @param id 主键
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "获取常用字段")
|
||||
@Parameter(name = "id", description = "主键", required = true)
|
||||
@SaCheckPermission("systemData.dataModel")
|
||||
@GetMapping("/{id}")
|
||||
public ActionResult<ComFieldsInfoVO> info(@PathVariable("id") String id) throws DataException {
|
||||
ComFieldsEntity entity = comFieldsService.getInfo(id);
|
||||
ComFieldsInfoVO vo = JsonUtilEx.getJsonToBeanEx(entity, ComFieldsInfoVO.class);
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增常用字段
|
||||
*
|
||||
* @param comFieldsCrForm 新增常用字段模型
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "添加常用字段")
|
||||
@Parameter(name = "comFieldsCrForm", description = "新建模型", required = true)
|
||||
@SaCheckPermission("systemData.dataModel")
|
||||
@PostMapping
|
||||
public ActionResult create(@RequestBody @Valid ComFieldsCrForm comFieldsCrForm) {
|
||||
ComFieldsEntity entity = JsonUtil.getJsonToBean(comFieldsCrForm, ComFieldsEntity.class);
|
||||
List<String> javaSql = new ArrayList<>();
|
||||
javaSql.addAll(GenerateConstant.JAVA_KEYWORD);
|
||||
javaSql.addAll(GenerateConstant.SQL_KEYWORD);
|
||||
if(javaSql.contains(entity.getField())){
|
||||
return ActionResult.fail(MsgCode.SYS128.get("列名" + entity.getField()));
|
||||
}
|
||||
if (comFieldsService.isExistByFullName(entity.getField(), entity.getId())) {
|
||||
return ActionResult.fail(MsgCode.EXIST001.get());
|
||||
}
|
||||
comFieldsService.create(entity);
|
||||
return ActionResult.success(MsgCode.SU001.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改常用字段
|
||||
*
|
||||
* @param id 主键
|
||||
* @param comFieldsUpForm 修改常用字段模型
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "修改常用字段")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true),
|
||||
@Parameter(name = "comFieldsUpForm", description = "修改模型", required = true)
|
||||
})
|
||||
@SaCheckPermission("systemData.dataModel")
|
||||
@PutMapping("/{id}")
|
||||
public ActionResult update(@PathVariable("id") String id, @RequestBody @Valid ComFieldsUpForm comFieldsUpForm) {
|
||||
ComFieldsEntity entity = JsonUtil.getJsonToBean(comFieldsUpForm, ComFieldsEntity.class);
|
||||
List<String> javaSql = new ArrayList<>();
|
||||
javaSql.addAll(GenerateConstant.JAVA_KEYWORD);
|
||||
javaSql.addAll(GenerateConstant.SQL_KEYWORD);
|
||||
if(javaSql.contains(entity.getField())){
|
||||
return ActionResult.fail(MsgCode.SYS128.get("列名" + entity.getField()));
|
||||
}
|
||||
if (comFieldsService.isExistByFullName(entity.getField(), id)) {
|
||||
return ActionResult.fail(MsgCode.EXIST001.get());
|
||||
}
|
||||
boolean flag = comFieldsService.update(id, entity);
|
||||
if (!flag) {
|
||||
return ActionResult.fail(MsgCode.FA002.get());
|
||||
}
|
||||
return ActionResult.success(MsgCode.SU004.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除常用字段
|
||||
*
|
||||
* @param id 主键
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "删除常用字段")
|
||||
@Parameter(name = "id", description = "主键", required = true)
|
||||
@SaCheckPermission("systemData.dataModel")
|
||||
@DeleteMapping("/{id}")
|
||||
public ActionResult delete(@PathVariable("id") String id) {
|
||||
ComFieldsEntity entity = comFieldsService.getInfo(id);
|
||||
if (entity != null) {
|
||||
comFieldsService.delete(entity);
|
||||
return ActionResult.success(MsgCode.SU003.get());
|
||||
}
|
||||
return ActionResult.fail(MsgCode.FA003.get());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,194 @@
|
||||
package com.yunzhupaas.base.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import cn.dev33.satoken.annotation.SaMode;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import com.yunzhupaas.base.ActionResult;
|
||||
import com.yunzhupaas.base.entity.CommonWordsEntity;
|
||||
import com.yunzhupaas.base.entity.SystemEntity;
|
||||
import com.yunzhupaas.base.model.commonword.ComWordsPagination;
|
||||
import com.yunzhupaas.base.model.commonword.CommonWordsForm;
|
||||
import com.yunzhupaas.base.model.commonword.CommonWordsVO;
|
||||
import com.yunzhupaas.base.service.CommonWordsService;
|
||||
import com.yunzhupaas.base.service.SystemService;
|
||||
import com.yunzhupaas.base.vo.ListVO;
|
||||
import com.yunzhupaas.base.vo.PageListVO;
|
||||
import com.yunzhupaas.base.vo.PaginationVO;
|
||||
import com.yunzhupaas.constant.MsgCode;
|
||||
import com.yunzhupaas.util.JsonUtil;
|
||||
import com.yunzhupaas.util.RandomUtil;
|
||||
import com.yunzhupaas.util.StringUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 常用语控制类
|
||||
*
|
||||
* @author 云筑产品开发平台组
|
||||
* @version v3.4.6
|
||||
* @copyrignt 深圳市乐程软件有限公司
|
||||
* @date 2023-01-06
|
||||
*/
|
||||
@Tag(name = "审批常用语", description = "commonWords")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/CommonWords")
|
||||
public class CommonWordsController extends SuperController<CommonWordsService, CommonWordsEntity> {
|
||||
|
||||
@Autowired
|
||||
private CommonWordsService commonWordsService;
|
||||
@Autowired
|
||||
private SystemService systemService;
|
||||
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*
|
||||
* @param comWordsPagination 页面参数对象
|
||||
* @return 列表结果集
|
||||
*/
|
||||
@Operation(summary = "当前系统应用列表")
|
||||
@GetMapping()
|
||||
public ActionResult<PageListVO<CommonWordsVO>> getList(ComWordsPagination comWordsPagination) {
|
||||
List<CommonWordsEntity> entityList = commonWordsService.getSysList(comWordsPagination, false);
|
||||
List<CommonWordsVO> voList = JsonUtil.getJsonToList(entityList, CommonWordsVO.class);
|
||||
formatSystemNames(voList);
|
||||
return ActionResult.page(voList, JsonUtil.getJsonToBean(comWordsPagination, PaginationVO.class));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取信息
|
||||
*
|
||||
* @param id 主键
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "获取信息")
|
||||
@Parameter(name = "id", description = "主键", required = true)
|
||||
@GetMapping("/{id}")
|
||||
public ActionResult<CommonWordsVO> getInfo(@PathVariable String id) {
|
||||
CommonWordsEntity entity = commonWordsService.getById(id);
|
||||
if (StringUtil.isNotEmpty(entity.getSystemIds())) {
|
||||
String[] sysIds = entity.getSystemIds().split(",");
|
||||
List<String> ids = new ArrayList<>();
|
||||
for (String sysId : sysIds) {
|
||||
if (!StringUtil.isEmpty(sysId)) {
|
||||
SystemEntity systemEntity = systemService.getInfo(sysId);
|
||||
if (systemEntity != null && systemEntity.getEnabledMark() == 1) {
|
||||
ids.add(sysId);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ids.size() > 0) {
|
||||
entity.setSystemIds(StringUtil.join(ids, ","));
|
||||
} else {
|
||||
entity.setSystemIds(null);
|
||||
}
|
||||
}
|
||||
CommonWordsVO vo = JsonUtil.getJsonToBean(entity, CommonWordsVO.class);
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 下拉列表
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "下拉列表")
|
||||
@GetMapping("/Selector")
|
||||
public ActionResult<ListVO<CommonWordsVO>> getSelect(String type) {
|
||||
List<CommonWordsVO> voList = JsonUtil.getJsonToList(commonWordsService.getListModel(type), CommonWordsVO.class);
|
||||
formatSystemNames(voList);
|
||||
return ActionResult.success(new ListVO<>(voList));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新建
|
||||
*
|
||||
* @param commonWordsForm 实体模型
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "新建")
|
||||
@Parameter(name = "commonWordsForm", description = "实体模型", required = true)
|
||||
@PostMapping("")
|
||||
public ActionResult<CommonWordsForm> create(@RequestBody CommonWordsForm commonWordsForm) {
|
||||
if (commonWordsService.existCommonWord(null, commonWordsForm.getCommonWordsText(), commonWordsForm.getCommonWordsType())) {
|
||||
return ActionResult.fail(MsgCode.SYS105.get());
|
||||
}
|
||||
CommonWordsEntity entity = JsonUtil.getJsonToBean(commonWordsForm, CommonWordsEntity.class);
|
||||
entity.setId(RandomUtil.uuId());
|
||||
entity.setUsesNum(0l);
|
||||
commonWordsService.save(entity);
|
||||
return ActionResult.success(MsgCode.SU001.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
*
|
||||
* @param commonWordsForm 实体模型
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "修改")
|
||||
@Parameters({
|
||||
@Parameter(name = "commonWordsForm", description = "实体模型", required = true)
|
||||
})
|
||||
@PutMapping("/{id}")
|
||||
public ActionResult<CommonWordsForm> update(@RequestBody CommonWordsForm commonWordsForm) {
|
||||
if (commonWordsService.existCommonWord(commonWordsForm.getId(), commonWordsForm.getCommonWordsText(), commonWordsForm.getCommonWordsType())) {
|
||||
return ActionResult.fail(MsgCode.SYS105.get());
|
||||
}
|
||||
CommonWordsEntity entity = JsonUtil.getJsonToBean(commonWordsForm, CommonWordsEntity.class);
|
||||
entity.setId(commonWordsForm.getId());
|
||||
commonWordsService.updateById(entity);
|
||||
return ActionResult.success(MsgCode.SU004.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*
|
||||
* @param id 主键
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "删除")
|
||||
@SaCheckPermission("commonWords")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true)
|
||||
})
|
||||
@DeleteMapping("/{id}")
|
||||
public ActionResult<CommonWordsForm> delete(@PathVariable String id) {
|
||||
//对象存在判断
|
||||
if (commonWordsService.getById(id) != null) {
|
||||
commonWordsService.removeById(id);
|
||||
return ActionResult.success(MsgCode.SU003.get());
|
||||
} else {
|
||||
return ActionResult.fail(MsgCode.FA003.get());
|
||||
}
|
||||
}
|
||||
|
||||
@Operation(summary = "常用语使用")
|
||||
@Parameters({
|
||||
@Parameter(name = "commonWordsForm", description = "实体模型")
|
||||
})
|
||||
@PostMapping("/UsesNum")
|
||||
public ActionResult<CommonWordsForm> addCommonWordsNum(@RequestBody CommonWordsForm commonWordsForm) {
|
||||
commonWordsService.addCommonWordsNum(commonWordsForm.getCommonWordsText());
|
||||
return ActionResult.success(MsgCode.SU000.get());
|
||||
}
|
||||
|
||||
private void formatSystemNames(List<CommonWordsVO> voList) {
|
||||
voList.forEach(vo -> {
|
||||
if (StringUtil.isNotEmpty(vo.getSystemIds())) {
|
||||
List<String> sysNameList = systemService.getListByIds(vo.getSystemIds(), null).stream()
|
||||
.map(SystemEntity::getFullName).collect(Collectors.toList());
|
||||
vo.setSystemNames(StringUtil.join(sysNameList, ","));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,648 @@
|
||||
package com.yunzhupaas.base.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson.serializer.SerializerFeature;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import com.yunzhupaas.base.*;
|
||||
import com.yunzhupaas.base.entity.DataInterfaceEntity;
|
||||
import com.yunzhupaas.base.entity.DictionaryDataEntity;
|
||||
import com.yunzhupaas.base.entity.InterfaceOauthEntity;
|
||||
import com.yunzhupaas.base.model.datainterface.*;
|
||||
import com.yunzhupaas.base.service.DataInterfaceService;
|
||||
import com.yunzhupaas.base.service.DictionaryDataService;
|
||||
import com.yunzhupaas.base.service.DictionaryTypeService;
|
||||
import com.yunzhupaas.base.service.InterfaceOauthService;
|
||||
import com.yunzhupaas.base.util.interfaceUtil.InterfaceUtil;
|
||||
import com.yunzhupaas.base.vo.PageListVO;
|
||||
import com.yunzhupaas.constant.DbSensitiveConstant;
|
||||
import com.yunzhupaas.base.vo.DownloadVO;
|
||||
import com.yunzhupaas.base.vo.ListVO;
|
||||
import com.yunzhupaas.base.vo.PaginationVO;
|
||||
import com.yunzhupaas.config.ConfigValueUtil;
|
||||
import com.yunzhupaas.constant.MsgCode;
|
||||
import com.yunzhupaas.emnus.ModuleTypeEnum;
|
||||
import com.yunzhupaas.exception.DataException;
|
||||
import com.yunzhupaas.database.util.*;
|
||||
import com.yunzhupaas.util.*;
|
||||
import com.yunzhupaas.util.enums.DictionaryDataEnum;
|
||||
import com.yunzhupaas.util.treeutil.SumTree;
|
||||
import com.yunzhupaas.util.treeutil.TreeDotUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 数据接口
|
||||
*
|
||||
* @author 云筑产品开发平台组
|
||||
* @version V3.1.0
|
||||
* @copyright 深圳市乐程软件有限公司(http://www.szlecheng.cn)
|
||||
* @date 2024-03-15 10:29
|
||||
*/
|
||||
@Tag(name = "数据接口", description = "DataInterface")
|
||||
@RestController
|
||||
@RequestMapping(value = "/api/system/DataInterface")
|
||||
public class DataInterfaceController extends SuperController<DataInterfaceService, DataInterfaceEntity> {
|
||||
@Autowired
|
||||
private DataInterfaceService dataInterfaceService;
|
||||
@Autowired
|
||||
private DictionaryDataService dictionaryDataService;
|
||||
@Autowired
|
||||
private DictionaryTypeService dictionaryTypeService;
|
||||
|
||||
@Autowired
|
||||
private ConfigValueUtil configValueUtil;
|
||||
@Autowired
|
||||
private InterfaceOauthService interfaceOauthService;
|
||||
@Autowired
|
||||
private DataFileExport fileExport;
|
||||
|
||||
/**
|
||||
* 获取接口列表(分页)
|
||||
*
|
||||
* @param pagination 分页模型
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "获取接口列表(分页)")
|
||||
@SaCheckPermission("systemData.dataInterface")
|
||||
@GetMapping
|
||||
public ActionResult<PageListVO<DataInterfaceListVO>> getList(PaginationDataInterface pagination) {
|
||||
List<DataInterfaceEntity> data = dataInterfaceService.getList(pagination, 0);
|
||||
List<DataInterfaceListVO> list = JsonUtil.getJsonToList(data, DataInterfaceListVO.class);
|
||||
// 添加tenantId字段
|
||||
for (DataInterfaceListVO vo : list) {
|
||||
// 类别转换
|
||||
if ("1".equals(vo.getType())) {
|
||||
vo.setType("SQL操作");
|
||||
} else if ("2".equals(vo.getType())) {
|
||||
vo.setType("静态数据");
|
||||
} else if ("3".equals(vo.getType())) {
|
||||
vo.setType("API操作");
|
||||
}
|
||||
if (StringUtil.isNotEmpty(UserProvider.getUser().getTenantId())) {
|
||||
vo.setTenantId(UserProvider.getUser().getTenantId());
|
||||
}
|
||||
}
|
||||
PaginationVO paginationVO = JsonUtil.getJsonToBean(pagination, PaginationVO.class);
|
||||
return ActionResult.page(list, paginationVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取接口列表(工作流选择时调用)
|
||||
*
|
||||
* @param pagination 分页参数
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "获取接口列表(工作流选择时调用)")
|
||||
@GetMapping("/getList")
|
||||
public ActionResult<PageListVO<DataInterfaceGetListVO>> getLists(PaginationDataInterfaceSelector pagination) {
|
||||
List<DataInterfaceEntity> data = dataInterfaceService.getList(pagination);
|
||||
List<DataInterfaceGetListVO> list = JsonUtil.getJsonToList(data, DataInterfaceGetListVO.class);
|
||||
for (DataInterfaceGetListVO vo : list) {
|
||||
// 类别转换
|
||||
if ("1".equals(vo.getType())) {
|
||||
vo.setType("SQL操作");
|
||||
} else if ("2".equals(vo.getType())) {
|
||||
vo.setType("静态数据");
|
||||
} else if ("3".equals(vo.getType())) {
|
||||
vo.setType("API操作");
|
||||
}
|
||||
}
|
||||
PaginationVO paginationVO = JsonUtil.getJsonToBean(pagination, PaginationVO.class);
|
||||
return ActionResult.page(list, paginationVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取接口列表下拉框
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "获取接口列表下拉框")
|
||||
@GetMapping("/Selector")
|
||||
public ActionResult<List<DataInterfaceTreeVO>> getSelector() {
|
||||
List<DataInterfaceTreeModel> tree = new ArrayList<>();
|
||||
List<DataInterfaceEntity> data = dataInterfaceService.getList(false);
|
||||
List<DictionaryDataEntity> dataEntityList = dictionaryDataService.getList(dictionaryTypeService.getInfoByEnCode(DictionaryDataEnum.SYSTEM_DATAINTERFACE.getDictionaryTypeId()).getId());
|
||||
// 获取数据接口外层菜单
|
||||
for (DictionaryDataEntity dictionaryDataEntity : dataEntityList) {
|
||||
DataInterfaceTreeModel firstModel = JsonUtil.getJsonToBean(dictionaryDataEntity, DataInterfaceTreeModel.class);
|
||||
firstModel.setId(dictionaryDataEntity.getId());
|
||||
firstModel.setCategory("0");
|
||||
long num = data.stream().filter(t -> t.getCategory().equals(dictionaryDataEntity.getId())).count();
|
||||
if (num > 0) {
|
||||
tree.add(firstModel);
|
||||
}
|
||||
}
|
||||
for (DataInterfaceEntity entity : data) {
|
||||
DataInterfaceTreeModel treeModel = JsonUtil.getJsonToBean(entity, DataInterfaceTreeModel.class);
|
||||
treeModel.setCategory("1");
|
||||
treeModel.setParentId(entity.getCategory());
|
||||
treeModel.setId(entity.getId());
|
||||
DictionaryDataEntity dataEntity = dictionaryDataService.getInfo(entity.getCategory());
|
||||
if (dataEntity != null) {
|
||||
tree.add(treeModel);
|
||||
}
|
||||
}
|
||||
List<SumTree<DataInterfaceTreeModel>> sumTrees = TreeDotUtils.convertListToTreeDot(tree);
|
||||
List<DataInterfaceTreeVO> list = JsonUtil.getJsonToList(sumTrees, DataInterfaceTreeVO.class);
|
||||
ListVO<DataInterfaceTreeVO> vo = new ListVO<>();
|
||||
vo.setList(list);
|
||||
return ActionResult.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取接口参数列表下拉框
|
||||
*
|
||||
* @param id 主键
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "获取接口参数列表下拉框")
|
||||
@Parameter(name = "id", description = "主键", required = true)
|
||||
@SaCheckPermission("systemData.dataInterface")
|
||||
@GetMapping("/GetParam/{id}")
|
||||
public ActionResult<List<DataInterfaceModel>> getSelector(@PathVariable("id") String id) {
|
||||
DataInterfaceEntity entity = dataInterfaceService.getInfo(id);
|
||||
if (entity!=null) {
|
||||
String parameterJson = entity.getParameterJson();
|
||||
List<DataInterfaceModel> jsonToList = JsonUtil.getJsonToList(parameterJson, DataInterfaceModel.class);
|
||||
return ActionResult.success(jsonToList == null ? new ArrayList<>() : jsonToList);
|
||||
}
|
||||
return ActionResult.fail(MsgCode.FA001.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取接口数据
|
||||
*
|
||||
* @param id 主键
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "获取接口数据")
|
||||
@Parameter(name = "id", description = "主键", required = true)
|
||||
@SaCheckPermission("systemData.dataInterface")
|
||||
@GetMapping("/{id}")
|
||||
public ActionResult<DataInterfaceVo> getInfo(@PathVariable("id") String id) throws DataException {
|
||||
DataInterfaceEntity entity = dataInterfaceService.getInfo(id);
|
||||
DataInterfaceVo vo = JsonUtil.getJsonToBean(entity, DataInterfaceVo.class);
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加接口
|
||||
*
|
||||
* @param dataInterfaceCrForm 实体模型
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "添加接口")
|
||||
@Parameter(name = "dataInterfaceCrForm", description = "实体模型", required = true)
|
||||
@SaCheckPermission("systemData.dataInterface")
|
||||
@PostMapping
|
||||
public ActionResult create(@RequestBody @Valid DataInterfaceCrForm dataInterfaceCrForm) throws DataException {
|
||||
DataInterfaceEntity entity = JsonUtil.getJsonToBean(dataInterfaceCrForm, DataInterfaceEntity.class);
|
||||
// 判断是否有敏感字
|
||||
String containsSensitive = containsSensitive(entity);
|
||||
if (StringUtil.isNotEmpty(containsSensitive)) {
|
||||
return ActionResult.fail(MsgCode.SYS006.get(containsSensitive));
|
||||
}
|
||||
if (dataInterfaceService.isExistByFullNameOrEnCode(entity.getId(), entity.getFullName(), null)) {
|
||||
return ActionResult.fail(MsgCode.EXIST001.get());
|
||||
}
|
||||
if (dataInterfaceService.isExistByFullNameOrEnCode(entity.getId(), null, entity.getEnCode())) {
|
||||
return ActionResult.fail(MsgCode.EXIST002.get());
|
||||
}
|
||||
dataInterfaceService.create(entity);
|
||||
return ActionResult.success(MsgCode.SYS005.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否有敏感字
|
||||
*
|
||||
* @param entity
|
||||
* @return
|
||||
*/
|
||||
private String containsSensitive(DataInterfaceEntity entity) {
|
||||
// 判断是否有敏感字
|
||||
if (entity.getType() == 1 && (entity.getAction() != null && entity.getAction() == 3)) {
|
||||
DataConfigJsonModel dataConfigJsonModel = JsonUtil.getJsonToBean(entity.getDataConfigJson(), DataConfigJsonModel.class);
|
||||
String sql = dataConfigJsonModel.getSqlData().getSql();
|
||||
if (StringUtil.isNotEmpty(sql)) {
|
||||
return ParameterUtil.checkContainsSensitive(sql, DbSensitiveConstant.SENSITIVE);
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改接口
|
||||
*
|
||||
* @param dataInterfaceUpForm 实体模型
|
||||
* @param id 主键
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "修改接口")
|
||||
@Parameters({
|
||||
@Parameter(name = "dataInterfaceUpForm", description = "实体模型", required = true),
|
||||
@Parameter(name = "id", description = "主键", required = true)
|
||||
})
|
||||
@SaCheckPermission("systemData.dataInterface")
|
||||
@PutMapping("/{id}")
|
||||
public ActionResult update(@RequestBody @Valid DataInterfaceUpForm dataInterfaceUpForm, @PathVariable("id") String id) throws DataException {
|
||||
DataInterfaceEntity entity = JsonUtilEx.getJsonToBeanEx(dataInterfaceUpForm, DataInterfaceEntity.class);
|
||||
// 判断是否有敏感字
|
||||
String containsSensitive = containsSensitive(entity);
|
||||
if (StringUtil.isNotEmpty(containsSensitive)) {
|
||||
return ActionResult.fail(MsgCode.SYS006.get(containsSensitive));
|
||||
}
|
||||
if (dataInterfaceService.isExistByFullNameOrEnCode(id, entity.getFullName(), null)) {
|
||||
return ActionResult.fail(MsgCode.EXIST001.get());
|
||||
}
|
||||
if (dataInterfaceService.isExistByFullNameOrEnCode(id, null, entity.getEnCode())) {
|
||||
return ActionResult.fail(MsgCode.EXIST002.get());
|
||||
}
|
||||
boolean flag = dataInterfaceService.update(entity, id);
|
||||
if (!flag) {
|
||||
return ActionResult.fail(MsgCode.FA001.get());
|
||||
}
|
||||
return ActionResult.success(MsgCode.SU004.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除接口
|
||||
*
|
||||
* @param id 主键
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "删除接口")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true)
|
||||
})
|
||||
@SaCheckPermission("systemData.dataInterface")
|
||||
@DeleteMapping("/{id}")
|
||||
public ActionResult delete(@PathVariable String id) {
|
||||
DataInterfaceEntity entity = dataInterfaceService.getInfo(id);
|
||||
if (entity != null) {
|
||||
dataInterfaceService.delete(entity);
|
||||
return ActionResult.success(MsgCode.SU003.get());
|
||||
}
|
||||
return ActionResult.fail(MsgCode.FA001.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新接口状态
|
||||
*
|
||||
* @param id 主键
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "更新接口状态")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true)
|
||||
})
|
||||
@SaCheckPermission("systemData.dataInterface")
|
||||
@PutMapping("/{id}/Actions/State")
|
||||
public ActionResult update(@PathVariable("id") String id) throws DataException {
|
||||
DataInterfaceEntity entity = dataInterfaceService.getInfo(id);
|
||||
if (entity != null) {
|
||||
if (entity.getEnabledMark() == 0) {
|
||||
entity.setEnabledMark(1);
|
||||
} else {
|
||||
entity.setEnabledMark(0);
|
||||
}
|
||||
dataInterfaceService.update(entity, id);
|
||||
return ActionResult.success(MsgCode.SU014.get());
|
||||
}
|
||||
return ActionResult.fail(MsgCode.FA001.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取接口分页数据
|
||||
*
|
||||
* @param id 主键
|
||||
* @param page 分页参数
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "获取接口分页数据")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true),
|
||||
@Parameter(name = "page", description = "分页参数", required = true)
|
||||
})
|
||||
@PostMapping("/{id}/Actions/List")
|
||||
public ActionResult infoToIdPageList(@PathVariable("id") String id, @RequestBody DataInterfacePage page) {
|
||||
ActionResult result = dataInterfaceService.infoToIdPageList(id, page);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取接口详情数据
|
||||
*
|
||||
* @param id 主键
|
||||
* @param page 分页参数
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "获取接口详情数据")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true),
|
||||
@Parameter(name = "page", description = "分页参数", required = true)
|
||||
})
|
||||
@PostMapping("/{id}/Actions/InfoByIds")
|
||||
public ActionResult<List<Map<String, Object>>> infoByIds(@PathVariable("id") String id, @RequestBody DataInterfacePage page) {
|
||||
List<Map<String, Object>> data = dataInterfaceService.infoToInfo(id, page);
|
||||
return ActionResult.success(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试接口
|
||||
*
|
||||
* @param id 主键
|
||||
* @param objectMap 参数、参数值对象
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "测试接口")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true),
|
||||
@Parameter(name = "objectMap", description = "参数、参数值对象")
|
||||
})
|
||||
@PostMapping("/{id}/Actions/Preview")
|
||||
@NoDataSourceBind
|
||||
public ActionResult callPreview(@PathVariable("id") String id, @RequestBody(required = false) Map<String, Object> objectMap) {
|
||||
DataInterfaceParamModel model = JsonUtil.getJsonToBean(objectMap, DataInterfaceParamModel.class);
|
||||
Map<String, String> map = null;
|
||||
if (model != null) {
|
||||
if (configValueUtil.isMultiTenancy()) {
|
||||
//切换成租户库
|
||||
try{
|
||||
TenantDataSourceUtil.switchTenant(model.getTenantId());
|
||||
}catch (Exception e){
|
||||
return ActionResult.fail(ActionResultCode.SessionOverdue.getMessage());
|
||||
}
|
||||
}
|
||||
if (model.getParamList() != null && model.getParamList().size() > 0) {
|
||||
map = new HashMap<>(16);
|
||||
List<DataInterfaceModel> jsonToList = JsonUtil.getJsonToList(model.getParamList(), DataInterfaceModel.class);
|
||||
dataInterfaceService.paramSourceTypeReplaceValue(jsonToList, map);
|
||||
}
|
||||
}
|
||||
ActionResult actionResult = dataInterfaceService.infoToId(id, null, map);
|
||||
if (actionResult.getCode() == 200) {
|
||||
actionResult.setMsg(MsgCode.SYS007.get());
|
||||
}
|
||||
return actionResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* 访问接口GET
|
||||
*
|
||||
* @param id 主键
|
||||
* @param map 参数、参数值对象
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "访问接口GET")
|
||||
@GetMapping("/{id}/Actions/Response")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true),
|
||||
@Parameter(name = "map", description = "参数、参数值对象")
|
||||
})
|
||||
@NoDataSourceBind
|
||||
public ActionResult getResponse(@PathVariable("id") String id,@RequestParam(required = false) Map<String,String> map) {
|
||||
DataInterfaceActionModel entity;
|
||||
try{
|
||||
entity= dataInterfaceService.checkParams(map);
|
||||
entity.setInvokType("GET");
|
||||
}catch (Exception e){
|
||||
return ActionResult.fail(e.getMessage());
|
||||
}
|
||||
String name = null;
|
||||
if (configValueUtil.isMultiTenancy()) {
|
||||
//切换成租户库
|
||||
try{
|
||||
TenantDataSourceUtil.switchTenant(entity.getTenantId());
|
||||
}catch (Exception e){
|
||||
return ActionResult.fail(ActionResultCode.SessionOverdue.getMessage());
|
||||
}
|
||||
}
|
||||
return dataInterfaceService.infoToIdNew(id, name, entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* 访问接口POST
|
||||
*
|
||||
* @param id 主键
|
||||
* @param map 参数、参数值对象
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "访问接口POST")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true),
|
||||
@Parameter(name = "map", description = "参数、参数值对象")
|
||||
})
|
||||
@PostMapping("/{id}/Actions/Response")
|
||||
@NoDataSourceBind
|
||||
public ActionResult postResponse(@PathVariable("id") String id, @RequestBody(required = false) Map<String,String> map) {
|
||||
DataInterfaceActionModel entity;
|
||||
try{
|
||||
entity= dataInterfaceService.checkParams(map);
|
||||
entity.setInvokType("POST");
|
||||
}catch (Exception e){
|
||||
return ActionResult.fail(e.getMessage());
|
||||
}
|
||||
String name = null;
|
||||
if (configValueUtil.isMultiTenancy()) {
|
||||
//切换成租户库
|
||||
try{
|
||||
TenantDataSourceUtil.switchTenant(entity.getTenantId());
|
||||
}catch (Exception e){
|
||||
return ActionResult.fail(ActionResultCode.SessionOverdue.getMessage());
|
||||
}
|
||||
}
|
||||
return dataInterfaceService.infoToIdNew(id, name, entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* 外部接口获取authorization
|
||||
*
|
||||
* @param appId 应用id
|
||||
* @param intefaceId 接口id
|
||||
* @param map 参数、参数值对象
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "外部接口获取authorization")
|
||||
@Parameters({
|
||||
@Parameter(name = "appId", description = "应用id", required = true),
|
||||
@Parameter(name = "intefaceId", description = "接口id"),
|
||||
@Parameter(name = "map", description = "参数、参数值对象")
|
||||
})
|
||||
@PostMapping("/Actions/GetAuth")
|
||||
@NoDataSourceBind
|
||||
public ActionResult getAuthorization(@RequestParam("appId") String appId,@RequestParam("intefaceId") String intefaceId, @RequestBody(required = false) Map<String,String> map) {
|
||||
InterfaceOauthEntity infoByAppId = interfaceOauthService.getInfoByAppId(appId);
|
||||
if(infoByAppId==null){
|
||||
return ActionResult.fail(MsgCode.SYS127.get());
|
||||
}
|
||||
Map<String, String> authorization = InterfaceUtil.getAuthorization(intefaceId,appId,infoByAppId.getAppSecret(), map);
|
||||
return ActionResult.success(MsgCode.SU005.get(),authorization);
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据接口导出功能
|
||||
*
|
||||
* @param id 接口id
|
||||
*/
|
||||
@Operation(summary = "导出数据接口数据")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true)
|
||||
})
|
||||
@SaCheckPermission("systemData.dataInterface")
|
||||
@GetMapping("/{id}/Actions/Export")
|
||||
public ActionResult exportFile(@PathVariable("id") String id) {
|
||||
DataInterfaceEntity entity = dataInterfaceService.getInfo(id);
|
||||
//导出文件
|
||||
DownloadVO downloadVO = fileExport.exportFile(entity, configValueUtil.getTemporaryFilePath(), entity.getFullName(), ModuleTypeEnum.SYSTEM_DATAINTEFASE.getTableName());
|
||||
return ActionResult.success(downloadVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据接口导入功能
|
||||
*
|
||||
* @param multipartFile
|
||||
* @return
|
||||
* @throws DataException
|
||||
*/
|
||||
@Operation(summary = "数据接口导入功能")
|
||||
@SaCheckPermission("systemData.dataInterface")
|
||||
@PostMapping(value = "/Actions/Import", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
public ActionResult importFile(@RequestPart("file") MultipartFile multipartFile,
|
||||
@RequestParam("type") Integer type) throws DataException {
|
||||
//判断是否为.json结尾
|
||||
if (FileUtil.existsSuffix(multipartFile, ModuleTypeEnum.SYSTEM_DATAINTEFASE.getTableName())) {
|
||||
return ActionResult.fail(MsgCode.IMP002.get());
|
||||
}
|
||||
try {
|
||||
//读取文件内容
|
||||
String fileContent = FileUtil.getFileContent(multipartFile);
|
||||
DataInterfaceEntity entity = JsonUtil.getJsonToBean(fileContent, DataInterfaceEntity.class);
|
||||
// 验证数据是否正常
|
||||
if (dictionaryDataService.getInfo(entity.getCategory()) == null) {
|
||||
return ActionResult.fail(MsgCode.IMP004.get());
|
||||
}
|
||||
StringJoiner stringJoiner = new StringJoiner("、");
|
||||
QueryWrapper<DataInterfaceEntity> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.lambda().eq(DataInterfaceEntity::getId, entity.getId());
|
||||
if (dataInterfaceService.count(queryWrapper) > 0) {
|
||||
if (Objects.equals(type, 0)) {
|
||||
stringJoiner.add("ID");
|
||||
} else {
|
||||
entity.setId(RandomUtil.uuId());
|
||||
}
|
||||
}
|
||||
queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.lambda().eq(DataInterfaceEntity::getEnCode, entity.getEnCode());
|
||||
if (dataInterfaceService.count(queryWrapper) > 0) {
|
||||
stringJoiner.add(MsgCode.IMP009.get());
|
||||
}
|
||||
queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.lambda().eq(DataInterfaceEntity::getFullName, entity.getFullName());
|
||||
if (dataInterfaceService.count(queryWrapper) > 0) {
|
||||
stringJoiner.add(MsgCode.IMP008.get());
|
||||
}
|
||||
if (stringJoiner.length() > 0 && ObjectUtil.equal(type, 1)) {
|
||||
String copyNum = UUID.randomUUID().toString().substring(0, 5);
|
||||
entity.setFullName(entity.getFullName() + ".副本" + copyNum);
|
||||
entity.setEnCode(entity.getEnCode() + copyNum);
|
||||
} else if (ObjectUtil.equal(type, 0) && stringJoiner.length() > 0) {
|
||||
return ActionResult.fail(stringJoiner.toString() + MsgCode.IMP007.get());
|
||||
}
|
||||
entity.setCreatorTime(new Date());
|
||||
entity.setCreatorUserId(UserProvider.getLoginUserId());
|
||||
entity.setLastModifyTime(null);
|
||||
entity.setLastModifyUserId(null);
|
||||
try {
|
||||
dataInterfaceService.setIgnoreLogicDelete().removeById(entity);
|
||||
entity.setEnabledMark(0);
|
||||
dataInterfaceService.setIgnoreLogicDelete().saveOrUpdate(entity);
|
||||
} catch (Exception e) {
|
||||
throw new DataException(MsgCode.IMP003.get());
|
||||
}finally {
|
||||
dataInterfaceService.clearIgnoreLogicDelete();
|
||||
}
|
||||
return ActionResult.success(MsgCode.IMP001.get());
|
||||
} catch (Exception e) {
|
||||
return ActionResult.fail(MsgCode.IMP004.get());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取接口字段
|
||||
*
|
||||
* @param id 主键
|
||||
* @param objectMap 参数、参数值
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "获取接口字段")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true),
|
||||
@Parameter(name = "objectMap", description = "参数、参数值")
|
||||
})
|
||||
@PostMapping("/{id}/Actions/GetFields")
|
||||
public ActionResult getFields(@PathVariable("id") String id, @RequestBody(required = false) Map<String, Object> objectMap) {
|
||||
DataInterfacePage model = JsonUtil.getJsonToBean(objectMap, DataInterfacePage.class);
|
||||
ActionResult actionResult = dataInterfaceService.infoToIdPageList(id, model);
|
||||
if (actionResult.getCode() == 200) {
|
||||
try{
|
||||
Object data = actionResult.getData();
|
||||
if (data instanceof List) {
|
||||
List<Map<String,Object>> list=(List)data;
|
||||
List<String> listKey=new ArrayList();
|
||||
for(String key:list.get(0).keySet()){
|
||||
listKey.add(key);
|
||||
}
|
||||
actionResult.setData(listKey);
|
||||
}else{
|
||||
Map<String,Object> map=JsonUtil.stringToMap(JSONObject.toJSONString(data, SerializerFeature.WriteMapNullValue));
|
||||
List<Map<String,Object>> list=(List)map.get("list");
|
||||
List<String> listKey=new ArrayList();
|
||||
for(String key:list.get(0).keySet()){
|
||||
listKey.add(key);
|
||||
}
|
||||
actionResult.setData(listKey);
|
||||
}
|
||||
}catch (Exception e){
|
||||
return ActionResult.fail(MsgCode.SYS008.get());
|
||||
}
|
||||
}
|
||||
return actionResult;
|
||||
}
|
||||
/**
|
||||
* 复制数据接口
|
||||
*
|
||||
* @param id 数据接口ID
|
||||
* @return 执行结构
|
||||
* @throws DataException ignore
|
||||
*/
|
||||
@Operation(summary = "复制数据接口")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "数据接口ID", required = true)
|
||||
})
|
||||
@SaCheckPermission("systemData.dataInterface")
|
||||
@PostMapping("/{id}/Actions/Copy")
|
||||
public ActionResult<?> Copy(@PathVariable("id") String id) throws DataException {
|
||||
String copyNum = UUID.randomUUID().toString().substring(0, 5);
|
||||
DataInterfaceEntity entity = dataInterfaceService.getInfo(id);
|
||||
entity.setFullName(entity.getFullName() + ".副本" + copyNum);
|
||||
if(entity.getFullName().length() > 50) return ActionResult.fail(MsgCode.COPY001.get());
|
||||
entity.setEnCode(entity.getEnCode() + copyNum);
|
||||
entity.setEnabledMark(0);
|
||||
dataInterfaceService.create(entity);
|
||||
return ActionResult.success(MsgCode.SU007.get());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
package com.yunzhupaas.base.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import com.yunzhupaas.base.ActionResult;
|
||||
import com.yunzhupaas.base.Pagination;
|
||||
import com.yunzhupaas.base.entity.DataInterfaceLogEntity;
|
||||
import com.yunzhupaas.base.model.datainterface.DataInterfaceLogVO;
|
||||
import com.yunzhupaas.base.service.DataInterfaceLogService;
|
||||
import com.yunzhupaas.base.vo.PageListVO;
|
||||
import com.yunzhupaas.base.vo.PaginationVO;
|
||||
import com.yunzhupaas.permission.entity.UserEntity;
|
||||
import com.yunzhupaas.permission.service.UserService;
|
||||
import com.yunzhupaas.util.JsonUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 数据接口调用日志控制器
|
||||
*
|
||||
* @author 云筑产品开发平台组
|
||||
* @version V3.1.0
|
||||
* @copyright 深圳市乐程软件有限公司(http://www.szlecheng.cn)
|
||||
* @date 2024-06-03
|
||||
*/
|
||||
@Tag(description = "DataInterfaceLog", name = "数据接口调用日志")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/DataInterfaceLog")
|
||||
public class DataInterfaceLogController extends SuperController<DataInterfaceLogService, DataInterfaceLogEntity> {
|
||||
@Autowired
|
||||
private DataInterfaceLogService dataInterfaceLogService;
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
/**
|
||||
* 获取数据接口调用日志列表
|
||||
*
|
||||
* @param id 主键
|
||||
* @param pagination 分页参数
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "获取数据接口调用日志列表")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true)
|
||||
})
|
||||
@SaCheckPermission("systemData.dataInterface")
|
||||
@GetMapping("{id}")
|
||||
public ActionResult<PageListVO<DataInterfaceLogVO>> getList(@PathVariable("id") String id, Pagination pagination) {
|
||||
List<DataInterfaceLogEntity> list = dataInterfaceLogService.getList(id, pagination);
|
||||
List<DataInterfaceLogVO> voList = JsonUtil.getJsonToList(list, DataInterfaceLogVO.class);
|
||||
for (DataInterfaceLogVO vo : voList) {
|
||||
UserEntity entity = userService.getInfo(vo.getUserId());
|
||||
if (entity != null) {
|
||||
vo.setUserId(entity.getRealName() + "/" + entity.getAccount());
|
||||
}
|
||||
}
|
||||
PaginationVO vo = JsonUtil.getJsonToBean(pagination, PaginationVO.class);
|
||||
return ActionResult.page(voList, vo);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,272 @@
|
||||
package com.yunzhupaas.base.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import com.yunzhupaas.base.ActionResult;
|
||||
import com.yunzhupaas.base.Page;
|
||||
import com.yunzhupaas.base.entity.DataInterfaceEntity;
|
||||
import com.yunzhupaas.base.entity.DataInterfaceVariateEntity;
|
||||
import com.yunzhupaas.base.model.datainterfacevariate.DataInterfaceVariateListVO;
|
||||
import com.yunzhupaas.base.model.datainterfacevariate.DataInterfaceVariateModel;
|
||||
import com.yunzhupaas.base.model.datainterfacevariate.DataInterfaceVariateSelectorVO;
|
||||
import com.yunzhupaas.base.model.datainterfacevariate.DataInterfaceVariateVO;
|
||||
import com.yunzhupaas.base.service.DataInterfaceService;
|
||||
import com.yunzhupaas.base.service.DataInterfaceVariateService;
|
||||
import com.yunzhupaas.base.vo.DownloadVO;
|
||||
import com.yunzhupaas.base.vo.ListVO;
|
||||
import com.yunzhupaas.config.ConfigValueUtil;
|
||||
import com.yunzhupaas.constant.MsgCode;
|
||||
import com.yunzhupaas.emnus.ModuleTypeEnum;
|
||||
import com.yunzhupaas.exception.DataException;
|
||||
import com.yunzhupaas.permission.entity.UserEntity;
|
||||
import com.yunzhupaas.permission.service.UserService;
|
||||
import com.yunzhupaas.util.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 数据接口变量
|
||||
*
|
||||
* @author 云筑产品开发平台组
|
||||
* @version V3.1.0
|
||||
* @copyright 深圳市乐程软件有限公司(http://www.szlecheng.cn)
|
||||
* @date 2024-03-15 10:29
|
||||
*/
|
||||
@Tag(name = "数据接口变量", description = "DataInterfaceVariate")
|
||||
@RestController
|
||||
@RequestMapping(value = "/api/system/DataInterfaceVariate")
|
||||
public class DataInterfaceVariateController {
|
||||
|
||||
@Autowired
|
||||
private DataInterfaceVariateService dataInterfaceVariateService;
|
||||
@Autowired
|
||||
private UserService userApi;
|
||||
@Autowired
|
||||
private DataInterfaceService dataInterfaceService;
|
||||
@Autowired
|
||||
private DataFileExport fileExport;
|
||||
@Autowired
|
||||
private ConfigValueUtil configValueUtil;
|
||||
|
||||
/**
|
||||
* 获取数据接口变量
|
||||
*
|
||||
* @param id 主键
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "获取数据接口变量")
|
||||
@SaCheckPermission("systemData.dataInterface")
|
||||
@Parameter(name = "id", description = "自然主键")
|
||||
@GetMapping("/{id}")
|
||||
public ActionResult<ListVO<DataInterfaceVariateListVO>> list(@PathVariable("id") String id, Page page) {
|
||||
List<DataInterfaceVariateListVO> list = new ArrayList<>();
|
||||
List<DataInterfaceVariateEntity> data = dataInterfaceVariateService.getList(id, page);
|
||||
data.forEach(t -> {
|
||||
DataInterfaceVariateListVO vo = new DataInterfaceVariateListVO();
|
||||
vo.setId(t.getId());
|
||||
vo.setInterfaceId(t.getInterfaceId());
|
||||
vo.setFullName(t.getFullName());
|
||||
vo.setValue(t.getValue());
|
||||
vo.setCreatorTime(t.getCreatorTime() != null ? t.getCreatorTime().getTime() : null);
|
||||
vo.setLastModifyTime(t.getLastModifyTime() != null ? t.getLastModifyTime().getTime() : null);
|
||||
UserEntity userEntity = userApi.getInfo(t.getCreatorUserId());
|
||||
vo.setCreatorUser(userEntity != null ? userEntity.getRealName() + "/" + userEntity.getAccount() : null);
|
||||
list.add(vo);
|
||||
});
|
||||
ListVO<DataInterfaceVariateListVO> listVO = new ListVO<>();
|
||||
listVO.setList(list);
|
||||
return ActionResult.success(listVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 下拉列表
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "下拉列表")
|
||||
@SaCheckPermission("systemData.dataInterface")
|
||||
@GetMapping("/Selector")
|
||||
public ActionResult<List<DataInterfaceVariateSelectorVO>> selector() {
|
||||
List<DataInterfaceVariateEntity> data = dataInterfaceVariateService.getList(null, null);
|
||||
List<DataInterfaceEntity> list = dataInterfaceService.getList(data.stream().map(DataInterfaceVariateEntity::getInterfaceId).collect(Collectors.toList()));
|
||||
List<DataInterfaceVariateSelectorVO> jsonToList = JsonUtil.getJsonToList(list, DataInterfaceVariateSelectorVO.class);
|
||||
jsonToList.forEach(t -> {
|
||||
t.setParentId("-1");
|
||||
t.setType(0);
|
||||
});
|
||||
jsonToList.forEach(t -> {
|
||||
List<DataInterfaceVariateEntity> collect = data.stream().filter(variateEntity -> t.getId().equals(variateEntity.getInterfaceId())).collect(Collectors.toList());
|
||||
List<DataInterfaceVariateSelectorVO> selectorVOS = JsonUtil.getJsonToList(collect, DataInterfaceVariateSelectorVO.class);
|
||||
selectorVOS.forEach(selectorVO -> {
|
||||
selectorVO.setParentId(t.getId());
|
||||
selectorVO.setType(1);
|
||||
});
|
||||
t.setChildren(selectorVOS);
|
||||
});
|
||||
return ActionResult.success(jsonToList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 详情
|
||||
*
|
||||
* @param id 主键
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "详情")
|
||||
@SaCheckPermission("systemData.dataInterface")
|
||||
@Parameter(name = "id", description = "自然主键")
|
||||
@GetMapping("/{id}/Info")
|
||||
public ActionResult<DataInterfaceVariateVO> info(@PathVariable("id") String id) {
|
||||
DataInterfaceVariateEntity entity = dataInterfaceVariateService.getInfo(id);
|
||||
DataInterfaceVariateVO vo = JsonUtil.getJsonToBean(entity, DataInterfaceVariateVO.class);
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出
|
||||
*
|
||||
* @param id 自然主键
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "导出")
|
||||
@SaCheckPermission("systemData.dataInterface")
|
||||
@Parameter(name = "id", description = "自然主键")
|
||||
@GetMapping("/{id}/Actions/Export")
|
||||
public ActionResult<DownloadVO> export(@PathVariable("id") String id) {
|
||||
DataInterfaceVariateEntity entity = dataInterfaceVariateService.getInfo(id);
|
||||
DownloadVO downloadVO = fileExport.exportFile(entity, configValueUtil.getTemporaryFilePath(), entity.getFullName(), ModuleTypeEnum.SYSTEM_DATAINTEFASE_VARIATE.getTableName());
|
||||
return ActionResult.success(downloadVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
*
|
||||
* @param dataInterfaceVariateModel 模型
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "添加")
|
||||
@SaCheckPermission("systemData.dataInterface")
|
||||
@Parameter(name = "dataInterfaceVariateModel", description = "模型")
|
||||
@PostMapping
|
||||
public ActionResult<String> create(@RequestBody DataInterfaceVariateModel dataInterfaceVariateModel) {
|
||||
DataInterfaceVariateEntity entity = JsonUtil.getJsonToBean(dataInterfaceVariateModel, DataInterfaceVariateEntity.class);
|
||||
if (entity.getFullName().contains("@")) {
|
||||
return ActionResult.fail(MsgCode.SYS009.get());
|
||||
}
|
||||
if (dataInterfaceVariateService.isExistByFullName(entity)) {
|
||||
return ActionResult.fail(MsgCode.SYS010.get());
|
||||
}
|
||||
dataInterfaceVariateService.create(entity);
|
||||
return ActionResult.success(MsgCode.SU001.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
*
|
||||
* @param id 自然主键
|
||||
* @param dataInterfaceVariateModel 模型
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "修改")
|
||||
@SaCheckPermission("systemData.dataInterface")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "自然主键"),
|
||||
@Parameter(name = "dataInterfaceVariateModel", description = "模型")
|
||||
})
|
||||
@PutMapping("/{id}")
|
||||
public ActionResult<String> update(@PathVariable("id") String id, @RequestBody DataInterfaceVariateModel dataInterfaceVariateModel) {
|
||||
DataInterfaceVariateEntity entity = JsonUtil.getJsonToBean(dataInterfaceVariateModel, DataInterfaceVariateEntity.class);
|
||||
if (entity.getFullName().contains("@")) {
|
||||
return ActionResult.fail(MsgCode.SYS009.get());
|
||||
}
|
||||
entity.setId(id);
|
||||
if (dataInterfaceVariateService.isExistByFullName(entity)) {
|
||||
return ActionResult.fail(MsgCode.SYS010.get());
|
||||
}
|
||||
dataInterfaceVariateService.update(entity);
|
||||
return ActionResult.success(MsgCode.SU004.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*
|
||||
* @param id 自然主键
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "删除")
|
||||
@SaCheckPermission("systemData.dataInterface")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "自然主键")
|
||||
})
|
||||
@DeleteMapping("/{id}")
|
||||
public ActionResult<String> delete(@PathVariable("id") String id) {
|
||||
DataInterfaceVariateEntity entity = dataInterfaceVariateService.getInfo(id);
|
||||
if (entity == null) {
|
||||
return ActionResult.fail(MsgCode.FA001.get());
|
||||
}
|
||||
dataInterfaceVariateService.delete(entity);
|
||||
return ActionResult.success(MsgCode.SU003.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 导入
|
||||
*
|
||||
* @param multipartFile 文件
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "导入")
|
||||
@SaCheckPermission("systemData.dataInterface")
|
||||
@PostMapping(value = "/Actions/Import", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
public ActionResult<String> delete(@RequestPart("file") MultipartFile multipartFile) {
|
||||
//判断是否为.json结尾
|
||||
if (FileUtil.existsSuffix(multipartFile, ModuleTypeEnum.SYSTEM_DATAINTEFASE_VARIATE.getTableName())) {
|
||||
return ActionResult.fail(MsgCode.IMP002.get());
|
||||
}
|
||||
//读取文件内容
|
||||
String fileContent = FileUtil.getFileContent(multipartFile);
|
||||
try {
|
||||
DataInterfaceVariateEntity entity = JsonUtil.getJsonToBean(fileContent, DataInterfaceVariateEntity.class);
|
||||
if (dataInterfaceVariateService.getInfo(entity.getId()) == null &&
|
||||
!dataInterfaceVariateService.isExistByFullName(entity)) {
|
||||
dataInterfaceVariateService.create(entity);
|
||||
return ActionResult.success(MsgCode.IMP001.get());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new DataException(MsgCode.IMP004.get());
|
||||
}
|
||||
return ActionResult.fail(MsgCode.IMP003.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 复制
|
||||
*
|
||||
* @param id 自然主键
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "复制")
|
||||
@SaCheckPermission("systemData.dataInterface")
|
||||
@Parameter(name = "id", description = "自然主键", required = true)
|
||||
@PostMapping("/{id}/Actions/Copy")
|
||||
public ActionResult<String> copy(@PathVariable("id") String id) {
|
||||
String copyNum = UUID.randomUUID().toString().substring(0, 5);
|
||||
DataInterfaceVariateEntity entity = dataInterfaceVariateService.getInfo(id);
|
||||
entity.setFullName(entity.getFullName() + ".副本" + copyNum);
|
||||
if(entity.getFullName().length() > 50) return ActionResult.fail(MsgCode.COPY001.get());
|
||||
entity.setLastModifyTime(null);
|
||||
entity.setLastModifyUserId(null);
|
||||
dataInterfaceVariateService.create(entity);
|
||||
return ActionResult.success(MsgCode.SU007.get());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,287 @@
|
||||
package com.yunzhupaas.base.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import cn.dev33.satoken.annotation.SaMode;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import com.yunzhupaas.base.ActionResult;
|
||||
import com.yunzhupaas.base.entity.DataInterfaceEntity;
|
||||
import com.yunzhupaas.base.entity.DataSetEntity;
|
||||
import com.yunzhupaas.base.model.datainterface.DataInterfaceModel;
|
||||
import com.yunzhupaas.base.model.dataset.*;
|
||||
import com.yunzhupaas.base.service.DataInterfaceService;
|
||||
import com.yunzhupaas.base.service.DataSetService;
|
||||
import com.yunzhupaas.base.util.dataSet.DataSetConstant;
|
||||
import com.yunzhupaas.base.util.dataSet.DataSetSwapUtil;
|
||||
import com.yunzhupaas.constant.DataInterfaceVarConst;
|
||||
import com.yunzhupaas.constant.DbSensitiveConstant;
|
||||
import com.yunzhupaas.constant.MsgCode;
|
||||
import com.yunzhupaas.model.visualJson.FieLdsModel;
|
||||
import com.yunzhupaas.model.visualJson.config.ConfigModel;
|
||||
import com.yunzhupaas.util.JsonUtil;
|
||||
import com.yunzhupaas.util.ParameterUtil;
|
||||
import com.yunzhupaas.util.RandomUtil;
|
||||
import com.yunzhupaas.util.StringUtil;
|
||||
import com.yunzhupaas.util.treeutil.SumTree;
|
||||
import com.yunzhupaas.util.visiual.YunzhupaasKeyConsts;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 数据集控制器
|
||||
*
|
||||
* @author 云筑产品开发平台组
|
||||
* @version v5.0.0
|
||||
* @copyright 深圳市乐程软件有限公司
|
||||
* @date 2024/5/7 10:09:18
|
||||
*/
|
||||
@Tag(name = "数据集", description = "DataSet")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/DataSet")
|
||||
public class DataSetController {
|
||||
|
||||
@Autowired
|
||||
private DataSetService dataSetService;
|
||||
@Autowired
|
||||
private DataSetSwapUtil dataSetSwapUtil;
|
||||
@Autowired
|
||||
private DataInterfaceService dataInterfaceService;
|
||||
|
||||
@Operation(summary = "列表")
|
||||
@SaCheckPermission(value = { "onlineDev.printDev", "onlineDev.report" }, mode = SaMode.OR)
|
||||
@GetMapping
|
||||
public ActionResult<List<SumTree<TableTreeModel>>> list(DataSetPagination pagination) throws Exception {
|
||||
List<DataSetEntity> list = dataSetService.getList(pagination);
|
||||
List<SumTree<TableTreeModel>> res = new ArrayList<>();
|
||||
for (DataSetEntity item : list) {
|
||||
if (StringUtil.isNotEmpty(ParameterUtil.checkContainsSensitive(item.getDataConfigJson(),
|
||||
DbSensitiveConstant.PRINT_SENSITIVE))) {
|
||||
return ActionResult.fail(MsgCode.SYS047.get());
|
||||
}
|
||||
// if (!item.getDataConfigJson().contains("@formId")) {
|
||||
// return ActionResult.fail(MsgCode.SYS048.get());
|
||||
// }
|
||||
SumTree<TableTreeModel> printTableFields = dataSetService.getTabFieldStruct(item);
|
||||
res.add(printTableFields);
|
||||
}
|
||||
return ActionResult.success(res);
|
||||
}
|
||||
|
||||
@Operation(summary = "获取字段")
|
||||
@SaCheckPermission(value = { "onlineDev.printDev", "onlineDev.report" }, mode = SaMode.OR)
|
||||
@PostMapping("/fields")
|
||||
public ActionResult<List<SumTree<TableTreeModel>>> getOneFields(@RequestBody DataSetForm form) throws Exception {
|
||||
DataSetEntity item = JsonUtil.getJsonToBean(form, DataSetEntity.class);
|
||||
SumTree<TableTreeModel> printTableFields = dataSetService.getTabFieldStruct(item);
|
||||
return ActionResult.success(printTableFields.getChildren());
|
||||
}
|
||||
|
||||
@Operation(summary = "获取数据")
|
||||
@PostMapping("/Data")
|
||||
public ActionResult getData(@RequestBody DataSetQuery query) {
|
||||
String moduleId = query.getModuleId();
|
||||
StpUtil.checkPermissionOr(moduleId, "onlineDev.report");
|
||||
Map<String, Object> dataMapOrList = dataSetService.getDataList(query);
|
||||
String id = query.getId();
|
||||
String convertConfig = query.getConvertConfig();
|
||||
Map<String, List<Map<String, Object>>> resultData = new HashMap<>();
|
||||
dataSetSwapUtil.swapData(id, convertConfig, dataMapOrList);
|
||||
for (String key : dataMapOrList.keySet()) {
|
||||
if (dataMapOrList.get(key) instanceof List) {
|
||||
List<Map<String, Object>> list = (List<Map<String, Object>>) dataMapOrList.get(key);
|
||||
resultData.put(key, list);
|
||||
}
|
||||
}
|
||||
return ActionResult.success(resultData);
|
||||
}
|
||||
|
||||
@Operation(summary = "参数转换")
|
||||
@PostMapping("/parameterData")
|
||||
public ActionResult getParameterData(@RequestBody DataSetQuery query) {
|
||||
String moduleId = query.getModuleId();
|
||||
StpUtil.checkPermissionOr(moduleId, "onlineDev.report");
|
||||
Map<String, Object> queryMap = query.getMap() != null ? query.getMap() : new HashMap<>();
|
||||
List<FieLdsModel> queryList = StringUtil.isNotEmpty(query.getQueryList())
|
||||
? JsonUtil.getJsonToList(query.getQueryList(), FieLdsModel.class)
|
||||
: new ArrayList<>();
|
||||
Map<String, Map<String, Object>> dataMap = new HashMap<>();
|
||||
List<String> systemId = ImmutableList.of(
|
||||
DataInterfaceVarConst.USER, DataInterfaceVarConst.USERANDSUB, DataInterfaceVarConst.ORG,
|
||||
DataInterfaceVarConst.ORGANDSUB, DataInterfaceVarConst.CHARORG, DataInterfaceVarConst.ID);
|
||||
List<DataSetSwapModel> convertList = new ArrayList<>();
|
||||
List<DataInterfaceModel> dataInterfaceList = new ArrayList<>();
|
||||
for (String id : systemId) {
|
||||
DataInterfaceModel model = new DataInterfaceModel();
|
||||
model.setField(id);
|
||||
model.setSourceType(4);
|
||||
model.setRelationField(id);
|
||||
model.setDefaultValue(
|
||||
StringUtil.isNotEmpty(query.getSnowFlakeId()) ? query.getSnowFlakeId() : RandomUtil.uuId());
|
||||
dataInterfaceList.add(model);
|
||||
DataSetSwapModel swapModel = new DataSetSwapModel();
|
||||
switch (id) {
|
||||
case DataInterfaceVarConst.USER:
|
||||
case DataInterfaceVarConst.USERANDSUB:
|
||||
swapModel.setType(DataSetConstant.KEY_USER);
|
||||
break;
|
||||
case DataInterfaceVarConst.ORGANDSUB:
|
||||
case DataInterfaceVarConst.CHARORG:
|
||||
case DataInterfaceVarConst.ORG:
|
||||
swapModel.setType(DataSetConstant.KEY_DEP);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
swapModel.setField(id + "." + id);
|
||||
swapModel.setConfig(new DataSetConfig());
|
||||
convertList.add(swapModel);
|
||||
}
|
||||
Map<String, String> paramSystemMap = new HashMap<>();
|
||||
dataInterfaceService.paramSourceTypeReplaceValue(dataInterfaceList, paramSystemMap);
|
||||
for (String key : paramSystemMap.keySet()) {
|
||||
String value = paramSystemMap.get(key);
|
||||
Object systemValue = Objects.equals(DataInterfaceVarConst.ID, key) ? value
|
||||
: JsonUtil.getObjectToString(value.split(","));
|
||||
Map<String, Object> systemMap = new HashMap<>();
|
||||
systemMap.put(key, systemValue);
|
||||
dataMap.put(key, systemMap);
|
||||
}
|
||||
for (String key : queryMap.keySet()) {
|
||||
String vModel = key.replace("-", ".");
|
||||
String[] name = key.split("-");
|
||||
FieLdsModel fieLdsModel = queryList.stream().filter(t -> Objects.equals(t.getVModel(), vModel)).findFirst()
|
||||
.orElse(null);
|
||||
if (fieLdsModel != null) {
|
||||
// 转换配置
|
||||
ConfigModel config = fieLdsModel.getConfig();
|
||||
String type = fieLdsModel.getType();
|
||||
DataSetConfig dataSetConfig = new DataSetConfig();
|
||||
dataSetConfig.setDataType(config.getDataType());
|
||||
dataSetConfig.setOptions(JsonUtil.getJsonToList(config.getOptions(), DataSetOptions.class));
|
||||
dataSetConfig.setDictionaryType(config.getDictionaryType());
|
||||
dataSetConfig.setPropsValue(config.getPropsValue());
|
||||
dataSetConfig.setFormat(config.getFormat());
|
||||
Object value = queryMap.get(key);
|
||||
switch (type) {
|
||||
case YunzhupaasKeyConsts.NUM_INPUT:
|
||||
type = DataSetConstant.KEY_NUMBER;
|
||||
break;
|
||||
case YunzhupaasKeyConsts.COMSELECT:
|
||||
type = DataSetConstant.KEY_ORG;
|
||||
if (value instanceof List) {
|
||||
value = JsonUtil.getObjectToString(value);
|
||||
}
|
||||
break;
|
||||
case YunzhupaasKeyConsts.DEPSELECT:
|
||||
type = DataSetConstant.KEY_DEP;
|
||||
if (value instanceof List) {
|
||||
value = JsonUtil.getObjectToString(value);
|
||||
}
|
||||
break;
|
||||
case YunzhupaasKeyConsts.ROLESELECT:
|
||||
type = DataSetConstant.KEY_ROLE;
|
||||
if (value instanceof List) {
|
||||
value = JsonUtil.getObjectToString(value);
|
||||
}
|
||||
break;
|
||||
case YunzhupaasKeyConsts.POSSELECT:
|
||||
type = DataSetConstant.KEY_POS;
|
||||
if (value instanceof List) {
|
||||
value = JsonUtil.getObjectToString(value);
|
||||
}
|
||||
break;
|
||||
case YunzhupaasKeyConsts.USERSELECT:
|
||||
type = DataSetConstant.KEY_USERS;
|
||||
if (value instanceof List) {
|
||||
value = JsonUtil.getObjectToString(value);
|
||||
}
|
||||
break;
|
||||
case YunzhupaasKeyConsts.GROUPSELECT:
|
||||
type = DataSetConstant.KEY_GROUP;
|
||||
if (value instanceof List) {
|
||||
value = JsonUtil.getObjectToString(value);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
DataSetSwapModel swapModel = new DataSetSwapModel();
|
||||
swapModel.setType(type);
|
||||
swapModel.setField(fieLdsModel.getVModel());
|
||||
swapModel.setConfig(dataSetConfig);
|
||||
convertList.add(swapModel);
|
||||
// 数据
|
||||
String model = name[0];
|
||||
Map<String, Object> map = dataMap.get(model) != null ? dataMap.get(model) : new HashMap<>();
|
||||
map.put(name[1], value);
|
||||
dataMap.put(model, map);
|
||||
}
|
||||
}
|
||||
String convertConfig = JsonUtil.getObjectToString(convertList);
|
||||
Map<String, Object> dataMapOrList = new HashMap<>();
|
||||
for (String key : dataMap.keySet()) {
|
||||
List<Map<String, Object>> dataList = new ArrayList<>();
|
||||
dataList.add(dataMap.get(key));
|
||||
dataMapOrList.put(key, dataList);
|
||||
}
|
||||
dataSetSwapUtil.swapData(RandomUtil.uuId(), convertConfig, dataMapOrList);
|
||||
return ActionResult.success(dataMap);
|
||||
}
|
||||
|
||||
@Operation(summary = "列表")
|
||||
@SaCheckPermission(value = { "onlineDev.printDev", "onlineDev.report" }, mode = SaMode.OR)
|
||||
@GetMapping("/getList")
|
||||
public ActionResult<List<DataSetInfo>> getList(DataSetPagination pagination) {
|
||||
List<DataSetEntity> list = dataSetService.getList(pagination);
|
||||
List<DataSetInfo> dataSetInfoList = new ArrayList<>();
|
||||
if (ObjectUtil.isNotEmpty(list)) {
|
||||
for (DataSetEntity item : list) {
|
||||
DataSetInfo bean = JsonUtil.getJsonToBean(item, DataSetInfo.class);
|
||||
try {
|
||||
SumTree<TableTreeModel> printTableFields = dataSetService.getTabFieldStruct(item);
|
||||
bean.setChildren(printTableFields.getChildren());
|
||||
dataSetInfoList.add(bean);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (Objects.equals(item.getType(), 3)) {
|
||||
DataInterfaceEntity info = dataInterfaceService.getInfo(item.getInterfaceId());
|
||||
if (info != null) {
|
||||
bean.setTreePropsName(info.getFullName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return ActionResult.success(dataSetInfoList);
|
||||
}
|
||||
|
||||
@Operation(summary = "批量保存")
|
||||
@Parameters({
|
||||
@Parameter(name = "form", description = "数据集表单")
|
||||
})
|
||||
@SaCheckPermission(value = { "onlineDev.printDev", "onlineDev.report" }, mode = SaMode.OR)
|
||||
@PostMapping("/save")
|
||||
public ActionResult saveList(@RequestBody DataForm form) {
|
||||
List<DataSetInfo> list = form.getList() != null ? form.getList() : new ArrayList<>();
|
||||
dataSetService.create(JsonUtil.getJsonToList(list, DataSetForm.class), form.getObjectType(),
|
||||
form.getObjectId());
|
||||
return ActionResult.success(MsgCode.SU002.get());
|
||||
}
|
||||
|
||||
@Operation(summary = "数据预览")
|
||||
@SaCheckPermission(value = { "onlineDev.printDev", "onlineDev.report" }, mode = SaMode.OR)
|
||||
@PostMapping("/getPreviewData")
|
||||
public ActionResult<DataSetViewInfo> getPreviewData(@RequestBody DataSetForm dataSetForm) {
|
||||
if (Objects.equals(dataSetForm.getType(), 3)) {
|
||||
DataSetViewInfo info = dataSetService.getPreviewDataInterface(dataSetForm);
|
||||
return ActionResult.success(info);
|
||||
}
|
||||
DataSetViewInfo info = dataSetService.getPreviewData(dataSetForm);
|
||||
return ActionResult.success(info);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,277 @@
|
||||
package com.yunzhupaas.base.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import com.yunzhupaas.base.controller.SuperController;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import com.yunzhupaas.base.ActionResult;
|
||||
import com.yunzhupaas.base.entity.DictionaryDataEntity;
|
||||
import com.yunzhupaas.base.entity.SuperBaseEntity;
|
||||
import com.yunzhupaas.base.model.dblink.*;
|
||||
import com.yunzhupaas.base.service.DbLinkService;
|
||||
import com.yunzhupaas.base.service.DictionaryDataService;
|
||||
import com.yunzhupaas.base.service.DictionaryTypeService;
|
||||
import com.yunzhupaas.base.vo.ListVO;
|
||||
import com.yunzhupaas.base.vo.PageListVO;
|
||||
import com.yunzhupaas.base.vo.PaginationVO;
|
||||
import com.yunzhupaas.constant.MsgCode;
|
||||
import com.yunzhupaas.database.model.entity.DbLinkEntity;
|
||||
import com.yunzhupaas.database.util.DataSourceUtil;
|
||||
import com.yunzhupaas.exception.DataException;
|
||||
import com.yunzhupaas.permission.entity.UserEntity;
|
||||
import com.yunzhupaas.permission.service.UserService;
|
||||
import com.yunzhupaas.util.JsonUtil;
|
||||
import com.yunzhupaas.util.XSSEscape;
|
||||
import com.yunzhupaas.util.enums.DictionaryDataEnum;
|
||||
import com.yunzhupaas.util.treeutil.SumTree;
|
||||
import com.yunzhupaas.util.treeutil.newtreeutil.TreeDotUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 数据连接
|
||||
*
|
||||
* @author 云筑产品开发平台组
|
||||
* @version V3.1.0
|
||||
* @copyright 深圳市乐程软件有限公司
|
||||
* @date 2023/09/27
|
||||
*/
|
||||
@Tag(name = "数据连接", description = "DataSource")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/DataSource")
|
||||
public class DbLinkController extends SuperController<DbLinkService, DbLinkEntity> {
|
||||
|
||||
@Autowired
|
||||
private DbLinkService dblinkService;
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
@Autowired
|
||||
private DictionaryDataService dictionaryDataService;
|
||||
@Autowired
|
||||
private DictionaryTypeService dictionaryTypeService;
|
||||
@Autowired
|
||||
private DataSourceUtil dataSourceUtil;
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*
|
||||
* @param type 类型
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/Selector")
|
||||
@Operation(summary = "获取数据连接下拉框列表")
|
||||
public ActionResult<ListVO<DbLinkSelectorListVO>> selectorList(String type) {
|
||||
List<DbLinkModel> modelAll = new LinkedList<>();
|
||||
List<DbLinkEntity> dbLinkList = dblinkService.getList();
|
||||
List<DictionaryDataEntity> dictionaryDataList = dictionaryDataService.getList(dictionaryTypeService.getInfoByEnCode(DictionaryDataEnum.SYSTEM_DBLINK.getDictionaryTypeId()).getId());
|
||||
// 1、连接中字典目录
|
||||
for (DictionaryDataEntity entity : dictionaryDataList) {
|
||||
long num = dbLinkList.stream().filter(t -> t.getDbType().equals(entity.getEnCode())).count();
|
||||
if (num > 0){
|
||||
DbLinkModel model = new DbLinkModel();
|
||||
model.setNum(num);
|
||||
model.setFullName(entity.getFullName());
|
||||
model.setParentId("-1");
|
||||
model.setId(entity.getId());
|
||||
modelAll.add(model);
|
||||
}
|
||||
}
|
||||
// 2、字典中的连接集合
|
||||
for (DbLinkEntity entity : dbLinkList) {
|
||||
dictionaryDataList.stream().filter(t -> t.getEnCode().equals(entity.getDbType())).findFirst().ifPresent((dataEntity)->{
|
||||
DbLinkModel model = JsonUtil.getJsonToBean(entity, DbLinkModel.class);
|
||||
model.setParentId(dataEntity.getId());
|
||||
modelAll.add(model);
|
||||
});
|
||||
}
|
||||
List<SumTree<DbLinkModel>> trees = TreeDotUtils.convertListToTreeDot(modelAll.stream().sorted(Comparator.comparing(DbLinkModel::getFullName)).collect(Collectors.toList()));
|
||||
List<DbLinkSelectorListVO> list = new ArrayList<>();
|
||||
// type为空时返回默认库
|
||||
if(type == null){
|
||||
DbLinkListVO dbLink = new DbLinkListVO();
|
||||
dbLink.setFullName("默认数据库");
|
||||
dbLink.setId("0");
|
||||
dbLink.setDbType(dataSourceUtil.getDbType());
|
||||
DbLinkSelectorListVO defaultDb = new DbLinkSelectorListVO();
|
||||
defaultDb.setFullName("");
|
||||
defaultDb.setChildren(Collections.singletonList(dbLink));
|
||||
list.add(defaultDb);
|
||||
}
|
||||
list.addAll(JsonUtil.getJsonToList(trees, DbLinkSelectorListVO.class));
|
||||
return ActionResult.success(new ListVO<>(list));
|
||||
}
|
||||
|
||||
/**
|
||||
* 2:列表
|
||||
*
|
||||
* @param page 关键字
|
||||
* @return ignore
|
||||
*/
|
||||
@GetMapping
|
||||
@Operation(summary = "获取数据连接列表")
|
||||
public ActionResult<PageListVO<DbLinkListVO>> getList(PaginationDbLink page) {
|
||||
List<DbLinkEntity> data = dblinkService.getList(page);
|
||||
List<String> userId = data.stream().map(SuperBaseEntity.SuperCBaseEntity::getCreatorUserId).collect(Collectors.toList());
|
||||
List<String> lastUserId = data.stream().map(SuperBaseEntity.SuperCUBaseEntity::getLastModifyUserId).collect(Collectors.toList());
|
||||
List<UserEntity> userEntities = userService.getUserName(userId);
|
||||
List<UserEntity> lastUserIdEntities = userService.getUserName(lastUserId);
|
||||
List<DictionaryDataEntity> typeList = dictionaryDataService.getList(dictionaryTypeService.getInfoByEnCode(DictionaryDataEnum.SYSTEM_DBLINK.getDictionaryTypeId()).getId());
|
||||
List<DbLinkListVO> jsonToList = JsonUtil.getJsonToList(data, DbLinkListVO.class);
|
||||
for (DbLinkListVO vo : jsonToList) {
|
||||
//存在类型的字典对象
|
||||
DictionaryDataEntity dataEntity = typeList.stream().filter(t -> t.getEnCode().equals(vo.getDbType())).findFirst().orElse(null);
|
||||
if (dataEntity != null) {
|
||||
vo.setDbType(dataEntity.getFullName());
|
||||
} else {
|
||||
vo.setDbType("");
|
||||
}
|
||||
//创建者
|
||||
UserEntity creatorUser = userEntities.stream().filter(t -> t.getId().equals(vo.getCreatorUser())).findFirst().orElse(null);
|
||||
vo.setCreatorUser(creatorUser != null ? creatorUser.getRealName() + "/" + creatorUser.getAccount() : vo.getCreatorUser());
|
||||
//修改人
|
||||
UserEntity lastModifyUser = lastUserIdEntities.stream().filter(t -> t.getId().equals(vo.getLastModifyUser())).findFirst().orElse(null);
|
||||
vo.setLastModifyUser(lastModifyUser != null ? lastModifyUser.getRealName() + "/" + lastModifyUser.getAccount() : vo.getLastModifyUser());
|
||||
}
|
||||
PaginationVO paginationVO = JsonUtil.getJsonToBean(page, PaginationVO.class);
|
||||
return ActionResult.page(jsonToList , paginationVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表分组
|
||||
*
|
||||
* @param page 查询条件
|
||||
* @return 数据源分组列表
|
||||
*/
|
||||
@GetMapping("/getGroup")
|
||||
@Operation(summary = "获取数据连接列表")
|
||||
public ActionResult<List<Map<String, Object>>> getGroup(PaginationDbLink page) {
|
||||
ActionResult<PageListVO<DbLinkListVO>> result = getList(page);
|
||||
List<DbLinkListVO> voList = result.getData().getList();
|
||||
// host分组
|
||||
Set<String> hostSet = voList.stream().sorted(Comparator.comparing(DbLinkListVO::getHost))
|
||||
.map(DbLinkListVO::getHost).collect(Collectors.toSet());
|
||||
List<Map<String, Object>> groupList = new ArrayList<>();
|
||||
for (String host : hostSet) {
|
||||
Map<String, Object> groupMap = new HashMap<>();
|
||||
groupMap.put("host", host);
|
||||
groupMap.put("options", voList.stream().filter(vo->vo.getHost().equals(host)).toArray());
|
||||
groupList.add(groupMap);
|
||||
}
|
||||
return ActionResult.success(groupList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 3:单条数据连接
|
||||
*
|
||||
* @param id 主键
|
||||
* @return ignore
|
||||
* @throws DataException ignore
|
||||
*/
|
||||
@GetMapping("/{id}")
|
||||
@Operation(summary = "获取数据连接")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键")
|
||||
})
|
||||
@SaCheckPermission("systemData.dataSource")
|
||||
public ActionResult<DbLinkInfoVO> get(@PathVariable("id") String id) throws DataException {
|
||||
return ActionResult.success(new DbLinkInfoVO().getDbLinkInfoVO(dblinkService.getInfo(XSSEscape.escape(id))));
|
||||
}
|
||||
|
||||
/**
|
||||
* 4:新建数据连接
|
||||
*
|
||||
* @param dbLinkCreUpForm 新建数据连接表单对象
|
||||
* @return ignore
|
||||
*/
|
||||
@PostMapping
|
||||
@Operation(summary = "添加数据连接")
|
||||
@Parameters({
|
||||
@Parameter(name = "dbLinkCreUpForm", description = "新建数据连接表单对象", required = true)
|
||||
})
|
||||
@SaCheckPermission("systemData.dataSource")
|
||||
public ActionResult<String> create(@RequestBody @Valid DbLinkCreUpForm dbLinkCreUpForm) {
|
||||
DbLinkEntity entity = dbLinkCreUpForm.getDbLinkEntity(dbLinkCreUpForm);
|
||||
if (dblinkService.isExistByFullName(entity.getFullName(), entity.getId())) {
|
||||
return ActionResult.fail(MsgCode.EXIST001.get());
|
||||
}
|
||||
dblinkService.create(entity);
|
||||
return ActionResult.success(MsgCode.SU001.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 5:更新数据连接
|
||||
*
|
||||
* @param id 主键
|
||||
* @param dbLinkCreUpForm dto实体
|
||||
* @return ignore
|
||||
*/
|
||||
@PutMapping("/{id}")
|
||||
@Operation(summary = "修改数据连接")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true),
|
||||
@Parameter(name = "dbLinkCreUpForm", description = "新建数据连接表单对象", required = true)
|
||||
})
|
||||
@SaCheckPermission("systemData.dataSource")
|
||||
public ActionResult<String> update(@PathVariable("id") String id, @RequestBody @Valid DbLinkCreUpForm dbLinkCreUpForm) {
|
||||
id = XSSEscape.escape(id);
|
||||
DbLinkEntity entity = dbLinkCreUpForm.getDbLinkEntity(dbLinkCreUpForm);
|
||||
if (dblinkService.isExistByFullName(entity.getFullName(), id)) {
|
||||
return ActionResult.fail(MsgCode.EXIST001.get());
|
||||
}
|
||||
if (!dblinkService.update(id, entity)) {
|
||||
return ActionResult.fail(MsgCode.FA002.get());
|
||||
}
|
||||
return ActionResult.success(MsgCode.SU004.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 6:删除
|
||||
*
|
||||
* @param id 主键
|
||||
* @return ignore
|
||||
*/
|
||||
@DeleteMapping("/{id}")
|
||||
@Operation(summary = "删除数据连接")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true)
|
||||
})
|
||||
@SaCheckPermission("systemData.dataSource")
|
||||
public ActionResult<String> delete(@PathVariable("id") String id) {
|
||||
DbLinkEntity entity = dblinkService.getInfo(id);
|
||||
if (entity != null) {
|
||||
dblinkService.delete(entity);
|
||||
return ActionResult.success(MsgCode.SU003.get());
|
||||
}
|
||||
return ActionResult.fail(MsgCode.FA003.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 7:测试连接
|
||||
*
|
||||
* @param dbLinkBaseForm 数据连接参数
|
||||
* @return ignore
|
||||
* @throws DataException ignore
|
||||
*/
|
||||
@PostMapping("/Actions/Test")
|
||||
@Operation(summary = "测试连接")
|
||||
@Parameters({
|
||||
@Parameter(name = "dbLinkBaseForm", description = "数据连接参数", required = true)
|
||||
})
|
||||
@SaCheckPermission("systemData.dataSource")
|
||||
public ActionResult<String> test(@RequestBody DbLinkBaseForm dbLinkBaseForm) throws Exception {
|
||||
boolean data = dblinkService.testDbConnection(dbLinkBaseForm.getDbLinkEntity(dbLinkBaseForm));
|
||||
if (data) {
|
||||
return ActionResult.success(MsgCode.DB301.get());
|
||||
} else {
|
||||
return ActionResult.fail(MsgCode.DB302.get());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,291 @@
|
||||
package com.yunzhupaas.base.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import com.yunzhupaas.base.ActionResult;
|
||||
import com.yunzhupaas.base.model.dbsync.DbSyncForm;
|
||||
import com.yunzhupaas.base.model.dbsync.DbSyncPrintForm;
|
||||
import com.yunzhupaas.base.model.dbsync.DbSyncVo;
|
||||
import com.yunzhupaas.base.service.DbLinkService;
|
||||
import com.yunzhupaas.base.service.DbSyncService;
|
||||
import com.yunzhupaas.base.service.DbTableService;
|
||||
import com.yunzhupaas.constant.MsgCode;
|
||||
import com.yunzhupaas.database.datatype.db.interfaces.DtInterface;
|
||||
import com.yunzhupaas.database.datatype.sync.util.DtSyncUtil;
|
||||
import com.yunzhupaas.database.model.dbfield.DbFieldModel;
|
||||
import com.yunzhupaas.database.model.dto.PrepSqlDTO;
|
||||
import com.yunzhupaas.database.model.entity.DbLinkEntity;
|
||||
import com.yunzhupaas.database.source.impl.DbOracle;
|
||||
import com.yunzhupaas.database.sql.model.SqlPrintHandler;
|
||||
import com.yunzhupaas.database.sql.param.FormatSqlOracle;
|
||||
import com.yunzhupaas.database.sql.util.SqlFastUtil;
|
||||
import com.yunzhupaas.database.util.DataSourceUtil;
|
||||
import com.yunzhupaas.util.XSSEscape;
|
||||
import lombok.Cleanup;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.sql.Connection;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 数据同步
|
||||
*
|
||||
* @author 云筑产品开发平台组
|
||||
* @version V3.1.0
|
||||
* @copyright 深圳市乐程软件有限公司
|
||||
* @date 2023/09/27
|
||||
*/
|
||||
@Tag(name = "数据同步", description = "DataSync")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/DataSync")
|
||||
public class DbSyncController {
|
||||
|
||||
@Autowired
|
||||
private DbSyncService dbSyncService;
|
||||
@Autowired
|
||||
private DbLinkService dblinkService;
|
||||
@Autowired
|
||||
private DbTableService dbTableService;
|
||||
@Autowired
|
||||
private SqlPrintHandler sqlPrintHandler;
|
||||
@Autowired
|
||||
private DataSourceUtil dataSourceUtil;
|
||||
|
||||
/**
|
||||
* 验证连接
|
||||
*
|
||||
* @param dbSyncForm 页面参数
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
@PostMapping("Actions/checkDbLink")
|
||||
@Parameters({
|
||||
@Parameter(name = "dbSyncForm", description = "页面参数", required = true)
|
||||
})
|
||||
@SaCheckPermission("systemData.dataSync")
|
||||
@Operation(summary = "验证连接")
|
||||
public ActionResult<DbSyncVo> checkDbLink(@RequestBody DbSyncForm dbSyncForm) throws Exception {
|
||||
String fromDbType;
|
||||
String toDbType;
|
||||
DbSyncVo vo = new DbSyncVo();
|
||||
try {
|
||||
DbLinkEntity dbLinkEntity = dblinkService.getResource(dbSyncForm.getDbConnectionFrom());
|
||||
DbLinkEntity dbLinkEntity1 = dblinkService.getResource(dbSyncForm.getDbConnectionTo());
|
||||
fromDbType = dbLinkEntity.getDbType();
|
||||
toDbType = dbLinkEntity1.getDbType();
|
||||
@Cleanup Connection conn = PrepSqlDTO.getConn(dbLinkEntity);
|
||||
@Cleanup Connection conn1 = PrepSqlDTO.getConn(dbLinkEntity1);
|
||||
if (conn.getMetaData().getURL().equals(conn1.getMetaData().getURL())) {
|
||||
return ActionResult.fail(MsgCode.SYS011.get());
|
||||
}
|
||||
vo.setCheckDbFlag(true);
|
||||
vo.setTableList(SqlFastUtil.getTableList(dbLinkEntity, null));
|
||||
// 字段类型全部对应关系
|
||||
Map<String, List<String>> ruleMap = getConvertRules(fromDbType, toDbType).getData();
|
||||
Map<String, String> defaultRuleMap = getDefaultRules(fromDbType, toDbType).getData();
|
||||
// 默认类型置顶
|
||||
for (String key : defaultRuleMap.keySet()) {
|
||||
List<String> list = ruleMap.get(key);
|
||||
if(list != null){
|
||||
String rule = defaultRuleMap.get(key);
|
||||
list.remove(rule);
|
||||
list.add(0, rule + " (默认)");
|
||||
ruleMap.put(key, list);
|
||||
}
|
||||
}
|
||||
vo.setConvertRuleMap(ruleMap);
|
||||
}catch (Exception e){
|
||||
return ActionResult.fail(MsgCode.DB302.get());
|
||||
}
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行数据同步
|
||||
*
|
||||
* @param dbSyncForm 数据同步参数
|
||||
* @return ignore
|
||||
* @throws Exception ignore
|
||||
*/
|
||||
@PostMapping
|
||||
@Operation(summary = "数据同步校验")
|
||||
@Parameters({
|
||||
@Parameter(name = "dbSyncForm", description = "页面参数", required = true)
|
||||
})
|
||||
@SaCheckPermission("systemData.dataSync")
|
||||
public ActionResult<Object> checkExecute(@RequestBody DbSyncForm dbSyncForm) throws Exception {
|
||||
int status;
|
||||
try {
|
||||
status = dbSyncService.executeCheck(dbSyncForm.getDbConnectionFrom(), dbSyncForm.getDbConnectionTo(), dbSyncForm.getConvertRuleMap(), dbSyncForm.getDbTable());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return ActionResult.fail(e.getMessage());
|
||||
}
|
||||
if (status == -1) {
|
||||
return ActionResult.fail(MsgCode.SYS012.get());
|
||||
}
|
||||
return ActionResult.success(status);
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行数据同步
|
||||
*
|
||||
* @param dbSyncForm 数据同步参数
|
||||
* @return ignore
|
||||
* @throws Exception ignore
|
||||
*/
|
||||
@PostMapping("Actions/Execute")
|
||||
@Operation(summary = "执行数据同步")
|
||||
@Parameters({
|
||||
@Parameter(name = "dbSyncForm", description = "页面参数", required = true)
|
||||
})
|
||||
@SaCheckPermission("systemData.dataSync")
|
||||
public ActionResult<String> execute(@RequestBody DbSyncForm dbSyncForm) {
|
||||
try{
|
||||
dbSyncService.execute(dbSyncForm.getDbConnectionFrom(), dbSyncForm.getDbConnectionTo(), dbSyncForm.getConvertRuleMap(), dbSyncForm.getDbTable());
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
return ActionResult.fail(MsgCode.SYS013.get(e.getMessage()));
|
||||
}
|
||||
return ActionResult.success(MsgCode.SU005.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量执行数据同步
|
||||
*
|
||||
* @param dbSyncForm 数据同步参数
|
||||
* @return ignore
|
||||
* @throws Exception ignore
|
||||
*/
|
||||
@PostMapping("Actions/batchExecute")
|
||||
@Operation(summary = "批量执行数据同步")
|
||||
@Parameters({
|
||||
@Parameter(name = "dbSyncForm", description = "页面参数", required = true)
|
||||
})
|
||||
@SaCheckPermission("systemData.dataSync")
|
||||
public ActionResult<Map<String, Integer>> executeBatch(@RequestBody DbSyncForm dbSyncForm) {
|
||||
Map<String, Integer> result = dbSyncService.executeBatch(dbSyncForm.getDbConnectionFrom(), dbSyncForm.getDbConnectionTo(), dbSyncForm.getConvertRuleMap(), dbSyncForm.getDbTableList());
|
||||
return ActionResult.success(MsgCode.SU005.get(), result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取数据类型默认转换规则
|
||||
* 一对一
|
||||
* @param fromDbType 被转换数据库类型
|
||||
* @param toDbType 转换数据库类型
|
||||
* @return 转换规则
|
||||
* @throws Exception 未找到数库
|
||||
*/
|
||||
@GetMapping("Actions/getDefaultRules")
|
||||
@SaCheckPermission("systemData.dataSync")
|
||||
@Operation(summary = "获取一对一数据类型默认转换规则")
|
||||
public static ActionResult<Map<String, String>> getDefaultRules(String fromDbType, String toDbType) throws Exception{
|
||||
Map<String, String> map = new LinkedHashMap<>();
|
||||
for (DtInterface dtInterface : DtInterface.getClz(fromDbType).getEnumConstants()) {
|
||||
DtInterface toFixCovert = DtSyncUtil.getToFixCovert(dtInterface, toDbType);
|
||||
if(toFixCovert != null){
|
||||
map.put(dtInterface.getDataType(), toFixCovert.getDataType());
|
||||
}
|
||||
}
|
||||
return ActionResult.success(map);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取数据类型转换规则
|
||||
* 一对多
|
||||
* @param fromDbType 被转换数据库类型
|
||||
* @param toDbType 转换数据库类型
|
||||
* @return 转换规则
|
||||
* @throws Exception 未找到数库
|
||||
*/
|
||||
@GetMapping("Actions/getConvertRules")
|
||||
@SaCheckPermission("systemData.dataSync")
|
||||
@Operation(summary = "获取一对多数据类型转换规则")
|
||||
public static ActionResult<Map<String, List<String>>> getConvertRules(String fromDbType, String toDbType) throws Exception{
|
||||
Map<String, List<String>> map = new LinkedHashMap<>();
|
||||
for (DtInterface dtInterface : DtInterface.getClz(fromDbType).getEnumConstants()) {
|
||||
List<String> list = new LinkedList<>();
|
||||
DtInterface[] allConverts = DtSyncUtil.getAllConverts(dtInterface, toDbType);
|
||||
if(allConverts != null){
|
||||
for (DtInterface allConvert : allConverts) {
|
||||
list.add(allConvert.getDataType());
|
||||
}
|
||||
map.put(dtInterface.getDataType(), list);
|
||||
}
|
||||
}
|
||||
return ActionResult.success(map);
|
||||
}
|
||||
|
||||
/* ===================================== SQL转换项目 ======================================= */
|
||||
|
||||
/**
|
||||
* 打印转换SQL
|
||||
*
|
||||
* @param form 参数表单
|
||||
*/
|
||||
@PostMapping("Actions/print")
|
||||
@Operation(summary = "打印同步表")
|
||||
public ActionResult<Object> print(@RequestBody DbSyncPrintForm form) throws Exception{
|
||||
PrintFunction func = ()-> dbSyncService.printDbInit(form.getDbLinkFrom(), form.getDbTypeTo(),
|
||||
form.getDbTableList(), form.getConvertRuleMap(), form.getPrintType());
|
||||
return ActionResult.success(printCommon(form, form.getPrintType(), func));
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface PrintFunction {
|
||||
Object execute() throws Exception;
|
||||
}
|
||||
|
||||
private Object printCommon(DbSyncPrintForm form, String printType, PrintFunction func) throws Exception {
|
||||
String filePath = XSSEscape.escapePath(form.getOutPath());
|
||||
sqlPrintHandler.start(filePath, true, true, true, form.getDbTypeTo());
|
||||
sqlPrintHandler.setFileName(form.getOutFileName());
|
||||
Object obj = func.execute();
|
||||
sqlPrintHandler.print();
|
||||
sqlPrintHandler.close();
|
||||
// SqlPrintHandler.openDirectory(new File(filePath).getPath());
|
||||
return obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据类型转换
|
||||
*
|
||||
* @param dataType 数据类型 例如:varchar(50)
|
||||
* @param fromDbEncode 源数据库类型
|
||||
* @param toDbEncode 目标数据库类型
|
||||
*/
|
||||
@GetMapping("getConvertDataType")
|
||||
@Operation(summary = "数据类型转换")
|
||||
public String getConvertDataType(String dataType, String dtLength, String fromDbEncode, String toDbEncode) throws Exception{
|
||||
DbFieldModel dbFieldModel = new DbFieldModel();
|
||||
dbFieldModel.setLength(dtLength);
|
||||
DtInterface toFixCovert = DtSyncUtil.getToFixCovert(DtInterface.newInstanceByDt(dataType, fromDbEncode), toDbEncode);
|
||||
dbFieldModel.setDataType(toFixCovert.getDataType());
|
||||
return dbFieldModel.formatDataTypeByView(toDbEncode);
|
||||
}
|
||||
|
||||
@PostMapping("formatOracleValue")
|
||||
@Operation(summary = "格式化SQL语句中的Oracle值")
|
||||
public String getConvertDataType(@RequestBody String data) throws Exception{
|
||||
Map<String, Object> json = JSONObject.parseObject(data).getInnerMap();
|
||||
// 指定F_Id为主键
|
||||
Map<String, Object> dataMap = JSONObject.parseObject(json.get("dataMap").toString()).getInnerMap();
|
||||
// 特殊处理:存在值超过2000的字符
|
||||
StringBuilder valStrBuilder = new StringBuilder();
|
||||
String context = FormatSqlOracle.clobExecute(DbOracle.ORACLE, json.get("valueStr"),
|
||||
json.get("table").toString(), json.get("column").toString(), dataMap, valStrBuilder).toString();
|
||||
return valStrBuilder.toString();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,471 @@
|
||||
package com.yunzhupaas.base.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.Valid;
|
||||
import com.yunzhupaas.base.ActionResult;
|
||||
import com.yunzhupaas.base.Page;
|
||||
import com.yunzhupaas.base.Pagination;
|
||||
import com.yunzhupaas.base.entity.PrintDevEntity;
|
||||
import com.yunzhupaas.base.model.dbtable.dto.DbTableFieldDTO;
|
||||
import com.yunzhupaas.base.model.dbtable.form.DbFieldForm;
|
||||
import com.yunzhupaas.base.model.dbtable.vo.DbFieldVO;
|
||||
import com.yunzhupaas.base.model.dbtable.vo.DbTableInfoVO;
|
||||
import com.yunzhupaas.base.model.dbtable.vo.DbTableListVO;
|
||||
import com.yunzhupaas.base.service.DbLinkService;
|
||||
import com.yunzhupaas.base.service.DbTableService;
|
||||
import com.yunzhupaas.base.vo.DownloadVO;
|
||||
import com.yunzhupaas.base.vo.ListVO;
|
||||
import com.yunzhupaas.base.vo.PageListVO;
|
||||
import com.yunzhupaas.base.vo.PaginationVO;
|
||||
import com.yunzhupaas.config.ConfigValueUtil;
|
||||
import com.yunzhupaas.constant.GenerateConstant;
|
||||
import com.yunzhupaas.constant.MsgCode;
|
||||
import com.yunzhupaas.database.datatype.model.DtModelDTO;
|
||||
import com.yunzhupaas.database.model.dbfield.DbFieldModel;
|
||||
import com.yunzhupaas.database.model.dbtable.DbTableFieldModel;
|
||||
import com.yunzhupaas.database.model.entity.DbLinkEntity;
|
||||
import com.yunzhupaas.database.model.page.DbTableDataForm;
|
||||
import com.yunzhupaas.database.sql.util.SqlFastUtil;
|
||||
import com.yunzhupaas.emnus.ModuleTypeEnum;
|
||||
import com.yunzhupaas.exception.DataException;
|
||||
import com.yunzhupaas.util.*;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.StringJoiner;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 数据建模
|
||||
* N:方法说明 - 微服务同步使用
|
||||
*
|
||||
* @author 云筑产品开发平台组
|
||||
* @version V3.1.0
|
||||
* @copyright 深圳市乐程软件有限公司
|
||||
* @date 2023/09/27
|
||||
*/
|
||||
@Tag(name = "数据建模", description = "DataModel")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/DataModel")
|
||||
@Slf4j
|
||||
public class DbTableController {
|
||||
|
||||
@Autowired
|
||||
private DbTableService dbTableService;
|
||||
@Autowired
|
||||
private FileExport fileExport;
|
||||
@Autowired
|
||||
private ConfigValueUtil configValueUtil;
|
||||
@Autowired
|
||||
private DbLinkService dblinkService;
|
||||
|
||||
/**
|
||||
* 1:列表
|
||||
*
|
||||
* @param id 连接id
|
||||
* @param pagination 关键词
|
||||
* @return 数据库表列表
|
||||
* @throws DataException ignore
|
||||
*/
|
||||
@Operation(summary = "获取数据库表列表")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "连接id", required = true)
|
||||
})
|
||||
@GetMapping("/{id}/Tables")
|
||||
public ActionResult<DbTableListVO<DbTableFieldModel>> getList(@PathVariable("id") String id, Pagination pagination) throws Exception {
|
||||
try {
|
||||
List<DbTableFieldModel> tableList = dbTableService.getListPage(XSSEscape.escape(id), pagination);
|
||||
return ActionResult.success(new DbTableListVO<>(tableList, JsonUtil.getJsonToBean(pagination, PaginationVO.class)));
|
||||
} catch (Exception e) {
|
||||
log.error("获取表列表失败", e);
|
||||
throw new DataException(MsgCode.DB302.get());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 1:列表
|
||||
*
|
||||
* @param id 连接id
|
||||
* @param page 关键字
|
||||
* @return 数据库表列表
|
||||
* @throws DataException ignore
|
||||
*/
|
||||
@Operation(summary = "获取数据库表列表")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "连接id", required = true)
|
||||
})
|
||||
@GetMapping("/{id}/TableAll")
|
||||
public ActionResult<ListVO<DbTableFieldModel>> getList(@PathVariable("id") String id, Page page) throws Exception {
|
||||
List<DbTableFieldModel> tableList = dbTableService.getListPage(XSSEscape.escape(id), page);
|
||||
ListVO<DbTableFieldModel> list = new ListVO<>();
|
||||
list.setList(tableList);
|
||||
return ActionResult.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 2:预览数据库表
|
||||
*
|
||||
* @param dbTableDataForm 查询条件
|
||||
* @param linkId 接Id
|
||||
* @param tableName 表名
|
||||
* @return 数据库表
|
||||
* @throws Exception ignore
|
||||
*/
|
||||
@Operation(summary = "预览数据库表")
|
||||
@Parameters({
|
||||
@Parameter(name = "linkId", description = "数据连接ID", required = true),
|
||||
@Parameter(name = "tableName", description = "表名", required = true)
|
||||
})
|
||||
@SaCheckPermission("systemData.dataModel")
|
||||
@GetMapping("/{linkId}/Table/{tableName}/Preview")
|
||||
public ActionResult<PageListVO<Map<String, Object>>> data(DbTableDataForm dbTableDataForm, @PathVariable("linkId") String linkId, @PathVariable("tableName") String tableName) throws Exception {
|
||||
String escape = XSSEscape.escape(linkId);
|
||||
String escapeTableName = XSSEscape.escape(tableName);
|
||||
List<Map<String, Object>> data = dbTableService.getData(dbTableDataForm, escape, escapeTableName);
|
||||
PaginationVO paginationVO = JsonUtilEx.getJsonToBeanEx(dbTableDataForm, PaginationVO.class);
|
||||
return ActionResult.page(JsonUtil.getJsonToListMap(JsonUtil.getObjectToStringAsDate(data)), paginationVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 3:列表
|
||||
*
|
||||
* @param linkId 数据连接ID
|
||||
* @param tableName 表名
|
||||
* @return 列表
|
||||
* @throws DataException ignore
|
||||
*/
|
||||
@GetMapping("/{linkId}/Tables/{tableName}/Fields/Selector")
|
||||
@Operation(summary = "获取数据库表字段下拉框列表")
|
||||
@Parameters({
|
||||
@Parameter(name = "linkId", description = "数据连接ID", required = true),
|
||||
@Parameter(name = "tableName", description = "表名", required = true)
|
||||
})
|
||||
public ActionResult<ListVO<DbFieldVO>> selectorList(@PathVariable("linkId") String linkId, @PathVariable("tableName") String tableName) throws Exception {
|
||||
List<DbFieldModel> data = dbTableService.getFieldList(linkId, tableName);
|
||||
List<DbFieldVO> vos = JsonUtil.getJsonToList(data, DbFieldVO.class);
|
||||
ListVO<DbFieldVO> vo = new ListVO<>();
|
||||
vo.setList(vos);
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 4:字段列表
|
||||
*
|
||||
* @param linkId 连接Id
|
||||
* @param tableName 表名
|
||||
* @param type 类型
|
||||
* @return 段列表
|
||||
* @throws DataException ignore
|
||||
*/
|
||||
@Operation(summary = "获取数据库表字段列表")
|
||||
@Parameters({
|
||||
@Parameter(name = "linkId", description = "数据连接ID", required = true),
|
||||
@Parameter(name = "tableName", description = "表名", required = true),
|
||||
@Parameter(name = "type", description = "类型")
|
||||
})
|
||||
@GetMapping("/{linkId}/Tables/{tableName}/Fields")
|
||||
public ActionResult<ListVO<DbFieldVO>> fieldList(@PathVariable("linkId") String linkId, @PathVariable("tableName") String tableName, String type) throws Exception {
|
||||
List<DbFieldModel> data;
|
||||
try {
|
||||
data = dbTableService.getFieldList(linkId, tableName);
|
||||
} catch (Exception e) {
|
||||
log.error("获取表字段列表失败", e);
|
||||
return ActionResult.fail(MsgCode.DB302.get());
|
||||
}
|
||||
if (CollectionUtils.isEmpty(data)) {
|
||||
return ActionResult.fail(MsgCode.DB018.get());
|
||||
}
|
||||
List<DbFieldVO> voList = data.stream().map(DbFieldVO::new).collect(Collectors.toList());
|
||||
//返回数据库原字段
|
||||
// for (DbFieldVO vo : voList) {
|
||||
// String columnName = vo.getField();
|
||||
// if ("1".equals(type)) {
|
||||
// String name = vo.getField().toLowerCase();
|
||||
// name = name.startsWith("f_")? name.substring(2) : name;
|
||||
// vo.setField(CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, name));
|
||||
// }
|
||||
// vo.setColumnName(columnName);
|
||||
// }
|
||||
ListVO<DbFieldVO> vo = new ListVO<>();
|
||||
vo.setList(voList);
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 5:编辑显示 - 表、字段信息
|
||||
*
|
||||
* @param dbLinkId 连接Id
|
||||
* @param tableName 表名
|
||||
* @return 表、字段信息
|
||||
* @throws DataException ignore
|
||||
*/
|
||||
@Operation(summary = "获取表及表字段信息")
|
||||
@Parameters({
|
||||
@Parameter(name = "dbLinkId", description = "数据连接ID", required = true),
|
||||
@Parameter(name = "tableName", description = "表名", required = true)
|
||||
})
|
||||
@SaCheckPermission("systemData.dataModel")
|
||||
@GetMapping("/{dbLinkId}/Table/{tableName}")
|
||||
public ActionResult<DbTableInfoVO> get(@PathVariable("dbLinkId") String dbLinkId, @PathVariable("tableName") String tableName) throws Exception {
|
||||
return ActionResult.success(new DbTableInfoVO(dbTableService.getTable(dbLinkId, tableName), dbTableService.getFieldList(dbLinkId, tableName)));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 验证表名字段名是否系统关键字
|
||||
*
|
||||
* @param dbTableFieldDTO
|
||||
* @return
|
||||
*/
|
||||
private static String checkName(DbTableFieldDTO dbTableFieldDTO, Integer index) {
|
||||
List<String> javaSql = new ArrayList<>();
|
||||
javaSql.addAll(GenerateConstant.JAVA_KEYWORD);
|
||||
javaSql.addAll(GenerateConstant.SQL_KEYWORD);
|
||||
if (javaSql.contains(dbTableFieldDTO.getTableInfo().getNewTable().toLowerCase())) {
|
||||
return "表名称" + dbTableFieldDTO.getTableInfo().getNewTable();
|
||||
}
|
||||
if (dbTableFieldDTO.getTableFieldList() != null && dbTableFieldDTO.getTableFieldList().size() > 0) {
|
||||
StringJoiner sj = new StringJoiner(",");
|
||||
for (int n = 0; n < dbTableFieldDTO.getTableFieldList().size(); n++) {
|
||||
DbFieldForm item = dbTableFieldDTO.getTableFieldList().get(n);
|
||||
if (javaSql.contains(item.getField().toLowerCase())) {
|
||||
// sj.add("第" + (index + n + 1) + "行列名" + item.getField());
|
||||
sj.add("列名" + item.getField());
|
||||
}
|
||||
}
|
||||
if (StringUtil.isNotEmpty(sj.toString())) {
|
||||
return sj.toString();
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* 6:新建表
|
||||
*
|
||||
* @param linkId 连接Id
|
||||
* @return 执行结果
|
||||
* @throws DataException ignore
|
||||
*/
|
||||
@Operation(summary = "新建")
|
||||
@Parameters({
|
||||
@Parameter(name = "linkId", description = "数据连接ID", required = true),
|
||||
@Parameter(name = "dbTableFieldDTO", description = "建表参数对象", required = true)
|
||||
})
|
||||
@SaCheckPermission("systemData.dataModel")
|
||||
@PostMapping("{linkId}/Table")
|
||||
public ActionResult<String> create(@PathVariable("linkId") String linkId, @RequestBody @Valid DbTableFieldDTO dbTableFieldDTO) throws Exception {
|
||||
try {
|
||||
String err = this.checkName(dbTableFieldDTO, 0);
|
||||
if (StringUtil.isNotEmpty(err)) {
|
||||
return ActionResult.fail(MsgCode.SYS128.get(err));
|
||||
}
|
||||
int status = dbTableService.createTable(dbTableFieldDTO.getCreDbTableModel(linkId));
|
||||
if (status == 1) {
|
||||
return ActionResult.success(MsgCode.SU001.get());
|
||||
} else if (status == 0) {
|
||||
return ActionResult.fail(MsgCode.EXIST001.get());
|
||||
} else {
|
||||
return ActionResult.fail(MsgCode.DB019.get());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return ActionResult.fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 7:更新
|
||||
*
|
||||
* @param linkId 连接Id
|
||||
* @return 执行结果
|
||||
* @throws DataException ignore
|
||||
*/
|
||||
@Operation(summary = "更新")
|
||||
@Parameters({
|
||||
@Parameter(name = "linkId", description = "数据连接ID", required = true),
|
||||
@Parameter(name = "dbTableFieldDTO", description = "建表参数对象", required = true)
|
||||
})
|
||||
@SaCheckPermission("systemData.dataModel")
|
||||
@PutMapping("/{linkId}/Table")
|
||||
public ActionResult<String> update(@PathVariable("linkId") String linkId, @RequestBody @Valid DbTableFieldDTO dbTableFieldDTO) throws Exception {
|
||||
String err = this.checkName(dbTableFieldDTO, 0);
|
||||
if (StringUtil.isNotEmpty(err)) {
|
||||
return ActionResult.fail(MsgCode.SYS128.get(err));
|
||||
}
|
||||
DbTableFieldModel dbTableModel = dbTableFieldDTO.getUpDbTableModel(linkId);
|
||||
// 当修改表名时,验证是否与其他表名重名
|
||||
if (!dbTableModel.getUpdateNewTable().equals(dbTableModel.getUpdateOldTable())) {
|
||||
if (dbTableService.isExistTable(linkId, dbTableModel.getUpdateNewTable())) {
|
||||
return ActionResult.fail(MsgCode.EXIST001.get());
|
||||
}
|
||||
}
|
||||
try {
|
||||
dbTableService.update(dbTableModel);
|
||||
return ActionResult.success(MsgCode.SU004.get());
|
||||
} catch (Exception e) {
|
||||
return ActionResult.fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 8:更新
|
||||
*
|
||||
* @param linkId 连接Id
|
||||
* @return 执行结果
|
||||
* @throws DataException ignore
|
||||
*/
|
||||
@Operation(summary = "添加字段")
|
||||
@Parameters({
|
||||
@Parameter(name = "linkId", description = "数据连接ID", required = true),
|
||||
@Parameter(name = "dbTableFieldDTO", description = "建表参数对象", required = true)
|
||||
})
|
||||
@SaCheckPermission("systemData.dataModel")
|
||||
@PutMapping("/{linkId}/addFields")
|
||||
public ActionResult<String> addField(@PathVariable("linkId") String linkId, @RequestBody @Valid DbTableFieldDTO dbTableFieldDTO) throws Exception {
|
||||
int size = 0;
|
||||
// try {
|
||||
// DbLinkEntity dbLinkEntity = dblinkService.getResource(linkId);
|
||||
// List<DbFieldModel> fieldList = SqlFastUtil.getFieldList(dbLinkEntity, dbTableFieldDTO.getTableInfo().getTable());
|
||||
// size = fieldList.size();
|
||||
// } catch (Exception e) {
|
||||
// }
|
||||
|
||||
String err = this.checkName(dbTableFieldDTO, size);
|
||||
if (StringUtil.isNotEmpty(err)) {
|
||||
return ActionResult.fail(MsgCode.SYS128.get(err));
|
||||
}
|
||||
DbTableFieldModel dbTableModel = dbTableFieldDTO.getUpDbTableModel(linkId);
|
||||
dbTableService.addField(dbTableModel);
|
||||
return ActionResult.success(MsgCode.SU004.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 9:删除
|
||||
*
|
||||
* @param linkId 连接Id
|
||||
* @param tableName 表名
|
||||
* @return 执行结果
|
||||
* @throws DataException ignore
|
||||
*/
|
||||
@Operation(summary = "删除")
|
||||
@Parameters({
|
||||
@Parameter(name = "linkId", description = "数据连接ID", required = true),
|
||||
@Parameter(name = "tableName", description = "表名", required = true)
|
||||
})
|
||||
@SaCheckPermission("systemData.dataModel")
|
||||
@DeleteMapping("/{linkId}/Table/{tableName}")
|
||||
public ActionResult<String> delete(@PathVariable("linkId") String linkId, @PathVariable("tableName") String tableName) throws Exception {
|
||||
dbTableService.delete(linkId, tableName);
|
||||
return ActionResult.success(MsgCode.SU003.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除全部表(慎用)
|
||||
*
|
||||
* @param linkId 连接Id
|
||||
* @return 执行结果
|
||||
* @throws DataException ignore
|
||||
*/
|
||||
@Operation(summary = "删除全部表")
|
||||
@Parameters({
|
||||
@Parameter(name = "linkId", description = "数据连接ID", required = true),
|
||||
})
|
||||
@SaCheckPermission("systemData.dataModel")
|
||||
@DeleteMapping("/{linkId}/deleteAllTable")
|
||||
public ActionResult<String> deleteAllTable(@PathVariable("linkId") String linkId, String dbType) throws Exception {
|
||||
dbTableService.deleteAllTable(linkId, dbType);
|
||||
return ActionResult.success(MsgCode.SU003.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 10:导入
|
||||
*
|
||||
* @param linkId 连接id
|
||||
* @param multipartFile 文件
|
||||
* @return 执行结果
|
||||
* @throws DataException ignore
|
||||
*/
|
||||
@Operation(summary = "导入")
|
||||
@Parameters({
|
||||
@Parameter(name = "linkId", description = "数据连接ID", required = true),
|
||||
})
|
||||
@SaCheckPermission("systemData.dataModel")
|
||||
@PostMapping(value = "/{linkId}/Actions/Import", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
public ActionResult<PageListVO<PrintDevEntity>> importData(@PathVariable String linkId, @RequestPart("file") MultipartFile multipartFile) throws Exception {
|
||||
//判断是否为.json结尾
|
||||
if (FileUtil.existsSuffix(multipartFile, ModuleTypeEnum.SYSTEM_DBTABLE.getTableName())) {
|
||||
return ActionResult.fail(MsgCode.IMP002.get());
|
||||
}
|
||||
// 读取文件内容
|
||||
String fileContent = FileUtil.getFileContent(multipartFile);
|
||||
DbTableFieldModel dbTableFieldModel = JSONObject.parseObject(fileContent, DbTableFieldModel.class);
|
||||
|
||||
// 数据类型长度解析(enum枚举无法Json化)
|
||||
for (DbFieldModel dbFieldModel : dbTableFieldModel.getDbFieldModelList()) {
|
||||
String formatDataType = dbFieldModel.getLength();
|
||||
String dataType = "";
|
||||
String dtLength = "";
|
||||
if (formatDataType.contains("(")) {
|
||||
Matcher matcher = Pattern.compile("(.+)\\((.*)\\)").matcher(formatDataType);
|
||||
if (matcher.find()) {
|
||||
dataType = matcher.group(1).trim();
|
||||
dtLength = matcher.group(2).trim();
|
||||
}
|
||||
} else {
|
||||
dataType = formatDataType.trim();
|
||||
}
|
||||
dbFieldModel.setDtModelDTO(new DtModelDTO(dataType, dtLength, dbTableFieldModel.getDbEncode(), false)
|
||||
.setConvertType(DtModelDTO.DB_VAL));
|
||||
}
|
||||
|
||||
dbTableFieldModel.setDbLinkId(linkId);
|
||||
int i = dbTableService.createTable(dbTableFieldModel);
|
||||
if (i == 1) {
|
||||
return ActionResult.success(MsgCode.IMP001.get());
|
||||
} else {
|
||||
return ActionResult.fail(MsgCode.DB007.get());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 11:导出
|
||||
*
|
||||
* @param tableName 表明
|
||||
* @param linkId 连接id
|
||||
* @return 执行结果
|
||||
*/
|
||||
@Operation(summary = "导出")
|
||||
@Parameters({
|
||||
@Parameter(name = "tableName", description = "表明", required = true),
|
||||
@Parameter(name = "linkId", description = "连接id", required = true)
|
||||
})
|
||||
@SaCheckPermission("systemData.dataModel")
|
||||
@GetMapping("/{linkId}/Table/{tableName}/Actions/Export")
|
||||
public ActionResult<DownloadVO> export(@PathVariable String tableName, @PathVariable String linkId) throws Exception {
|
||||
DbTableFieldModel dbTable = dbTableService.getDbTableModel(linkId, tableName);
|
||||
dbTable.getDbFieldModelList().forEach(dbField -> {
|
||||
dbField.setLength(dbField.getDtModelDTO().convert().formatDataType());
|
||||
dbField.setDtModelDTO(null);
|
||||
});
|
||||
//导出文件
|
||||
DownloadVO downloadVO = fileExport.exportFile(dbTable, configValueUtil.getTemporaryFilePath(),
|
||||
dbTable.getTable() + "_", ModuleTypeEnum.SYSTEM_DBTABLE.getTableName());
|
||||
return ActionResult.success(downloadVO);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,441 @@
|
||||
package com.yunzhupaas.base.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import com.yunzhupaas.base.ActionResult;
|
||||
import com.yunzhupaas.base.model.dictionarytype.DictionaryExportModel;
|
||||
import com.yunzhupaas.base.service.DictionaryDataService;
|
||||
import com.yunzhupaas.base.service.DictionaryTypeService;
|
||||
import com.yunzhupaas.base.vo.DownloadVO;
|
||||
import com.yunzhupaas.base.vo.ListVO;
|
||||
import com.yunzhupaas.base.entity.DictionaryDataEntity;
|
||||
import com.yunzhupaas.base.entity.DictionaryTypeEntity;
|
||||
import com.yunzhupaas.config.ConfigValueUtil;
|
||||
import com.yunzhupaas.constant.MsgCode;
|
||||
import com.yunzhupaas.exception.DataException;
|
||||
import com.yunzhupaas.base.model.dictionarydata.*;
|
||||
import com.yunzhupaas.base.model.dictionarytype.DictionaryTypeSelectModel;
|
||||
import com.yunzhupaas.base.model.dictionarytype.DictionaryTypeSelectVO;
|
||||
import com.yunzhupaas.util.FileUtil;
|
||||
import com.yunzhupaas.util.JsonUtil;
|
||||
import com.yunzhupaas.util.JsonUtilEx;
|
||||
import com.yunzhupaas.util.StringUtil;
|
||||
import com.yunzhupaas.emnus.ModuleTypeEnum;
|
||||
import com.yunzhupaas.util.treeutil.ListToTreeUtil;
|
||||
import com.yunzhupaas.util.treeutil.SumTree;
|
||||
import com.yunzhupaas.util.treeutil.newtreeutil.TreeDotUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 字典数据
|
||||
*
|
||||
* @author 云筑产品开发平台组
|
||||
* @version V3.1.0
|
||||
* @copyright 深圳市乐程软件有限公司
|
||||
* @date 2023/09/27
|
||||
*/
|
||||
@Tag(name = "数据字典", description = "DictionaryData")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/DictionaryData")
|
||||
public class DictionaryDataController extends SuperController<DictionaryDataService, DictionaryDataEntity> {
|
||||
|
||||
@Autowired
|
||||
private DictionaryDataService dictionaryDataService;
|
||||
@Autowired
|
||||
private DictionaryTypeService dictionaryTypeService;
|
||||
@Autowired
|
||||
private ConfigValueUtil configValueUtil;
|
||||
|
||||
/**
|
||||
* 获取数据字典列表
|
||||
*
|
||||
* @param dictionaryTypeId 数据字典id
|
||||
* @param pageDictionaryData 分页参数
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "获取数据字典列表")
|
||||
@Parameters({
|
||||
@Parameter(name = "dictionaryTypeId", description = "数据分类id", required = true)
|
||||
})
|
||||
@GetMapping("/{dictionaryTypeId}")
|
||||
public ActionResult bindDictionary(@PathVariable("dictionaryTypeId") String dictionaryTypeId, PageDictionaryData pageDictionaryData) {
|
||||
List<DictionaryDataEntity> data = dictionaryDataService.getList(dictionaryTypeId);
|
||||
List<DictionaryDataEntity> dataAll = data;
|
||||
if (StringUtil.isNotEmpty(pageDictionaryData.getKeyword())) {
|
||||
data = data.stream().filter(t -> t.getFullName().contains(pageDictionaryData.getKeyword()) || t.getEnCode().contains(pageDictionaryData.getKeyword())).collect(Collectors.toList());
|
||||
}
|
||||
if (pageDictionaryData.getIsTree() != null && "1".equals(pageDictionaryData.getIsTree())) {
|
||||
List<DictionaryDataEntity> treeData = JsonUtil.getJsonToList(ListToTreeUtil.treeWhere(data, dataAll), DictionaryDataEntity.class);
|
||||
List<DictionaryDataModel> voListVO = JsonUtil.getJsonToList(treeData, DictionaryDataModel.class);
|
||||
List<SumTree<DictionaryDataModel>> sumTrees = TreeDotUtils.convertListToTreeDot(voListVO);
|
||||
List<DictionaryDataListVO> list = JsonUtil.getJsonToList(sumTrees, DictionaryDataListVO.class);
|
||||
ListVO<DictionaryDataListVO> treeVo = new ListVO<>();
|
||||
treeVo.setList(list);
|
||||
return ActionResult.success(treeVo);
|
||||
}
|
||||
List<DictionaryDataModel> voListVO = JsonUtil.getJsonToList(data, DictionaryDataModel.class);
|
||||
ListVO<DictionaryDataModel> treeVo = new ListVO<>();
|
||||
treeVo.setList(voListVO);
|
||||
return ActionResult.success(treeVo);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取数据字典列表
|
||||
*
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "获取数据字典列表(分类+内容)")
|
||||
@GetMapping("/All")
|
||||
public ActionResult<ListVO<Map<String, Object>>> allBindDictionary() {
|
||||
List<DictionaryTypeEntity> dictionaryTypeList = dictionaryTypeService.getList();
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
for (DictionaryTypeEntity dictionaryTypeEntity : dictionaryTypeList) {
|
||||
List<DictionaryDataEntity> childNodeList = dictionaryDataService.getList(dictionaryTypeEntity.getId(), true);
|
||||
if (dictionaryTypeEntity.getIsTree().compareTo(1) == 0) {
|
||||
List<Map<String, Object>> selectList = new ArrayList<>();
|
||||
for (DictionaryDataEntity item : childNodeList) {
|
||||
Map<String, Object> ht = new HashMap<>(16);
|
||||
ht.put("fullName", item.getFullName());
|
||||
ht.put("enCode", item.getEnCode());
|
||||
ht.put("id", item.getId());
|
||||
ht.put("parentId", item.getParentId());
|
||||
selectList.add(ht);
|
||||
}
|
||||
List<DictionaryDataAllModel> jsonToList = JsonUtil.getJsonToList(selectList, DictionaryDataAllModel.class);
|
||||
//==============转换树
|
||||
List<SumTree<DictionaryDataAllModel>> list1 = TreeDotUtils.convertListToTreeDot(jsonToList);
|
||||
List<DictionaryDataAllVO> list2 = JsonUtil.getJsonToList(list1, DictionaryDataAllVO.class);
|
||||
//==============
|
||||
Map<String, Object> htItem = new HashMap<>(16);
|
||||
htItem.put("id", dictionaryTypeEntity.getId());
|
||||
htItem.put("enCode", dictionaryTypeEntity.getEnCode());
|
||||
htItem.put("dictionaryList", list2);
|
||||
htItem.put("isTree", 1);
|
||||
list.add(htItem);
|
||||
} else {
|
||||
List<Map<String, Object>> selectList = new ArrayList<>();
|
||||
for (DictionaryDataEntity item : childNodeList) {
|
||||
Map<String, Object> ht = new HashMap<>(16);
|
||||
ht.put("enCode", item.getEnCode());
|
||||
ht.put("id", item.getId());
|
||||
ht.put("fullName", item.getFullName());
|
||||
selectList.add(ht);
|
||||
}
|
||||
Map<String, Object> htItem = new HashMap<>(16);
|
||||
htItem.put("id", dictionaryTypeEntity.getId());
|
||||
htItem.put("enCode", dictionaryTypeEntity.getEnCode());
|
||||
htItem.put("dictionaryList", selectList);
|
||||
htItem.put("isTree", 0);
|
||||
list.add(htItem);
|
||||
}
|
||||
}
|
||||
ListVO<Map<String, Object>> vo = new ListVO<>();
|
||||
vo.setList(list);
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取数据字典下拉框数据
|
||||
*
|
||||
* @param dictionaryTypeId 类别主键
|
||||
* @param isTree 是否为树
|
||||
* @param id 主键
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "获取数据字典分类下拉框数据")
|
||||
@Parameters({
|
||||
@Parameter(name = "dictionaryTypeId", description = "数据分类id", required = true),
|
||||
@Parameter(name = "isTree", description = "是否树形"),
|
||||
@Parameter(name = "id", description = "主键", required = true)
|
||||
})
|
||||
@GetMapping("{dictionaryTypeId}/Selector/{id}")
|
||||
public ActionResult<ListVO<DictionaryDataSelectVO>> treeView(@PathVariable("dictionaryTypeId") String dictionaryTypeId, String isTree, @PathVariable("id") String id) {
|
||||
DictionaryTypeEntity typeEntity = dictionaryTypeService.getInfo(dictionaryTypeId);
|
||||
List<DictionaryDataModel> treeList = new ArrayList<>();
|
||||
DictionaryDataModel treeViewModel = new DictionaryDataModel();
|
||||
treeViewModel.setId("0");
|
||||
treeViewModel.setFullName(typeEntity.getFullName());
|
||||
treeViewModel.setParentId("-1");
|
||||
treeViewModel.setIcon("fa fa-tags");
|
||||
treeList.add(treeViewModel);
|
||||
if ("1".equals(isTree)) {
|
||||
List<DictionaryDataEntity> data = dictionaryDataService.getList(dictionaryTypeId).stream().filter(t -> "1".equals(String.valueOf(t.getEnabledMark()))).collect(Collectors.toList());
|
||||
//过滤子集
|
||||
if (!"0".equals(id)) {
|
||||
data.remove(dictionaryDataService.getInfo(id));
|
||||
}
|
||||
for (DictionaryDataEntity entity : data) {
|
||||
DictionaryDataModel treeModel = new DictionaryDataModel();
|
||||
treeModel.setId(entity.getId());
|
||||
treeModel.setFullName(entity.getFullName());
|
||||
treeModel.setParentId("-1".equals(entity.getParentId()) ? entity.getDictionaryTypeId() : entity.getParentId());
|
||||
treeList.add(treeModel);
|
||||
}
|
||||
}
|
||||
List<SumTree<DictionaryDataModel>> sumTrees = TreeDotUtils.convertListToTreeDotFilter(treeList);
|
||||
List<DictionaryDataSelectVO> list = JsonUtil.getJsonToList(sumTrees, DictionaryDataSelectVO.class);
|
||||
ListVO<DictionaryDataSelectVO> treeVo = new ListVO<>();
|
||||
treeVo.setList(list);
|
||||
return ActionResult.success(treeVo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取字典分类
|
||||
*
|
||||
* @param dictionaryTypeId 分类id、分类编码
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "获取某个字典数据下拉框列表")
|
||||
@Parameters({
|
||||
@Parameter(name = "dictionaryTypeId", description = "数据分类id", required = true)
|
||||
})
|
||||
@GetMapping("/{dictionaryTypeId}/Data/Selector")
|
||||
public ActionResult<ListVO<DictionaryTypeSelectVO>> selectorOneTreeView(@PathVariable("dictionaryTypeId") String dictionaryTypeId) {
|
||||
List<DictionaryDataEntity> data = dictionaryDataService.getList(dictionaryTypeId, true);
|
||||
if(data.isEmpty()){
|
||||
DictionaryTypeEntity typeEntity = dictionaryTypeService.getInfoByEnCode(dictionaryTypeId);
|
||||
if(typeEntity != null){
|
||||
data = dictionaryDataService.getList(typeEntity.getId(), true);
|
||||
}
|
||||
|
||||
}
|
||||
List<DictionaryTypeSelectModel> voListVO = JsonUtil.getJsonToList(data, DictionaryTypeSelectModel.class);
|
||||
List<SumTree<DictionaryTypeSelectModel>> sumTrees = TreeDotUtils.convertListToTreeDot(voListVO);
|
||||
List<DictionaryTypeSelectVO> list = JsonUtil.getJsonToList(sumTrees, DictionaryTypeSelectVO.class);
|
||||
ListVO<DictionaryTypeSelectVO> vo = new ListVO<>();
|
||||
vo.setList(list);
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取数据字典信息
|
||||
*
|
||||
* @param id 主键
|
||||
* @return ignore
|
||||
* @throws DataException ignore
|
||||
*/
|
||||
@Operation(summary = "获取数据字典信息")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键值", required = true)
|
||||
})
|
||||
@GetMapping("/{id}/Info")
|
||||
public ActionResult<DictionaryDataInfoVO> info(@PathVariable("id") String id) throws DataException {
|
||||
DictionaryDataEntity entity = dictionaryDataService.getInfo(id);
|
||||
DictionaryDataInfoVO vo = JsonUtilEx.getJsonToBeanEx(entity, DictionaryDataInfoVO.class);
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 重复验证(名称)
|
||||
*
|
||||
* @param dictionaryTypeId 类别主键
|
||||
* @param fullName 名称
|
||||
* @param id 主键值
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "(待定)重复验证(名称)")
|
||||
@GetMapping("/IsExistByFullName")
|
||||
public ActionResult isExistByFullName(String dictionaryTypeId, String fullName, String id) {
|
||||
boolean data = dictionaryDataService.isExistByFullName(dictionaryTypeId, fullName, id);
|
||||
return ActionResult.success(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 重复验证(编码)
|
||||
*
|
||||
* @param dictionaryTypeId 类别主键
|
||||
* @param enCode 编码
|
||||
* @param id 主键值
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "(待定)重复验证(编码)")
|
||||
@GetMapping("/IsExistByEnCode")
|
||||
public ActionResult isExistByEnCode(String dictionaryTypeId, String enCode, String id) {
|
||||
boolean data = dictionaryDataService.isExistByEnCode(dictionaryTypeId, enCode, id);
|
||||
return ActionResult.success(data);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 添加数据字典
|
||||
*
|
||||
* @param dictionaryDataCrForm 实体对象
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "添加数据字典")
|
||||
@Parameters({
|
||||
@Parameter(name = "dictionaryDataCrForm", description = "实体对象", required = true)
|
||||
})
|
||||
@SaCheckPermission("systemData.dictionary")
|
||||
@PostMapping
|
||||
public ActionResult create(@RequestBody @Valid DictionaryDataCrForm dictionaryDataCrForm) {
|
||||
DictionaryDataEntity entity = JsonUtil.getJsonToBean(dictionaryDataCrForm, DictionaryDataEntity.class);
|
||||
if (dictionaryDataService.isExistByFullName(entity.getDictionaryTypeId(), entity.getFullName(), entity.getId())) {
|
||||
return ActionResult.fail(MsgCode.EXIST001.get());
|
||||
}
|
||||
if (dictionaryDataService.isExistByEnCode(entity.getDictionaryTypeId(), entity.getEnCode(), entity.getId())) {
|
||||
return ActionResult.fail(MsgCode.EXIST002.get());
|
||||
}
|
||||
dictionaryDataService.create(entity);
|
||||
return ActionResult.success(MsgCode.SU001.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改数据字典
|
||||
*
|
||||
* @param id 主键值
|
||||
* @param dictionaryDataUpForm 实体对象
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "修改数据字典")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键值", required = true),
|
||||
@Parameter(name = "dictionaryDataUpForm", description = "实体对象", required = true)
|
||||
})
|
||||
@SaCheckPermission("systemData.dictionary")
|
||||
@PutMapping("/{id}")
|
||||
public ActionResult update(@PathVariable("id") String id, @RequestBody @Valid DictionaryDataUpForm dictionaryDataUpForm) {
|
||||
DictionaryDataEntity entity = JsonUtil.getJsonToBean(dictionaryDataUpForm, DictionaryDataEntity.class);
|
||||
if (dictionaryDataService.isExistByFullName(entity.getDictionaryTypeId(), entity.getFullName(), id)) {
|
||||
return ActionResult.fail(MsgCode.EXIST001.get());
|
||||
}
|
||||
if (dictionaryDataService.isExistByEnCode(entity.getDictionaryTypeId(), entity.getEnCode(), id)) {
|
||||
return ActionResult.fail(MsgCode.EXIST002.get());
|
||||
}
|
||||
boolean flag = dictionaryDataService.update(id, entity);
|
||||
if (!flag) {
|
||||
return ActionResult.fail(MsgCode.FA002.get());
|
||||
}
|
||||
return ActionResult.success(MsgCode.SU004.get());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除数据字典
|
||||
*
|
||||
* @param id 主键值
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "删除数据字典")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键值", required = true)
|
||||
})
|
||||
@SaCheckPermission("systemData.dictionary")
|
||||
@DeleteMapping("/{id}")
|
||||
public ActionResult delete(@PathVariable("id") String id) {
|
||||
DictionaryDataEntity entity = dictionaryDataService.getInfo(id);
|
||||
if (entity != null) {
|
||||
if (dictionaryDataService.isExistSubset(entity.getId())) {
|
||||
return ActionResult.fail(MsgCode.SYS014.get());
|
||||
}
|
||||
dictionaryDataService.delete(entity);
|
||||
return ActionResult.success(MsgCode.SU003.get());
|
||||
}
|
||||
return ActionResult.fail(MsgCode.FA003.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新字典状态
|
||||
*
|
||||
* @param id 主键值
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "更新字典状态")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键值", required = true)
|
||||
})
|
||||
@SaCheckPermission("systemData.dictionary")
|
||||
@PutMapping("/{id}/Actions/State")
|
||||
public ActionResult update(@PathVariable("id") String id) {
|
||||
DictionaryDataEntity entity = dictionaryDataService.getInfo(id);
|
||||
if (entity != null) {
|
||||
if ("1".equals(String.valueOf(entity.getEnabledMark()))) {
|
||||
entity.setEnabledMark(0);
|
||||
} else {
|
||||
entity.setEnabledMark(1);
|
||||
}
|
||||
boolean flag = dictionaryDataService.update(entity.getId(), entity);
|
||||
if (!flag) {
|
||||
return ActionResult.success(MsgCode.FA002.get());
|
||||
}
|
||||
}
|
||||
return ActionResult.success(MsgCode.SU004.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据字典导出功能
|
||||
*
|
||||
* @param id 接口id
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "导出数据字典数据")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键值", required = true)
|
||||
})
|
||||
@SaCheckPermission("systemData.dictionary")
|
||||
@GetMapping("/{id}/Actions/Export")
|
||||
public ActionResult exportFile(@PathVariable("id") String id) {
|
||||
DownloadVO downloadVO = dictionaryDataService.exportData(id);
|
||||
return ActionResult.success(downloadVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据字典导入功能
|
||||
*
|
||||
* @param multipartFile 文件
|
||||
* @return ignore
|
||||
* @throws DataException ignore
|
||||
*/
|
||||
@Operation(summary = "数据字典导入功能")
|
||||
@SaCheckPermission("systemData.dictionary")
|
||||
@PostMapping(value = "/Actions/Import", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
public ActionResult importFile(@RequestPart("file") MultipartFile multipartFile,
|
||||
@RequestParam("type") Integer type) throws DataException {
|
||||
//判断是否为.json结尾
|
||||
if (FileUtil.existsSuffix(multipartFile, ModuleTypeEnum.SYSTEM_DICTIONARYDATA.getTableName())) {
|
||||
return ActionResult.fail(MsgCode.IMP002.get());
|
||||
}
|
||||
try {
|
||||
//获取文件内容
|
||||
String fileContent = FileUtil.getFileContent(multipartFile);
|
||||
DictionaryExportModel exportModel = JsonUtil.getJsonToBean(fileContent, DictionaryExportModel.class);
|
||||
List<DictionaryTypeEntity> list = exportModel.getList();
|
||||
//父级分类id不存在的话,直接抛出异常
|
||||
//如果分类只有一个
|
||||
if (list.size() == 1 && !"-1".equals(list.get(0).getParentId()) && dictionaryTypeService.getInfo(list.get(0).getParentId()) == null) {
|
||||
return ActionResult.fail(MsgCode.IMP010.get());
|
||||
}
|
||||
//如果有多个需要验证分类是否存在
|
||||
if (list.stream().filter(t -> "-1".equals(t.getParentId())).count() < 1) {
|
||||
boolean exist = false;
|
||||
for (DictionaryTypeEntity dictionaryTypeEntity : list) {
|
||||
//判断父级是否存在
|
||||
if (dictionaryTypeService.getInfo(dictionaryTypeEntity.getParentId()) != null) {
|
||||
exist = true;
|
||||
}
|
||||
}
|
||||
if (!exist) {
|
||||
return ActionResult.fail(MsgCode.IMP010.get());
|
||||
}
|
||||
}
|
||||
//判断数据是否存在
|
||||
return dictionaryDataService.importData(exportModel, type);
|
||||
} catch (Exception e) {
|
||||
throw new DataException(MsgCode.IMP004.get());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,266 @@
|
||||
package com.yunzhupaas.base.controller;
|
||||
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import com.yunzhupaas.base.Page;
|
||||
import com.yunzhupaas.base.controller.SuperController;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import com.yunzhupaas.constant.MsgCode;
|
||||
import com.yunzhupaas.exception.DataException;
|
||||
import com.yunzhupaas.util.JsonUtil;
|
||||
import com.yunzhupaas.base.ActionResult;
|
||||
import com.yunzhupaas.base.vo.ListVO;
|
||||
import com.yunzhupaas.base.model.dictionarytype.*;
|
||||
import com.yunzhupaas.base.entity.DictionaryTypeEntity;
|
||||
import com.yunzhupaas.base.service.DictionaryTypeService;
|
||||
import com.yunzhupaas.util.RandomUtil;
|
||||
import com.yunzhupaas.util.StringUtil;
|
||||
import com.yunzhupaas.util.treeutil.SumTree;
|
||||
import com.yunzhupaas.util.treeutil.TreeDotUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 字典分类
|
||||
*
|
||||
* @author 云筑产品开发平台组
|
||||
* @version V3.1.0
|
||||
* @copyright 深圳市乐程软件有限公司(http://www.szlecheng.cn)
|
||||
* @date 2023/09/27
|
||||
*/
|
||||
@Tag(name = "数据字典分类", description = "DictionaryType")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/DictionaryType")
|
||||
public class DictionaryTypeController extends SuperController<DictionaryTypeService, DictionaryTypeEntity> {
|
||||
|
||||
@Autowired
|
||||
private DictionaryTypeService dictionaryTypeService;
|
||||
|
||||
/**
|
||||
* 获取字典分类
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "获取字典分类")
|
||||
@GetMapping
|
||||
public ActionResult<ListVO<DictionaryTypeListVO>> list() {
|
||||
List<DictionaryTypeEntity> data = dictionaryTypeService.getList();
|
||||
List<DictionaryTypeModel> voListVO = JsonUtil.getJsonToList(data, DictionaryTypeModel.class);
|
||||
voListVO.forEach(vo -> {
|
||||
if (StringUtil.isNotEmpty(vo.getCategory()) && "1".equals(vo.getCategory()) && "-1".equals(vo.getParentId())) {
|
||||
vo.setCategory("系统");
|
||||
vo.setParentId("1");
|
||||
} else if (StringUtil.isNotEmpty(vo.getCategory()) && "0".equals(vo.getCategory()) && "-1".equals(vo.getParentId())) {
|
||||
vo.setCategory("业务");
|
||||
vo.setParentId("0");
|
||||
}
|
||||
});
|
||||
List<SumTree<DictionaryTypeModel>> sumTrees = TreeDotUtils.convertListToTreeDot(voListVO);
|
||||
List<DictionaryTypeListVO> list = JsonUtil.getJsonToList(sumTrees, DictionaryTypeListVO.class);
|
||||
|
||||
DictionaryTypeListVO parentVO = new DictionaryTypeListVO();
|
||||
parentVO.setFullName("系统字典");
|
||||
parentVO.setChildren(new ArrayList<>());
|
||||
parentVO.setId("1");
|
||||
DictionaryTypeListVO parentVO1 = new DictionaryTypeListVO();
|
||||
parentVO1.setFullName("业务字典");
|
||||
parentVO1.setChildren(new ArrayList<>());
|
||||
parentVO1.setId("0");
|
||||
|
||||
list.forEach(vo -> {
|
||||
if ("系统".equals(vo.getCategory())) {
|
||||
List<DictionaryTypeListVO> children = parentVO.getChildren();
|
||||
children.add(vo);
|
||||
parentVO.setHasChildren(true);
|
||||
}else {
|
||||
List<DictionaryTypeListVO> children = parentVO1.getChildren();
|
||||
children.add(vo);
|
||||
parentVO1.setHasChildren(true);
|
||||
}
|
||||
});
|
||||
List<DictionaryTypeListVO> listVo = new ArrayList<>();
|
||||
listVo.add(parentVO1);
|
||||
listVo.add(parentVO);
|
||||
|
||||
ListVO<DictionaryTypeListVO> vo = new ListVO<>();
|
||||
vo.setList(listVo);
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取字典分类
|
||||
*
|
||||
* @param id 主键
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "获取所有字典分类下拉框列表")
|
||||
@Parameter(name = "id", description = "主键", required = true)
|
||||
@GetMapping("/Selector/{id}")
|
||||
public ActionResult<ListVO<DictionaryTypeListVO>> selectorTreeView(@PathVariable("id") String id) {
|
||||
List<DictionaryTypeEntity> data = dictionaryTypeService.getList();
|
||||
if (!"0".equals(id)) {
|
||||
data.remove(dictionaryTypeService.getInfo(id));
|
||||
}
|
||||
List<DictionaryTypeModel> voListVO = JsonUtil.getJsonToList(data, DictionaryTypeModel.class);
|
||||
voListVO.forEach(vo -> {
|
||||
if (StringUtil.isNotEmpty(vo.getCategory()) && "1".equals(vo.getCategory()) && "-1".equals(vo.getParentId())) {
|
||||
vo.setCategory("系统");
|
||||
vo.setParentId("1");
|
||||
} else if (StringUtil.isNotEmpty(vo.getCategory()) && "0".equals(vo.getCategory()) && "-1".equals(vo.getParentId())) {
|
||||
vo.setCategory("业务");
|
||||
vo.setParentId("0");
|
||||
}
|
||||
});
|
||||
List<SumTree<DictionaryTypeModel>> sumTrees = TreeDotUtils.convertListToTreeDot(voListVO);
|
||||
List<DictionaryTypeListVO> list = JsonUtil.getJsonToList(sumTrees, DictionaryTypeListVO.class);
|
||||
|
||||
DictionaryTypeListVO parentVO = new DictionaryTypeListVO();
|
||||
parentVO.setFullName("系统字典");
|
||||
parentVO.setChildren(new ArrayList<>());
|
||||
parentVO.setId("1");
|
||||
DictionaryTypeListVO parentVO1 = new DictionaryTypeListVO();
|
||||
parentVO1.setFullName("业务字典");
|
||||
parentVO1.setChildren(new ArrayList<>());
|
||||
parentVO1.setId("0");
|
||||
|
||||
list.forEach(vo -> {
|
||||
if ("系统".equals(vo.getCategory())) {
|
||||
List<DictionaryTypeListVO> children = parentVO.getChildren();
|
||||
children.add(vo);
|
||||
parentVO.setHasChildren(true);
|
||||
}else {
|
||||
List<DictionaryTypeListVO> children = parentVO1.getChildren();
|
||||
children.add(vo);
|
||||
parentVO1.setHasChildren(true);
|
||||
}
|
||||
});
|
||||
List<DictionaryTypeListVO> listVo = new ArrayList<>();
|
||||
listVo.add(parentVO1);
|
||||
listVo.add(parentVO);
|
||||
|
||||
ListVO<DictionaryTypeListVO> vo = new ListVO<>();
|
||||
vo.setList(listVo);
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取字典分类信息
|
||||
*
|
||||
* @param id 主键值
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "获取字典分类信息")
|
||||
@Parameter(name = "id", description = "主键", required = true)
|
||||
@GetMapping("/{id}")
|
||||
public ActionResult<DictionaryTypeInfoVO> info(@PathVariable("id") String id) throws DataException {
|
||||
DictionaryTypeEntity entity = dictionaryTypeService.getInfo(id);
|
||||
if ("-1".equals(entity.getParentId())) {
|
||||
entity.setParentId(String.valueOf(entity.getCategory()));
|
||||
}
|
||||
DictionaryTypeInfoVO vo = JsonUtil.getJsonToBeanEx(entity, DictionaryTypeInfoVO.class);
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加字典分类
|
||||
*
|
||||
* @param dictionaryTypeCrForm 实体对象
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "添加字典分类")
|
||||
@Parameter(name = "dictionaryTypeCrForm", description = "实体对象", required = true)
|
||||
@SaCheckPermission("systemData.dictionary")
|
||||
@PostMapping
|
||||
public ActionResult create(@RequestBody @Valid DictionaryTypeCrForm dictionaryTypeCrForm) {
|
||||
DictionaryTypeEntity entity = JsonUtil.getJsonToBean(dictionaryTypeCrForm, DictionaryTypeEntity.class);
|
||||
if ("0".equals(entity.getParentId()) || "1".equals(entity.getParentId())) {
|
||||
entity.setCategory(Integer.parseInt(entity.getParentId()));
|
||||
entity.setParentId("-1");
|
||||
} else {
|
||||
DictionaryTypeEntity entity1 = dictionaryTypeService.getInfo(dictionaryTypeCrForm.getParentId());
|
||||
entity.setCategory(entity1.getCategory());
|
||||
}
|
||||
if (dictionaryTypeService.isExistByFullName(entity.getFullName(), entity.getId())) {
|
||||
return ActionResult.fail(MsgCode.EXIST001.get());
|
||||
}
|
||||
if (dictionaryTypeService.isExistByEnCode(entity.getEnCode(), entity.getId())) {
|
||||
return ActionResult.fail(MsgCode.EXIST002.get());
|
||||
}
|
||||
dictionaryTypeService.create(entity);
|
||||
return ActionResult.success(MsgCode.SU001.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改字典分类
|
||||
*
|
||||
* @param dictionaryTypeUpForm 实体对象
|
||||
* @param id 主键值
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "修改字典分类")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键值", required = true),
|
||||
@Parameter(name = "dictionaryTypeUpForm", description = "实体对象", required = true)
|
||||
})
|
||||
@SaCheckPermission("systemData.dictionary")
|
||||
@PutMapping("/{id}")
|
||||
public ActionResult update(@PathVariable("id") String id, @RequestBody @Valid DictionaryTypeUpForm dictionaryTypeUpForm) {
|
||||
DictionaryTypeEntity entity = JsonUtil.getJsonToBean(dictionaryTypeUpForm, DictionaryTypeEntity.class);
|
||||
if ("0".equals(entity.getParentId()) || "1".equals(entity.getParentId())) {
|
||||
entity.setCategory(Integer.parseInt(entity.getParentId()));
|
||||
entity.setParentId("-1");
|
||||
} else {
|
||||
DictionaryTypeEntity entity1 = dictionaryTypeService.getInfo(dictionaryTypeUpForm.getParentId());
|
||||
entity.setCategory(entity1.getCategory());
|
||||
}
|
||||
if (dictionaryTypeService.isExistByFullName(entity.getFullName(), id)) {
|
||||
return ActionResult.fail(MsgCode.EXIST001.get());
|
||||
}
|
||||
if (dictionaryTypeService.isExistByEnCode(entity.getEnCode(), id)) {
|
||||
return ActionResult.fail(MsgCode.EXIST002.get());
|
||||
}
|
||||
boolean flag = dictionaryTypeService.update(id, entity);
|
||||
if (!flag) {
|
||||
return ActionResult.success(MsgCode.FA002.get());
|
||||
}
|
||||
return ActionResult.success(MsgCode.SU004.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除字典分类
|
||||
*
|
||||
* @param id 主键值
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "删除字典分类")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键值", required = true)
|
||||
})
|
||||
@SaCheckPermission("systemData.dictionary")
|
||||
@DeleteMapping("/{id}")
|
||||
public ActionResult delete(@PathVariable("id") String id) {
|
||||
DictionaryTypeEntity entity = dictionaryTypeService.getInfo(id);
|
||||
if (entity != null) {
|
||||
boolean isOk = dictionaryTypeService.delete(entity);
|
||||
if (isOk) {
|
||||
return ActionResult.success(MsgCode.SU003.get());
|
||||
} else {
|
||||
return ActionResult.fail(MsgCode.SYS014.get());
|
||||
}
|
||||
}
|
||||
return ActionResult.fail(MsgCode.FA003.get());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,299 @@
|
||||
package com.yunzhupaas.base.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import com.yunzhupaas.base.ActionResult;
|
||||
import com.yunzhupaas.base.entity.DataInterfaceEntity;
|
||||
import com.yunzhupaas.base.entity.DataInterfaceLogEntity;
|
||||
import com.yunzhupaas.base.entity.DataInterfaceUserEntity;
|
||||
import com.yunzhupaas.base.entity.InterfaceOauthEntity;
|
||||
import com.yunzhupaas.base.model.InterfaceOauth.*;
|
||||
import com.yunzhupaas.base.model.datainterface.DataInterfaceVo;
|
||||
import com.yunzhupaas.base.service.DataInterfaceLogService;
|
||||
import com.yunzhupaas.base.service.DataInterfaceService;
|
||||
import com.yunzhupaas.base.service.DataInterfaceUserService;
|
||||
import com.yunzhupaas.base.service.InterfaceOauthService;
|
||||
import com.yunzhupaas.base.vo.PageListVO;
|
||||
import com.yunzhupaas.base.vo.PaginationVO;
|
||||
import com.yunzhupaas.constant.MsgCode;
|
||||
import com.yunzhupaas.exception.DataException;
|
||||
import com.yunzhupaas.permission.entity.UserEntity;
|
||||
import com.yunzhupaas.permission.service.UserService;
|
||||
import com.yunzhupaas.util.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
|
||||
/**
|
||||
* 接口认证控制器
|
||||
*
|
||||
* @author 云筑产品开发平台组
|
||||
* @version V3.4.2
|
||||
* @copyright 深圳市乐程软件有限公司
|
||||
* @date 2024/6/8
|
||||
*/
|
||||
@Tag(name = "接口认证", description = "interfaceoauth")
|
||||
@RestController
|
||||
@RequestMapping(value = "/api/system/InterfaceOauth")
|
||||
public class InterfaceOauthController extends SuperController<InterfaceOauthService, InterfaceOauthEntity> {
|
||||
@Autowired
|
||||
private DataInterfaceService dataInterfaceService;
|
||||
@Autowired
|
||||
private DataInterfaceLogService dataInterfaceLogService;
|
||||
|
||||
@Autowired
|
||||
private InterfaceOauthService interfaceOauthService;
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
|
||||
|
||||
@Autowired
|
||||
private DataInterfaceUserService dataInterfaceUserService;
|
||||
|
||||
|
||||
/**
|
||||
* 获取接口认证列表(分页)
|
||||
*
|
||||
* @param pagination 分页参数
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "获取接口认证列表(分页)")
|
||||
@SaCheckPermission("systemData.interfaceAuth")
|
||||
@GetMapping
|
||||
public ActionResult<PageListVO<InterfaceIdentListVo>> getList(PaginationOauth pagination) {
|
||||
List<InterfaceOauthEntity> data = interfaceOauthService.getList(pagination);
|
||||
List<InterfaceIdentListVo> jsonToList = JsonUtil.getJsonToList(data, InterfaceIdentListVo.class);
|
||||
jsonToList.forEach(item -> {
|
||||
if (StringUtil.isNotEmpty(UserProvider.getUser().getTenantId())) {
|
||||
item.setTenantId(UserProvider.getUser().getTenantId());
|
||||
}
|
||||
if (item.getCreatorUserId() != null) {
|
||||
item.setCreatorUser(userService.getInfo(item.getCreatorUserId()).getRealName());
|
||||
}
|
||||
});
|
||||
PaginationVO paginationVO = JsonUtil.getJsonToBean(pagination, PaginationVO.class);
|
||||
return ActionResult.page(jsonToList, paginationVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加接口认证
|
||||
*
|
||||
* @param interfaceIdentForm 添加接口认证模型
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "添加接口认证")
|
||||
@Parameter(name = "interfaceIdentForm", description = "添加接口认证模型", required = true)
|
||||
@SaCheckPermission("systemData.interfaceAuth")
|
||||
@PostMapping
|
||||
public ActionResult create(@RequestBody @Valid InterfaceIdentForm interfaceIdentForm) {
|
||||
InterfaceOauthEntity entity = JsonUtil.getJsonToBean(interfaceIdentForm, InterfaceOauthEntity.class);
|
||||
if (interfaceOauthService.isExistByAppName(entity.getAppName(), entity.getId())) {
|
||||
return ActionResult.fail(MsgCode.EXIST001.get());
|
||||
}
|
||||
if (interfaceOauthService.isExistByAppId(entity.getAppId(), entity.getId())) {
|
||||
return ActionResult.fail("AppId" +MsgCode.EXIST103.get());
|
||||
}
|
||||
interfaceOauthService.create(entity);
|
||||
return ActionResult.success(MsgCode.SU001.get());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 修改接口认证
|
||||
*
|
||||
* @param interfaceIdentForm 添加接口认证模型
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "修改接口认证")
|
||||
@Parameters({
|
||||
@Parameter(name = "interfaceIdentForm", description = "添加接口认证模型", required = true),
|
||||
@Parameter(name = "id", description = "主键", required = true)
|
||||
})
|
||||
@SaCheckPermission("systemData.interfaceAuth")
|
||||
@PutMapping("/{id}")
|
||||
public ActionResult update(@RequestBody @Valid InterfaceIdentForm interfaceIdentForm, @PathVariable("id") String id) throws DataException {
|
||||
InterfaceOauthEntity entity = JsonUtil.getJsonToBean(interfaceIdentForm, InterfaceOauthEntity.class);
|
||||
if (interfaceOauthService.isExistByAppName(entity.getAppName(), id)) {
|
||||
return ActionResult.fail(MsgCode.EXIST001.get());
|
||||
}
|
||||
if (interfaceOauthService.isExistByAppId(entity.getAppId(), id)) {
|
||||
return ActionResult.fail("AppId" +MsgCode.EXIST103.get());
|
||||
}
|
||||
boolean flag = interfaceOauthService.update(entity, id);
|
||||
if (flag == false) {
|
||||
return ActionResult.fail(MsgCode.FA002.get());
|
||||
}
|
||||
return ActionResult.success(MsgCode.SU004.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除接口认证
|
||||
*
|
||||
* @param id 主键
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "删除接口")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true)
|
||||
})
|
||||
@SaCheckPermission("systemData.interfaceAuth")
|
||||
@DeleteMapping("/{id}")
|
||||
public ActionResult delete(@PathVariable String id) {
|
||||
InterfaceOauthEntity entity = interfaceOauthService.getInfo(id);
|
||||
if (entity != null) {
|
||||
interfaceOauthService.delete(entity);
|
||||
return ActionResult.success(MsgCode.SU003.get());
|
||||
}
|
||||
return ActionResult.fail(MsgCode.FA003.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取秘钥
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "获取接口认证密钥")
|
||||
@SaCheckPermission("systemData.interfaceAuth")
|
||||
@GetMapping("/getAppSecret")
|
||||
public ActionResult getAppSecret() {
|
||||
String uuid = UUID.randomUUID().toString().replace("-", "");
|
||||
return ActionResult.success(MsgCode.SU019.get(), uuid);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 保存綁定认证接口
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "保存綁定认证接口")
|
||||
@Parameters({
|
||||
@Parameter(name = "identInterfaceListModel", description = "授权接口列表模型", required = true)
|
||||
})
|
||||
@SaCheckPermission("systemData.interfaceAuth")
|
||||
@PostMapping("/saveInterfaceList")
|
||||
public ActionResult getInterfaceList(@RequestBody IdentInterfaceListModel identInterfaceListModel) {
|
||||
InterfaceOauthEntity entity = new InterfaceOauthEntity();
|
||||
entity.setId(identInterfaceListModel.getInterfaceIdentId());
|
||||
entity.setDataInterfaceIds(identInterfaceListModel.getDataInterfaceIds());
|
||||
boolean b = interfaceOauthService.updateById(entity);
|
||||
if (b) {
|
||||
return ActionResult.success(MsgCode.SU002.get());
|
||||
}
|
||||
return ActionResult.success(MsgCode.FA101.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取接口授权绑定接口列表
|
||||
*
|
||||
* @param id 主键
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "获取认证基础信息及接口列表")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true)
|
||||
})
|
||||
@SaCheckPermission("systemData.interfaceAuth")
|
||||
@GetMapping("/{id}")
|
||||
public ActionResult getInterfaceList(@PathVariable("id") String id) {
|
||||
InterfaceOauthEntity entity = interfaceOauthService.getInfo(id);
|
||||
InterfaceIdentVo bean = JsonUtil.getJsonToBean(entity, InterfaceIdentVo.class);
|
||||
if (StringUtils.isNotEmpty(bean.getDataInterfaceIds())) {
|
||||
List<DataInterfaceVo> listDataInterfaceVo = new ArrayList<>();
|
||||
List<DataInterfaceEntity> list = dataInterfaceService.getList(false);
|
||||
list.forEach(item -> {
|
||||
if (bean.getDataInterfaceIds().contains(item.getId())) {
|
||||
DataInterfaceVo dataInterfaceVo = JsonUtil.getJsonToBean(item, DataInterfaceVo.class);
|
||||
listDataInterfaceVo.add(dataInterfaceVo);
|
||||
}
|
||||
});
|
||||
bean.setList(listDataInterfaceVo);
|
||||
}
|
||||
|
||||
//添加授权用户信息
|
||||
List<InterfaceUserVo> listIuv =new ArrayList<>();
|
||||
List<DataInterfaceUserEntity> select = dataInterfaceUserService.select(id);
|
||||
for(DataInterfaceUserEntity diue:select){
|
||||
String userId = diue.getUserId();
|
||||
UserEntity info = userService.getInfo(userId);
|
||||
InterfaceUserVo iuv=new InterfaceUserVo();
|
||||
iuv.setUserId(userId);
|
||||
iuv.setUserKey(diue.getUserKey());
|
||||
iuv.setUserName(info.getRealName()+"/"+info.getAccount());
|
||||
listIuv.add(iuv);
|
||||
}
|
||||
bean.setUserList(listIuv);
|
||||
return ActionResult.success(MsgCode.SU019.get(), bean);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取日志列表
|
||||
*
|
||||
* @param id 主键
|
||||
* @param paginationIntrfaceLog 分页参数
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "获取日志列表")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true)
|
||||
})
|
||||
@SaCheckPermission("systemData.interfaceAuth")
|
||||
@GetMapping("/dataInterfaceLog/{id}")
|
||||
public ActionResult<PageListVO<IdentDataInterfaceLogVO>> getInterfaceList(@PathVariable("id") String id,PaginationIntrfaceLog paginationIntrfaceLog) {
|
||||
InterfaceOauthEntity entity = interfaceOauthService.getInfo(id);
|
||||
List<IdentDataInterfaceLogVO> voList = null;
|
||||
PaginationVO vo = null;
|
||||
if (entity!=null&&StringUtils.isNotEmpty(entity.getDataInterfaceIds())) {
|
||||
String dataInterfaceIds = entity.getDataInterfaceIds();
|
||||
String[] split = dataInterfaceIds.split(",");
|
||||
List<String> list = Arrays.asList(split);
|
||||
List<DataInterfaceLogEntity> listByIds = dataInterfaceLogService.getListByIds(entity.getAppId(),list, paginationIntrfaceLog);
|
||||
voList = JsonUtil.getJsonToList(listByIds, IdentDataInterfaceLogVO.class);
|
||||
List<DataInterfaceEntity> listDataInt = dataInterfaceService.getList(false);
|
||||
for (IdentDataInterfaceLogVO invo : voList) {
|
||||
if (StringUtil.isNotEmpty(UserProvider.getUser().getTenantId())) {
|
||||
invo.setTenantId(UserProvider.getUser().getTenantId());
|
||||
}
|
||||
//绑定用户
|
||||
UserEntity userEntity = userService.getInfo(invo.getUserId());
|
||||
if (userEntity != null) {
|
||||
invo.setUserId(userEntity.getRealName() + "/" + userEntity.getAccount());
|
||||
}
|
||||
//绑定接口基础数据
|
||||
listDataInt.forEach(item -> {
|
||||
if (invo.getInvokId().contains(item.getId())) {
|
||||
DataInterfaceVo dataInterfaceVo = JsonUtil.getJsonToBean(item, DataInterfaceVo.class);
|
||||
invo.setFullName(dataInterfaceVo.getFullName());
|
||||
invo.setEnCode(dataInterfaceVo.getEnCode());
|
||||
}
|
||||
});
|
||||
}
|
||||
vo = JsonUtil.getJsonToBean(paginationIntrfaceLog, PaginationVO.class);
|
||||
|
||||
}
|
||||
return ActionResult.page(voList, vo);
|
||||
}
|
||||
|
||||
|
||||
@Operation(summary = "授权用户")
|
||||
@SaCheckPermission("systemData.interfaceAuth")
|
||||
@PostMapping("/SaveUserList")
|
||||
public ActionResult saveUserList(@RequestBody InterfaceUserForm interfaceUserForm) {
|
||||
dataInterfaceUserService.saveUserList(interfaceUserForm);
|
||||
return ActionResult.success(MsgCode.SU002.get());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,138 @@
|
||||
package com.yunzhupaas.base.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import com.yunzhupaas.base.ActionResult;
|
||||
import com.yunzhupaas.base.model.province.MapParams;
|
||||
import com.yunzhupaas.constant.MsgCode;
|
||||
import com.yunzhupaas.util.NoDataSourceBind;
|
||||
import com.yunzhupaas.util.ServletUtil;
|
||||
import com.yunzhupaas.util.wxutil.HttpUtil;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
|
||||
@Tag(name = "定位转发接口", description = "location")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/Location")
|
||||
public class LocationController {
|
||||
|
||||
@Operation(summary = "查询附近数据")
|
||||
@GetMapping("/around")
|
||||
@NoDataSourceBind
|
||||
public ActionResult<JSONObject> getAroundList(MapParams params) {
|
||||
JSONObject rstObj;
|
||||
String url = "https://restapi.amap.com/v3/place/around?key=" + params.getKey() + "&location=" + params.getLocation()
|
||||
+ "&radius=" + params.getRadius() + "&offset=" + params.getOffset() + "&page=" + params.getPage();
|
||||
try {
|
||||
rstObj = HttpUtil.httpRequest(url, "GET", null);
|
||||
} catch (Exception e) {
|
||||
return ActionResult.fail(MsgCode.SYS023.get());
|
||||
}
|
||||
if (rstObj == null) {
|
||||
return ActionResult.fail(MsgCode.SYS024.get());
|
||||
}
|
||||
return ActionResult.success(rstObj);
|
||||
}
|
||||
|
||||
@Operation(summary = "根据关键字查询附近数据")
|
||||
@GetMapping("/text")
|
||||
@NoDataSourceBind
|
||||
public ActionResult<JSONObject> getTextList(MapParams params) {
|
||||
JSONObject rstObj;
|
||||
String url = "https://restapi.amap.com/v3/place/text?key=" + params.getKey() + "&keywords=" + params.getKeywords()
|
||||
+ "&radius=" + params.getRadius() + "&offset=" + params.getOffset() + "&page=" + params.getPage();
|
||||
try {
|
||||
rstObj = HttpUtil.httpRequest(url, "GET", null);
|
||||
} catch (Exception e) {
|
||||
return ActionResult.fail(MsgCode.SYS023.get());
|
||||
}
|
||||
if (rstObj == null) {
|
||||
return ActionResult.fail(MsgCode.SYS024.get());
|
||||
}
|
||||
return ActionResult.success(rstObj);
|
||||
}
|
||||
|
||||
@Operation(summary = "输入提示")
|
||||
@GetMapping("/inputtips")
|
||||
@NoDataSourceBind
|
||||
public ActionResult<JSONObject> getInputTips(MapParams params) {
|
||||
JSONObject rstObj;
|
||||
String url = "https://restapi.amap.com/v3/assistant/inputtips?key=" + params.getKey() + "&keywords=" + params.getKeywords();
|
||||
try {
|
||||
rstObj = HttpUtil.httpRequest(url, "GET", null);
|
||||
} catch (Exception e) {
|
||||
return ActionResult.fail(MsgCode.SYS023.get());
|
||||
}
|
||||
if (rstObj == null) {
|
||||
return ActionResult.fail(MsgCode.SYS024.get());
|
||||
}
|
||||
return ActionResult.success(rstObj);
|
||||
}
|
||||
|
||||
@Operation(summary = "定位图片")
|
||||
@GetMapping("/staticmap")
|
||||
@NoDataSourceBind
|
||||
public void staticmap(MapParams params) {
|
||||
String requestUrl = "https://restapi.amap.com/v3/staticmap?location=" + params.getLocation() + "&zoom=" + params.getZoom() + "&size="
|
||||
+ params.getSize() + "&key=" + params.getKey();
|
||||
try {
|
||||
URL url = new URL(requestUrl);
|
||||
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||
conn.setDoOutput(true);
|
||||
conn.setDoInput(true);
|
||||
conn.setUseCaches(false);
|
||||
conn.setRequestMethod("GET");
|
||||
conn.setConnectTimeout(50000);
|
||||
conn.setReadTimeout(60000);
|
||||
conn.setRequestProperty("Content-Type", "image/png");
|
||||
InputStream ins = null;
|
||||
OutputStream os = null;
|
||||
try {
|
||||
ins = conn.getInputStream();
|
||||
HttpServletResponse response = ServletUtil.getResponse();
|
||||
BufferedImage image = ImageIO.read(ins);
|
||||
os = response.getOutputStream();
|
||||
if (image != null) {
|
||||
ImageIO.write(image, "png", os);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
conn.disconnect();
|
||||
os.flush();
|
||||
os.close();
|
||||
ins.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Operation(summary = "经纬度转地址")
|
||||
@GetMapping("/regeo")
|
||||
@NoDataSourceBind
|
||||
public ActionResult<JSONObject> regeo(MapParams params) {
|
||||
JSONObject rstObj;
|
||||
String url = "https://restapi.amap.com/v3/geocode/regeo?key=" + params.getKey() + "&&location=" + params.getLocation();
|
||||
try {
|
||||
rstObj = HttpUtil.httpRequest(url, "GET", null);
|
||||
} catch (Exception e) {
|
||||
return ActionResult.fail(MsgCode.SYS023.get());
|
||||
}
|
||||
if (rstObj == null) {
|
||||
return ActionResult.fail(MsgCode.SYS024.get());
|
||||
}
|
||||
return ActionResult.success(rstObj);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,271 @@
|
||||
package com.yunzhupaas.base.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import com.yunzhupaas.base.ActionResult;
|
||||
import com.yunzhupaas.base.Pagination;
|
||||
import com.yunzhupaas.base.entity.MessageTemplateEntity;
|
||||
import com.yunzhupaas.base.entity.SmsTemplateEntity;
|
||||
import com.yunzhupaas.base.model.messagetemplate.*;
|
||||
import com.yunzhupaas.base.SmsModel;
|
||||
import com.yunzhupaas.base.service.MessageTemplateService;
|
||||
import com.yunzhupaas.base.service.SmsTemplateService;
|
||||
import com.yunzhupaas.util.message.SmsUtil;
|
||||
import com.yunzhupaas.base.vo.PageListVO;
|
||||
import com.yunzhupaas.base.vo.PaginationVO;
|
||||
import com.yunzhupaas.constant.MsgCode;
|
||||
import com.yunzhupaas.permission.entity.UserEntity;
|
||||
import com.yunzhupaas.permission.service.UserService;
|
||||
import com.yunzhupaas.util.JsonUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 消息模板控制类
|
||||
*
|
||||
* @author 云筑产品开发平台组
|
||||
* @version V3.1.0
|
||||
* @copyright 深圳市乐程软件有限公司(http://www.szlecheng.cn)
|
||||
* @date 2024-12-08
|
||||
*/
|
||||
@Tag(description = "BaseMessageTemplateController", name = "消息模板控制类")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/MessageTemplate")
|
||||
public class MessageTemplateController extends SuperController<MessageTemplateService, MessageTemplateEntity> {
|
||||
|
||||
@Autowired
|
||||
private MessageTemplateService messageTemplateService;
|
||||
@Autowired
|
||||
private SmsTemplateService smsTemplateService;
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
/**
|
||||
* 消息模板列表
|
||||
*
|
||||
* @param pagination 分页模型
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "消息模板列表")
|
||||
@SaCheckPermission("msgTemplate")
|
||||
@GetMapping
|
||||
public ActionResult<PageListVO<MessageTemplateListVO>> list(Pagination pagination) {
|
||||
List<MessageTemplateEntity> list = messageTemplateService.getList(pagination, false);
|
||||
List<MessageTemplateListVO> listVO = JsonUtil.getJsonToList(list, MessageTemplateListVO.class);
|
||||
for (MessageTemplateListVO messageTemplateListVO : listVO) {
|
||||
StringBuilder noticeMethod = new StringBuilder();
|
||||
if (messageTemplateListVO.getIsDingTalk() == 1) {
|
||||
noticeMethod.append("、阿里钉钉");
|
||||
}
|
||||
if (messageTemplateListVO.getIsEmail() == 1) {
|
||||
noticeMethod.append("、电子邮箱");
|
||||
}
|
||||
if (messageTemplateListVO.getIsSms() == 1) {
|
||||
noticeMethod.append("、短信");
|
||||
}
|
||||
if (messageTemplateListVO.getIsStationLetter() == 1) {
|
||||
noticeMethod.append("、站内信");
|
||||
}
|
||||
if (messageTemplateListVO.getIsWecom() == 1) {
|
||||
noticeMethod.append("、企业微信");
|
||||
}
|
||||
if (noticeMethod.length() > 0) {
|
||||
messageTemplateListVO.setNoticeMethod(noticeMethod.toString().replaceFirst("、", ""));
|
||||
}
|
||||
if ("1".equals(messageTemplateListVO.getCategory())) {
|
||||
messageTemplateListVO.setCategory("普通");
|
||||
} else if ("2".equals(messageTemplateListVO.getCategory())) {
|
||||
messageTemplateListVO.setCategory("重要");
|
||||
} else if ("3".equals(messageTemplateListVO.getCategory())) {
|
||||
messageTemplateListVO.setCategory("紧急");
|
||||
}
|
||||
UserEntity entity = userService.getInfo(messageTemplateListVO.getCreatorUserId());
|
||||
messageTemplateListVO.setCreatorUser(entity!= null ? entity.getRealName() + "/" + entity.getAccount() : null);
|
||||
}
|
||||
PaginationVO paginationVO = JsonUtil.getJsonToBean(pagination, PaginationVO.class);
|
||||
return ActionResult.page(listVO, paginationVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 消息模板下拉框
|
||||
*
|
||||
* @param pagination 分页模型
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "消息模板下拉框")
|
||||
@GetMapping("/Selector")
|
||||
public ActionResult selector(Pagination pagination) {
|
||||
List<MessageTemplateEntity> list = messageTemplateService.getList(pagination, true);
|
||||
for (MessageTemplateEntity entity : list) {
|
||||
if ("1".equals(entity.getCategory())) {
|
||||
entity.setCategory("普通");
|
||||
} else if ("2".equals(entity.getCategory())) {
|
||||
entity.setCategory("重要");
|
||||
} else if ("3".equals(entity.getCategory())) {
|
||||
entity.setCategory("紧急");
|
||||
}
|
||||
}
|
||||
List<MessageTemplateSelector> listVO = JsonUtil.getJsonToList(list, MessageTemplateSelector.class);
|
||||
PaginationVO paginationVO = JsonUtil.getJsonToBean(pagination, PaginationVO.class);
|
||||
return ActionResult.page(listVO, paginationVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取消息模板
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "获取消息模板")
|
||||
@Parameter(name = "id", description = "主键", required = true)
|
||||
@GetMapping("/{id}")
|
||||
public ActionResult<MessageTemplateVO> info(@PathVariable("id") String id) {
|
||||
MessageTemplateEntity entity = messageTemplateService.getInfo(id);
|
||||
MessageTemplateVO vo = JsonUtil.getJsonToBean(entity, MessageTemplateVO.class);
|
||||
SmsTemplateEntity info = smsTemplateService.getInfo(vo.getSmsId());
|
||||
vo.setSmsTemplateName(info != null ? info.getFullName() : null);
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取消息模板参数
|
||||
*
|
||||
* @param id 主键
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "获取消息模板参数")
|
||||
@Parameter(name = "id", description = "主键", required = true)
|
||||
@GetMapping("/getTemplate/{id}")
|
||||
public ActionResult<?> getParameter(@PathVariable("id") String id) {
|
||||
MessageTemplateEntity entity = messageTemplateService.getInfo(id);
|
||||
if (entity == null) {
|
||||
return ActionResult.fail(MsgCode.SYS015.get());
|
||||
}
|
||||
// 获取参数
|
||||
String templateJson = entity.getTemplateJson();
|
||||
Map<String, Object> map = JsonUtil.stringToMap(templateJson);
|
||||
// 如果是短信,获取短信模板参数
|
||||
if (entity.getIsSms() == 1) {
|
||||
SmsModel smsModel = smsTemplateService.getSmsConfig();
|
||||
String smsId = entity.getSmsId();
|
||||
SmsTemplateEntity info = smsTemplateService.getInfo(smsId);
|
||||
List<String> list = SmsUtil.querySmsTemplateRequest(info.getCompany(), smsModel, info.getEndpoint(), info.getRegion(), info.getTemplateId());
|
||||
for (String key : list) {
|
||||
map.put(key, null);
|
||||
}
|
||||
}
|
||||
return ActionResult.success(map);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新建
|
||||
*
|
||||
* @param messageTemplateCrForm 新建消息模板
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "新建")
|
||||
@Parameter(name = "messageTemplateCrForm", description = "新建消息模板", required = true)
|
||||
@SaCheckPermission("msgTemplate")
|
||||
@PostMapping
|
||||
public ActionResult<String> create(@RequestBody @Valid MessageTemplateCrForm messageTemplateCrForm) {
|
||||
MessageTemplateEntity entity = JsonUtil.getJsonToBean(messageTemplateCrForm, MessageTemplateEntity.class);
|
||||
if (messageTemplateService.isExistByFullName(entity.getFullName(), entity.getId())) {
|
||||
return ActionResult.fail(MsgCode.EXIST001.get());
|
||||
}
|
||||
if (messageTemplateService.isExistByEnCode(entity.getEnCode(), entity.getId())) {
|
||||
return ActionResult.fail(MsgCode.EXIST002.get());
|
||||
}
|
||||
messageTemplateService.create(entity);
|
||||
return ActionResult.success(MsgCode.SU001.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
*
|
||||
* @param id 主键
|
||||
* @param messageTemplateUpForm 修改消息模板
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "修改")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true),
|
||||
@Parameter(name = "messageTemplateUpForm", description = "修改消息模板", required = true)
|
||||
})
|
||||
@SaCheckPermission("msgTemplate")
|
||||
@PutMapping("/{id}")
|
||||
public ActionResult<String> update(@PathVariable("id") String id, @RequestBody @Valid MessageTemplateUpForm messageTemplateUpForm) {
|
||||
MessageTemplateEntity entity = JsonUtil.getJsonToBean(messageTemplateUpForm, MessageTemplateEntity.class);
|
||||
if (entity != null) {
|
||||
if (messageTemplateService.isExistByFullName(entity.getFullName(), id)) {
|
||||
return ActionResult.fail(MsgCode.EXIST001.get());
|
||||
}
|
||||
if (messageTemplateService.isExistByEnCode(entity.getEnCode(), id)) {
|
||||
return ActionResult.fail(MsgCode.EXIST002.get());
|
||||
}
|
||||
boolean flag = messageTemplateService.update(id, entity);
|
||||
if (!flag) {
|
||||
return ActionResult.fail(MsgCode.FA002.get());
|
||||
}
|
||||
return ActionResult.success(MsgCode.SU004.get());
|
||||
}
|
||||
return ActionResult.fail(MsgCode.FA002.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*
|
||||
* @param id 主键
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "删除")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true)
|
||||
})
|
||||
@SaCheckPermission("msgTemplate")
|
||||
@DeleteMapping("/{id}")
|
||||
public ActionResult<String> delete(@PathVariable("id") String id) {
|
||||
MessageTemplateEntity entity = messageTemplateService.getInfo(id);
|
||||
if (entity == null) {
|
||||
return ActionResult.fail(MsgCode.FA003.get());
|
||||
}
|
||||
messageTemplateService.delete(entity);
|
||||
return ActionResult.success(MsgCode.SU003.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改状态
|
||||
*
|
||||
* @param id 主键
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "修改状态")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true)
|
||||
})
|
||||
@SaCheckPermission("msgTemplate")
|
||||
@PutMapping("/{id}/Actions/State")
|
||||
public ActionResult<String> update(@PathVariable("id") String id) {
|
||||
MessageTemplateEntity entity = messageTemplateService.getInfo(id);
|
||||
if (entity != null) {
|
||||
if (entity.getEnabledMark() == 0) {
|
||||
entity.setEnabledMark(1);
|
||||
} else {
|
||||
entity.setEnabledMark(0);
|
||||
}
|
||||
boolean flag = messageTemplateService.update(id, entity);
|
||||
if (!flag) {
|
||||
return ActionResult.fail(MsgCode.FA002.get());
|
||||
}
|
||||
return ActionResult.success(MsgCode.SU004.get());
|
||||
}
|
||||
return ActionResult.success(MsgCode.FA002.get());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,206 @@
|
||||
package com.yunzhupaas.base.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import com.yunzhupaas.base.ActionResult;
|
||||
import com.yunzhupaas.base.Pagination;
|
||||
import com.yunzhupaas.base.service.ModuleButtonService;
|
||||
import com.yunzhupaas.base.vo.ListVO;
|
||||
import com.yunzhupaas.base.entity.ModuleButtonEntity;
|
||||
import com.yunzhupaas.constant.MsgCode;
|
||||
import com.yunzhupaas.exception.DataException;
|
||||
import com.yunzhupaas.base.model.button.*;
|
||||
import com.yunzhupaas.util.JsonUtil;
|
||||
import com.yunzhupaas.util.JsonUtilEx;
|
||||
import com.yunzhupaas.util.treeutil.SumTree;
|
||||
import com.yunzhupaas.util.treeutil.newtreeutil.TreeDotUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 按钮权限
|
||||
*
|
||||
* @author 云筑产品开发平台组
|
||||
* @version V3.1.0
|
||||
* @copyright 深圳市乐程软件有限公司
|
||||
* @date 2023/09/27
|
||||
*/
|
||||
@Tag(name = "按钮权限", description = "ModuleButton")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/ModuleButton")
|
||||
public class ModuleButtonController extends SuperController<ModuleButtonService, ModuleButtonEntity> {
|
||||
|
||||
@Autowired
|
||||
private ModuleButtonService moduleButtonService;
|
||||
|
||||
/**
|
||||
* 按钮按钮权限列表
|
||||
*
|
||||
* @param menuId 功能主键
|
||||
* @param pagination 分页参数
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "获取按钮权限列表")
|
||||
@Parameters({
|
||||
@Parameter(name = "menuId", description = "功能主键", required = true)
|
||||
})
|
||||
@SaCheckPermission("system.menu")
|
||||
@GetMapping("/{menuId}/List")
|
||||
public ActionResult list(@PathVariable("menuId") String menuId, Pagination pagination) {
|
||||
List<ModuleButtonEntity> data = moduleButtonService.getListByModuleIds(menuId, pagination);
|
||||
List<ButtonTreeListModel> treeList = JsonUtil.getJsonToList(data, ButtonTreeListModel.class);
|
||||
List<SumTree<ButtonTreeListModel>> sumTrees = TreeDotUtils.convertListToTreeDot(treeList);
|
||||
if (data.size() > sumTrees.size()) {
|
||||
List<ButtonTreeListVO> list = JsonUtil.getJsonToList(sumTrees, ButtonTreeListVO.class);
|
||||
ListVO<ButtonTreeListVO> treeVo = new ListVO<>();
|
||||
treeVo.setList(list);
|
||||
return ActionResult.success(treeVo);
|
||||
}
|
||||
List<ButtonListVO> list = JsonUtil.getJsonToList(treeList, ButtonListVO.class);
|
||||
ListVO<ButtonListVO> treeVo1 = new ListVO<>();
|
||||
treeVo1.setList(list);
|
||||
return ActionResult.success(treeVo1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 按钮按钮权限列表
|
||||
*
|
||||
* @param menuId 功能主键
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "获取按钮权限下拉框")
|
||||
@Parameters({
|
||||
@Parameter(name = "menuId", description = "功能主键", required = true)
|
||||
})
|
||||
@GetMapping("/{menuId}/Selector")
|
||||
public ActionResult<ListVO<ButtonTreeListVO>> selectList(@PathVariable("menuId") String menuId) {
|
||||
List<ModuleButtonEntity> data = moduleButtonService.getListByModuleIds(menuId);
|
||||
List<ButtonTreeListModel> treeList = JsonUtil.getJsonToList(data, ButtonTreeListModel.class);
|
||||
List<SumTree<ButtonTreeListModel>> sumTrees = TreeDotUtils.convertListToTreeDot(treeList);
|
||||
List<ButtonTreeListVO> list = JsonUtil.getJsonToList(sumTrees, ButtonTreeListVO.class);
|
||||
ListVO<ButtonTreeListVO> treeVo = new ListVO<>();
|
||||
treeVo.setList(list);
|
||||
return ActionResult.success(treeVo);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取按钮权限信息
|
||||
*
|
||||
* @param id 主键值
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "获取按钮权限信息")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键值", required = true)
|
||||
})
|
||||
@SaCheckPermission("system.menu")
|
||||
@GetMapping("/{id}")
|
||||
public ActionResult<ModuleButtonInfoVO> info(@PathVariable("id") String id) throws DataException {
|
||||
ModuleButtonEntity entity = moduleButtonService.getInfo(id);
|
||||
ModuleButtonInfoVO vo = JsonUtilEx.getJsonToBeanEx(entity, ModuleButtonInfoVO.class);
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新建按钮权限
|
||||
*
|
||||
* @param moduleButtonCrForm 实体对象
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "新建按钮权限")
|
||||
@Parameters({
|
||||
@Parameter(name = "moduleButtonCrForm", description = "实体对象", required = true)
|
||||
})
|
||||
@SaCheckPermission("system.menu")
|
||||
@PostMapping
|
||||
public ActionResult create(@RequestBody ModuleButtonCrForm moduleButtonCrForm) {
|
||||
ModuleButtonEntity entity = JsonUtil.getJsonToBean(moduleButtonCrForm, ModuleButtonEntity.class);
|
||||
if (moduleButtonService.isExistByEnCode(entity.getModuleId(), entity.getEnCode(), entity.getId())) {
|
||||
return ActionResult.fail(MsgCode.EXIST002.get());
|
||||
}
|
||||
moduleButtonService.create(entity);
|
||||
return ActionResult.success(MsgCode.SU001.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新按钮权限
|
||||
*
|
||||
* @param id 主键值
|
||||
* @param moduleButtonUpForm 更新参数
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "更新按钮权限")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键值", required = true),
|
||||
@Parameter(name = "moduleButtonUpForm", description = "实体对象", required = true)
|
||||
})
|
||||
@SaCheckPermission("system.menu")
|
||||
@PutMapping("/{id}")
|
||||
public ActionResult update(@PathVariable("id") String id, @RequestBody ModuleButtonUpForm moduleButtonUpForm) {
|
||||
ModuleButtonEntity entity = JsonUtil.getJsonToBean(moduleButtonUpForm, ModuleButtonEntity.class);
|
||||
if (moduleButtonService.isExistByEnCode(entity.getModuleId(), entity.getEnCode(), id)) {
|
||||
return ActionResult.fail(MsgCode.EXIST002.get());
|
||||
}
|
||||
boolean flag = moduleButtonService.update(id, entity);
|
||||
if (flag == false) {
|
||||
return ActionResult.success(MsgCode.FA002.get());
|
||||
}
|
||||
return ActionResult.success(MsgCode.SU004.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除按钮权限
|
||||
*
|
||||
* @param id 主键值
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "删除按钮权限")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键值", required = true)
|
||||
})
|
||||
@SaCheckPermission("system.menu")
|
||||
@DeleteMapping("/{id}")
|
||||
public ActionResult delete(@PathVariable("id") String id) {
|
||||
ModuleButtonEntity entity = moduleButtonService.getInfo(id);
|
||||
if (entity != null) {
|
||||
moduleButtonService.delete(entity);
|
||||
return ActionResult.success(MsgCode.SU003.get());
|
||||
}
|
||||
return ActionResult.fail(MsgCode.FA003.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新菜单状态
|
||||
*
|
||||
* @param id 主键值
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "更新菜单状态")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键值", required = true)
|
||||
})
|
||||
@SaCheckPermission("system.menu")
|
||||
@PutMapping("/{id}/Actions/State")
|
||||
public ActionResult upState(@PathVariable("id") String id) {
|
||||
ModuleButtonEntity entity = moduleButtonService.getInfo(id);
|
||||
if (entity.getEnabledMark() == null || "1".equals(String.valueOf(entity.getEnabledMark()))) {
|
||||
entity.setEnabledMark(0);
|
||||
} else {
|
||||
entity.setEnabledMark(1);
|
||||
}
|
||||
boolean flag = moduleButtonService.update(id, entity);
|
||||
if (!flag) {
|
||||
return ActionResult.success(MsgCode.FA002.get());
|
||||
}
|
||||
return ActionResult.success(MsgCode.SU004.get());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,409 @@
|
||||
package com.yunzhupaas.base.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import com.yunzhupaas.base.ActionResult;
|
||||
import com.yunzhupaas.base.Pagination;
|
||||
import com.yunzhupaas.base.entity.ModuleEntity;
|
||||
import com.yunzhupaas.base.model.ColumnDataModel;
|
||||
import com.yunzhupaas.base.model.Template6.ColumnListField;
|
||||
import com.yunzhupaas.base.model.module.PropertyJsonModel;
|
||||
import com.yunzhupaas.base.service.ModuleColumnService;
|
||||
import com.yunzhupaas.base.service.ModuleService;
|
||||
import com.yunzhupaas.base.vo.ListVO;
|
||||
import com.yunzhupaas.base.entity.ModuleColumnEntity;
|
||||
import com.yunzhupaas.constant.MsgCode;
|
||||
import com.yunzhupaas.exception.DataException;
|
||||
import com.yunzhupaas.base.model.column.*;
|
||||
import com.yunzhupaas.util.JsonUtil;
|
||||
import com.yunzhupaas.util.JsonUtilEx;
|
||||
import com.yunzhupaas.util.ReflectionUtil;
|
||||
import com.yunzhupaas.util.StringUtil;
|
||||
import com.yunzhupaas.util.context.SpringContext;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 列表权限
|
||||
*
|
||||
* @author 云筑产品开发平台组
|
||||
* @version V3.1.0
|
||||
* @copyright 深圳市乐程软件有限公司
|
||||
* @date 2023/09/27
|
||||
*/
|
||||
@Tag(name = "列表权限", description = "ModuleColumn")
|
||||
@Validated
|
||||
@RestController
|
||||
@RequestMapping("/api/system/ModuleColumn")
|
||||
public class ModuleColumnController extends SuperController<ModuleColumnService, ModuleColumnEntity> {
|
||||
|
||||
@Autowired
|
||||
private ModuleColumnService moduleColumnService;
|
||||
@Autowired
|
||||
private ModuleService moduleService;
|
||||
|
||||
/**
|
||||
* 获取列表权限信息列表
|
||||
*
|
||||
* @param moduleId 功能主键
|
||||
* @param pagination 分页参数
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "获取列表权限列表")
|
||||
@Parameters({
|
||||
@Parameter(name = "moduleId", description = "功能主键", required = true)
|
||||
})
|
||||
@SaCheckPermission("system.menu")
|
||||
@GetMapping("/{moduleId}/Fields")
|
||||
public ActionResult<ListVO<ColumnListVO>> getList(@PathVariable("moduleId") String moduleId,
|
||||
Pagination pagination) {
|
||||
List<ModuleColumnEntity> list = moduleColumnService.getList(moduleId, pagination);
|
||||
List<ColumnListVO> voList = JsonUtil.getJsonToList(list, ColumnListVO.class);
|
||||
voList.stream().forEach(t -> {
|
||||
String enCode = t.getEnCode();
|
||||
if (StringUtil.isNotEmpty(enCode)) {
|
||||
if (enCode.contains("-")) {
|
||||
enCode = enCode.substring(enCode.indexOf("-") + 1);
|
||||
}
|
||||
t.setEnCode(enCode.replace("yunzhupaas_" + t.getBindTable() + "_yunzhupaas_", ""));
|
||||
}
|
||||
});
|
||||
ListVO<ColumnListVO> vo = new ListVO<>();
|
||||
vo.setList(voList);
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 菜单列表权限
|
||||
*
|
||||
* @param moduleId 功能主键
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "菜单列表权限")
|
||||
@Parameters({
|
||||
@Parameter(name = "moduleId", description = "功能主键", required = true)
|
||||
})
|
||||
@SaCheckPermission("system.menu")
|
||||
@GetMapping("/{moduleId}/FieldList")
|
||||
public ActionResult<List<Map<String, String>>> fieldList(@PathVariable("moduleId") String moduleId) {
|
||||
List<Map<String, String>> list = new ArrayList<>();
|
||||
// 得到菜单id
|
||||
ModuleEntity entity = moduleService.getInfo(moduleId);
|
||||
if (entity != null) {
|
||||
PropertyJsonModel model = JsonUtil.getJsonToBean(entity.getPropertyJson(), PropertyJsonModel.class);
|
||||
if (model == null) {
|
||||
model = new PropertyJsonModel();
|
||||
}
|
||||
// 得到bean
|
||||
Object bean = SpringContext.getBean("visualdevServiceImpl");
|
||||
Object method = ReflectionUtil.invokeMethod(bean, "getInfo", new Class[] { String.class },
|
||||
new Object[] { model.getModuleId() });
|
||||
Map<String, Object> map = JsonUtil.entityToMap(method);
|
||||
boolean isPc = entity.getCategory().equalsIgnoreCase("web");
|
||||
if (map != null) {
|
||||
Object columnData = isPc ? map.get("columnData") : map.get("appColumnData");
|
||||
if (Objects.nonNull(columnData)) {
|
||||
ColumnDataModel columnDataModel = JsonUtil.getJsonToBean(columnData.toString(),
|
||||
ColumnDataModel.class);
|
||||
List<ColumnListField> columnListFields = JsonUtil
|
||||
.getJsonToList(columnDataModel.getDefaultColumnList(), ColumnListField.class);
|
||||
if (Objects.nonNull(columnListFields)) {
|
||||
columnListFields.stream().forEach(col -> {
|
||||
Map<String, String> dataMap = new HashMap<>();
|
||||
dataMap.put("field", col.getProp());
|
||||
dataMap.put("fieldName", col.getLabel());
|
||||
list.add(dataMap);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if (map != null && map.containsKey("formData")) {
|
||||
// // 需要排除的key
|
||||
// String[] filterKey = new String[]{"PsdInput", "colorPicker", "rate",
|
||||
// "slider", "divider",
|
||||
// "uploadImg", "uploadFz", "editor", "YUNZHUPAASText", "relationFormAttr",
|
||||
// "popupAttr", "groupTitle"};
|
||||
// List<String> filterKeyList = Arrays.asList(filterKey);
|
||||
// FormDataModel formDataModel =
|
||||
// JsonUtil.getJsonToBean(String.valueOf(map.get("formData")),
|
||||
// FormDataModel.class);
|
||||
// List<FieLdsModel> fieLdsModelList =
|
||||
// JsonUtil.getJsonToList(formDataModel.getFields(), FieLdsModel.class);
|
||||
// RecursionForm recursionForm = new RecursionForm();
|
||||
// recursionForm.setList(fieLdsModelList);
|
||||
// recursionForm.setTableModelList(JsonUtil.getJsonToList(String.valueOf(map.get("tables")),
|
||||
// TableModel.class));
|
||||
// List<FormAllModel> formAllModel = new ArrayList<>();
|
||||
// FormCloumnUtil.recursionForm(recursionForm, formAllModel);
|
||||
// for (FormAllModel allModel : formAllModel) {
|
||||
// if (FormEnum.mast.getMessage().equals(allModel.getYunzhupaasKey())) {
|
||||
// FormColumnModel formColumnModel = allModel.getFormColumnModel();
|
||||
// FieLdsModel fieLdsModel = formColumnModel.getFieLdsModel();
|
||||
// long count = filterKeyList.stream().filter(t -> fieLdsModel != null &&
|
||||
// fieLdsModel.getConfig()!=null &&
|
||||
// t.equals(fieLdsModel.getConfig().getYunzhupaasKey())).count();
|
||||
// if (count < 1) {
|
||||
// if (fieLdsModel != null && StringUtil.isNotEmpty(fieLdsModel.getVModel())) {
|
||||
// Map<String, String> map1 = new HashedMap<>();
|
||||
// map1.put("field", fieLdsModel.getVModel());
|
||||
// map1.put("fieldName", fieLdsModel.getConfig().getLabel());
|
||||
// list.add(map1);
|
||||
// }
|
||||
// }
|
||||
// } else if
|
||||
// (FormEnum.mastTable.getMessage().equals(allModel.getYunzhupaasKey())) {
|
||||
// FormMastTableModel formColumnModel = allModel.getFormMastTableModel();
|
||||
// FieLdsModel fieLdsModel = formColumnModel.getMastTable().getFieLdsModel();
|
||||
// long count = filterKeyList.stream().filter(t -> fieLdsModel != null &&
|
||||
// fieLdsModel.getConfig() != null &&
|
||||
// t.equals(fieLdsModel.getConfig().getYunzhupaasKey())).count();
|
||||
// if (count < 1) {
|
||||
// if (fieLdsModel != null && StringUtil.isNotEmpty(fieLdsModel.getVModel())) {
|
||||
// Map<String, String> map1 = new HashedMap<>();
|
||||
// map1.put("field", fieLdsModel.getVModel());
|
||||
// map1.put("fieldName", fieLdsModel.getConfig().getLabel());
|
||||
// list.add(map1);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
///// 后面会用到
|
||||
//// else if (FormEnum.table.getMessage().equals(allModel.getYunzhupaasKey())) {
|
||||
//// FormColumnTableModel childList = allModel.getChildList();
|
||||
//// List<FormColumnModel> childList1 = childList.getChildList();
|
||||
//// for (FormColumnModel formColumnModel : childList1) {
|
||||
//// FieLdsModel fieLdsModel = formColumnModel.getFieLdsModel();
|
||||
//// if (StringUtil.isNotEmpty(fieLdsModel.getVModel())) {
|
||||
//// Map<String, String> map1 = new HashedMap<>();
|
||||
//// map1.put("field", fieLdsModel.getVModel());
|
||||
//// map1.put("fieldName", fieLdsModel.getConfig().getLabel());
|
||||
//// list.add(map1);
|
||||
//// }
|
||||
//// }
|
||||
//// }
|
||||
/////
|
||||
// }
|
||||
// }
|
||||
return ActionResult.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取列表权限信息
|
||||
*
|
||||
* @param id 主键值
|
||||
* @return ignore
|
||||
* @throws DataException ignore
|
||||
*/
|
||||
@Operation(summary = "获取列表权限信息")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键值", required = true)
|
||||
})
|
||||
@GetMapping("/{id}")
|
||||
public ActionResult<ModuleColumnInfoVO> info(@PathVariable("id") String id) throws DataException {
|
||||
ModuleColumnEntity entity = moduleColumnService.getInfo(id);
|
||||
String enCode = entity.getEnCode();
|
||||
if (StringUtil.isNotEmpty(enCode)) {
|
||||
if (enCode.contains("-") && entity.getFieldRule() == 2) {
|
||||
enCode = enCode.substring(enCode.indexOf("-") + 1);
|
||||
entity.setEnCode(enCode);
|
||||
}
|
||||
if (Objects.equals(entity.getFieldRule(), 1) && entity.getBindTable() != null) {
|
||||
entity.setEnCode(enCode.replace("yunzhupaas_" + entity.getBindTable() + "_yunzhupaas_", ""));
|
||||
}
|
||||
}
|
||||
ModuleColumnInfoVO vo = JsonUtilEx.getJsonToBeanEx(entity, ModuleColumnInfoVO.class);
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新建列表权限
|
||||
*
|
||||
* @param moduleColumnCrForm 实体对象
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "新建列表权限")
|
||||
@Parameters({
|
||||
@Parameter(name = "moduleColumnCrForm", description = "实体对象", required = true)
|
||||
})
|
||||
@SaCheckPermission("system.menu")
|
||||
@PostMapping
|
||||
public ActionResult create(@RequestBody @Valid ModuleColumnCrForm moduleColumnCrForm) {
|
||||
ModuleEntity moduleEntity = moduleService.getInfo(moduleColumnCrForm.getModuleId());
|
||||
ModuleColumnEntity entity = JsonUtil.getJsonToBean(moduleColumnCrForm, ModuleColumnEntity.class);
|
||||
|
||||
if (moduleEntity != null) {
|
||||
PropertyJsonModel model = JsonUtil.getJsonToBean(moduleEntity.getPropertyJson(), PropertyJsonModel.class);
|
||||
if (model == null) {
|
||||
model = new PropertyJsonModel();
|
||||
}
|
||||
if (entity.getFieldRule() == 1 && StringUtil.isNotEmpty(moduleColumnCrForm.getBindTable())) {
|
||||
String enCode = "yunzhupaas_" + moduleColumnCrForm.getBindTable() + "_yunzhupaas_" + entity.getEnCode();
|
||||
entity.setEnCode(enCode);
|
||||
}
|
||||
|
||||
if (entity.getFieldRule() == 2 && StringUtil.isNotEmpty(moduleColumnCrForm.getChildTableKey())) {
|
||||
// 得到bean
|
||||
// Object bean = SpringContext.getBean("visualdevServiceImpl");
|
||||
// Object method = ReflectionUtil.invokeMethod(bean, "getTableNameToKey", new
|
||||
// Class[]{String.class}, new Object[]{model.getModuleId()});
|
||||
// Map<String, Object> map = JsonUtil.entityToMap(method);
|
||||
//
|
||||
// String enCode = map.get(moduleColumnCrForm.getBindTable().toLowerCase()) +
|
||||
// "-" + entity.getEnCode();
|
||||
String enCode = moduleColumnCrForm.getChildTableKey() + "-" + entity.getEnCode();
|
||||
entity.setEnCode(enCode);
|
||||
}
|
||||
}
|
||||
if (moduleColumnService.isExistByEnCode(entity.getModuleId(), entity.getEnCode(), entity.getId())) {
|
||||
return ActionResult.fail(MsgCode.EXIST002.get());
|
||||
}
|
||||
moduleColumnService.create(entity);
|
||||
return ActionResult.success(MsgCode.SU001.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新列表权限
|
||||
*
|
||||
* @param id 主键值
|
||||
* @param moduleColumnUpForm 实体对象
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "更新列表权限")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键值", required = true),
|
||||
@Parameter(name = "moduleColumnUpForm", description = "实体对象", required = true)
|
||||
})
|
||||
@SaCheckPermission("system.menu")
|
||||
@PutMapping("/{id}")
|
||||
public ActionResult update(@PathVariable("id") String id,
|
||||
@RequestBody @Valid ModuleColumnUpForm moduleColumnUpForm) {
|
||||
ModuleEntity moduleEntity = moduleService.getInfo(moduleColumnUpForm.getModuleId());
|
||||
ModuleColumnEntity entity = JsonUtil.getJsonToBean(moduleColumnUpForm, ModuleColumnEntity.class);
|
||||
if (moduleEntity != null) {
|
||||
PropertyJsonModel model = JsonUtil.getJsonToBean(moduleEntity.getPropertyJson(), PropertyJsonModel.class);
|
||||
if (model == null) {
|
||||
model = new PropertyJsonModel();
|
||||
}
|
||||
if (entity.getFieldRule() == 1 && StringUtil.isNotEmpty(moduleColumnUpForm.getBindTable())) {
|
||||
String enCode = "yunzhupaas_" + moduleColumnUpForm.getBindTable() + "_yunzhupaas_" + entity.getEnCode();
|
||||
entity.setEnCode(enCode);
|
||||
}
|
||||
|
||||
if (entity.getFieldRule() == 2 && StringUtil.isNotEmpty(moduleColumnUpForm.getChildTableKey())) {
|
||||
// // 得到bean
|
||||
// Object bean = SpringContext.getBean("visualdevServiceImpl");
|
||||
// Object method = ReflectionUtil.invokeMethod(bean, "getTableNameToKey", new
|
||||
// Class[]{String.class}, new Object[]{model.getModuleId()});
|
||||
// Map<String, Object> map = JsonUtil.entityToMap(method);
|
||||
|
||||
// String enCode = map.get(moduleColumnUpForm.getBindTable().toLowerCase()) +
|
||||
// "-" + entity.getEnCode();
|
||||
String enCode = moduleColumnUpForm.getChildTableKey() + "-" + entity.getEnCode();
|
||||
entity.setEnCode(enCode);
|
||||
}
|
||||
}
|
||||
if (moduleColumnService.isExistByEnCode(entity.getModuleId(), entity.getEnCode(), id)) {
|
||||
return ActionResult.fail(MsgCode.EXIST002.get());
|
||||
}
|
||||
boolean flag = moduleColumnService.update(id, entity);
|
||||
if (!flag) {
|
||||
return ActionResult.success(MsgCode.FA002.get());
|
||||
}
|
||||
return ActionResult.success(MsgCode.SU004.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除列表权限
|
||||
*
|
||||
* @param id 主键值
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "删除列表权限")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键值", required = true)
|
||||
})
|
||||
@SaCheckPermission("system.menu")
|
||||
@DeleteMapping("/{id}")
|
||||
public ActionResult delete(@PathVariable("id") String id) {
|
||||
ModuleColumnEntity entity = moduleColumnService.getInfo(id);
|
||||
if (entity != null) {
|
||||
moduleColumnService.delete(entity);
|
||||
return ActionResult.success(MsgCode.SU003.get());
|
||||
}
|
||||
return ActionResult.fail(MsgCode.FA003.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新列表权限状态
|
||||
*
|
||||
* @param id 主键值
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "更新列表权限状态")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键值", required = true)
|
||||
})
|
||||
@SaCheckPermission("system.menu")
|
||||
@PutMapping("/{id}/Actions/State")
|
||||
public ActionResult upState(@PathVariable("id") String id) {
|
||||
ModuleColumnEntity entity = moduleColumnService.getInfo(id);
|
||||
if (entity.getEnabledMark() == null || "1".equals(String.valueOf(entity.getEnabledMark()))) {
|
||||
entity.setEnabledMark(0);
|
||||
} else {
|
||||
entity.setEnabledMark(1);
|
||||
}
|
||||
boolean flag = moduleColumnService.update(id, entity);
|
||||
if (!flag) {
|
||||
return ActionResult.success(MsgCode.FA002.get());
|
||||
}
|
||||
return ActionResult.success(MsgCode.SU004.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量新建
|
||||
*
|
||||
* @param columnBatchForm 权限模型
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "批量新建列表权限")
|
||||
@Parameters({
|
||||
@Parameter(name = "columnBatchForm", description = "权限模型", required = true)
|
||||
})
|
||||
@SaCheckPermission("system.menu")
|
||||
@PostMapping("/Actions/Batch")
|
||||
public ActionResult batchCreate(@RequestBody @Valid ColumnBatchForm columnBatchForm) {
|
||||
List<ModuleColumnEntity> entitys = columnBatchForm.getColumnJson() != null
|
||||
? JsonUtil.getJsonToList(columnBatchForm.getColumnJson(), ModuleColumnEntity.class)
|
||||
: new ArrayList<>();
|
||||
List<String> name = new ArrayList<>();
|
||||
for (ModuleColumnEntity entity : entitys) {
|
||||
entity.setModuleId(columnBatchForm.getModuleId());
|
||||
if (entity.getFieldRule() == 1) {
|
||||
String enCode = "yunzhupaas_" + entity.getBindTable() + "_yunzhupaas_" + entity.getEnCode();
|
||||
entity.setEnCode(enCode);
|
||||
}
|
||||
if (entity.getFieldRule() == 2) {
|
||||
String enCode = entity.getChildTableKey() + "-" + entity.getEnCode();
|
||||
entity.setEnCode(enCode);
|
||||
}
|
||||
if (moduleColumnService.isExistByEnCode(entity.getModuleId(), entity.getEnCode(), null)) {
|
||||
return ActionResult.fail(MsgCode.EXIST002.get());
|
||||
}
|
||||
if (name.contains(entity.getEnCode())) {
|
||||
return ActionResult.fail(MsgCode.EXIST002.get());
|
||||
}
|
||||
name.add(entity.getEnCode());
|
||||
}
|
||||
moduleColumnService.create(entitys);
|
||||
return ActionResult.success(MsgCode.SU001.get());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,954 @@
|
||||
package com.yunzhupaas.base.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import com.yunzhupaas.base.entity.*;
|
||||
import com.yunzhupaas.base.model.online.VisualMenuModel;
|
||||
import com.yunzhupaas.base.service.*;
|
||||
import com.yunzhupaas.base.util.visualUtil.PubulishUtil;
|
||||
import com.yunzhupaas.base.vo.DownloadVO;
|
||||
import com.yunzhupaas.base.vo.PaginationVO;
|
||||
import com.yunzhupaas.config.ConfigValueUtil;
|
||||
import com.yunzhupaas.constant.YunzhupaasConst;
|
||||
import com.yunzhupaas.constant.MsgCode;
|
||||
import com.yunzhupaas.base.model.module.MenuSelectVO;
|
||||
import com.yunzhupaas.database.util.TenantDataSourceUtil;
|
||||
import com.yunzhupaas.exception.WorkFlowException;
|
||||
import com.yunzhupaas.model.AppDataInfoModel;
|
||||
import com.yunzhupaas.model.AppObjectDataModel;
|
||||
import com.yunzhupaas.model.FlowWorkModel;
|
||||
import com.yunzhupaas.model.UserMenuModel;
|
||||
import com.yunzhupaas.model.tenant.*;
|
||||
import com.yunzhupaas.permission.entity.AuthorizeEntity;
|
||||
import com.yunzhupaas.permission.entity.PermissionGroupEntity;
|
||||
import com.yunzhupaas.permission.model.user.UserIdListVo;
|
||||
import com.yunzhupaas.permission.service.AuthorizeService;
|
||||
import com.yunzhupaas.permission.service.PermissionGroupService;
|
||||
import com.yunzhupaas.permission.service.UserService;
|
||||
import com.yunzhupaas.util.*;
|
||||
import com.yunzhupaas.exception.DataException;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import com.yunzhupaas.base.ActionResult;
|
||||
import com.yunzhupaas.base.model.module.*;
|
||||
import com.yunzhupaas.util.context.SpringContext;
|
||||
import com.yunzhupaas.emnus.ModuleTypeEnum;
|
||||
import com.yunzhupaas.util.treeutil.ListToTreeUtil;
|
||||
import com.yunzhupaas.util.treeutil.SumTree;
|
||||
import com.yunzhupaas.util.treeutil.TreeViewModel;
|
||||
import com.yunzhupaas.util.treeutil.newtreeutil.TreeDotUtils;
|
||||
import com.yunzhupaas.base.vo.ListVO;
|
||||
import com.yunzhupaas.util.type.AuthorizeType;
|
||||
import com.yunzhupaas.workflow.service.TemplateApi;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 系统功能
|
||||
*
|
||||
* @author 云筑产品开发平台组
|
||||
* @version V3.1.0
|
||||
* @copyright 深圳市乐程软件有限公司
|
||||
* @date 2023/09/27
|
||||
*/
|
||||
@Tag(name = "系统菜单", description = "menu")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/Menu")
|
||||
public class ModuleController extends SuperController<ModuleService, ModuleEntity> {
|
||||
|
||||
@Autowired
|
||||
private ModuleService moduleService;
|
||||
@Autowired
|
||||
private RedisUtil redisUtil;
|
||||
@Autowired
|
||||
private CacheKeyUtil cacheKeyUtil;
|
||||
|
||||
@Autowired
|
||||
private SystemService systemService;
|
||||
@Autowired
|
||||
private PermissionGroupService permissionGroupApi;
|
||||
@Autowired
|
||||
private ModuleButtonService buttonService;
|
||||
@Autowired
|
||||
private ModuleColumnService columnService;
|
||||
@Autowired
|
||||
private ModuleFormService formService;
|
||||
@Autowired
|
||||
private ModuleDataAuthorizeSchemeService dataAuthorizeSchemeService;
|
||||
@Autowired
|
||||
private AuthorizeService authorizeApi;
|
||||
@Autowired
|
||||
private UserService userApi;
|
||||
@Autowired
|
||||
private ConfigValueUtil configValueUtil;
|
||||
@Autowired
|
||||
private TemplateApi templateApi;
|
||||
@Autowired
|
||||
private PubulishUtil pubulishUtil;
|
||||
|
||||
/**
|
||||
* 获取菜单列表
|
||||
*
|
||||
* @param systemId 系统id
|
||||
* @param paginationMenu 分页参数
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "获取菜单列表")
|
||||
@Parameters({
|
||||
@Parameter(name = "systemId", description = "系统id", required = true)
|
||||
})
|
||||
@GetMapping("/ModuleBySystem/{systemId}")
|
||||
public ActionResult<ListVO<MenuListVO>> list(@PathVariable("systemId") String systemId,
|
||||
PaginationMenu paginationMenu) {
|
||||
List<ModuleEntity> data = moduleService.getList(systemId, paginationMenu.getCategory(),
|
||||
paginationMenu.getKeyword(), paginationMenu.getType(), paginationMenu.getEnabledMark(), null, false);
|
||||
// 递归查上级
|
||||
Map<String, ModuleEntity> moduleEntityMap = data.stream()
|
||||
.collect(Collectors.toMap(ModuleEntity::getId, Function.identity()));
|
||||
if (StringUtil.isNotEmpty(paginationMenu.getKeyword())) {
|
||||
moduleService.getParentModule(data, moduleEntityMap);
|
||||
}
|
||||
List<UserMenuModel> list = JsonUtil.getJsonToList(moduleEntityMap.values(), UserMenuModel.class);
|
||||
list = list.stream()
|
||||
.sorted(Comparator
|
||||
.comparing(UserMenuModel::getSortCode, Comparator.nullsLast(Comparator.naturalOrder()))
|
||||
.thenComparing(UserMenuModel::getCreatorTime, Comparator.nullsLast(Comparator.reverseOrder())))
|
||||
.collect(Collectors.toList());
|
||||
List<SumTree<UserMenuModel>> menuList = TreeDotUtils.convertListToTreeDot(list);
|
||||
List<MenuListVO> menuvo = JsonUtil.getJsonToList(menuList, MenuListVO.class);
|
||||
ListVO vo = new ListVO();
|
||||
vo.setList(menuvo);
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取菜单列表(下拉框)
|
||||
*
|
||||
* @param category 分类
|
||||
* @param id 主键
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "获取菜单列表(下拉框)")
|
||||
@Parameters({
|
||||
@Parameter(name = "category", description = "分类"),
|
||||
@Parameter(name = "id", description = "主键", required = true)
|
||||
})
|
||||
@GetMapping("/Selector/{id}")
|
||||
public ActionResult<ListVO<MenuSelectVO>> treeView(String category, @PathVariable("id") String id) {
|
||||
String systemId = "App".equals(category) ? UserProvider.getUser().getAppSystemId()
|
||||
: UserProvider.getUser().getSystemId();
|
||||
List<ModuleEntity> data = moduleService.getList(systemId, category, null, 1, 1, null, false);
|
||||
if (!"0".equals(id)) {
|
||||
data.remove(moduleService.getInfo(id));
|
||||
}
|
||||
List<UserMenuModel> list = JsonUtil.getJsonToList(data, UserMenuModel.class);
|
||||
List<SumTree<UserMenuModel>> menuList = TreeDotUtils.convertListToTreeDotFilter(list);
|
||||
List<MenuSelectVO> menuvo = JsonUtil.getJsonToList(menuList, MenuSelectVO.class);
|
||||
ListVO vo = new ListVO();
|
||||
vo.setList(menuvo);
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取开发平台菜单
|
||||
*
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "获取开发平台菜单")
|
||||
@GetMapping("/SystemSelector")
|
||||
public ActionResult<ListVO<MenuSelectVO>> mainSystemSelector() {
|
||||
SystemEntity mainSystem = systemService.getInfoByEnCode(YunzhupaasConst.MAIN_SYSTEM_CODE);
|
||||
List<ModuleEntity> data = moduleService.getList(mainSystem.getId(), null, null, null, 1, null, false);
|
||||
List<UserMenuModel> list = JsonUtil.getJsonToList(data, UserMenuModel.class);
|
||||
list.forEach(t -> {
|
||||
if ("-1".equals(t.getParentId())) {
|
||||
t.setParentId(t.getSystemId());
|
||||
}
|
||||
});
|
||||
UserMenuModel userMenuModel = JsonUtil.getJsonToBean(mainSystem, UserMenuModel.class);
|
||||
userMenuModel.setType(0);
|
||||
userMenuModel.setParentId("-1");
|
||||
list.add(userMenuModel);
|
||||
List<SumTree<UserMenuModel>> menuList = TreeDotUtils.convertListToTreeDotFilter(list);
|
||||
List<MenuSelectVO> menuvo = JsonUtil.getJsonToList(menuList, MenuSelectVO.class);
|
||||
ListVO vo = new ListVO();
|
||||
vo.setList(menuvo);
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过系统id获取菜单列表(下拉框)
|
||||
*
|
||||
* @param category 分类
|
||||
* @param id 主键
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "通过系统id获取菜单列表(下拉框)")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true),
|
||||
@Parameter(name = "systemId", description = "系统主键", required = true),
|
||||
@Parameter(name = "enabledMark", description = "查询类型:null-全部,0-禁用,1-启用", required = false)
|
||||
})
|
||||
@GetMapping("/Selector/{id}/{systemId}")
|
||||
public ActionResult<ListVO<MenuSelectAllVO>> treeView(@PathVariable("id") String id,
|
||||
@PathVariable("systemId") String systemId,
|
||||
@RequestParam("category") String category,
|
||||
@RequestParam(value = "enabledMark", required = false) Integer enabledMark) {
|
||||
List<ModuleEntity> data = moduleService.getList(systemId, category, null, 1, enabledMark, null, true);
|
||||
if (!"0".equals(id)) {
|
||||
data.remove(moduleService.getInfo(id));
|
||||
}
|
||||
List<UserMenuModel> list = JsonUtil.getJsonToList(data, UserMenuModel.class);
|
||||
if ("0".equals(systemId)) {
|
||||
List<String> moduleAuthorize = new ArrayList<>();
|
||||
if (configValueUtil.isMultiTenancy()) {
|
||||
TenantAuthorizeModel tenantAuthorizeModel = TenantDataSourceUtil
|
||||
.getCacheModuleAuthorize(UserProvider.getUser().getTenantId());
|
||||
moduleAuthorize = tenantAuthorizeModel.getModuleIdList();
|
||||
}
|
||||
List<SystemEntity> list1 = systemService.getList(null, true, false, true, false, moduleAuthorize);
|
||||
list.forEach(t -> {
|
||||
if ("-1".equals(t.getParentId())) {
|
||||
t.setParentId(t.getSystemId());
|
||||
}
|
||||
});
|
||||
List<UserMenuModel> jsonToList = JsonUtil.getJsonToList(list1, UserMenuModel.class);
|
||||
jsonToList.forEach(t -> {
|
||||
t.setType(0);
|
||||
t.setParentId("-1");
|
||||
});
|
||||
list.addAll(jsonToList);
|
||||
}
|
||||
List<SumTree<UserMenuModel>> menuList = TreeDotUtils.convertListToTreeDotFilter(list);
|
||||
List<MenuSelectAllVO> menuvo = JsonUtil.getJsonToList(menuList, MenuSelectAllVO.class);
|
||||
ListVO vo = new ListVO();
|
||||
vo.setList(menuvo);
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过系统id获取菜单列表(下拉框)
|
||||
*
|
||||
* @param category 分类
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "通过系统id获取菜单列表(下拉框)")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true),
|
||||
@Parameter(name = "systemId", description = "系统主键", required = true)
|
||||
})
|
||||
@GetMapping("/SelectorFilter/{visualId}")
|
||||
public ActionResult<ListVO<MenuSelectAllVO>> SelectorFilter(String category,
|
||||
@PathVariable("visualId") String visualId) {
|
||||
List<ModuleEntity> data = moduleService.getList("0", category, null, 1, 1, null, true);
|
||||
List<ModuleEntity> moduleList = moduleService.getModuleList(visualId);
|
||||
List<String> moduleIds = new ArrayList<>();
|
||||
List<String> systemIds = new ArrayList<>();
|
||||
if (CollectionUtils.isNotEmpty(moduleList)) {
|
||||
for (ModuleEntity item : moduleList) {
|
||||
if ("-1".equals(item.getParentId())) {
|
||||
systemIds.add(item.getSystemId());
|
||||
} else {
|
||||
moduleIds.add(item.getParentId());
|
||||
}
|
||||
}
|
||||
}
|
||||
List<UserMenuModel> list = JsonUtil.getJsonToList(data, UserMenuModel.class);
|
||||
|
||||
List<String> moduleAuthorize = new ArrayList<>();
|
||||
if (configValueUtil.isMultiTenancy()) {
|
||||
TenantAuthorizeModel tenantAuthorizeModel = TenantDataSourceUtil
|
||||
.getCacheModuleAuthorize(UserProvider.getUser().getTenantId());
|
||||
moduleAuthorize = tenantAuthorizeModel.getModuleIdList();
|
||||
}
|
||||
List<SystemEntity> list1 = systemService.getList(null, true, false, true, false, moduleAuthorize);
|
||||
list.forEach(t -> {
|
||||
if ("-1".equals(t.getParentId())) {
|
||||
t.setParentId(t.getSystemId());
|
||||
}
|
||||
});
|
||||
List<UserMenuModel> jsonToList = JsonUtil.getJsonToList(list1, UserMenuModel.class);
|
||||
jsonToList.forEach(t -> {
|
||||
t.setType(0);
|
||||
t.setParentId("-1");
|
||||
});
|
||||
list.addAll(jsonToList);
|
||||
for (UserMenuModel userMenuModel : list) {
|
||||
if (moduleIds.contains(userMenuModel.getId()) || systemIds.contains(userMenuModel.getId())) {
|
||||
userMenuModel.setDisabled(true);
|
||||
}
|
||||
}
|
||||
List<SumTree<UserMenuModel>> menuList = TreeDotUtils.convertListToTreeDotFilter(list);
|
||||
List<MenuSelectAllVO> menuvo = JsonUtil.getJsonToList(menuList, MenuSelectAllVO.class);
|
||||
ListVO vo = new ListVO();
|
||||
vo.setList(menuvo);
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取菜单权限返回权限组
|
||||
*
|
||||
* @param id 主键
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "获取菜单权限返回权限组")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true)
|
||||
})
|
||||
@GetMapping("/getPermissionGroup/{id}")
|
||||
public ActionResult<Map<String, Object>> getPermissionGroup(@PathVariable("id") String id) {
|
||||
Map<String, Object> map = new HashMap<>(2);
|
||||
int type = 0; // 0未开启权限,1有
|
||||
List<FlowWorkModel> list = new ArrayList<>();
|
||||
// 获取当前菜单开启了哪些权限
|
||||
ModuleEntity entity = moduleService.getInfo(id);
|
||||
if (entity == null) {
|
||||
return ActionResult.fail(MsgCode.FA001.get());
|
||||
}
|
||||
// 权限是否被绑定,是否有权限
|
||||
List<ModuleButtonEntity> buttonList = buttonService.getListByModuleIds(id);
|
||||
List<ModuleColumnEntity> columnList = columnService.getList(id);
|
||||
List<ModuleFormEntity> formList = formService.getList(id);
|
||||
List<ModuleDataAuthorizeSchemeEntity> dataAuthorizeList = dataAuthorizeSchemeService.getList(id);
|
||||
if (buttonList.size() > 0 || columnList.size() > 0 || formList.size() > 0 || dataAuthorizeList.size() > 0) {
|
||||
List<AuthorizeEntity> authorizeByItem = authorizeApi.getAuthorizeByItem(AuthorizeType.MODULE,
|
||||
entity.getId());
|
||||
List<String> collect = authorizeByItem.stream().map(AuthorizeEntity::getObjectId)
|
||||
.collect(Collectors.toList());
|
||||
List<PermissionGroupEntity> permissionGroupByUserId = permissionGroupApi.list(collect);
|
||||
list = JsonUtil.getJsonToList(permissionGroupByUserId, FlowWorkModel.class);
|
||||
list.forEach(t -> t.setIcon("icon-ym icon-ym-authGroup"));
|
||||
if (list.size() > 0) {
|
||||
type = 1;
|
||||
} else {
|
||||
type = 2;
|
||||
}
|
||||
}
|
||||
map.put("list", list);
|
||||
map.put("type", type);
|
||||
return ActionResult.success(map);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过权限组id获取相关权限
|
||||
*
|
||||
* @param id 主键
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "通过权限组id获取相关权限")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "权限组id", required = true)
|
||||
})
|
||||
@GetMapping("/getPermission/{id}/{permissionId}")
|
||||
public ActionResult<ModulePermissionVO> getPermission(@PathVariable("id") String id,
|
||||
@PathVariable("permissionId") String permissionId) {
|
||||
// 获取当前菜单开启了哪些权限
|
||||
ModuleEntity entity = moduleService.getInfo(id);
|
||||
if (entity == null) {
|
||||
return ActionResult.fail(MsgCode.FA001.get());
|
||||
}
|
||||
PermissionGroupEntity permissionGroupEntity = permissionGroupApi.info(permissionId);
|
||||
if (permissionGroupEntity == null) {
|
||||
return ActionResult.fail(MsgCode.FA001.get());
|
||||
}
|
||||
// 权限组的权限
|
||||
List<AuthorizeEntity> authList = authorizeApi.getListByObjectId(Collections.singletonList(permissionId));
|
||||
|
||||
ModulePermissionVO modulePermissionVO = new ModulePermissionVO();
|
||||
|
||||
ModulePermissionModel permissionMemberModel = new ModulePermissionModel();
|
||||
permissionMemberModel.setFullName("权限成员");
|
||||
permissionMemberModel.setType(1);
|
||||
List<ModulePermissionModel.ModulePermissionBaseModel> permissionMember = new ArrayList<>();
|
||||
if (StringUtil.isNotEmpty(permissionGroupEntity.getPermissionMember())) {
|
||||
List<UserIdListVo> userIdListVos = userApi
|
||||
.selectedByIds(Arrays.asList(permissionGroupEntity.getPermissionMember().split(",")));
|
||||
permissionMember = JsonUtil.getJsonToList(userIdListVos,
|
||||
ModulePermissionModel.ModulePermissionBaseModel.class);
|
||||
}
|
||||
permissionMemberModel.setList(permissionMember);
|
||||
modulePermissionVO.setPermissionMember(permissionMemberModel);
|
||||
|
||||
ModulePermissionModel moduleButtonPermissionModel = new ModulePermissionModel();
|
||||
moduleButtonPermissionModel.setFullName("按钮权限");
|
||||
List<ModuleButtonEntity> buttonList = buttonService.getListByModuleIds(id);
|
||||
if (buttonList.size() > 0) {
|
||||
int type = 2;
|
||||
List<ModuleButtonEntity> collect = buttonList.stream()
|
||||
.filter(t -> authList.stream().map(AuthorizeEntity::getItemId).collect(Collectors.toList())
|
||||
.contains(t.getId()))
|
||||
.collect(Collectors.toList());
|
||||
List<ModulePermissionModel.ModulePermissionBaseModel> buttonPermissionList = JsonUtil.getJsonToList(collect,
|
||||
ModulePermissionModel.ModulePermissionBaseModel.class);
|
||||
moduleButtonPermissionModel.setList(buttonPermissionList);
|
||||
if (buttonPermissionList.size() > 0) {
|
||||
type = 1;
|
||||
}
|
||||
moduleButtonPermissionModel.setType(type);
|
||||
}
|
||||
modulePermissionVO.setButtonAuthorize(moduleButtonPermissionModel);
|
||||
|
||||
ModulePermissionModel moduleColumnPermissionModel = new ModulePermissionModel();
|
||||
moduleColumnPermissionModel.setFullName("列表权限");
|
||||
List<ModuleColumnEntity> columnList = columnService.getList(id);
|
||||
if (columnList.size() > 0) {
|
||||
int type = 2;
|
||||
List<ModuleColumnEntity> collect = columnList.stream()
|
||||
.filter(t -> authList.stream().map(AuthorizeEntity::getItemId).collect(Collectors.toList())
|
||||
.contains(t.getId()))
|
||||
.collect(Collectors.toList());
|
||||
List<ModulePermissionModel.ModulePermissionBaseModel> buttonPermissionList = JsonUtil.getJsonToList(collect,
|
||||
ModulePermissionModel.ModulePermissionBaseModel.class);
|
||||
moduleColumnPermissionModel.setList(buttonPermissionList);
|
||||
if (buttonPermissionList.size() > 0) {
|
||||
type = 1;
|
||||
}
|
||||
moduleColumnPermissionModel.setType(type);
|
||||
}
|
||||
modulePermissionVO.setColumnAuthorize(moduleColumnPermissionModel);
|
||||
|
||||
ModulePermissionModel moduleFromPermissionModel = new ModulePermissionModel();
|
||||
moduleFromPermissionModel.setFullName("表单权限");
|
||||
List<ModuleFormEntity> formList = formService.getList(id);
|
||||
if (formList.size() > 0) {
|
||||
int type = 2;
|
||||
List<ModuleFormEntity> collect = formList.stream()
|
||||
.filter(t -> authList.stream().map(AuthorizeEntity::getItemId).collect(Collectors.toList())
|
||||
.contains(t.getId()))
|
||||
.collect(Collectors.toList());
|
||||
List<ModulePermissionModel.ModulePermissionBaseModel> buttonPermissionList = JsonUtil.getJsonToList(collect,
|
||||
ModulePermissionModel.ModulePermissionBaseModel.class);
|
||||
moduleFromPermissionModel.setList(buttonPermissionList);
|
||||
if (buttonPermissionList.size() > 0) {
|
||||
type = 1;
|
||||
}
|
||||
moduleFromPermissionModel.setType(type);
|
||||
}
|
||||
modulePermissionVO.setFormAuthorize(moduleFromPermissionModel);
|
||||
|
||||
ModulePermissionModel moduleDataPermissionModel = new ModulePermissionModel();
|
||||
moduleDataPermissionModel.setFullName("数据权限");
|
||||
List<ModuleDataAuthorizeSchemeEntity> dataAuthorizeList = dataAuthorizeSchemeService.getList(id);
|
||||
if (dataAuthorizeList.size() > 0) {
|
||||
int type = 2;
|
||||
List<ModuleDataAuthorizeSchemeEntity> collect = dataAuthorizeList.stream()
|
||||
.filter(t -> authList.stream().map(AuthorizeEntity::getItemId).collect(Collectors.toList())
|
||||
.contains(t.getId()))
|
||||
.collect(Collectors.toList());
|
||||
List<ModulePermissionModel.ModulePermissionBaseModel> buttonPermissionList = JsonUtil.getJsonToList(collect,
|
||||
ModulePermissionModel.ModulePermissionBaseModel.class);
|
||||
moduleDataPermissionModel.setList(buttonPermissionList);
|
||||
if (buttonPermissionList.size() > 0) {
|
||||
type = 1;
|
||||
}
|
||||
moduleDataPermissionModel.setType(type);
|
||||
}
|
||||
modulePermissionVO.setDataAuthorize(moduleDataPermissionModel);
|
||||
|
||||
return ActionResult.success(modulePermissionVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取菜单列表(下拉框)
|
||||
*
|
||||
* @param category 分类
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "获取菜单列表下拉框")
|
||||
@GetMapping("/Selector/All")
|
||||
public ActionResult<ListVO<MenuSelectAllVO>> menuSelect(String category) {
|
||||
List<ModuleEntity> data = moduleService.getList("0", category, null, null, 1, null, false);
|
||||
List<UserMenuModel> list = JsonUtil.getJsonToList(data, UserMenuModel.class);
|
||||
List<String> moduleAuthorize = new ArrayList<>();
|
||||
if (configValueUtil.isMultiTenancy()) {
|
||||
TenantAuthorizeModel tenantAuthorizeModel = TenantDataSourceUtil
|
||||
.getCacheModuleAuthorize(UserProvider.getUser().getTenantId());
|
||||
moduleAuthorize = tenantAuthorizeModel.getModuleIdList();
|
||||
}
|
||||
List<SystemEntity> list1 = systemService.getList(null, true, false, false, false, moduleAuthorize);
|
||||
list.forEach(t -> {
|
||||
t.setHasModule(!"1".equals(String.valueOf(t.getType())));
|
||||
if ("-1".equals(t.getParentId())) {
|
||||
t.setParentId(t.getSystemId());
|
||||
}
|
||||
});
|
||||
List<UserMenuModel> jsonToList = JsonUtil.getJsonToList(list1, UserMenuModel.class);
|
||||
jsonToList.forEach(t -> {
|
||||
t.setType(0);
|
||||
t.setHasModule(false);
|
||||
t.setParentId("-1");
|
||||
});
|
||||
list.addAll(jsonToList);
|
||||
List<SumTree<UserMenuModel>> menuList = TreeDotUtils.convertListToTreeDotFilter(list);
|
||||
List<MenuSelectAllVO> menuvo = JsonUtil.getJsonToList(menuList, MenuSelectAllVO.class);
|
||||
ListVO vo = new ListVO();
|
||||
vo.setList(menuvo);
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 系统功能类别树形
|
||||
*
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "系统功能类别树形")
|
||||
@GetMapping("/{systemId}/TreeView")
|
||||
public ActionResult treeView(@PathVariable("systemId") String systemId) {
|
||||
List<ModuleEntity> moduleList = moduleService.getList(systemId, null, null, null, null, "0", true);
|
||||
List<TreeViewModel> treeList = new ArrayList<>();
|
||||
TreeViewModel treeViewModel = new TreeViewModel();
|
||||
treeViewModel.setId("apply");
|
||||
treeViewModel.setText("软件开发平台");
|
||||
treeViewModel.setParentId("0");
|
||||
treeViewModel.setImg("fa fa-windows apply");
|
||||
treeList.add(treeViewModel);
|
||||
for (ModuleEntity entity : moduleList) {
|
||||
TreeViewModel treeModel = new TreeViewModel();
|
||||
treeModel.setId(entity.getId());
|
||||
treeModel.setText(entity.getFullName());
|
||||
treeModel.setParentId("apply");
|
||||
treeModel.setImg("fa fa-tags");
|
||||
treeList.add(treeModel);
|
||||
}
|
||||
return ActionResult.success(ListToTreeUtil.toTreeView(treeList));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取菜单信息
|
||||
*
|
||||
* @param id 主键值
|
||||
* @return ignore
|
||||
* @throws DataException ignore
|
||||
*/
|
||||
@Operation(summary = "获取菜单信息")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键值", required = true)
|
||||
})
|
||||
@SaCheckPermission("system.menu")
|
||||
@GetMapping("/{id}")
|
||||
public ActionResult<ModuleInfoVO> info(@PathVariable("id") String id) throws DataException {
|
||||
ModuleEntity entity = moduleService.getInfo(id);
|
||||
ModuleInfoVO vo = JsonUtilEx.getJsonToBeanEx(entity, ModuleInfoVO.class);
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新建系统功能
|
||||
*
|
||||
* @param moduleCrForm 实体对象
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "新建系统功能")
|
||||
@Parameters({
|
||||
@Parameter(name = "moduleCrForm", description = "实体对象", required = true)
|
||||
})
|
||||
@SaCheckPermission("system.menu")
|
||||
@PostMapping
|
||||
public ActionResult create(@RequestBody @Valid ModuleCrForm moduleCrForm) {
|
||||
ModuleEntity entity = JsonUtil.getJsonToBean(moduleCrForm, ModuleEntity.class);
|
||||
if (entity.getUrlAddress() != null) {
|
||||
entity.setUrlAddress(entity.getUrlAddress().trim());
|
||||
}
|
||||
if (moduleService.isExistByFullName(entity, moduleCrForm.getCategory(), moduleCrForm.getSystemId())) {
|
||||
return ActionResult.fail(MsgCode.EXIST001.get());
|
||||
}
|
||||
if (moduleService.isExistByEnCode(entity, moduleCrForm.getCategory(), moduleCrForm.getSystemId())) {
|
||||
return ActionResult.fail(MsgCode.EXIST002.get());
|
||||
}
|
||||
moduleService.create(entity);
|
||||
return ActionResult.success(MsgCode.SU001.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新系统功能
|
||||
*
|
||||
* @param id 主键值
|
||||
* @param moduleUpForm 实体对象
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "更新系统功能")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键值", required = true),
|
||||
@Parameter(name = "moduleUpForm", description = "实体对象", required = true)
|
||||
})
|
||||
@SaCheckPermission("system.menu")
|
||||
@PutMapping("/{id}")
|
||||
public ActionResult update(@PathVariable("id") String id, @RequestBody @Valid ModuleUpForm moduleUpForm) {
|
||||
ModuleEntity entity = JsonUtil.getJsonToBean(moduleUpForm, ModuleEntity.class);
|
||||
// 判断如果是目录则不能修改类型
|
||||
ModuleEntity moduleEntity = moduleService.getInfo(id);
|
||||
if (moduleEntity != null && moduleEntity.getType() == 1 && entity.getType() != 1
|
||||
&& moduleService.getList(moduleEntity.getId()).size() > 0) {
|
||||
return ActionResult.fail(MsgCode.SYS016.get());
|
||||
}
|
||||
entity.setId(id);
|
||||
if (entity.getUrlAddress() != null) {
|
||||
entity.setUrlAddress(entity.getUrlAddress().trim());
|
||||
}
|
||||
if (moduleService.isExistByFullName(entity, moduleUpForm.getCategory(), moduleUpForm.getSystemId())) {
|
||||
return ActionResult.fail(MsgCode.EXIST001.get());
|
||||
}
|
||||
if (moduleService.isExistByEnCode(entity, moduleUpForm.getCategory(), moduleUpForm.getSystemId())) {
|
||||
return ActionResult.fail(MsgCode.EXIST002.get());
|
||||
}
|
||||
boolean flag = moduleService.update(id, entity);
|
||||
if (!flag) {
|
||||
return ActionResult.fail(MsgCode.FA002.get());
|
||||
}
|
||||
return ActionResult.success(MsgCode.SU004.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除系统功能
|
||||
*
|
||||
* @param id 主键值
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "删除系统功能")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键值", required = true)
|
||||
})
|
||||
@SaCheckPermission("system.menu")
|
||||
@DeleteMapping("/{id}")
|
||||
public ActionResult delete(@PathVariable("id") String id) {
|
||||
ModuleEntity entity = moduleService.getInfo(id);
|
||||
if (entity != null) {
|
||||
List<ModuleEntity> list = moduleService.getList(false, new ArrayList<>(), new ArrayList<>()).stream()
|
||||
.filter(t -> t.getParentId().equals(entity.getId())).collect(Collectors.toList());
|
||||
if (list.size() > 0) {
|
||||
return ActionResult.fail(MsgCode.SYS017.get());
|
||||
}
|
||||
moduleService.delete(entity);
|
||||
return ActionResult.success(MsgCode.SU003.get());
|
||||
}
|
||||
return ActionResult.fail(MsgCode.FA003.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新菜单状态
|
||||
*
|
||||
* @param id 主键值
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "更新菜单状态")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键值", required = true)
|
||||
})
|
||||
@SaCheckPermission("system.menu")
|
||||
@PutMapping("/{id}/Actions/State")
|
||||
public ActionResult upState(@PathVariable("id") String id) {
|
||||
ModuleEntity entity = moduleService.getInfo(id);
|
||||
if (entity != null) {
|
||||
if (entity.getEnabledMark() == null || "1".equals(String.valueOf(entity.getEnabledMark()))) {
|
||||
entity.setEnabledMark(0);
|
||||
} else {
|
||||
entity.setEnabledMark(1);
|
||||
}
|
||||
moduleService.update(id, entity);
|
||||
// 清除redis权限
|
||||
String cacheKey = cacheKeyUtil.getUserAuthorize() + UserProvider.getUser().getUserId();
|
||||
if (redisUtil.exists(cacheKey)) {
|
||||
redisUtil.remove(cacheKey);
|
||||
}
|
||||
return ActionResult.success(MsgCode.SU004.get());
|
||||
}
|
||||
return ActionResult.fail(MsgCode.FA002.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 系统菜单导出功能
|
||||
*
|
||||
* @param id 接口id
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "导出系统菜单数据")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键值", required = true)
|
||||
})
|
||||
@SaCheckPermission("system.menu")
|
||||
@GetMapping("/{id}/Actions/Export")
|
||||
public ActionResult exportFile(@PathVariable("id") String id) {
|
||||
DownloadVO downloadVO = moduleService.exportData(id);
|
||||
return ActionResult.success(downloadVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 系统菜单导入功能
|
||||
*
|
||||
* @param systemId 系统id
|
||||
* @param multipartFile 文件
|
||||
* @param parentId 父级id
|
||||
* @param category 分类
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "系统菜单导入功能")
|
||||
@Parameters({
|
||||
@Parameter(name = "systemId", description = "系统id", required = true),
|
||||
})
|
||||
@SaCheckPermission("system.menu")
|
||||
@PostMapping(value = "/{systemId}/Actions/Import", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
public ActionResult importFile(@PathVariable("systemId") String systemId,
|
||||
@RequestPart("file") MultipartFile multipartFile,
|
||||
@RequestParam("parentId") String parentId,
|
||||
@RequestParam("category") String category,
|
||||
@RequestParam("type") Integer type) throws DataException {
|
||||
// 判断是否为.bm结尾
|
||||
if (FileUtil.existsSuffix(multipartFile, ModuleTypeEnum.SYSTEM_MODULE.getTableName())) {
|
||||
return ActionResult.fail(MsgCode.IMP002.get());
|
||||
}
|
||||
try {
|
||||
// 读取文件内容
|
||||
String fileContent = FileUtil.getFileContent(multipartFile);
|
||||
// 转model后导入
|
||||
ModuleExportModel exportModel = JsonUtil.getJsonToBean(fileContent, ModuleExportModel.class);
|
||||
ModuleEntity moduleEntity = exportModel.getModuleEntity();
|
||||
if (!category.equals(moduleEntity.getCategory())) {
|
||||
return ActionResult.fail(MsgCode.SYS018.get(category.toUpperCase()));
|
||||
}
|
||||
if ("App".equals(moduleEntity.getCategory()) && "-1".equals(parentId)) {
|
||||
return ActionResult.fail(MsgCode.SYS019.get());
|
||||
}
|
||||
// 设置系统id然后重新赋值
|
||||
moduleEntity.setSystemId(systemId);
|
||||
moduleEntity.setParentId(parentId);
|
||||
// 清空同步菜单记录 避免重复
|
||||
moduleEntity.setModuleId(null);
|
||||
moduleEntity.setCreatorTime(new Date());
|
||||
// String enCode = moduleEntity.getEnCode();
|
||||
// moduleEntity.setEnCode(moduleEntity.getEnCode() + "_" +
|
||||
// RandomUtil.getRandomCode());
|
||||
// if (moduleEntity.getType() == 3) {
|
||||
// moduleEntity.setUrlAddress(moduleEntity.getUrlAddress().replace(enCode,
|
||||
// moduleEntity.getEnCode()));
|
||||
// }
|
||||
exportModel.setModuleEntity(moduleEntity);
|
||||
return moduleService.importData(exportModel, type);
|
||||
} catch (Exception e) {
|
||||
throw new DataException(MsgCode.IMP004.get());
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------多租户调用
|
||||
/**
|
||||
* 通过租户id获取菜单
|
||||
*
|
||||
* @param tenantMenuModel 模型
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "通过租户id获取菜单")
|
||||
@Parameters({
|
||||
@Parameter(name = "tenantMenuModel", description = "模型", required = true)
|
||||
})
|
||||
@NoDataSourceBind
|
||||
@PostMapping("/Tenant/Menu")
|
||||
public TenantMenuVO menu(@RequestBody TenantMenuModel tenantMenuModel) throws DataException {
|
||||
if (configValueUtil.isMultiTenancy()) {
|
||||
TenantDataSourceUtil.switchTenant(tenantMenuModel.getTenantId());
|
||||
}
|
||||
List<SystemEntity> systemEntityList = systemService.getList();
|
||||
List<String> ids = new ArrayList<>();
|
||||
if (Objects.nonNull(tenantMenuModel.getIds())) {
|
||||
ids = tenantMenuModel.getIds();
|
||||
}
|
||||
List<String> urlAddressList = new ArrayList<>();
|
||||
if (Objects.nonNull(tenantMenuModel.getIds())) {
|
||||
urlAddressList = tenantMenuModel.getUrlAddressList();
|
||||
}
|
||||
List<ModuleEntity> moduleEntityList = moduleService.getList(true, new ArrayList<>(), new ArrayList<>());
|
||||
TenantMenuVO module = module(systemEntityList, moduleEntityList, ids, urlAddressList);
|
||||
return module;
|
||||
}
|
||||
|
||||
/**
|
||||
* 功能权限
|
||||
*
|
||||
* @param moduleEntityList 所有菜单
|
||||
* @param systemEntityList 所有应用
|
||||
* @return
|
||||
*/
|
||||
private TenantMenuVO module(List<SystemEntity> systemEntityList, List<ModuleEntity> moduleEntityList,
|
||||
List<String> ids, List<String> urlAddressList) {
|
||||
TenantMenuVO vo = new TenantMenuVO();
|
||||
// 转树前所有数据
|
||||
List<TenantMenuTreeModel> moduleAllList = new ArrayList<>();
|
||||
List<TenantMenuTreeModel> systemList = JsonUtil.getJsonToList(systemEntityList, TenantMenuTreeModel.class);
|
||||
systemList.forEach(t -> t.setParentId("-1"));
|
||||
moduleAllList.addAll(systemList);
|
||||
Map<String, List<ModuleEntity>> moduleMap = moduleEntityList.stream().collect(Collectors.groupingBy(t -> {
|
||||
if ("Web".equals(t.getCategory())) {
|
||||
return "Web";
|
||||
} else {
|
||||
return "App";
|
||||
}
|
||||
}));
|
||||
List<ModuleEntity> webModuleList = moduleMap.get("Web") == null ? new ArrayList<>() : moduleMap.get("Web");
|
||||
List<ModuleEntity> appModuleList = moduleMap.get("App") == null ? new ArrayList<>() : moduleMap.get("App");
|
||||
Map<String, ModuleEntity> appModuleMap = appModuleList.stream()
|
||||
.collect(Collectors.toMap(ModuleEntity::getId, Function.identity()));
|
||||
Map<String, String> webIds = new HashMap<>(16);
|
||||
List<ModuleEntity> temWebList = webModuleList.stream().filter(t -> "-1".equals(t.getParentId()))
|
||||
.collect(Collectors.toList());
|
||||
temWebList.stream().filter(t -> "-1".equals(t.getParentId())).forEach(t -> {
|
||||
if (!webIds.containsKey(t.getSystemId())) {
|
||||
ModuleEntity webData = new ModuleEntity();
|
||||
webData.setId(t.getSystemId() + "1");
|
||||
t.setParentId(webData.getId());
|
||||
webData.setFullName("WEB菜单");
|
||||
webData.setIcon("icon-ym icon-ym-pc");
|
||||
webData.setParentId(t.getSystemId());
|
||||
webData.setSystemId(t.getSystemId());
|
||||
webModuleList.add(webData);
|
||||
webIds.put(t.getSystemId(), webData.getId());
|
||||
} else {
|
||||
t.setParentId(webIds.get(t.getSystemId()) + "");
|
||||
}
|
||||
});
|
||||
List<TenantMenuTreeModel> webReturnModuleList = JsonUtil.getJsonToList(webModuleList,
|
||||
TenantMenuTreeModel.class);
|
||||
moduleAllList.addAll(webReturnModuleList);
|
||||
// 处理App菜单
|
||||
List<ModuleEntity> temList = appModuleList.stream()
|
||||
.filter(t -> "-1".equals(t.getParentId()) && !YunzhupaasConst.MAIN_SYSTEM_CODE.equals(t.getEnCode()))
|
||||
.collect(Collectors.toList());
|
||||
Map<String, String> appIds = new HashMap<>(16);
|
||||
for (ModuleEntity appModuleEntity : temList) {
|
||||
if (StringUtil.isEmpty(appIds.get(appModuleEntity.getSystemId()))) {
|
||||
ModuleEntity appData = new ModuleEntity();
|
||||
appData.setId(appModuleEntity.getSystemId() + appModuleEntity.getSystemId() + "2");
|
||||
appModuleEntity.setParentId(appData.getId());
|
||||
appData.setFullName("APP菜单");
|
||||
appData.setIcon("icon-ym icon-ym-mobile");
|
||||
appData.setParentId(appModuleEntity.getSystemId());
|
||||
appData.setSystemId(appModuleEntity.getSystemId());
|
||||
appModuleList.add(appData);
|
||||
appIds.put(appModuleEntity.getSystemId(), appData.getId());
|
||||
} else {
|
||||
appModuleList.remove(appModuleEntity);
|
||||
ModuleEntity entity = appModuleMap.get(appModuleEntity.getId());
|
||||
entity.setParentId(appIds.get(appModuleEntity.getSystemId()));
|
||||
appModuleList.add(entity);
|
||||
}
|
||||
}
|
||||
List<TenantMenuTreeModel> appReturnModuleList = JsonUtil.getJsonToList(appModuleList,
|
||||
TenantMenuTreeModel.class);
|
||||
moduleAllList.addAll(appReturnModuleList);
|
||||
List<SumTree<TenantMenuTreeModel>> sumTrees = TreeDotUtils.convertListToTreeDot(moduleAllList);
|
||||
List<TenantMenuTreeReturnModel> data = new ArrayList<>();
|
||||
TenantMenuTreeReturnModel workFlowEnabled = new TenantMenuTreeReturnModel();
|
||||
workFlowEnabled.setId("-999");
|
||||
workFlowEnabled.setFullName("协同办公");
|
||||
data.add(workFlowEnabled);
|
||||
data.addAll(JsonUtil.getJsonToList(sumTrees, TenantMenuTreeReturnModel.class));
|
||||
vo.setList(data);
|
||||
List<String> allId = moduleAllList.stream().map(TenantMenuTreeModel::getId).collect(Collectors.toList());
|
||||
allId.add(workFlowEnabled.getId());
|
||||
vo.setAll(allId);
|
||||
List<String> ids0 = moduleService.getListByUrlAddress(ids, urlAddressList).stream().map(ModuleEntity::getId)
|
||||
.collect(Collectors.toList());
|
||||
List<String> selectorIds = allId.stream().filter(t -> !ids0.contains(t)).collect(Collectors.toList());
|
||||
if (ids.contains("-999")) {
|
||||
selectorIds.remove("-999");
|
||||
}
|
||||
vo.setIds(selectorIds);
|
||||
return vo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过租户id及菜单id获取菜单
|
||||
*
|
||||
* @param tenantMenuModel 模型
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "通过租户id及菜单id获取菜单")
|
||||
@Parameters({
|
||||
@Parameter(name = "tenantMenuModel", description = "模型", required = true)
|
||||
})
|
||||
@NoDataSourceBind
|
||||
@PostMapping("/Tenant/MenuByIds")
|
||||
public Map MenuByIds(@RequestBody TenantMenuModel tenantMenuModel) throws DataException {
|
||||
if (configValueUtil.isMultiTenancy()) {
|
||||
TenantDataSourceUtil.switchTenant(tenantMenuModel.getTenantId());
|
||||
}
|
||||
List<ModuleEntity> list = moduleService.getList();
|
||||
return list.stream().collect(Collectors.toMap(ModuleEntity::getId, ModuleEntity::getUrlAddress));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取在线开发“表单”和“流程”类型的菜单数据
|
||||
*/
|
||||
@Operation(summary = "菜单获取表单列表")
|
||||
@GetMapping("/Selector/Form")
|
||||
@Parameters({
|
||||
@Parameter(name = "systemId", description = "系统id", required = false),
|
||||
})
|
||||
public ActionResult getFormList(ModulePagination pagination) {
|
||||
List<ModuleSelectorVo> list = moduleService.getFormMenuList(pagination);
|
||||
list.stream().forEach(t -> {
|
||||
t.setTypeName(Objects.equals(t.getType(), 3) ? "表单" : "流程");
|
||||
PropertyJsonModel model = JsonUtil.getJsonToBean(t.getPropertyJson(), PropertyJsonModel.class);
|
||||
if (Objects.equals(t.getType(), 3)) {
|
||||
t.setFormId(model.getModuleId());
|
||||
} else {
|
||||
t.setFlowId(model.getModuleId());
|
||||
t.setFormId(templateApi.getFormByFlowId(model.getModuleId()));
|
||||
}
|
||||
});
|
||||
PaginationVO paginationVO = JsonUtil.getJsonToBean(pagination, PaginationVO.class);
|
||||
return ActionResult.page(list, paginationVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 报表发布菜单
|
||||
*
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "报表发布菜单")
|
||||
@Parameters({
|
||||
@Parameter(name = "menuModel", description = "模型", required = true)
|
||||
})
|
||||
@PostMapping("/saveReportMenu")
|
||||
public ActionResult saveReportMenu(@RequestBody VisualMenuModel menuModel) {
|
||||
try {
|
||||
pubulishUtil.publishMenu(menuModel);
|
||||
return ActionResult.success();
|
||||
} catch (WorkFlowException e) {
|
||||
return ActionResult.fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 报表发布菜单
|
||||
*
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "获取报表发布菜单")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键值", required = true)
|
||||
})
|
||||
@PostMapping("/getReportMenu")
|
||||
public ActionResult getReportMenu(@RequestBody VisualMenuModel menuModel) {
|
||||
ModuleNameVO moduleNameVO = moduleService.getModuleNameList(menuModel.getId());
|
||||
return ActionResult.success(moduleNameVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取系统菜单列表(下拉树形)
|
||||
*/
|
||||
@Operation(summary = "获取系统菜单列表(下拉树形)")
|
||||
@GetMapping("/getSystemMenu")
|
||||
public ActionResult<List<MenuSelectAllVO>> getSystemMenu() {
|
||||
List<MenuSelectAllVO> systemMenu = moduleService.getSystemMenu(3, Arrays.asList(2, 4), Arrays.asList("web"));
|
||||
return ActionResult.success(systemMenu);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,315 @@
|
||||
package com.yunzhupaas.base.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import com.yunzhupaas.base.controller.SuperController;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import com.yunzhupaas.base.ActionResult;
|
||||
import com.yunzhupaas.base.entity.ModuleDataAuthorizeSchemeEntity;
|
||||
import com.yunzhupaas.base.entity.ModuleEntity;
|
||||
import com.yunzhupaas.base.model.module.PropertyJsonModel;
|
||||
import com.yunzhupaas.base.service.ModuleDataAuthorizeSchemeService;
|
||||
import com.yunzhupaas.base.service.ModuleDataAuthorizeService;
|
||||
import com.yunzhupaas.base.service.ModuleService;
|
||||
import com.yunzhupaas.base.vo.ListVO;
|
||||
import com.yunzhupaas.base.entity.ModuleDataAuthorizeEntity;
|
||||
import com.yunzhupaas.constant.MsgCode;
|
||||
import com.yunzhupaas.emnus.SearchMethodEnum;
|
||||
import com.yunzhupaas.exception.DataException;
|
||||
import com.yunzhupaas.base.model.moduledataauthorize.DataAuthorizeCrForm;
|
||||
import com.yunzhupaas.base.model.moduledataauthorize.DataAuthorizeInfoVO;
|
||||
import com.yunzhupaas.base.model.moduledataauthorize.DataAuthorizeListVO;
|
||||
import com.yunzhupaas.base.model.moduledataauthorize.DataAuthorizeUpForm;
|
||||
import com.yunzhupaas.model.*;
|
||||
import com.yunzhupaas.model.visualJson.FieLdsModel;
|
||||
import com.yunzhupaas.model.visualJson.FormCloumnUtil;
|
||||
import com.yunzhupaas.model.visualJson.FormDataModel;
|
||||
import com.yunzhupaas.model.visualJson.TableModel;
|
||||
import com.yunzhupaas.model.visualJson.analysis.*;
|
||||
import com.yunzhupaas.permission.model.authorize.AuthorizeConditionEnum;
|
||||
import com.yunzhupaas.permission.model.authorize.ConditionModel;
|
||||
import com.yunzhupaas.util.JsonUtil;
|
||||
import com.yunzhupaas.util.JsonUtilEx;
|
||||
import com.yunzhupaas.util.ReflectionUtil;
|
||||
import com.yunzhupaas.util.StringUtil;
|
||||
import com.yunzhupaas.util.context.SpringContext;
|
||||
import org.apache.commons.collections4.map.HashedMap;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.StringJoiner;
|
||||
|
||||
/**
|
||||
* 数据权限配置
|
||||
*
|
||||
* @author 云筑产品开发平台组
|
||||
* @version V3.1.0
|
||||
* @copyright 深圳市乐程软件有限公司
|
||||
* @date 2023/09/27
|
||||
*/
|
||||
@Tag(name = "数据权限字段管理", description = "ModuleDataAuthorize")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/ModuleDataAuthorize")
|
||||
public class ModuleDataAuthorizeController
|
||||
extends SuperController<ModuleDataAuthorizeService, ModuleDataAuthorizeEntity> {
|
||||
|
||||
@Autowired
|
||||
private ModuleDataAuthorizeService dataAuthorizeService;
|
||||
@Autowired
|
||||
private ModuleDataAuthorizeSchemeService dataAuthorizeSchemeService;
|
||||
@Autowired
|
||||
private ModuleService moduleService;
|
||||
|
||||
/**
|
||||
* 获取数据权限配置信息列表
|
||||
*
|
||||
* @param moduleId 功能主键
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "获取字段列表")
|
||||
@Parameters({
|
||||
@Parameter(name = "moduleId", description = "功能主键", required = true)
|
||||
})
|
||||
@SaCheckPermission("system.menu")
|
||||
@GetMapping("/{moduleId}/List")
|
||||
public ActionResult<ListVO<DataAuthorizeListVO>> list(@PathVariable("moduleId") String moduleId) {
|
||||
List<ModuleDataAuthorizeEntity> data = dataAuthorizeService.getList(moduleId);
|
||||
List<DataAuthorizeListVO> list = JsonUtil.getJsonToList(data, DataAuthorizeListVO.class);
|
||||
list.stream().forEach(t -> {
|
||||
String conditionSymbol = StringUtil.isNotEmpty(t.getConditionSymbol()) ? t.getConditionSymbol() : "";
|
||||
StringJoiner symbolJoiner = new StringJoiner(",");
|
||||
String[] symbolSplit = conditionSymbol.split(",");
|
||||
for (String id : symbolSplit) {
|
||||
SearchMethodEnum itemMethod = SearchMethodEnum.getSearchMethod(id);
|
||||
if (itemMethod != null) {
|
||||
symbolJoiner.add(itemMethod.getMessage());
|
||||
}
|
||||
}
|
||||
t.setConditionText(StringUtil.isNotEmpty(t.getConditionText()) ? t.getConditionText() : "");
|
||||
StringJoiner textJoiner = new StringJoiner(",");
|
||||
String conditionText = StringUtil.isNotEmpty(t.getConditionText()) ? t.getConditionText() : "";
|
||||
String[] textSplit = conditionText.split(",");
|
||||
for (String id : textSplit) {
|
||||
AuthorizeConditionEnum itemMethod = AuthorizeConditionEnum.getByMessage(id);
|
||||
if (itemMethod != null) {
|
||||
textJoiner.add(itemMethod.getMessage());
|
||||
}
|
||||
}
|
||||
t.setConditionSymbolName(symbolJoiner.toString());
|
||||
t.setConditionName(textJoiner.toString());
|
||||
if (StringUtil.isNotEmpty(t.getBindTable())) {
|
||||
t.setEnCode(
|
||||
StringUtil.isNotEmpty(t.getEnCode()) ? t.getEnCode().replace(t.getBindTable() + ".", "") : "");
|
||||
}
|
||||
});
|
||||
|
||||
ListVO<DataAuthorizeListVO> vo = new ListVO<>();
|
||||
vo.setList(list);
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 菜单数据权限
|
||||
*
|
||||
* @param moduleId 功能主键
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "菜单数据权限")
|
||||
@Parameters({
|
||||
@Parameter(name = "moduleId", description = "功能主键", required = true)
|
||||
})
|
||||
@SaCheckPermission("system.menu")
|
||||
@GetMapping("/{moduleId}/FieldList")
|
||||
public ActionResult<List<Map<String, String>>> fieldList(@PathVariable("moduleId") String moduleId) {
|
||||
List<Map<String, String>> list = new ArrayList<>();
|
||||
// 得到菜单id
|
||||
ModuleEntity entity = moduleService.getInfo(moduleId);
|
||||
PropertyJsonModel model = JsonUtil.getJsonToBean(entity.getPropertyJson(), PropertyJsonModel.class);
|
||||
if (model == null) {
|
||||
model = new PropertyJsonModel();
|
||||
}
|
||||
// 得到bean
|
||||
Object bean = SpringContext.getBean("visualdevServiceImpl");
|
||||
Object method = ReflectionUtil.invokeMethod(bean, "getInfo", new Class[] { String.class },
|
||||
new Object[] { model.getModuleId() });
|
||||
Map<String, Object> map = JsonUtil.entityToMap(method);
|
||||
if (map != null && map.containsKey("formData")) {
|
||||
FormDataModel formDataModel = JsonUtil.getJsonToBean(String.valueOf(map.get("formData")),
|
||||
FormDataModel.class);
|
||||
List<FieLdsModel> fieLdsModelList = JsonUtil.getJsonToList(formDataModel.getFields(), FieLdsModel.class);
|
||||
RecursionForm recursionForm = new RecursionForm();
|
||||
recursionForm.setList(fieLdsModelList);
|
||||
recursionForm
|
||||
.setTableModelList(JsonUtil.getJsonToList(String.valueOf(map.get("tables")), TableModel.class));
|
||||
List<FormAllModel> formAllModel = new ArrayList<>();
|
||||
FormCloumnUtil.recursionForm(recursionForm, formAllModel);
|
||||
for (FormAllModel allModel : formAllModel) {
|
||||
if (FormEnum.table.getMessage().equals(allModel.getYunzhupaasKey())) {
|
||||
FormColumnTableModel childList = allModel.getChildList();
|
||||
List<FormColumnModel> childList1 = childList.getChildList();
|
||||
for (FormColumnModel formColumnModel : childList1) {
|
||||
FieLdsModel fieLdsModel = formColumnModel.getFieLdsModel();
|
||||
if (StringUtil.isNotEmpty(fieLdsModel.getVModel())) {
|
||||
Map<String, String> map1 = new HashedMap<>();
|
||||
map1.put("field", fieLdsModel.getVModel());
|
||||
map1.put("fieldName", fieLdsModel.getConfig().getLabel());
|
||||
list.add(map1);
|
||||
}
|
||||
}
|
||||
} else if (FormEnum.mast.getMessage().equals(allModel.getYunzhupaasKey())) {
|
||||
FormColumnModel formColumnModel = allModel.getFormColumnModel();
|
||||
FieLdsModel fieLdsModel = formColumnModel.getFieLdsModel();
|
||||
if (StringUtil.isNotEmpty(fieLdsModel.getVModel())) {
|
||||
Map<String, String> map1 = new HashedMap<>();
|
||||
map1.put("field", fieLdsModel.getVModel());
|
||||
map1.put("fieldName", fieLdsModel.getConfig().getLabel());
|
||||
list.add(map1);
|
||||
}
|
||||
} else if (FormEnum.mastTable.getMessage().equals(allModel.getYunzhupaasKey())) {
|
||||
FormMastTableModel formColumnModel = allModel.getFormMastTableModel();
|
||||
FieLdsModel fieLdsModel = formColumnModel.getMastTable().getFieLdsModel();
|
||||
if (StringUtil.isNotEmpty(fieLdsModel.getVModel())) {
|
||||
Map<String, String> map1 = new HashedMap<>();
|
||||
map1.put("field", fieLdsModel.getVModel());
|
||||
map1.put("fieldName", fieLdsModel.getConfig().getLabel());
|
||||
list.add(map1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return ActionResult.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取数据权限配置信息
|
||||
*
|
||||
* @param id 主键值
|
||||
* @return ignore
|
||||
* @throws DataException ignore
|
||||
*/
|
||||
@Operation(summary = "获取数据权限配置信息")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键值", required = true)
|
||||
})
|
||||
@SaCheckPermission("system.menu")
|
||||
@GetMapping("/{id}")
|
||||
public ActionResult<DataAuthorizeInfoVO> info(@PathVariable("id") String id) throws DataException {
|
||||
ModuleDataAuthorizeEntity entity = dataAuthorizeService.getInfo(id);
|
||||
ModuleEntity moduleEntity = moduleService.getInfo(entity.getModuleId());
|
||||
if (moduleEntity != null && StringUtil.isNotEmpty(entity.getBindTable())) {
|
||||
entity.setEnCode(StringUtil.isNotEmpty(entity.getEnCode())
|
||||
? entity.getEnCode().replace(entity.getBindTable() + ".", "")
|
||||
: "");
|
||||
}
|
||||
DataAuthorizeInfoVO vo = JsonUtilEx.getJsonToBeanEx(entity, DataAuthorizeInfoVO.class);
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新建数据权限配置
|
||||
*
|
||||
* @param dataAuthorizeCrForm 实体对象
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "新建数据权限配置")
|
||||
@Parameters({
|
||||
@Parameter(name = "dataAuthorizeCrForm", description = "实体对象", required = true)
|
||||
})
|
||||
@SaCheckPermission("system.menu")
|
||||
@PostMapping
|
||||
public ActionResult create(@RequestBody @Valid DataAuthorizeCrForm dataAuthorizeCrForm) {
|
||||
ModuleEntity moduleEntity = moduleService.getInfo(dataAuthorizeCrForm.getModuleId());
|
||||
ModuleDataAuthorizeEntity entity = JsonUtil.getJsonToBean(dataAuthorizeCrForm, ModuleDataAuthorizeEntity.class);
|
||||
entity.setPropertyJson(dataAuthorizeCrForm.getChildTableKey());
|
||||
if (moduleEntity != null && moduleEntity.getType() == 3 && entity.getFieldRule() != 0
|
||||
&& StringUtil.isNotEmpty(entity.getBindTable())) {
|
||||
String enCode = entity.getBindTable() + "." + entity.getEnCode();
|
||||
entity.setEnCode(enCode);
|
||||
}
|
||||
dataAuthorizeService.create(entity);
|
||||
return ActionResult.success(MsgCode.SU001.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新数据权限配置
|
||||
*
|
||||
* @param id 主键值
|
||||
* @param dataAuthorizeUpForm 实体对象
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "更新数据权限配置")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键值", required = true),
|
||||
@Parameter(name = "dataAuthorizeUpForm", description = "实体对象", required = true)
|
||||
})
|
||||
@SaCheckPermission("system.menu")
|
||||
@PutMapping("/{id}")
|
||||
public ActionResult update(@PathVariable("id") String id,
|
||||
@RequestBody @Valid DataAuthorizeUpForm dataAuthorizeUpForm) {
|
||||
ModuleEntity moduleEntity = moduleService.getInfo(dataAuthorizeUpForm.getModuleId());
|
||||
ModuleDataAuthorizeEntity entity = JsonUtil.getJsonToBean(dataAuthorizeUpForm, ModuleDataAuthorizeEntity.class);
|
||||
if (moduleEntity != null && moduleEntity.getType() == 3 && entity.getFieldRule() == 1
|
||||
&& StringUtil.isNotEmpty(entity.getBindTable())) {
|
||||
String enCode = entity.getBindTable() + "." + entity.getEnCode();
|
||||
entity.setEnCode(enCode);
|
||||
}
|
||||
entity.setPropertyJson(dataAuthorizeUpForm.getChildTableKey());
|
||||
boolean flag = dataAuthorizeService.update(id, entity);
|
||||
if (!flag) {
|
||||
return ActionResult.success(MsgCode.FA002.get());
|
||||
}
|
||||
return ActionResult.success(MsgCode.SU004.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除数据权限配置
|
||||
*
|
||||
* @param id 主键值
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "删除数据权限配置")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键值", required = true)
|
||||
})
|
||||
@SaCheckPermission("system.menu")
|
||||
@DeleteMapping("/{id}")
|
||||
public ActionResult delete(@PathVariable("id") String id) {
|
||||
ModuleDataAuthorizeEntity entity = dataAuthorizeService.getInfo(id);
|
||||
// 菜单id
|
||||
String moduleId = entity.getModuleId();
|
||||
// 该菜单下的数据权限方案
|
||||
List<ModuleDataAuthorizeSchemeEntity> list = dataAuthorizeSchemeService.getList(moduleId);
|
||||
|
||||
String schemeName = null;
|
||||
for (ModuleDataAuthorizeSchemeEntity schemeEntity : list) {
|
||||
List<ConditionModel> conditionModels = JsonUtil.getJsonToList(schemeEntity.getConditionJson(),
|
||||
ConditionModel.class);
|
||||
if (conditionModels != null) {
|
||||
for (ConditionModel conditionModel : conditionModels) {
|
||||
List<ConditionModel.ConditionItemModel> groups = conditionModel.getGroups();
|
||||
for (ConditionModel.ConditionItemModel conditionItemModel : groups) {
|
||||
if (conditionItemModel.getField().equalsIgnoreCase(entity.getEnCode())) {
|
||||
schemeName = schemeEntity.getFullName();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (StringUtil.isNotEmpty(schemeName)) {
|
||||
return ActionResult.fail(MsgCode.SYS020.get(schemeName));
|
||||
}
|
||||
if (entity != null) {
|
||||
dataAuthorizeService.delete(entity);
|
||||
return ActionResult.success(MsgCode.SU003.get());
|
||||
}
|
||||
return ActionResult.fail(MsgCode.FA003.get());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,187 @@
|
||||
package com.yunzhupaas.base.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.google.common.base.CaseFormat;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import com.yunzhupaas.base.ActionResult;
|
||||
import com.yunzhupaas.base.Pagination;
|
||||
import com.yunzhupaas.base.entity.ModuleDataAuthorizeLinkEntity;
|
||||
import com.yunzhupaas.base.entity.ModuleEntity;
|
||||
import com.yunzhupaas.base.model.dbtable.vo.DbFieldVO;
|
||||
import com.yunzhupaas.base.model.module.PropertyJsonModel;
|
||||
import com.yunzhupaas.base.model.moduledataauthorize.DataAuthorizeLinkForm;
|
||||
import com.yunzhupaas.base.model.moduledataauthorize.DataAuthorizeTableNameVO;
|
||||
import com.yunzhupaas.base.service.DbTableService;
|
||||
import com.yunzhupaas.base.service.ModuleDataAuthorizeLinkDataService;
|
||||
import com.yunzhupaas.base.service.ModuleService;
|
||||
import com.yunzhupaas.base.vo.PaginationVO;
|
||||
import com.yunzhupaas.constant.MsgCode;
|
||||
import com.yunzhupaas.database.model.dbfield.DbFieldModel;
|
||||
import com.yunzhupaas.model.visualJson.TableModel;
|
||||
import com.yunzhupaas.util.*;
|
||||
import com.yunzhupaas.util.context.SpringContext;
|
||||
import com.yunzhupaas.workflow.service.TemplateApi;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 数据权限字段管理 数据连接
|
||||
*
|
||||
* @author 云筑产品开发平台组
|
||||
* @version V3.4.2
|
||||
* @copyright 深圳市乐程软件有限公司(http://www.szlecheng.cn)
|
||||
* @date 2024/6/7
|
||||
*/
|
||||
@Tag(name = "数据权限字段管理数据连接" , description = "ModuleDataAuthorizeLink")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/ModuleDataAuthorizeLink")
|
||||
public class ModuleDataAuthorizeLinkController {
|
||||
|
||||
@Autowired
|
||||
private ModuleDataAuthorizeLinkDataService linkDataService;
|
||||
@Autowired
|
||||
private ModuleService moduleService;
|
||||
@Autowired
|
||||
private DbTableService dbTableService;
|
||||
@Autowired
|
||||
private TemplateApi templateApi;
|
||||
|
||||
/**
|
||||
* 页面参数
|
||||
*
|
||||
* @param linkForm 页面参数
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "保存编辑数据连接")
|
||||
@Parameters({
|
||||
@Parameter(name = "linkForm", description = "页面参数", required = true)
|
||||
})
|
||||
@SaCheckPermission("system.menu")
|
||||
@PostMapping("/saveLinkData")
|
||||
public ActionResult saveLinkData(@RequestBody @Valid DataAuthorizeLinkForm linkForm) {
|
||||
ModuleDataAuthorizeLinkEntity linkDataEntity = JsonUtil.getJsonToBean(linkForm, ModuleDataAuthorizeLinkEntity.class);
|
||||
if (StringUtil.isEmpty(linkDataEntity.getId())) {
|
||||
linkDataEntity.setId(RandomUtil.uuId());
|
||||
linkDataService.save(linkDataEntity);
|
||||
return ActionResult.success(MsgCode.SU002.get());
|
||||
} else {
|
||||
linkDataService.updateById(linkDataEntity);
|
||||
return ActionResult.success(MsgCode.SU004.get());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取表名
|
||||
*
|
||||
* @param menuId 菜单id
|
||||
* @param type 分类
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "获取表名")
|
||||
@Parameters({
|
||||
@Parameter(name = "menuId", description = "菜单id", required = true),
|
||||
@Parameter(name = "type", description = "分类", required = true)
|
||||
})
|
||||
@SaCheckPermission("system.menu")
|
||||
@GetMapping("/getVisualTables/{menuId}/{type}")
|
||||
public ActionResult<DataAuthorizeTableNameVO> getVisualTables(@PathVariable("menuId") String menuId, @PathVariable("type") Integer type) {
|
||||
ModuleEntity info = moduleService.getInfo(menuId);
|
||||
DataAuthorizeTableNameVO vo = null;
|
||||
if (ObjectUtil.isNotNull(info)) {
|
||||
PropertyJsonModel model = JsonUtil.getJsonToBean(info.getPropertyJson(), PropertyJsonModel.class);
|
||||
if (model == null) {
|
||||
model = new PropertyJsonModel();
|
||||
}
|
||||
//功能
|
||||
if (info.getType() == 3 || info.getType() ==9) {
|
||||
String formId = model.getModuleId();
|
||||
if(info.getType()==9){
|
||||
formId = templateApi.getFormByFlowId(model.getModuleId());
|
||||
}
|
||||
// 得到bean
|
||||
Object bean = SpringContext.getBean("visualdevServiceImpl");
|
||||
Object method = ReflectionUtil.invokeMethod(bean, "getInfo" , new Class[]{String.class}, new Object[]{formId});
|
||||
Map<String, Object> map = JsonUtil.entityToMap(method);
|
||||
if (map != null) {
|
||||
List<TableModel> tables = JsonUtil.getJsonToList(String.valueOf(map.get("tables")), TableModel.class);
|
||||
List<String> collect = tables.stream().map(t -> t.getTable()).collect(Collectors.toList());
|
||||
vo = DataAuthorizeTableNameVO.builder().linkTables(collect).linkId(String.valueOf(map.get("dbLinkId"))).build();
|
||||
}
|
||||
} else {
|
||||
ModuleDataAuthorizeLinkEntity linkDataEntity = linkDataService.getLinkDataEntityByMenuId(menuId,type);
|
||||
String linkTables = linkDataEntity.getLinkTables();
|
||||
List<String> tables = StringUtil.isNotEmpty(linkTables) ? Arrays.asList(linkTables.split(",")) : new ArrayList<>();
|
||||
vo = DataAuthorizeTableNameVO.builder().linkTables(tables).linkId(linkDataEntity.getLinkId()).build();
|
||||
}
|
||||
}
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据连接信息
|
||||
*
|
||||
* @param menudId 菜单id
|
||||
* @param type 分类
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "数据连接信息")
|
||||
@Parameters({
|
||||
@Parameter(name = "menudId", description = "菜单id", required = true),
|
||||
@Parameter(name = "type", description = "分类", required = true)
|
||||
})
|
||||
@SaCheckPermission("system.menu")
|
||||
@GetMapping("/getInfo/{menudId}/{type}")
|
||||
public ActionResult getInfo(@PathVariable("menudId") String menudId,@PathVariable("type") Integer type) {
|
||||
ModuleDataAuthorizeLinkEntity linkDataEntity = linkDataService.getLinkDataEntityByMenuId(menudId,type);
|
||||
DataAuthorizeLinkForm linkForm = JsonUtil.getJsonToBean(linkDataEntity, DataAuthorizeLinkForm.class);
|
||||
return ActionResult.success(linkForm);
|
||||
}
|
||||
|
||||
/**
|
||||
* 表名获取数据表字段
|
||||
*
|
||||
* @param linkId 连接id
|
||||
* @param tableName 表名
|
||||
* @param menuType 菜单类型
|
||||
* @param dataType 数据类型
|
||||
* @param pagination 分页模型
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
@Operation(summary = "表名获取数据表字段")
|
||||
@Parameters({
|
||||
@Parameter(name = "linkId", description = "连接id", required = true),
|
||||
@Parameter(name = "tableName", description = "表名", required = true),
|
||||
@Parameter(name = "menuType", description = "菜单类型", required = true),
|
||||
@Parameter(name = "dataType", description = "数据类型", required = true)
|
||||
})
|
||||
@SaCheckPermission("system.menu")
|
||||
@GetMapping("/{linkId}/Tables/{tableName}/Fields/{menuType}/{dataType}")
|
||||
public ActionResult getTableInfoByTableName(@PathVariable("linkId") String linkId, @PathVariable("tableName") String tableName, @PathVariable("menuType") Integer menuType,@PathVariable("dataType") Integer dataType, Pagination pagination) throws Exception {
|
||||
List<DbFieldModel> data = dbTableService.getFieldList(linkId, tableName);
|
||||
List<DbFieldVO> vos = JsonUtil.getJsonToList(data, DbFieldVO.class);
|
||||
if (StringUtil.isNotEmpty(pagination.getKeyword())) {
|
||||
vos = vos.stream().filter(vo -> {
|
||||
boolean ensure;
|
||||
String fieldName = vo.getFieldName();
|
||||
fieldName = Optional.ofNullable(fieldName).orElse("");
|
||||
ensure = fieldName.toLowerCase().contains(pagination.getKeyword().toLowerCase()) || vo.getField().toLowerCase().contains(pagination.getKeyword().toLowerCase());
|
||||
return ensure;
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
List listPage = PageUtil.getListPage((int) pagination.getCurrentPage(), (int) pagination.getPageSize(), vos);
|
||||
PaginationVO paginationVO = JsonUtil.getJsonToBean(pagination, PaginationVO.class);
|
||||
paginationVO.setTotal(vos.size());
|
||||
return ActionResult.page(listPage,paginationVO);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,170 @@
|
||||
package com.yunzhupaas.base.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import com.yunzhupaas.base.controller.SuperController;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import com.yunzhupaas.base.ActionResult;
|
||||
import com.yunzhupaas.base.service.ModuleDataAuthorizeSchemeService;
|
||||
import com.yunzhupaas.base.vo.ListVO;
|
||||
import com.yunzhupaas.base.entity.ModuleDataAuthorizeSchemeEntity;
|
||||
import com.yunzhupaas.constant.MsgCode;
|
||||
import com.yunzhupaas.exception.DataException;
|
||||
import com.yunzhupaas.base.model.moduledataauthorizescheme.DataAuthorizeSchemeCrForm;
|
||||
import com.yunzhupaas.base.model.moduledataauthorizescheme.DataAuthorizeSchemeInfoVO;
|
||||
import com.yunzhupaas.base.model.moduledataauthorizescheme.DataAuthorizeSchemeListVO;
|
||||
import com.yunzhupaas.base.model.moduledataauthorizescheme.DataAuthorizeSchemeUpForm;
|
||||
import com.yunzhupaas.permission.service.AuthorizeService;
|
||||
import com.yunzhupaas.util.JsonUtil;
|
||||
import com.yunzhupaas.util.JsonUtilEx;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 数据权限方案
|
||||
*
|
||||
* @author 云筑产品开发平台组
|
||||
* @version V3.1.0
|
||||
* @copyright 深圳市乐程软件有限公司
|
||||
* @date 2023/09/27
|
||||
*/
|
||||
@Tag(name = "数据权限方案", description = "ModuleDataAuthorizeScheme")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/ModuleDataAuthorizeScheme")
|
||||
public class ModuleDataAuthorizeSchemeController extends SuperController<ModuleDataAuthorizeSchemeService, ModuleDataAuthorizeSchemeEntity> {
|
||||
|
||||
@Autowired
|
||||
private ModuleDataAuthorizeSchemeService schemeService;
|
||||
|
||||
@Autowired
|
||||
private AuthorizeService authorizeService;
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*
|
||||
* @param moduleId 功能主键
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "方案列表")
|
||||
@Parameters({
|
||||
@Parameter(name = "moduleId", description = "功能主键", required = true)
|
||||
})
|
||||
@GetMapping("/{moduleId}/List")
|
||||
public ActionResult<ListVO<DataAuthorizeSchemeListVO>> list(@PathVariable("moduleId") String moduleId) {
|
||||
List<ModuleDataAuthorizeSchemeEntity> data = schemeService.getList(moduleId);
|
||||
List<DataAuthorizeSchemeListVO> list = JsonUtil.getJsonToList(data, DataAuthorizeSchemeListVO.class);
|
||||
ListVO<DataAuthorizeSchemeListVO> vo = new ListVO<>();
|
||||
vo.setList(list);
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 信息
|
||||
*
|
||||
* @param id 主键值
|
||||
* @return ignore
|
||||
* @throws DataException ignore
|
||||
*/
|
||||
@Operation(summary = "获取方案信息")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键值", required = true)
|
||||
})
|
||||
@SaCheckPermission("system.menu")
|
||||
@GetMapping("/{id}")
|
||||
public ActionResult<DataAuthorizeSchemeInfoVO> info(@PathVariable("id") String id) throws DataException {
|
||||
ModuleDataAuthorizeSchemeEntity entity = schemeService.getInfo(id);
|
||||
DataAuthorizeSchemeInfoVO vo = JsonUtilEx.getJsonToBeanEx(entity, DataAuthorizeSchemeInfoVO.class);
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新建
|
||||
*
|
||||
* @param dataAuthorizeSchemeCrForm 实体对象
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "新建方案")
|
||||
@Parameters({
|
||||
@Parameter(name = "dataAuthorizeSchemeCrForm", description = "实体对象", required = true)
|
||||
})
|
||||
@SaCheckPermission("system.menu")
|
||||
@PostMapping
|
||||
public ActionResult create(@RequestBody @Valid DataAuthorizeSchemeCrForm dataAuthorizeSchemeCrForm) {
|
||||
ModuleDataAuthorizeSchemeEntity entity = JsonUtil.getJsonToBean(dataAuthorizeSchemeCrForm, ModuleDataAuthorizeSchemeEntity.class);
|
||||
// 判断fullName是否重复
|
||||
if (schemeService.isExistByFullName(entity.getId(), entity.getFullName(), entity.getModuleId())) {
|
||||
return ActionResult.fail(MsgCode.EXIST001.get());
|
||||
}
|
||||
// 判断encode是否重复
|
||||
if (schemeService.isExistByEnCode(entity.getId(), entity.getEnCode(), entity.getModuleId())) {
|
||||
return ActionResult.fail(MsgCode.EXIST002.get());
|
||||
}
|
||||
schemeService.create(entity);
|
||||
return ActionResult.success(MsgCode.SU001.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新
|
||||
*
|
||||
* @param id 主键值
|
||||
* @param dataAuthorizeSchemeUpForm 实体对象
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "更新方案")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键值", required = true),
|
||||
@Parameter(name = "dataAuthorizeSchemeUpForm", description = "实体对象", required = true)
|
||||
})
|
||||
@SaCheckPermission("system.menu")
|
||||
@PutMapping("/{id}")
|
||||
public ActionResult update(@PathVariable("id") String id, @RequestBody @Valid DataAuthorizeSchemeUpForm dataAuthorizeSchemeUpForm) {
|
||||
ModuleDataAuthorizeSchemeEntity entity = JsonUtil.getJsonToBean(dataAuthorizeSchemeUpForm, ModuleDataAuthorizeSchemeEntity.class);
|
||||
// 判断encode是否重复
|
||||
if ("1".equals(String.valueOf(entity.getAllData()))) {
|
||||
return ActionResult.fail(MsgCode.SYS021.get());
|
||||
}
|
||||
// 判断fullName是否重复
|
||||
if (schemeService.isExistByFullName(id, entity.getFullName(), entity.getModuleId())) {
|
||||
return ActionResult.fail(MsgCode.EXIST001.get());
|
||||
}
|
||||
// 判断encode是否重复
|
||||
if (schemeService.isExistByEnCode(id, entity.getEnCode(), entity.getModuleId())) {
|
||||
return ActionResult.fail(MsgCode.EXIST002.get());
|
||||
}
|
||||
boolean flag = schemeService.update(id, entity);
|
||||
if (!flag) {
|
||||
return ActionResult.success(MsgCode.FA002.get());
|
||||
}
|
||||
authorizeService.removeAuthByUserOrMenu(null, new ArrayList(){{add(dataAuthorizeSchemeUpForm.getModuleId());}});
|
||||
return ActionResult.success(MsgCode.SU004.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*
|
||||
* @param id 主键值
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "删除方案")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键值", required = true)
|
||||
})
|
||||
@SaCheckPermission("system.menu")
|
||||
@DeleteMapping("/{id}")
|
||||
public ActionResult delete(@PathVariable("id") String id) {
|
||||
ModuleDataAuthorizeSchemeEntity entity = schemeService.getInfo(id);
|
||||
if (entity != null) {
|
||||
schemeService.delete(entity);
|
||||
return ActionResult.success(MsgCode.SU003.get());
|
||||
}
|
||||
return ActionResult.fail(MsgCode.FA003.get());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,132 @@
|
||||
package com.yunzhupaas.base.controller;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import com.yunzhupaas.base.ActionResult;
|
||||
import com.yunzhupaas.base.Page;
|
||||
import com.yunzhupaas.base.Pagination;
|
||||
import com.yunzhupaas.base.UserInfo;
|
||||
import com.yunzhupaas.base.entity.ModuleDataEntity;
|
||||
import com.yunzhupaas.base.entity.ModuleEntity;
|
||||
import com.yunzhupaas.base.service.ModuleDataService;
|
||||
import com.yunzhupaas.base.service.ModuleService;
|
||||
import com.yunzhupaas.base.vo.ListVO;
|
||||
import com.yunzhupaas.constant.MsgCode;
|
||||
import com.yunzhupaas.consts.DeviceType;
|
||||
import com.yunzhupaas.model.login.AllMenuSelectVO;
|
||||
import com.yunzhupaas.util.JsonUtil;
|
||||
import com.yunzhupaas.util.UserProvider;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @author :云筑产品开发平台组
|
||||
* @version: V3.1.0
|
||||
* @copyright 深圳市乐程软件有限公司
|
||||
* @date :2024/5/6 上午11:19
|
||||
*/
|
||||
@Tag(name = "常用菜单", description = "data")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/MenuData")
|
||||
public class ModuleDataController extends SuperController<ModuleDataService, ModuleDataEntity> {
|
||||
|
||||
@Autowired
|
||||
private ModuleService moduleService;
|
||||
@Autowired
|
||||
private ModuleDataService moduleDataService;
|
||||
|
||||
/**
|
||||
* 常用菜单
|
||||
*
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "常用菜单")
|
||||
@GetMapping
|
||||
public ActionResult<ListVO<AllMenuSelectVO>> getDataList(Page page) {
|
||||
UserInfo user = UserProvider.getUser();
|
||||
String category = DeviceType.PC.getDevice().equals(user.getLoginDevice())?"Web":"App";
|
||||
List<ModuleDataEntity> list = moduleDataService.getList(category,page);
|
||||
List<AllMenuSelectVO> listVO = new ArrayList<>();
|
||||
for (ModuleDataEntity entity : list) {
|
||||
ModuleEntity info = moduleService.getInfo(entity.getModuleId());
|
||||
if(info != null && Objects.equals(info.getEnabledMark(),1)) {
|
||||
AllMenuSelectVO vo = JsonUtil.getJsonToBean(info, AllMenuSelectVO.class);
|
||||
vo.setHasChildren(false);
|
||||
listVO.add(vo);
|
||||
}
|
||||
}
|
||||
ListVO vo = new ListVO();
|
||||
vo.setList(listVO);
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新建
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/{id}")
|
||||
@Operation(summary = "新建")
|
||||
public ActionResult create(@PathVariable("id") String id) {
|
||||
if (moduleDataService.isExistByObjectId(id)) {
|
||||
return ActionResult.fail(MsgCode.FA036.get());
|
||||
}
|
||||
moduleDataService.create(id);
|
||||
return ActionResult.success(MsgCode.SU016.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "删除")
|
||||
@DeleteMapping("/{id}")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true),
|
||||
})
|
||||
public ActionResult delete(@PathVariable("id") String id) {
|
||||
ModuleDataEntity entity = moduleDataService.getInfo(id);
|
||||
if (entity != null) {
|
||||
moduleDataService.delete(entity);
|
||||
return ActionResult.success(MsgCode.SU021.get());
|
||||
}
|
||||
return ActionResult.fail(MsgCode.FA003.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* app常用菜单
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "app常用菜单")
|
||||
@GetMapping("/getDataList")
|
||||
public ActionResult<ListVO<AllMenuSelectVO>> getAllList(Page page) {
|
||||
List<AllMenuSelectVO> list = moduleDataService.getDataList(page);
|
||||
ListVO listVO = new ListVO();
|
||||
listVO.setList(list);
|
||||
return ActionResult.success(listVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* app常用详情
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "app常用详情")
|
||||
@GetMapping("/getAppDataList")
|
||||
public ActionResult<ListVO<AllMenuSelectVO>> getAppDataList(Pagination pagination) {
|
||||
List<AllMenuSelectVO> list = moduleDataService.getAppDataList(pagination);
|
||||
ListVO listVO = new ListVO();
|
||||
listVO.setList(list);
|
||||
return ActionResult.success(listVO);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,361 @@
|
||||
package com.yunzhupaas.base.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import com.yunzhupaas.base.controller.SuperController;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import com.yunzhupaas.base.ActionResult;
|
||||
import com.yunzhupaas.base.Pagination;
|
||||
import com.yunzhupaas.base.entity.ModuleEntity;
|
||||
import com.yunzhupaas.base.entity.ModuleFormEntity;
|
||||
import com.yunzhupaas.base.model.form.*;
|
||||
import com.yunzhupaas.base.model.module.PropertyJsonModel;
|
||||
import com.yunzhupaas.base.service.ModuleFormService;
|
||||
import com.yunzhupaas.base.service.ModuleService;
|
||||
import com.yunzhupaas.base.vo.ListVO;
|
||||
import com.yunzhupaas.constant.MsgCode;
|
||||
import com.yunzhupaas.exception.DataException;
|
||||
import com.yunzhupaas.model.*;
|
||||
import com.yunzhupaas.model.visualJson.FieLdsModel;
|
||||
import com.yunzhupaas.model.visualJson.FormCloumnUtil;
|
||||
import com.yunzhupaas.model.visualJson.FormDataModel;
|
||||
import com.yunzhupaas.model.visualJson.TableModel;
|
||||
import com.yunzhupaas.model.visualJson.analysis.*;
|
||||
import com.yunzhupaas.util.JsonUtil;
|
||||
import com.yunzhupaas.util.JsonUtilEx;
|
||||
import com.yunzhupaas.util.ReflectionUtil;
|
||||
import com.yunzhupaas.util.StringUtil;
|
||||
import com.yunzhupaas.util.context.SpringContext;
|
||||
import org.apache.commons.collections4.map.HashedMap;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 表单权限
|
||||
* 版本: V3.1.0
|
||||
* 版权: 深圳市乐程软件有限公司(http://www.szlecheng.cn)
|
||||
* 作者: 云筑产品开发平台组
|
||||
* 日期: 2021-09-14
|
||||
*/
|
||||
@Tag(name = "表单权限", description = "ModuleForm")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/ModuleForm")
|
||||
public class ModuleFormController extends SuperController<ModuleFormService, ModuleFormEntity> {
|
||||
|
||||
@Autowired
|
||||
private ModuleFormService moduleFormService;
|
||||
@Autowired
|
||||
private ModuleService moduleService;
|
||||
|
||||
/**
|
||||
* 获取表单权限列表
|
||||
*
|
||||
* @param moduleId 功能主键
|
||||
* @param pagination 分页参数
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "获取表单权限列表")
|
||||
@Parameters({
|
||||
@Parameter(name = "moduleId", description = "功能主键", required = true)
|
||||
})
|
||||
@SaCheckPermission("system.menu")
|
||||
@GetMapping("/{moduleId}/Fields")
|
||||
public ActionResult<ListVO<ModuleFormListVO>> getList(@PathVariable("moduleId") String moduleId,
|
||||
Pagination pagination) {
|
||||
List<ModuleFormEntity> list = moduleFormService.getList(moduleId, pagination);
|
||||
List<ModuleFormListVO> voList = JsonUtil.getJsonToList(list, ModuleFormListVO.class);
|
||||
voList.stream().forEach(t -> {
|
||||
String enCode = t.getEnCode();
|
||||
if (StringUtil.isNotEmpty(enCode)) {
|
||||
if (enCode.contains("-")) {
|
||||
enCode = enCode.substring(enCode.indexOf("-") + 1);
|
||||
}
|
||||
t.setEnCode(enCode.replace("yunzhupaas_" + t.getBindTable() + "_yunzhupaas_", ""));
|
||||
}
|
||||
});
|
||||
ListVO vo = new ListVO<>();
|
||||
vo.setList(voList);
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 菜单数据权限
|
||||
*
|
||||
* @param moduleId 功能主键
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "菜单数据权限")
|
||||
@Parameters({
|
||||
@Parameter(name = "moduleId", description = "功能主键", required = true)
|
||||
})
|
||||
@SaCheckPermission("system.menu")
|
||||
@GetMapping("/{moduleId}/FieldList")
|
||||
public ActionResult<List<Map<String, String>>> fieldList(@PathVariable("moduleId") String moduleId) {
|
||||
List<Map<String, String>> list = new ArrayList<>();
|
||||
// 得到菜单id
|
||||
ModuleEntity entity = moduleService.getInfo(moduleId);
|
||||
PropertyJsonModel model = JsonUtil.getJsonToBean(entity.getPropertyJson(), PropertyJsonModel.class);
|
||||
if (model == null) {
|
||||
model = new PropertyJsonModel();
|
||||
}
|
||||
// 得到bean
|
||||
Object bean = SpringContext.getBean("visualdevServiceImpl");
|
||||
Object method = ReflectionUtil.invokeMethod(bean, "getInfo", new Class[] { String.class },
|
||||
new Object[] { model.getModuleId() });
|
||||
Map<String, Object> map = JsonUtil.entityToMap(method);
|
||||
if (map != null && map.containsKey("formData")) {
|
||||
FormDataModel formDataModel = JsonUtil.getJsonToBean(String.valueOf(map.get("formData")),
|
||||
FormDataModel.class);
|
||||
List<FieLdsModel> fieLdsModelList = JsonUtil.getJsonToList(formDataModel.getFields(), FieLdsModel.class);
|
||||
RecursionForm recursionForm = new RecursionForm();
|
||||
recursionForm.setList(fieLdsModelList);
|
||||
recursionForm
|
||||
.setTableModelList(JsonUtil.getJsonToList(String.valueOf(map.get("tables")), TableModel.class));
|
||||
List<FormAllModel> formAllModel = new ArrayList<>();
|
||||
FormCloumnUtil.recursionForm(recursionForm, formAllModel);
|
||||
for (FormAllModel allModel : formAllModel) {
|
||||
if (FormEnum.table.getMessage().equals(allModel.getYunzhupaasKey())) {
|
||||
FormColumnTableModel childList = allModel.getChildList();
|
||||
Map<String, String> map1 = new HashedMap<>();
|
||||
map1.put("field", childList.getTableModel());
|
||||
map1.put("fieldName", childList.getLabel());
|
||||
list.add(map1);
|
||||
} else if (FormEnum.mast.getMessage().equals(allModel.getYunzhupaasKey())) {
|
||||
FormColumnModel formColumnModel = allModel.getFormColumnModel();
|
||||
FieLdsModel fieLdsModel = formColumnModel.getFieLdsModel();
|
||||
if (StringUtil.isNotEmpty(fieLdsModel.getVModel())) {
|
||||
Map<String, String> map1 = new HashedMap<>();
|
||||
map1.put("field", fieLdsModel.getVModel());
|
||||
map1.put("fieldName", fieLdsModel.getConfig().getLabel());
|
||||
list.add(map1);
|
||||
}
|
||||
} else if (FormEnum.mastTable.getMessage().equals(allModel.getYunzhupaasKey())) {
|
||||
FormMastTableModel formColumnModel = allModel.getFormMastTableModel();
|
||||
FieLdsModel fieLdsModel = formColumnModel.getMastTable().getFieLdsModel();
|
||||
if (StringUtil.isNotEmpty(fieLdsModel.getVModel())) {
|
||||
Map<String, String> map1 = new HashedMap<>();
|
||||
map1.put("field", fieLdsModel.getVModel());
|
||||
map1.put("fieldName", fieLdsModel.getConfig().getLabel());
|
||||
list.add(map1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return ActionResult.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取表单权限信息
|
||||
*
|
||||
* @param id 主键值
|
||||
* @return ignore
|
||||
* @throws DataException ignore
|
||||
*/
|
||||
@Operation(summary = "获取表单权限信息")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键值", required = true)
|
||||
})
|
||||
@GetMapping("/{id}")
|
||||
public ActionResult<ModuleFormInfoVO> info(@PathVariable("id") String id) throws DataException {
|
||||
ModuleFormEntity entity = moduleFormService.getInfo(id);
|
||||
String enCode = entity.getEnCode();
|
||||
if (StringUtil.isNotEmpty(enCode)) {
|
||||
if (enCode.contains("-") && entity.getFieldRule() == 2) {
|
||||
enCode = enCode.substring(enCode.indexOf("-") + 1);
|
||||
entity.setEnCode(enCode);
|
||||
}
|
||||
if (entity.getFieldRule() == 1 && entity.getBindTable() != null) {
|
||||
entity.setEnCode(enCode.replace("yunzhupaas_" + entity.getBindTable() + "_yunzhupaas_", ""));
|
||||
}
|
||||
}
|
||||
ModuleFormInfoVO vo = JsonUtilEx.getJsonToBeanEx(entity, ModuleFormInfoVO.class);
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新建表单权限
|
||||
*
|
||||
* @param moduleFormCrForm 实体对象
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "新建表单权限")
|
||||
@Parameters({
|
||||
@Parameter(name = "moduleFormCrForm", description = "实体对象", required = true)
|
||||
})
|
||||
@SaCheckPermission("system.menu")
|
||||
@PostMapping
|
||||
public ActionResult create(@RequestBody @Valid ModuleFormCrForm moduleFormCrForm) {
|
||||
ModuleEntity moduleEntity = moduleService.getInfo(moduleFormCrForm.getModuleId());
|
||||
ModuleFormEntity entity = JsonUtil.getJsonToBean(moduleFormCrForm, ModuleFormEntity.class);
|
||||
|
||||
if (moduleEntity != null) {
|
||||
PropertyJsonModel model = JsonUtil.getJsonToBean(moduleEntity.getPropertyJson(), PropertyJsonModel.class);
|
||||
if (model == null) {
|
||||
model = new PropertyJsonModel();
|
||||
}
|
||||
if (entity.getFieldRule() == 1 && StringUtil.isNotEmpty(moduleFormCrForm.getBindTable())) {
|
||||
String enCode = "yunzhupaas_" + moduleFormCrForm.getBindTable() + "_yunzhupaas_" + entity.getEnCode();
|
||||
entity.setEnCode(enCode);
|
||||
}
|
||||
|
||||
if (entity.getFieldRule() == 2 && StringUtil.isNotEmpty(moduleFormCrForm.getChildTableKey())) {
|
||||
// 得到bean
|
||||
// Object bean = SpringContext.getBean("visualdevServiceImpl");
|
||||
// Object method = ReflectionUtil.invokeMethod(bean, "getTableNameToKey", new
|
||||
// Class[]{String.class}, new Object[]{model.getModuleId()});
|
||||
// Map<String, Object> map = JsonUtil.entityToMap(method);
|
||||
//
|
||||
// String enCode = map.get(moduleFormCrForm.getBindTable().toLowerCase()) + "-"
|
||||
// + entity.getEnCode();
|
||||
String enCode = moduleFormCrForm.getChildTableKey() + "-" + entity.getEnCode();
|
||||
entity.setEnCode(enCode);
|
||||
}
|
||||
}
|
||||
if (moduleFormService.isExistByEnCode(entity.getModuleId(), entity.getEnCode(), entity.getId())) {
|
||||
return ActionResult.fail(MsgCode.EXIST002.get());
|
||||
}
|
||||
moduleFormService.create(entity);
|
||||
return ActionResult.success(MsgCode.SU001.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新表单权限
|
||||
*
|
||||
* @param id 主键值
|
||||
* @param moduleFormUpForm 实体对象
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "更新表单权限")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键值", required = true),
|
||||
@Parameter(name = "moduleFormUpForm", description = "实体对象", required = true)
|
||||
})
|
||||
@SaCheckPermission("system.menu")
|
||||
@PutMapping("/{id}")
|
||||
public ActionResult update(@PathVariable("id") String id, @RequestBody @Valid ModuleFormUpForm moduleFormUpForm) {
|
||||
ModuleEntity moduleEntity = moduleService.getInfo(moduleFormUpForm.getModuleId());
|
||||
ModuleFormEntity entity = JsonUtil.getJsonToBean(moduleFormUpForm, ModuleFormEntity.class);
|
||||
if (moduleEntity != null) {
|
||||
PropertyJsonModel model = JsonUtil.getJsonToBean(moduleEntity.getPropertyJson(), PropertyJsonModel.class);
|
||||
if (model == null) {
|
||||
model = new PropertyJsonModel();
|
||||
}
|
||||
if (entity.getFieldRule() == 1 && StringUtil.isNotEmpty(moduleFormUpForm.getBindTable())) {
|
||||
String enCode = "yunzhupaas_" + moduleFormUpForm.getBindTable() + "_yunzhupaas_" + entity.getEnCode();
|
||||
entity.setEnCode(enCode);
|
||||
}
|
||||
|
||||
if (entity.getFieldRule() == 2 && StringUtil.isNotEmpty(moduleFormUpForm.getChildTableKey())) {
|
||||
// // 得到bean
|
||||
// Object bean = SpringContext.getBean("visualdevServiceImpl");
|
||||
// Object method = ReflectionUtil.invokeMethod(bean, "getTableNameToKey", new
|
||||
// Class[]{String.class}, new Object[]{model.getModuleId()});
|
||||
// Map<String, Object> map = JsonUtil.entityToMap(method);
|
||||
//
|
||||
// String enCode = map.get(moduleFormUpForm.getBindTable().toLowerCase()) + "-"
|
||||
// + entity.getEnCode();
|
||||
String enCode = moduleFormUpForm.getChildTableKey() + "-" + entity.getEnCode();
|
||||
entity.setEnCode(enCode);
|
||||
}
|
||||
}
|
||||
if (moduleFormService.isExistByEnCode(entity.getModuleId(), entity.getEnCode(), id)) {
|
||||
return ActionResult.fail(MsgCode.EXIST002.get());
|
||||
}
|
||||
boolean flag = moduleFormService.update(id, entity);
|
||||
if (!flag) {
|
||||
return ActionResult.success(MsgCode.FA002.get());
|
||||
}
|
||||
return ActionResult.success(MsgCode.SU004.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除表单权限
|
||||
*
|
||||
* @param id 主键值
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "删除表单权限")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键值", required = true)
|
||||
})
|
||||
@SaCheckPermission("system.menu")
|
||||
@DeleteMapping("/{id}")
|
||||
public ActionResult delete(@PathVariable("id") String id) {
|
||||
ModuleFormEntity entity = moduleFormService.getInfo(id);
|
||||
if (entity != null) {
|
||||
moduleFormService.delete(entity);
|
||||
return ActionResult.success(MsgCode.SU003.get());
|
||||
}
|
||||
return ActionResult.fail(MsgCode.FA003.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量新建
|
||||
*
|
||||
* @param formBatchForm 批量表单模型
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "批量新建表单权限")
|
||||
@Parameters({
|
||||
@Parameter(name = "formBatchForm", description = "批量表单模型", required = true)
|
||||
})
|
||||
@SaCheckPermission("system.menu")
|
||||
@PostMapping("/Actions/Batch")
|
||||
public ActionResult batchCreate(@RequestBody @Valid FormBatchForm formBatchForm) {
|
||||
List<ModuleFormEntity> entitys = formBatchForm.getFormJson() != null
|
||||
? JsonUtil.getJsonToList(formBatchForm.getFormJson(), ModuleFormEntity.class)
|
||||
: new ArrayList<>();
|
||||
List<String> name = new ArrayList<>();
|
||||
for (ModuleFormEntity entity : entitys) {
|
||||
if (entity.getFieldRule() == 1) {
|
||||
String enCode = "yunzhupaas_" + entity.getBindTable() + "_yunzhupaas_" + entity.getEnCode();
|
||||
entity.setEnCode(enCode);
|
||||
}
|
||||
if (entity.getFieldRule() == 2) {
|
||||
String enCode = entity.getChildTableKey() + "-" + entity.getEnCode();
|
||||
entity.setEnCode(enCode);
|
||||
}
|
||||
entity.setModuleId(formBatchForm.getModuleId());
|
||||
if (moduleFormService.isExistByEnCode(entity.getModuleId(), entity.getEnCode(), null)) {
|
||||
return ActionResult.fail(MsgCode.EXIST002.get());
|
||||
}
|
||||
if (name.contains(entity.getEnCode())) {
|
||||
return ActionResult.fail(MsgCode.EXIST002.get());
|
||||
}
|
||||
name.add(entity.getEnCode());
|
||||
}
|
||||
moduleFormService.create(entitys);
|
||||
return ActionResult.success(MsgCode.SU001.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新表单权限状态
|
||||
*
|
||||
* @param id 主键值
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "更新表单权限状态")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键值", required = true)
|
||||
})
|
||||
@SaCheckPermission("system.menu")
|
||||
@PutMapping("/{id}/Actions/State")
|
||||
public ActionResult upState(@PathVariable("id") String id) {
|
||||
ModuleFormEntity entity = moduleFormService.getInfo(id);
|
||||
entity.setEnabledMark("1".equals(String.valueOf(entity.getEnabledMark())) ? 0 : 1);
|
||||
boolean flag = moduleFormService.update(id, entity);
|
||||
if (!flag) {
|
||||
return ActionResult.success(MsgCode.FA002.get());
|
||||
}
|
||||
return ActionResult.success(MsgCode.SU004.get());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.yunzhupaas.base.controller;
|
||||
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import com.yunzhupaas.base.ActionResult;
|
||||
import com.yunzhupaas.base.model.monitor.MonitorListVO;
|
||||
import com.yunzhupaas.util.JsonUtil;
|
||||
import com.yunzhupaas.base.util.MonitorUtil;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* 系统监控
|
||||
*
|
||||
* @author 云筑产品开发平台组
|
||||
* @version V3.1.0
|
||||
* @copyright 深圳市乐程软件有限公司
|
||||
* @date 2023/09/27
|
||||
*/
|
||||
@Tag(name = "系统监控", description = "Monitor")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/Monitor")
|
||||
public class MonitorController {
|
||||
|
||||
/**
|
||||
* 系统监控
|
||||
*
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "系统监控")
|
||||
@SaCheckPermission("system.monitor")
|
||||
@GetMapping
|
||||
public ActionResult<MonitorListVO> list() {
|
||||
MonitorUtil monitorUtil = new MonitorUtil();
|
||||
MonitorListVO vo = JsonUtil.getJsonToBean(monitorUtil, MonitorListVO.class);
|
||||
vo.setTime(System.currentTimeMillis());
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
package com.yunzhupaas.base.controller;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import com.yunzhupaas.base.ActionResult;
|
||||
import com.yunzhupaas.base.entity.PortalManageEntity;
|
||||
import com.yunzhupaas.base.model.portalManage.*;
|
||||
import com.yunzhupaas.base.service.PortalManageService;
|
||||
import com.yunzhupaas.base.vo.PageListVO;
|
||||
import com.yunzhupaas.constant.MsgCode;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 门户管理
|
||||
*
|
||||
* @author 云筑产品开发平台组
|
||||
* @version v3.4.6
|
||||
* @copyrignt 深圳市乐程软件有限公司
|
||||
* @date 2023-02-16
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@Tag(name = "门户管理", description = "PortalManage")
|
||||
@RequestMapping("/api/system/PortalManage")
|
||||
public class PortalManageController extends SuperController<PortalManageService, PortalManageEntity> {
|
||||
|
||||
@Autowired
|
||||
PortalManageService portalManageService;
|
||||
// @Autowired
|
||||
// PortalService portalApi;
|
||||
// @Autowired
|
||||
// private AuthorizeService authorizeService;
|
||||
|
||||
@Operation(summary = "新增")
|
||||
@PostMapping
|
||||
public ActionResult<String> create(@RequestBody @Valid PortalManageCreForm portalManageForm) {
|
||||
PortalManageEntity entity = portalManageForm.convertEntity();
|
||||
try {
|
||||
portalManageService.checkCreUp(entity);
|
||||
} catch (Exception e) {
|
||||
return ActionResult.fail(e.getMessage());
|
||||
}
|
||||
portalManageService.save(entity);
|
||||
return ActionResult.success(MsgCode.SU018.get());
|
||||
}
|
||||
|
||||
@Operation(summary = "删除")
|
||||
@DeleteMapping("/{id}")
|
||||
public ActionResult<String> delete(@PathVariable String id) {
|
||||
boolean flag = portalManageService.removeById(id);
|
||||
if(flag){
|
||||
// 删除绑定的所有权限
|
||||
// authorizeService.remove(new AuthorizePortalManagePrimary(null, id).getQuery());
|
||||
return ActionResult.success(MsgCode.SU003.get());
|
||||
} else {
|
||||
return ActionResult.fail(MsgCode.FA003.get());
|
||||
}
|
||||
}
|
||||
|
||||
@Operation(summary = "编辑")
|
||||
@PutMapping("/{id}")
|
||||
public ActionResult<String> update(@PathVariable("id") String id, @RequestBody @Valid PortalManageUpForm portalManageUpForm){
|
||||
PortalManageEntity update = portalManageUpForm.convertEntity();
|
||||
try {
|
||||
portalManageService.checkCreUp(update);
|
||||
} catch (Exception e) {
|
||||
return ActionResult.fail(e.getMessage());
|
||||
}
|
||||
portalManageService.updateById(update);
|
||||
return ActionResult.success(MsgCode.SU004.get());
|
||||
}
|
||||
|
||||
@Operation(summary = "查看")
|
||||
@GetMapping("/{id}")
|
||||
public ActionResult<PortalManageVO> getOne(@PathVariable("id") String id) {
|
||||
PortalManageEntity entity = portalManageService.getById(id);
|
||||
return ActionResult.success(portalManageService.convertVO(entity));
|
||||
}
|
||||
|
||||
@Operation(summary = "列表")
|
||||
@GetMapping("/list/{systemId}")
|
||||
public ActionResult<PageListVO<PortalManageVO>> getPage(@PathVariable("systemId") String systemId, PortalManagePage pmPage) {
|
||||
pmPage.setSystemId(systemId);
|
||||
return ActionResult.page(
|
||||
portalManageService.getPage(pmPage).getRecords()
|
||||
.stream().map(PortalManagePageDO::convert).collect(Collectors.toList()),
|
||||
pmPage.getPaginationVO());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,389 @@
|
||||
package com.yunzhupaas.base.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.Valid;
|
||||
import com.yunzhupaas.base.ActionResult;
|
||||
import com.yunzhupaas.base.entity.DictionaryDataEntity;
|
||||
import com.yunzhupaas.base.entity.PrintDevEntity;
|
||||
import com.yunzhupaas.base.entity.PrintVersionEntity;
|
||||
import com.yunzhupaas.base.model.print.*;
|
||||
import com.yunzhupaas.base.model.query.PrintDevDataQuery;
|
||||
import com.yunzhupaas.base.model.query.PrintDevParam;
|
||||
import com.yunzhupaas.base.model.vo.PrintDevListVO;
|
||||
import com.yunzhupaas.base.model.vo.PrintDevVO;
|
||||
import com.yunzhupaas.base.service.DictionaryDataService;
|
||||
import com.yunzhupaas.base.service.PrintDevService;
|
||||
import com.yunzhupaas.base.service.PrintVersionService;
|
||||
import com.yunzhupaas.base.vo.DownloadVO;
|
||||
import com.yunzhupaas.base.vo.ListVO;
|
||||
import com.yunzhupaas.base.vo.PageListVO;
|
||||
import com.yunzhupaas.base.vo.PaginationVO;
|
||||
import com.yunzhupaas.config.ConfigValueUtil;
|
||||
import com.yunzhupaas.constant.MsgCode;
|
||||
import com.yunzhupaas.emnus.ModuleTypeEnum;
|
||||
import com.yunzhupaas.exception.DataException;
|
||||
import com.yunzhupaas.exception.WorkFlowException;
|
||||
import com.yunzhupaas.permission.entity.UserEntity;
|
||||
import com.yunzhupaas.permission.service.UserService;
|
||||
import com.yunzhupaas.util.*;
|
||||
import com.yunzhupaas.util.enums.DictionaryDataEnum;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 打印模板 -控制器
|
||||
*
|
||||
* @author 云筑产品开发平台组
|
||||
* @version V3.2.0
|
||||
* @copyright 深圳市乐程软件有限公司
|
||||
* @date 2024-09-30
|
||||
*/
|
||||
@Tag(name = "打印模板", description = "print")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/printDev")
|
||||
public class PrintDevController {
|
||||
|
||||
@Autowired
|
||||
private PrintDevService printDevService;
|
||||
@Autowired
|
||||
private PrintVersionService versionService;
|
||||
@Autowired
|
||||
private FileExport fileExport;
|
||||
@Autowired
|
||||
private ConfigValueUtil configValueUtil;
|
||||
@Autowired
|
||||
private DictionaryDataService dictionaryDataService;
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@Operation(summary = "列表")
|
||||
@SaCheckPermission("onlineDev.printDev")
|
||||
@GetMapping
|
||||
public ActionResult list(PaginationPrint paginationPrint) {
|
||||
List<PrintDevEntity> list = printDevService.getList(paginationPrint);
|
||||
List<String> userId = list.stream().map(t -> t.getCreatorUserId()).collect(Collectors.toList());
|
||||
List<String> lastUserId = list.stream().map(t -> t.getLastModifyUserId()).collect(Collectors.toList());
|
||||
lastUserId.removeAll(Collections.singleton(null));
|
||||
List<UserEntity> userEntities = userService.getUserName(userId);
|
||||
List<UserEntity> lastUserIdEntities = userService.getUserName(lastUserId);
|
||||
List<DictionaryDataEntity> typeList = dictionaryDataService.getListByTypeDataCode(DictionaryDataEnum.SYSTEM_PRINTDEV.getDictionaryTypeId());
|
||||
List<PrintDevListVO> listVOS = new ArrayList<>();
|
||||
for (PrintDevEntity entity : list) {
|
||||
PrintDevListVO vo = JsonUtil.getJsonToBean(entity, PrintDevListVO.class);
|
||||
DictionaryDataEntity dataEntity = typeList.stream().filter(t -> t.getId().equals(entity.getCategory())).findFirst().orElse(null);
|
||||
if (dataEntity != null) {
|
||||
vo.setCategory(dataEntity.getFullName());
|
||||
} else {
|
||||
vo.setCategory("");
|
||||
}
|
||||
//创建者
|
||||
UserEntity creatorUser = userEntities.stream().filter(t -> t.getId().equals(entity.getCreatorUserId())).findFirst().orElse(null);
|
||||
vo.setCreatorUser(creatorUser != null ? creatorUser.getRealName() + "/" + creatorUser.getAccount() : entity.getCreatorUserId());
|
||||
//修改人
|
||||
UserEntity lastModifyUser = lastUserIdEntities.stream().filter(t -> t.getId().equals(entity.getLastModifyUserId())).findFirst().orElse(null);
|
||||
vo.setLastModifyUser(lastModifyUser != null ? lastModifyUser.getRealName() + "/" + lastModifyUser.getAccount() : entity.getLastModifyUserId());
|
||||
listVOS.add(vo);
|
||||
}
|
||||
PaginationVO paginationVO = JsonUtil.getJsonToBean(paginationPrint, PaginationVO.class);
|
||||
return ActionResult.page(listVOS, paginationVO);
|
||||
}
|
||||
|
||||
/*============模板增删改==============*/
|
||||
|
||||
@Operation(summary = "新增")
|
||||
@Parameters({
|
||||
@Parameter(name = "printDevForm", description = "打印模板数据传输对象")
|
||||
})
|
||||
@SaCheckPermission("onlineDev.printDev")
|
||||
@PostMapping
|
||||
public ActionResult create(@RequestBody @Valid PrintDevFormDTO printDevForm) {
|
||||
printDevService.create(printDevForm);
|
||||
return ActionResult.success(MsgCode.SU001.get(), printDevForm.getId());
|
||||
}
|
||||
|
||||
@Operation(summary = "详情")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "打印模板id")
|
||||
})
|
||||
@SaCheckPermission("onlineDev.printDev")
|
||||
@GetMapping("/{id}")
|
||||
public ActionResult<PrintDevInfoVO> info(@PathVariable("id") String id) {
|
||||
PrintDevEntity byId = printDevService.getById(id);
|
||||
PrintDevInfoVO vo = JsonUtil.getJsonToBean(byId, PrintDevInfoVO.class);
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
@Operation(summary = "更新")
|
||||
@PutMapping("/{id}")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true),
|
||||
@Parameter(name = "form", description = "流程模型", required = true),
|
||||
})
|
||||
public ActionResult update(@PathVariable("id") String id, @RequestBody @Valid PrintDevFormDTO printDevForm) throws WorkFlowException {
|
||||
PrintDevEntity printDevEntity = JsonUtil.getJsonToBean(printDevForm, PrintDevEntity.class);
|
||||
PrintDevEntity originEntity = printDevService.getById(id);
|
||||
printDevService.creUpdateCheck(printDevEntity,
|
||||
!originEntity.getFullName().equals(printDevForm.getFullName()),
|
||||
!originEntity.getEnCode().equals(printDevForm.getEnCode()));
|
||||
printDevEntity.setId(id);
|
||||
printDevService.updateById(printDevEntity);
|
||||
return ActionResult.success(MsgCode.SU004.get());
|
||||
}
|
||||
|
||||
@Operation(summary = "删除")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "打印模板id")
|
||||
})
|
||||
@SaCheckPermission("onlineDev.printDev")
|
||||
@DeleteMapping("/{id}")
|
||||
public ActionResult<PrintDevFormDTO> delete(@PathVariable String id) {
|
||||
//对象存在判断
|
||||
if (printDevService.getById(id) != null) {
|
||||
printDevService.removeById(id);
|
||||
versionService.removeByTemplateId(id);
|
||||
return ActionResult.success(MsgCode.SU003.get());
|
||||
} else {
|
||||
return ActionResult.fail(MsgCode.FA003.get());
|
||||
}
|
||||
}
|
||||
|
||||
/*============版本增删改==============*/
|
||||
@Operation(summary = "版本详情")
|
||||
@Parameters({
|
||||
@Parameter(name = "versionId", description = "打印版本id")
|
||||
})
|
||||
@SaCheckPermission("onlineDev.printDev")
|
||||
@GetMapping("/Info/{versionId}")
|
||||
public ActionResult<PrintDevInfoVO> versionInfo(@PathVariable String versionId) {
|
||||
PrintDevInfoVO info = printDevService.getVersionInfo(versionId);
|
||||
return ActionResult.success(info);
|
||||
}
|
||||
|
||||
@Operation(summary = "版本新增")
|
||||
@Parameters({
|
||||
@Parameter(name = "versionId", description = "打印版本id")
|
||||
})
|
||||
@SaCheckPermission("onlineDev.printDev")
|
||||
@PostMapping("/Info/{versionId}")
|
||||
public ActionResult copyVersion(@PathVariable String versionId) {
|
||||
String newVersionId = versionService.copyVersion(versionId);
|
||||
return ActionResult.success(MsgCode.SU005.get(), newVersionId);
|
||||
}
|
||||
|
||||
@Operation(summary = "版本删除")
|
||||
@Parameters({
|
||||
@Parameter(name = "versionId", description = "打印版本id")
|
||||
})
|
||||
@SaCheckPermission("onlineDev.printDev")
|
||||
@DeleteMapping("/Info/{versionId}")
|
||||
public ActionResult deleteVersion(@PathVariable String versionId) {
|
||||
PrintVersionEntity byId = versionService.getById(versionId);
|
||||
if (byId != null) {
|
||||
List<PrintVersionEntity> list = versionService.getList(byId.getTemplateId());
|
||||
if (list.size() == 1) {
|
||||
return ActionResult.fail(MsgCode.SYS043.get());
|
||||
}
|
||||
if (Objects.equals(byId.getState(), 1)) {
|
||||
return ActionResult.fail(MsgCode.SYS044.get());
|
||||
}
|
||||
if (Objects.equals(byId.getState(), 2)) {
|
||||
return ActionResult.fail(MsgCode.SYS045.get());
|
||||
}
|
||||
versionService.removeById(versionId);
|
||||
}
|
||||
return ActionResult.success(MsgCode.SU003.get());
|
||||
}
|
||||
|
||||
@Operation(summary = "版本列表")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "打印模板id")
|
||||
})
|
||||
@SaCheckPermission("onlineDev.printDev")
|
||||
@GetMapping("/Version/{id}")
|
||||
public ActionResult<List<PrintVersionListVO>> versionList(@PathVariable String id) {
|
||||
List<PrintVersionEntity> list = versionService.getList(id);
|
||||
List<PrintVersionListVO> listVO = new ArrayList<>();
|
||||
for (PrintVersionEntity jsonEntity : list) {
|
||||
PrintVersionListVO vo = JsonUtil.getJsonToBean(jsonEntity, PrintVersionListVO.class);
|
||||
vo.setFullName("打印版本V" + vo.getVersion());
|
||||
listVO.add(vo);
|
||||
}
|
||||
return ActionResult.success(listVO);
|
||||
}
|
||||
|
||||
//***********************************动作start
|
||||
@Operation(summary = "保存或者发布")
|
||||
@Parameters({
|
||||
@Parameter(name = "printDevForm", description = "打印模板数据传输对象")
|
||||
})
|
||||
@SaCheckPermission("onlineDev.printDev")
|
||||
@PostMapping("/Save")
|
||||
public ActionResult saveOrRelease(@RequestBody @Valid PrintDevUpForm form) {
|
||||
printDevService.saveOrRelease(form);
|
||||
if (Objects.equals(form.getType(), 1)) {
|
||||
return ActionResult.success(MsgCode.SU011.get());
|
||||
}
|
||||
return ActionResult.success(MsgCode.SU002.get());
|
||||
}
|
||||
|
||||
@Operation(summary = "复制")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "打印模板id")
|
||||
})
|
||||
@SaCheckPermission("onlineDev.printDev")
|
||||
@PostMapping("/{id}/Actions/Copy")
|
||||
public ActionResult<PageListVO<PrintDevEntity>> copy(@PathVariable String id) {
|
||||
printDevService.copyPrintdev(id);
|
||||
return ActionResult.success(MsgCode.SU007.get());
|
||||
}
|
||||
|
||||
@Operation(summary = "导出")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "打印模板id")
|
||||
})
|
||||
@SaCheckPermission("onlineDev.printDev")
|
||||
@GetMapping("/{id}/Actions/Export")
|
||||
public ActionResult<DownloadVO> export(@PathVariable String id) {
|
||||
PrintDevEntity entity = printDevService.getById(id);
|
||||
List<PrintVersionEntity> list = versionService.getList(id);
|
||||
if (CollectionUtils.isEmpty(list)) {
|
||||
return ActionResult.fail(MsgCode.FA001.get());
|
||||
}
|
||||
PrintDevInfoVO info = printDevService.getVersionInfo(list.get(0).getId());
|
||||
//导出文件
|
||||
DownloadVO downloadVO = fileExport.exportFile(info, configValueUtil.getTemporaryFilePath(), entity.getFullName(), ModuleTypeEnum.SYSTEM_PRINT.getTableName());
|
||||
return ActionResult.success(downloadVO);
|
||||
}
|
||||
|
||||
@Operation(summary = "导入")
|
||||
@SaCheckPermission("onlineDev.printDev")
|
||||
@PostMapping(value = "/Actions/Import", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
public ActionResult<PageListVO<PrintDevEntity>> importData(@RequestPart("file") MultipartFile multipartFile,
|
||||
@RequestParam("type") Integer type) throws DataException {
|
||||
//判断是否为.json结尾
|
||||
if (FileUtil.existsSuffix(multipartFile, ModuleTypeEnum.SYSTEM_PRINT.getTableName())) {
|
||||
return ActionResult.fail(MsgCode.IMP002.get());
|
||||
}
|
||||
//读取文件内容
|
||||
String fileContent = FileUtil.getFileContent(multipartFile);
|
||||
PrintDevInfoVO infVo = JsonUtil.getJsonToBean(fileContent, PrintDevInfoVO.class);
|
||||
String str = printDevService.importData(infVo, type);
|
||||
if (StringUtil.isNotEmpty(str)) {
|
||||
return ActionResult.fail(str);
|
||||
}
|
||||
return ActionResult.success(MsgCode.IMP001.get());
|
||||
}
|
||||
//***********************************动作end
|
||||
|
||||
/**
|
||||
* 下拉列表
|
||||
*
|
||||
* @return 返回列表数据
|
||||
*/
|
||||
@Operation(summary = "下拉列表")
|
||||
@GetMapping("/Selector")
|
||||
public ActionResult<ListVO<PrintDevVO>> selectorList(String category) throws Exception {
|
||||
ListVO<PrintDevVO> vo = new ListVO<>();
|
||||
vo.setList(printDevService.getTreeModel(category));
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
@Operation(summary = "Sql数据获取")
|
||||
@PostMapping("/BatchData")
|
||||
public ActionResult getBatchData(@RequestBody PrintDevDataQuery query) {
|
||||
String id = XSSEscape.escape(query.getId());
|
||||
PrintDevEntity entity = printDevService.getById(id);
|
||||
if (entity == null) {
|
||||
return ActionResult.fail(MsgCode.PRI001.get());
|
||||
}
|
||||
ArrayList<Object> list = new ArrayList<>();
|
||||
if (query.getFormInfo() != null && query.getFormInfo().size() > 0) {
|
||||
List<PrintDevParam> flowTaskInfo = query.getFormInfo();
|
||||
for (PrintDevParam rid : flowTaskInfo) {
|
||||
String oneId = "";
|
||||
String flowTaskId = "";
|
||||
if (Objects.nonNull(rid.getFormId())) {
|
||||
oneId = XSSEscape.escape(rid.getFormId().toString());
|
||||
}
|
||||
if (Objects.nonNull(rid.getFlowTaskId())) {
|
||||
flowTaskId = XSSEscape.escape(rid.getFlowTaskId().toString());
|
||||
}
|
||||
Map<String, Object> dataMap = printDevService.getDataMap(id, oneId, flowTaskId, query.getMap());
|
||||
dataMap.put("fullName", entity.getFullName());
|
||||
list.add(dataMap);
|
||||
}
|
||||
return ActionResult.success(list);
|
||||
}
|
||||
return ActionResult.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询打印列表
|
||||
*
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "查询打印列表")
|
||||
@Parameters({
|
||||
@Parameter(name = "ids", description = "主键集合")
|
||||
})
|
||||
@PostMapping("getListById")
|
||||
public List<PrintOption> getListById(@RequestBody List<String> ids) {
|
||||
return printDevService.getPrintTemplateOptions(ids);
|
||||
}
|
||||
|
||||
@Operation(summary = "查询打印列表")
|
||||
@Parameters({
|
||||
@Parameter(name = "data", description = "打印模板-数查询对象")
|
||||
})
|
||||
@PostMapping("getListOptions")
|
||||
public ActionResult getListOptions(@RequestBody PrintDevDataQuery data) {
|
||||
List<String> ids = data.getIds();
|
||||
QueryWrapper<PrintDevEntity> wrapper = new QueryWrapper<>();
|
||||
wrapper.lambda().in(PrintDevEntity::getId, ids);
|
||||
List<PrintDevEntity> list = printDevService.getBaseMapper().selectList(wrapper);
|
||||
List<PrintOption> options = JsonUtil.getJsonToList(list, PrintOption.class);
|
||||
return ActionResult.success(options);
|
||||
}
|
||||
|
||||
//新增
|
||||
|
||||
@Operation(summary = "列表预览")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "打印模板id")
|
||||
})
|
||||
@SaCheckPermission("onlineDev.printDev")
|
||||
@GetMapping("/{id}/Actions/Preview")
|
||||
public ActionResult<PrintDevInfoVO> previewInfo(@PathVariable("id") String id) {
|
||||
List<PrintVersionEntity> list = versionService.getList(id);
|
||||
if (CollectionUtils.isEmpty(list)) {
|
||||
return ActionResult.fail(MsgCode.FA001.get());
|
||||
}
|
||||
PrintDevInfoVO info = printDevService.getVersionInfo(list.get(0).getId());
|
||||
PrintDevInfoVO vo = JsonUtil.getJsonToBean(info, PrintDevInfoVO.class);
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
@Operation(summary = "打印模板业务列表")
|
||||
@GetMapping("/WorkSelector")
|
||||
public ActionResult<PageListVO<PrintDevListVO>> getWorkSelector(PaginationPrint pagination) {
|
||||
List<PrintDevEntity> list = printDevService.getWorkSelector(pagination);
|
||||
List<PrintDevListVO> listVO = JsonUtil.getJsonToList(list, PrintDevListVO.class);
|
||||
PaginationVO paginationVO = JsonUtil.getJsonToBean(pagination, PaginationVO.class);
|
||||
return ActionResult.page(listVO, paginationVO);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
package com.yunzhupaas.base.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import com.yunzhupaas.base.PaginationTime;
|
||||
import com.yunzhupaas.base.UserInfo;
|
||||
import com.yunzhupaas.base.model.vo.PrintLogVO;
|
||||
import com.yunzhupaas.base.vo.PaginationVO;
|
||||
import com.yunzhupaas.constant.MsgCode;
|
||||
import com.yunzhupaas.permission.service.UserService;
|
||||
import com.yunzhupaas.util.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import com.yunzhupaas.base.ActionResult;
|
||||
import com.yunzhupaas.base.entity.PrintLogEntity;
|
||||
import com.yunzhupaas.base.service.PrintLogService;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import com.yunzhupaas.base.model.printlog.PrintLogInfo;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@Tag(name = "打印模板日志", description = "PrintLogController")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/printLog")
|
||||
public class PrintLogController {
|
||||
@Autowired
|
||||
private PrintLogService printLogService;
|
||||
|
||||
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
/**
|
||||
* 获取列表
|
||||
*
|
||||
* @param page 分页模型
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "获取列表")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "打印模板ID", required = true)
|
||||
})
|
||||
@SaCheckPermission("system.printDev")
|
||||
@GetMapping("/{id}")
|
||||
public ActionResult<?> list(@PathVariable("id") String printId, PaginationTime page) {
|
||||
List<PrintLogVO> list = printLogService.list(printId, page);
|
||||
PaginationVO paginationVO = JsonUtil.getJsonToBean(page, PaginationVO.class);
|
||||
return ActionResult.page(list, paginationVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存信息
|
||||
*
|
||||
* @param info 实体对象
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "保存信息")
|
||||
@Parameters({
|
||||
@Parameter(name = "info", description = "实体对象", required = true)
|
||||
})
|
||||
@SaCheckPermission("system.printDev")
|
||||
@PostMapping("save")
|
||||
public ActionResult<?> save(@RequestBody @Validated PrintLogInfo info) {
|
||||
PrintLogEntity printLogEntity = BeanUtil.copyProperties(info, PrintLogEntity.class);
|
||||
UserInfo userInfo = UserProvider.getUser();
|
||||
|
||||
printLogEntity.setId(RandomUtil.uuId());
|
||||
printLogEntity.setCreatorTime(new Date());
|
||||
printLogEntity.setCreatorUserId(userInfo.getUserId());
|
||||
printLogService.save(printLogEntity);
|
||||
return ActionResult.success(MsgCode.SU002);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,213 @@
|
||||
package com.yunzhupaas.base.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
||||
import com.google.common.base.Joiner;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import com.yunzhupaas.base.ActionResult;
|
||||
import com.yunzhupaas.base.entity.ProvinceAtlasEntity;
|
||||
import com.yunzhupaas.base.model.province.AtlasJsonModel;
|
||||
import com.yunzhupaas.base.model.province.MapParams;
|
||||
import com.yunzhupaas.base.model.province.ProvinceListTreeVO;
|
||||
import com.yunzhupaas.base.service.ProvinceAtlasService;
|
||||
import com.yunzhupaas.constant.MsgCode;
|
||||
import com.yunzhupaas.util.JsonUtil;
|
||||
import com.yunzhupaas.util.NoDataSourceBind;
|
||||
import com.yunzhupaas.util.ServletUtil;
|
||||
import com.yunzhupaas.util.StringUtil;
|
||||
import com.yunzhupaas.util.wxutil.HttpUtil;
|
||||
import net.sourceforge.pinyin4j.PinyinHelper;
|
||||
import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType;
|
||||
import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;
|
||||
import net.sourceforge.pinyin4j.format.HanyuPinyinToneType;
|
||||
import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.math.BigDecimal;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 行政区划-地图
|
||||
*
|
||||
* @author 云筑产品开发平台组
|
||||
* @version V3.4.2
|
||||
* @copyright 深圳市乐程软件有限公司
|
||||
* @date 2023/1/29 10:41:25
|
||||
*/
|
||||
@Tag(name = "行政区划-地图", description = "atlas")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/atlas")
|
||||
public class ProvinceAtlasController extends SuperController<ProvinceAtlasService, ProvinceAtlasEntity> {
|
||||
|
||||
@Autowired
|
||||
private ProvinceAtlasService provinceAtlasService;
|
||||
public static final String ATLAS_URL = "https://geo.datav.aliyun.com/areas_v3/bound/geojson?code=";
|
||||
|
||||
//树形递归
|
||||
private static boolean addChild(ProvinceListTreeVO node, List<ProvinceListTreeVO> list) {
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
ProvinceListTreeVO n = list.get(i);
|
||||
if (n.getId().equals(node.getParentId())) {
|
||||
if (n.getChildren() == null) {
|
||||
n.setChildren(new ArrayList<>());
|
||||
}
|
||||
List<ProvinceListTreeVO> children = n.getChildren();
|
||||
children.add(node);
|
||||
n.setChildren(children);
|
||||
return true;
|
||||
}
|
||||
if (n.getChildren() != null && n.getChildren().size() > 0) {
|
||||
List<ProvinceListTreeVO> children = n.getChildren();
|
||||
if (addChild(node, children)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有列表
|
||||
*
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "获取所有列表")
|
||||
@GetMapping
|
||||
public ActionResult<List<ProvinceListTreeVO>> list() {
|
||||
List<ProvinceAtlasEntity> list = provinceAtlasService.getList();
|
||||
List<ProvinceListTreeVO> listVOS = JsonUtil.getJsonToList(list, ProvinceListTreeVO.class);
|
||||
listVOS.forEach(item -> {
|
||||
if( StringUtil.isNotEmpty(item.getAtlasCenter())){
|
||||
String[] split = item.getAtlasCenter().split(",");
|
||||
item.setCenterLong(new BigDecimal(split[0]));
|
||||
item.setCenterLat(new BigDecimal(split[1]));
|
||||
}
|
||||
});
|
||||
for (int i = 0; i < listVOS.size(); i++) {
|
||||
ProvinceListTreeVO item = listVOS.get(i);
|
||||
if (!StringUtil.isEmpty(item.getParentId())) {
|
||||
if (addChild(item, listVOS) && listVOS.size() > 0) {
|
||||
listVOS.remove(item);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ActionResult.success(listVOS);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取列表
|
||||
*
|
||||
* @param pid 主键
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "获取列表")
|
||||
@Parameters({
|
||||
@Parameter(name = "pid", description = "主键", required = true)
|
||||
})
|
||||
@GetMapping("/list/{pid}")
|
||||
public ActionResult<List<ProvinceListTreeVO>> getListByPid(@PathVariable("pid") String pid) {
|
||||
List<ProvinceAtlasEntity> list = provinceAtlasService.getListByPid(pid);
|
||||
List<ProvinceListTreeVO> listVOS = JsonUtil.getJsonToList(list, ProvinceListTreeVO.class);
|
||||
return ActionResult.success(listVOS);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取地图json
|
||||
*
|
||||
* @param code 编码
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "获取地图json")
|
||||
@Parameters({
|
||||
@Parameter(name = "code", description = "编码", required = true)
|
||||
})
|
||||
@GetMapping("/geojson")
|
||||
public ActionResult<JSONObject> geojson(@RequestParam("code") String code) {
|
||||
ProvinceAtlasEntity oneByCode = provinceAtlasService.findOneByCode(code);
|
||||
if(oneByCode == null){
|
||||
return ActionResult.fail(MsgCode.SYS022.get());
|
||||
}
|
||||
List<ProvinceAtlasEntity> listByPid = provinceAtlasService.getListByPid(oneByCode.getId());
|
||||
String url = ATLAS_URL + code;
|
||||
if (CollectionUtils.isNotEmpty(listByPid)) {
|
||||
url += "_full";
|
||||
}
|
||||
JSONObject rstObj;
|
||||
try {
|
||||
rstObj = HttpUtil.httpRequest(url, "GET", null);
|
||||
} catch (Exception e) {
|
||||
return ActionResult.fail(MsgCode.SYS023.get());
|
||||
}
|
||||
if (rstObj == null) {
|
||||
return ActionResult.fail(MsgCode.SYS024.get());
|
||||
}
|
||||
return ActionResult.success(rstObj);
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步行政区划信息
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "同步行政区划信息")
|
||||
@GetMapping("/crePy")
|
||||
public ActionResult crePy() {
|
||||
List<ProvinceAtlasEntity> list = provinceAtlasService.list();
|
||||
for (ProvinceAtlasEntity p : list) {
|
||||
|
||||
String url = ATLAS_URL + p.getId();
|
||||
JSONObject rstObj;
|
||||
try {
|
||||
rstObj = HttpUtil.httpRequest(url, "GET", null);
|
||||
if (rstObj == null) {
|
||||
provinceAtlasService.removeById(p);
|
||||
} else {
|
||||
//将获取到的信息写入表
|
||||
AtlasJsonModel jsonToBean = JsonUtil.getJsonToBean(rstObj, AtlasJsonModel.class);
|
||||
List<BigDecimal> center = jsonToBean.getFeatures().get(0).getProperties().getCenter();
|
||||
p.setAtlasCenter(Joiner.on(",").join(center));
|
||||
//生成拼音
|
||||
// String getpy = getpy(p.getFullName());
|
||||
// p.setQuickQuery(getpy);
|
||||
provinceAtlasService.updateById(p);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return ActionResult.fail(MsgCode.SYS023.get());
|
||||
}
|
||||
}
|
||||
return ActionResult.success();
|
||||
}
|
||||
|
||||
private String getpy(String name) {
|
||||
HanyuPinyinOutputFormat outputFormat = new HanyuPinyinOutputFormat();
|
||||
outputFormat.setCaseType(HanyuPinyinCaseType.LOWERCASE);
|
||||
outputFormat.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
|
||||
StringBuilder result = new StringBuilder();
|
||||
char[] charArray = name.toCharArray();
|
||||
for (char c : charArray) {
|
||||
try {
|
||||
String[] pinyinArray = PinyinHelper.toHanyuPinyinStringArray(c, outputFormat);
|
||||
result.append(pinyinArray[0]);
|
||||
} catch (BadHanyuPinyinOutputFormatCombination e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,282 @@
|
||||
package com.yunzhupaas.base.controller;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.Valid;
|
||||
import com.yunzhupaas.base.ActionResult;
|
||||
import com.yunzhupaas.base.entity.DictionaryDataEntity;
|
||||
import com.yunzhupaas.base.entity.ScheduleNewEntity;
|
||||
import com.yunzhupaas.base.entity.ScheduleNewUserEntity;
|
||||
import com.yunzhupaas.base.model.schedule.*;
|
||||
import com.yunzhupaas.base.service.DictionaryDataService;
|
||||
import com.yunzhupaas.base.service.ScheduleNewApi;
|
||||
import com.yunzhupaas.base.service.ScheduleNewService;
|
||||
import com.yunzhupaas.base.service.ScheduleNewUserService;
|
||||
import com.yunzhupaas.base.vo.ListVO;
|
||||
import com.yunzhupaas.constant.MsgCode;
|
||||
import com.yunzhupaas.message.entity.SendMessageConfigEntity;
|
||||
import com.yunzhupaas.message.service.SendMessageConfigService;
|
||||
import com.yunzhupaas.permission.entity.UserEntity;
|
||||
import com.yunzhupaas.permission.service.UserService;
|
||||
import com.yunzhupaas.util.DateUtil;
|
||||
import com.yunzhupaas.util.JsonUtil;
|
||||
import com.yunzhupaas.util.RandomUtil;
|
||||
import com.yunzhupaas.util.StringUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 日程
|
||||
*
|
||||
* @author 云筑产品开发平台组
|
||||
* @copyright 深圳市乐程软件有限公司(http://www.szlecheng.cn)
|
||||
*/
|
||||
@Tag(name = "日程", description = "Schedule")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/Schedule")
|
||||
public class ScheduleNewController extends SuperController<ScheduleNewService, ScheduleNewEntity> implements ScheduleNewApi {
|
||||
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
@Autowired
|
||||
private SendMessageConfigService messageTemplateConfigService;
|
||||
@Autowired
|
||||
private DictionaryDataService dictionaryDataService;
|
||||
@Autowired
|
||||
private ScheduleNewService scheduleNewService;
|
||||
@Autowired
|
||||
private ScheduleNewUserService scheduleNewUserService;
|
||||
|
||||
/**
|
||||
* 获取日程安排列表
|
||||
*
|
||||
* @param scheduleNewTime 分页模型
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "获取日程安排列表")
|
||||
@GetMapping
|
||||
public ActionResult<ListVO<ScheduleNewListVO>> list(ScheduleNewTime scheduleNewTime) {
|
||||
List<ScheduleNewEntity> list = scheduleNewService.getList(scheduleNewTime);
|
||||
Date start = DateUtil.stringToDates(scheduleNewTime.getStartTime());
|
||||
Date end = DateUtil.stringToDates(scheduleNewTime.getEndTime());
|
||||
List<Date> dataAll = DateUtil.getAllDays(start, end);
|
||||
List<ScheduleNewEntity> result = new ArrayList<>();
|
||||
if (list.size() > 0) {
|
||||
for (Date date : dataAll) {
|
||||
for (ScheduleNewEntity entity : list) {
|
||||
Date startDay = DateUtil.stringToDates(DateUtil.daFormat(entity.getStartDay()));
|
||||
Date endDay = DateUtil.stringToDates(DateUtil.daFormat(entity.getEndDay()));
|
||||
if(DateUtil.isEffectiveDate(date,startDay,endDay)){
|
||||
result.add(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (ScheduleNewEntity item : result) {
|
||||
ScheduleNewEntity entity = BeanUtil.copyProperties(item, ScheduleNewEntity.class);
|
||||
if (entity.getAllDay() == 1) {
|
||||
entity.setEndDay(DateUtil.dateAddSeconds(entity.getEndDay(), 1));
|
||||
}
|
||||
}
|
||||
List<ScheduleNewListVO> vo = JsonUtil.getJsonToList(result, ScheduleNewListVO.class);
|
||||
ListVO listVO = new ListVO();
|
||||
listVO.setList(vo);
|
||||
return ActionResult.success(listVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取日程安排列表
|
||||
*
|
||||
* @param scheduleNewTime 分页模型
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "获取日程安排列表")
|
||||
@GetMapping("/AppList")
|
||||
public ActionResult<ScheduleNewAppListVO> selectList(ScheduleNewTime scheduleNewTime) {
|
||||
Map<String, Object> signMap = new HashMap<>(16);
|
||||
List<ScheduleNewEntity> list = scheduleNewService.getList(scheduleNewTime);
|
||||
Date start = DateUtil.stringToDates(scheduleNewTime.getStartTime());
|
||||
Date end = DateUtil.stringToDates(scheduleNewTime.getEndTime());
|
||||
List<Date> dateList = new ArrayList() {{
|
||||
add(start);
|
||||
add(end);
|
||||
}};
|
||||
if(StringUtils.isNotEmpty(scheduleNewTime.getDateTime())){
|
||||
dateList.add(DateUtil.strToDate(scheduleNewTime.getDateTime()));
|
||||
}
|
||||
Date minDate = dateList.stream().min(Date::compareTo).get();
|
||||
Date maxDate = dateList.stream().max(Date::compareTo).get();
|
||||
List<Date> dataAll = DateUtil.getAllDays(minDate, maxDate);
|
||||
ScheduleNewAppListVO vo = new ScheduleNewAppListVO();
|
||||
String pattern = "yyyyMMdd";
|
||||
String dateTime = StringUtils.isEmpty(scheduleNewTime.getDateTime()) ? DateUtil.dateNow(pattern) : scheduleNewTime.getDateTime().replaceAll("-", "");
|
||||
List<ScheduleNewEntity> todayList = new ArrayList<>();
|
||||
for (Date date : dataAll) {
|
||||
String time = DateUtil.dateToString(date, pattern);
|
||||
List<ScheduleNewEntity> result = new ArrayList<>();
|
||||
for (ScheduleNewEntity entity : list) {
|
||||
Date startDay = DateUtil.stringToDates(DateUtil.daFormat(entity.getStartDay()));
|
||||
Date endDay = DateUtil.stringToDates(DateUtil.daFormat(entity.getEndDay()));
|
||||
if(DateUtil.isEffectiveDate(date,startDay,endDay)){
|
||||
result.add(entity);
|
||||
}
|
||||
}
|
||||
signMap.put(time, result.size());
|
||||
if(time.equals(dateTime)){
|
||||
todayList.addAll(result);
|
||||
}
|
||||
}
|
||||
vo.setSignList(signMap);
|
||||
vo.setTodayList(JsonUtil.getJsonToList(todayList, ScheduleNewListVO.class));
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 信息
|
||||
*
|
||||
* @param id 主键
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "获取日程安排信息")
|
||||
@GetMapping("/{id}")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true),
|
||||
})
|
||||
public ActionResult<ScheduleNewInfoVO> info(@PathVariable("id") String id) {
|
||||
ScheduleNewEntity entity = scheduleNewService.getInfo(id);
|
||||
ScheduleNewInfoVO vo = JsonUtil.getJsonToBean(entity, ScheduleNewInfoVO.class);
|
||||
if (vo != null) {
|
||||
SendMessageConfigEntity config = StringUtil.isNotEmpty(vo.getSend()) ? messageTemplateConfigService.getInfo(vo.getSend()) : null;
|
||||
vo.setSendName(config!=null?config.getFullName():"");
|
||||
List<String> toUserIds = scheduleNewUserService.getList(entity.getId(),2).stream().map(ScheduleNewUserEntity::getToUserId).collect(Collectors.toList());
|
||||
vo.setToUserIds(toUserIds);
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
return ActionResult.fail(MsgCode.FA001.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 信息
|
||||
*
|
||||
* @param detailModel 查询模型
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "获取日程安排信息")
|
||||
@GetMapping("/detail")
|
||||
public ActionResult<ScheduleNewDetailInfoVO> detail(ScheduleDetailModel detailModel) {
|
||||
List<ScheduleNewEntity> groupList = scheduleNewService.getGroupList(detailModel);
|
||||
ScheduleNewEntity entity = groupList.size() > 0 ? groupList.get(0) : null;
|
||||
boolean isVO = entity != null;
|
||||
if (isVO) {
|
||||
ScheduleNewDetailInfoVO vo = JsonUtil.getJsonToBean(entity, ScheduleNewDetailInfoVO.class);
|
||||
DictionaryDataEntity info = dictionaryDataService.getInfo(entity.getCategory());
|
||||
vo.setCategory(info != null ? info.getFullName() : "");
|
||||
vo.setUrgent("1".equals(vo.getUrgent()) ? "普通" : "2".equals(vo.getUrgent()) ? "重要" : "紧急");
|
||||
UserEntity infoById = userService.getInfo(vo.getCreatorUserId());
|
||||
vo.setCreatorUserId(infoById != null ? infoById.getRealName() + "/" + infoById.getAccount() : "");
|
||||
List<String> toUserIds = scheduleNewUserService.getList(entity.getId(),2).stream().map(ScheduleNewUserEntity::getToUserId).collect(Collectors.toList());
|
||||
List<UserEntity> userName = userService.getUserName(toUserIds);
|
||||
StringJoiner joiner = new StringJoiner(",");
|
||||
for (UserEntity userEntity : userName) {
|
||||
joiner.add(userEntity.getRealName() + "/" + userEntity.getAccount());
|
||||
}
|
||||
vo.setToUserIds(joiner.toString());
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
return ActionResult.fail(MsgCode.SYS042.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 新建
|
||||
*
|
||||
* @param scheduleCrForm 日程模型
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "新建日程安排")
|
||||
@PostMapping
|
||||
@Parameters({
|
||||
@Parameter(name = "scheduleCrForm", description = "日程模型",required = true),
|
||||
})
|
||||
public ActionResult create(@RequestBody @Valid ScheduleNewCrForm scheduleCrForm) {
|
||||
if (scheduleCrForm.paramCheck()) {
|
||||
return ActionResult.fail(scheduleCrForm.getErrMsg());
|
||||
}
|
||||
ScheduleNewEntity entity = JsonUtil.getJsonToBean(scheduleCrForm, ScheduleNewEntity.class);
|
||||
try {
|
||||
scheduleNewService.create(entity, scheduleCrForm.getToUserIds(), RandomUtil.uuId(),"1",new ArrayList<>());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return ActionResult.fail(e.getMessage());
|
||||
}
|
||||
return ActionResult.success(MsgCode.SU001.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新
|
||||
*
|
||||
* @param id 主键
|
||||
* @param scheduleUpForm 日程模型
|
||||
* @param type 1.此日程 2.此日程及后续 3.所有日程
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "更新日程安排")
|
||||
@PutMapping("/{id}/{type}")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true),
|
||||
@Parameter(name = "scheduleUpForm", description = "日程模型", required = true),
|
||||
@Parameter(name = "type", description = "类型", required = true),
|
||||
})
|
||||
public ActionResult update(@PathVariable("id") String id, @RequestBody @Valid ScheduleNewUpForm scheduleUpForm, @PathVariable("type") String type) {
|
||||
if("1".equals(type)){
|
||||
scheduleUpForm.setRepeatTime(null);
|
||||
scheduleUpForm.setRepetition(1);
|
||||
}
|
||||
if (scheduleUpForm.paramCheck()) {
|
||||
return ActionResult.fail(scheduleUpForm.getErrMsg());
|
||||
}
|
||||
ScheduleNewEntity entity = JsonUtil.getJsonToBean(scheduleUpForm, ScheduleNewEntity.class);
|
||||
boolean flag = false;
|
||||
try {
|
||||
flag = scheduleNewService.update(id, entity, scheduleUpForm.getToUserIds(), type);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return ActionResult.fail(e.getMessage());
|
||||
}
|
||||
if (flag == false) {
|
||||
return ActionResult.fail(MsgCode.FA002.get());
|
||||
}
|
||||
return ActionResult.success(MsgCode.SU004.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*
|
||||
* @param id 主键
|
||||
* @param type 1.此日程 2.此日程及后续 3.所有日程
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "删除日程安排")
|
||||
@DeleteMapping("/{id}/{type}")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true),
|
||||
@Parameter(name = "type", description = "类型", required = true),
|
||||
})
|
||||
public ActionResult delete(@PathVariable("id") String id, @PathVariable("type") String type) {
|
||||
ScheduleNewEntity entity = scheduleNewService.getInfo(id);
|
||||
if (entity != null) {
|
||||
scheduleNewService.delete(entity, type);
|
||||
return ActionResult.success(MsgCode.SU003.get());
|
||||
}
|
||||
return ActionResult.fail(MsgCode.FA003.get());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,172 @@
|
||||
package com.yunzhupaas.base.controller;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import com.yunzhupaas.base.ActionResult;
|
||||
import com.yunzhupaas.base.entity.SignatureEntity;
|
||||
import com.yunzhupaas.base.model.signature.*;
|
||||
import com.yunzhupaas.base.service.SignatureService;
|
||||
import com.yunzhupaas.base.vo.ListVO;
|
||||
import com.yunzhupaas.base.vo.PageListVO;
|
||||
import com.yunzhupaas.base.vo.PaginationVO;
|
||||
import com.yunzhupaas.constant.MsgCode;
|
||||
import com.yunzhupaas.base.model.signature.SignatureListVO;
|
||||
import com.yunzhupaas.util.JsonUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 电子签章
|
||||
*
|
||||
* @author 云筑产品开发平台组
|
||||
* @copyright 深圳市乐程软件有限公司(http://www.szlecheng.cn)
|
||||
*/
|
||||
@Tag(name = "电子签章", description = "Signature")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/Signature")
|
||||
public class SignatureController extends SuperController<SignatureService, SignatureEntity> {
|
||||
|
||||
|
||||
@Autowired
|
||||
private SignatureService signatureService;
|
||||
|
||||
/**
|
||||
* 获取电子签章列表
|
||||
*
|
||||
* @param signaturePage 分页模型
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "获取电子签章列表")
|
||||
@GetMapping
|
||||
public ActionResult<PageListVO<SignatureListVO>> list(PaginationSignature signaturePage) {
|
||||
List<SignatureListVO> list = signatureService.getList(signaturePage);
|
||||
PaginationVO paginationVO = JsonUtil.getJsonToBean(signaturePage, PaginationVO.class);
|
||||
return ActionResult.page(list, paginationVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取电子签章下拉框
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "获取电子签章下拉框")
|
||||
@GetMapping("/Selector")
|
||||
public ActionResult<ListVO<SignatureSelectorListVO>> selector() {
|
||||
List<SignatureEntity> list = signatureService.getList();
|
||||
List<SignatureSelectorListVO> listVOS = JsonUtil.getJsonToList(list, SignatureSelectorListVO.class);
|
||||
ListVO<SignatureSelectorListVO> vo = new ListVO<>();
|
||||
vo.setList(listVOS);
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过主键id集合获取有权限的电子签章列表
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "通过主键id集合获取有权限的电子签章列表")
|
||||
@PostMapping("/ListByIds")
|
||||
public ActionResult<ListVO<SignatureSelectorListVO>> listByIds(@RequestBody SignatureListByIdsModel model) {
|
||||
List<SignatureSelectorListVO> list = signatureService.getListByIds(model);
|
||||
ListVO<SignatureSelectorListVO> vo = new ListVO<>();
|
||||
vo.setList(list);
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取电子签章信息
|
||||
*
|
||||
* @param id 主键
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "获取电子签章信息")
|
||||
@GetMapping("/{id}")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true),
|
||||
})
|
||||
public ActionResult<SignatureInfoVO> info(@PathVariable("id") String id) {
|
||||
SignatureInfoVO vo = signatureService.getInfo(id);
|
||||
if (vo == null) {
|
||||
return ActionResult.fail(MsgCode.FA001.get());
|
||||
}
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新建电子签章
|
||||
*
|
||||
* @param signatureCrForm model
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "新建电子签章")
|
||||
@PostMapping
|
||||
@Parameters({
|
||||
@Parameter(name = "signatureCrForm", description = "新建电子签章模型", required = true),
|
||||
})
|
||||
public ActionResult create(@RequestBody @Valid SignatureCrForm signatureCrForm) {
|
||||
SignatureEntity entity = JsonUtil.getJsonToBean(signatureCrForm, SignatureEntity.class);
|
||||
if (signatureService.isExistByFullName(entity.getFullName(), entity.getId())) {
|
||||
return ActionResult.fail(MsgCode.EXIST001.get());
|
||||
}
|
||||
if (signatureService.isExistByEnCode(entity.getEnCode(), entity.getId())) {
|
||||
return ActionResult.fail(MsgCode.EXIST002.get());
|
||||
}
|
||||
signatureService.create(entity, signatureCrForm.getUserIds());
|
||||
return ActionResult.success(MsgCode.SU001.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新电子签章
|
||||
*
|
||||
* @param id 主键
|
||||
* @param signatureUpForm 日程模型
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "更新电子签章")
|
||||
@PutMapping("/{id}")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true),
|
||||
@Parameter(name = "signatureUpForm", description = "更新电子签章模型", required = true),
|
||||
})
|
||||
public ActionResult update(@PathVariable("id") String id, @RequestBody @Valid SignatureUpForm signatureUpForm) {
|
||||
SignatureEntity entity = signatureService.getInfoById(id);
|
||||
if (entity == null) {
|
||||
return ActionResult.fail(MsgCode.FA002.get());
|
||||
}
|
||||
if (signatureService.isExistByFullName(signatureUpForm.getFullName(), id)) {
|
||||
return ActionResult.fail(MsgCode.EXIST001.get());
|
||||
}
|
||||
if (signatureService.isExistByEnCode(signatureUpForm.getEnCode(), id)) {
|
||||
return ActionResult.fail(MsgCode.EXIST002.get());
|
||||
}
|
||||
boolean update = signatureService.update(id, signatureUpForm);
|
||||
return ActionResult.success(MsgCode.SU004.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除电子签章
|
||||
*
|
||||
* @param id 主键
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "删除电子签章")
|
||||
@DeleteMapping("/{id}")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true),
|
||||
})
|
||||
public ActionResult delete(@PathVariable("id") String id) {
|
||||
SignatureEntity entity = signatureService.getInfoById(id);
|
||||
if (entity == null) {
|
||||
return ActionResult.fail(MsgCode.FA003.get());
|
||||
}
|
||||
boolean delete = signatureService.delete(id);
|
||||
return ActionResult.success(MsgCode.SU003.get());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,235 @@
|
||||
package com.yunzhupaas.base.controller;
|
||||
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import com.yunzhupaas.base.ActionResult;
|
||||
import com.yunzhupaas.base.Page;
|
||||
import com.yunzhupaas.base.Pagination;
|
||||
import com.yunzhupaas.base.entity.SmsTemplateEntity;
|
||||
import com.yunzhupaas.base.model.smstemplate.*;
|
||||
import com.yunzhupaas.base.service.SmsTemplateService;
|
||||
import com.yunzhupaas.util.message.SmsUtil;
|
||||
import com.yunzhupaas.base.vo.ListVO;
|
||||
import com.yunzhupaas.base.vo.PageListVO;
|
||||
import com.yunzhupaas.base.vo.PaginationVO;
|
||||
import com.yunzhupaas.base.SmsModel;
|
||||
import com.yunzhupaas.constant.MsgCode;
|
||||
import com.yunzhupaas.util.JsonUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 短信模板控制类
|
||||
*
|
||||
* @author 云筑产品开发平台组
|
||||
* @version V3.1.0
|
||||
* @copyright 深圳市乐程软件有限公司(http://www.szlecheng.cn)
|
||||
* @date 2024-12-09
|
||||
*/
|
||||
@Tag(description = "SmsTemplateController", name = "短信模板控制类")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/SmsTemplate")
|
||||
public class SmsTemplateController extends SuperController<SmsTemplateService, SmsTemplateEntity> {
|
||||
|
||||
@Autowired
|
||||
private SmsTemplateService smsTemplateService;
|
||||
|
||||
/**
|
||||
* 短信模板列表
|
||||
*
|
||||
* @param pagination
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "短信模板列表")
|
||||
@GetMapping
|
||||
public ActionResult<PageListVO<SmsTemplateListVO>> list(Pagination pagination) {
|
||||
List<SmsTemplateEntity> list = smsTemplateService.getList(pagination);
|
||||
List<SmsTemplateListVO> listVO = JsonUtil.getJsonToList(list, SmsTemplateListVO.class);
|
||||
for (SmsTemplateListVO smsTemplateListVO : listVO) {
|
||||
if ("1".equals(smsTemplateListVO.getCompany())) {
|
||||
smsTemplateListVO.setCompany("阿里");
|
||||
} else if ("2".equals(smsTemplateListVO.getCompany())) {
|
||||
smsTemplateListVO.setCompany("腾讯");
|
||||
}
|
||||
}
|
||||
PaginationVO paginationVO = JsonUtil.getJsonToBean(pagination, PaginationVO.class);
|
||||
return ActionResult.page(listVO, paginationVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 短信模板下拉框
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "短信模板下拉框")
|
||||
@GetMapping("/Selector")
|
||||
public ActionResult<ListVO<SmsTemplateSelector>> selector(Page page) {
|
||||
List<SmsTemplateEntity> list = smsTemplateService.getList(page.getKeyword());
|
||||
List<SmsTemplateSelector> jsonToList = JsonUtil.getJsonToList(list, SmsTemplateSelector.class);
|
||||
for (SmsTemplateSelector smsTemplateSelector : jsonToList) {
|
||||
if ("1".equals(smsTemplateSelector.getCompany())) {
|
||||
smsTemplateSelector.setCompany("阿里");
|
||||
} else if ("2".equals(smsTemplateSelector.getCompany())) {
|
||||
smsTemplateSelector.setCompany("腾讯");
|
||||
}
|
||||
}
|
||||
ListVO<SmsTemplateSelector> listVO = new ListVO<>();
|
||||
listVO.setList(jsonToList);
|
||||
return ActionResult.success(listVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取消息模板
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "获取短信模板")
|
||||
@GetMapping("/{id}")
|
||||
public ActionResult<SmsTemplateVO> info(@PathVariable("id") String id) {
|
||||
SmsTemplateEntity entity = smsTemplateService.getInfo(id);
|
||||
SmsTemplateVO vo = JsonUtil.getJsonToBean(entity, SmsTemplateVO.class);
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新建
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "新建")
|
||||
@PostMapping
|
||||
public ActionResult<String> create(@RequestBody @Valid SmsTemplateCrForm smsTemplateCrForm) {
|
||||
SmsTemplateEntity entity = JsonUtil.getJsonToBean(smsTemplateCrForm, SmsTemplateEntity.class);
|
||||
if (smsTemplateService.isExistByTemplateName(entity.getFullName(), entity.getId())) {
|
||||
return ActionResult.fail(MsgCode.EXIST001.get());
|
||||
}
|
||||
if (smsTemplateService.isExistByEnCode(entity.getEnCode(), entity.getId())) {
|
||||
return ActionResult.fail(MsgCode.EXIST002.get());
|
||||
}
|
||||
smsTemplateService.create(entity);
|
||||
return ActionResult.success(MsgCode.SU001.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "修改")
|
||||
@PutMapping("/{id}")
|
||||
public ActionResult<String> update(@PathVariable("id") String id, @RequestBody @Valid SmsTemplateUpForm smsTemplateUpForm) {
|
||||
SmsTemplateEntity entity = JsonUtil.getJsonToBean(smsTemplateUpForm, SmsTemplateEntity.class);
|
||||
if (smsTemplateService.isExistByTemplateName(entity.getFullName(), id)) {
|
||||
return ActionResult.fail(MsgCode.EXIST001.get());
|
||||
}
|
||||
if (smsTemplateService.isExistByEnCode(entity.getEnCode(), id)) {
|
||||
return ActionResult.fail(MsgCode.EXIST002.get());
|
||||
}
|
||||
boolean flag = smsTemplateService.update(id, entity);
|
||||
if (!flag) {
|
||||
return ActionResult.fail(MsgCode.FA002.get());
|
||||
}
|
||||
return ActionResult.success(MsgCode.SU004.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "删除")
|
||||
@DeleteMapping("/{id}")
|
||||
public ActionResult<String> delete(@PathVariable("id") String id) {
|
||||
SmsTemplateEntity entity = smsTemplateService.getInfo(id);
|
||||
if (entity == null) {
|
||||
return ActionResult.fail(MsgCode.FA003.get());
|
||||
}
|
||||
smsTemplateService.delete(entity);
|
||||
return ActionResult.success(MsgCode.SU003.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改状态
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "修改状态")
|
||||
@PutMapping("/{id}/Actions/State")
|
||||
public ActionResult<String> update(@PathVariable("id") String id) {
|
||||
SmsTemplateEntity entity = smsTemplateService.getInfo(id);
|
||||
if (entity != null) {
|
||||
if (entity.getEnabledMark() == 0) {
|
||||
entity.setEnabledMark(1);
|
||||
} else {
|
||||
entity.setEnabledMark(0);
|
||||
}
|
||||
boolean flag = smsTemplateService.update(id, entity);
|
||||
if (!flag) {
|
||||
return ActionResult.fail(MsgCode.FA002.get());
|
||||
}
|
||||
return ActionResult.success(MsgCode.SU004.get());
|
||||
}
|
||||
return ActionResult.fail(MsgCode.FA002.get());
|
||||
}
|
||||
|
||||
@Operation(summary = "获取模板参数")
|
||||
@PostMapping("/getTemplate")
|
||||
public ActionResult<?> testConnect(@RequestBody SmsTemplateCrForm smsTemplateCrForm) {
|
||||
// 定义返回对象
|
||||
List<String> list = null;
|
||||
if (smsTemplateCrForm != null) {
|
||||
// 得到短信模型
|
||||
SmsModel smsModel = smsTemplateService.getSmsConfig();
|
||||
list = SmsUtil.querySmsTemplateRequest(smsTemplateCrForm.getCompany(), smsModel, smsTemplateCrForm.getEndpoint(), smsTemplateCrForm.getRegion(), smsTemplateCrForm.getTemplateId());
|
||||
}
|
||||
if (list == null) {
|
||||
return ActionResult.fail(MsgCode.SYS015.get());
|
||||
}
|
||||
return ActionResult.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定短信模板参数
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "获取指定短信模板参数")
|
||||
@GetMapping("/getTemplate/{id}")
|
||||
public ActionResult<?> getTemplateById(@PathVariable("id") String id) {
|
||||
// 定义返回对象
|
||||
List<String> list = new ArrayList<>();
|
||||
SmsTemplateEntity entity = smsTemplateService.getInfo(id);
|
||||
if (entity != null && entity.getCompany() != null) {
|
||||
// 得到系统配置
|
||||
SmsModel smsModel = smsTemplateService.getSmsConfig();
|
||||
list = SmsUtil.querySmsTemplateRequest(entity.getCompany(), smsModel, entity.getEndpoint(), entity.getRegion(), entity.getTemplateId());
|
||||
}
|
||||
if (list == null) {
|
||||
return ActionResult.success(new ArrayList<>());
|
||||
}
|
||||
return ActionResult.success(list);
|
||||
}
|
||||
|
||||
@Operation(summary = "发送测试短信")
|
||||
@PostMapping("/testSent")
|
||||
public ActionResult testSentSms(@RequestBody SmsTemplateCrForm smsTemplateCrForm) {
|
||||
if (smsTemplateCrForm.getCompany() != null) {
|
||||
// 得到短信模型
|
||||
SmsModel smsModel = smsTemplateService.getSmsConfig();
|
||||
// 发送短信
|
||||
String sentCode = SmsUtil.sentSms(smsTemplateCrForm.getCompany(), smsModel, smsTemplateCrForm.getEndpoint(), smsTemplateCrForm.getRegion(), smsTemplateCrForm.getPhoneNumbers(), smsTemplateCrForm.getSignContent(), smsTemplateCrForm.getTemplateId(), smsTemplateCrForm.getParameters());
|
||||
if ("OK".equalsIgnoreCase(sentCode)) {
|
||||
return ActionResult.success(MsgCode.SU017.get());
|
||||
}
|
||||
}
|
||||
return ActionResult.fail(MsgCode.GT103.get());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,888 @@
|
||||
package com.yunzhupaas.base.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import com.yunzhupaas.base.controller.SuperController;
|
||||
import cn.hutool.core.util.BooleanUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.dingtalk.api.response.OapiV2DepartmentListsubResponse;
|
||||
import com.dingtalk.api.response.OapiV2UserListResponse;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import com.yunzhupaas.base.ActionResult;
|
||||
import com.yunzhupaas.base.UserInfo;
|
||||
import com.yunzhupaas.config.ConfigValueUtil;
|
||||
import com.yunzhupaas.constant.MsgCode;
|
||||
import com.yunzhupaas.exception.DataException;
|
||||
import com.yunzhupaas.exception.WxErrorException;
|
||||
import com.yunzhupaas.message.entity.SynThirdInfoEntity;
|
||||
import com.yunzhupaas.message.model.message.*;
|
||||
import com.yunzhupaas.message.service.MessageService;
|
||||
import com.yunzhupaas.message.service.SynThirdDingTalkService;
|
||||
import com.yunzhupaas.message.service.SynThirdInfoService;
|
||||
import com.yunzhupaas.message.service.SynThirdQyService;
|
||||
import com.yunzhupaas.base.util.SynDingTalkUtil;
|
||||
import com.yunzhupaas.base.util.SynQyWebChatUtil;
|
||||
import com.yunzhupaas.message.util.SynThirdConsts;
|
||||
import com.yunzhupaas.message.util.SynThirdTotal;
|
||||
import com.yunzhupaas.model.BaseSystemInfo;
|
||||
import com.yunzhupaas.permission.entity.OrganizeEntity;
|
||||
import com.yunzhupaas.permission.entity.UserEntity;
|
||||
import com.yunzhupaas.permission.model.organize.OrganizeModel;
|
||||
import com.yunzhupaas.permission.service.OrganizeService;
|
||||
import com.yunzhupaas.permission.service.UserService;
|
||||
import com.yunzhupaas.util.*;
|
||||
import com.yunzhupaas.util.treeutil.SumTree;
|
||||
import com.yunzhupaas.util.treeutil.newtreeutil.TreeDotUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import java.text.ParseException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 第三方工具的公司-部门-用户同步表模型
|
||||
*
|
||||
* @author 云筑产品开发平台组
|
||||
* @version V3.1.0
|
||||
* @copyright 深圳市乐程软件有限公司
|
||||
* @date 2024/4/25 9:30
|
||||
*/
|
||||
@Tag(name = "第三方信息同步", description = "SynThirdInfo")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/SynThirdInfo")
|
||||
@Slf4j
|
||||
public class SynThirdInfoController extends SuperController<SynThirdInfoService, SynThirdInfoEntity> {
|
||||
|
||||
@Autowired
|
||||
private SynThirdInfoService synThirdInfoService;
|
||||
@Autowired
|
||||
private SynThirdQyService synThirdQyService;
|
||||
@Autowired
|
||||
private SynThirdDingTalkService synThirdDingTalkService;
|
||||
@Autowired
|
||||
private OrganizeService organizeService;
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
@Autowired
|
||||
private RedisUtil redisUtil;
|
||||
@Autowired
|
||||
private ConfigValueUtil configValueUtil;
|
||||
@Autowired
|
||||
private MessageService messageService;
|
||||
@Autowired
|
||||
private CacheKeyUtil cacheKeyUtil;
|
||||
|
||||
/**
|
||||
* 新增同步表信息
|
||||
*
|
||||
* @param synThirdInfoCrForm 新建模型
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "新增同步表信息")
|
||||
@Parameters({
|
||||
@Parameter(name = "synThirdInfoCrForm", description = "同步信息模型", required = true)
|
||||
})
|
||||
@SaCheckPermission("system.sysConfig")
|
||||
@PostMapping
|
||||
@DSTransactional
|
||||
public ActionResult create(@RequestBody @Valid SynThirdInfoCrForm synThirdInfoCrForm) throws DataException {
|
||||
UserInfo userInfo = UserProvider.getUser();
|
||||
SynThirdInfoEntity entity = JsonUtil.getJsonToBean(synThirdInfoCrForm, SynThirdInfoEntity.class);
|
||||
entity.setCreatorUserId(userInfo.getUserId());
|
||||
entity.setCreatorTime(DateUtil.getNowDate());
|
||||
entity.setId(RandomUtil.uuId());
|
||||
synThirdInfoService.create(entity);
|
||||
return ActionResult.success(MsgCode.SU001.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取同步表信息
|
||||
*
|
||||
* @param id 主键
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "获取同步表信息")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true)
|
||||
})
|
||||
@SaCheckPermission("system.sysConfig")
|
||||
@GetMapping("/{id}")
|
||||
public SynThirdInfoEntity getInfo(@PathVariable("id") String id) {
|
||||
SynThirdInfoEntity entity = synThirdInfoService.getInfo(id);
|
||||
return entity;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定类型的同步对象
|
||||
*
|
||||
* @param thirdType 1:企业微信 2:钉钉
|
||||
* @param dataType 1:公司 2:部门 3:用户
|
||||
* @param id dataType对应的对象ID
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "获取指定类型的同步对象")
|
||||
@GetMapping("/getInfoBySysObjId/{thirdType}/{dataType}/{id}")
|
||||
public SynThirdInfoEntity getInfoBySysObjId(@PathVariable("thirdType") String thirdType, @PathVariable("dataType") String dataType, @PathVariable("id") String id) {
|
||||
SynThirdInfoEntity entity = synThirdInfoService.getInfoBySysObjId(thirdType, dataType, id);
|
||||
return entity;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 更新同步表信息
|
||||
*
|
||||
* @param id 主键
|
||||
* @param synThirdInfoUpForm 修改对象
|
||||
* @return ignore
|
||||
* @throws DataException ignore
|
||||
*/
|
||||
@Operation(summary = "更新同步表信息")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true),
|
||||
@Parameter(name = "synThirdInfoUpForm", description = "同步模型", required = true)
|
||||
})
|
||||
@SaCheckPermission("system.sysConfig")
|
||||
@PutMapping("/{id}")
|
||||
@DSTransactional
|
||||
public ActionResult update(@PathVariable("id") String id, @RequestBody @Valid SynThirdInfoUpForm synThirdInfoUpForm) throws DataException {
|
||||
SynThirdInfoEntity entity = synThirdInfoService.getInfo(id);
|
||||
UserInfo userInfo = UserProvider.getUser();
|
||||
if (entity != null) {
|
||||
SynThirdInfoEntity entityUpd = JsonUtil.getJsonToBean(synThirdInfoUpForm, SynThirdInfoEntity.class);
|
||||
entityUpd.setCreatorUserId(entity.getCreatorUserId());
|
||||
entityUpd.setCreatorTime(entity.getCreatorTime());
|
||||
entityUpd.setLastModifyUserId(userInfo.getUserId());
|
||||
entityUpd.setLastModifyTime(DateUtil.getNowDate());
|
||||
synThirdInfoService.update(id, entityUpd);
|
||||
|
||||
return ActionResult.success(MsgCode.SU004.get());
|
||||
} else {
|
||||
return ActionResult.fail(MsgCode.FA002.get());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 删除同步表信息
|
||||
*
|
||||
* @param id 主键
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "删除同步表信息")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true)
|
||||
})
|
||||
@SaCheckPermission("system.sysConfig")
|
||||
@DeleteMapping("/{id}")
|
||||
@DSTransactional
|
||||
public ActionResult delete(@PathVariable("id") String id) {
|
||||
SynThirdInfoEntity entity = synThirdInfoService.getInfo(id);
|
||||
if (entity != null) {
|
||||
synThirdInfoService.delete(entity);
|
||||
}
|
||||
return ActionResult.success(MsgCode.SU003.get());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取第三方(如:企业微信、钉钉)的组织与用户同步统计信息
|
||||
*
|
||||
* @param thirdType 第三方类型(1:企业微信;2:钉钉)
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "获取第三方(如:企业微信、钉钉)的组织与用户同步统计信息")
|
||||
@Parameters({
|
||||
@Parameter(name = "thirdType", description = "第三方类型(1:企业微信;2:钉钉)", required = true)
|
||||
})
|
||||
@SaCheckPermission("system.sysConfig")
|
||||
@GetMapping("/getSynThirdTotal/{thirdType}")
|
||||
public ActionResult<List<SynThirdTotal>> getSynThirdTotal(@PathVariable("thirdType") String thirdType) {
|
||||
List<SynThirdTotal> synTotalList = new ArrayList<>();
|
||||
synTotalList.add(synThirdInfoService.getSynTotal(thirdType, SynThirdConsts.DATA_TYPE_ORG));
|
||||
synTotalList.add(synThirdInfoService.getSynTotal(thirdType, SynThirdConsts.DATA_TYPE_USER));
|
||||
return ActionResult.success(synTotalList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取第三方(如:企业微信、钉钉)的组织或用户同步统计信息
|
||||
*
|
||||
* @param thirdType 第三方类型(1:企业微信;2:钉钉)
|
||||
* @param dataType 数据类型(1:组织(公司与部门);2:用户)
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "获取第三方(如:企业微信、钉钉)的组织或用户同步统计信息")
|
||||
@Parameters({
|
||||
@Parameter(name = "thirdType", description = "第三方类型(1:企业微信;2:钉钉)", required = true),
|
||||
@Parameter(name = "dataType", description = "数据类型(1:组织(公司与部门);2:用户)", required = true)
|
||||
})
|
||||
@SaCheckPermission("system.sysConfig")
|
||||
@GetMapping("/getSynThirdTotal/{thirdType}/{dataType}")
|
||||
public SynThirdTotal getSynThirdTotal(@PathVariable("thirdType") String thirdType, @PathVariable("dataType") String dataType) {
|
||||
SynThirdTotal synThirdTotal = synThirdInfoService.getSynTotal(thirdType, dataType);
|
||||
return synThirdTotal;
|
||||
}
|
||||
|
||||
//==================================企业微信的公司-部门-用户批量同步到本系统20220609==================================
|
||||
|
||||
/**
|
||||
* 本地所有组织信息(包含公司和部门)同步到企业微信
|
||||
* 不带第三方错误定位判断的功能代码,只获取调用接口的返回信息 20210604
|
||||
*
|
||||
* @return ignore
|
||||
* @throws WxErrorException ignore
|
||||
*/
|
||||
@Operation(summary = "本地所有组织信息(包含公司和部门)同步到企业微信")
|
||||
@Parameters({
|
||||
@Parameter(name = "type", description = "类型", required = true)
|
||||
})
|
||||
@SaCheckPermission("system.sysConfig")
|
||||
@GetMapping("/synAllOrganizeSysToQy")
|
||||
public ActionResult synAllOrganizeSysToQy(@RequestParam("type") String type) throws WxErrorException {
|
||||
if("1".equals(type)){
|
||||
//类型为1走企业微信组织信息同步到本地
|
||||
ActionResult actionResult = this.synAllOrganizeQyToSys();
|
||||
return actionResult;
|
||||
}
|
||||
JSONObject retMsg = new JSONObject();
|
||||
BaseSystemInfo config = synThirdQyService.getQyhConfig();
|
||||
String corpId = config.getQyhCorpId();
|
||||
// 向企业微信插入数据需要另外token(凭证密钥)
|
||||
String corpSecret = config.getQyhAgentSecret();
|
||||
String access_token = "";
|
||||
try {
|
||||
// 获取Token值
|
||||
JSONObject tokenObject = SynQyWebChatUtil.getAccessToken(corpId, corpSecret);
|
||||
if (!tokenObject.getBoolean("code")) {
|
||||
return ActionResult.fail(MsgCode.SYS025.get());
|
||||
}
|
||||
access_token = tokenObject.getString("access_token");
|
||||
|
||||
// 获取同步表、部门表的信息
|
||||
List<SynThirdInfoEntity> synThirdInfoList = synThirdInfoService.getList(SynThirdConsts.THIRD_TYPE_QY, SynThirdConsts.DATA_TYPE_ORG);
|
||||
Map<String, OrganizeEntity> organizeList = organizeService.getOrgMapsAll();
|
||||
|
||||
// 部门进行树结构化,固化上下层级序列化
|
||||
List<OrganizeModel> organizeModelList = JsonUtil.getJsonToList(organizeList.values(), OrganizeModel.class);
|
||||
List<SumTree<OrganizeModel>> trees = TreeDotUtils.convertListToTreeDot(organizeModelList);
|
||||
List<OraganizeListVO> listVO = JsonUtil.getJsonToList(trees, OraganizeListVO.class);
|
||||
|
||||
// 转化成为按上下层级顺序排序的列表数据
|
||||
List<OrganizeEntity> listByOrder = new ArrayList<>();
|
||||
for (OraganizeListVO organizeVo : listVO) {
|
||||
OrganizeEntity entity = organizeList.get(organizeVo.getId());
|
||||
listByOrder.add(entity);
|
||||
SynQyWebChatUtil.getOrganizeTreeToList(organizeVo, organizeList, listByOrder);
|
||||
}
|
||||
|
||||
// 根据同步表、公司表进行比较,判断不存的执行删除
|
||||
for (SynThirdInfoEntity synThirdInfoEntity : synThirdInfoList) {
|
||||
if (organizeList.get(synThirdInfoEntity.getSysObjId()) == null) {
|
||||
//执行删除操作
|
||||
// retMsg = synThirdQyService.deleteDepartmentSysToQy(true, synThirdInfoEntity.getSysObjId(), access_token);
|
||||
}
|
||||
}
|
||||
|
||||
synThirdInfoList = synThirdInfoService.getList(SynThirdConsts.THIRD_TYPE_QY, SynThirdConsts.DATA_TYPE_ORG);
|
||||
// 根据公司表、同步表进行比较,决定执行创建、还是更新
|
||||
for (OrganizeEntity organizeEntity : listByOrder) {
|
||||
if (synThirdInfoList.stream().filter(t -> t.getSysObjId().equals(organizeEntity.getId())).count() > 0 ? true : false) {
|
||||
// 执行更新功能
|
||||
retMsg = synThirdQyService.updateDepartmentSysToQy(true, organizeEntity, access_token);
|
||||
} else {
|
||||
// 执行创建功能
|
||||
retMsg = synThirdQyService.createDepartmentSysToQy(true, organizeEntity, access_token);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
ActionResult.fail(e.toString());
|
||||
}
|
||||
//获取结果
|
||||
SynThirdTotal synThirdTotal = synThirdInfoService.getSynTotal(SynThirdConsts.THIRD_TYPE_QY, SynThirdConsts.DATA_TYPE_ORG);
|
||||
return ActionResult.success(synThirdTotal);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 本地所有用户信息同步到企业微信
|
||||
* 不带第三方错误定位判断的功能代码,只获取调用接口的返回信息 20210604
|
||||
*
|
||||
* @return ignore
|
||||
* @throws WxErrorException ignore
|
||||
*/
|
||||
@Operation(summary = "本地所有用户信息同步到企业微信")
|
||||
@Parameters({
|
||||
@Parameter(name = "type", description = "类型", required = true)
|
||||
})
|
||||
@SaCheckPermission("system.sysConfig")
|
||||
@GetMapping("/synAllUserSysToQy")
|
||||
public ActionResult synAllUserSysToQy(@RequestParam("type") String type) throws WxErrorException {
|
||||
if("1".equals(type)){
|
||||
//类型为1走企业微信用户同步到本地
|
||||
ActionResult actionResult = this.synAllUserQyToSys();
|
||||
return actionResult;
|
||||
}
|
||||
JSONObject retMsg = new JSONObject();
|
||||
BaseSystemInfo config = synThirdQyService.getQyhConfig();
|
||||
String corpId = config.getQyhCorpId();
|
||||
// 向企业微信插入数据需要另外token(凭证密钥)
|
||||
String corpSecret = config.getQyhAgentSecret();
|
||||
String access_token = "";
|
||||
|
||||
try {
|
||||
// 获取Token值
|
||||
JSONObject tokenObject = SynQyWebChatUtil.getAccessToken(corpId, corpSecret);
|
||||
if (!tokenObject.getBoolean("code")) {
|
||||
return ActionResult.fail(MsgCode.SYS025.get());
|
||||
}
|
||||
access_token = tokenObject.getString("access_token");
|
||||
|
||||
// 获取同步表、用户表的信息
|
||||
List<SynThirdInfoEntity> synThirdInfoList = synThirdInfoService.getList(SynThirdConsts.THIRD_TYPE_QY, SynThirdConsts.DATA_TYPE_USER);
|
||||
List<UserEntity> userList = userService.getList(false);
|
||||
|
||||
// 根据同步表、公司表进行比较,判断不存的执行删除
|
||||
for (SynThirdInfoEntity synThirdInfoEntity : synThirdInfoList) {
|
||||
if (userList.stream().filter(t -> t.getId().equals(synThirdInfoEntity.getSysObjId())).count() == 0 ? true : false) {
|
||||
//执行删除操作
|
||||
retMsg = synThirdQyService.deleteUserSysToQy(true, synThirdInfoEntity.getSysObjId(), access_token);
|
||||
}
|
||||
}
|
||||
|
||||
// 根据公司表、同步表进行比较,决定执行创建、还是更新
|
||||
for (UserEntity userEntity : userList) {
|
||||
if (synThirdInfoList.stream().filter(t -> t.getSysObjId().equals(userEntity.getId())).count() == 0 ? true : false) {
|
||||
// 执行创建功能
|
||||
retMsg = synThirdQyService.createUserSysToQy(true, userEntity, access_token);
|
||||
} else {
|
||||
// 执行更新功能
|
||||
retMsg = synThirdQyService.updateUserSysToQy(true, userEntity, access_token);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
ActionResult.fail(e.toString());
|
||||
}
|
||||
|
||||
//获取结果
|
||||
SynThirdTotal synThirdTotal = synThirdInfoService.getSynTotal(SynThirdConsts.THIRD_TYPE_QY, SynThirdConsts.DATA_TYPE_USER);
|
||||
return ActionResult.success(synThirdTotal);
|
||||
}
|
||||
|
||||
//==================================企业微信的公司-部门-用户批量同步到本系统20220609==================================
|
||||
|
||||
/**
|
||||
* 企业微信所有组织信息(包含公司和部门)同步到本系统
|
||||
*
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "企业微信所有组织信息(包含公司和部门)同步到本系统")
|
||||
@SaCheckPermission("system.sysConfig")
|
||||
@GetMapping("/synAllOrganizeQyToSys")
|
||||
public ActionResult synAllOrganizeQyToSys() {
|
||||
// 设置redis的key
|
||||
String synDing = "";
|
||||
UserInfo userInfo = UserProvider.getUser();
|
||||
if (configValueUtil.isMultiTenancy()) {
|
||||
synDing = userInfo.getTenantId() + "_" + userInfo.getUserId() + "_synAllOrganizeQyToSys";
|
||||
} else {
|
||||
synDing = userInfo.getUserId() + "_synAllOrganizeQyToSys";
|
||||
}
|
||||
// 如果redis中存在key说明同步正在进行
|
||||
if (redisUtil.exists(synDing)) {
|
||||
return ActionResult.fail(MsgCode.SYS026.get());
|
||||
}
|
||||
BaseSystemInfo config = synThirdQyService.getQyhConfig();
|
||||
|
||||
// 获取Token值
|
||||
JSONObject tokenObject = SynQyWebChatUtil.getAccessToken(config.getQyhCorpId(), config.getQyhCorpSecret());
|
||||
if (!tokenObject.getBoolean("code")) {
|
||||
return ActionResult.fail(MsgCode.SYS025.get());
|
||||
}
|
||||
|
||||
// 异步执行
|
||||
String finalSynDing = synDing;
|
||||
ThreadPoolExecutorUtil.getExecutor().execute(() -> {
|
||||
String userId = userInfo.getUserId();
|
||||
try {
|
||||
redisUtil.insert(finalSynDing, "true");
|
||||
String access_token = tokenObject.getString("access_token");
|
||||
|
||||
List<OapiV2DepartmentListsubResponse.DeptBaseResponse> DingDeptList = new ArrayList<>();
|
||||
|
||||
List<QyWebChatDeptModel> QyDeptAllList = new ArrayList<>();
|
||||
|
||||
// 获取同步表的信息
|
||||
List<SynThirdInfoEntity> synThirdInfoList = synThirdInfoService.syncThirdInfoByType(SynThirdConsts.THIRD_TYPE_QY_To_Sys, SynThirdConsts.DATA_TYPE_ORG, SynThirdConsts.THIRD_TYPE_QY);
|
||||
|
||||
// 获取企业微信上的根目录部门(本系统的组织)
|
||||
String departId = SynThirdConsts.QY_ROOT_DEPT_ID;
|
||||
|
||||
// 获取企业微信上的部门列表
|
||||
JSONObject retMsg = SynQyWebChatUtil.getDepartmentList(departId, access_token);
|
||||
StringBuilder department = new StringBuilder(retMsg.get("department").toString());
|
||||
QyDeptAllList = JsonUtil.getJsonToList(department.toString(),QyWebChatDeptModel.class);
|
||||
|
||||
|
||||
// 根据同步表、公司表进行比较,判断不存的执行删除
|
||||
for (SynThirdInfoEntity synThirdInfoEntity : synThirdInfoList) {
|
||||
if (QyDeptAllList.stream().filter(t -> String.valueOf(t.getParentid()).equals(synThirdInfoEntity.getThirdObjId())).count() == 0) {
|
||||
// // 执行删除操作
|
||||
// retMsg = synThirdDingTalkService.deleteDepartmentDingToSys(true, synThirdInfoEntity.getThirdObjId());
|
||||
}
|
||||
}
|
||||
|
||||
// 删除后需要重新获取数据
|
||||
synThirdInfoList = synThirdInfoService.getList(SynThirdConsts.THIRD_TYPE_QY_To_Sys, SynThirdConsts.DATA_TYPE_ORG);
|
||||
|
||||
// 根据公司表、同步表进行比较,决定执行创建、还是更新
|
||||
for (QyWebChatDeptModel qyWebChatDeptModel : QyDeptAllList) {
|
||||
if (synThirdInfoList.stream().filter(t -> t.getThirdObjId().equals(String.valueOf(qyWebChatDeptModel.getId()))).count() > 0) {
|
||||
// 执行本地更新功能
|
||||
synThirdQyService.updateDepartmentQyToSys(true, qyWebChatDeptModel, access_token);
|
||||
} else {
|
||||
// 执行本的创建功能
|
||||
synThirdQyService.createDepartmentQyToSys(true, qyWebChatDeptModel, access_token);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error(finalSynDing + ",企业微信所有组织信息同步到本系统失败:" + e.getMessage());
|
||||
} finally {
|
||||
redisUtil.remove(finalSynDing);
|
||||
redisUtil.remove(cacheKeyUtil.getOrganizeList());
|
||||
List<String> toUserId = new ArrayList<>(1);
|
||||
toUserId.add(userId);
|
||||
messageService.sentMessage(toUserId, "企业微信所有组织信息同步到本系统", "同步完成", userInfo,1,1);
|
||||
redisUtil.remove(cacheKeyUtil.getOrganizeInfoList());
|
||||
}
|
||||
});
|
||||
return ActionResult.success(MsgCode.SYS026.get());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 企业微信所有用户信息同步到本系统
|
||||
*
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "企业微信所有用户信息同步到本系统")
|
||||
@SaCheckPermission("system.sysConfig")
|
||||
@GetMapping("/synAllUserQyToSys")
|
||||
@Transactional
|
||||
public ActionResult synAllUserQyToSys() {
|
||||
// 设置redis的key
|
||||
String synDing = "";
|
||||
UserInfo userInfo = UserProvider.getUser();
|
||||
if (configValueUtil.isMultiTenancy()) {
|
||||
synDing = userInfo.getTenantId() + "_" + userInfo.getUserId() + "_synAllUserQyToSys";
|
||||
} else {
|
||||
synDing = userInfo.getUserId() + "_synAllUserQyToSys";
|
||||
}
|
||||
// 如果redis中存在key说明同步正在进行
|
||||
if (redisUtil.exists(synDing)) {
|
||||
return ActionResult.fail(MsgCode.SYS026.get());
|
||||
}
|
||||
// 获取已同步的部门信息
|
||||
List<SynThirdInfoEntity> synThirdOrgList = synThirdInfoService.getList(SynThirdConsts.THIRD_TYPE_QY_To_Sys, SynThirdConsts.DATA_TYPE_ORG);
|
||||
List<String> dingDeptIdList = new ArrayList<>();
|
||||
if (synThirdOrgList != null && synThirdOrgList.size() > 0) {
|
||||
dingDeptIdList = synThirdOrgList.stream().map(SynThirdInfoEntity::getThirdObjId).distinct().collect(Collectors.toList());
|
||||
} else {
|
||||
return ActionResult.fail(MsgCode.SYS027.get());
|
||||
}
|
||||
|
||||
// 获取Token值
|
||||
BaseSystemInfo config = synThirdQyService.getQyhConfig();
|
||||
JSONObject tokenObject = SynQyWebChatUtil.getAccessToken(config.getQyhCorpId(), config.getQyhCorpSecret());
|
||||
if (!tokenObject.getBoolean("code")) {
|
||||
return ActionResult.fail(MsgCode.SYS025.get());
|
||||
}
|
||||
// 异步执行
|
||||
List<String> finalDingDeptIdList = dingDeptIdList;
|
||||
String finalSynDing = synDing;
|
||||
ThreadPoolExecutorUtil.getExecutor().execute(() -> {
|
||||
String userId = userInfo.getUserId();
|
||||
try {
|
||||
redisUtil.insert(finalSynDing, "true");
|
||||
List<OapiV2UserListResponse.ListUserResponse> dingUserList = new ArrayList<>();
|
||||
List<QyWebChatUserModel> qyUserAllList = new ArrayList<>();
|
||||
String access_token = tokenObject.getString("access_token");
|
||||
|
||||
// 获取企业微信的用户列表
|
||||
JSONObject retMsg = SynQyWebChatUtil.getUserList("1", "1",access_token);
|
||||
StringBuilder department = new StringBuilder(retMsg.get("userlist").toString());
|
||||
qyUserAllList = JsonUtil.getJsonToList(retMsg.get("userlist"),QyWebChatUserModel.class);
|
||||
|
||||
// 获取同步表、用户表的信息
|
||||
List<SynThirdInfoEntity> synThirdInfoList = synThirdInfoService.syncThirdInfoByType(SynThirdConsts.THIRD_TYPE_QY_To_Sys, SynThirdConsts.DATA_TYPE_USER, SynThirdConsts.THIRD_TYPE_QY);
|
||||
|
||||
// 根据同步表、公司表进行比较,判断不存的执行删除
|
||||
for (SynThirdInfoEntity synThirdInfoEntity : synThirdInfoList) {
|
||||
// 线上不包含中间表的这条记录
|
||||
if (qyUserAllList.stream().filter(t -> t.getUserid().equals(synThirdInfoEntity.getThirdObjId())).count() == 0) {
|
||||
// 执行删除此条中间表记录
|
||||
synThirdDingTalkService.deleteUserDingToSys(true, synThirdInfoEntity.getThirdObjId());
|
||||
}
|
||||
}
|
||||
// 得到企业微信信息
|
||||
List<SynThirdInfoEntity> synThirdInfoLists = synThirdInfoService.syncThirdInfoByType(SynThirdConsts.THIRD_TYPE_QY_To_Sys, SynThirdConsts.DATA_TYPE_USER, SynThirdConsts.THIRD_TYPE_QY);
|
||||
// 根据公司表、同步表进行比较,决定执行创建、还是更新
|
||||
for (QyWebChatUserModel qyWebChatUserModel : qyUserAllList) {
|
||||
if (synThirdInfoList.stream().filter(t -> t.getThirdObjId().equals(qyWebChatUserModel.getUserid())).count() == 0
|
||||
&& synThirdInfoLists.stream().filter(t -> t.getThirdObjId().equals(qyWebChatUserModel.getUserid())).count() == 0) {
|
||||
// 执行创建功能
|
||||
synThirdQyService.createUserQyToSys(true, qyWebChatUserModel,access_token);
|
||||
} else {
|
||||
// 执行更新功能
|
||||
synThirdQyService.updateUserQyToSystem(true, qyWebChatUserModel,access_token);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
log.error(finalSynDing + ",企业微信所有用户信息同步到本系统失败:" + e.getMessage());
|
||||
} finally {
|
||||
redisUtil.remove(finalSynDing);
|
||||
List<String> toUserId = new ArrayList<>(1);
|
||||
toUserId.add(userId);
|
||||
messageService.sentMessage(toUserId, "企业微信所有用户信息同步到本系统", "同步完成", userInfo,1,1);
|
||||
}
|
||||
});
|
||||
return ActionResult.success(MsgCode.SYS026.get());
|
||||
}
|
||||
|
||||
//==================================本系统的公司-部门-用户批量同步到钉钉==================================
|
||||
|
||||
/**
|
||||
* 本地所有组织信息(包含公司和部门)同步到钉钉
|
||||
* 不带第三方错误定位判断的功能代码 20210604
|
||||
*
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "本地所有组织信息(包含公司和部门)同步到钉钉")
|
||||
@Parameters({
|
||||
@Parameter(name = "type", description = "类型", required = true)
|
||||
})
|
||||
@SaCheckPermission("system.sysConfig")
|
||||
@GetMapping("/synAllOrganizeSysToDing")
|
||||
public ActionResult synAllOrganizeSysToDing(@RequestParam("type") String type) {
|
||||
if("1".equals(type)){
|
||||
//类型为1走钉钉组织部门信息同步到本地
|
||||
ActionResult actionResult = this.synAllOrganizeDingToSys();
|
||||
return actionResult;
|
||||
}
|
||||
JSONObject retMsg = new JSONObject();
|
||||
BaseSystemInfo config = synThirdDingTalkService.getDingTalkConfig();
|
||||
String corpId = config.getDingSynAppKey();
|
||||
String corpSecret = config.getDingSynAppSecret();
|
||||
|
||||
try {
|
||||
// 获取Token值
|
||||
JSONObject tokenObject = SynDingTalkUtil.getAccessToken(corpId, corpSecret);
|
||||
if (!tokenObject.getBoolean("code")) {
|
||||
return ActionResult.fail(MsgCode.SYS053.get());
|
||||
}
|
||||
String access_token = tokenObject.getString("access_token");
|
||||
|
||||
// 获取同步表、部门表的信息
|
||||
List<SynThirdInfoEntity> synThirdInfoList = synThirdInfoService.getList(SynThirdConsts.THIRD_TYPE_DING, SynThirdConsts.DATA_TYPE_ORG);
|
||||
Map<String, OrganizeEntity> organizeList = organizeService.getOrgMapsAll();
|
||||
|
||||
// 部门进行树结构化,固化上下层级序列化
|
||||
List<OrganizeModel> organizeModelList = JsonUtil.getJsonToList(organizeList.values(), OrganizeModel.class);
|
||||
List<SumTree<OrganizeModel>> trees = TreeDotUtils.convertListToTreeDot(organizeModelList);
|
||||
List<OraganizeListVO> listVO = JsonUtil.getJsonToList(trees, OraganizeListVO.class);
|
||||
|
||||
// 转化成为按上下层级顺序排序的列表数据
|
||||
List<OrganizeEntity> listByOrder = new ArrayList<>();
|
||||
for (OraganizeListVO organizeVo : listVO) {
|
||||
OrganizeEntity entity = organizeList.get(organizeVo.getId());
|
||||
listByOrder.add(entity);
|
||||
SynDingTalkUtil.getOrganizeTreeToList(organizeVo, organizeList, listByOrder);
|
||||
}
|
||||
|
||||
// 根据同步表、公司表进行比较,判断不存的执行删除
|
||||
for (SynThirdInfoEntity synThirdInfoEntity : synThirdInfoList) {
|
||||
if (organizeList.get(synThirdInfoEntity.getSysObjId()) == null) {
|
||||
//执行删除操作
|
||||
retMsg = synThirdDingTalkService.deleteDepartmentSysToDing(true, synThirdInfoEntity.getSysObjId(), access_token);
|
||||
}
|
||||
}
|
||||
|
||||
synThirdInfoList = synThirdInfoService.getList(SynThirdConsts.THIRD_TYPE_DING, SynThirdConsts.DATA_TYPE_ORG);
|
||||
// 根据公司表、同步表进行比较,决定执行创建、还是更新
|
||||
for (OrganizeEntity organizeEntity : listByOrder) {
|
||||
if (synThirdInfoList.stream().filter(t -> t.getSysObjId().equals(organizeEntity.getId())).count() > 0 ? true : false) {
|
||||
// 执行更新功能
|
||||
retMsg = synThirdDingTalkService.updateDepartmentSysToDing(true, organizeEntity, access_token);
|
||||
} else {
|
||||
// 执行创建功能
|
||||
retMsg = synThirdDingTalkService.createDepartmentSysToDing(true, organizeEntity, access_token);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
ActionResult.fail(e.toString());
|
||||
}
|
||||
|
||||
//获取结果
|
||||
SynThirdTotal synThirdTotal = synThirdInfoService.getSynTotal(SynThirdConsts.THIRD_TYPE_DING, SynThirdConsts.DATA_TYPE_ORG);
|
||||
return ActionResult.success(synThirdTotal);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 本地所有用户信息同步到钉钉
|
||||
* 不带第三方错误定位判断的功能代码 20210604
|
||||
*
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "本地所有用户信息同步到钉钉")
|
||||
@Parameters({
|
||||
@Parameter(name = "type", description = "类型", required = true)
|
||||
})
|
||||
@SaCheckPermission("system.sysConfig")
|
||||
@GetMapping("/synAllUserSysToDing")
|
||||
public ActionResult synAllUserSysToDing(@RequestParam("type") String type) throws ParseException {
|
||||
if("1".equals(type)){
|
||||
//类型为1走钉钉用户信息同步到本地
|
||||
ActionResult actionResult = this.synAllUserDingToSys();
|
||||
return actionResult;
|
||||
}
|
||||
JSONObject retMsg = new JSONObject();
|
||||
BaseSystemInfo config = synThirdDingTalkService.getDingTalkConfig();
|
||||
String corpId = config.getDingSynAppKey();
|
||||
String corpSecret = config.getDingSynAppSecret();
|
||||
|
||||
try {
|
||||
// 获取Token值
|
||||
JSONObject tokenObject = SynDingTalkUtil.getAccessToken(corpId, corpSecret);
|
||||
if (!tokenObject.getBoolean("code")) {
|
||||
return ActionResult.success(MsgCode.SYS053.get());
|
||||
}
|
||||
String access_token = tokenObject.getString("access_token");
|
||||
|
||||
// 获取同步表、用户表的信息
|
||||
List<SynThirdInfoEntity> synThirdInfoList = synThirdInfoService.getList(SynThirdConsts.THIRD_TYPE_DING, SynThirdConsts.DATA_TYPE_USER);
|
||||
List<UserEntity> userList = userService.getList(false);
|
||||
|
||||
// 根据同步表、公司表进行比较,判断不存的执行删除
|
||||
for (SynThirdInfoEntity synThirdInfoEntity : synThirdInfoList) {
|
||||
if (userList.stream().filter(t -> t.getId().equals(synThirdInfoEntity.getSysObjId())).count() == 0 ? true : false) {
|
||||
// 执行删除操作
|
||||
retMsg = synThirdDingTalkService.deleteUserSysToDing(true, synThirdInfoEntity.getSysObjId(), access_token);
|
||||
}
|
||||
}
|
||||
|
||||
// 根据公司表、同步表进行比较,决定执行创建、还是更新
|
||||
for (UserEntity userEntity : userList) {
|
||||
if (synThirdInfoList.stream().filter(t -> t.getSysObjId().equals(userEntity.getId())).count() == 0 ? true : false) {
|
||||
// 执行创建功能
|
||||
retMsg = synThirdDingTalkService.createUserSysToDing(true, userEntity, access_token);
|
||||
} else {
|
||||
// 执行更新功能
|
||||
retMsg = synThirdDingTalkService.updateUserSysToDing(true, userEntity, access_token);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
ActionResult.fail(e.toString());
|
||||
}
|
||||
|
||||
//获取结果
|
||||
SynThirdTotal synThirdTotal = synThirdInfoService.getSynTotal(SynThirdConsts.THIRD_TYPE_DING, SynThirdConsts.DATA_TYPE_USER);
|
||||
return ActionResult.success(synThirdTotal);
|
||||
}
|
||||
|
||||
|
||||
//==================================钉钉的公司-部门-用户批量同步到本系统20220330==================================
|
||||
|
||||
/**
|
||||
* 钉钉所有组织信息(包含公司和部门)同步到本系统
|
||||
* 不带第三方错误定位判断的功能代码 20220330
|
||||
*
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "钉钉所有组织信息(包含公司和部门)同步到本系统")
|
||||
@SaCheckPermission("system.sysConfig")
|
||||
@GetMapping("/synAllOrganizeDingToSys")
|
||||
public ActionResult synAllOrganizeDingToSys() {
|
||||
// 设置redis的key
|
||||
String synDing = "";
|
||||
UserInfo userInfo = UserProvider.getUser();
|
||||
if (configValueUtil.isMultiTenancy()) {
|
||||
synDing = userInfo.getTenantId() + "_" + userInfo.getUserId() + "_synAllOrganizeDingToSys";
|
||||
} else {
|
||||
synDing = userInfo.getUserId() + "_synAllOrganizeDingToSys";
|
||||
}
|
||||
// 如果redis中存在key说明同步正在进行
|
||||
if (redisUtil.exists(synDing)) {
|
||||
return ActionResult.fail(MsgCode.SYS026.get());
|
||||
}
|
||||
BaseSystemInfo config = synThirdDingTalkService.getDingTalkConfig();
|
||||
|
||||
// 获取Token值
|
||||
JSONObject tokenObject = SynDingTalkUtil.getAccessToken(config.getDingSynAppKey(), config.getDingSynAppSecret());
|
||||
if (!tokenObject.getBoolean("code")) {
|
||||
return ActionResult.fail(MsgCode.SYS053.get());
|
||||
}
|
||||
|
||||
// 异步执行
|
||||
String finalSynDing = synDing;
|
||||
ThreadPoolExecutorUtil.getExecutor().execute(() -> {
|
||||
String userId = userInfo.getUserId();
|
||||
try {
|
||||
redisUtil.insert(finalSynDing, "true");
|
||||
|
||||
List<OapiV2DepartmentListsubResponse.DeptBaseResponse> DingDeptList = new ArrayList<>();
|
||||
|
||||
List<DingTalkDeptModel> DingDeptAllList = new ArrayList<>();
|
||||
String access_token = tokenObject.getString("access_token");
|
||||
|
||||
// 获取同步表的信息
|
||||
List<SynThirdInfoEntity> synThirdInfoList = synThirdInfoService.syncThirdInfoByType(SynThirdConsts.THIRD_TYPE_DING_To_Sys, SynThirdConsts.DATA_TYPE_ORG, SynThirdConsts.THIRD_TYPE_DING);
|
||||
|
||||
// 获取钉钉上的根目录部门(本系统的组织)
|
||||
long departId = SynThirdConsts.DING_ROOT_DEPT_ID;
|
||||
if (StringUtil.isNoneBlank(config.getDingDepartment())) {
|
||||
departId = Long.parseLong(config.getDingDepartment());
|
||||
}
|
||||
synThirdInfoService.initBaseDept(departId, access_token,SynThirdConsts.THIRD_TYPE_DING_To_Sys);
|
||||
|
||||
// 获取钉钉上的部门列表
|
||||
JSONObject retMsg = SynDingTalkUtil.getDepartmentList(departId, access_token);
|
||||
DingDeptList = (List<OapiV2DepartmentListsubResponse.DeptBaseResponse>) retMsg.get("department");
|
||||
List<DingTalkDeptModel> dingDeptListVo = JsonUtil.getJsonToList(DingDeptList, DingTalkDeptModel.class);
|
||||
DingDeptAllList.addAll(dingDeptListVo);
|
||||
|
||||
|
||||
// 根据同步表、公司表进行比较,判断不存的执行删除
|
||||
for (SynThirdInfoEntity synThirdInfoEntity : synThirdInfoList) {
|
||||
if (DingDeptAllList.stream().filter(t -> String.valueOf(t.getDeptId()).equals(synThirdInfoEntity.getThirdObjId())).count() == 0) {
|
||||
// // 执行删除操作
|
||||
// retMsg = synThirdDingTalkService.deleteDepartmentDingToSys(true, synThirdInfoEntity.getThirdObjId());
|
||||
}
|
||||
}
|
||||
|
||||
// 删除后需要重新获取数据
|
||||
synThirdInfoList = synThirdInfoService.getList(SynThirdConsts.THIRD_TYPE_DING_To_Sys, SynThirdConsts.DATA_TYPE_ORG);
|
||||
|
||||
// 根据公司表、同步表进行比较,决定执行创建、还是更新
|
||||
for (DingTalkDeptModel dingDeptEntity : DingDeptAllList) {
|
||||
if (synThirdInfoList.stream().filter(t -> t.getThirdObjId().equals(String.valueOf(dingDeptEntity.getDeptId()))).count() > 0) {
|
||||
// 执行本地更新功能
|
||||
synThirdDingTalkService.updateDepartmentDingToSys(true, dingDeptEntity, access_token);
|
||||
} else {
|
||||
// 执行本的创建功能
|
||||
synThirdDingTalkService.createDepartmentDingToSys(true, dingDeptEntity, access_token);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error(finalSynDing + ",钉钉所有组织信息同步到本系统失败:" + e.getMessage());
|
||||
} finally {
|
||||
redisUtil.remove(finalSynDing);
|
||||
redisUtil.remove(cacheKeyUtil.getOrganizeList());
|
||||
List<String> toUserId = new ArrayList<>(1);
|
||||
toUserId.add(userId);
|
||||
messageService.sentMessage(toUserId, "钉钉所有组织信息同步到本系统", "同步完成", userInfo,1,1);
|
||||
}
|
||||
});
|
||||
return ActionResult.success(MsgCode.SYS026.get());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 钉钉所有用户信息同步到本系统
|
||||
* 不带第三方错误定位判断的功能代码 20210604
|
||||
*
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "钉钉所有用户信息同步到本系统")
|
||||
@SaCheckPermission("system.sysConfig")
|
||||
@GetMapping("/synAllUserDingToSys")
|
||||
@Transactional
|
||||
public ActionResult synAllUserDingToSys() {
|
||||
// 设置redis的key
|
||||
String synDing = "";
|
||||
UserInfo userInfo = UserProvider.getUser();
|
||||
if (configValueUtil.isMultiTenancy()) {
|
||||
synDing = userInfo.getTenantId() + "_" + userInfo.getUserId() + "_synAllUserDingToSys";
|
||||
} else {
|
||||
synDing = userInfo.getUserId() + "_synAllUserDingToSys";
|
||||
}
|
||||
// 如果redis中存在key说明同步正在进行
|
||||
if (redisUtil.exists(synDing)) {
|
||||
return ActionResult.fail(MsgCode.SYS026.get());
|
||||
}
|
||||
// 获取已同步的部门信息
|
||||
List<SynThirdInfoEntity> synThirdOrgList = synThirdInfoService.getList(SynThirdConsts.THIRD_TYPE_DING_To_Sys, SynThirdConsts.DATA_TYPE_ORG);
|
||||
List<String> dingDeptIdList = new ArrayList<>();
|
||||
if (synThirdOrgList != null && synThirdOrgList.size() > 0) {
|
||||
dingDeptIdList = synThirdOrgList.stream().map(SynThirdInfoEntity::getThirdObjId).distinct().collect(Collectors.toList());
|
||||
} else {
|
||||
return ActionResult.fail(MsgCode.SYS028.get());
|
||||
}
|
||||
|
||||
// 获取Token值
|
||||
BaseSystemInfo config = synThirdDingTalkService.getDingTalkConfig();
|
||||
JSONObject tokenObject = SynDingTalkUtil.getAccessToken(config.getDingSynAppKey(), config.getDingSynAppSecret());
|
||||
if (!tokenObject.getBoolean("code")) {
|
||||
return ActionResult.fail(MsgCode.SYS053.get());
|
||||
}
|
||||
// 异步执行
|
||||
List<String> finalDingDeptIdList = dingDeptIdList;
|
||||
String finalSynDing = synDing;
|
||||
ThreadPoolExecutorUtil.getExecutor().execute(() -> {
|
||||
String userId = userInfo.getUserId();
|
||||
try {
|
||||
redisUtil.insert(finalSynDing, "true");
|
||||
List<OapiV2UserListResponse.ListUserResponse> dingUserList = new ArrayList<>();
|
||||
String access_token = tokenObject.getString("access_token");
|
||||
|
||||
// 获取钉钉的用户列表
|
||||
JSONObject retMsg = SynDingTalkUtil.getUserDingList(finalDingDeptIdList, access_token);
|
||||
dingUserList = (List<OapiV2UserListResponse.ListUserResponse>) retMsg.get("userlist");
|
||||
|
||||
// 获取同步表、用户表的信息
|
||||
List<SynThirdInfoEntity> synThirdInfoList = synThirdInfoService.syncThirdInfoByType(SynThirdConsts.THIRD_TYPE_DING_To_Sys, SynThirdConsts.DATA_TYPE_USER, SynThirdConsts.THIRD_TYPE_DING);
|
||||
|
||||
// 根据同步表、公司表进行比较,判断不存的执行删除
|
||||
for (SynThirdInfoEntity synThirdInfoEntity : synThirdInfoList) {
|
||||
// 线上不包含中间表的这条记录
|
||||
if (dingUserList.stream().filter(t -> t.getUserid().equals(synThirdInfoEntity.getThirdObjId())).count() == 0) {
|
||||
// 执行删除此条中间表记录
|
||||
synThirdDingTalkService.deleteUserDingToSys(true, synThirdInfoEntity.getThirdObjId());
|
||||
}
|
||||
}
|
||||
// 得到推送钉钉信息
|
||||
List<SynThirdInfoEntity> synThirdInfoLists = synThirdInfoService.syncThirdInfoByType(SynThirdConsts.THIRD_TYPE_DING, SynThirdConsts.DATA_TYPE_USER, SynThirdConsts.THIRD_TYPE_DING);
|
||||
// 根据公司表、同步表进行比较,决定执行创建、还是更新
|
||||
for (OapiV2UserListResponse.ListUserResponse dingUserModel : dingUserList) {
|
||||
if (synThirdInfoList.stream().filter(t -> t.getThirdObjId().equals(dingUserModel.getUserid())).count() == 0
|
||||
&& synThirdInfoLists.stream().filter(t -> t.getThirdObjId().equals(dingUserModel.getUserid())).count() == 0) {
|
||||
// 执行创建功能
|
||||
synThirdDingTalkService.createUserDingToSys(true, dingUserModel, access_token);
|
||||
} else {
|
||||
// 执行更新功能
|
||||
synThirdDingTalkService.updateUserDingToSystem(true, dingUserModel);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
log.error(finalSynDing + ",钉钉所有用户信息同步到本系统失败:" + e.getMessage());
|
||||
} finally {
|
||||
redisUtil.remove(finalSynDing);
|
||||
List<String> toUserId = new ArrayList<>(1);
|
||||
toUserId.add(userId);
|
||||
messageService.sentMessage(toUserId, "钉钉所有用户信息同步到本系统", "同步完成", userInfo,1,1);
|
||||
}
|
||||
});
|
||||
return ActionResult.success(MsgCode.SYS026.get());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,249 @@
|
||||
package com.yunzhupaas.base.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import com.yunzhupaas.base.controller.SuperController;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import com.yunzhupaas.base.ActionResult;
|
||||
import com.yunzhupaas.base.entity.EmailConfigEntity;
|
||||
import com.yunzhupaas.base.entity.SysConfigEntity;
|
||||
import com.yunzhupaas.base.model.systemconfig.EmailTestForm;
|
||||
import com.yunzhupaas.base.model.systemconfig.SysConfigModel;
|
||||
import com.yunzhupaas.base.service.SysconfigService;
|
||||
import com.yunzhupaas.base.service.SystemConfigApi;
|
||||
import com.yunzhupaas.constant.MsgCode;
|
||||
import com.yunzhupaas.exception.WorkFlowException;
|
||||
import com.yunzhupaas.message.entity.QyWebChatModel;
|
||||
import com.yunzhupaas.message.model.message.DingTalkModel;
|
||||
import com.yunzhupaas.message.util.QyWebChatUtil;
|
||||
import com.yunzhupaas.permission.model.user.form.UserUpAdminForm;
|
||||
import com.yunzhupaas.permission.model.user.vo.UserAdminVO;
|
||||
import com.yunzhupaas.permission.service.UserService;
|
||||
import com.yunzhupaas.util.JsonUtil;
|
||||
import com.yunzhupaas.util.RandomUtil;
|
||||
import com.yunzhupaas.util.third.DingTalkUtil;
|
||||
import com.yunzhupaas.util.wxutil.HttpUtil;
|
||||
import com.yunzhupaas.workflow.service.TaskApi;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 系统配置
|
||||
*
|
||||
* @author 云筑产品开发平台组
|
||||
* @version V3.1.0
|
||||
* @copyright 深圳市乐程软件有限公司
|
||||
* @date 2023/09/27
|
||||
*/
|
||||
@Tag(name = "系统配置", description = "SysConfig")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/SysConfig")
|
||||
public class SysConfigController extends SuperController<SysconfigService, SysConfigEntity> implements SystemConfigApi {
|
||||
|
||||
@Autowired
|
||||
private SysconfigService sysconfigService;
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@Autowired
|
||||
private TaskApi taskApi;
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "列表")
|
||||
@GetMapping
|
||||
@SaCheckPermission("system.sysConfig")
|
||||
public ActionResult<SysConfigModel> list() {
|
||||
List<SysConfigEntity> list = sysconfigService.getList("SysConfig");
|
||||
HashMap<String, String> map = new HashMap<>(16);
|
||||
for (SysConfigEntity sys : list) {
|
||||
map.put(sys.getFkey(), sys.getValue());
|
||||
}
|
||||
SysConfigModel sysConfigModel = JsonUtil.getJsonToBean(map, SysConfigModel.class);
|
||||
return ActionResult.success(sysConfigModel);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存设置
|
||||
*
|
||||
* @param sysConfigModel 系统配置模型
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "更新系统配置")
|
||||
@Parameter(name = "sysConfigModel", description = "系统模型", required = true)
|
||||
@SaCheckPermission("system.sysConfig")
|
||||
@PutMapping
|
||||
public ActionResult save(@RequestBody SysConfigModel sysConfigModel) {
|
||||
if (Objects.nonNull(sysConfigModel.getVerificationCodeNumber())) {
|
||||
if (sysConfigModel.getVerificationCodeNumber() > 6) {
|
||||
return ActionResult.fail(MsgCode.SYS029.get());
|
||||
}
|
||||
if (sysConfigModel.getVerificationCodeNumber() < 3) {
|
||||
return ActionResult.fail(MsgCode.SYS030.get());
|
||||
}
|
||||
}
|
||||
String flowTodo = sysconfigService.getValueByKey("flowTodo");
|
||||
if (ObjectUtil.equals(flowTodo, "1") && ObjectUtil.equals(sysConfigModel.getFlowTodo(), 0)) {
|
||||
if (taskApi.checkTodo()) {
|
||||
return ActionResult.fail(MsgCode.WF141.get());
|
||||
}
|
||||
}
|
||||
String flowSign = sysconfigService.getValueByKey("flowSign");
|
||||
if (ObjectUtil.equals(flowSign, "1") && ObjectUtil.equals(sysConfigModel.getFlowSign(), 0)) {
|
||||
if (taskApi.checkSign()) {
|
||||
return ActionResult.fail(MsgCode.WF138.get());
|
||||
}
|
||||
}
|
||||
if (sysConfigModel.getAddSignLevel() > 6 || sysConfigModel.getAddSignLevel() < 1) {
|
||||
return ActionResult.fail("加签层级的范围不在1-6之间");
|
||||
}
|
||||
List<SysConfigEntity> entitys = new ArrayList<>();
|
||||
Map<String, Object> map = JsonUtil.entityToMap(sysConfigModel);
|
||||
map.put("isLog", "1");
|
||||
map.put("sysTheme", "1");
|
||||
map.put("pageSize", "30");
|
||||
map.put("lastLoginTime", 1);
|
||||
for (Map.Entry<String, Object> entry : map.entrySet()) {
|
||||
SysConfigEntity entity = new SysConfigEntity();
|
||||
entity.setId(RandomUtil.uuId());
|
||||
entity.setFkey(entry.getKey());
|
||||
entity.setValue(String.valueOf(entry.getValue()));
|
||||
entitys.add(entity);
|
||||
}
|
||||
sysconfigService.save(entitys);
|
||||
return ActionResult.success(MsgCode.SU005.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 邮箱账户密码验证
|
||||
*
|
||||
* @param emailTestForm 邮箱测试模型
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "邮箱连接测试")
|
||||
@Parameter(name = "emailTestForm", description = "邮箱测试模型", required = true)
|
||||
@SaCheckPermission("system.sysConfig")
|
||||
@PostMapping("/Email/Test")
|
||||
public ActionResult checkLogin(@RequestBody EmailTestForm emailTestForm) {
|
||||
EmailConfigEntity entity = JsonUtil.getJsonToBean(emailTestForm, EmailConfigEntity.class);
|
||||
entity.setEmailSsl(Integer.valueOf(emailTestForm.getSsl()));
|
||||
String result = sysconfigService.checkLogin(entity);
|
||||
if ("true".equals(result)) {
|
||||
return ActionResult.success(MsgCode.SU017.get());
|
||||
} else {
|
||||
return ActionResult.fail(result);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//=====================================测试企业微信、钉钉的连接=====================================
|
||||
|
||||
/**
|
||||
* 测试企业微信配置的连接功能
|
||||
*
|
||||
* @param type 0-发送消息,1-同步组织
|
||||
* @param qyWebChatModel 企业微信模型
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "测试企业微信配置的连接")
|
||||
@Parameters({
|
||||
@Parameter(name = "type", description = "0-发送消息,1-同步组织", required = true),
|
||||
@Parameter(name = "qyWebChatModel", description = "企业微信模型", required = true)
|
||||
})
|
||||
@SaCheckPermission("system.sysConfig")
|
||||
@PostMapping("{type}/testQyWebChatConnect")
|
||||
public ActionResult testQyWebChatConnect(@PathVariable("type") String type, @RequestBody @Valid QyWebChatModel qyWebChatModel) {
|
||||
JSONObject retMsg = new JSONObject();
|
||||
// 测试发送消息、组织同步的连接
|
||||
String corpId = qyWebChatModel.getQyhCorpId();
|
||||
String agentSecret = qyWebChatModel.getQyhAgentSecret();
|
||||
String corpSecret = qyWebChatModel.getQyhCorpSecret();
|
||||
// 测试发送消息的连接
|
||||
if ("0".equals(type)) {
|
||||
retMsg = QyWebChatUtil.getAccessToken(corpId, agentSecret);
|
||||
if (HttpUtil.isWxError(retMsg)) {
|
||||
return ActionResult.fail(MsgCode.SYS031.get(retMsg.getString("errmsg")));
|
||||
}
|
||||
return ActionResult.success(MsgCode.SYS032.get());
|
||||
} else if ("1".equals(type)) {
|
||||
retMsg = QyWebChatUtil.getAccessToken(corpId, corpSecret);
|
||||
if (HttpUtil.isWxError(retMsg)) {
|
||||
return ActionResult.fail(MsgCode.SYS033.get(retMsg.getString("errmsg")));
|
||||
}
|
||||
return ActionResult.success(MsgCode.SYS034.get());
|
||||
}
|
||||
return ActionResult.fail(MsgCode.SYS035.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试钉钉配置的连接功能
|
||||
*
|
||||
* @param dingTalkModel 钉钉模板
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "测试钉钉配置的连接")
|
||||
@Parameters({
|
||||
@Parameter(name = "dingTalkModel", description = "钉钉模型", required = true)
|
||||
})
|
||||
@SaCheckPermission("system.sysConfig")
|
||||
@PostMapping("/testDingTalkConnect")
|
||||
public ActionResult testDingTalkConnect(@RequestBody @Valid DingTalkModel dingTalkModel) {
|
||||
JSONObject retMsg = new JSONObject();
|
||||
// 测试钉钉配置的连接
|
||||
String appKey = dingTalkModel.getDingSynAppKey();
|
||||
String appSecret = dingTalkModel.getDingSynAppSecret();
|
||||
///
|
||||
// String agentId = dingTalkModel.getDingAgentId();
|
||||
// 测试钉钉的连接
|
||||
retMsg = DingTalkUtil.getAccessToken(appKey, appSecret);
|
||||
if (!retMsg.getBoolean("code")) {
|
||||
return ActionResult.fail(MsgCode.SYS036.get(retMsg.getString("error")));
|
||||
}
|
||||
|
||||
return ActionResult.success(MsgCode.SYS037.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取管理员集合
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "获取管理员集合")
|
||||
@SaCheckPermission("system.sysConfig")
|
||||
@GetMapping("/getAdminList")
|
||||
public ActionResult<List<UserAdminVO>> getAdminList(){
|
||||
List<UserAdminVO> admins = JsonUtil.getJsonToList(userService.getAdminList(), UserAdminVO.class);
|
||||
return ActionResult.success(admins);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取管理员集合
|
||||
*
|
||||
* @param userUpAdminForm 超级管理员设置表单参数
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "获取管理员集合")
|
||||
@Parameters({
|
||||
@Parameter(name = "userUpAdminForm", description = "超级管理员设置表单参数", required = true)
|
||||
})
|
||||
@SaCheckPermission("system.sysConfig")
|
||||
@PutMapping("/setAdminList")
|
||||
public ActionResult<String> setAdminList(@RequestBody UserUpAdminForm userUpAdminForm){
|
||||
userService.setAdminListByIds(userUpAdminForm.getAdminIds());
|
||||
return ActionResult.success(MsgCode.SU004.get());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,260 @@
|
||||
package com.yunzhupaas.base.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import com.yunzhupaas.base.ActionResult;
|
||||
import com.yunzhupaas.base.entity.ModuleEntity;
|
||||
import com.yunzhupaas.base.entity.SystemEntity;
|
||||
import com.yunzhupaas.base.model.base.SystemCrModel;
|
||||
import com.yunzhupaas.base.model.base.SystemListVO;
|
||||
import com.yunzhupaas.base.model.base.SystemPageVO;
|
||||
import com.yunzhupaas.base.model.base.SystemUpModel;
|
||||
import com.yunzhupaas.base.model.base.SystemVO;
|
||||
import com.yunzhupaas.base.model.portalManage.PortalManagePage;
|
||||
import com.yunzhupaas.base.model.portalManage.PortalManagePageDO;
|
||||
import com.yunzhupaas.base.service.CommonWordsService;
|
||||
import com.yunzhupaas.base.service.ModuleService;
|
||||
import com.yunzhupaas.base.service.PortalManageService;
|
||||
import com.yunzhupaas.base.service.SystemService;
|
||||
import com.yunzhupaas.base.vo.ListVO;
|
||||
import com.yunzhupaas.constant.MsgCode;
|
||||
import com.yunzhupaas.message.util.OnlineUserModel;
|
||||
import com.yunzhupaas.message.util.OnlineUserProvider;
|
||||
import com.yunzhupaas.permission.service.AuthorizeService;
|
||||
import com.yunzhupaas.permission.service.OrganizeAdministratorService;
|
||||
import com.yunzhupaas.permission.service.UserService;
|
||||
import com.yunzhupaas.util.JsonUtil;
|
||||
import com.yunzhupaas.util.StringUtil;
|
||||
import com.yunzhupaas.util.UserProvider;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 系统控制器
|
||||
*
|
||||
* @author :云筑产品开发平台组
|
||||
* @version: V3.1.0
|
||||
* @copyright 深圳市乐程软件有限公司
|
||||
* @date :2022/6/21 15:33
|
||||
*/
|
||||
@Tag(name = "系统", description = "system")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/System")
|
||||
public class SystemController extends SuperController<SystemService, SystemEntity> {
|
||||
|
||||
@Autowired
|
||||
private SystemService systemService;
|
||||
@Autowired
|
||||
private UserService userApi;
|
||||
|
||||
@Autowired
|
||||
private CommonWordsService commonWordsService;
|
||||
@Autowired
|
||||
private OrganizeAdministratorService organizeAdminTratorApi;
|
||||
@Autowired
|
||||
private AuthorizeService authorizeApi;
|
||||
|
||||
@Autowired
|
||||
PortalManageService portalManageService;
|
||||
@Autowired
|
||||
private ModuleService moduleService;
|
||||
|
||||
/**
|
||||
* 获取系统列表
|
||||
*
|
||||
* @param page 关键字
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "获取系统列表")
|
||||
@SaCheckPermission("system.menu")
|
||||
@GetMapping
|
||||
public ActionResult<ListVO<SystemListVO>> list(SystemPageVO page) {
|
||||
Boolean enabledMark = false;
|
||||
if (ObjectUtil.equal(page.getEnabledMark(), "0")) {
|
||||
enabledMark = null;
|
||||
}
|
||||
if (ObjectUtil.equal(page.getEnabledMark(), "1")) {
|
||||
enabledMark = true;
|
||||
}
|
||||
List<SystemEntity> list = systemService.getList(page.getKeyword(), enabledMark, true, page.getSelector(), true, new ArrayList<>());
|
||||
List<SystemListVO> jsonToList = JsonUtil.getJsonToList(list, SystemListVO.class);
|
||||
return ActionResult.success(new ListVO<>(jsonToList));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取系统详情
|
||||
*
|
||||
* @param id 主键
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "获取系统详情")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true)
|
||||
})
|
||||
@SaCheckPermission("system.menu")
|
||||
@GetMapping("/{id}")
|
||||
public ActionResult<SystemVO> info(@PathVariable("id") String id) {
|
||||
SystemEntity entity = systemService.getInfo(id);
|
||||
if (entity == null) {
|
||||
return ActionResult.fail(MsgCode.FA001.get());
|
||||
}
|
||||
SystemVO jsonToBean = JsonUtil.getJsonToBean(entity, SystemVO.class);
|
||||
return ActionResult.success(jsonToBean);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新建系统
|
||||
*
|
||||
* @param systemCrModel 新建模型
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "新建系统")
|
||||
@Parameters({
|
||||
@Parameter(name = "systemCrModel", description = "新建模型", required = true)
|
||||
})
|
||||
@SaCheckPermission("system.menu")
|
||||
@PostMapping
|
||||
public ActionResult create(@RequestBody SystemCrModel systemCrModel) {
|
||||
SystemEntity entity = JsonUtil.getJsonToBean(systemCrModel, SystemEntity.class);
|
||||
if (systemService.isExistFullName(entity.getId(), entity.getFullName())) {
|
||||
return ActionResult.fail(MsgCode.EXIST001.get());
|
||||
}
|
||||
if (systemService.isExistEnCode(entity.getId(), entity.getEnCode())) {
|
||||
return ActionResult.fail(MsgCode.EXIST002.get());
|
||||
}
|
||||
systemService.create(entity);
|
||||
return ActionResult.success(MsgCode.SU001.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改系统
|
||||
*
|
||||
* @param id 主键
|
||||
* @param systemUpModel 修改模型
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "修改系统")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true),
|
||||
@Parameter(name = "systemCrModel", description = "修改模型", required = true)
|
||||
})
|
||||
@SaCheckPermission("system.menu")
|
||||
@PutMapping("/{id}")
|
||||
public ActionResult update(@PathVariable("id") String id, @RequestBody SystemUpModel systemUpModel) {
|
||||
SystemEntity systemEntity = systemService.getInfo(id);
|
||||
if (systemEntity == null) {
|
||||
return ActionResult.fail(MsgCode.FA002.get());
|
||||
}
|
||||
// 主系统不允许禁用
|
||||
if (systemEntity.getIsMain() != null && systemEntity.getIsMain() == 1 && systemUpModel.getEnabledMark() == 0) {
|
||||
if (systemUpModel.getEnabledMark() == 0) {
|
||||
return ActionResult.fail(MsgCode.SYS101.get());
|
||||
}
|
||||
if (!systemEntity.getEnCode().equals(systemUpModel.getEnCode())) {
|
||||
return ActionResult.fail(MsgCode.SYS104.get());
|
||||
}
|
||||
}
|
||||
SystemEntity entity = JsonUtil.getJsonToBean(systemUpModel, SystemEntity.class);
|
||||
entity.setIsMain(systemEntity.getIsMain());
|
||||
if (systemService.isExistFullName(id, entity.getFullName())) {
|
||||
return ActionResult.fail(MsgCode.EXIST001.get());
|
||||
}
|
||||
if (systemService.isExistEnCode(id, entity.getEnCode())) {
|
||||
return ActionResult.fail(MsgCode.EXIST002.get());
|
||||
}
|
||||
systemService.update(id, entity);
|
||||
// 如果禁用了系统,则需要将系统
|
||||
if (systemEntity.getEnabledMark() == 1 && entity.getEnabledMark() == 0) {
|
||||
sentMessage("应用已被禁用,正为您切换应用", systemEntity);
|
||||
}
|
||||
return ActionResult.success(MsgCode.SU004.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除系统
|
||||
*
|
||||
* @param id 主键
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "删除系统")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true)
|
||||
})
|
||||
@SaCheckPermission("system.menu")
|
||||
@DeleteMapping("/{id}")
|
||||
public ActionResult<String> delete(@PathVariable("id") String id) {
|
||||
SystemEntity entity = systemService.getInfo(id);
|
||||
if (entity == null) {
|
||||
return ActionResult.fail(MsgCode.FA003.get());
|
||||
}
|
||||
// 查询门户
|
||||
PortalManagePage portalManagePage = new PortalManagePage();
|
||||
portalManagePage.setSystemId(id);
|
||||
List<PortalManagePageDO> portalList = portalManageService.getSelectList(portalManagePage);
|
||||
// 查询平台下菜单
|
||||
List<ModuleEntity> webData = moduleService.getList(id, "web", null, null, null, null, false);
|
||||
List<ModuleEntity> appData = moduleService.getList(id, "app", null, null, null, null, false);
|
||||
if((CollectionUtils.isNotEmpty(webData) || CollectionUtils.isNotEmpty(appData) ) && CollectionUtils.isNotEmpty(portalList)){
|
||||
return ActionResult.fail(MsgCode.SYS039.get());
|
||||
}
|
||||
if(CollectionUtils.isNotEmpty(webData) || CollectionUtils.isNotEmpty(appData)){
|
||||
return ActionResult.fail(MsgCode.SYS040.get());
|
||||
}
|
||||
if(CollectionUtils.isNotEmpty(portalList)){
|
||||
return ActionResult.fail(MsgCode.SYS041.get());
|
||||
}
|
||||
|
||||
if (entity.getIsMain() != null && entity.getIsMain() == 1) {
|
||||
return ActionResult.fail(MsgCode.SYS102.get());
|
||||
}
|
||||
// 系统绑定审批常用语时不允许被删除
|
||||
if(commonWordsService.existSystem(id)){
|
||||
return ActionResult.fail(MsgCode.SYS103.get());
|
||||
}else {
|
||||
systemService.delete(id);
|
||||
sentMessage("应用已被删除,正为您切换应用", entity);
|
||||
}
|
||||
return ActionResult.success(MsgCode.SU003.get());
|
||||
}
|
||||
|
||||
private void sentMessage(String message, SystemEntity entity) {
|
||||
// 如果禁用了系统,则需要将系统
|
||||
List<OnlineUserModel> onlineUserList = OnlineUserProvider.getOnlineUserList();
|
||||
for (OnlineUserModel item : onlineUserList) {
|
||||
String systemId = item.getSystemId();
|
||||
if (entity.getId().equals(systemId)) {
|
||||
if (item.getWebSocket().isOpen()) {
|
||||
Map<String, String> maps = new HashMap<>(1);
|
||||
maps.put("method", "logout");
|
||||
maps.put("msg", "应用已被禁用或删除");
|
||||
if (StringUtil.isNotEmpty(UserProvider.getUser().getTenantId())) {
|
||||
if (UserProvider.getUser().getTenantId().equals(item.getTenantId())) {
|
||||
item.getWebSocket().getAsyncRemote().sendText(JsonUtil.getObjectToString(maps));
|
||||
}
|
||||
} else {
|
||||
item.getWebSocket().getAsyncRemote().sendText(JsonUtil.getObjectToString(maps));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
package com.yunzhupaas.base.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import com.yunzhupaas.base.ActionResult;
|
||||
import com.yunzhupaas.base.Page;
|
||||
import com.yunzhupaas.base.Pagination;
|
||||
import com.yunzhupaas.base.model.online.BatchOnlineModel;
|
||||
import com.yunzhupaas.base.service.UserOnlineService;
|
||||
import com.yunzhupaas.base.vo.ListVO;
|
||||
import com.yunzhupaas.base.vo.PageListVO;
|
||||
import com.yunzhupaas.base.vo.PaginationVO;
|
||||
import com.yunzhupaas.constant.MsgCode;
|
||||
import com.yunzhupaas.message.model.UserOnlineModel;
|
||||
import com.yunzhupaas.message.model.UserOnlineVO;
|
||||
import com.yunzhupaas.util.JsonUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 在线用户
|
||||
*
|
||||
* @author 云筑产品开发平台组
|
||||
* @version V3.1.0
|
||||
* @copyright 深圳市乐程软件有限公司
|
||||
* @date 2024-09-26 上午9:18
|
||||
*/
|
||||
@Tag(name = "在线用户", description = "Online")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/OnlineUser")
|
||||
public class UserOnlineController {
|
||||
|
||||
@Autowired
|
||||
private UserOnlineService userOnlineService;
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*
|
||||
* @param page 分页参数
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "获取在线用户列表")
|
||||
@SaCheckPermission("permission.userOnline")
|
||||
@GetMapping
|
||||
public ActionResult<PageListVO<UserOnlineVO>> list(Pagination page) {
|
||||
List<UserOnlineModel> data = userOnlineService.getList(page);
|
||||
List<UserOnlineVO> voList= data.stream().map(online->{
|
||||
UserOnlineVO vo = JsonUtil.getJsonToBean(online, UserOnlineVO.class);
|
||||
vo.setUserId(online.getToken());
|
||||
//vo.setUserName(vo.getUserName() + "/" + online.getDevice());
|
||||
return vo;
|
||||
}).collect(Collectors.toList());
|
||||
PaginationVO paginationVO = JsonUtil.getJsonToBean(page, PaginationVO.class);
|
||||
return ActionResult.page(voList, paginationVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 注销
|
||||
*
|
||||
* @param token 主键值
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "强制下线")
|
||||
@Parameter(name = "token", description = "token", required = true)
|
||||
@SaCheckPermission("permission.userOnline")
|
||||
@DeleteMapping("/{token}")
|
||||
public ActionResult delete(@PathVariable("token") String token) {
|
||||
userOnlineService.delete(token);
|
||||
return ActionResult.success(MsgCode.SU005.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量下线用户
|
||||
*
|
||||
* @param model 主键值
|
||||
* @return ignore
|
||||
*/
|
||||
@Operation(summary = "批量下线用户")
|
||||
@Parameter(name = "model", description = "在线用户id集合", required = true)
|
||||
@SaCheckPermission("permission.userOnline")
|
||||
@DeleteMapping
|
||||
public ActionResult clear(@RequestBody BatchOnlineModel model) {
|
||||
userOnlineService.delete(model.getIds());
|
||||
return ActionResult.success(MsgCode.SU005.get());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,210 @@
|
||||
package com.yunzhupaas.base.controller;
|
||||
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import cn.dev33.satoken.annotation.SaMode;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.Valid;
|
||||
import com.yunzhupaas.base.ActionResult;
|
||||
import com.yunzhupaas.base.entity.DictionaryDataEntity;
|
||||
import com.yunzhupaas.base.entity.VisualKitEntity;
|
||||
import com.yunzhupaas.base.model.print.PrintDevFormDTO;
|
||||
import com.yunzhupaas.base.model.visualkit.*;
|
||||
import com.yunzhupaas.base.model.vo.PrintDevVO;
|
||||
import com.yunzhupaas.base.service.DictionaryDataService;
|
||||
import com.yunzhupaas.base.service.VisualKitService;
|
||||
import com.yunzhupaas.base.vo.DownloadVO;
|
||||
import com.yunzhupaas.base.vo.ListVO;
|
||||
import com.yunzhupaas.base.vo.PageListVO;
|
||||
import com.yunzhupaas.base.vo.PaginationVO;
|
||||
import com.yunzhupaas.config.ConfigValueUtil;
|
||||
import com.yunzhupaas.constant.MsgCode;
|
||||
import com.yunzhupaas.emnus.ModuleTypeEnum;
|
||||
import com.yunzhupaas.exception.DataException;
|
||||
import com.yunzhupaas.exception.WorkFlowException;
|
||||
import com.yunzhupaas.permission.entity.UserEntity;
|
||||
import com.yunzhupaas.permission.service.UserService;
|
||||
import com.yunzhupaas.util.FileExport;
|
||||
import com.yunzhupaas.util.FileUtil;
|
||||
import com.yunzhupaas.util.JsonUtil;
|
||||
import com.yunzhupaas.util.StringUtil;
|
||||
import com.yunzhupaas.util.enums.DictionaryDataEnum;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 表单套件
|
||||
*
|
||||
* @author 云筑产品开发平台组
|
||||
* @version v5.1.0
|
||||
* @copyright 深圳市乐程软件有限公司
|
||||
* @date 2024/8/22 11:17:25
|
||||
*/
|
||||
@Tag(name = "表单套件", description = "VisualKit")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/Kit")
|
||||
public class VisualKitController {
|
||||
|
||||
@Autowired
|
||||
private VisualKitService visualKitService;
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
@Autowired
|
||||
private DictionaryDataService dictionaryDataService;
|
||||
@Autowired
|
||||
private FileExport fileExport;
|
||||
@Autowired
|
||||
private ConfigValueUtil configValueUtil;
|
||||
|
||||
|
||||
@Operation(summary = "列表")
|
||||
@GetMapping
|
||||
public ActionResult<PageListVO<VisualKitVo>> list(KitPagination page) {
|
||||
List<VisualKitEntity> list = visualKitService.getList(page);
|
||||
List<String> userId = list.stream().map(t -> t.getCreatorUserId()).collect(Collectors.toList());
|
||||
List<String> lastUserId = list.stream().map(t -> t.getLastModifyUserId()).collect(Collectors.toList());
|
||||
lastUserId.removeAll(Collections.singleton(null));
|
||||
List<UserEntity> userEntities = userService.getUserName(userId);
|
||||
List<UserEntity> lastUserIdEntities = userService.getUserName(lastUserId);
|
||||
List<DictionaryDataEntity> typeList = dictionaryDataService.getListByTypeDataCode(DictionaryDataEnum.VISUALDEV.getDictionaryTypeId());
|
||||
List<VisualKitVo> listVOS = new ArrayList<>();
|
||||
for (VisualKitEntity entity : list) {
|
||||
VisualKitVo vo = JsonUtil.getJsonToBean(entity, VisualKitVo.class);
|
||||
DictionaryDataEntity dataEntity = typeList.stream().filter(t -> t.getId().equals(entity.getCategory())).findFirst().orElse(null);
|
||||
if (dataEntity != null) {
|
||||
vo.setCategory(dataEntity.getFullName());
|
||||
} else {
|
||||
vo.setCategory("");
|
||||
}
|
||||
//创建者
|
||||
UserEntity creatorUser = userEntities.stream().filter(t -> t.getId().equals(entity.getCreatorUserId())).findFirst().orElse(null);
|
||||
vo.setCreatorUser(creatorUser != null ? creatorUser.getRealName() + "/" + creatorUser.getAccount() : entity.getCreatorUserId());
|
||||
//修改人
|
||||
UserEntity lastModifyUser = lastUserIdEntities.stream().filter(t -> t.getId().equals(entity.getLastModifyUserId())).findFirst().orElse(null);
|
||||
vo.setLastModifyUser(lastModifyUser != null ? lastModifyUser.getRealName() + "/" + lastModifyUser.getAccount() : entity.getLastModifyUserId());
|
||||
listVOS.add(vo);
|
||||
}
|
||||
PaginationVO paginationVO = JsonUtil.getJsonToBean(page, PaginationVO.class);
|
||||
return ActionResult.page(listVOS, paginationVO);
|
||||
}
|
||||
|
||||
|
||||
@Operation(summary = "新增")
|
||||
@Parameters({
|
||||
@Parameter(name = "VisualKitForm", description = "套件表单信息")
|
||||
})
|
||||
@SaCheckPermission(value = {"system.kit", "onlineDev.webDesign"}, mode = SaMode.OR)
|
||||
@PostMapping
|
||||
public ActionResult create(@RequestBody @Valid VisualKitForm form) {
|
||||
visualKitService.create(form);
|
||||
return ActionResult.success(MsgCode.SU001.get(), form.getId());
|
||||
}
|
||||
|
||||
@Operation(summary = "详情")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "表单条件id")
|
||||
})
|
||||
@SaCheckPermission("system.kit")
|
||||
@GetMapping("/{id}")
|
||||
public ActionResult<VisualKitInfoVo> info(@PathVariable("id") String id) {
|
||||
VisualKitEntity byId = visualKitService.getById(id);
|
||||
VisualKitInfoVo vo = JsonUtil.getJsonToBean(byId, VisualKitInfoVo.class);
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
@Operation(summary = "更新")
|
||||
@PutMapping("/{id}")
|
||||
@SaCheckPermission("system.kit")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true),
|
||||
@Parameter(name = "form", description = "套件表单信息", required = true),
|
||||
})
|
||||
public ActionResult update(@PathVariable("id") String id, @RequestBody @Valid VisualKitForm form) throws WorkFlowException {
|
||||
boolean b = visualKitService.update(id, form);
|
||||
if (b) {
|
||||
return ActionResult.success(MsgCode.SU004.get());
|
||||
}
|
||||
return ActionResult.success(MsgCode.FA102.get());
|
||||
}
|
||||
|
||||
@Operation(summary = "删除")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "表单条件id")
|
||||
})
|
||||
@SaCheckPermission("system.kit")
|
||||
@DeleteMapping("/{id}")
|
||||
public ActionResult<PrintDevFormDTO> delete(@PathVariable String id) {
|
||||
if (visualKitService.getById(id) != null) {
|
||||
visualKitService.removeById(id);
|
||||
return ActionResult.success(MsgCode.SU003.get());
|
||||
} else {
|
||||
return ActionResult.fail(MsgCode.FA003.get());
|
||||
}
|
||||
}
|
||||
|
||||
@Operation(summary = "下拉列表")
|
||||
@GetMapping("/Selector")
|
||||
public ActionResult<List<KitTreeVo>> selectorList(){
|
||||
List<KitTreeVo> kitTreeVos = visualKitService.selectorList();
|
||||
return ActionResult.success(kitTreeVos);
|
||||
}
|
||||
|
||||
//***************************动作*********************
|
||||
|
||||
@Operation(summary = "复制")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "打印模板id")
|
||||
})
|
||||
@SaCheckPermission("system.kit")
|
||||
@PostMapping("/{id}/Actions/Copy")
|
||||
public ActionResult copy(@PathVariable String id) {
|
||||
visualKitService.actionsCopy(id);
|
||||
return ActionResult.success(MsgCode.SU007.get());
|
||||
}
|
||||
|
||||
@Operation(summary = "导出")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "打印模板id")
|
||||
})
|
||||
@SaCheckPermission("system.kit")
|
||||
@GetMapping("/{id}/Actions/Export")
|
||||
public ActionResult<DownloadVO> export(@PathVariable String id) {
|
||||
VisualKitEntity entity = visualKitService.getById(id);
|
||||
//导出文件
|
||||
DownloadVO downloadVO = fileExport.exportFile(entity, configValueUtil.getTemporaryFilePath(), entity.getFullName(), ModuleTypeEnum.SYSTEM_KIT.getTableName());
|
||||
return ActionResult.success(downloadVO);
|
||||
}
|
||||
|
||||
@Operation(summary = "导入")
|
||||
@Parameters({
|
||||
@Parameter(name = "type", description = "导入类型:0跳过,1追加")
|
||||
})
|
||||
@SaCheckPermission("system.kit")
|
||||
@PostMapping(value = "/Actions/Import", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
public ActionResult importData(@RequestPart("file") MultipartFile multipartFile,
|
||||
@RequestParam("type") Integer type) throws DataException {
|
||||
//判断是否为.json结尾
|
||||
if (FileUtil.existsSuffix(multipartFile, ModuleTypeEnum.SYSTEM_KIT.getTableName())) {
|
||||
return ActionResult.fail(MsgCode.IMP002.get());
|
||||
}
|
||||
//读取文件内容
|
||||
String fileContent = FileUtil.getFileContent(multipartFile);
|
||||
VisualKitEntity entity = JsonUtil.getJsonToBean(fileContent, VisualKitEntity.class);
|
||||
String str = visualKitService.importData(entity, type);
|
||||
if (StringUtil.isNotEmpty(str)) {
|
||||
return ActionResult.fail(str);
|
||||
}
|
||||
return ActionResult.success(MsgCode.IMP001.get());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user