diff --git a/hiver-modules/hiver-base/src/main/java/cc/hiver/base/controller/manage/AuthController.java b/hiver-modules/hiver-base/src/main/java/cc/hiver/base/controller/manage/AuthController.java
index a7bcba19..f1bcf7eb 100644
--- a/hiver-modules/hiver-base/src/main/java/cc/hiver/base/controller/manage/AuthController.java
+++ b/hiver-modules/hiver-base/src/main/java/cc/hiver/base/controller/manage/AuthController.java
@@ -18,25 +18,28 @@ import cc.hiver.core.config.properties.HiverTokenProperties;
import cc.hiver.core.entity.Role;
import cc.hiver.core.entity.User;
import cc.hiver.core.entity.UserRole;
+import cc.hiver.core.entity.Worker;
import cc.hiver.core.service.RoleService;
import cc.hiver.core.service.UserRoleService;
import cc.hiver.core.service.UserService;
-import cc.hiver.mall.debt.service.DebtService;
+import cc.hiver.core.service.WorkerService;
import cc.hiver.mall.entity.Shop;
import cc.hiver.mall.entity.ShopTakeaway;
import cc.hiver.mall.entity.ShopUser;
+import cc.hiver.mall.entity.WorkerRelaPrice;
import cc.hiver.mall.invitelog.constant.InviteLogConstant;
import cc.hiver.mall.invitelog.entity.InviteLog;
import cc.hiver.mall.invitelog.service.InviteLogService;
+import cc.hiver.mall.pojo.vo.WorkerRedisVo;
import cc.hiver.mall.service.ShopService;
import cc.hiver.mall.service.ShopTakeawayService;
import cc.hiver.mall.service.ShopUserService;
-import cc.hiver.mall.service.SupplierService;
-import cc.hiver.mall.service.mybatis.CustomerService;
-import cc.hiver.mall.service.mybatis.DealingsRecordService;
import cc.hiver.mall.service.mybatis.ProductCategoryService;
+import cc.hiver.mall.service.mybatis.WorkerRelaPriceService;
+import cc.hiver.mall.utils.WorkerRedisCacheUtil;
import cn.hutool.core.text.CharSequenceUtil;
import cn.hutool.core.util.IdUtil;
+import cn.hutool.core.util.StrUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
@@ -52,10 +55,7 @@ import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
import java.util.concurrent.TimeUnit;
/**
@@ -109,24 +109,21 @@ public class AuthController {
private ShopUserService shopUserService;
@Autowired
- private ProductCategoryService productCategoryService;
- @PersistenceContext
- private EntityManager entityManager;
-
- @Autowired
- private InviteLogService inviteLogService;
+ private WorkerService workerService;
@Autowired
- private SupplierService supplierService;
+ private WorkerRelaPriceService workerRelaPriceService;
@Autowired
- private CustomerService customerService;
+ private ProductCategoryService productCategoryService;
+ @PersistenceContext
+ private EntityManager entityManager;
@Autowired
- private DebtService debtService;
+ private InviteLogService inviteLogService;
@Autowired
- private DealingsRecordService dealingsRecordService;
+ WorkerRedisCacheUtil workerRedisCacheUtil;
@RequestMapping(value = "/login", method = RequestMethod.POST)
@SystemLog(description = "账号登录", type = LogType.LOGIN)
@@ -177,31 +174,73 @@ public class AuthController {
// 返回当前登录人的信息
result.put("user", user);
- // 店铺登录的话,根据登录人查询所有关联的店铺(店铺启用,并且在有效期内)
- if (UserConstant.USER_TYPE_NORMAL.equals(type)) {
- // 获取
- final List
shopUsers = shopUserService.selectByUserId(user.getId());
- if (shopUsers != null && !shopUsers.isEmpty()) {
- // 获取店主手机号
- for (ShopUser shopUser : shopUsers) {
- final Shop shop = shopService.findById(shopUser.getShop().getId());
- if (shop != null && shop.getShopOwnerId() != null && StringUtils.isNotEmpty(shop.getShopOwnerId())) {
- shop.setClientId(clientId);
- shopService.update(shop);
- shopService.refreshShopCache(shop.getId(), shop.getRegionId());
- final User shopOwner = userService.findById(shop.getShopOwnerId());
- if(shopOwner != null){
- shopUser.setShopOwnerName(shopOwner.getNickname());
- shopUser.setShopOwnerPhone(shopOwner.getMobile());
+ List shop = shopService.getShopByUserid(user.getId());
+ if(!shop.isEmpty()){
+ List shopIds = new ArrayList<>();
+ for (Shop item : shop) {
+ shopIds.add(item.getId());
+ if (StringUtils.isNotEmpty(clientId)) {
+ item.setClientId(clientId);
+ shopService.update(item);
+ shopService.refreshShopCache(item.getId(), item.getRegionId());
+ }
+ }
+ if(!shopIds.isEmpty()){
+ List shopTakeaway = shopTakeawayService.selectListByshopId(shopIds);
+ if(shopTakeaway != null){
+ shop.forEach(e -> {
+ for(ShopTakeaway shopTakeawa : shopTakeaway) {
+ if (e.getId().equals(shopTakeawa.getShopId())) {
+ e.setShopTakeaway(shopTakeawa);
+ }
}
-
+ });
+ }
+ }
+ result.put("shop", shop);
+ }
+ Worker worker = workerService.findByUserId(user.getId());
+ //更新配送员 推送id
+ if(worker!= null){
+ worker.setClientId(clientId);
+ workerService.update(worker);
+ String oldRegion = worker.getRegion();
+ WorkerRedisVo workerRedisVo = StrUtil.isNotBlank(oldRegion) ? workerRedisCacheUtil.get(oldRegion, worker.getWorkerId()) : null;
+ if(workerRedisVo != null){
+ workerRedisVo.setWorker(worker);
+ if (Objects.equals(oldRegion, worker.getRegion())) {
+ workerRedisCacheUtil.update(worker.getRegion(), workerRedisVo);
+ } else {
+ workerRedisCacheUtil.remove(oldRegion, worker.getWorkerId());
+ if (StrUtil.isNotBlank(worker.getRegion())) {
+ workerRedisCacheUtil.put(worker.getRegion(), workerRedisVo);
}
}
- result.put("shopList", shopUsers);
- } else {
- return ResultUtil.error("店铺未开通!");
}
}
+ if(worker!= null && worker.getGetPushOrder() != null && worker.getGetPushOrder() == 1){
+ final List workerRelaPriceList = workerRelaPriceService.selectByWorkerId(worker.getWorkerId());
+ List workerRelaPriceListWaimai = new ArrayList<>();
+ List workerRelaPriceListKuaidi = new ArrayList<>();
+ if(workerRelaPriceList != null && workerRelaPriceList.size() > 0){
+ workerRelaPriceList.forEach(workerRelaPrice -> {
+ if(workerRelaPrice.getGetPushOrder() == 1){
+ if(workerRelaPrice.getOrderType() == 0 ){
+ workerRelaPriceListWaimai.add(workerRelaPrice);
+ }else{
+ workerRelaPriceListKuaidi.add(workerRelaPrice);
+ }
+ }
+ });
+ }
+ if(workerRelaPriceListWaimai.size() > 0){
+ result.put("waimaiData", workerRelaPriceListWaimai);
+ }
+ if(workerRelaPriceListKuaidi.size() > 0){
+ result.put("kuaidiData", workerRelaPriceListKuaidi);
+ }
+ }
+ result.put("worker", worker);
return ResultUtil.data(result);
}
diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/billing/entity/BillingUsageRecord.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/billing/entity/BillingUsageRecord.java
new file mode 100644
index 00000000..c576a3d1
--- /dev/null
+++ b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/billing/entity/BillingUsageRecord.java
@@ -0,0 +1,32 @@
+package cc.hiver.mall.billing.entity;
+
+import cc.hiver.core.common.utils.SnowFlakeUtil;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Data;
+
+import java.time.LocalDate;
+import java.util.Date;
+
+@Data
+@TableName("billing_usage_record")
+public class BillingUsageRecord {
+
+ @TableId
+ private String id = SnowFlakeUtil.nextId().toString();
+
+ private String recordType;
+ private String regionId;
+ private LocalDate billingDate;
+ private Date occurTime;
+ private String provider;
+ private String usageType;
+ private String bizType;
+ private String bizId;
+ private String userId;
+ private String receiveMobile;
+ private String resultStatus;
+ private String requestId;
+ private String detail;
+ private Date createTime;
+}
diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/billing/mapper/BillingUsageRecordMapper.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/billing/mapper/BillingUsageRecordMapper.java
new file mode 100644
index 00000000..af18950a
--- /dev/null
+++ b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/billing/mapper/BillingUsageRecordMapper.java
@@ -0,0 +1,9 @@
+package cc.hiver.mall.billing.mapper;
+
+import cc.hiver.mall.billing.entity.BillingUsageRecord;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.springframework.stereotype.Repository;
+
+@Repository
+public interface BillingUsageRecordMapper extends BaseMapper {
+}
diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/billing/mq/BillingRecordConsumer.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/billing/mq/BillingRecordConsumer.java
new file mode 100644
index 00000000..21b56f86
--- /dev/null
+++ b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/billing/mq/BillingRecordConsumer.java
@@ -0,0 +1,50 @@
+package cc.hiver.mall.billing.mq;
+
+import cc.hiver.mall.billing.entity.BillingUsageRecord;
+import cc.hiver.mall.billing.mapper.BillingUsageRecordMapper;
+import com.alibaba.fastjson.JSON;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.amqp.rabbit.annotation.RabbitListener;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.time.ZoneId;
+import java.util.Date;
+
+@Slf4j
+@Component
+public class BillingRecordConsumer {
+
+ @Autowired
+ private BillingUsageRecordMapper billingUsageRecordMapper;
+
+ @RabbitListener(queues = BillingRecordMqConfig.BILLING_RECORD_QUEUE)
+ public void handleBillingRecord(String messageBody) {
+ try {
+ BillingRecordEvent event = JSON.parseObject(messageBody, BillingRecordEvent.class);
+ if (event == null || event.getRecordType() == null) {
+ log.warn("计费记录MQ消息为空或缺少类型,body={}", messageBody);
+ return;
+ }
+ Date occurTime = event.getOccurTime() == null ? new Date() : event.getOccurTime();
+ BillingUsageRecord record = new BillingUsageRecord();
+ record.setRecordType(event.getRecordType());
+ record.setRegionId(event.getRegionId());
+ record.setBillingDate(occurTime.toInstant().atZone(ZoneId.systemDefault()).toLocalDate());
+ record.setOccurTime(occurTime);
+ record.setProvider(event.getProvider());
+ record.setUsageType(event.getUsageType());
+ record.setBizType(event.getBizType());
+ record.setBizId(event.getBizId());
+ record.setUserId(event.getUserId());
+ record.setReceiveMobile(event.getReceiveMobile());
+ record.setResultStatus(event.getResultStatus());
+ record.setRequestId(event.getRequestId());
+ record.setDetail(event.getDetail());
+ record.setCreateTime(new Date());
+ billingUsageRecordMapper.insert(record);
+ } catch (Exception e) {
+ log.error("计费记录MQ处理失败,body={}", messageBody, e);
+ }
+ }
+}
diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/billing/mq/BillingRecordEvent.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/billing/mq/BillingRecordEvent.java
new file mode 100644
index 00000000..c6704885
--- /dev/null
+++ b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/billing/mq/BillingRecordEvent.java
@@ -0,0 +1,26 @@
+package cc.hiver.mall.billing.mq;
+
+import lombok.Data;
+
+import java.util.Date;
+
+@Data
+public class BillingRecordEvent {
+
+ public static final String TYPE_SMS = "sms";
+ public static final String TYPE_CONTENT_AUDIT = "content_audit";
+ public static final String TYPE_REAL_NAME_AUTH = "real_name_auth";
+
+ private String recordType;
+ private String regionId;
+ private Date occurTime;
+ private String provider;
+ private String usageType;
+ private String bizType;
+ private String bizId;
+ private String userId;
+ private String receiveMobile;
+ private String resultStatus;
+ private String requestId;
+ private String detail;
+}
diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/billing/mq/BillingRecordMqConfig.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/billing/mq/BillingRecordMqConfig.java
new file mode 100644
index 00000000..8b058b36
--- /dev/null
+++ b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/billing/mq/BillingRecordMqConfig.java
@@ -0,0 +1,31 @@
+package cc.hiver.mall.billing.mq;
+
+import org.springframework.amqp.core.Binding;
+import org.springframework.amqp.core.BindingBuilder;
+import org.springframework.amqp.core.DirectExchange;
+import org.springframework.amqp.core.Queue;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+public class BillingRecordMqConfig {
+
+ public static final String BILLING_RECORD_EXCHANGE = "billing.record.direct.exchange";
+ public static final String BILLING_RECORD_QUEUE = "billing.record.queue";
+ public static final String BILLING_RECORD_ROUTING = "billing.record.routing";
+
+ @Bean
+ public DirectExchange billingRecordExchange() {
+ return new DirectExchange(BILLING_RECORD_EXCHANGE, true, false);
+ }
+
+ @Bean
+ public Queue billingRecordQueue() {
+ return new Queue(BILLING_RECORD_QUEUE, true);
+ }
+
+ @Bean
+ public Binding bindingBillingRecordQueue() {
+ return BindingBuilder.bind(billingRecordQueue()).to(billingRecordExchange()).with(BILLING_RECORD_ROUTING);
+ }
+}
diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/billing/mq/BillingRecordProducer.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/billing/mq/BillingRecordProducer.java
new file mode 100644
index 00000000..5050588d
--- /dev/null
+++ b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/billing/mq/BillingRecordProducer.java
@@ -0,0 +1,79 @@
+package cc.hiver.mall.billing.mq;
+
+import cn.hutool.core.text.CharSequenceUtil;
+import com.alibaba.fastjson.JSON;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.amqp.rabbit.core.RabbitTemplate;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.Date;
+
+@Slf4j
+@Component
+public class BillingRecordProducer {
+
+ private static final int DETAIL_MAX_LENGTH = 500;
+
+ @Autowired
+ private RabbitTemplate rabbitTemplate;
+
+ public void recordSms(String regionId, String smsType, String receiveMobile, String bizType, String bizId) {
+ BillingRecordEvent event = baseEvent(BillingRecordEvent.TYPE_SMS, regionId, "sms", smsType, bizType, bizId, null);
+ event.setReceiveMobile(receiveMobile);
+ event.setResultStatus("sent");
+ send(event);
+ }
+
+ public void recordContentAudit(String regionId, String auditType, String bizType, String bizId,
+ String userId, String resultStatus, String requestId, String detail) {
+ BillingRecordEvent event = baseEvent(BillingRecordEvent.TYPE_CONTENT_AUDIT, regionId, "aliyun", auditType, bizType, bizId, userId);
+ event.setResultStatus(resultStatus);
+ event.setRequestId(requestId);
+ event.setDetail(limit(detail));
+ send(event);
+ }
+
+ public void recordRealNameAuth(String regionId, String userId, String resultStatus, String requestId, String detail) {
+ BillingRecordEvent event = baseEvent(BillingRecordEvent.TYPE_REAL_NAME_AUTH, regionId,
+ "aliyun_three_element", "three_element", "ie_real_name_auth", null, userId);
+ event.setResultStatus(resultStatus);
+ event.setRequestId(requestId);
+ event.setDetail(limit(detail));
+ send(event);
+ }
+
+ private BillingRecordEvent baseEvent(String recordType, String regionId, String provider,
+ String usageType, String bizType, String bizId, String userId) {
+ BillingRecordEvent event = new BillingRecordEvent();
+ event.setRecordType(recordType);
+ event.setRegionId(regionId);
+ event.setOccurTime(new Date());
+ event.setProvider(provider);
+ event.setUsageType(usageType);
+ event.setBizType(bizType);
+ event.setBizId(bizId);
+ event.setUserId(userId);
+ return event;
+ }
+
+ private void send(BillingRecordEvent event) {
+ if (event == null) {
+ return;
+ }
+ try {
+ rabbitTemplate.convertAndSend(BillingRecordMqConfig.BILLING_RECORD_EXCHANGE,
+ BillingRecordMqConfig.BILLING_RECORD_ROUTING, JSON.toJSONString(event));
+ } catch (Exception e) {
+ log.warn("计费记录MQ发送失败,不影响主流程 recordType={}, regionId={}, usageType={}",
+ event.getRecordType(), event.getRegionId(), event.getUsageType(), e);
+ }
+ }
+
+ private String limit(String value) {
+ if (CharSequenceUtil.isBlank(value) || value.length() <= DETAIL_MAX_LENGTH) {
+ return value;
+ }
+ return value.substring(0, DETAIL_MAX_LENGTH);
+ }
+}
diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/AdminBillingUsageController.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/AdminBillingUsageController.java
new file mode 100644
index 00000000..fbcf9fe3
--- /dev/null
+++ b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/AdminBillingUsageController.java
@@ -0,0 +1,150 @@
+package cc.hiver.mall.controller;
+
+import cc.hiver.core.common.utils.ResultUtil;
+import cc.hiver.core.common.vo.Result;
+import cc.hiver.mall.billing.entity.BillingUsageRecord;
+import cc.hiver.mall.billing.mapper.BillingUsageRecordMapper;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiModelProperty;
+import io.swagger.annotations.ApiOperation;
+import lombok.Data;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.time.LocalDate;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+@RestController
+@Api(tags = "后台管理系统第三方计费用量接口")
+@RequestMapping("/hiver/mall/admin/billingUsage")
+public class AdminBillingUsageController {
+
+ @Autowired
+ private BillingUsageRecordMapper billingUsageRecordMapper;
+
+ @Data
+ public static class BillingUsageQuery {
+ @ApiModelProperty(value = "校区/学校ID")
+ private String regionId;
+ @ApiModelProperty(value = "记录类型:sms/content_audit/real_name_auth")
+ private String recordType;
+ @ApiModelProperty(value = "调用类型:短信模板、text/image/video_submit等")
+ private String usageType;
+ @ApiModelProperty(value = "开始日期,格式yyyy-MM-dd")
+ private String startDate;
+ @ApiModelProperty(value = "结束日期,格式yyyy-MM-dd")
+ private String endDate;
+ @ApiModelProperty(value = "页码")
+ private int pageNumber = 1;
+ @ApiModelProperty(value = "每页条数")
+ private int pageSize = 10;
+ }
+
+ @Data
+ public static class BillingUsageSummaryVo {
+ @ApiModelProperty(value = "校区/学校ID")
+ private String regionId;
+ @ApiModelProperty(value = "计费日期")
+ private LocalDate billingDate;
+ @ApiModelProperty(value = "记录类型")
+ private String recordType;
+ @ApiModelProperty(value = "调用类型")
+ private String usageType;
+ @ApiModelProperty(value = "用量次数")
+ private Long usageCount;
+ }
+
+ @PostMapping("/summaryList")
+ @ApiOperation(value = "按校区/日期/类型查询第三方计费用量汇总")
+ public Result> summaryList(@RequestBody BillingUsageQuery query) {
+ QueryWrapper wrapper = new QueryWrapper<>();
+ wrapper.select("region_id", "billing_date", "record_type", "usage_type", "count(1) as usage_count");
+ applyMapConditions(wrapper, query);
+ wrapper.groupBy("region_id", "billing_date", "record_type", "usage_type");
+ wrapper.orderByDesc("billing_date").orderByAsc("region_id", "record_type", "usage_type");
+ Page