/api/v2/alloc/canteen/list-avail-pay-type--查询食堂所有开启的支付方式

This commit is contained in:
tqzhang 2025-02-06 10:39:43 +08:00
parent 468591a2f1
commit c5914155ad
10 changed files with 588 additions and 0 deletions

View File

@ -9,4 +9,6 @@ import java.util.List;
public interface AllocMetadataService {
List<AllocMetadata> listPayMetadataByType(MetadataModelTypeEnum modelType, Long canteenId, Long stallId);
List<AllocMetadata> listPayMetadataCacheable(MetadataModelTypeEnum modelTypeEnum);
}

View File

@ -30,6 +30,7 @@ public class AllocMetadataServiceImpl extends ServiceImpl<AllocPayMetadataMapper
@Resource
private AllocStallApi allocStallApi;
@Override
public List<AllocMetadata> listPayMetadataCacheable(MetadataModelTypeEnum modelTypeEnum) {
return this.listPayMetadataCacheable(modelTypeEnum.getKey());
}

View File

@ -0,0 +1,27 @@
package com.bonus.core.allocation.api;
import cn.hutool.core.util.StrUtil;
import com.bonus.core.common.enums.MetadataModelTypeEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;
@Component
public class AllocPayMetadataApi {
private static final Logger log = LoggerFactory.getLogger(AllocPayMetadataApi.class);
@Resource
@Lazy
private GlobalMetadataApi globalMetadataApi;
public List<Integer> supportPayChannels(Long canteenId) {
String supportChannels = this.globalMetadataApi.getAvailableValue(MetadataModelTypeEnum.PAY, "payTypes", canteenId, (Long)null);
log.info("【支付配置】当前配置支持支付方式:{}", supportChannels);
return (List) StrUtil.splitTrim(supportChannels, ",").stream().filter(Objects::nonNull).map(Integer::valueOf).collect(Collectors.toList());
}
}

View File

