You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

193 lines
7.7 KiB

3 years ago
package com.zh.project0512.controller;
import com.alibaba.fastjson.JSONObject;
3 years ago
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
3 years ago
//import com.zh.project0512.service.IUserService;
3 years ago
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
3 years ago
import com.zh.project0512.mapper.QywxDepartmentUserLinkMapper;
import com.zh.project0512.mapper.RankMapper;
3 years ago
import com.zh.project0512.mapper.UserMapper;
3 years ago
import com.zh.project0512.model.Rank;
3 years ago
import com.zh.project0512.model.Task;
3 years ago
import com.zh.project0512.model.UserPointsRecords;
import com.zh.project0512.model.Video;
3 years ago
import com.zh.project0512.model.dto.RankListDTO;
import com.zh.project0512.model.vo.RankListVo;
3 years ago
import com.zh.project0512.service.IRewardRuleService;
3 years ago
import com.zh.project0512.service.ITaskService;
3 years ago
import com.zh.project0512.service.IUserPointsRecordsService;
3 years ago
import com.zh.project0512.service.IVideoService;
3 years ago
import com.zh.project0512.utils.AliyunOss;
import com.zh.project0512.utils.FileTypeUtil;
import com.zh.project0512.utils.result.HttpStatusEnum;
import com.zh.project0512.utils.result.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
3 years ago
import org.jsoup.helper.StringUtil;
3 years ago
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
3 years ago
import org.springframework.transaction.annotation.Transactional;
3 years ago
import org.springframework.util.StringUtils;
3 years ago
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
3 years ago
import ws.schild.jave.MultimediaObject;
3 years ago
3 years ago
import javax.annotation.Resource;
3 years ago
import java.io.File;
3 years ago
import java.math.BigDecimal;
3 years ago
import java.time.LocalDateTime;
import java.time.ZoneOffset;
3 years ago
import java.time.format.DateTimeFormatter;
3 years ago
import java.util.*;
3 years ago
import java.util.regex.Matcher;
import java.util.regex.Pattern;
3 years ago
/**
* <p>
*
* </p>
*
* @author zh
* @since 2022-05-12
*/
@Tag(name = "工具中心")
@RestController
@RequestMapping("/util")
public class UtilsController {
@Autowired
3 years ago
private RedisTemplate<String, String> redisTemplate;
3 years ago
@Autowired
private AliyunOss aliyunOss;
3 years ago
@Value("${web.uploadPath}")
3 years ago
private String path;
3 years ago
@Value("${web.cdn}")
private String cdn;
3 years ago
3 years ago
@Operation(summary = "上传")
3 years ago
@PostMapping("/upload")
@ResponseBody
3 years ago
public Result upload(@RequestParam("file") MultipartFile file, @RequestParam(required = false) String name) {
if (file.isEmpty()) {
return Result.fail(HttpStatusEnum.CUSTOM_EXCEPTION, "请选择文件");
3 years ago
}
String fileName = file.getOriginalFilename();//文件名
3 years ago
String newFileName = UUID.randomUUID().toString().replace("-", "") + LocalDateTime.now().toInstant(ZoneOffset.ofHours(8)).toEpochMilli() + fileName.substring(fileName.lastIndexOf("."));
3 years ago
//String path = System.getProperty("user.home"); //文件存储位置 我放在了我的项目下
3 years ago
// //获取jar包所在目录
// ApplicationHome h = new ApplicationHome(getClass());
// File jarF = h.getSource();
// //在jar包所在目录下生成一个upload文件夹用来存储上传的图片
// String dirPath = jarF.getParentFile().toString()+"/upload/";
// System.out.println(dirPath);
// System.out.println(path);
// File dest = new File(dirPath+fileName);
3 years ago
File dest = new File(path + "/" + newFileName);
3 years ago
if (!dest.getParentFile().exists()) {
dest.getParentFile().mkdirs();
}
try {
file.transferTo(dest);
JSONObject res = new JSONObject();
3 years ago
int fileTypeNum = FileTypeUtil.getcontentTypeNum((fileName.substring(fileName.lastIndexOf("."))));
3 years ago
res.put("fileUrl", "/upload/" + newFileName);
3 years ago
res.put("fileName", fileName);
3 years ago
res.put("fileType", FileTypeUtil.getcontentType((fileName.substring(fileName.lastIndexOf(".")))));
3 years ago
res.put("fileTypeNum", fileTypeNum);
if (fileTypeNum == 1) {
3 years ago
res.put("duration", new MultimediaObject(dest).getInfo().getDuration());
3 years ago
}
3 years ago
return Result.success(res, "上传完成");
3 years ago
} catch (Exception e) {
3 years ago
e.printStackTrace();
}
3 years ago
return Result.fail(HttpStatusEnum.CUSTOM_EXCEPTION, "上传失败");
3 years ago
}
3 years ago
// @PostMapping("/uploadImg")
// public Result uploadImg(@RequestParam("file") MultipartFile file, @RequestParam(value = "name", defaultValue = "name") String name) {
// try {
// String homeImage = aliyunOss.checkImage(file);//此处是调用上传服务接口
// String fileUrl = aliyunOss.getImgUrl(homeImage);
// String fileType = FileTypeUtil.getcontentType((fileUrl.substring(fileUrl.lastIndexOf("."))));
// System.out.println(fileType == "video/mp4" ? 1 : (fileType == "image/jpg" ? 2 : (fileType == "text/plain" ? 3 : 0)));
// Result result = Result.success("上传成功!");
// return result;
// } catch (Exception e) {
// e.printStackTrace();
// return Result.fail(HttpStatusEnum.NOT_FOUND);
// }
// }
@Operation(summary = "编辑器内上传")
@PostMapping("/upload2")
@ResponseBody
public JSONObject upload2(@RequestParam("file") MultipartFile file, @RequestParam(required = false) String name) {
JSONObject res = new JSONObject();
3 years ago
res.put("errno", 1);
3 years ago
if (file.isEmpty()) {
3 years ago
res.put("message", "请选择文件");
3 years ago
return res;
}
String fileName = file.getOriginalFilename();//文件名
String newFileName = UUID.randomUUID().toString().replace("-", "") + LocalDateTime.now().toInstant(ZoneOffset.ofHours(8)).toEpochMilli() + fileName.substring(fileName.lastIndexOf("."));
File dest = new File(path + "/" + newFileName);
if (!dest.getParentFile().exists()) {
dest.getParentFile().mkdirs();
}
3 years ago
try {
3 years ago
file.transferTo(dest);
3 years ago
res.replace("errno", 0);
3 years ago
JSONObject obj = new JSONObject();
obj.put("alt", fileName);
3 years ago
obj.put("url", cdn + "/upload/" + newFileName);
res.put("data", obj);
3 years ago
return res;
3 years ago
} catch (Exception e) {
3 years ago
e.printStackTrace();
}
3 years ago
res.put("message", "上传失败");
3 years ago
return res;
3 years ago
}
3 years ago
3 years ago
@Autowired
private ITaskService taskService;
@Resource
QywxDepartmentUserLinkMapper qywxDepartmentUserLinkMapper;
@Resource
RankMapper rankMapper;
@Autowired
private IVideoService videoService;
3 years ago
3 years ago
@PostMapping("/test")
@ResponseBody
3 years ago
public Result test() {
3 years ago
String url ="http://www.baidu.com/#wd=%E6%88%91%E6%98%AF%E6%AD%8C%E6%89%8B&rsv_bp=0&tn=baidu&rsv_spt=3&ie=utf-8&rsv_sug3=11&rsv_sug4=643&rsv_sug1=11&inputT=5484&rsv_sug2=0";
Pattern p = Pattern.compile("(http://|https://)?([^/]*)",Pattern.CASE_INSENSITIVE);
Matcher m = p.matcher(url);
String a= m.find()?m.group(2):url;
// (https://)+\S*\s
return Result.success(a);
3 years ago
}
3 years ago
3 years ago
// public static void main(String[] args) {
// String url ="9.20 tRK:/ 男人第一天上班就被当成修电脑的,谁知他竟然是总经理%好剧推荐 %全集解说%幸福一家人%关于爱情%宅家dou剧 %持续关注持续精彩 https://v.kuaishou.com/Yh4DwM9/ 复制此链接打开Dou音搜索直接观看视频";
// Pattern p = Pattern.compile("((https://)+\\S*\\s)",Pattern.CASE_INSENSITIVE);
//
// Matcher m = p.matcher(url);
//System.out.println(m);
// String a= m.find()?m.group(1):url;
// System.out.println(a);
// int b = StringUtils.countOccurrencesOf(a,"https://v.douyin");
// System.out.println(b);
// }
3 years ago
}