bug修复

This commit is contained in:
GUO 2024-05-05 22:34:36 +08:00
parent 0ba4e7e415
commit 58bdefaea5
6 changed files with 128 additions and 86 deletions

View File

@ -2,6 +2,7 @@ package com.zhgd.mybatis;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.handler.DataPermissionHandler; import com.baomidou.mybatisplus.extension.plugins.handler.DataPermissionHandler;
import com.zhgd.annotation.DataScope; import com.zhgd.annotation.DataScope;
import com.zhgd.xmgl.modules.worker.entity.EnterpriseInfo; import com.zhgd.xmgl.modules.worker.entity.EnterpriseInfo;
@ -124,68 +125,75 @@ public class DataScopeHandler implements DataPermissionHandler {
} }
private PlainSelect dataScopeFilterByProject(PlainSelect plainSelect, UserInfo user, Object obj) { private PlainSelect dataScopeFilterByProject(PlainSelect plainSelect, UserInfo user, Object obj) {
DataScope ds = (DataScope) obj; JSONObject jo = (JSONObject) obj;
Object parameter = jo.get("parameter");
DataScope ds = jo.getObject("ds", DataScope.class);
init(plainSelect); init(plainSelect);
List<Expression> expressions = new ArrayList<>(); List<Expression> expressions = new ArrayList<>();
if (user.getAccountType() == 6) { if (!DataScopeInterceptor.findIgnoreDataScope(parameter, ds)) {
List<String> filterEnterprises = getNeedFilterLeftExpression(plainSelect, getFieldEnterpriseTables(), ds); if (user.getAccountType() == 6) {
if (CollUtil.isNotEmpty(filterEnterprises)) { List<String> filterEnterprises = getNeedFilterLeftExpression(plainSelect, getFieldEnterpriseTables(), ds);
List<String> enterpriseIds = userEnterpriseService.getEnterpriseIdsIfSubProject(); if (CollUtil.isNotEmpty(filterEnterprises)) {
List<String> enterpriseIds = userEnterpriseService.getEnterpriseIdsIfSubProject();
for (String filterEnterprise : filterEnterprises) {
inExpression(filterEnterprise, enterpriseIds, plainSelect);
}
}
List<String> filterItems = getNeedFilterLeftExpression(plainSelect, getFieldVideoTables(), ds);
if (CollUtil.isNotEmpty(filterItems)) {
List<String> videoItems = userDevAuthorityService.getVideoItemsIfSubProject();
for (String item : filterItems) {
inExpression(item, videoItems, plainSelect);
}
}
} else if (user.getAccountType() == 11) {
List<String> filterEnterprises = getNeedFilterLeftExpression(plainSelect, getFieldEnterpriseTables(), ds);
EnterpriseInfo ei = enterpriseInfoMapper.getXzSupplierByUserId(SecurityUtils.getUser().getUserId());
Long id;
if (ei == null) {
id = -1L;
} else {
id = ei.getId();
}
for (String filterEnterprise : filterEnterprises) { for (String filterEnterprise : filterEnterprises) {
inExpression(filterEnterprise, enterpriseIds, plainSelect); String sql = StrUtil.format(" ({} = {} OR {} IN ( SELECT DISTINCT t.enterprise_id FROM " +
"(SELECT t.id FROM project_enterprise t WHERE t.enterprise_id = {}) t2 join project_enterprise t on find_in_set( t2.id, ancestors ) )) ",
filterEnterprise, id, filterEnterprise, id);
Expression expression = null;
try {
expression = CCJSqlParserUtil.parseCondExpression(sql);
expressions.add(expression);
} catch (JSQLParserException e) {
log.error(e.getMessage(), e);
}
} }
} Expression dataExpression;
if (expressions.size() > 1) {
List<String> filterItems = getNeedFilterLeftExpression(plainSelect, getFieldVideoTables(), ds); //数据权限大于1个之间用或
if (CollUtil.isNotEmpty(filterItems)) { OrExpression orExpression = new OrExpression(expressions.get(0), expressions.get(1));
List<String> videoItems = userDevAuthorityService.getVideoItemsIfSubProject(); for (int i = 2; i < expressions.size(); i++) {
for (String item : filterItems) { orExpression = new OrExpression(orExpression, expressions.get(i));
inExpression(item, videoItems, plainSelect); }
// 数据权限使用单独的括号 防止与其他条件冲突
dataExpression = new Parenthesis(orExpression);
} else {
dataExpression = expressions.get(0);
} }
} Expression where = plainSelect.getWhere();
if (where != null) {
} else if (user.getAccountType() == 11) { where = new AndExpression(where, dataExpression);
List<String> filterEnterprises = getNeedFilterLeftExpression(plainSelect, getFieldEnterpriseTables(), ds); } else {
EnterpriseInfo ei = enterpriseInfoMapper.getXzSupplierByUserId(SecurityUtils.getUser().getUserId()); where = dataExpression;
Long id;
if (ei == null) {
id = -1L;
} else {
id = ei.getId();
}
for (String filterEnterprise : filterEnterprises) {
String sql = StrUtil.format(" ({} = {} OR {} IN ( SELECT DISTINCT t.enterprise_id FROM " +
"(SELECT t.id FROM project_enterprise t WHERE t.enterprise_id = {}) t2 join project_enterprise t on find_in_set( t2.id, ancestors ) )) ",
filterEnterprise, id, filterEnterprise, id);
Expression expression = null;
try {
expression = CCJSqlParserUtil.parseCondExpression(sql);
expressions.add(expression);
} catch (JSQLParserException e) {
log.error(e.getMessage(), e);
} }
plainSelect.setWhere(where);
} }
Expression dataExpression;
if (expressions.size() > 1) {
//数据权限大于1个之间用或
OrExpression orExpression = new OrExpression(expressions.get(0), expressions.get(1));
for (int i = 2; i < expressions.size(); i++) {
orExpression = new OrExpression(orExpression, expressions.get(i));
}
// 数据权限使用单独的括号 防止与其他条件冲突
dataExpression = new Parenthesis(orExpression);
} else {
dataExpression = expressions.get(0);
}
Expression where = plainSelect.getWhere();
if (where != null) {
where = new AndExpression(where, dataExpression);
} else {
where = dataExpression;
}
plainSelect.setWhere(where);
} }
if (!DataScopeInterceptor.isNotSqlTest()) {
equalsTo("'qqq'", "'qqq'", plainSelect);
}
//List<String> scopeIds = systemUserDataScopeService.list(Wrappers.<SystemUserDataScope>lambdaQuery().eq(SystemUserDataScope::getUserId, user.getUserId())) //List<String> scopeIds = systemUserDataScopeService.list(Wrappers.<SystemUserDataScope>lambdaQuery().eq(SystemUserDataScope::getUserId, user.getUserId()))
// .stream().map(u -> u.getRelevanceId()).collect(Collectors.toList()); // .stream().map(u -> u.getRelevanceId()).collect(Collectors.toList());

View File

@ -23,7 +23,10 @@ import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.mapping.SqlCommandType; import org.apache.ibatis.mapping.SqlCommandType;
import org.apache.ibatis.session.ResultHandler; import org.apache.ibatis.session.ResultHandler;
import org.apache.ibatis.session.RowBounds; import org.apache.ibatis.session.RowBounds;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.sql.Connection; import java.sql.Connection;
import java.sql.SQLException; import java.sql.SQLException;
@ -38,6 +41,25 @@ public class DataScopeInterceptor extends JsqlParserSupport implements InnerInte
@Setter @Setter
private DataScopeHandler dataScopeHandler; private DataScopeHandler dataScopeHandler;
public static boolean findIgnoreDataScope(Object parameter, DataScope annotation) {
if (annotation == null || !annotation.enable()) {
return true;
}
if (parameter instanceof Map) {
for (Object val : ((Map<?, ?>) parameter).values()) {
if (val instanceof String) {
if (val.equals("ignoreDataScope")) {
return true;
}
}
}
}
if (parameter instanceof String) {
return parameter.equals("ignoreDataScope");
}
return false;
}
public void beforePrepare(StatementHandler sh, Connection connection, Integer transactionTimeout) { public void beforePrepare(StatementHandler sh, Connection connection, Integer transactionTimeout) {
PluginUtils.MPStatementHandler mpSh = PluginUtils.mpStatementHandler(sh); PluginUtils.MPStatementHandler mpSh = PluginUtils.mpStatementHandler(sh);
MappedStatement ms = mpSh.mappedStatement(); MappedStatement ms = mpSh.mappedStatement();
@ -77,37 +99,26 @@ public class DataScopeInterceptor extends JsqlParserSupport implements InnerInte
Method[] declaredMethods = clazz.getDeclaredMethods(); Method[] declaredMethods = clazz.getDeclaredMethods();
Optional<DataScope> dsOption = Arrays.stream(declaredMethods).filter(method -> method.getName().equals(methodName)).map(method -> method.getAnnotation(DataScope.class)).filter(Objects::nonNull).findFirst(); Optional<DataScope> dsOption = Arrays.stream(declaredMethods).filter(method -> method.getName().equals(methodName)).map(method -> method.getAnnotation(DataScope.class)).filter(Objects::nonNull).findFirst();
annotation = dsOption.orElseGet(() -> clazz.getAnnotation(DataScope.class)); annotation = dsOption.orElseGet(() -> clazz.getAnnotation(DataScope.class));
if (findIgnoreDataScope(parameter, annotation)) { if (findIgnoreDataScope(parameter, annotation) && isNotSqlTest()) {
return; return;
} }
PluginUtils.MPBoundSql mpBs = PluginUtils.mpBoundSql(boundSql); PluginUtils.MPBoundSql mpBs = PluginUtils.mpBoundSql(boundSql);
mpBs.sql(this.parserSingle(mpBs.sql(), annotation)); JSONObject jo = new JSONObject();
jo.put("ds", annotation);
jo.put("parameter", parameter);
mpBs.sql(this.parserSingle(mpBs.sql(), jo));
} catch (Exception e) { } catch (Exception e) {
log.error(e.getMessage(), e); log.error(e.getMessage(), e);
} }
} }
protected void processSelect(Select select, int index, String sql, Object obj) { public static boolean isNotSqlTest() {
this.processSelectBody(select.getSelectBody(), obj); HttpServletRequest request = ((ServletRequestAttributes) (RequestContextHolder.currentRequestAttributes())).getRequest();
return request.getParameter("qqq") == null;
} }
private boolean findIgnoreDataScope(Object parameter, DataScope annotation) { protected void processSelect(Select select, int index, String sql, Object obj) {
if (annotation == null || !annotation.enable()) { this.processSelectBody(select.getSelectBody(), obj);
return true;
}
if (parameter instanceof Map) {
for (Object val : ((Map<?, ?>) parameter).values()) {
if (val instanceof String) {
if (val.equals("ignoreDataScope")) {
return true;
}
}
}
}
if (parameter instanceof String) {
return parameter.equals("ignoreDataScope");
}
return false;
} }
protected void processSelectBody(SelectBody selectBody, Object obj) { protected void processSelectBody(SelectBody selectBody, Object obj) {

View File

@ -30,5 +30,15 @@ public interface INoticeService extends IService<Notice> {
*/ */
void addUserNotice(Long accountId, String msg, String title, String type); void addUserNotice(Long accountId, String msg, String title, String type);
/**
* 发通知给某人和app通知
*
* @param accountId 账号id
* @param msg 消息内容
* @param title 标题
* @param type 类型
*/
void addUserNoticeAndApp(Long accountId, String msg, String title, String type);
void sendProjectNoicte(String projectSn, String title, String msg, String type); void sendProjectNoicte(String projectSn, String title, String msg, String type);
} }

View File

@ -11,11 +11,12 @@ import com.zhgd.xmgl.modules.basicdata.entity.SystemUser;
import com.zhgd.xmgl.modules.basicdata.mapper.NoticeMapper; import com.zhgd.xmgl.modules.basicdata.mapper.NoticeMapper;
import com.zhgd.xmgl.modules.basicdata.mapper.SystemUserMapper; import com.zhgd.xmgl.modules.basicdata.mapper.SystemUserMapper;
import com.zhgd.xmgl.modules.basicdata.service.INoticeService; import com.zhgd.xmgl.modules.basicdata.service.INoticeService;
import com.zhgd.xmgl.push.service.UniPushService;
import org.apache.commons.collections.MapUtils; import org.apache.commons.collections.MapUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
@ -39,6 +40,9 @@ public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, Notice> impleme
@Value("${mqtt-scope}") @Value("${mqtt-scope}")
private String scope; private String scope;
@Lazy
@Autowired
private UniPushService uniPushService;
@Override @Override
public IPage<Notice> selectNoticePageList(Map<String, Object> map) { public IPage<Notice> selectNoticePageList(Map<String, Object> map) {
@ -77,6 +81,16 @@ public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, Notice> impleme
sendPushMessage(notice); sendPushMessage(notice);
} }
@Override
public void addUserNoticeAndApp(Long accountId, String msg, String title, String type) {
addUserNotice(accountId, msg, title, type);
SystemUser systemUser = systemUserMapper.selectById(accountId);
if (systemUser == null) {
return;
}
uniPushService.pushToSingleByAlias(systemUser.getClientId(), title, msg, null);
}
@Override @Override
public void sendProjectNoicte(String projectSn, String title, String msg, String type) { public void sendProjectNoicte(String projectSn, String title, String msg, String type) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

View File

@ -11,7 +11,6 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gexin.fastjson.JSON; import com.gexin.fastjson.JSON;
import com.gexin.fastjson.JSONArray; import com.gexin.fastjson.JSONArray;
import com.gexin.fastjson.JSONObject; import com.gexin.fastjson.JSONObject;
import com.zhgd.jeecg.common.mybatis.EntityMap;
import com.zhgd.xmgl.call.SanjiangDataCall; import com.zhgd.xmgl.call.SanjiangDataCall;
import com.zhgd.xmgl.modules.basicdata.service.INoticeService; import com.zhgd.xmgl.modules.basicdata.service.INoticeService;
import com.zhgd.xmgl.modules.quality.entity.QualityInspectionRecord; import com.zhgd.xmgl.modules.quality.entity.QualityInspectionRecord;
@ -80,7 +79,7 @@ public class QualityRectifyRecordServiceImpl extends ServiceImpl<QualityRectifyR
//已整改时候需要复查 //已整改时候需要复查
if (qualityRectifyRecord.getStatus() == 2) { if (qualityRectifyRecord.getStatus() == 2) {
qualityInspectionRecord.setStatus(3); qualityInspectionRecord.setStatus(3);
noticeService.addUserNotice(tempQualityInspectionRecord.getReviewId(), "您有一条质量检查的整改结果需要复查,请及时查看。", "质量管理整改结果待复查", "11"); noticeService.addUserNoticeAndApp(tempQualityInspectionRecord.getReviewId(), "您有一条质量检查的整改结果需要复查,请及时查看。", "质量管理整改结果待复查", "11");
} else { } else {
qualityInspectionRecord.setStatus(2); qualityInspectionRecord.setStatus(2);
} }
@ -88,19 +87,19 @@ public class QualityRectifyRecordServiceImpl extends ServiceImpl<QualityRectifyR
//复查合格时候需要核验 //复查合格时候需要核验
if (qualityRectifyRecord.getStatus() == 2) { if (qualityRectifyRecord.getStatus() == 2) {
qualityInspectionRecord.setStatus(4); qualityInspectionRecord.setStatus(4);
noticeService.addUserNotice(tempQualityInspectionRecord.getVerifyManId(), "您有一条质量检查的整改结果需要核验,请及时查看。", "质量管理整改结果核验通知", "11"); noticeService.addUserNoticeAndApp(tempQualityInspectionRecord.getVerifyManId(), "您有一条质量检查的整改结果需要核验,请及时查看。", "质量管理整改结果核验通知", "11");
} else { } else {
qualityInspectionRecord.setStatus(2); qualityInspectionRecord.setStatus(2);
noticeService.addUserNotice(tempQualityInspectionRecord.getChangeId(), "您提交的质量检查的整改结果复查不通过,请及时重新整改。", "质量管理整改结果复查通知", "11"); noticeService.addUserNoticeAndApp(tempQualityInspectionRecord.getChangeId(), "您提交的质量检查的整改结果复查不通过,请及时重新整改。", "质量管理整改结果复查通知", "11");
} }
} else { } else {
//核验合格时候则该记录合格 //核验合格时候则该记录合格
if (qualityRectifyRecord.getStatus() == 2) { if (qualityRectifyRecord.getStatus() == 2) {
qualityInspectionRecord.setStatus(5); qualityInspectionRecord.setStatus(5);
noticeService.addUserNotice(tempQualityInspectionRecord.getChangeId(), "您提交的质量检查的整改结果已通过核验。", "质量管理整改结果核验通知", "11"); noticeService.addUserNoticeAndApp(tempQualityInspectionRecord.getChangeId(), "您提交的质量检查的整改结果已通过核验。", "质量管理整改结果核验通知", "11");
} else { } else {
qualityInspectionRecord.setStatus(2); qualityInspectionRecord.setStatus(2);
noticeService.addUserNotice(tempQualityInspectionRecord.getChangeId(), "您提交的质量检查的整改结果核验不通过,请及时重新整改。", "质量管理整改结果核验通知", "11"); noticeService.addUserNoticeAndApp(tempQualityInspectionRecord.getChangeId(), "您提交的质量检查的整改结果核验不通过,请及时重新整改。", "质量管理整改结果核验通知", "11");
} }
} }
qualityInspectionRecordMapper.updateById(qualityInspectionRecord); qualityInspectionRecordMapper.updateById(qualityInspectionRecord);

