Merge branch 'refs/heads/test' into gyj
This commit is contained in:
commit
f808912006
|
|
@ -74,4 +74,6 @@ public interface CacheKey {
|
|||
*/
|
||||
String PRODUCT = "PRODUCT:";
|
||||
String SONG_URL = "song:";
|
||||
|
||||
String VIPCODE = "VIPCODE:";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import cn.ysk.cashier.cons.domain.TbConsInfo;
|
|||
import cn.ysk.cashier.cons.domain.TbConsInfoFlow;
|
||||
import cn.ysk.cashier.cons.repository.TbConsInfoFlowRepository;
|
||||
import cn.ysk.cashier.cons.repository.TbConsInfoRepository;
|
||||
import cn.ysk.cashier.exception.BadRequestException;
|
||||
import cn.ysk.cashier.utils.FileUtil;
|
||||
import cn.ysk.cashier.utils.PageUtil;
|
||||
import cn.ysk.cashier.utils.QueryHelp;
|
||||
|
|
@ -65,6 +66,12 @@ public class TbConCheckServiceImpl implements TbConCheckService {
|
|||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public TbConCheckDto create(TbConCheck resources) throws Exception {
|
||||
|
||||
if(BigDecimal.ZERO.compareTo(resources.getStockNumber())>0||resources.getStockNumber().compareTo(new BigDecimal("99999999999999"))>0){
|
||||
throw new BadRequestException("请输入正确的数值");
|
||||
}
|
||||
|
||||
|
||||
TbConsInfo consInfo= tbConsInfoRepository.getById(resources.getConInfoId());
|
||||
if(Objects.isNull(consInfo)){
|
||||
throw new Exception("耗材信息不存在");
|
||||
|
|
|
|||
|
|
@ -1,18 +1,33 @@
|
|||
package cn.ysk.cashier.mybatis.rest;
|
||||
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.ysk.cashier.annotation.rest.AnonymousPostMapping;
|
||||
import cn.ysk.cashier.domain.QiniuContent;
|
||||
import cn.ysk.cashier.exception.BadRequestException;
|
||||
import cn.ysk.cashier.mybatis.entity.Activate;
|
||||
import cn.ysk.cashier.mybatis.service.ShopService;
|
||||
import cn.ysk.cashier.service.QiNiuService;
|
||||
import cn.ysk.cashier.utils.CacheKey;
|
||||
import cn.ysk.cashier.utils.RedisUtils;
|
||||
import cn.ysk.cashier.utils.SecurityUtils;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.google.gson.JsonObject;
|
||||
import io.swagger.annotations.Api;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import cn.ysk.cashier.annotation.Log;
|
||||
import cn.ysk.cashier.mybatis.entity.StorageVo;
|
||||
import cn.ysk.cashier.mybatis.service.ShopService;
|
||||
import cn.ysk.cashier.utils.SecurityUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@Api(tags = "/shop/storage")
|
||||
|
|
@ -20,6 +35,13 @@ import org.springframework.web.bind.annotation.*;
|
|||
public class StorageController {
|
||||
@Autowired
|
||||
private ShopService shopService;
|
||||
private final RedisUtils redisUtils;
|
||||
|
||||
private final QiNiuService qiNiuService;
|
||||
private static final String APP_ID = "wxd88fffa983758a30";
|
||||
private static final String APP_SECRET = "a34a61adc0602118b49400baa8812454";
|
||||
private static final String TOKEN_URL = "https://api.weixin.qq.com/cgi-bin/token";
|
||||
private static final String QR_CODE_URL = "https://api.weixin.qq.com/wxa/getwxacode";
|
||||
|
||||
@GetMapping("/findActivate")
|
||||
public ResponseEntity<Object> findActivate(@RequestParam String shopId){
|
||||
|
|
@ -32,4 +54,47 @@ public class StorageController {
|
|||
shopService.modityActivate(activate);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param params
|
||||
* shopId 必填
|
||||
* env_version 存在即生成体验版
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/getwxacode")
|
||||
public ResponseEntity<Object> getwxacode(@RequestBody Map<String, Object> params) {
|
||||
if (CollectionUtils.isEmpty(params) || !params.containsKey("shopId")) throw new BadRequestException("参数错误");
|
||||
if (redisUtils.hasKey(CacheKey.VIPCODE + params.get("shopId"))) return new ResponseEntity<>(redisUtils.get(CacheKey.VIPCODE + params.get("shopId")),HttpStatus.OK);
|
||||
try {
|
||||
InputStream qrCodeStream = fetchQRCode(params);
|
||||
QiniuContent qiniuContent = qiNiuService.uploadByte(IoUtil.readBytes(qrCodeStream),qiNiuService.findCloud());
|
||||
redisUtils.set(CacheKey.VIPCODE + params.get("shopId"),qiniuContent.getUrl());
|
||||
return new ResponseEntity<>(qiniuContent.getUrl(),HttpStatus.OK);
|
||||
} catch (Exception e) {
|
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
|
||||
.body("Failed to generate QR code: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private String getAccessToken() {
|
||||
String url = String.format("%s?grant_type=client_credential&appid=%s&secret=%s", TOKEN_URL, APP_ID, APP_SECRET);
|
||||
String response = HttpUtil.get(url);
|
||||
JSONObject jsonResponse = JSONObject.parseObject(response);
|
||||
if (!jsonResponse.containsKey("access_token")) {
|
||||
throw new RuntimeException("Failed to retrieve access token: " + response);
|
||||
}
|
||||
return jsonResponse.getString("access_token");
|
||||
}
|
||||
private InputStream fetchQRCode(Map<String, Object> params) {
|
||||
JsonObject jsonObject = new JsonObject();
|
||||
jsonObject.addProperty("path", "pages/member/index");//路径
|
||||
jsonObject.addProperty("is_hyaline", true);//是否需要透明底色,为 true 时,生成透明底色的小程序码
|
||||
if (params.containsKey("env_version")) jsonObject.addProperty("env_version", "trial");//正式版为 release,体验版为 trial,开发版为 develop
|
||||
String accessToken = getAccessToken();
|
||||
String url = String.format("%s?access_token=%s&shopId=%s", QR_CODE_URL, accessToken,params.get("shopId"));
|
||||
return HttpUtil.createPost(url)
|
||||
.body(jsonObject.toString(), "application/json")
|
||||
.execute()
|
||||
.bodyStream();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -70,6 +70,7 @@ public interface QiNiuService {
|
|||
* @return QiniuContent
|
||||
*/
|
||||
QiniuContent upload(MultipartFile file, CloudStorageConfig cloudStorageConfig);
|
||||
QiniuContent uploadByte(byte[] bytes, CloudStorageConfig qiniuConfig);
|
||||
|
||||
/**
|
||||
* 查询文件
|
||||
|
|
|
|||
|
|
@ -148,6 +148,36 @@ public class QiNiuServiceImpl implements QiNiuService {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public QiniuContent uploadByte(byte[] bytes, CloudStorageConfig qiniuConfig) {
|
||||
if(qiniuConfig== null){
|
||||
throw new BadRequestException("请先添加相应配置,再操作");
|
||||
}
|
||||
// 构造一个带指定Zone对象的配置类
|
||||
try {
|
||||
String url = OSSFactory.build(qiniuConfig).uploadSuffix(bytes, "png");
|
||||
if(url != null){
|
||||
//存入数据库
|
||||
String[] str=url.split("/");
|
||||
|
||||
String fileName=str[str.length-1];
|
||||
|
||||
QiniuContent qiniuContent = new QiniuContent();
|
||||
qiniuContent.setKey(fileName);
|
||||
qiniuContent.setSuffix(fileName.split("\\.")[1]);
|
||||
qiniuContent.setBucket(qiniuConfig.getBucketName());
|
||||
qiniuContent.setSize(bytes.length+"");
|
||||
qiniuContent.setType("公开");
|
||||
qiniuContent.setUrl(url);
|
||||
return qiniuContentRepository.save(qiniuContent);
|
||||
}
|
||||
return new QiniuContent();
|
||||
} catch (Exception e) {
|
||||
throw new BadRequestException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public QiniuContent findByContentId(Long id) {
|
||||
QiniuContent qiniuContent = qiniuContentRepository.findById(id).orElseGet(QiniuContent::new);
|
||||
|
|
|
|||
Loading…
Reference in New Issue