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

做网站用什么语言开发中国万网域名注册免费

做网站用什么语言开发,中国万网域名注册免费,南宁哪里有seo推广厂家,Wordpress去除文章发布日期拦截插入操作 场景描述:插入当前数据时,同时复制当前数据插入多行。比如平台权限的用户,可以同时给其他国家级别用户直接插入数据 实现: 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.hrbkazy.com/news/55997.html

相关文章:

  • 免费做电子相册的网站关键词检测工具
  • 建站系统做的网站百度可以搜索到吗潍坊seo教程
  • wordpress qq分享插件山西seo排名
  • 汽车4s店网站模板怎么申请网站空间
  • 哪个网站推广比较好自助建站系统个人网站
  • wordpress 搭配keycdn太原关键词优化报价
  • 宝安网站设计公司万网官网入口
  • 松江建设新城有限公司网站seo数据统计分析工具有哪些
  • 如何在线实现手机版网站建设网上永久视频会员是真的吗
  • 呼和浩特网站建设小程序网站注册搜索引擎的目的是
  • 专业做电脑系统下载网站好seo竞价
  • 建设医院官方网站电商的推广方式有哪些
  • 外贸网站建站案例seo优化博客
  • 国外的工业设计网站百度seo网站在线诊断
  • 网址大全快捷怎么来的seoul national university
  • 合肥网络推广公司哪家专业seo关键字优化价格
  • 化妆品网站建设流程图软件开发网站
  • 做网站可以赚多少钱互联网运营推广
  • 仿淘宝电商网站开发报价app推广多少钱一单
  • 综合电子商务型企业网站有哪些培训学校
  • 微站电池哪些平台可以免费打广告
  • 防伪码做网站的还能没导入吗怎样让自己的网站排名靠前
  • 新材料 东莞网站建设seo搜索引擎优化薪资
  • 集团企业网站设计方案seo网站优化快速排名软件
  • 宁波新亚建设公司网站营销公司排行
  • 网站广告的图片怎么做搜索推广开户
  • 网站建设的开发方式西安网站seo价格
  • 锡盟本地网站建设百度竞价推广专员
  • 有没有做头像的网站厦门人才网唯一官网
  • 南宁网站制作建设网店营销策略有哪些