|
@@ -0,0 +1,255 @@
|
|
|
|
+package com.ruoyi.web.controller.dragForm;
|
|
|
|
+
|
|
|
|
+import com.alibaba.fastjson2.JSON;
|
|
|
|
+import com.alibaba.fastjson2.JSONArray;
|
|
|
|
+import com.alibaba.fastjson2.JSONObject;
|
|
|
|
+import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
|
+import com.ruoyi.business.entity.CommonEntity;
|
|
|
|
+import com.ruoyi.business.entity.DragForm;
|
|
|
|
+import com.ruoyi.business.entity.DragTableBtn;
|
|
|
|
+import com.ruoyi.business.entity.DragTableGroup;
|
|
|
|
+import com.ruoyi.business.entity.vo.DragTableGroupVo;
|
|
|
|
+import com.ruoyi.business.entity.vo.DragTableVo;
|
|
|
|
+import com.ruoyi.business.mapper.DragTableBtnMapper;
|
|
|
|
+import com.ruoyi.business.mapper.DragTableBtnRelevanceMapper;
|
|
|
|
+import com.ruoyi.business.mapper.DragTableGroupMapper;
|
|
|
|
+import com.ruoyi.business.mapper.DragTableMapper;
|
|
|
|
+import com.ruoyi.business.service.ICommonService;
|
|
|
|
+import com.ruoyi.business.service.IDragFormService;
|
|
|
|
+import com.ruoyi.business.service.IDragTableBtnService;
|
|
|
|
+import com.ruoyi.business.service.IDragTableGroupService;
|
|
|
|
+import com.ruoyi.common.constant.ButtonTypeConstants;
|
|
|
|
+import com.ruoyi.common.core.controller.BaseController;
|
|
|
|
+import com.ruoyi.common.core.domain.AjaxResult;
|
|
|
|
+import com.ruoyi.common.utils.bean.BeanUtils;
|
|
|
|
+import com.ruoyi.common.utils.form.FromUtils;
|
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
|
+import javax.annotation.Resource;
|
|
|
|
+import java.util.*;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * @author hanzihang
|
|
|
|
+ * @date 2023/11/16 05:49
|
|
|
|
+ */
|
|
|
|
+@RestController
|
|
|
|
+@RequestMapping("/dragform/commonbtn")
|
|
|
|
+public class CommonBtnController extends BaseController {
|
|
|
|
+
|
|
|
|
+ @Resource // 共通crud
|
|
|
|
+ private ICommonService commonService;
|
|
|
|
+
|
|
|
|
+ @Resource // 动态表单
|
|
|
|
+ private IDragFormService dragFormService;
|
|
|
|
+
|
|
|
|
+ @Resource // 表格按钮
|
|
|
|
+ private IDragTableBtnService iDragTableBtnService;
|
|
|
|
+
|
|
|
|
+ @Resource
|
|
|
|
+ private FromUtils fromUtils;
|
|
|
|
+
|
|
|
|
+ @Resource
|
|
|
|
+ private DragTableMapper dragTableMapper;
|
|
|
|
+
|
|
|
|
+ @Resource
|
|
|
|
+ private DragTableGroupMapper dragTableGroupMapper;
|
|
|
|
+
|
|
|
|
+ @Resource
|
|
|
|
+ private DragTableBtnRelevanceMapper dragTableBtnRelevanceMapper;
|
|
|
|
+
|
|
|
|
+ @Resource
|
|
|
|
+ private DragTableBtnMapper dragTableBtnMapper;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 处理按钮通用接口(新增、修改、删除)
|
|
|
|
+ * @param commonEntity
|
|
|
|
+ * @return
|
|
|
|
+ * @throws JsonProcessingException
|
|
|
|
+ */
|
|
|
|
+ @PostMapping("/commonBtnHandle")
|
|
|
|
+ public AjaxResult commonBtnHandle(@RequestBody CommonEntity commonEntity) throws JsonProcessingException {
|
|
|
|
+
|
|
|
|
+ //按钮类型
|
|
|
|
+ Long btnType = Long.valueOf(commonEntity.getBasicMap().get("btnType").toString());
|
|
|
|
+ String type = "";
|
|
|
|
+ if (btnType == ButtonTypeConstants.INSERT) {
|
|
|
|
+ type = "INSERT";
|
|
|
|
+ } else if (btnType == ButtonTypeConstants.UPDATE) {
|
|
|
|
+ type = "UPDATE";
|
|
|
|
+ } else if (btnType == ButtonTypeConstants.DELETE) {
|
|
|
|
+ type = "DELETE";
|
|
|
|
+ }
|
|
|
|
+ /*
|
|
|
|
+ * 判断什么类型走什么接口:
|
|
|
|
+ * btnType 10:新增、8:修改、9:删除、5:脚本
|
|
|
|
+ * visible false代表弹窗未开启时走回显表单模板及数据信息接口;true代表弹窗开启时走保存数据接口
|
|
|
|
+ * */
|
|
|
|
+ //是否提交表单操作 true是 false回显表单数据 commonEntity.getBasicMap().get("visible").toString()
|
|
|
|
+ switch (type) {
|
|
|
|
+ case "INSERT":
|
|
|
|
+ return insertBtn(commonEntity);
|
|
|
|
+ case "UPDATE":
|
|
|
|
+ return updateBtn(commonEntity);
|
|
|
|
+ case "DELETE":
|
|
|
|
+ return deleteBtn(commonEntity);
|
|
|
|
+ default:
|
|
|
|
+ return warn("暂不支持该操作!");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 新增类型按钮
|
|
|
|
+ * @param commonEntity
|
|
|
|
+ * @return
|
|
|
|
+ * @throws JsonProcessingException
|
|
|
|
+ */
|
|
|
|
+ public AjaxResult insertBtn(CommonEntity commonEntity) throws JsonProcessingException {
|
|
|
|
+ if (commonEntity.getBasicMap().get("visible").toString().equals("true")) {
|
|
|
|
+ return AjaxResult.btnMessage(commonService.batchInsert(commonEntity));
|
|
|
|
+ } else if (commonEntity.getBasicMap().get("visible").toString().equals("false")) {
|
|
|
|
+ String sqlKey = commonEntity.getBasicMap().get("sqlKey").toString();
|
|
|
|
+ return success(dragFormService.selectDragFormBySqlKey(sqlKey));
|
|
|
|
+ } else {
|
|
|
|
+ return warn("暂不支持该操作!");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 修改类型按钮
|
|
|
|
+ * @param commonEntity
|
|
|
|
+ * @return
|
|
|
|
+ * @throws JsonProcessingException
|
|
|
|
+ */
|
|
|
|
+ public AjaxResult updateBtn(CommonEntity commonEntity) throws JsonProcessingException {
|
|
|
|
+ //是否开启弹窗
|
|
|
|
+ if (commonEntity.getBasicMap().get("visible").toString().equals("true")) {
|
|
|
|
+ if (commonEntity.getBasicMap().containsKey("btnKey")) { // 按钮提交时会触发别的操作
|
|
|
|
+ // 根据按钮别名查询按钮详细信息
|
|
|
|
+ DragTableBtn dragTableBtn = iDragTableBtnService.selectDragTableBtnByBtnKey(commonEntity.getBasicMap().get("btnKey").toString());
|
|
|
|
+ // 根据流程的key判断当前按钮是否执行触发流程
|
|
|
|
+ if (!dragTableBtn.getBtnProcessKey().isEmpty()) {
|
|
|
|
+ // 调用发起流程接口
|
|
|
|
+ fromUtils.runBpmProductionScheduling(commonEntity);
|
|
|
|
+// if (dragTableBtn.getBtnFormKey().isEmpty()) { // 校验当前按钮是否是直接触发流程 或者脚本 (新增按钮类型)
|
|
|
|
+// fromUtils.runBpmProductionScheduling(commonEntity);
|
|
|
|
+// }
|
|
|
|
+ } else if (!dragTableBtn.getBtnScriptKey().isEmpty()) {
|
|
|
|
+ // 调用执行脚本接口
|
|
|
|
+ fromUtils.triggerScript(commonEntity);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return toAjax(commonService.edit(commonEntity));
|
|
|
|
+ } else if (commonEntity.getBasicMap().get("visible").toString().equals("false")) {
|
|
|
|
+ //单纯是表格还是弹窗里有表格
|
|
|
|
+ return getAjaxResult(commonEntity);
|
|
|
|
+ } else {
|
|
|
|
+ return warn("暂不支持该操作!");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 删除类型按钮
|
|
|
|
+ * @param commonEntity
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public AjaxResult deleteBtn(CommonEntity commonEntity) {
|
|
|
|
+ return toAjax(commonService.batchDelete(commonEntity));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 判断是正常的表单渲染还是表单表格渲染
|
|
|
|
+ * @param commonEntity
|
|
|
|
+ * @return
|
|
|
|
+ * @throws JsonProcessingException
|
|
|
|
+ */
|
|
|
|
+ private AjaxResult getAjaxResult(CommonEntity commonEntity) throws JsonProcessingException {
|
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
|
+ //先拿到btnKey
|
|
|
|
+ String btnKey = commonEntity.getBasicMap().get("btnKey").toString();
|
|
|
|
+ //查询按钮列表
|
|
|
|
+ DragTableBtn dragTableBtn = iDragTableBtnService.selectDragTableBtnByBtnKey(btnKey);
|
|
|
|
+ //判断是走原生的表单解析还是、走配置的表单解析
|
|
|
|
+ if (dragTableBtn.getBtnTableFormGroupKey()!=null&&dragTableBtn.getBtnTableFormGroupKey()!="") {
|
|
|
|
+ //查询组信息
|
|
|
|
+ DragTableGroup dragTableGroup = dragTableGroupMapper.selectDragTableGroupOneByGroupKey(dragTableBtn.getBtnTableFormGroupKey());
|
|
|
|
+ DragTableGroupVo dragTableGroupVo=new DragTableGroupVo();
|
|
|
|
+ //赋值给vo才好放表格
|
|
|
|
+ BeanUtils.copyProperties(dragTableGroup, dragTableGroupVo);
|
|
|
|
+
|
|
|
|
+ //把[{"tableKey":"a1","sort":0},{"tableKey":"a2","sort":1}]转换成Map对象
|
|
|
|
+ JSONArray jsonArray = JSON.parseArray( dragTableGroup.getGroupTableInfo());
|
|
|
|
+ //排序确保表格的顺序
|
|
|
|
+ JSONArray sortArray = jsonArray.stream().sorted(
|
|
|
|
+ Comparator.comparingLong(
|
|
|
|
+ // 根据对象中的ID进行排序
|
|
|
|
+ e -> JSONObject.parseObject(e.toString()).getIntValue("sort")
|
|
|
|
+ )
|
|
|
|
+ ).collect(Collectors.toCollection(JSONArray::new));
|
|
|
|
+ //用in查询
|
|
|
|
+ List<String> tableKeys = new ArrayList<>();
|
|
|
|
+ sortArray.stream().forEach(item->
|
|
|
|
+ tableKeys.add(JSONObject.parseObject(item.toString()).get("tableKey").toString()));
|
|
|
|
+
|
|
|
|
+ //查询表格信息
|
|
|
|
+ List<DragTableVo> dragTableVos = dragTableMapper.selectDragTableTableKeysOrderby(tableKeys);
|
|
|
|
+ dragTableVos.forEach(item->{
|
|
|
|
+ // 动态表格按钮信息
|
|
|
|
+ //根据tableKey获取根节点信息
|
|
|
|
+ List<String> btnKeys = dragTableBtnRelevanceMapper.selectBtnKeyByTableKey(item.getTableKey());
|
|
|
|
+ //获取根节点数据
|
|
|
|
+ if(btnKeys.size() > 0){
|
|
|
|
+ List<DragTableBtn> rootNodes = dragTableBtnMapper.selectDragTableBtnListByBtnKey(btnKeys);
|
|
|
|
+ //查询子节点
|
|
|
|
+ List<Long> ids = rootNodes.stream().map(m -> m.getId()).collect(Collectors.toList());
|
|
|
|
+ if (ids.isEmpty()){
|
|
|
|
+ item.setDragTableBtnList(rootNodes);
|
|
|
|
+ }else {
|
|
|
|
+ List<DragTableBtn> childNodes = dragTableBtnMapper.selectChildNodeById(ids);
|
|
|
|
+ List<DragTableBtn> btnList = rootNodes.stream().peek(
|
|
|
|
+ root -> root.setChildren(getChildrenList(root, childNodes))
|
|
|
|
+ ).collect(Collectors.toList());
|
|
|
|
+ item.setDragTableBtnList(btnList);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ //查询表格按钮
|
|
|
|
+ dragTableGroupVo.setDragTables(dragTableVos);
|
|
|
|
+ map.put("template", null);
|
|
|
|
+ //把groupKey放进去
|
|
|
|
+ map.put("result",dragTableGroupVo);
|
|
|
|
+ }else {
|
|
|
|
+ String sqlKey = commonEntity.getBasicMap().get("sqlKey").toString();
|
|
|
|
+ DragForm dragForm = dragFormService.selectDragFormBySqlKey(sqlKey);
|
|
|
|
+ map.put("template", dragForm);
|
|
|
|
+ //返回结果
|
|
|
|
+ map.put("result", commonService.getInfoById(commonEntity));
|
|
|
|
+ }
|
|
|
|
+ return success(map);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 递归查询按钮子级的方法
|
|
|
|
+ * @param root
|
|
|
|
+ * @param childNodes
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ private List<DragTableBtn> getChildrenList(DragTableBtn root, List<DragTableBtn> childNodes) {
|
|
|
|
+ List<DragTableBtn> list = childNodes.stream().filter(dragTableBtn ->
|
|
|
|
+ //筛选出下一节点元素
|
|
|
|
+ Objects.equals(dragTableBtn.getBtnParentId(), root.getId())).map(dragTableBtn -> {
|
|
|
|
+ //递归set子节点
|
|
|
|
+ dragTableBtn.setChildren(this.getChildrenList(dragTableBtn, childNodes));
|
|
|
|
+ return dragTableBtn;
|
|
|
|
+ }).collect(Collectors.toList());
|
|
|
|
+ return list;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+}
|