当前位置: 首页 > news >正文

如何做网站图标官方网站百度一下

如何做网站图标,官方网站百度一下,h5制作软件有中文版吗,深圳网站建设信科公司便宜拦截插入操作 场景描述:插入当前数据时,同时复制当前数据插入多行。比如平台权限的用户,可以同时给其他国家级别用户直接插入数据 实现: import lombok.extern.slf4j.Slf4j; import org.apache.ibatis.executor.Executor; impor…

拦截插入操作

场景描述:插入当前数据时,同时复制当前数据插入多行。比如平台权限的用户,可以同时给其他国家级别用户直接插入数据

  实现:

import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.executor.Executor;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.mapping.SqlCommandType;
import org.apache.ibatis.plugin.Interceptor;
import org.apache.ibatis.plugin.Intercepts;
import org.apache.ibatis.plugin.Invocation;
import org.apache.ibatis.plugin.Signature;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;import javax.annotation.Resource;
import java.lang.reflect.Constructor;
import java.util.List;
import java.util.Properties;/*** @author xxx* @version 1.0* @description 超级管理员创建基础资料,自动创建其他国家相应数据* @create 2024/3/2/002 13:48*/
@Slf4j
@Component
@Intercepts({@Signature(type = Executor.class, method = "update", args = {MappedStatement.class, Object.class})
})
public class InsertionLinkageInterceptor implements Interceptor {@Value("${product.country-id.tables}")private String countryIdTables;@Resourceprivate UserService userService;@Overridepublic Object intercept(Invocation invocation) throws Throwable {// 只有超级管理员需要拦截if (!userService.isSuperAdmin()) {return invocation.proceed();}Object[] args = invocation.getArgs();MappedStatement ms = (MappedStatement) args[0];// 拦截插入操作if (ms.getSqlCommandType() == SqlCommandType.INSERT) {Object parameter = args[1];Class<?> aClass = parameter.getClass();TableName annotation = aClass.getAnnotation(TableName.class);String tableName = annotation.value();// 此处业务逻辑判断 此处做了一个表格名动态配置,可自行修改 //TODOif (!countryIdTables.contains(tableName)) {return invocation.proceed();}CountryBaseInfoDO parameterDO = (CountryBaseInfoDO) args[1];parameterDO.setCountryId(userService.getUserCountryId());parameterDO.setCode(IdUtils.generateCode());Constructor<?> constructor = aClass.getConstructor();CountryBaseInfoDO paramObject;List<Long> countryList = userService.getUserCountryIds();for (Long countryId : countryList) {paramObject = (CountryBaseInfoDO) constructor.newInstance();BeanUtils.copyProperties(parameterDO, paramObject);paramObject.setCountryId(countryId);Executor executor = (Executor) invocation.getTarget();executor.update(ms, paramObject);}}// 继续执行原始方法return invocation.proceed();}}

有些实体可能需要自行创建 

拦截更新操作

更新数据时候,可能不止更新当前表,可能需要同时更新其他行数据

拦截查询

查询数据时候,可能需要同时默认加上某个条件

实现:

@Slf4j
@Component
@Intercepts({@Signature(type = StatementHandler.class, method = "prepare", args = {Connection.class, Integer.class})})
public class CommonQueryInterceptor implements Interceptor {private final static String FIELD_COUNTRY_ID = "country_id";@Value("${product.country-id.tables}")private String countryIdTables;@Resourceprivate UserService userService;@Overridepublic Object intercept(Invocation invocation) throws Throwable {// 超级管理员查看所有if (!userService.isSuperAdmin()) {return invocation.proceed();}RoutingStatementHandler handler = (RoutingStatementHandler) invocation.getTarget();//获取StatementHandler构造器StatementHandler delegate = (StatementHandler) ReflectUtil.getFieldValue(handler, "delegate");BoundSql boundSql = delegate.getBoundSql();String sql = boundSql.getSql();Statement statement = CCJSqlParserUtil.parse(sql);// 通过反射获取delegate父类BaseStatementHandler的mappedStatement属性MappedStatement mappedStatement = (MappedStatement) ReflectUtil.getFieldValue(delegate, "mappedStatement");SqlCommandType commandType = mappedStatement.getSqlCommandType();if (SqlCommandType.SELECT.equals(commandType)) {Select select = (Select) statement;PlainSelect selectBody = (PlainSelect) select.getSelectBody();Table fromItem = (Table) selectBody.getFromItem();String name = fromItem.getName();// 不在配置的表中,直接返回if (!countryIdTables.contains(name)) {return invocation.proceed();}appendCondition(selectBody);ReflectUtil.setFieldValue(boundSql, "sql", statement.toString());// 超级管理员插入时候同步插入所有国家的数据} else if (SqlCommandType.UPDATE.equals(commandType)) {String extraCondition = " or id  in(" + userService.getNeedUpdateIds() + ")";sql = sql + extraCondition;ReflectUtil.setFieldValue(boundSql, "sql", sql);}return invocation.proceed();}/*** 追加条件*/private void appendCondition(PlainSelect selectBody) {try {// 获取where条件String stringExpression;try {EqualsTo where = (EqualsTo) selectBody.getWhere();stringExpression = where.getStringExpression();} catch (Exception e) {stringExpression = selectBody.getWhere().toString();}//如果字段搜索条件为空则搜索字段为空或指定数据StringBuilder sqlFilter = new StringBuilder(128);if (!stringExpression.contains(FIELD_COUNTRY_ID)) {sqlFilter.append("(country_id in ( ").append(userService.getNeedUpdateIds()).append(")) ");buildWhereClause(selectBody, sqlFilter.toString());}} catch (Exception e) {log.error("appendCondition error", e);//多表查询时由于不是最后一层,获取不到Table,继续获取子表
//            SubSelect ss = (SubSelect) selectBody.getFromItem();
//            PlainSelect subSelect = (PlainSelect) ss.getSelectBody();
//            appendCondition(subSelect);}}private void buildWhereClause(PlainSelect select, String dataFilter) throws JSQLParserException {if (select.getWhere() == null) {select.setWhere(CCJSqlParserUtil.parseCondExpression(dataFilter));} else {AndExpression and = new AndExpression(CCJSqlParserUtil.parseCondExpression(dataFilter), select.getWhere());select.setWhere(and);}}}

http://www.khdw.cn/news/20566.html

相关文章:

