许鹏程
6 天以前 929e9fedb97a88ef122100e03f775fedae79c474
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package com.product.mobile.core.service;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.product.admin.service.SystemButtonsService;
import com.product.common.lang.StringUtils;
import com.product.core.entity.DataTableEntity;
import com.product.core.entity.FieldSetEntity;
import com.product.core.service.support.AbstractBaseService;
import com.product.mobile.core.config.MobileCoreConst;
import com.product.util.BaseUtil;
import com.product.util.SystemParamReplace;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.*;
 
/**
 * @Author cheng
 * @Date 2022/3/8 16:33
 * @Desc 功能相关 service
 */
@Service
public class SystemFunctionService extends AbstractBaseService {
 
    private SystemButtonsService systemButtonsService;
 
    @Autowired
    public SystemFunctionService(SystemButtonsService systemButtonsService) {
        this.systemButtonsService = systemButtonsService;
    }
 
    /**
     * 获取当前进入当前页面的按钮和当前页面连接(link) 的按钮
     *
     * @return
     */
    public Object getFunctionButton(FieldSetEntity fse) {
        String functionUuid = fse.getString("function_uuid");
        String buttonUuid = fse.getString("button_uuid");
        StringBuilder sql = new StringBuilder();
        sql.append(" SELECT ");
        sql.append(" a.*,JSON_object('face_uuid',c.face_uuid,'flow_title',flow_title,'uuid',c.uuid,'page_type',c.page_type,'tree_data',c.tree_data,'tree_data_type',tree_data_type ,'flow_uuid' ,c.flow_uuid,'page_element_disabled',c.page_element_disabled,'page_name',c.page_name,'from_param_key',c.from_param_key) as current_page, ");
        sql.append(" ( SELECT table_name FROM product_sys_datamodel_table where uuid =(select table_uuid FROM product_sys_functions b WHERE a.function_uuid = b.uuid and data_type=1) ) table_name ");
        sql.append(" FROM ");
        sql.append(" product_sys_function_buttons a ");
        sql.append(" JOIN product_sys_link b ON b.line_from = a.uuid ");
        sql.append(" JOIN product_sys_mvc_page c ON c.uuid = b.line_to ");
        sql.append(" WHERE a.function_uuid=? and a.uuid=? ");
        FieldSetEntity currentButton = getBaseDao().getFieldSetEntityBySQL(sql.toString(), new Object[]{functionUuid, buttonUuid}, false);
        if (currentButton != null && !StringUtils.isEmpty(currentButton.getString("params"))) {
            String params = currentButton.getString("params");
            boolean valid = JSON.isValid(params);
            if (valid) {
                JSONObject json = JSON.parseObject(params);
                Iterator var12 = json.entrySet().iterator();
                while (var12.hasNext()) {
                    Map.Entry<String, Object> one = (Map.Entry<String, Object>) var12.next();
                    Object value = one.getValue();
                    if (value != null) {
                        String val = value.toString();
                        one.setValue(SystemParamReplace.replaceParams(val, null));
                    }
                }
 
                currentButton.setValue("params", json.toJSONString());
            }
        }
        if (currentButton != null && currentButton.getObject("current_page") != null) {
            currentButton.setValue("current_page", JSON.parseObject(currentButton.getString("current_page")));
        }
        Map<String, Object> map = new HashMap<>();
        map.put("currentButton", BaseUtil.fieldSetEntityToJson(currentButton));
        DataTableEntity buttonByPage = systemButtonsService.findButtonByPage(fse);
        return BaseUtil.success(buttonByPage, map);
    }
 
 
}