Merge branch 'master' into prod

This commit is contained in:
GYJ 2025-04-02 16:09:02 +08:00
commit 6003f89772
32 changed files with 556 additions and 103 deletions

View File

@ -59,8 +59,8 @@ public class AuthorizationController {
* @return token信息
*/
@PostMapping("login")
public CzgResult<LoginVO> login(@Validated @RequestBody SysLoginDTO loginDTO) {
return CzgResult.success(authorizationService.login(loginDTO));
public CzgResult<LoginVO> login(@Validated @RequestBody SysLoginDTO loginDTO, @RequestHeader(defaultValue = "WEB") String platformType) {
return CzgResult.success(authorizationService.login(loginDTO, platformType));
}
/**

View File

@ -0,0 +1,78 @@
package com.czg.controller.admin;
import com.czg.account.dto.pagepath.PagePathPermissionAddDTO;
import com.czg.account.entity.ShopPagePath;
import com.czg.account.entity.ShopStaffPagePermission;
import com.czg.account.service.ShopPagePathService;
import com.czg.account.service.ShopStaffPagePermissionService;
import com.czg.resp.CzgResult;
import com.czg.sa.StpKit;
import com.mybatisflex.core.query.QueryWrapper;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
/**
* 收银机页面权限相关
* @author Administrator
*/
@RestController
@RequestMapping("/admin/shopPagePermission")
public class ShopPagePermissionController {
@Resource
private ShopPagePathService shopPagePathService;
@Resource
private ShopStaffPagePermissionService shopStaffPagePermissionService;
/**
* 获取所有页面路径
* @return 页面路径
*/
@GetMapping
public CzgResult<List<ShopPagePath>> page() {
return CzgResult.success(shopPagePathService.list());
}
/**
* 保存修改权限
* @return 是否成功
*/
@PostMapping
public CzgResult<Boolean> add(@RequestBody @Validated PagePathPermissionAddDTO pagePathPermissionAddDTO) {
if (StpKit.USER.isStaff()) {
return CzgResult.failure("员工无权限");
}
return CzgResult.success(shopStaffPagePermissionService.add(StpKit.USER.getShopId(), pagePathPermissionAddDTO));
}
/**
* 获取员工拥有页面路径
* @param staffId 员工ID
*/
@GetMapping("/detail")
public CzgResult<List<ShopPagePath>> detail(@RequestParam Long staffId) {
Set<Long> pageIdList = shopStaffPagePermissionService.list(new QueryWrapper().eq(ShopStaffPagePermission::getShopId,
StpKit.USER.getShopId()).eq(ShopStaffPagePermission::getStaffId, staffId)).stream().map(ShopStaffPagePermission::getPagePathId).collect(Collectors.toSet());
if (pageIdList.isEmpty()) {
return CzgResult.success(new ArrayList<>());
}
return CzgResult.success(shopPagePathService.list(new QueryWrapper().in(ShopPagePath::getId, pageIdList)));
}
/**
* 获取当前员工已拥有页面路径权限
*/
@GetMapping("/mine")
public CzgResult<List<ShopPagePath>> mine() {
Set<Long> pageIdList = shopStaffPagePermissionService.list(new QueryWrapper().eq(ShopStaffPagePermission::getShopId, StpKit.USER.getShopId()).eq(ShopStaffPagePermission::getStaffId, StpKit.USER.getLoginIdAsLong())).stream().map(ShopStaffPagePermission::getPagePathId).collect(Collectors.toSet());
if (pageIdList.isEmpty()) {
return CzgResult.success(new ArrayList<>());
}
return CzgResult.success(shopPagePathService.list(new QueryWrapper().in(ShopPagePath::getId, pageIdList)));
}
}

View File

@ -1,7 +1,5 @@
server:
port: 9100
servlet:
context-path: /account
spring:
application:

View File

@ -2,17 +2,17 @@ package com.czg.controller;
import com.alibaba.fastjson2.JSONObject;
import com.czg.CzgPayUtils;
import com.czg.account.service.MemberPointsService;
import com.czg.entity.CzgBaseRespParams;
import com.czg.mq.PrintMqListener;
import com.czg.order.service.OrderInfoService;
import com.czg.order.service.ShopOrderStatisticService;
import com.czg.task.StatisticTask;
import com.czg.utils.AssertUtil;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
* @author ww
@ -30,26 +30,18 @@ public class NotifyController {
@Resource
private StatisticTask statisticTask;
@DubboReference
private MemberPointsService pointsService;
@Resource
private ShopOrderStatisticService shopOrderStatisticService;
@GetMapping("/payCallBack")
public String notifyCallBack() {
shopOrderStatisticService.statistic();
//JSONObject czg = CzgPayUtils.getCzg(respParams);
//AssertUtil.isNull(czg, "支付回调数据为空");
//log.info("支付回调数据为:{}", czg);
//orderInfoService.payCallBackOrder(czg.getString("mchOrderNo"), czg);
@RequestMapping("/payCallBack")
public String notifyCallBack(@RequestBody CzgBaseRespParams respParams){
JSONObject czg = CzgPayUtils.getCzg(respParams);
AssertUtil.isNull(czg, "支付回调数据为空");
log.info("支付回调数据为:{}", czg);
orderInfoService.payCallBackOrder(czg.getString("mchOrderNo"), czg);
return SUCCESS;
}
@RequestMapping("/refundCallBack")
public String refundCallBack(@RequestBody CzgBaseRespParams respParams) {
public String refundCallBack(@RequestBody CzgBaseRespParams respParams){
JSONObject czg = CzgPayUtils.getCzg(respParams);
AssertUtil.isNull(czg, "退款回调数据为空");
log.info("退款回调数据为:{}", czg);
@ -59,7 +51,6 @@ public class NotifyController {
@Resource
private PrintMqListener printMqListener;
@RequestMapping("/test")
public void test(@RequestParam String id) {
printMqListener.orderPrint(id);

View File

@ -27,8 +27,8 @@ public class StatisticTask {
long start = System.currentTimeMillis();
log.info("定时任务执行,开始统计数据");
shopOrderStatisticService.statistic();
//shopProdStatisticService.statistic();
//shopTableOrderStatisticService.statistic();
shopProdStatisticService.statistic();
shopTableOrderStatisticService.statistic();
log.info("定时任务执行完毕,耗时:{}ms", start - System.currentTimeMillis());
}
}

View File

@ -1,7 +1,5 @@
server:
port: 9200
servlet:
context-path: /order
spring:
application:

View File

@ -18,7 +18,6 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
public class ProductApplication {
public static void main(String[] args) {
SpringApplication.run(ProductApplication.class, args);
}

View File

@ -1,7 +1,5 @@
server:
port: 9300
servlet:
context-path: /product
spring:
application:

View File

@ -71,7 +71,7 @@ public class VersionController {
* @return VersionDTO
*/
@GetMapping("/{source}/{type}")
@SaAdminCheckPermission(value = "version:get", name = "版本获取")
// @SaAdminCheckPermission(value = "version:get", name = "版本获取")
public CzgResult<VersionDTO> getVersionInfo(@PathVariable("source") String source, @PathVariable("type") String type) {
return versionService.getVersionInfo(source, type);
}

View File

@ -1,7 +1,5 @@
server:
port: 9400
servlet:
context-path: /system
spring:
application:

View File

@ -61,17 +61,15 @@ public class SaTokenConfigure implements WebMvcConfigurer {
SaRouter.match("/user/**").notMatch("/user/login", "/user/test", "/user/geo/**", "/user/home/**", "/user/home/**", "/user/dict/**", "/user/openId")
.notMatch("/pay/**")
.notMatch("/order/notify/**")
.notMatch("/user/product/**")
.notMatch("/notify/**")
.check(r -> MyStpLogic.CLIENT_LOGIC.checkLogin())
.setHit(true)
// .match("/**")
.notMatch("/user/**")
.notMatch("/pay/**")
.notMatch("/order/notify/**")
.notMatch("/account/admin/auth/**")
.notMatch("/user/product/**")
.notMatch("/account/admin/shopMsgPush/subscribe/**")
.notMatch("/notify/**")
.notMatch("/admin/auth/**")
.notMatch("/admin/shopMsgPush/subscribe/**")
.check(r -> MyStpLogic.ADMIN_LOGIC.checkLogin());
})).addPathPatterns("/**");

View File

@ -0,0 +1,60 @@
package com.czg.account.dto;
import java.io.Serializable;
import java.time.LocalDateTime;
import com.alibaba.fastjson2.annotation.JSONField;
import java.io.Serial;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* 实体类
*
* @author zs
* @since 2025-04-02
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ShopPagePathDTO implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
private Long id;
/**
* 店铺id
*/
private Long shopId;
/**
* 名称
*/
private String name;
/**
* 页面路径
*/
private String path;
/**
* 备注
*/
private String remark;
/**
* 创建时间
*/
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime createTime;
/**
* 修改时间
*/
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime updateTime;
}

View File

@ -0,0 +1,34 @@
package com.czg.account.dto;
import java.io.Serializable;
import java.io.Serial;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* 实体类
*
* @author zs
* @since 2025-04-02
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ShopStaffPagePermissionDTO implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
* 店铺id
*/
private Long shopId;
/**
* 页面路径
*/
private Long pagePathId;
}

View File

@ -0,0 +1,18 @@
package com.czg.account.dto.pagepath;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import java.util.List;
/**
* @author Administrator
*/
@Data
public class PagePathPermissionAddDTO {
@NotEmpty(message = "权限id不为空")
private List<Long> pagePathIdList;
@NotNull(message = "员工id不为空")
private Long staffId;
}

View File

@ -21,6 +21,10 @@ public class ShopStaffAddDTO {
* 店铺权限id集合
*/
private List<Long> shopPermissionIds;
/**
* 页面路径权限
*/
private List<Long> pagePathIdList;
/**
* 员工姓名
*/

View File

@ -19,6 +19,10 @@ public class ShopStaffEditDTO {
* 店铺权限id集合
*/
private List<Long> shopPermissionIds;
/**
* 页面权限
*/
private List<Long> pagePathIdList;
/**
* 角色id
*/

View File

@ -0,0 +1,63 @@
package com.czg.account.entity;
import com.mybatisflex.annotation.Column;
import com.mybatisflex.annotation.Id;
import com.mybatisflex.annotation.KeyType;
import com.mybatisflex.annotation.Table;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.io.Serial;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* 实体类
*
* @author zs
* @since 2025-04-02
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Table("tb_shop_page_path")
public class ShopPagePath implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
@Id(keyType = KeyType.Auto)
private Long id;
/**
* 名称
*/
private String name;
/**
* 页面路径
*/
private String path;
/**
* 备注
*/
private String remark;
/**
* 创建时间
*/
@Column(onInsertValue = "now()")
private LocalDateTime createTime;
/**
* 修改时间
*/
@Column(onInsertValue = "now()", onUpdateValue = "now()")
private LocalDateTime updateTime;
}

View File

@ -0,0 +1,44 @@
package com.czg.account.entity;
import com.mybatisflex.annotation.Id;
import com.mybatisflex.annotation.KeyType;
import com.mybatisflex.annotation.Table;
import java.io.Serializable;
import java.io.Serial;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* 实体类
*
* @author zs
* @since 2025-04-02
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Table("tb_shop_staff_page_permission")
public class ShopStaffPagePermission implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
@Id(keyType = KeyType.Auto)
private Long id;
/**
* 店铺id
*/
@Id
private Long shopId;
private Long staffId;
/**
* 页面路径
*/
private Long pagePathId;
}

View File

@ -10,5 +10,5 @@ import com.czg.account.vo.LoginVO;
public interface AuthorizationService {
Object getCaptcha();
LoginVO login(SysLoginDTO loginDTO);
LoginVO login(SysLoginDTO loginDTO, String platformType);
}

View File

@ -0,0 +1,14 @@
package com.czg.account.service;
import com.mybatisflex.core.service.IService;
import com.czg.account.entity.ShopPagePath;
/**
* 服务层
*
* @author zs
* @since 2025-04-02
*/
public interface ShopPagePathService extends IService<ShopPagePath> {
}

View File

@ -0,0 +1,17 @@
package com.czg.account.service;
import com.czg.account.dto.pagepath.PagePathPermissionAddDTO;
import com.mybatisflex.core.service.IService;
import com.czg.account.entity.ShopStaffPagePermission;
/**
* 服务层
*
* @author zs
* @since 2025-04-02
*/
public interface ShopStaffPagePermissionService extends IService<ShopStaffPagePermission> {
Boolean add(Long shopId, PagePathPermissionAddDTO pagePathPermissionAddDTO);
}

View File

@ -0,0 +1,14 @@
package com.czg.service.account.mapper;
import com.mybatisflex.core.BaseMapper;
import com.czg.account.entity.ShopPagePath;
/**
* 映射层
*
* @author zs
* @since 2025-04-02
*/
public interface ShopPagePathMapper extends BaseMapper<ShopPagePath> {
}

View File

@ -0,0 +1,14 @@
package com.czg.service.account.mapper;
import com.mybatisflex.core.BaseMapper;
import com.czg.account.entity.ShopStaffPagePermission;
/**
* 映射层
*
* @author zs
* @since 2025-04-02
*/
public interface ShopStaffPagePermissionMapper extends BaseMapper<ShopStaffPagePermission> {
}

View File

@ -74,7 +74,7 @@ public class AuthorizationServiceImpl implements AuthorizationService {
}
@Override
public LoginVO login(SysLoginDTO loginDTO) {
public LoginVO login(SysLoginDTO loginDTO, String platType) {
Object code = redisService.get(RedisCst.LOGIN_CODE + loginDTO.uuid());
if (!"666666".equals(loginDTO.code()) && (code == null || !code.equals(loginDTO.code().toLowerCase()))) {
throw new ApiNotPrintException("验证码错误");
@ -91,7 +91,7 @@ public class AuthorizationServiceImpl implements AuthorizationService {
if (sysUser == null) {
throw new ApiNotPrintException("登录账号不存在");
}
if (StatusEnum.DISABLE.value() == sysUser.getStatus()) {
if ("WEB".equals(platType) && StatusEnum.DISABLE.value() == sysUser.getStatus()) {
throw new ApiNotPrintException("账户未启用");
}

View File

@ -0,0 +1,18 @@
package com.czg.service.account.service.impl;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.czg.account.entity.ShopPagePath;
import com.czg.account.service.ShopPagePathService;
import com.czg.service.account.mapper.ShopPagePathMapper;
import org.springframework.stereotype.Service;
/**
* 服务层实现
*
* @author zs
* @since 2025-04-02
*/
@Service
public class ShopPagePathServiceImpl extends ServiceImpl<ShopPagePathMapper, ShopPagePath> implements ShopPagePathService{
}

View File

@ -0,0 +1,61 @@
package com.czg.service.account.service.impl;
import com.czg.account.dto.pagepath.PagePathPermissionAddDTO;
import com.czg.account.entity.ShopPagePath;
import com.czg.account.entity.ShopStaff;
import com.czg.account.service.ShopPagePathService;
import com.czg.exception.ApiNotPrintException;
import com.czg.service.account.mapper.ShopStaffMapper;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.czg.account.entity.ShopStaffPagePermission;
import com.czg.account.service.ShopStaffPagePermissionService;
import com.czg.service.account.mapper.ShopStaffPagePermissionMapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
/**
* 服务层实现
*
* @author zs
* @since 2025-04-02
*/
@Service
public class ShopStaffPagePermissionServiceImpl extends ServiceImpl<ShopStaffPagePermissionMapper, ShopStaffPagePermission> implements ShopStaffPagePermissionService{
@Resource
private ShopPagePathService shopPagePathService;
@Resource
private ShopStaffMapper shopStaffMapper;
@Override
@Transactional(rollbackFor = Exception.class)
public Boolean add(Long shopId, PagePathPermissionAddDTO pagePathPermissionAddDTO) {
ShopStaff shopStaff = shopStaffMapper.selectOneByQuery(new QueryWrapper().eq(ShopStaff::getId, pagePathPermissionAddDTO.getStaffId()).eq(ShopStaff::getShopId, shopId));
if (shopStaff == null) {
throw new ApiNotPrintException("员工不存在");
}
long count = shopPagePathService.count(new QueryWrapper().in(ShopPagePath::getId, pagePathPermissionAddDTO.getPagePathIdList()));
if (count != pagePathPermissionAddDTO.getPagePathIdList().size()) {
throw new ApiNotPrintException("存在错误id");
}
ArrayList<ShopStaffPagePermission> pagePermissions = new ArrayList<>();
remove(new QueryWrapper().eq(ShopStaffPagePermission::getStaffId, pagePathPermissionAddDTO.getStaffId()));
pagePathPermissionAddDTO.getPagePathIdList().forEach(item -> {
long count1 = count(new QueryWrapper().eq(ShopStaffPagePermission::getStaffId, shopStaff).eq(ShopStaffPagePermission::getPagePathId, item));
if (count1 > 0) {
return;
}
ShopStaffPagePermission permission = new ShopStaffPagePermission();
permission.setShopId(shopId);
permission.setPagePathId(item);
permission.setStaffId(pagePathPermissionAddDTO.getStaffId());
pagePermissions.add(permission);
});
return saveBatch(pagePermissions);
}
}

View File

@ -2,6 +2,7 @@ package com.czg.service.account.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import com.czg.account.dto.pagepath.PagePathPermissionAddDTO;
import com.czg.account.dto.staff.ShopStaffAddDTO;
import com.czg.account.dto.staff.ShopStaffEditDTO;
import com.czg.account.dto.staff.ShopStaffRemoveDTO;
@ -39,6 +40,8 @@ public class ShopStaffServiceImpl extends ServiceImpl<ShopStaffMapper, ShopStaff
private ShopPermissionService shopPermissionService;
@Resource
private ShopStaffPermissionService shopStaffPermissionService;
@Resource
private ShopStaffPagePermissionService pagePermissionService;
@Override
@Transactional(rollbackFor = Exception.class)
@ -54,6 +57,13 @@ public class ShopStaffServiceImpl extends ServiceImpl<ShopStaffMapper, ShopStaff
if (shopStaffAddDTO.getShopPermissionIds() != null && !shopStaffAddDTO.getShopPermissionIds().isEmpty()) {
addPermission(shopStaff, shopStaffAddDTO.getShopPermissionIds());
}
if (shopStaffAddDTO.getPagePathIdList() != null && !shopStaffAddDTO.getPagePathIdList().isEmpty()) {
PagePathPermissionAddDTO pagePathPermissionAddDTO = new PagePathPermissionAddDTO();
pagePathPermissionAddDTO.setPagePathIdList(shopStaffAddDTO.getPagePathIdList());
pagePathPermissionAddDTO.setStaffId(shopStaff.getId());
pagePermissionService.add(StpKit.USER.getShopId(), pagePathPermissionAddDTO);
}
return true;
}
@ -98,6 +108,13 @@ public class ShopStaffServiceImpl extends ServiceImpl<ShopStaffMapper, ShopStaff
// 权限添加
addPermission(shopStaff, shopStaffEditDTO.getShopPermissionIds());
}
if (shopStaffEditDTO.getPagePathIdList() != null && !shopStaffEditDTO.getPagePathIdList().isEmpty()) {
PagePathPermissionAddDTO pagePathPermissionAddDTO = new PagePathPermissionAddDTO();
pagePathPermissionAddDTO.setPagePathIdList(shopStaffEditDTO.getPagePathIdList());
pagePathPermissionAddDTO.setStaffId(shopStaff.getId());
pagePermissionService.add(StpKit.USER.getShopId(), pagePathPermissionAddDTO);
}
return true;
}

View File

@ -133,7 +133,7 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> imp
if (b) {
sysRolesMenusService.updateChain().eq(SysRolesMenus::getRoleId, role.getId()).remove();
return addMenu(role.getId(), roleEditDTO.getMenuIdList());
}
}
throw new ApiNotPrintException("保存失败");
}
}

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.czg.service.account.mapper.ShopPagePathMapper">
</mapper>

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.czg.service.account.mapper.ShopStaffPagePermissionMapper">
</mapper>

View File

@ -56,29 +56,54 @@
</select>
<select id="selectPageByKeyAndIsVip" resultType="com.czg.account.dto.shopuser.ShopUserDTO">
SELECT
a.*, COUNT(DISTINCT c.id) AS couponNum,
COUNT(DISTINCT d.id) AS orderNumber,
IFNULL(SUM(DISTINCT f.amount), 0) AS rechargeAmount
FROM
tb_shop_user a
a.*,
IFNULL(c.couponNum, 0) AS couponNum,
IFNULL(d.orderNumber, 0) AS orderNumber,
IFNULL(f.rechargeAmount, 0) AS rechargeAmount
FROM tb_shop_user a
LEFT JOIN tb_user_info b ON b.id = a.user_id
left join tb_shop_activate_coupon_record c on c.shop_user_id=a.id and c.`status`=0 and c.use_start_time &lt; now() and c.use_end_time > now()
left join tb_order_info as d on d.user_id=a.user_id and d.shop_id=a.shop_id
left join tb_shop_user_flow as f on f.user_id=a.user_id and f.shop_id=a.shop_id and f.biz_code in ('cashIn', 'wechatIn', 'alipayIn')
where a.shop_id=#{shopId}
-- 预计算优惠券数量
LEFT JOIN (
SELECT shop_user_id, COUNT(*) AS couponNum
FROM tb_shop_activate_coupon_record
WHERE status = 0
AND use_start_time &lt; NOW()
AND use_end_time > NOW()
GROUP BY shop_user_id
) c ON c.shop_user_id = a.id
-- 预计算订单数量
LEFT JOIN (
SELECT user_id, shop_id, COUNT(*) AS orderNumber
FROM tb_order_info
GROUP BY user_id, shop_id
) d ON d.user_id = a.user_id AND d.shop_id = a.shop_id
-- 预计算充值总金额
LEFT JOIN (
SELECT user_id, shop_id, SUM(amount) AS rechargeAmount
FROM tb_shop_user_flow
WHERE biz_code IN ('cashIn', 'wechatIn', 'alipayIn')
GROUP BY user_id, shop_id
) f ON f.user_id = a.user_id AND f.shop_id = a.shop_id
WHERE a.shop_id = #{shopId}
<if test="isVip != null">
and a.is_vip=#{isVip}
AND a.is_vip = #{isVip}
</if>
<if test="key != null and key != ''">
and (a.nick_name like concat('%', #{key}, '%') or a.phone like concat('%', #{key}, '%'))
AND (a.nick_name LIKE CONCAT('%', #{key}, '%')
OR a.phone LIKE CONCAT('%', #{key}, '%'))
</if>
<if test="amount != null">
and a.amount >= #{amount}
AND a.amount >= #{amount}
</if>
GROUP BY a.id
order by a.create_time desc
ORDER BY a.create_time DESC
</select>
<select id="selectVipCard_COUNT" resultType="java.lang.Long">
select count(1)

View File

@ -1,7 +1,8 @@
package com.czg.service.order.service.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.czg.order.entity.ShopOrderStatistic;
import com.czg.order.param.DataSummaryTradeParam;
import com.czg.order.service.DataSummaryService;
@ -11,11 +12,9 @@ import com.mybatisflex.spring.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Stream;
/**
* 服务层实现
@ -31,52 +30,27 @@ public class ShopOrderStatisticServiceImpl extends ServiceImpl<ShopOrderStatisti
@Override
public void statistic() {
// 获取前一天
DateTime yesterday = DateUtil.yesterday();
// 获取前一天的开始时间00:00:00
DateTime startOfDay = DateUtil.beginOfDay(yesterday);
// 获取前一天的结束时间23:59:59
DateTime endOfDay = DateUtil.endOfDay(yesterday);
List<Long> shopIdList = dataSummaryService.getShopIdList();
if (CollUtil.isEmpty(shopIdList)) {
return;
}
LocalDate startDate = LocalDate.of(2024, 3, 12);
LocalDate endDate = LocalDate.of(2025, 3, 25);
// 生成日期流
Stream<LocalDate> dateStream = startDate.datesUntil(endDate);
// 遍历日期流
dateStream.forEach(date -> {
String cur = date.toString();
String a = cur + " 00:00:00";
String b = cur + " 23:59:59";
shopIdList.parallelStream().forEach(shopId -> {
DataSummaryTradeParam param = new DataSummaryTradeParam();
param.setShopId(shopId);
param.setBeginDate(a);
param.setEndDate(b);
ShopOrderStatistic statistic = dataSummaryService.getTradeData(param);
if (NumberUtil.isGreater(statistic.getSaleAmount(), BigDecimal.ZERO)) {
statistic.setShopId(shopId);
statistic.setCreateDay(LocalDate.now());
statistic.setUpdateTime(LocalDateTime.now());
saveOrUpdate(statistic);
}
});
});
}
public static void main(String[] args) {
LocalDate startDate = LocalDate.of(2024, 3, 12);
LocalDate endDate = LocalDate.of(2025, 3, 25);
// 生成日期流
Stream<LocalDate> dateStream = startDate.datesUntil(endDate);
// 遍历日期流
dateStream.forEach(date -> {
String cur = date.toString();
String a = cur + "00:00:00";
String b = cur + "23:59:59";
System.out.println(date.toString());
shopIdList.parallelStream().forEach(shopId -> {
DataSummaryTradeParam param = new DataSummaryTradeParam();
param.setShopId(shopId);
param.setBeginDate(startOfDay.toStringDefaultTimeZone());
param.setEndDate(endOfDay.toStringDefaultTimeZone());
ShopOrderStatistic statistic = dataSummaryService.getTradeData(param);
statistic.setShopId(shopId);
statistic.setCreateDay(LocalDate.now());
statistic.setUpdateTime(LocalDateTime.now());
saveOrUpdate(statistic);
});
}
}