Merge branch 'tkk' into test

This commit is contained in:
Tankaikai 2024-09-27 15:41:19 +08:00
commit 70af101daf
9 changed files with 450 additions and 0 deletions

View File

@ -0,0 +1,75 @@
package cn.ysk.cashier.controller.shop;
import cn.hutool.core.map.MapProxy;
import cn.hutool.core.util.StrUtil;
import cn.hutool.core.util.URLUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import cn.ysk.cashier.exception.BadRequestException;
import cn.ysk.cashier.system.enums.ParamsEnum;
import cn.ysk.cashier.system.service.ParamsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.nio.charset.Charset;
import java.util.Map;
/**
* 店铺支付相关接口
*
* @author tankaikai
* @since 2024-09-24 16:56
*/
@Slf4j
@RestController
@RequiredArgsConstructor
@Api(tags = "店铺支付相关接口")
@RequestMapping("/api/shop-pay-api")
public class ShopPayApiController {
private final ParamsService paramsService;
@Value("${spring.profiles.active}")
private String env;
@GetMapping("getOrderPayUrl")
@ApiOperation("获取店铺订单支付URL")
@ApiImplicitParams({
@ApiImplicitParam(name = "orderId", value = "订单id", paramType = "query", required = true, dataType="String") ,
@ApiImplicitParam(name = "shopId", value = "店铺id", paramType = "query",required = true, dataType="String") ,
})
public ResponseEntity url(@RequestParam Map<String, Object> params) {
MapProxy mapProxy = MapProxy.create(params);
String shopId = mapProxy.getStr("shopId");
String orderId = mapProxy.getStr("orderId");
try {
if(StrUtil.isBlank(shopId)){
throw new BadRequestException("店铺id不能为空");
}
if(StrUtil.isBlank(orderId)){
throw new BadRequestException("订单id不能为空");
}
String text = paramsService.getValue(ParamsEnum.SHOP_ORDER_PAY_BASE_URL.name());
JSONObject config = JSONUtil.parseObj(text);
String baseUrl = config.getStr(env);
String buildUrl = URLUtil.buildQuery(params, Charset.defaultCharset());
String fullUrl = baseUrl.concat("?").concat(buildUrl);
return ResponseEntity.ok().body(fullUrl);
}catch (BadRequestException e){
return ResponseEntity.badRequest().body(e.getMessage());
}catch (Exception e){
log.error("获取店铺订单支付URL异常",e);
return ResponseEntity.ok().body("获取店铺订单支付URL异常");
}
}
}

View File

@ -0,0 +1,16 @@
package cn.ysk.cashier.mybatis.mapper;
import cn.ysk.cashier.system.domain.Params;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
/**
* 参数管理
*
* @author tankaikai
* @since 2024-09-27 11:34
*/
@Mapper
public interface SysParamsMapper extends BaseMapper<Params> {
}

View File

@ -0,0 +1,63 @@
package cn.ysk.cashier.system.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* 参数管理
*
* @author tankaikai
* @since 2024-09-27 11:34
*/
@Data
@TableName("sys_params")
public class Params implements Serializable {
private static final long serialVersionUID = 1L;
/**
* id
*/
@TableId(type = IdType.AUTO)
@TableField("param_id")
private Long paramId;
/**
* 参数编码
*/
private String paramCode;
/**
* 参数值
*/
private String paramValue;
/**
* 类型 0系统参数 1非系统参数
*/
private Integer paramType;
/**
* 备注
*/
private String remark;
/**
* 创建者
*/
private Long createBy;
/**
* 创建时间
*/
private Date createTime;
/**
* 更新者
*/
private Long updateBy;
/**
* 更新时间
*/
private Date updateTime;
}

View File

@ -0,0 +1,15 @@
package cn.ysk.cashier.system.enums;
/**
* 参数枚举类
* @author tankaikai
* @since 2024-09-27 14:21
*/
public enum ParamsEnum {
/**
* 店铺订单支付BASE_URL
*/
SHOP_ORDER_PAY_BASE_URL
;
}

