From e6e93f2d54eabda66a024e53d85546631a1c10ad Mon Sep 17 00:00:00 2001 From: xukai <1027104849@qq.com> Date: Tue, 10 May 2022 16:49:11 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B9=B3=E5=AE=89=E9=93=B6=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xgl/lottery/constants/ActivityEnum.java | 2 +- .../lottery/controller/FileController.java | 62 +++++++++++++++++-- .../xgl/lottery/service/BusinessService.java | 9 ++- .../service/impl/LotteryServiceImpl.java | 5 +- 4 files changed, 66 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/xgl/lottery/constants/ActivityEnum.java b/src/main/java/com/xgl/lottery/constants/ActivityEnum.java index 41e4b3d..bde0624 100644 --- a/src/main/java/com/xgl/lottery/constants/ActivityEnum.java +++ b/src/main/java/com/xgl/lottery/constants/ActivityEnum.java @@ -7,7 +7,7 @@ import java.util.*; public enum ActivityEnum { - A("A", "2022-05-09 00:00:00","2022-05-13 22:00:00"), + A("A", "2022-05-06 00:00:00","2022-05-13 22:00:00"), B("B", "2022-12-01 00:00:00","2022-12-01 23:59:59"), diff --git a/src/main/java/com/xgl/lottery/controller/FileController.java b/src/main/java/com/xgl/lottery/controller/FileController.java index f37be89..16afa66 100644 --- a/src/main/java/com/xgl/lottery/controller/FileController.java +++ b/src/main/java/com/xgl/lottery/controller/FileController.java @@ -5,13 +5,18 @@ package com.xgl.lottery.controller; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.aliyun.oss.OSSClient; +import com.aliyun.oss.OSSClientBuilder; +import com.aliyun.oss.ServiceException; import com.xgl.lottery.ReturnCodeEnum; import com.xgl.lottery.config.AccessToken; import com.xgl.lottery.service.dto.ResultResp; import com.xgl.lottery.utils.DateUtil; -import io.swagger.annotations.Api; + + +import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; +import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.URL; import java.text.MessageFormat; @@ -28,10 +33,9 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.data.redis.core.RedisTemplate; 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.RestController; +import org.springframework.web.bind.annotation.*; import org.springframework.web.client.RestTemplate; +import org.springframework.web.multipart.MultipartFile; @RestController @RequestMapping({"/oss"}) @@ -45,6 +49,54 @@ public class FileController { RedisTemplate redisTemplate; + @PostMapping("/file") + public ResultResp SingleFileUpLoad(@RequestParam("file") MultipartFile file) throws IOException { + + //创建输入输出流 + InputStream inputStream = null; + OutputStream outputStream = null; + + + + //获取文件的输入流 + inputStream = file.getInputStream(); + //获取上传时的文件名 + String fileName = file.getOriginalFilename(); + String url = null; + OSSClient ossClient = null; + try { + + String endpoint = "oss-cn-shenzhen.aliyuncs.com"; + String accessKeyId = "sSJ5t0yC1CaKhPJ4"; + String accessKeySecret = "PsbdUTexU95BkiqO4ADELXpIaYdWGk"; + String bucketName = "szxgl"; + OSSClientBuilder builder = new OSSClientBuilder(); + + ossClient = (OSSClient) builder.build(endpoint, accessKeyId, accessKeySecret); + + String datePath = DateUtil.format(new Date(), "yyyy/MM/dd"); + String fileNa = UUID.randomUUID().toString().replaceAll("-", ""); + String key = "user/clock/" + datePath + "/" + fileNa + ".jpg"; + + ossClient.putObject(bucketName, key, inputStream); + url = "https://" + bucketName + "." + endpoint + "/" + key; + } catch (RuntimeException e) { + log.error("阿里云OSS上传文件出错", e); + throw new ServiceException("网络异常,请稍候再试!"); + } finally { + if (ossClient != null) { + // 关闭OSSClient。 + ossClient.shutdown(); + } + } + return ResultResp.success(ReturnCodeEnum.SUCCESS.getCode(), ReturnCodeEnum.SUCCESS.getMsg(),url); + + + } + + + + @GetMapping({"/get/file"}) public ResultResp getUpload(ServletRequest servletRequest, ServletResponse servletResponse) throws IOException { HttpServletRequest request = (HttpServletRequest)servletRequest; @@ -72,7 +124,7 @@ public class FileController { assert wxOAuth2AccessToken != null; access_token = wxOAuth2AccessToken.getAccessToken(); - this.redisTemplate.opsForValue().set("wx_token", access_token, (long)(wxOAuth2AccessToken.getExpires_in() - 2000), TimeUnit.SECONDS); + this.redisTemplate.opsForValue().set("wx_token", access_token, (long)(wxOAuth2AccessToken.getExpires_in() - 3000), TimeUnit.SECONDS); } } } diff --git a/src/main/java/com/xgl/lottery/service/BusinessService.java b/src/main/java/com/xgl/lottery/service/BusinessService.java index 7361f9f..781ef63 100644 --- a/src/main/java/com/xgl/lottery/service/BusinessService.java +++ b/src/main/java/com/xgl/lottery/service/BusinessService.java @@ -161,7 +161,8 @@ public class BusinessService { public ResultResp> userInfo(UserInfoDTO userInfoDTO) throws ParseException { - + HashMap map = new HashMap<>(); + map.put("flag","false"); UserInfo userInfo = new UserInfo(); // BeanUtils.copyProperties(userInfoDTO, userInfo); String shareid=""; @@ -197,6 +198,7 @@ public class BusinessService { SimpleDateFormat dateFormat3 = new SimpleDateFormat("yyyy-MM-dd"); String format3 = dateFormat3.format(date3); clockRecordMapper.insertHelp(userInfo2.getOpenid(),userInfoDTO.getOpenid(),format3); + map.put("flag","true"); } } } @@ -216,7 +218,7 @@ public class BusinessService { log.info("新增加的用户为:"+JSONObject.toJSONString(userInfo)); userInfoMapper.insert(userInfo); } - HashMap map = new HashMap<>(); + map.put("shareId", userInfo.getShareId()); return ResultResp.success(ReturnCodeEnum.SUCCESS.getCode(), ReturnCodeEnum.SUCCESS.getMsg(), map); } @@ -264,7 +266,10 @@ public class BusinessService { if ((parse2.isAfter(startTime2) && parse2.isBefore(endTime2))) { ClockRecord clockRecord = clockRecords.get(0); if (null != clockRecord) { + SportCard sportCard = sportCardMapper.selectByCardType(clockRecord.getCardType()); userInfo.setClockUrl(clockRecord.getPhoto()); + userInfo.setCardType(clockRecord.getCardType()); + userInfo.setUrl(sportCard.getContent()); } } diff --git a/src/main/java/com/xgl/lottery/service/impl/LotteryServiceImpl.java b/src/main/java/com/xgl/lottery/service/impl/LotteryServiceImpl.java index fc33bea..6db0d04 100644 --- a/src/main/java/com/xgl/lottery/service/impl/LotteryServiceImpl.java +++ b/src/main/java/com/xgl/lottery/service/impl/LotteryServiceImpl.java @@ -65,10 +65,7 @@ public class LotteryServiceImpl extends ServiceImpl impl context.setKey(key); AbstractRewardProcessor.rewardProcessorMap.get(prizeType).doReward(context); } catch (UnRewardException u) { - context.setKey(RedisKeyManager.getDefaultLotteryPrizeRedisKey(lotteryItem.getLotteryId())); - lotteryItem = (LotteryItem) redisTemplate.opsForValue().get(RedisKeyManager.getDefaultLotteryItemRedisKey(lotteryItem.getLotteryId())); - context.setLotteryItem(lotteryItem); - AbstractRewardProcessor.rewardProcessorMap.get(LotteryConstants.PrizeTypeEnum.THANK.getValue()).doReward(context); + } drawDto.setLevel(lotteryItem.getLevel()); drawDto.setPrizeName(context.getPrizeName());