|
|
|
package com.zh.project0512.controller;
|
|
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
import com.baomidou.mybatisplus.annotation.TableField;
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
//import com.zh.project0512.service.IUserService;
|
|
|
|
import com.zh.project0512.mapper.QywxDepartmentGroupLinkMapper;
|
|
|
|
import com.zh.project0512.mapper.QywxDepartmentUserLinkMapper;
|
|
|
|
import com.zh.project0512.mapper.RankMapper;
|
|
|
|
import com.zh.project0512.model.Rank;
|
|
|
|
import com.zh.project0512.model.Task;
|
|
|
|
import com.zh.project0512.model.dto.RankListDTO;
|
|
|
|
import com.zh.project0512.model.vo.RankListVo;
|
|
|
|
import com.zh.project0512.service.IQywxDepartmentGroupLinkService;
|
|
|
|
import com.zh.project0512.service.IRewardRuleService;
|
|
|
|
import com.zh.project0512.service.ITaskService;
|
|
|
|
import com.zh.project0512.service.IVideoService;
|
|
|
|
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.media.Schema;
|
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
|
import lombok.Data;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
import ws.schild.jave.MultimediaObject;
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
import java.io.File;
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
import java.time.ZoneOffset;
|
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* <p>
|
|
|
|
* 前端控制器
|
|
|
|
* </p>
|
|
|
|
*
|
|
|
|
* @author zh
|
|
|
|
* @since 2022-05-12
|
|
|
|
*/
|
|
|
|
@Tag(name = "工具中心")
|
|
|
|
@RestController
|
|
|
|
@RequestMapping("/util")
|
|
|
|
public class UtilsController {
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
private RedisTemplate<String, String> redisTemplate;
|
|
|
|
@Autowired
|
|
|
|
private AliyunOss aliyunOss;
|
|
|
|
|
|
|
|
@Value("${web.uploadPath}")
|
|
|
|
private String path;
|
|
|
|
@Value("${web.cdn}")
|
|
|
|
private String cdn;
|
|
|
|
|
|
|
|
@Operation(summary = "上传")
|
|
|
|
@PostMapping("/upload")
|
|
|
|
@ResponseBody
|
|
|
|
public Result upload(@RequestParam("file") MultipartFile file, @RequestParam(required = false) String name) {
|
|
|
|
if (file.isEmpty()) {
|
|
|
|
return Result.fail(HttpStatusEnum.CUSTOM_EXCEPTION, "请选择文件");
|
|
|
|
}
|
|
|
|
String fileName = file.getOriginalFilename();//文件名
|
|
|
|
String newFileName = UUID.randomUUID().toString().replace("-", "") + LocalDateTime.now().toInstant(ZoneOffset.ofHours(8)).toEpochMilli() + fileName.substring(fileName.lastIndexOf("."));
|
|
|
|
//String path = System.getProperty("user.home"); //文件存储位置 我放在了我的项目下
|
|
|
|
// //获取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);
|
|
|
|
File dest = new File(path + "/" + newFileName);
|
|
|
|
if (!dest.getParentFile().exists()) {
|
|
|
|
dest.getParentFile().mkdirs();
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
file.transferTo(dest);
|
|
|
|
JSONObject res = new JSONObject();
|
|
|
|
int fileTypeNum = FileTypeUtil.getcontentTypeNum((fileName.substring(fileName.lastIndexOf("."))));
|
|
|
|
res.put("fileUrl", "/upload/" + newFileName);
|
|
|
|
res.put("fileName", fileName);
|
|
|
|
res.put("fileType", FileTypeUtil.getcontentType((fileName.substring(fileName.lastIndexOf(".")))));
|
|
|
|
res.put("fileTypeNum", fileTypeNum);
|
|
|
|
if (fileTypeNum == 1) {
|
|
|
|
res.put("duration", new MultimediaObject(dest).getInfo().getDuration());
|
|
|
|
}
|
|
|
|
return Result.success(res, "上传完成");
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
return Result.fail(HttpStatusEnum.CUSTOM_EXCEPTION, "上传失败");
|
|
|
|
}
|
|
|
|
|
|
|
|
// @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();
|
|
|
|
res.put("errno", 1);
|
|
|
|
if (file.isEmpty()) {
|
|
|
|
res.put("message", "请选择文件");
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
file.transferTo(dest);
|
|
|
|
res.replace("errno", 0);
|
|
|
|
JSONObject obj = new JSONObject();
|
|
|
|
obj.put("alt", fileName);
|
|
|
|
obj.put("url", cdn + "/upload/" + newFileName);
|
|
|
|
res.put("data", obj);
|
|
|
|
return res;
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
res.put("message", "上传失败");
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
private ITaskService taskService;
|
|
|
|
@Resource
|
|
|
|
QywxDepartmentUserLinkMapper qywxDepartmentUserLinkMapper;
|
|
|
|
@Resource
|
|
|
|
RankMapper rankMapper;
|
|
|
|
@Autowired
|
|
|
|
private IVideoService videoService;
|
|
|
|
@Autowired
|
|
|
|
private IRewardRuleService rewardRuleService;
|
|
|
|
@Autowired
|
|
|
|
private IQywxDepartmentGroupLinkService qywxDepartmentGroupLinkService;
|
|
|
|
@PostMapping("/test")
|
|
|
|
@ResponseBody
|
|
|
|
public Result test() {
|
|
|
|
//获取员工排名进排名数据库
|
|
|
|
QueryWrapper<RankListDTO> queryWrapper = new QueryWrapper<>();
|
|
|
|
queryWrapper.eq("date_format(v.creatAt, '%Y-%m')", LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM")));
|
|
|
|
queryWrapper.groupBy("u.id");
|
|
|
|
queryWrapper.orderByDesc("value");
|
|
|
|
List<RankListVo> rankUserList = qywxDepartmentUserLinkMapper.getUserRankList(queryWrapper);
|
|
|
|
ArrayList<Rank> list = new ArrayList<>();
|
|
|
|
if (rankUserList != null && rankUserList.size() > 0) {
|
|
|
|
for (RankListVo e : rankUserList) {
|
|
|
|
new Rank().setTitle(e.getTitle()).setSubtitle(e.getSubtitle()).setLinkId(e.getLinkId()).setValue(e.getValue()).setCreateDate(LocalDateTime.now());
|
|
|
|
// list.add();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Result.success(rankUserList);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Data
|
|
|
|
static class Param {
|
|
|
|
@Schema(title="接受任务部门列表")
|
|
|
|
private List<Integer> departmentList;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
private QywxDepartmentGroupLinkMapper qywxDepartmentGroupLinkMapper;
|
|
|
|
@PostMapping("/test2")
|
|
|
|
@ResponseBody
|
|
|
|
public Result test2(@RequestBody Param param) {
|
|
|
|
List departmentIdList = qywxDepartmentGroupLinkService.departmentIdList(0,param.getDepartmentList());
|
|
|
|
// QueryWrapper<Task> qw = new QueryWrapper<>();
|
|
|
|
// LocalDateTime now = LocalDateTime.now().minusWeeks(1);
|
|
|
|
// String format = now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
|
|
|
// qw.eq("date_format(end, '%Y-%m-%d')", format);
|
|
|
|
// List<Task> taskList = taskService.list(qw);
|
|
|
|
// // 处理每个任务的传播值
|
|
|
|
//
|
|
|
|
// // 生成奖励流水并更新给用户积分
|
|
|
|
// for (Task t : taskList) {
|
|
|
|
// Integer taskId = t.getId();
|
|
|
|
// List<Map> videoEffectResult = videoService.videoEffectResult(taskId);
|
|
|
|
// List<Map> rewardRule = rewardRuleService.listByTemplateId(t.getRewardRuleTemplateId());
|
|
|
|
//
|
|
|
|
// System.out.println("videoEffectResult" + videoEffectResult);
|
|
|
|
// // 处理任务中每个用户的传播值
|
|
|
|
// for (Map m : videoEffectResult) {
|
|
|
|
// if (m.get("effectResultSum") != null && (Integer) m.get("effectResultSum") != 0) {
|
|
|
|
// int point = 0;
|
|
|
|
// int effectResultSum = (Integer) m.get("effectResultSum");
|
|
|
|
// // 根据传播值计算规则算出奖励
|
|
|
|
// for (Map r : rewardRule) {
|
|
|
|
// if (effectResultSum > (Integer) r.get("limitNum")) {
|
|
|
|
// point = (Integer) r.get("reward");
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
return Result.success();
|
|
|
|
}
|
|
|
|
}
|