View File

@ -0,0 +1,93 @@
package cn.ysk.cashier.system.rest;
import cn.hutool.core.bean.BeanUtil;
import cn.ysk.cashier.annotation.Log;
import cn.ysk.cashier.system.domain.Params;
import cn.ysk.cashier.system.service.ParamsService;
import cn.ysk.cashier.system.service.dto.ParamsDTO;
import cn.ysk.cashier.utils.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import java.util.Date;
import java.util.Map;
/**
* 参数管理
*
* @author tankaikai
* @since 2024-09-27 11:34
*/
@RestController
@RequiredArgsConstructor
@RequestMapping("/sys/params")
@Api(tags="参数管理")
public class ParamsController {
private final ParamsService paramsService;
@GetMapping("page")
@ApiOperation("分页")
@ApiImplicitParams({
@ApiImplicitParam(name = "page", value = "当前页码从1开始", paramType = "query", required = true, dataType="int") ,
@ApiImplicitParam(name = "size", value = "每页显示记录数", paramType = "query",required = true, dataType="int") ,
@ApiImplicitParam(name = "paramCode", value = "参数编码", paramType = "query", dataType="String")
})
public ResponseEntity page(@ApiIgnore @RequestParam Map<String, Object> params){
Map<String, Object> page = paramsService.page(params);
return ResponseEntity.ok().body(page);
}
@GetMapping("{id}")
@ApiOperation("信息")
public ResponseEntity get(@PathVariable("id") Long id){
Params entity = paramsService.getById(id);
ParamsDTO data = BeanUtil.toBean(entity, ParamsDTO.class);
return ResponseEntity.ok().body(data);
}
@PostMapping
@ApiOperation("保存")
@Log("保存")
public ResponseEntity save(@RequestBody ParamsDTO dto){
Params entity = BeanUtil.toBean(dto, Params.class);
Long currentUserId = SecurityUtils.getCurrentUserId();
entity.setCreateBy(currentUserId);
entity.setCreateTime(new Date());
entity.setUpdateBy(currentUserId);
entity.setUpdateTime(entity.getCreateTime());
paramsService.save(entity);
return new ResponseEntity<>(HttpStatus.OK);
}
@PutMapping
@ApiOperation("修改")
@Log("修改")
public ResponseEntity update(@RequestBody ParamsDTO dto){
Long paramId = dto.getParamId();
Params entity = paramsService.getById(paramId);
BeanUtil.copyProperties(dto, entity,"createBy","createTime");
Long currentUserId = SecurityUtils.getCurrentUserId();
entity.setUpdateBy(currentUserId);
entity.setUpdateTime(entity.getCreateTime());
paramsService.updateById(entity);
return new ResponseEntity<>(HttpStatus.OK);
}
@DeleteMapping("{id}")
@ApiOperation("删除")
@Log("删除")
public ResponseEntity delete(@PathVariable("paramId") Long paramId){
paramsService.removeById(paramId);
return new ResponseEntity<>(HttpStatus.OK);
}
}

View File

@ -0,0 +1,43 @@
package cn.ysk.cashier.system.service;
import cn.ysk.cashier.system.domain.Params;
import cn.ysk.cashier.system.service.dto.ParamsDTO;
import com.baomidou.mybatisplus.extension.service.IService;
import java.util.List;
import java.util.Map;
/**
* 参数管理
*
* @author tankaikai
* @since 2024-09-27 11:34
*/
public interface ParamsService extends IService<Params> {
Map<String,Object> page(Map<String, Object> params);
List<ParamsDTO> list(Map<String, Object> params);
/**
* 根据参数编码获取参数的value值
*
* @param paramCode 参数编码
*/
String getValue(String paramCode);
/**
* 根据参数编码获取value的Object对象
* @param paramCode 参数编码
* @param clazz Object对象
*/
<T> T getValueObject(String paramCode, Class<T> clazz);
/**
* 根据参数编码更新value
* @param paramCode 参数编码
* @param paramValue 参数值
*/
int updateValueByCode(String paramCode, String paramValue);
}

