Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
3dd6e2e189
|
|
@ -0,0 +1,45 @@
|
||||||
|
package com.czg.config;
|
||||||
|
|
||||||
|
import com.mybatisflex.core.dialect.impl.CommonsDialectImpl;
|
||||||
|
import com.mybatisflex.core.exception.FlexExceptions;
|
||||||
|
import com.mybatisflex.core.exception.locale.LocalizedFormats;
|
||||||
|
import com.mybatisflex.core.query.CPI;
|
||||||
|
import com.mybatisflex.core.query.QueryCondition;
|
||||||
|
import com.mybatisflex.core.query.QueryTable;
|
||||||
|
import com.mybatisflex.core.query.QueryWrapper;
|
||||||
|
import com.mybatisflex.core.util.StringUtil;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static com.mybatisflex.core.constant.SqlConsts.ASTERISK;
|
||||||
|
import static com.mybatisflex.core.constant.SqlConsts.WHERE;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自定义sql解析器 备用
|
||||||
|
*/
|
||||||
|
//@Component
|
||||||
|
public class MyCommonsDialectImpl extends CommonsDialectImpl {
|
||||||
|
@Override
|
||||||
|
public String wrap(String keyword) {
|
||||||
|
return ASTERISK.equals(keyword) ? keyword : keywordWrap.wrap(keyword);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void buildWhereSql(StringBuilder sqlBuilder, QueryWrapper queryWrapper, List<QueryTable> queryTables, boolean allowNoCondition) {
|
||||||
|
QueryCondition whereQueryCondition = CPI.getWhereQueryCondition(queryWrapper);
|
||||||
|
if (whereQueryCondition != null) {
|
||||||
|
String whereSql = whereQueryCondition.toSql(queryTables, this);
|
||||||
|
if (StringUtil.hasText(whereSql)) {
|
||||||
|
sqlBuilder.append(WHERE).append(whereSql);
|
||||||
|
} else if (!allowNoCondition) {
|
||||||
|
throw FlexExceptions.wrap(LocalizedFormats.UPDATE_OR_DELETE_NOT_ALLOW);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// whereQueryCondition == null
|
||||||
|
if (!allowNoCondition) {
|
||||||
|
throw FlexExceptions.wrap(LocalizedFormats.UPDATE_OR_DELETE_NOT_ALLOW);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,18 +0,0 @@
|
||||||
package com.czg.config;
|
|
||||||
|
|
||||||
import com.mybatisflex.core.mybatis.FlexConfiguration;
|
|
||||||
import com.mybatisflex.spring.boot.ConfigurationCustomizer;
|
|
||||||
import org.apache.ibatis.logging.stdout.StdOutImpl;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Administrator
|
|
||||||
*/
|
|
||||||
@Configuration
|
|
||||||
public class MyConfigurationCustomizer implements ConfigurationCustomizer {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void customize(FlexConfiguration configuration) {
|
|
||||||
configuration.setLogImpl(StdOutImpl.class);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -0,0 +1,36 @@
|
||||||
|
package com.czg.config;
|
||||||
|
|
||||||
|
import com.mybatisflex.core.audit.AuditManager;
|
||||||
|
import com.mybatisflex.core.dialect.DbType;
|
||||||
|
import com.mybatisflex.core.dialect.DialectFactory;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自定义sql方言
|
||||||
|
*
|
||||||
|
* @author Administrator
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
@Slf4j(topic = "mybatis-flex-sql")
|
||||||
|
public class MybatisFlexConfig {
|
||||||
|
|
||||||
|
public MybatisFlexConfig() {
|
||||||
|
//开启审计功能
|
||||||
|
AuditManager.setAuditEnable(true);
|
||||||
|
|
||||||
|
//设置 SQL 审计收集器
|
||||||
|
AuditManager.setMessageCollector(auditMessage ->
|
||||||
|
log.info("{},{}ms", auditMessage.getFullSql()
|
||||||
|
, auditMessage.getElapsedTime())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// @Resource
|
||||||
|
private MyCommonsDialectImpl myCommonsDialect;
|
||||||
|
|
||||||
|
// @PostConstruct
|
||||||
|
public void init() {
|
||||||
|
DialectFactory.registerDialect(DbType.MYSQL, myCommonsDialect);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package com.czg.utils;
|
package com.czg.utils;
|
||||||
|
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import com.mybatisflex.core.constant.SqlConnector;
|
||||||
import com.mybatisflex.core.exception.FlexExceptions;
|
import com.mybatisflex.core.exception.FlexExceptions;
|
||||||
import com.mybatisflex.core.query.*;
|
import com.mybatisflex.core.query.*;
|
||||||
import com.mybatisflex.core.table.TableInfo;
|
import com.mybatisflex.core.table.TableInfo;
|
||||||
|
|
@ -10,12 +11,14 @@ import com.mybatisflex.core.util.LambdaGetter;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.lang.invoke.SerializedLambda;
|
import java.lang.invoke.SerializedLambda;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
import static com.mybatisflex.core.util.LambdaUtil.getFieldName;
|
import static com.mybatisflex.core.util.LambdaUtil.getFieldName;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 关联查询的queryWrapper
|
* 关联查询的queryWrapper
|
||||||
|
*
|
||||||
* @author Administrator
|
* @author Administrator
|
||||||
*/
|
*/
|
||||||
public class JoinQueryWrapper extends QueryWrapper {
|
public class JoinQueryWrapper extends QueryWrapper {
|
||||||
|
|
@ -55,6 +58,59 @@ public class JoinQueryWrapper extends QueryWrapper {
|
||||||
return tableInfo.getTableName() + "." + StrUtil.toUnderlineCase(getFieldName(column));
|
return tableInfo.getTableName() + "." + StrUtil.toUnderlineCase(getFieldName(column));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static <T> QueryColumn column(LambdaGetter<T> getter) {
|
||||||
|
SerializedLambda lambda = getSerializedLambda(getter);
|
||||||
|
Class<?> entityClass = getImplClass0(lambda);
|
||||||
|
TableInfo tableInfo = TableInfoFactory.ofEntityClass(entityClass);
|
||||||
|
String fieldName = getFieldName(getter);
|
||||||
|
QueryColumn columnByProperty = tableInfo.getQueryColumnByProperty(fieldName);
|
||||||
|
columnByProperty.setName(tableInfo.getTableName() + "." + StrUtil.toUnderlineCase(fieldName));
|
||||||
|
return columnByProperty;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JoinQueryWrapper and(Consumer<QueryWrapper> consumer, boolean condition) {
|
||||||
|
if (!condition) {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
JoinQueryWrapper newWrapper = new JoinQueryWrapper();
|
||||||
|
consumer.accept(newWrapper);
|
||||||
|
QueryCondition whereQueryCondition = newWrapper.whereQueryCondition;
|
||||||
|
if (whereQueryCondition != null) {
|
||||||
|
and(new Brackets(whereQueryCondition));
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JoinQueryWrapper or(Consumer<QueryWrapper> consumer, boolean condition) {
|
||||||
|
if (!condition) {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
JoinQueryWrapper newWrapper = new JoinQueryWrapper();
|
||||||
|
consumer.accept(newWrapper);
|
||||||
|
QueryCondition whereQueryCondition = newWrapper.whereQueryCondition;
|
||||||
|
if (whereQueryCondition != null) {
|
||||||
|
or(new Brackets(whereQueryCondition));
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JoinQueryWrapper or(Consumer<QueryWrapper> consumer) {
|
||||||
|
return or(consumer, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JoinQueryWrapper and(Consumer<QueryWrapper> consumer) {
|
||||||
|
return and(consumer, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public QueryWrapper and(QueryCondition queryCondition) {
|
||||||
|
return addWhereQueryCondition(queryCondition, SqlConnector.AND);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T> JoinQueryWrapper eq(LambdaGetter<T> column, Object value) {
|
public <T> JoinQueryWrapper eq(LambdaGetter<T> column, Object value) {
|
||||||
eq(getColum(column), value);
|
eq(getColum(column), value);
|
||||||
|
|
@ -90,4 +146,12 @@ public class JoinQueryWrapper extends QueryWrapper {
|
||||||
orderBy(getColum(column), asc);
|
orderBy(getColum(column), asc);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T> JoinQueryWrapper like(LambdaGetter<T> column, Object value) {
|
||||||
|
like(getColum(column), value);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ import com.czg.sa.StpKit;
|
||||||
import com.czg.service.RedisService;
|
import com.czg.service.RedisService;
|
||||||
import com.czg.service.account.mapper.ShopUserMapper;
|
import com.czg.service.account.mapper.ShopUserMapper;
|
||||||
import com.czg.utils.AssertUtil;
|
import com.czg.utils.AssertUtil;
|
||||||
|
import com.czg.utils.JoinQueryWrapper;
|
||||||
import com.czg.utils.PageUtil;
|
import com.czg.utils.PageUtil;
|
||||||
import com.mybatisflex.core.paginate.Page;
|
import com.mybatisflex.core.paginate.Page;
|
||||||
import com.mybatisflex.core.query.QueryWrapper;
|
import com.mybatisflex.core.query.QueryWrapper;
|
||||||
|
|
@ -56,9 +57,15 @@ public class ShopUserServiceImpl extends ServiceImpl<ShopUserMapper, ShopUser> i
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Page<ShopUser> getPage(String key, Integer isVip) {
|
public Page<ShopUser> getPage(String key, Integer isVip) {
|
||||||
QueryWrapper queryWrapper = new QueryWrapper().eq(ShopUser::getShopId, StpKit.USER.getShopId());
|
JoinQueryWrapper queryWrapper = new JoinQueryWrapper().eq(ShopUser::getShopId, StpKit.USER.getShopId());
|
||||||
if (StrUtil.isNotBlank(key)) {
|
if (StrUtil.isNotBlank(key)) {
|
||||||
queryWrapper.and(column(UserInfo::getNickName).like(key).or(column(UserInfo::getPhone).like(key)));
|
queryWrapper.and(q -> {
|
||||||
|
q.like(UserInfo::getNickName, key).or(r -> {
|
||||||
|
r.like(UserInfo::getPhone, key);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// queryWrapper.and(JoinQueryWrapper.column(UserInfo::getNickName).like(key).or(JoinQueryWrapper.column(UserInfo::getPhone).like(key)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isVip != null) {
|
if (isVip != null) {
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@
|
||||||
<select id="selectUserSummary" resultType="com.czg.account.dto.shopuser.ShopUserSummaryDTO">
|
<select id="selectUserSummary" resultType="com.czg.account.dto.shopuser.ShopUserSummaryDTO">
|
||||||
select count(a.id) userTotal, sum(IFNULL(a.amount, 0)) balanceTotal,sum(IFNULL(b.amount,0)) chargeTotal from
|
select count(a.id) userTotal, sum(IFNULL(a.amount, 0)) balanceTotal,sum(IFNULL(b.amount,0)) chargeTotal from
|
||||||
tb_shop_user as a
|
tb_shop_user as a
|
||||||
left join tb_shop_user_flow as b on a.id=b.user_id and b.biz_code in ('cashIn', 'wechatIn',
|
left join tb_shop_user_flow as b on a.id=b.user_id and b.biz_code in ('cashIn', 'wechatIn',
|
||||||
'alipayIn')
|
'alipayIn')
|
||||||
where a.shop_id = #{shopId}
|
where a.shop_id = #{shopId}
|
||||||
<if test="isVip !=null">
|
<if test="isVip !=null">
|
||||||
|
|
@ -37,18 +37,24 @@
|
||||||
where a.user_id = #{userInfoId}
|
where a.user_id = #{userInfoId}
|
||||||
</select>
|
</select>
|
||||||
<select id="selectAssetsSummary" resultType="com.czg.account.dto.user.userinfo.UserInfoAssetsSummaryDTO">
|
<select id="selectAssetsSummary" resultType="com.czg.account.dto.user.userinfo.UserInfoAssetsSummaryDTO">
|
||||||
select sum(IFNULL(b.amount, 0)) as amount, sum(IFNULL(b.account_points, 0)) as points, sum(IFNULL(c.over_num, 0)) as couponNum
|
select sum(IFNULL(b.amount, 0)) as amount,
|
||||||
|
sum(IFNULL(b.account_points, 0)) as points,
|
||||||
|
sum(IFNULL(c.id, 0)) as couponNum
|
||||||
from tb_user_info as a
|
from tb_user_info as a
|
||||||
left join tb_shop_user as b on a.id = b.user_id
|
left join tb_shop_user as b on a.id = b.user_id
|
||||||
left join tb_shop_activate_in_record as c on c.shop_id = b.shop_id
|
left join tb_shop_activate_coupon_record as c
|
||||||
where a.id=#{userId}
|
on c.shop_id = b.shop_id and c.vip_user_id = b.id and c.`status` = 'used'
|
||||||
|
where a.id = #{userId}
|
||||||
</select>
|
</select>
|
||||||
<select id="selectPageByKeyAndIsVip" resultType="com.czg.account.entity.ShopUser">
|
<select id="selectPageByKeyAndIsVip" resultType="com.czg.account.entity.ShopUser">
|
||||||
select tb_shop_user.* from tb_user_info
|
select tb_shop_user.*
|
||||||
left join tb_shop_user on tb_user_info.id=tb_shop_user.user_id ${qwSql} limit ${pageOffset}, ${pageSize}
|
from tb_user_info
|
||||||
|
left join tb_shop_user on tb_user_info.id = tb_shop_user.user_id ${qwSql}
|
||||||
|
limit ${pageOffset}, ${pageSize}
|
||||||
</select>
|
</select>
|
||||||
<select id="selectPageByKeyAndIsVip_COUNT" resultType="java.lang.Long">
|
<select id="selectPageByKeyAndIsVip_COUNT" resultType="java.lang.Long">
|
||||||
select count(1) from tb_user_info
|
select count(1)
|
||||||
left join tb_shop_user on tb_user_info.id=tb_shop_user.user_id ${qwSql}
|
from tb_user_info
|
||||||
|
left join tb_shop_user on tb_user_info.id = tb_shop_user.user_id ${qwSql}
|
||||||
</select>
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue