package com.product.admin.service;
|
|
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSONObject;
|
import com.google.common.base.Joiner;
|
import com.product.admin.config.CmnConst;
|
import com.product.admin.entity.RouterEntity;
|
import com.product.common.lang.StringUtils;
|
import com.product.core.cache.DataPoolCacheImpl;
|
import com.product.core.cache.util.RedisUtil;
|
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.module.sys.entity.SystemUser;
|
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.*;
|
|
/**
|
* Copyright LX-BASE
|
*
|
* @Title: SystemButtonsService
|
* @Project: LX-BASE-SERVER
|
* @Date: 2020-06-09 16:25
|
* @Author: ZhouJie
|
* @Description: 按钮Service层
|
*/
|
@Service
|
public class SystemButtonsService extends AbstractBaseService {
|
|
@Autowired
|
public BaseDao baseDao;
|
|
/***
|
* 查询按钮列表
|
* @param function_uuid 功能uuid
|
* @return
|
*/
|
public DataTableEntity getButtonList(String function_uuid) throws BaseException {
|
String sql = "select button.uuid,button.button_name,button.button_title,button.button_description,button.url,button.script,button.script_method,button.is_main,button.sequence,button.created_by,button.created_utc_datetime," +
|
"button.function_uuid," +
|
"button.button_type,dicttype.dict_label as button_type_name," +
|
"button.button_category_uuid,dictcategory.dict_label as button_category_name " +
|
" FROM product_sys_buttons button " +
|
" left join product_sys_dict dicttype on button.button_type = dicttype.uuid " +
|
" left join product_sys_dict dictcategory on button.button_category_uuid = dictcategory.uuid " +
|
" where button.function_uuid = ? ";
|
DataTableEntity dataTableEntity = baseDao.listTable(sql, new Object[]{function_uuid});
|
return dataTableEntity;
|
}
|
|
|
/***
|
* 获取排序序号
|
* @param function_uuid 功能uuid
|
* @throws BaseException
|
*/
|
public int getSequence(String function_uuid) throws BaseException {
|
String sql = "select max(sequence) as sequence FROM product_sys_buttons where function_uuid = ? ";
|
DataTableEntity dataTableEntity = baseDao.listTable(sql, new Object[]{function_uuid});
|
if (dataTableEntity != null && dataTableEntity.getMeta() != null) {
|
FieldSetEntity fieldSetEntity = dataTableEntity.getFieldSetEntity(0);
|
//周杰 2020年12月17日 上午11:16
|
if (!StringUtils.isEmpty(fieldSetEntity.getString("sequence"))) {
|
return fieldSetEntity.getInteger("sequence") + 1;
|
} else {
|
return 1;
|
}
|
} else {
|
return 1;
|
}
|
}
|
|
public FieldSetEntity getDict(String uuid) throws BaseException {
|
FieldSetEntity fieldSetEntity = baseDao.getFieldSetEntity("product_sys_dict", uuid, false);
|
return fieldSetEntity;
|
}
|
|
/**
|
* @Date: 2020-06-11 17:08
|
* @Author: ZhouJie
|
* @Description: 按钮详情查看
|
*/
|
public FieldSetEntity findButton(FieldSetEntity fs) throws BaseException {
|
return baseDao.getFieldSetEntity("product_sys_buttons", fs.getString("uuid"), false);
|
}
|
|
/**
|
* @throws BaseException
|
* @Date: 2020-06-11 17:46
|
* @Author: ZhouJie
|
* @Description: 按钮版本号
|
*/
|
public FieldSetEntity findBottonVersion(FieldSetEntity fs) throws BaseException {
|
String version = null;
|
String version1 = fs.getString("version");
|
if (version1 != null) {
|
String version2 = version1.substring(0, version1.indexOf(".", version1.indexOf(".") + 1) + 1) + String.valueOf(Integer.valueOf(version1.substring(version1.indexOf(".", version1.indexOf(".") + 1) + 1, version1.length())) + 1);
|
version = version1 + "," + version2;
|
}
|
fs.setValue("version", version);
|
return fs;
|
}
|
|
/**
|
* 获取路由信息
|
*
|
* @return
|
*/
|
public RouterEntity getRouterEntity() {
|
return (RouterEntity) RedisUtil.get("system-cache:router");
|
}
|
|
/**
|
* @throws BaseException
|
* @Date: 2020-06-12 11:05
|
* @Author: ZhouJie
|
* @Description: 新增按钮
|
*/
|
public String addButton(FieldSetEntity fs) throws BaseException {
|
FieldSetEntity newFunction = baseDao.getFieldSetEntityByFilter("product_sys_functions", " uuid = ?", new Object[]{fs.getString("function_uuid")}, false);
|
FieldSetEntity newModule = baseDao.getFieldSetEntityByFilter("product_sys_modules", " uuid = ?", new Object[]{newFunction.getString("module_uuid")}, false);
|
String bfs = fs.getString("version");
|
String ffs = newFunction.getString("version");
|
String mfs = newModule.getString("version");
|
//功能版本号小于按钮的版本号,则回写到功能版本号
|
if (Integer.valueOf(ffs.substring(ffs.indexOf(".", ffs.indexOf(".") + 1) + 1, ffs.length())) <
|
Integer.valueOf(bfs.substring(bfs.indexOf(".", bfs.indexOf(".") + 1) + 1, bfs.length()))) {
|
newFunction.setValue("version", bfs);
|
baseDao.update(newFunction);//回写上级功能的版本号
|
}
|
//模块的版本号小于按钮长级后的版本,则把版本号回写到模块
|
if (Integer.valueOf(mfs.substring(mfs.indexOf(".") + 1, mfs.indexOf(".", mfs.indexOf(".") + 1))) <
|
Integer.valueOf(bfs.substring(bfs.indexOf(".") + 1, bfs.indexOf(".", bfs.indexOf(".") + 1)))) {
|
newModule.setValue("version", bfs);
|
baseDao.update(newModule);//回写上级模块的版本号
|
}
|
return baseDao.add(fs);
|
}
|
|
/**
|
* @throws BaseException
|
* @Date: 2020-06-13 10:19
|
* @Author: ZhouJie
|
* @Description: 按钮版本号升级并回写版本号
|
*/
|
public FieldSetEntity upVersion(FieldSetEntity fs) throws BaseException {
|
FieldSetEntity now = baseDao.getFieldSetEntityByFilter("product_sys_function_buttons ", " uuid = ?", new Object[]{fs.getString("uuid")}, false);
|
//当前按钮版本号
|
String bfs = now.getString("version");
|
//升一级后的按钮版本号
|
String version = bfs.substring(0, bfs.indexOf(".", bfs.indexOf(".") + 1) + 1) + String.valueOf(Integer.valueOf(bfs.substring(bfs.indexOf(".", bfs.indexOf(".") + 1) + 1, bfs.length())) + 1);
|
fs.setValue("version", version);
|
baseDao.update(fs);
|
//回写版本号
|
FieldSetEntity newFunction = baseDao.getFieldSetEntityByFilter("product_sys_functions ", " uuid = ?", new Object[]{now.getString("function_uuid")}, false);
|
FieldSetEntity newModule = baseDao.getFieldSetEntityByFilter("product_sys_modules ", " uuid = ?", new Object[]{newFunction.getString("module_uuid")}, false);
|
String ffs = newFunction.getString("version");
|
String mfs = newModule.getString("version");
|
if (Integer.valueOf(ffs.substring(ffs.indexOf(".", ffs.indexOf(".") + 1) + 1, ffs.length())) <
|
Integer.valueOf(version.substring(version.indexOf(".", version.indexOf(".") + 1) + 1, version.length()))) {
|
newFunction.setValue("version", version);
|
baseDao.update(newFunction);//回写上级功能的版本号
|
}
|
//模块的版本号小于按钮长级后的版本,则把版本号回写到模块
|
if (Integer.valueOf(mfs.substring(mfs.indexOf(".") + 1, mfs.indexOf(".", mfs.indexOf(".") + 1))) <
|
Integer.valueOf(version.substring(version.indexOf(".") + 1, version.indexOf(".", version.indexOf(".") + 1)))) {
|
newModule.setValue("version", version);
|
baseDao.update(newModule);//回写上级模块的版本号
|
}
|
return fs;
|
}
|
|
/**
|
* 查询页面的按钮
|
*
|
* @param fse
|
*/
|
public DataTableEntity findButtonByPage(FieldSetEntity fse) throws BaseException {
|
SystemUser currentUser = SpringMVCContextHolder.getCurrentUser();
|
if (currentUser == null || StringUtils.isEmpty(currentUser.getRoles())) {
|
return null;
|
}
|
String function_uuid = fse.getString(CmnConst.FUNCTION_UUID);
|
//当前人拥有的角色
|
String[] role_uuid = currentUser.getRoles().split(",");
|
List<DataTableEntity> permission = new ArrayList<>();
|
for (int i = 0; i < role_uuid.length; i++) {
|
//根据角色取出功能权限
|
permission.add(DataPoolCacheImpl.getInstance().getCacheData("功能权限", new String[]{role_uuid[i], function_uuid}));
|
}
|
Set<String> buttons = new HashSet<>();
|
//循环功能权限将按钮权限放入Set集合
|
for (int i = 0; i < permission.size(); i++) {
|
if (BaseUtil.dataTableIsEmpty(permission.get(i))) {
|
continue;
|
}
|
for (int j = 0; j < permission.get(i).getRows(); j++) {
|
String button_uuid = permission.get(i).getString(j, "button_uuid");
|
if (!StringUtils.isEmpty(button_uuid)) {
|
buttons.addAll(Arrays.asList(button_uuid.split(",")));
|
}
|
}
|
}
|
DataTableEntity dt = DataPoolCacheImpl.getInstance().getCacheData("页面-按钮", new String[]{fse.getString(CmnConst.MVC_PAGE_UUID), function_uuid});
|
DataTableEntity button;
|
if (!BaseUtil.dataTableIsEmpty(dt)) {
|
button = dt.clones();
|
} else {
|
return null;
|
}
|
RouterEntity routerEntity = getRouterEntity();
|
for (int i = 0; i < button.getRows(); i++) {
|
String button_uuid = button.getString(i, "button_uuid");
|
String params = button.getString(i, "params");
|
String upload_parameter = button.getString(i, "upload_parameter");
|
if (!buttons.contains(button_uuid)) {
|
if (!StringUtils.isEmpty(params)) {
|
if (JSON.isValidObject(params)) {
|
JSONObject jsonObject = JSON.parseObject(params);
|
for (Map.Entry<String, Object> v : jsonObject.entrySet()) {
|
String value = (String) v.getValue();
|
List<String> matchStr = BaseUtil.getMatchStr("(\\{#)([\\w]+)(#\\})", value);
|
if (matchStr.size() > 0) {
|
if (StringUtils.isEmpty(upload_parameter)) {
|
upload_parameter = "";
|
} else if (upload_parameter.length() > 0) {
|
upload_parameter += ',';
|
}
|
upload_parameter += Joiner.on(",").join(matchStr);
|
|
}
|
}
|
button.setFieldValue(i, "upload_parameter", upload_parameter);
|
}
|
}
|
button.removeFieldSetEntity(i);
|
i--;
|
continue;
|
}
|
RouterEntity.RouterMeta routerByButton = routerEntity.getRouterByButton(button_uuid);
|
if (routerByButton != null) {
|
button.setFieldValue(i, "page_type", routerByButton.getPageType());
|
}
|
}
|
return button;
|
}
|
|
/**
|
* 查询页面的按钮
|
*
|
* @param fse
|
*/
|
public FieldSetEntity findFromButtonByPage(FieldSetEntity fse) throws BaseException {
|
// xupengheng 2021年3月10日14:15:18
|
String function_uuid = fse.getString(CmnConst.FUNCTION_UUID);
|
String mvc_page_uuid = fse.getString(CmnConst.MVC_PAGE_UUID);
|
String last_button = fse.getString("last_button");
|
Object[] param = null;
|
String filter = "";
|
if (StringUtils.isEmpty(last_button)) {
|
param = new Object[]{function_uuid, mvc_page_uuid};
|
} else {
|
param = new Object[]{function_uuid, mvc_page_uuid, last_button};
|
filter = " and (route_name =?) ";
|
}
|
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 ");
|
sql.append(" b.function_uuid = ? ");
|
sql.append(" AND b.line_to = ? ");
|
sql.append(filter);
|
sql.append(" AND b.from_type IN ( 0, 1 ) ");
|
FieldSetEntity fs = baseDao.getFieldSetEntityBySQL(sql.toString(), param, false);
|
if (fs != null && !StringUtils.isEmpty(fs.getString("params"))) {
|
String params = fs.getString("params");
|
boolean valid = JSON.isValid(params);
|
if (valid) {
|
JSONObject json = JSON.parseObject(params);
|
for (Map.Entry<String, Object> one : json.entrySet()) {
|
String val;
|
Object value = one.getValue();
|
if (value != null) {
|
val = value.toString();
|
} else {
|
continue;
|
}
|
one.setValue(SystemParamReplace.replaceParams(val, null));
|
}
|
fs.setValue("params", json.toJSONString());
|
}
|
}
|
return fs;
|
}
|
|
|
}
|