package com.product.org.admin.service;
|
|
import com.product.admin.service.RolesService;
|
import com.product.common.lang.StringUtils;
|
import com.product.core.cache.DataPoolCacheImpl;
|
import com.product.core.dao.BaseDao;
|
import com.product.core.entity.DataTableEntity;
|
import com.product.core.entity.FieldMetaEntity;
|
import com.product.core.entity.FieldSetEntity;
|
import com.product.core.exception.BaseException;
|
import com.product.core.permission.PermissionLoad;
|
import com.product.core.service.support.AbstractBaseService;
|
import com.product.core.spring.context.SpringMVCContextHolder;
|
import com.product.core.transfer.Transactional;
|
import com.product.org.admin.config.CmnConst;
|
import com.product.org.admin.config.SystemCode;
|
import com.product.org.admin.service.idel.ISystemDataPermissionService;
|
import com.product.util.BaseUtil;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Component;
|
|
import java.util.Map;
|
|
/**
|
* Copyright © 2020 LX-BASE
|
*
|
* @Title: LX-BASE-SERVER
|
* @Project: base-server-org-admin
|
* @Date: 2020年6月11日
|
* @Author: Mr.Xu
|
* @Description:数据策略Service
|
*/
|
@Component
|
public class SystemDataPermissionService extends AbstractBaseService implements ISystemDataPermissionService {
|
|
@Autowired
|
public BaseDao dao;
|
@Autowired
|
public RolesService rolesService;
|
/**
|
* 数据权限初始
|
*/
|
@Autowired
|
public PermissionLoad permissionLoad = null;
|
|
public PermissionLoad getPermissionLoad() {
|
return permissionLoad;
|
}
|
|
public void setPermissionLoad(PermissionLoad permissionLoad) {
|
this.permissionLoad = permissionLoad;
|
}
|
|
/**
|
* 数据策略列表
|
*
|
* @param fse
|
* @return
|
* @throws BaseException
|
*/
|
public DataTableEntity listDataPermission(FieldSetEntity fse) throws BaseException {
|
if (SpringMVCContextHolder.getCurrentUser() != null && SpringMVCContextHolder.getCurrentUser().getOrg_level_uuid() != null) {
|
StringBuilder sql = new StringBuilder();
|
sql.append(" SELECT ");
|
sql.append(" c.uuid org_level_uuid, ");
|
sql.append(" c.org_level_name,c.org_level_all, ");
|
sql.append(" GROUP_CONCAT( property_name ORDER BY property_name ) property_name ");
|
sql.append(" FROM ");
|
sql.append("product_sys_data_strategy_master a ");
|
sql.append(" JOIN product_sys_data_strategy_properties b ON a.property_uuid = b.uuid ");
|
sql.append(" join product_sys_org_levels c on a.org_level_uuid=c.uuid ");
|
sql.append(" WHERE ");
|
sql.append(" c.uuid = ? ");
|
sql.append(" AND a.is_used = 1 ");
|
sql.append(" GROUP BY ");
|
sql.append(" c.uuid, ");
|
sql.append(" c.org_level_name, ");
|
sql.append(" c.org_level_all ");
|
return dao.listTable(sql.toString(), new Object[]{fse.getString(CmnConst.ORG_LEVEL_UUID)}, fse.getInteger(CmnConst.PAGESIZE), fse.getInteger(CmnConst.CPAGE));
|
}
|
return null;
|
}
|
|
/**
|
* 数据策略详情
|
*
|
* @param fse
|
* @return
|
* @throws BaseException
|
*/
|
public FieldSetEntity findDataPermission(FieldSetEntity fse) throws BaseException {
|
DataTableEntity dt = dao.listTable(CmnConst.PRODUCT_SYS_DATA_STRATEGY_MASTER, "org_level_uuid=?", new Object[]{fse.getString(CmnConst.ORG_LEVEL_UUID)}, null, null, Integer.MAX_VALUE, 1, true);
|
if (!BaseUtil.dataTableIsEmpty(dt)) {
|
FieldSetEntity fs = new FieldSetEntity();
|
fs.setTableName(CmnConst.PRODUCT_SYS_DATA_STRATEGY_MASTER);
|
for (int i = 0; i < dt.getRows(); i++) {
|
FieldSetEntity fss = dt.getFieldSetEntity(i);
|
if(i==0){
|
fs.setValue(CmnConst.EFFECTIVE_START_DATE,fss.getObject(CmnConst.EFFECTIVE_START_DATE));
|
fs.setValue(CmnConst.EFFECTIVE_END_DATE,fss.getObject(CmnConst.EFFECTIVE_END_DATE));
|
fs.setValue(CmnConst.ORG_LEVEL_UUID,fss.getObject(CmnConst.ORG_LEVEL_UUID));
|
}
|
fs.setValue("master_uuid_" + fss.getString("property_uuid"), fss.getUUID());
|
if (fss.getSubTableNames() != null && fss.getSubTableNames().length > 0) {
|
fs.setValue(fss.getSubTableNames()[0] + "_is_used", fss.getInteger(CmnConst.IS_USED));
|
fs.setValue(fss.getSubTableNames()[0] + "_properties", fss.getString(CmnConst.PROPERTY_UUID));
|
}
|
Map<String, DataTableEntity> subData = fss.getSubData();
|
if (subData != null && subData.size() > 0) {
|
for (String ket_table : subData.keySet()) {
|
fs.addSubDataTable(subData.get(ket_table));
|
}
|
}
|
}
|
return fs;
|
}
|
return null;
|
}
|
|
/**
|
* 数据策略详情列表
|
*
|
* @param fse
|
* @return
|
* @throws BaseException
|
*/
|
public FieldSetEntity findDataPermissionList(FieldSetEntity fse) throws BaseException {
|
DataTableEntity dt = dao.listTable(CmnConst.PRODUCT_SYS_DATA_STRATEGY_MASTER, "org_level_uuid=?", new Object[]{fse.getString(CmnConst.ORG_LEVEL_UUID)}, null, null, Integer.MAX_VALUE, 1, true);
|
if (!BaseUtil.dataTableIsEmpty(dt)) {
|
if (BaseUtil.strIsNull(fse.getString("date"))) {
|
return dt.getFieldSetEntity(0);
|
}
|
for (int i = 0, length = dt.getRows(); i < length; i++) {
|
FieldSetEntity fs = dt.getFieldSetEntity(i);
|
if (fs.getSubTableNames() != null && fs.getSubTableNames().length > 0 && fse.getString("date").equals(fs.getSubTableNames()[0])) {
|
fs.setValue(fs.getSubTableNames()[0] + "_is_used", fs.getString(CmnConst.IS_USED));
|
fs.setValue(fs.getSubTableNames()[0] + "_properties", fs.getString(CmnConst.PROPERTY_UUID));
|
return fs;
|
}
|
}
|
}
|
|
return null;
|
}
|
|
/**
|
* 新增数据策略
|
*
|
* @param fse
|
* @return
|
* @throws BaseException
|
*/
|
@Transactional
|
public boolean addDataPermission(FieldSetEntity fse) throws BaseException {
|
DataTableEntity listTable = dao.listTable(CmnConst.PRODUCT_SYS_DATA_STRATEGY_MASTER, "org_level_uuid=?", new Object[]{fse.getString(CmnConst.ORG_LEVEL_UUID)});
|
if (!BaseUtil.dataTableIsEmpty(listTable)) { //判断是否存在该公司策略
|
throw new BaseException(SystemCode.SYSTEM_DATA_PERMISSION_ALREADY_EXIST_ADD_FAIL.getValue(), SystemCode.SYSTEM_DATA_PERMISSION_ALREADY_EXIST_ADD_FAIL.getText(), this.getClass(), "addDataPermission");
|
}
|
Map<String, DataTableEntity> subData = fse.getSubData();
|
DataTableEntity masterDt = new DataTableEntity();
|
if (fse.getSubData().size() != 0) {
|
FieldMetaEntity f = new FieldMetaEntity();
|
masterDt.setMeta(f);
|
f.setTableName(new Object[]{CmnConst.PRODUCT_SYS_DATA_STRATEGY_MASTER});
|
}
|
if (subData != null && subData.size() > 0) {
|
for (String sub_table_name : subData.keySet()) {
|
if (subData.get(sub_table_name) != null) {
|
FieldSetEntity fs = new FieldSetEntity();
|
fs.setMeta(fse.getMeta());
|
fs.setValue(CmnConst.IS_USED, fse.getString(sub_table_name + "_is_used"));
|
fs.setValue(CmnConst.PROPERTY_UUID, fse.getString(sub_table_name + "_properties"));
|
fs.setValue("org_level_uuid", fse.getString("org_level_uuid"));
|
fs.setValue(CmnConst.EFFECTIVE_START_DATE, fse.getString(CmnConst.EFFECTIVE_START_DATE));
|
fs.setValue(CmnConst.EFFECTIVE_END_DATE, fse.getString(CmnConst.EFFECTIVE_END_DATE));
|
fs = BaseUtil.createCreatorAndCreationTime(SpringMVCContextHolder.getCurrentUser(), fs);
|
DataTableEntity subDataTable = BaseUtil.createCreatorAndCreationTime(SpringMVCContextHolder.getCurrentUser(), subData.get(sub_table_name));
|
fs.addSubDataTable(subDataTable);
|
masterDt.addFieldSetEntity(fs);
|
}
|
}
|
}
|
boolean re = dao.add(masterDt);
|
//刷新单位的数据权限
|
if (re) {
|
DataPoolCacheImpl.getInstance().reFreshCacheDataByPermission(fse.getString(CmnConst.ORG_LEVEL_UUID));
|
}
|
return re;
|
}
|
|
/**
|
* 新增数据策略
|
*
|
* @param fse
|
* @return
|
* @throws BaseException
|
*/
|
@Transactional
|
public boolean saveDataPermission(FieldSetEntity fse) throws BaseException {
|
if (StringUtils.isEmpty(fse.getUUID())) {
|
DataTableEntity listTable = dao.listTable(CmnConst.PRODUCT_SYS_DATA_STRATEGY_MASTER, "org_level_uuid=?", new Object[]{fse.getString(CmnConst.ORG_LEVEL_UUID)});
|
if (!BaseUtil.dataTableIsEmpty(listTable)) { //判断是否存在该公司策略
|
throw new BaseException(SystemCode.SYSTEM_DATA_PERMISSION_ALREADY_EXIST_ADD_FAIL.getValue(), SystemCode.SYSTEM_DATA_PERMISSION_ALREADY_EXIST_ADD_FAIL.getText(), this.getClass(), "addDataPermission");
|
}
|
}
|
Map<String, DataTableEntity> subData = fse.getSubData();
|
DataTableEntity masterDt = new DataTableEntity();
|
if (fse.getSubData().size() != 0) {
|
FieldMetaEntity f = new FieldMetaEntity();
|
masterDt.setMeta(f);
|
f.setTableName(new Object[]{CmnConst.PRODUCT_SYS_DATA_STRATEGY_MASTER});
|
}
|
if (subData != null && subData.size() > 0) {
|
for (String sub_table_name : subData.keySet()) {
|
if (subData.get(sub_table_name) != null) {
|
FieldSetEntity fs = new FieldSetEntity();
|
fs.setMeta(fse.getMeta());
|
fs.setValue(CmnConst.IS_USED, fse.getString(sub_table_name + "_is_used"));
|
fs.setValue(CmnConst.PROPERTY_UUID, fse.getString(sub_table_name + "_properties"));
|
fs.setValue("org_level_uuid", fse.getString("org_level_uuid"));
|
fs.setValue(CmnConst.EFFECTIVE_START_DATE, fse.getString(CmnConst.EFFECTIVE_START_DATE));
|
fs.setValue(CmnConst.EFFECTIVE_END_DATE, fse.getString(CmnConst.EFFECTIVE_END_DATE));
|
fs = BaseUtil.createCreatorAndCreationTime(SpringMVCContextHolder.getCurrentUser(), fs);
|
DataTableEntity subDataTable = BaseUtil.createCreatorAndCreationTime(SpringMVCContextHolder.getCurrentUser(), subData.get(sub_table_name));
|
fs.addSubDataTable(subDataTable);
|
masterDt.addFieldSetEntity(fs);
|
}
|
}
|
}
|
boolean re = dao.add(masterDt);
|
//刷新单位的数据权限
|
if (re) {
|
DataPoolCacheImpl.getInstance().reFreshCacheDataByPermission(fse.getString(CmnConst.ORG_LEVEL_UUID));
|
}
|
return re;
|
}
|
|
/**
|
* 数据策略修改提交
|
* cheng 2021年4月16日16:28:39
|
* 批量修改数据策略
|
*
|
* @param fse
|
* @return
|
* @throws BaseException
|
*/
|
@Transactional
|
@Override
|
public boolean updateDataPermission(FieldSetEntity fse) throws BaseException {
|
if (fse != null ) {
|
String effective_start_date = fse.getString(CmnConst.EFFECTIVE_START_DATE);
|
String effective_end_date = fse.getString(CmnConst.EFFECTIVE_END_DATE);
|
//罗鑫2021年3月1日 开始时间不能大于结束时间 cheng 2021年4月16日16:52:14 copy
|
if (BaseUtil.strIsNull(effective_start_date)) {
|
throw new BaseException(com.product.admin.config.SystemCode.SYSTEM_VALID_TIME_WE_FAIL.getValue(), com.product.admin.config.SystemCode.SYSTEM_VALID_TIME_WE_FAIL.getText(), this.getClass(), "public boolean updateDataPermissionBasics(FieldSetEntity fse)throws BaseException");
|
}
|
if (!BaseUtil.strIsNull(effective_end_date)) {
|
if (BaseUtil.temporalComparison(effective_start_date, effective_end_date)) {
|
throw new BaseException(com.product.admin.config.SystemCode.SYSTEM_VALID_TIME_FAIL.getValue(), com.product.admin.config.SystemCode.SYSTEM_VALID_TIME_FAIL.getText(), this.getClass(), "public boolean updateDataPermissionBasics(FieldSetEntity fse)throws BaseException");
|
}
|
}
|
DataTableEntity master_add = new DataTableEntity();
|
DataTableEntity master_update = new DataTableEntity();
|
Map<String, DataTableEntity> subData = fse.getSubData();
|
if (subData != null && subData.size() > 0) {
|
for (String sub_table_name : subData.keySet()) {
|
if (subData.get(sub_table_name) != null) {
|
String uuid = fse.getString("master_uuid_" + fse.getString(sub_table_name + "_properties"));
|
FieldSetEntity fs = new FieldSetEntity();
|
fs.setMeta(fse.getMeta());
|
fs.setValue(CmnConst.IS_USED, fse.getString(sub_table_name + "_is_used"));
|
fs.setValue(CmnConst.PROPERTY_UUID, fse.getString(sub_table_name + "_properties"));
|
fs.setValue(CmnConst.UUID, uuid);
|
fs.setValue("org_level_uuid", fse.getString("org_level_uuid"));
|
fs.setValue(CmnConst.EFFECTIVE_START_DATE, fse.getString(CmnConst.EFFECTIVE_START_DATE));
|
fs.setValue(CmnConst.EFFECTIVE_END_DATE, fse.getString(CmnConst.EFFECTIVE_END_DATE));
|
DataTableEntity subDataTable = BaseUtil.createCreatorAndCreationTime(SpringMVCContextHolder.getCurrentUser(), subData.get(sub_table_name));
|
fs.addSubDataTable(subDataTable);
|
if(StringUtils.isEmpty(uuid)){
|
fs = BaseUtil.createCreatorAndCreationTime(SpringMVCContextHolder.getCurrentUser(), fs);
|
master_add.addFieldSetEntity(fs);
|
}else{
|
fs = BaseUtil.updatedRegeneratorAndUpdateTime(SpringMVCContextHolder.getCurrentUser(), fs);
|
master_update.addFieldSetEntity(fs);
|
}
|
}
|
}
|
}
|
if(master_add.getRows()>0){
|
dao.add(master_add);
|
}
|
if(master_update.getRows()>0){
|
dao.add(master_update);
|
}
|
return true;
|
}
|
return false;
|
}
|
|
/**
|
* 修改数据策略
|
*
|
* @param fse
|
* @return
|
* @throws BaseException
|
*/
|
@Transactional
|
public boolean updateDataPermissionBasics(FieldSetEntity fse) throws BaseException {
|
BaseUtil.createCreatorAndCreationTime(SpringMVCContextHolder.getCurrentUser(), fse);
|
String effective_start_date = fse.getString(CmnConst.EFFECTIVE_START_DATE);
|
String effective_end_date = fse.getString(CmnConst.EFFECTIVE_END_DATE);
|
//罗鑫2021年3月1日 开始时间不能大于结束时间
|
if (BaseUtil.strIsNull(effective_start_date)) {
|
throw new BaseException(com.product.admin.config.SystemCode.SYSTEM_VALID_TIME_WE_FAIL.getValue(), com.product.admin.config.SystemCode.SYSTEM_VALID_TIME_WE_FAIL.getText(), this.getClass(), "public boolean updateDataPermissionBasics(FieldSetEntity fse)throws BaseException");
|
}
|
if (!BaseUtil.strIsNull(effective_end_date)) {
|
if (BaseUtil.temporalComparison(effective_start_date, effective_end_date)) {
|
throw new BaseException(com.product.admin.config.SystemCode.SYSTEM_VALID_TIME_FAIL.getValue(), com.product.admin.config.SystemCode.SYSTEM_VALID_TIME_FAIL.getText(), this.getClass(), "public boolean updateDataPermissionBasics(FieldSetEntity fse)throws BaseException");
|
}
|
}
|
DataTableEntity dataTableEntity = dao.listTable(CmnConst.PRODUCT_SYS_DATA_STRATEGY_MASTER, "org_level_uuid = ?", new String[]{fse.getString("org_level_uuid")});
|
if (effective_end_date != null && effective_end_date.length() > 0) {
|
for (int i = 0, length = dataTableEntity.getRows(); i < length; i++) {
|
dataTableEntity.getFieldSetEntity(i).setValue(CmnConst.EFFECTIVE_START_DATE, fse.getString(CmnConst.EFFECTIVE_START_DATE));
|
dataTableEntity.getFieldSetEntity(i).setValue(CmnConst.EFFECTIVE_END_DATE, effective_end_date);
|
}
|
} else {
|
for (int i = 0, length = dataTableEntity.getRows(); i < length; i++) {
|
dataTableEntity.getFieldSetEntity(i).setValue(CmnConst.EFFECTIVE_START_DATE, fse.getString(CmnConst.EFFECTIVE_START_DATE));
|
}
|
}
|
|
boolean re = dao.update(dataTableEntity);
|
//刷新单位的数据权限
|
if (re) {
|
DataPoolCacheImpl.getInstance().reFreshCacheDataByPermission(fse.getString(CmnConst.ORG_LEVEL_UUID));
|
}
|
return re;
|
}
|
|
/**
|
* 删除数据策略
|
*
|
* @param fse
|
* @return
|
* @throws BaseException
|
*/
|
@Transactional
|
public boolean deleteDataPermission(FieldSetEntity fse) throws BaseException {
|
|
DataTableEntity dt = dao.listTable(CmnConst.PRODUCT_SYS_DATA_STRATEGY_MASTER, "org_level_uuid=?", new Object[]{fse.getString(CmnConst.ORG_LEVEL_UUID)}, null, null, Integer.MAX_VALUE, 1, true);
|
Object[] split = dt.getUuids();
|
if (BaseUtil.dataTableIsEmpty(dt) || dt.getUuids() == null || split.length <= 0) {
|
throw new BaseException(SystemCode.SYSTEM_FORM_COUNT.getValue(), SystemCode.SYSTEM_FORM_COUNT.getText(), this.getClass(), "deleteDataPermission");
|
}
|
String placeholder = "";
|
for (int i = 0; i < split.length; i++) {
|
placeholder += ",?";
|
}
|
boolean re = dao.delete(fse.getTableName(), "uuid in (" + placeholder.substring(1) + ")", split);
|
//刷新单位的数据权限
|
if (re) {
|
DataPoolCacheImpl.getInstance().reFreshCacheDataByPermission(fse.getString(CmnConst.ORG_LEVEL_UUID));
|
}
|
return re;
|
}
|
|
/**
|
* @param fse
|
* @return
|
* @throws BaseException
|
*/
|
public DataTableEntity listModulesAndFunctions(FieldSetEntity fse) throws BaseException {
|
return rolesService.listFunctionRoleForClients(null, fse.getString("client_role_uuid"), false);
|
}
|
|
/**
|
* 修改数据策略详情
|
*
|
* @param fse
|
* @return
|
* @throws BaseException
|
*/
|
@Transactional
|
public boolean updateDataPermissionDetails(FieldSetEntity fse) throws BaseException {
|
int is_used = fse.getInteger(fse.getTableName() + "_is_used");
|
String property_uuid = fse.getString(fse.getTableName() + "_properties");
|
//针对哪家公司进行配置:关联组织架构UUID
|
String org_level_uuid = fse.getString("org_level_uuid");
|
FieldSetEntity master = new FieldSetEntity();
|
master.setTableName(CmnConst.PRODUCT_SYS_DATA_STRATEGY_MASTER);
|
master.setValue(CmnConst.IS_USED, is_used);
|
master.setValue(CmnConst.PROPERTY_UUID, property_uuid);
|
master.setValue("org_level_uuid", org_level_uuid);
|
Map<String, DataTableEntity> details = fse.getSubData();
|
DataTableEntity dt = details.get(fse.getSubTableNames()[0]);
|
boolean status = false;
|
String strategy_uuid;
|
if (dt != null && dt.getRows() > 0) {
|
if (dt.getFieldSetEntity(0).getString(CmnConst.STRATEGY_UUID) == null) {
|
master = BaseUtil.createCreatorAndCreationTime(SpringMVCContextHolder.getCurrentUser(), master);
|
strategy_uuid = dao.add(master);
|
status = true;
|
} else {
|
strategy_uuid = dt.getFieldSetEntity(0).getString(CmnConst.STRATEGY_UUID);
|
master.setValue("uuid", strategy_uuid);
|
master = BaseUtil.updatedRegeneratorAndUpdateTime(SpringMVCContextHolder.getCurrentUser(), master);
|
status = dao.update(master);
|
}
|
for (int i = 0; i < dt.getRows(); i++) {
|
FieldSetEntity fs = dt.getFieldSetEntity(i);
|
fs.setTableName(fse.getTableName());
|
if (StringUtils.isEmpty(fs.getString("uuid")) && !"del".equals(fs.getString("type"))) {
|
fs.setValue(CmnConst.STRATEGY_UUID, strategy_uuid);
|
fs = BaseUtil.createCreatorAndCreationTime(SpringMVCContextHolder.getCurrentUser(), fs);
|
dao.add(fs);
|
} else if (!StringUtils.isEmpty(fs.getString("uuid")) && !"del".equals(fs.getString("type"))) {
|
fs.remove("created_utc_datetime");
|
fs.remove("updated_utc_datetime");
|
fs = BaseUtil.updatedRegeneratorAndUpdateTime(SpringMVCContextHolder.getCurrentUser(), fs);
|
dao.update(fs);
|
} else {
|
dao.delete(fs.getTableName(), "uuid=?", new String[]{fs.getString("uuid")});
|
}
|
}
|
//更新数据权限缓存
|
//刷新单位的数据权限
|
DataPoolCacheImpl.getInstance().reFreshCacheDataByPermission(fse.getString(CmnConst.ORG_LEVEL_UUID));
|
return status;
|
}
|
return false;
|
}
|
}
|