记得上下班打卡 | git大法好,push需谨慎

Commit 33065d14 authored by jiangxiulong's avatar jiangxiulong

Merge branch 'jxl_up_video' into dev_goblin

parents 26ab013e ad534d28
...@@ -25,6 +25,8 @@ public class UploadVo implements Serializable { ...@@ -25,6 +25,8 @@ public class UploadVo implements Serializable {
private String fileName; private String fileName;
@ApiModelProperty(value = "上传后的地址") @ApiModelProperty(value = "上传后的地址")
private String ossPath; private String ossPath;
@ApiModelProperty(value = "视频截帧图片文件地址")
private String videoImg;
@ApiModelProperty(value = "文件类型") @ApiModelProperty(value = "文件类型")
private String contentType; private String contentType;
@ApiModelProperty(value = "文件大小") @ApiModelProperty(value = "文件大小")
......
...@@ -111,20 +111,20 @@ public class AdminUpushServiceImpl extends ServiceImpl<AdminUpushMapper, AdminUp ...@@ -111,20 +111,20 @@ public class AdminUpushServiceImpl extends ServiceImpl<AdminUpushMapper, AdminUp
if (upushParam.getPushRange() == 1) { if (upushParam.getPushRange() == 1) {
if (!CollectionUtil.isEmpty(pushList)) { if (!CollectionUtil.isEmpty(pushList)) {
if (pushList.size() >= 20) { if (pushList.size() >= 20) {
pushList.remove(0); pushList.remove(pushList.size()-1);
} }
} }
pushList.addFirst(adminUpushVo); pushList.addFirst(adminUpushVo);
if (!CollectionUtil.isEmpty(pushList2)) { if (!CollectionUtil.isEmpty(pushList2)) {
if (pushList2.size() >= 20) { if (pushList2.size() >= 20) {
pushList2.remove(0); pushList2.remove(pushList.size()-1);
} }
} }
pushList2.addFirst(adminUpushVo); pushList2.addFirst(adminUpushVo);
} else { } else {
if (!CollectionUtil.isEmpty(pushList)) { if (!CollectionUtil.isEmpty(pushList)) {
if (pushList.size() >= 20) { if (pushList.size() >= 20) {
pushList.remove(0); pushList.remove(pushList.size()-1);
} }
} }
pushList.addFirst(adminUpushVo); pushList.addFirst(adminUpushVo);
......
...@@ -8,9 +8,12 @@ import java.math.BigInteger; ...@@ -8,9 +8,12 @@ import java.math.BigInteger;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.URL; import java.net.URL;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.time.LocalDateTime;
import java.util.UUID;
/** /**
* aloss 上传MultipartFile to File * aloss 上传MultipartFile to File
*
* @author jiangxiulong * @author jiangxiulong
* @since 2021-06-10 * @since 2021-06-10
*/ */
...@@ -22,19 +25,21 @@ public class FilesUtils { ...@@ -22,19 +25,21 @@ public class FilesUtils {
* @param file * @param file
* @throws Exception * @throws Exception
*/ */
public static File multipartFileToFile(MultipartFile file) throws Exception { public static File multipartFileToFile(MultipartFile file) {
try {
File toFile = null; File toFile = null;
if (file.equals("") || file.getSize() <= 0) { if (!file.equals("") && file.getSize() > 0) {
file = null; InputStream ins = null;
} else { ins = file.getInputStream();
InputStream ins = null; toFile = new File(file.getOriginalFilename());
ins = file.getInputStream(); inputStreamToFile(ins, toFile);
toFile = new File(file.getOriginalFilename()); ins.close();
inputStreamToFile(ins, toFile); }
ins.close(); return toFile;
} catch (Exception e) {
log.error("multipartFileToFileError", e);
return null;
} }
return toFile;
} }
//获取流文件 //获取流文件
...@@ -55,20 +60,22 @@ public class FilesUtils { ...@@ -55,20 +60,22 @@ public class FilesUtils {
/** /**
* 删除本地临时文件 * 删除本地临时文件
*
* @param file * @param file
*/ */
public static void delteTempFile(File file) { public static void deleteTempFile(File file) {
try { try {
if (file != null) { if (file != null) {
file.delete(); file.delete();
} }
} catch (Exception e) { } catch (Exception e) {
log.error("delteTempFileError", e); log.error("deleteTempFileError", e);
} }
} }
/** /**
* 获取文件的md5值 * 获取文件的md5值
*
* @param file 文件 * @param file 文件
* @return 返回文件的md5值字符串 * @return 返回文件的md5值字符串
*/ */
...@@ -100,7 +107,14 @@ public class FilesUtils { ...@@ -100,7 +107,14 @@ public class FilesUtils {
} }
} }
public static File inputStreamToFile(String url, String name){ /**
* 大美 通过URL上传
*
* @param url
* @param name
* @return
*/
public static File inputStreamToFile(String url, String name) {
try { try {
HttpURLConnection httpUrl = (HttpURLConnection) new URL(url).openConnection(); HttpURLConnection httpUrl = (HttpURLConnection) new URL(url).openConnection();
httpUrl.connect(); httpUrl.connect();
...@@ -119,9 +133,43 @@ public class FilesUtils { ...@@ -119,9 +133,43 @@ public class FilesUtils {
os.close(); os.close();
ins.close(); ins.close();
return file; return file;
}catch (Exception e){ } catch (Exception e) {
e.printStackTrace(); log.error("inputStreamToFileUrlError", e);
return null; return null;
} }
} }
/**
* 获取上传含文件名的完整路径 这里文件名用了uuid 防止重复,可以根据自己的需要来写
*
* @param pathName banner
* @param filename time.jpeg
* @return
*/
public static String getUploadPath(String pathName, String filename) {
// 078a77e0-cf80-481b-824c-5935247cff15.jpeg
String uploadName = UUID.randomUUID() + filename.substring(filename.lastIndexOf("."));
// 078a77e0cf80481b824c5935247cff15.jpeg
uploadName = uploadName.replace("-", "");
return pathName + "/" + DateUtil.format(LocalDateTime.now(), DateUtil.Formatter.yyyy_MM_dd2) + "/" + uploadName;
}
/**
* 获取 bucketName
*
* @param buckType
* @return
*/
public static String getBucketName(int buckType) {
String bucketName = "img-zhengzai-tv";
switch (buckType) {
case 1:
bucketName = "img-zhengzai-tv";
break;
case 2:
bucketName = "app-zhengzai-tv";
break;
}
return bucketName;
}
} }
...@@ -27,6 +27,7 @@ public class PlatformOssFiles implements Serializable ,Cloneable { ...@@ -27,6 +27,7 @@ public class PlatformOssFiles implements Serializable ,Cloneable {
private String ossFilesId; private String ossFilesId;
private String fileName; private String fileName;
private String ossPath; private String ossPath;
private String videoImg;
private String contentType; private String contentType;
private Integer size; private Integer size;
private String md5str; private String md5str;
......
...@@ -4,6 +4,7 @@ import com.liquidnet.service.base.ResponseDto; ...@@ -4,6 +4,7 @@ import com.liquidnet.service.base.ResponseDto;
import feign.hystrix.FallbackFactory; import feign.hystrix.FallbackFactory;
import org.springframework.cloud.openfeign.FeignClient; import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.PutMapping;
@Component @Component
...@@ -27,4 +28,7 @@ public interface FeignPlatformCandyTaskClient { ...@@ -27,4 +28,7 @@ public interface FeignPlatformCandyTaskClient {
@PutMapping("ccoupon/task/due/user") @PutMapping("ccoupon/task/due/user")
ResponseDto<String> dueProcessForUser(); ResponseDto<String> dueProcessForUser();
@GetMapping("followDoTask/doTask")
ResponseDto doTask();
} }
...@@ -110,4 +110,22 @@ public class PlatformTaskHandler { ...@@ -110,4 +110,22 @@ public class PlatformTaskHandler {
return fail; return fail;
} }
} }
// 关注任务加积分脚本
@XxlJob(value = "sev-platform:followDoTask")
public ReturnT<String> followDoTask() {
try {
ResponseDto<String> dto = feignPlatformCandyTaskClient.doTask();
String dtoStr = JsonUtils.toJson(dto);
log.info("result of handler:{}", dtoStr);
ReturnT<String> success = ReturnT.SUCCESS;
success.setMsg(dtoStr);
return success;
} catch (Exception e) {
log.error("exception of handler:{}", e.getMessage(), e);
ReturnT<String> fail = ReturnT.FAIL;
fail.setMsg(e.getLocalizedMessage());
return fail;
}
}
} }
...@@ -969,27 +969,6 @@ CREATE TABLE `kylin_zhengzai_app_versions` ...@@ -969,27 +969,6 @@ CREATE TABLE `kylin_zhengzai_app_versions`
DEFAULT CHARSET utf8mb4 DEFAULT CHARSET utf8mb4
COLLATE utf8mb4_unicode_ci COMMENT '正在现场app版本控制'; COLLATE utf8mb4_unicode_ci COMMENT '正在现场app版本控制';
drop TABLE if exists `platform_oss_files`;
create table platform_oss_files
(
`mid` int(11) unsigned NOT NULL AUTO_INCREMENT,
`oss_files_id` varchar(255) NOT NULL DEFAULT '' COMMENT 'oss_files_id',
`file_name` varchar(255) NOT NULL DEFAULT '' COMMENT '源文件名称',
`content_type` varchar(255) NOT NULL DEFAULT '' COMMENT '文件类型',
`size` int NOT NULL DEFAULT 0 COMMENT '文件大小',
`md5str` varchar(255) NOT NULL DEFAULT '' COMMENT 'md5值判断文件是否相同',
`oss_path` varchar(255) NOT NULL DEFAULT '' COMMENT '文件地址(阿里oss)',
`buck_type` tinyint NOT NULL DEFAULT '0' COMMENT 'buck_type',
`uploader_uid` varchar(255) NOT NULL DEFAULT '' COMMENT '上传人id',
`uploader_name` varchar(255) NOT NULL DEFAULT '' COMMENT '上传人姓名',
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
KEY `kylin_oss_files_id_index` (`oss_files_id`),
PRIMARY KEY (`mid`)
) ENGINE = InnoDB
DEFAULT CHARSET utf8mb4
COLLATE utf8mb4_unicode_ci COMMENT '阿里云OSS上传记录';
drop TABLE if exists `admin_upush`; drop TABLE if exists `admin_upush`;
CREATE TABLE `admin_upush` CREATE TABLE `admin_upush`
( (
......
drop TABLE if exists `platform_oss_files`;
create table platform_oss_files
(
`mid` int(11) unsigned NOT NULL AUTO_INCREMENT,
`oss_files_id` varchar(255) NOT NULL DEFAULT '' COMMENT 'oss_files_id',
`file_name` varchar(255) NOT NULL DEFAULT '' COMMENT '源文件名称',
`content_type` varchar(255) NOT NULL DEFAULT '' COMMENT '文件类型',
`size` int NOT NULL DEFAULT 0 COMMENT '文件大小',
`md5str` varchar(255) NOT NULL DEFAULT '' COMMENT 'md5值判断文件是否相同',
`oss_path` varchar(255) NOT NULL DEFAULT '' COMMENT '文件地址(阿里oss)',
`buck_type` tinyint NOT NULL DEFAULT '0' COMMENT 'buck_type',
`uploader_uid` varchar(255) NOT NULL DEFAULT '' COMMENT '上传人id',
`uploader_name` varchar(255) NOT NULL DEFAULT '' COMMENT '上传人姓名',
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
KEY `kylin_oss_files_id_index` (`oss_files_id`),
PRIMARY KEY (`mid`)
) ENGINE = InnoDB
DEFAULT CHARSET utf8mb4
COLLATE utf8mb4_unicode_ci COMMENT '阿里云OSS上传记录';
alter table platform_oss_files add video_img varchar(255) NOT NULL DEFAULT '' COMMENT '视频截帧图片文件地址(阿里oss)' after oss_path;
\ No newline at end of file
...@@ -8,7 +8,6 @@ import com.aliyun.oss.model.ProcessObjectRequest; ...@@ -8,7 +8,6 @@ import com.aliyun.oss.model.ProcessObjectRequest;
import com.aliyun.oss.model.PutObjectRequest; import com.aliyun.oss.model.PutObjectRequest;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.liquidnet.commons.lang.util.CollectionUtil;
import com.liquidnet.commons.lang.util.DateUtil; import com.liquidnet.commons.lang.util.DateUtil;
import com.liquidnet.commons.lang.util.FilesUtils; import com.liquidnet.commons.lang.util.FilesUtils;
import com.liquidnet.commons.lang.util.IDGenerator; import com.liquidnet.commons.lang.util.IDGenerator;
...@@ -23,10 +22,15 @@ import io.swagger.annotations.ApiOperation; ...@@ -23,10 +22,15 @@ import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import java.io.File; import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.Formatter; import java.util.Formatter;
import java.util.List; import java.util.List;
...@@ -51,6 +55,8 @@ public class AlOssController { ...@@ -51,6 +55,8 @@ public class AlOssController {
private String accessKeyId; private String accessKeyId;
@Value("${liquidnet.al-oss.accessKeySecret}") @Value("${liquidnet.al-oss.accessKeySecret}")
private String accessKeySecret; private String accessKeySecret;
@Value("${liquidnet.al-oss.imgUrl}")
private String imgUrl;
@Autowired @Autowired
private PlatformOssFilesMapper platformOssFilesMapper; private PlatformOssFilesMapper platformOssFilesMapper;
...@@ -59,81 +65,149 @@ public class AlOssController { ...@@ -59,81 +65,149 @@ public class AlOssController {
@ApiOperation("阿里云上传") @ApiOperation("阿里云上传")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(type = "form", dataType = "File", name = "file", value = "文件", required = true), @ApiImplicitParam(type = "form", dataType = "File", name = "file", value = "文件", required = true),
@ApiImplicitParam(type = "form", dataType = "String", name = "pathName", value = "归类的文件夹名称 比如banner上传就传 banner 返回的地址就会是bnanner/XXX", defaultValue = "other"), @ApiImplicitParam(type = "form", dataType = "String", name = "pathName", value = "归类的文件夹名称 比如banner上传就传 banner 返回的地址就会是bnanner/XXX", defaultValue = "test"),
@ApiImplicitParam(type = "form", dataType = "Integer", name = "buckType", value = "buckType 1正常的任何文件上传 2apk上传", defaultValue = "1"), @ApiImplicitParam(type = "form", dataType = "Integer", name = "buckType", value = "buckType 1正常的任何文件上传 2apk上传", defaultValue = "1"),
@ApiImplicitParam(type = "form", dataType = "Integer", name = "resize", value = "resize", defaultValue = "0"), @ApiImplicitParam(type = "form", dataType = "Integer", name = "resize", value = "resize", defaultValue = "0"),
@ApiImplicitParam(type = "form", dataType = "Integer", name = "isCutFrame", value = "是否截取帧数 用于视频获取图片 0不需要 1需要", defaultValue = "0"),
}) })
public ResponseDto<UploadVo> upload( public ResponseDto<UploadVo> upload(
@RequestParam MultipartFile file, @RequestParam MultipartFile file,
@RequestParam(defaultValue = "other") String pathName, @RequestParam(defaultValue = "other") String pathName,
@RequestParam(defaultValue = "1", required = false) int buckType, @RequestParam(defaultValue = "1", required = false) int buckType,
@RequestParam(defaultValue = "0", required = false) int resize @RequestParam(defaultValue = "0", required = false) int resize,
@RequestParam(defaultValue = "0", required = false) int isCutFrame
) { ) {
OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret); File fileNew = FilesUtils.multipartFileToFile(file);
if (null == fileNew) {
return ResponseDto.failure("上传失败");
}
File fileNew = null; // 是否上传过 有直接返回
try { PlatformOssFiles ossFile = this.getOldOssFile(fileNew);
fileNew = FilesUtils.multipartFileToFile(file); UploadVo uploadVo = new UploadVo();
} catch (Exception e) { if (null == ossFile) {
return null; // 上传
ossFile = this.uploadOssFile(file, pathName, buckType, resize, fileNew, isCutFrame);
} }
BeanUtils.copyProperties(ossFile, uploadVo);
// file md5 // 删除临时文件 因为老文件也生成了所以也要删除
String fileMD5 = FilesUtils.getFileMD5(fileNew); FilesUtils.deleteTempFile(fileNew);
return ResponseDto.success(uploadVo);
}
/**
* 获取老的上传文件
*
* @param file
* @return
*/
private PlatformOssFiles getOldOssFile(File file) {
String fileMD5 = FilesUtils.getFileMD5(file);
List<PlatformOssFiles> platformOssFiles = platformOssFilesMapper.selectList( List<PlatformOssFiles> platformOssFiles = platformOssFilesMapper.selectList(
Wrappers.lambdaQuery(PlatformOssFiles.class) Wrappers.lambdaQuery(PlatformOssFiles.class)
.eq(PlatformOssFiles::getMd5str, fileMD5) .eq(PlatformOssFiles::getMd5str, fileMD5)
); );
UploadVo uploadVo = new UploadVo();
if (CollectionUtils.isEmpty(platformOssFiles)) { if (CollectionUtils.isEmpty(platformOssFiles)) {
String filename = file.getResource().getFilename();// time.jpeg return null;
//这里文件名用了uuid 防止重复,可以根据自己的需要来写 } else {
String uploadName = UUID.randomUUID() + filename.substring(filename.lastIndexOf("."));// 078a77e0-cf80-481b-824c-5935247cff15.jpeg return platformOssFiles.get(0);
uploadName = uploadName.replace("-", "");// 078a77e0cf80481b824c5935247cff15.jpeg }
String uploadpath = pathName + "/" + DateUtil.format(LocalDateTime.now(), DateUtil.Formatter.yyyy_MM_dd2) + "/" + uploadName; }
String buckName = "img-zhengzai-tv";
if (2 == buckType) { /**
buckName = "app-zhengzai-tv"; * 上传文件
} *
PutObjectRequest putObjectRequest = new PutObjectRequest(buckName, uploadpath, fileNew); * @param file
ossClient.putObject(putObjectRequest); * @param pathName
if (resize > 0) { * @param buckType
// 将图片缩放 * @param resize
StringBuilder sbStyle = new StringBuilder(); * @param fileNew
Formatter styleFormatter = new Formatter(sbStyle); * @return
String styleType = "image/resize,w_" + resize; */
// String styleType = "image/resize,m_fixed,w_100,h_100"; private PlatformOssFiles uploadOssFile(MultipartFile file, String pathName, int buckType, int resize, File fileNew, int isCutFrame) {
styleFormatter.format("%s|sys/saveas,o_%s,b_%s", styleType, OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
BinaryUtil.toBase64String(uploadpath.getBytes()), String filename = "";
BinaryUtil.toBase64String(buckName.getBytes())); String contentType = "";
ProcessObjectRequest request = new ProcessObjectRequest(buckName, uploadpath, sbStyle.toString()); int size = 0;
GenericResult processResult = ossClient.processObject(request); if (null == file) {
filename = fileNew.getName();
Path fileNewPath = new File(fileNew.getPath()).toPath();
try {
contentType = Files.probeContentType(fileNewPath);
} catch (Exception e) {
} }
size = (int) fileNew.length();
} else {
filename = file.getResource().getFilename();
contentType = file.getContentType();
size = (int) file.getSize();
}
String uploadPath = FilesUtils.getUploadPath(pathName, filename);
String bucketName = FilesUtils.getBucketName(buckType);
PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, uploadPath, fileNew);
ossClient.putObject(putObjectRequest);
ossClient.shutdown(); if (resize > 0) { // 裁切
this.ossFileResize(resize, uploadPath, bucketName, ossClient);
}
// 入库 PlatformOssFiles ossFileVideoImg = null;
PlatformOssFiles platformOssFilesDate = new PlatformOssFiles(); if (isCutFrame > 0) { // 截取帧数
String ossFilesId = IDGenerator.nextSnowId(); ossFileVideoImg = this.ossFileCutFrame(uploadPath, pathName, buckType);
platformOssFilesDate.setOssFilesId(ossFilesId); }
platformOssFilesDate.setOssPath(uploadpath);
platformOssFilesDate.setFileName(filename);
platformOssFilesDate.setContentType(file.getContentType());
platformOssFilesDate.setSize((int) file.getSize());
platformOssFilesDate.setMd5str(fileMD5);
platformOssFilesDate.setBuckType(buckType);
platformOssFilesDate.setCreatedAt(DateUtil.getNowTime());
platformOssFilesMapper.insert(platformOssFilesDate);
BeanUtils.copyProperties(platformOssFilesDate, uploadVo); ossClient.shutdown();
} else {
PlatformOssFiles platformOssFilesOne = platformOssFiles.get(0); // 入库
BeanUtils.copyProperties(platformOssFilesOne, uploadVo); PlatformOssFiles platformOssFilesDate = new PlatformOssFiles();
String ossFilesId = IDGenerator.nextSnowId();
platformOssFilesDate.setOssFilesId(ossFilesId);
platformOssFilesDate.setOssPath(uploadPath);
if (null != ossFileVideoImg) {
platformOssFilesDate.setVideoImg(ossFileVideoImg.getOssPath());
} }
platformOssFilesDate.setFileName(filename);
platformOssFilesDate.setContentType(contentType);
platformOssFilesDate.setSize(size);
String fileMD5 = FilesUtils.getFileMD5(fileNew);
platformOssFilesDate.setMd5str(fileMD5);
platformOssFilesDate.setBuckType(buckType);
platformOssFilesDate.setCreatedAt(DateUtil.getNowTime());
platformOssFilesMapper.insert(platformOssFilesDate);
return platformOssFilesDate;
}
FilesUtils.delteTempFile(fileNew); // 删除临时文件 /**
* oss图片裁切
*
* @param resize
* @param uploadPath
* @param bucketName
* @param ossClient
* @return
*/
private GenericResult ossFileResize(int resize, String uploadPath, String bucketName, OSS ossClient) {
// 将图片缩放
StringBuilder sbStyle = new StringBuilder();
Formatter styleFormatter = new Formatter(sbStyle);
String styleType = "image/resize,w_" + resize;
// String styleType = "image/resize,m_fixed,w_100,h_100";
styleFormatter.format("%s|sys/saveas,o_%s,b_%s", styleType,
BinaryUtil.toBase64String(uploadPath.getBytes()),
BinaryUtil.toBase64String(bucketName.getBytes()));
ProcessObjectRequest request = new ProcessObjectRequest(bucketName, uploadPath, sbStyle.toString());
GenericResult processResult = ossClient.processObject(request);
return processResult;
}
return ResponseDto.success(uploadVo); private PlatformOssFiles ossFileCutFrame(String ossFileUrl, String pathName, int buckType) {
String style = "?x-oss-process=video/snapshot,t_0,f_jpg,w_0,h_0,m_fast,ar_auto";
File fileNew = FilesUtils.inputStreamToFile(imgUrl.concat(ossFileUrl).concat(style), System.currentTimeMillis() + ".jpg");
return this.uploadOssFile(null, pathName, buckType, 0, fileNew, 0);
} }
@PostMapping("/uploadUrl") @PostMapping("/uploadUrl")
...@@ -184,7 +258,7 @@ public class AlOssController { ...@@ -184,7 +258,7 @@ public class AlOssController {
BeanUtils.copyProperties(platformOssFilesOne, uploadVo); BeanUtils.copyProperties(platformOssFilesOne, uploadVo);
} }
FilesUtils.delteTempFile(fileNew); // 删除临时文件 FilesUtils.deleteTempFile(fileNew); // 删除临时文件
return ResponseDto.success(uploadVo); return ResponseDto.success(uploadVo);
} }
......
package com.liquidnet.service.platform.controller.sweet;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.feign.stone.api.FeignStoneIntegralClient;
import com.liquidnet.service.platform.utils.DataUtils;
import com.liquidnet.service.sweet.entity.SweetWechatUsers;
import com.liquidnet.service.sweet.mapper.SweetWechatUsersMapper;
import com.liquidnet.service.sweet.vo.SweetAppletUsersVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
/**
* <p>
* 关注任务加积分脚本
* </p>
*
* @author jiangxiulong
* @since 2021-12-28
*/
@Api(tags = "关注任务加积分脚本")
@Slf4j
@RestController
@RequestMapping("followDoTask")
public class TaskController {
@Autowired
private SweetWechatUsersMapper usersMapper;
@Autowired
private FeignStoneIntegralClient feignStoneIntegralClient;
@Autowired
private DataUtils dataUtils;
@GetMapping("doTask")
@ApiOperation("退款回调")
public ResponseDto doTask() {
int size = 1000;
LocalDateTime localDateTime = LocalDateTime.now();
LocalDateTime newTime = localDateTime.minusMinutes(10);
// String timeStr = "2021-12-28 00:00:00";
// DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
// LocalDateTime dateTime = LocalDateTime.parse(timeStr, df);
// 获取总记录数
Integer count = usersMapper.selectCount(
Wrappers.lambdaQuery(SweetWechatUsers.class)
.gt(SweetWechatUsers::getCreatedAt, newTime)
.eq(SweetWechatUsers::getType, 2)
);
// 总page
int countPage = (int) Math.ceil(count / size);
countPage = countPage + 1;
for (int page = 0; page < countPage; page++) {
List<SweetWechatUsers> sweetWechatUsers = usersMapper.selectList(
Wrappers.lambdaQuery(SweetWechatUsers.class)
.gt(SweetWechatUsers::getCreatedAt, newTime)
.last("limit " + (page * size) + "," + ((page + 1) * size))
);
for (SweetWechatUsers info : sweetWechatUsers) {
try {
SweetAppletUsersVo sweetAppletUsers = dataUtils.getSweetAppletUsersOfUnionId(info.getUnionId());
if (sweetAppletUsers != null) {
if (sweetAppletUsers.getUserId() != null && !sweetAppletUsers.getUserId().isEmpty()) {
log.info("followDoTask userId:{}", sweetAppletUsers.getUserId());
ResponseDto<HashMap<String, Object>> hashMapResponseDto = feignStoneIntegralClient.doTask(4, sweetAppletUsers.getUserId());
//log.info("followDoTask res:{}", hashMapResponseDto);
}
}
} catch (Exception e) {
}
}
}
return ResponseDto.success();
}
}
...@@ -13,6 +13,8 @@ import com.liquidnet.service.kylin.dto.vo.returns.KylinOrderListVo; ...@@ -13,6 +13,8 @@ import com.liquidnet.service.kylin.dto.vo.returns.KylinOrderListVo;
import com.liquidnet.service.kylin.entity.KylinBuyNotice; import com.liquidnet.service.kylin.entity.KylinBuyNotice;
import com.liquidnet.service.kylin.entity.KylinOrderCoupons; import com.liquidnet.service.kylin.entity.KylinOrderCoupons;
import com.liquidnet.service.kylin.mapper.KylinBuyNoticeMapper; import com.liquidnet.service.kylin.mapper.KylinBuyNoticeMapper;
import com.liquidnet.service.sweet.constant.SweetConstant;
import com.liquidnet.service.sweet.vo.SweetAppletUsersVo;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.data.mongodb.core.MongoTemplate;
...@@ -400,4 +402,15 @@ public class DataUtils { ...@@ -400,4 +402,15 @@ public class DataUtils {
return (ArrayList<KylinOrderCoupons>) obj; return (ArrayList<KylinOrderCoupons>) obj;
} }
} }
public SweetAppletUsersVo getSweetAppletUsersOfUnionId(String unionId) {
String redisKey = SweetConstant.REDIS_KEY_SWEET_APPLET_USERS_UNIONID.concat(unionId);
Object obj = redisDataSourceUtil.getRedisSweetUtil().get(redisKey);
if (null == obj) {
return null;
} else {
SweetAppletUsersVo sweetAppletUsersVo = (SweetAppletUsersVo) obj;
return sweetAppletUsersVo;
}
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment