shichongfu
2023-04-25 ce0b49552668d3331055e2b1a1447a743dc54939
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
package com.product.admin.service;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.product.admin.config.CmnConst;
import com.product.admin.config.SystemCode;
import com.product.admin.service.idel.IPortalsService;
import com.product.common.lang.StringUtils;
import com.product.core.dao.BaseDao;
import com.product.core.entity.DataTableEntity;
import com.product.core.entity.FieldSetEntity;
import com.product.core.exception.BaseException;
import com.product.core.service.support.AbstractBaseService;
import com.product.core.spring.context.SpringMVCContextHolder;
import com.product.core.transfer.Transactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
 
import java.util.Date;
 
/**
 * Copyright  LX-BASE
 *
 * @Title: PortalsService
 * @Project: LX-BASE-SERVER
 * @Date: 2021-03-18 09:55
 * @Author: ZhouJie
 * @Description: 门户配置
 */
@Component
public class PortalsService extends AbstractBaseService implements IPortalsService {
    @Autowired
    public BaseDao baseDao;
 
    /**
     * @Date: 2020-03-18 10:36
     * @Author: ZhouJie
     * @Description: 门户配置列表查询
     */
    public DataTableEntity getPortalList(FieldSetEntity fs) throws BaseException {
 
        DataTableEntity dt = baseDao.listTable(CmnConst.PRODUCT_SYS_PORTALS, null, null, null, null, fs.getInteger(CmnConst.PAGESIZE), fs.getInteger(CmnConst.CPAGE));
        baseDao.loadPromptData(dt);
        return dt;
    }
 
    public FieldSetEntity findUserIndexPortal() throws BaseException {
        int userType = SpringMVCContextHolder.getCurrentUser().getUserType();
        FieldSetEntity fieldSetBySQL = baseDao.getFieldSetBySQL("SELECT uuid FROM `product_sys_portals` where portal_type=?  ORDER BY sequence limit 1", new Object[]{userType}, false);
        if (fieldSetBySQL == null || StringUtils.isEmpty(fieldSetBySQL.getUUID())) {
            throw new BaseException(SystemCode.USER_PORTAL_EMPTY);
        }
        return getPortalInfo(fieldSetBySQL);
    }
 