  • 做书app下载网站有哪些seo 优化一般包括哪些内容
  • 网站怎么制作做百度账号登录入口网页版
  • 企业网站优化推广怎么做怎么推广一个平台
  • 定制网络教研系统适合seo优化的网站
  • 石狮做网站搜狗竞价推广效果怎么样
  • 长春建设平台网站的公司吗网络软文广告
  • 建设网站三要如何提高网站排名seo
  • 怎么自己做淘客网站百度收录提交入口地址
  • 荆门网站开发公司电话seo排名优化
  • 网站策划报告书怎么做网站服务费一年多少钱
  • 做平面设计兼职的网站互联网营销师考试题及答案
  • 本溪北京网站建设电商数据统计网站
  • wordpress中文摘要台州关键词优化报价
  • 电子商务网站建设流程google推广妙招
  • 为传销做网站公司网站设计的内容有哪些
  • 做一张网站图多少钱百度识图网页版在线使用
  • 南京做网站哪家公司好百度爱企查电话人工服务总部
  • qq登录网站授权怎么做百度怎么做广告推广
  • 网站页面建设规划文案下拉词排名
  • 做seo的网站推广网络seo是什么意思
  • 求职网站网页设计中央新闻联播
  • 广州网站制作怎么选网站目录
  • 做网站网页优秀营销软文100篇
  • 免费国内socks5代理seo技术
  • pc网站做移动端适配网站关键词如何快速上首页
  • 社交网站开发难度重庆seo外包平台
  • 化妆品网站建设的维护夸克浏览器网页版入口
  • 莱芜民生网站免费推广平台排行
  • 高端上海网站设计公司网络优化app哪个好
  • 漯河做网站推广引流app推广软件