@ -1,17 +1,25 @@
package com.bonus.core.allocation.api;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.bonus.constant.LeConstants;
import com.bonus.core.allocation.alloc.model.AllocMetadata;
import com.bonus.core.allocation.alloc.service.AllocMetadataService;
import com.bonus.core.allocation.canteen.model.AllocStall;
import com.bonus.core.allocation.util.MetadataUtil;
import com.bonus.core.common.enums.MetadataModelTypeEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
@Component
public class GlobalMetadataApi {
@ -20,6 +28,10 @@ public class GlobalMetadataApi {
@Lazy
private AllocMetadataService allocMetadataService;
@Resource
@Lazy
private AllocStallApi allocStallApi;
public <T> T getModel(MetadataModelTypeEnum modelTypeEnum, T t, Long canteenId, Long stallId) {
List<AllocMetadata> metadataList = this.getList(modelTypeEnum, canteenId, stallId);
return MetadataUtil.transferToPayModel(metadataList, t);
@ -30,4 +42,77 @@ public class GlobalMetadataApi {
Long finalStallId = ObjectUtil.equal(stallId, -1) ? null : stallId;
return this.allocMetadataService.listPayMetadataByType(modelTypeEnum, finalCanteenId, finalStallId);
}
public String getAvailableValue(MetadataModelTypeEnum modelTypeEnum, String modelKey, Long canteenId, Long stallId) {
return this.getAvailableValue(modelTypeEnum, modelKey, "", canteenId, stallId);
}
public String getAvailableValue(MetadataModelTypeEnum modelTypeEnum, String modelKey, String defaultValue, Long canteenId, Long stallId) {
List<AllocMetadata> metadataList = this.getAvailableList(modelTypeEnum, canteenId, stallId);
return (String)metadataList.stream().filter((s) -> {
return StrUtil.equals(s.getModelKey(), modelKey);
}).map(AllocMetadata::getModelValue).filter(Objects::nonNull).findFirst().orElse(defaultValue);
}
public List<AllocMetadata> getAvailableList(MetadataModelTypeEnum modelTypeEnum, Long canteenId, Long stallId) {
if (ObjectUtil.isNotNull(stallId) && ObjectUtil.isNull(canteenId)) {
AllocStall stall = this.allocStallApi.getAllocStall(stallId);
if (!ObjectUtil.isNull(stall) && !ObjectUtil.isNull(stall.getCanteenId())) {
canteenId = stall.getCanteenId();
} else {
log.warn("【配置项】未查到档口关联食堂:{},{},{}", new Object[]{modelTypeEnum, canteenId, stallId});
}
}
Long finalCanteenId = ObjectUtil.equal(canteenId, -1) ? null : canteenId;
Long finalStallId = ObjectUtil.equal(stallId, -1) ? null : stallId;
if (!modelTypeEnum.supportSeparated() || finalCanteenId == null && finalStallId == null) {
log.info("[配置]查询返回商户层配置信息");
return this.allocMetadataService.listPayMetadataByType(modelTypeEnum, finalCanteenId, finalStallId);
} else {
List<AllocMetadata> metadataList = (List)this.allocMetadataService.listPayMetadataCacheable(modelTypeEnum).stream().filter((s) -> {
return LeConstants.COMMON_YES.equals(s.getIfActive());
}).collect(Collectors.toList());
List<AllocMetadata> stallList = CollUtil.newArrayList(new AllocMetadata[0]);
List<AllocMetadata> canteenList = CollUtil.newArrayList(new AllocMetadata[0]);
List<AllocMetadata> merchantList = CollUtil.newArrayList(new AllocMetadata[0]);
Iterator var11 = metadataList.iterator();
while(var11.hasNext()) {
AllocMetadata metadata = (AllocMetadata)var11.next();
if (metadata.getStallId() != null) {
stallList.add(metadata);
} else if (metadata.getCanteenId() != null) {
canteenList.add(metadata);
} else {
merchantList.add(metadata);
}
}
List result;
if (finalStallId != null && CollUtil.isNotEmpty(stallList)) {
log.warn("[配置]返回档口层配置信息,canteenId:{}, stallId:{}", canteenId, stallId);
result = (List)stallList.stream().filter((s) -> {
return ObjectUtil.equal(s.getStallId(), finalStallId);
}).collect(Collectors.toList());
if (CollUtil.isNotEmpty(result)) {
return result;
}
}
if (finalCanteenId != null) {
log.warn("[配置]返回食堂层配置信息,canteenId:{}, stallId:{}", canteenId, stallId);
result = (List)canteenList.stream().filter((s) -> {
return ObjectUtil.equal(s.getCanteenId(), finalCanteenId);
}).collect(Collectors.toList());
if (CollUtil.isNotEmpty(result)) {
return result;
}
}
log.warn("[配置]返回商户层配置信息,canteenId:{}, stallId:{}", canteenId, stallId);
return merchantList;
}
}
}

View File

@ -0,0 +1,45 @@
package com.bonus.core.allocation.canteen.controller;
import cn.hutool.core.lang.tree.Tree;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.core.allocation.canteen.model.AllocCanteen;
import com.bonus.core.allocation.canteen.service.AllocCanteenService;
import com.bonus.core.allocation.canteen.service.AllocStallService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
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 javax.annotation.Resource;
import javax.validation.Valid;
import java.time.LocalDate;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping({"/api/v2/alloc/canteen"})
@Api(
tags = {"lsh_食堂档口相关控制器"}
)
public class AllocCanteenController {
private static final Logger log = LoggerFactory.getLogger(AllocCanteenController.class);
@Resource
@Lazy
private AllocCanteenService allocCanteenService;
@ApiOperation("查询食堂所有开启的支付方式")
@PostMapping({"/list-avail-pay-type"})
public AjaxResult listAvailPayTypeForApp(@RequestBody AllocCanteen bean) {
if (bean.getCanteenId() == null) {
return AjaxResult.error("食堂ID不能为空");
}
return AjaxResult.success(this.allocCanteenService.listAvailPayTypeForApp(bean.getCanteenId()));
}
}

View File

@ -0,0 +1,10 @@
package com.bonus.core.allocation.canteen.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.bonus.core.allocation.canteen.model.AllocCanteen;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface AllocCanteenMapper extends BaseMapper<AllocCanteen> {
}

View File

@ -0,0 +1,4 @@
<?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.bonus.core.allocation.canteen.mapper.AllocCanteenMapper">
</mapper>

View File

@ -0,0 +1,349 @@
package com.bonus.core.allocation.canteen.model;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.bonus.core.common.utils.SysUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.time.LocalDateTime;
import java.time.LocalTime;
@TableName("alloc_canteen")
@ApiModel("食堂信息表")
public class AllocCanteen {
@TableId
@ApiModelProperty("主键id")
private Long id;
@ApiModelProperty("食堂id")
private Long canteenId;
@ApiModelProperty("食堂编号")
private String canteenNum;
@ApiModelProperty("食堂名称")
private String canteenName;
@ApiModelProperty("区域id")
private Long areaId;
@ApiModelProperty("食堂业务类型")
private Integer canteenType;
@ApiModelProperty("第三方食堂id")
private String thirdCanteenId;
@ApiModelProperty("授权人员")
private Long effId;
@ApiModelProperty("人员id")
private Long custId;
@ApiModelProperty("联系电话")
private String contactTel;
@ApiModelProperty("主营项目")
private String mainProject;
@ApiModelProperty("食堂营业状态")
private Integer businessState;
@ApiModelProperty("营业时间")
private LocalTime startBusinessTime;
private LocalTime endBusinessTime;
@ApiModelProperty("食堂图片链接")
private String imgUrl;
@ApiModelProperty("最大容纳人数")
private Integer capacity;
@ApiModelProperty("是否启用支付配置")
private Integer ifEnablePay;
@ApiModelProperty("支付方式(多个数据之间使用,分隔)")
private String payTypes;
@ApiModelProperty("是否启用配送配置")
private Integer ifEnableDelivery;
@ApiModelProperty("配送方式(多个数据之间 使用,分隔)")
private String deliveries;
@ApiModelProperty("是否启用点餐配置")
private Integer ifEnableOrder;
@ApiModelProperty("是否支持报餐")
private Integer ifBook;
@ApiModelProperty("是否支持预定餐")
private Integer ifReserve;
@ApiModelProperty("是否启用收款码")
private Integer ifEnablePayCode;
@ApiModelProperty("食堂收款码链接")
private String payCodeUrl;
@ApiModelProperty("食堂特殊标识")
private Integer specialFlag;
@ApiModelProperty("是否删除")
private Integer ifDel;
@ApiModelProperty("备注")
private String remark;
@ApiModelProperty("创建人")
private String crby;
@ApiModelProperty("创建时间")
private LocalDateTime crtime;
@ApiModelProperty("更新人")
private String upby;
@ApiModelProperty("更新时间")
private LocalDateTime uptime;
public AllocCanteen(Long canteenId) {
this.canteenId = canteenId;
}
public AllocCanteen(Long canteenId, String canteenName, Long areaId, String thirdCanteenId) {
this.canteenId = canteenId;
this.canteenName = canteenName;
this.areaId = areaId;
this.thirdCanteenId = thirdCanteenId;
}
public String getImgUrl() {
return SysUtil.getCutPath(this.imgUrl);
}
public String getPayCodeUrl() {
return SysUtil.getCutPath(this.payCodeUrl);
}
public Long getId() {
return this.id;
}
public Long getCanteenId() {
return this.canteenId;
}
public String getCanteenNum() {
return this.canteenNum;
}
public String getCanteenName() {
return this.canteenName;
}
public Long getAreaId() {
return this.areaId;
}
public Integer getCanteenType() {
return this.canteenType;
}
public String getThirdCanteenId() {
return this.thirdCanteenId;
}
public Long getEffId() {
return this.effId;
}
public Long getCustId() {
return this.custId;
}
public String getContactTel() {
return this.contactTel;
}
public String getMainProject() {
return this.mainProject;
}
public Integer getBusinessState() {
return this.businessState;
}
public LocalTime getStartBusinessTime() {
return this.startBusinessTime;
}
public LocalTime getEndBusinessTime() {
return this.endBusinessTime;
}
public Integer getCapacity() {
return this.capacity;
}
public Integer getIfEnablePay() {
return this.ifEnablePay;
}
public String getPayTypes() {
return this.payTypes;
}
public Integer getIfEnableDelivery() {
return this.ifEnableDelivery;
}
public String getDeliveries() {
return this.deliveries;
}
public Integer getIfEnableOrder() {
return this.ifEnableOrder;
}
public Integer getIfBook() {
return this.ifBook;
}
public Integer getIfReserve() {
return this.ifReserve;
}
public Integer getIfEnablePayCode() {
return this.ifEnablePayCode;
}
public Integer getSpecialFlag() {
return this.specialFlag;
}
public Integer getIfDel() {
return this.ifDel;
}
public String getRemark() {
return this.remark;
}
public String getCrby() {
return this.crby;
}
public LocalDateTime getCrtime() {
return this.crtime;
}
public String getUpby() {
return this.upby;
}
public LocalDateTime getUptime() {
return this.uptime;
}
public void setId(final Long id) {
this.id = id;
}
public void setCanteenId(final Long canteenId) {
this.canteenId = canteenId;
}
public void setCanteenNum(final String canteenNum) {
this.canteenNum = canteenNum;
}
public void setCanteenName(final String canteenName) {
this.canteenName = canteenName;
}
public void setAreaId(final Long areaId) {
this.areaId = areaId;
}
public void setCanteenType(final Integer canteenType) {
this.canteenType = canteenType;
}
public void setThirdCanteenId(final String thirdCanteenId) {
this.thirdCanteenId = thirdCanteenId;
}
public void setEffId(final Long effId) {
this.effId = effId;
}
public void setCustId(final Long custId) {
this.custId = custId;
}
public void setContactTel(final String contactTel) {
this.contactTel = contactTel;
}
public void setMainProject(final String mainProject) {
this.mainProject = mainProject;
}
public void setBusinessState(final Integer businessState) {
this.businessState = businessState;
}
public void setStartBusinessTime(final LocalTime startBusinessTime) {
this.startBusinessTime = startBusinessTime;
}
public void setEndBusinessTime(final LocalTime endBusinessTime) {
this.endBusinessTime = endBusinessTime;
}
public void setImgUrl(final String imgUrl) {
this.imgUrl = imgUrl;
}
public void setCapacity(final Integer capacity) {
this.capacity = capacity;
}
public void setIfEnablePay(final Integer ifEnablePay) {
this.ifEnablePay = ifEnablePay;
}
public void setPayTypes(final String payTypes) {
this.payTypes = payTypes;
}
public void setIfEnableDelivery(final Integer ifEnableDelivery) {
this.ifEnableDelivery = ifEnableDelivery;
}
public void setDeliveries(final String deliveries) {
this.deliveries = deliveries;
}
public void setIfEnableOrder(final Integer ifEnableOrder) {
this.ifEnableOrder = ifEnableOrder;
}
public void setIfBook(final Integer ifBook) {
this.ifBook = ifBook;
}
public void setIfReserve(final Integer ifReserve) {
this.ifReserve = ifReserve;
}
public void setIfEnablePayCode(final Integer ifEnablePayCode) {
this.ifEnablePayCode = ifEnablePayCode;
}
public void setPayCodeUrl(final String payCodeUrl) {
this.payCodeUrl = payCodeUrl;
}
public void setSpecialFlag(final Integer specialFlag) {
this.specialFlag = specialFlag;
}
public void setIfDel(final Integer ifDel) {
this.ifDel = ifDel;
}
public void setRemark(final String remark) {
this.remark = remark;
}
public void setCrby(final String crby) {
this.crby = crby;
}
public void setCrtime(final LocalDateTime crtime) {
this.crtime = crtime;
}
public void setUpby(final String upby) {
this.upby = upby;
}
public void setUptime(final LocalDateTime uptime) {
this.uptime = uptime;
}
public AllocCanteen() {
}
}

View File

@ -0,0 +1,10 @@
package com.bonus.core.allocation.canteen.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.bonus.core.allocation.canteen.model.AllocCanteen;
import java.util.List;
public interface AllocCanteenService extends IService<AllocCanteen> {
List<Integer> listAvailPayTypeForApp(Long canteenId);
}

View File

@ -0,0 +1,55 @@
package com.bonus.core.allocation.canteen.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.lang.tree.Tree;
import cn.hutool.core.lang.tree.TreeNodeConfig;
import cn.hutool.core.lang.tree.TreeUtil;
import cn.hutool.core.text.CharSequenceUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bonus.constant.LeConstants;
import com.bonus.core.allocation.api.AllocMetadataApi;
import com.bonus.core.allocation.api.AllocPayMetadataApi;
import com.bonus.core.allocation.canteen.mapper.AllocCanteenMapper;
import com.bonus.core.allocation.canteen.mapper.AllocStallMapper;
import com.bonus.core.allocation.canteen.model.AllocCanteen;
import com.bonus.core.allocation.canteen.model.AllocStall;
import com.bonus.core.allocation.canteen.service.AllocCanteenService;
import com.bonus.core.common.utils.TenantContextHolder;
import com.bonus.core.menu.vo.AppletReserveStallVO;
import com.bonus.utils.AesEncryptUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.lang.invoke.SerializedLambda;
import java.util.*;
import java.util.stream.Collectors;
@Service
public class AllocCanteenServiceImpl extends ServiceImpl<AllocCanteenMapper, AllocCanteen> implements AllocCanteenService {
private static final Logger log = LoggerFactory.getLogger(AllocCanteenServiceImpl.class);
private static final String CACHE_PREFIX = "yst:";
private static final String CACHE_KEY = "alloc-canteen";
private static final long CACHE_SECONDS = 3600L;
@Resource
@Lazy
private AllocPayMetadataApi allocPayMetadataApi;
@Override
public List<Integer> listAvailPayTypeForApp(Long canteenId) {
return this.allocPayMetadataApi.supportPayChannels(canteenId);
}
}