    /**
     * @Date: 2020-03-18 10:18
     * @Author: ZhouJie
     * @Description: 门户配置详情查询
     */
    public FieldSetEntity getPortalInfo(FieldSetEntity fs) throws BaseException {
        FieldSetEntity fss = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_PORTALS, fs.getUUID(), true);
        DataTableEntity dt = fss.getSubDataTable(CmnConst.PRODUCT_SYS_PORTALS_SUB);
        if (dt != null && dt.getRows() > 0) {
            for (int i = 0; i < dt.getRows(); i++) {
                FieldSetEntity fsub = dt.getFieldSetEntity(i);
                FieldSetEntity fspage = baseDao.getFieldSetEntityByFilter(CmnConst.PRODUCT_SYS_PORTAL_COLUMN_CONFIG, CmnConst.UUID + "=?", new Object[]{fsub.getString("page_uuid")}, true);
                fsub.setValue("page_name", fspage.getString("page_name"));
                fsub.setValue("page_type", fspage.getString("page_type"));
                fsub.setValue("is_use", fspage.getString("is_use"));
                fsub.setValue("chart_name", fspage.getString("chart_name"));
                fsub.setValue("link_address", fspage.getString("link_address"));
                fsub.setValue("data_source", fspage.getString("data_source"));
                fsub.setValue("click_view_more", fspage.getString("click_view_more"));
                fsub.setValue("is_refresh_button", fspage.getString("is_refresh_button"));
                fsub.setValue("is_show_underline", fspage.getString("is_show_underline"));
                fsub.setValue("is_more_button", fspage.getString("is_more_button"));
                fsub.setValue("is_add_button", fspage.getString("is_add_button"));
                fsub.setValue("new_url", fspage.getString("new_url"));
                fsub.setValue("is_show_title", fspage.getString("is_show_title"));
                fsub.setValue("refresh_time", fspage.getInteger("refresh_time"));
                fsub.setValue("column_type", fspage.getObject("column_type"));
                fsub.setValue("color", fspage.getObject("color"));
                fsub.setValue("icon", fspage.getObject("icon"));
                String custom_button = fspage.getString("custom_button");
                if (!StringUtils.isEmpty(custom_button) && JSON.isValid(custom_button)) {
                    JSONObject parse = JSON.parseObject(custom_button);
                    for (String key : parse.keySet()) {
                        String value = parse.getString(key);
                        if (JSON.isValidArray(value)) {
                            parse.put(key, JSON.parseArray(value));
                        }
                        if (JSON.isValidObject(value)) {
                            JSONObject jsonObject = JSON.parseObject(value);
                            parse.put(key, jsonObject);
                        }
                    }
                    fspage.setValue("custom_button", parse);
                }
                fsub.setValue("custom_button", fspage.getString("custom_button"));
                fsub.setValue("is_custom_button", fspage.getString("is_custom_button"));
                fsub.setValue("title_name", fspage.getString("title_name"));
                if (!com.alibaba.druid.util.StringUtils.isEmpty(fsub.getString("page_uuid"))) {
                    FieldSetEntity fpage = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_PORTAL_COLUMN_CONFIG, fsub.getString("page_uuid"), false);
                    FieldSetEntity fsrc = null;
                    FieldSetEntity fsmp = null;
                    if (fpage != null && fpage.getInteger("page_type") == 1) {
                        fsrc = baseDao.getFieldSetEntityByFilter("product_sys_report_config", CmnConst.UUID + "=?", new Object[]{fpage.getString("data_source")}, false);
                    }
                    if (fpage != null && fpage.getInteger("page_type") == 2) {
                        fsrc = baseDao.getFieldSetEntityByFilter("product_sys_report_config ", CmnConst.UUID + "=?", new Object[]{fpage.getString("chart_name")}, false);
                    }
                    if (fsrc != null) {
                        fsmp = baseDao.getFieldSetEntityByFilter("product_sys_mvc_page ", "function_uuid = ?", new Object[]{fsrc.getString("function_uuid")}, false);
                        if (fsmp != null) {
                            fsub.setValue("link_address", fsmp.getString("page_url"));
                        }
                    }
                }
            }
        }
        return fss;
        //return baseDao.listInternationDataTable(baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_PORTALS, fs.getString(CmnConst.UUID), true),null);
    }
 
    /**
     * @Date: 2020-03-18 11:29
     * @Author: ZhouJie
     * @Description: 新增门户配置
     */
    public String addPortal(FieldSetEntity fs) throws BaseException {
        String addPortal = "addPortal";
        //判断菜单是否已在其他门户配置
        if (!StringUtils.isEmpty(fs.getString("portal_menu"))) {
            FieldSetEntity mfs = baseDao.getFieldSetEntityByFilter(CmnConst.PRODUCT_SYS_PORTALS, "portal_menu=?", new Object[]{fs.getString("portal_menu")}, false);
            if (mfs != null) {
                throw new BaseException(SystemCode.SYSTEM_MENUS_ALREADY_EXIST.getValue(), SystemCode.SYSTEM_MENUS_ALREADY_EXIST.getText(), this.getClass(), addPortal);
            }
        }
 
        //fs.setValue(CmnConst.CREATED_BY, SpringMVCContextHolder.getCurrentUser().getUser_id());
        fs.setValue(CmnConst.CREATED_BY, 1);
        fs.setValue(CmnConst.CREATED_UTC_DATETIME, new Date());
        return baseDao.add(fs);
    }
 
    /**
     * @Date: 2020-03-18 14:07
     * @Author: ZhouJie
     * @Description: 修改门户配置
     */
    @Transactional
    public boolean updatePortal(FieldSetEntity fs) throws BaseException {
        String updatePortal = "updatePortal";
        //判断菜单是否已在其他门户配置
        if (!StringUtils.isEmpty(fs.getString("portal_menu"))) {
            FieldSetEntity mfs = baseDao.getFieldSetEntityByFilter(CmnConst.PRODUCT_SYS_PORTALS, "portal_menu=?", new Object[]{fs.getString("portal_menu")}, false);
            if (mfs == null) {
                throw new BaseException(SystemCode.SYSTEM_MENUS_ALREADY_EXIST.getValue(), SystemCode.SYSTEM_MENUS_ALREADY_EXIST.getText(), this.getClass(), updatePortal);
            }
        }
        //fs.setValue(CmnConst.UPDATED_BY, SpringMVCContextHolder.getCurrentUser().getUser_id());
        fs.setValue(CmnConst.UPDATED_BY, 1);
        fs.setValue(CmnConst.UPDATED_UTC_DATETIME, new Date());
        return baseDao.update(fs, true);
    }
 
    /**
     * @Date: 2020-03-18 15:11
     * @Author: ZhouJie
     * @Description: 删除门户配置
     */
    @Transactional
    public boolean deletePortal(FieldSetEntity fs) throws BaseException {
 
 
        baseDao.delete(CmnConst.PRODUCT_SYS_PORTALS_SUB, "portal_uuid=?", new Object[]{fs.getString("portal_uuid")});
        /*
         * if (dt.getRows() > 0) { for (int i = 0; i < dt.getRows(); i++) {
         * FieldSetEntity fssub = dt.getFieldSetEntity(i); String fuuid =
         * fssub.getString(CmnConst.UUID);
         * baseDao.delete(CmnConst.PRODUCT_SYS_PORTALS_SUB, new
         * Object[]{fssub.getString(CmnConst.UUID)}); } }
         */
        return baseDao.delete(CmnConst.PRODUCT_SYS_PORTALS, new Object[]{fs.getString(CmnConst.UUID)});
    }
 
 
}