View File

@ -79,7 +79,7 @@ public class XzSecurityXzSecurityQualityRectifyRecordServiceImpl extends Service
//已整改时候需要复查 //已整改时候需要复查
if (xzSecurityQualityRectifyRecord.getStatus() == 2) { if (xzSecurityQualityRectifyRecord.getStatus() == 2) {
xzSecurityQualityInspectionRecord.setStatus(3); xzSecurityQualityInspectionRecord.setStatus(3);
noticeService.addUserNotice(tempXzSecurityQualityInspectionRecord.getReviewId(), "您有一条安全检查的整改结果需要复查,请及时查看。", "安全管理整改结果待复查", "10"); noticeService.addUserNoticeAndApp(tempXzSecurityQualityInspectionRecord.getReviewId(), "您有一条安全检查的整改结果需要复查,请及时查看。", "安全管理整改结果待复查", "10");
} else { } else {
xzSecurityQualityInspectionRecord.setStatus(2); xzSecurityQualityInspectionRecord.setStatus(2);
} }
@ -87,19 +87,19 @@ public class XzSecurityXzSecurityQualityRectifyRecordServiceImpl extends Service
//复查合格时候需要核验 //复查合格时候需要核验
if (xzSecurityQualityRectifyRecord.getStatus() == 2) { if (xzSecurityQualityRectifyRecord.getStatus() == 2) {
xzSecurityQualityInspectionRecord.setStatus(4); xzSecurityQualityInspectionRecord.setStatus(4);
noticeService.addUserNotice(tempXzSecurityQualityInspectionRecord.getVerifyManId(), "您有一条安全检查的整改结果需要核验,请及时查看。", "安全管理整改结果核验通知", "10"); noticeService.addUserNoticeAndApp(tempXzSecurityQualityInspectionRecord.getVerifyManId(), "您有一条安全检查的整改结果需要核验,请及时查看。", "安全管理整改结果核验通知", "10");
} else { } else {
xzSecurityQualityInspectionRecord.setStatus(2); xzSecurityQualityInspectionRecord.setStatus(2);
noticeService.addUserNotice(tempXzSecurityQualityInspectionRecord.getChangeId(), "您提交的安全检查的整改结果复查不通过,请及时重新整改。", "安全管理整改结果复查通知", "10"); noticeService.addUserNoticeAndApp(tempXzSecurityQualityInspectionRecord.getChangeId(), "您提交的安全检查的整改结果复查不通过,请及时重新整改。", "安全管理整改结果复查通知", "10");
} }
} else { } else {
//核验合格时候则该记录合格 //核验合格时候则该记录合格
if (xzSecurityQualityRectifyRecord.getStatus() == 2) { if (xzSecurityQualityRectifyRecord.getStatus() == 2) {
xzSecurityQualityInspectionRecord.setStatus(5); xzSecurityQualityInspectionRecord.setStatus(5);
noticeService.addUserNotice(tempXzSecurityQualityInspectionRecord.getChangeId(), "您提交的安全检查的整改结果已通过核验。", "安全管理整改结果核验通知", "10"); noticeService.addUserNoticeAndApp(tempXzSecurityQualityInspectionRecord.getChangeId(), "您提交的安全检查的整改结果已通过核验。", "安全管理整改结果核验通知", "10");
} else { } else {
xzSecurityQualityInspectionRecord.setStatus(2); xzSecurityQualityInspectionRecord.setStatus(2);
noticeService.addUserNotice(tempXzSecurityQualityInspectionRecord.getChangeId(), "您提交的安全检查的整改结果核验不通过,请及时重新整改。", "安全管理整改结果核验通知", "10"); noticeService.addUserNoticeAndApp(tempXzSecurityQualityInspectionRecord.getChangeId(), "您提交的安全检查的整改结果核验不通过,请及时重新整改。", "安全管理整改结果核验通知", "10");
} }
} }
xzSecurityQualityInspectionRecordMapper.updateById(xzSecurityQualityInspectionRecord); xzSecurityQualityInspectionRecordMapper.updateById(xzSecurityQualityInspectionRecord);