View File

@ -0,0 +1,45 @@
package cn.ysk.cashier.system.service.dto;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* 参数管理
*
* @author tankaikai
* @since 2024-09-27 11:34
*/
@Data
@ApiModel(value = "参数管理")
public class ParamsDTO implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "id")
private Long paramId;
@ApiModelProperty(value = "参数编码")
private String paramCode;
@ApiModelProperty(value = "参数值")
private String paramValue;
@ApiModelProperty(value = "备注")
private String remark;
@ApiModelProperty(value = "创建时间")
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date createTime;
@ApiModelProperty(value = "更新时间")
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date updateTime;
}

View File

@ -0,0 +1,94 @@
package cn.ysk.cashier.system.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.map.MapProxy;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import cn.ysk.cashier.exception.BadRequestException;
import cn.ysk.cashier.mybatis.mapper.SysParamsMapper;
import cn.ysk.cashier.system.domain.Params;
import cn.ysk.cashier.system.service.ParamsService;
import cn.ysk.cashier.system.service.dto.ParamsDTO;
import cn.ysk.cashier.utils.PageUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
import java.util.Optional;
/**
* 参数管理
*
* @author tankaikai
* @since 2024-09-27 11:34
*/
@Slf4j
@Service
@RequiredArgsConstructor
public class ParamsServiceImpl extends ServiceImpl<SysParamsMapper, Params> implements ParamsService {
private QueryWrapper<Params> getWrapper(Map<String, Object> params) {
MapProxy mapProxy = MapProxy.create(params);
QueryWrapper<Params> wrapper = new QueryWrapper<>();
wrapper.lambda().eq(Params::getParamType, 1);
String paramCode = mapProxy.getStr("paramCode");
wrapper.lambda().like(StrUtil.isNotEmpty(paramCode), Params::getParamCode, paramCode);
wrapper.lambda().orderByDesc(Params::getParamId);
return wrapper;
}
@Override
public Map<String, Object> page(Map<String, Object> params) {
MapProxy mapProxy = MapProxy.create(params);
int pageNum = mapProxy.getInt("page", 1);
int pageSize = mapProxy.getInt("size", 10);
Page<Params> page = super.page(new Page<>(pageNum, pageSize), getWrapper(params));
List<ParamsDTO> list = BeanUtil.copyToList(page.getRecords(), ParamsDTO.class);
return PageUtil.toPlusPage(list, Convert.toInt(page.getTotal()));
}
@Override
public List<ParamsDTO> list(Map<String, Object> params) {
List<Params> list = super.list(getWrapper(params));
return BeanUtil.copyToList(list, ParamsDTO.class);
}
@Override
public String getValue(String paramCode) {
Params params = baseMapper.selectOne(Wrappers.<Params>lambdaQuery().select(Params::getParamValue).eq(Params::getParamCode, paramCode));
return Optional.ofNullable(params).map(Params::getParamValue).orElseThrow(() -> new BadRequestException("找不到对应的系统参数值"));
}
@Override
public <T> T getValueObject(String paramCode, Class<T> clazz) {
String paramValue = getValue(paramCode);
if (StringUtils.isNotBlank(paramValue)) {
return JSONUtil.toBean(paramValue, clazz);
}
try {
return clazz.newInstance();
} catch (Exception e) {
throw new BadRequestException("获取参数失败");
}
}
@Override
public int updateValueByCode(String paramCode, String paramValue) {
return baseMapper.update(null, Wrappers.<Params>lambdaUpdate().eq(Params::getParamCode, paramCode).set(Params::getParamValue, paramValue));
}
}

View File

@ -0,0 +1,6 @@
<?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="cn.ysk.cashier.mybatis.mapper.SysParamsMapper">
</mapper>