zhangjinli 3 years ago
parent f3739a5f81
commit 1c2d971f29

@ -24,6 +24,9 @@ import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.IOException;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.UUID;
/**
* <p>
@ -40,23 +43,22 @@ public class UtilsController {
@Autowired
private RedisTemplate<String,String> redisTemplate;
private RedisTemplate<String, String> redisTemplate;
@Autowired
private AliyunOss aliyunOss;
@Value("${web.uploadPath}")
private String path;
@Operation(summary="上传")
@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,"请选择文件");
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();//文件名
// fileName=name;//图片名
// String suffixName = fileName.substring(fileName.lastIndexOf("."));//后缀名
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());
@ -66,31 +68,31 @@ public class UtilsController {
// System.out.println(dirPath);
// System.out.println(path);
// File dest = new File(dirPath+fileName);
File dest = new File(path+"/"+fileName);
File dest = new File(path + "/" + fileName);
if (!dest.getParentFile().exists()) {
dest.getParentFile().mkdirs();
}
try {
file.transferTo(dest);
JSONObject res = new JSONObject();
res.put("fileName",fileName);
res.put("fileUrl","/upload/"+fileName);
res.put("fileName", fileName);
res.put("fileUrl", "/upload/" + newFileName);
res.put("fileType", FileTypeUtil.getcontentType((fileName.substring(fileName.lastIndexOf(".")))));
res.put("fileTypeNum", FileTypeUtil.getcontentTypeNum((fileName.substring(fileName.lastIndexOf(".")))));
return Result.success(res,"上传完成");
return Result.success(res, "上传完成");
} catch (IOException e) {
e.printStackTrace();
}
return Result.fail(HttpStatusEnum.CUSTOM_EXCEPTION,"上传失败");
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)));
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) {
@ -99,13 +101,6 @@ public class UtilsController {
}
}
// @PostMapping("/add")
// public JSONResult add(@RequestParam String name){
// User u = new User();
// u.setName(name);
// userService.save(u);
// return JSONResult.ok();
// }
@PostMapping("/redis")
public void testString() {
ValueOperations<String, String> stringOps = redisTemplate.opsForValue();
@ -114,7 +109,7 @@ public class UtilsController {
System.out.println(stringOps.get("name"));
}
@Scheduled(fixedRate = 10000) //每10秒执行一次
@Scheduled(fixedRate = 60000) //每60秒执行一次
// @Scheduled(cron = "0 0 0 * * ?")
public void updDailyRank() {
System.out.println("进行中...");

@ -1,4 +1,4 @@
package com.zh.project0512.controller;
package com.zh.project0512.controller.manage;
import com.alibaba.fastjson.JSONObject;

@ -1,4 +1,4 @@
package com.zh.project0512.controller;
package com.zh.project0512.controller.manage;
import org.springframework.web.bind.annotation.RequestMapping;

@ -1,4 +1,4 @@
package com.zh.project0512.controller;
package com.zh.project0512.controller.manage;
import com.zh.project0512.utils.result.Result;
import io.swagger.v3.oas.annotations.tags.Tag;

@ -1,4 +1,4 @@
package com.zh.project0512.controller;
package com.zh.project0512.controller.manage;
import com.zh.project0512.utils.result.Result;
import io.swagger.v3.oas.annotations.tags.Tag;

@ -1,4 +1,4 @@
package com.zh.project0512.controller;
package com.zh.project0512.controller.manage;
import org.springframework.web.bind.annotation.RequestMapping;

@ -1,4 +1,4 @@
package com.zh.project0512.controller;
package com.zh.project0512.controller.manage;
import com.alibaba.fastjson.JSONObject;

@ -1,4 +1,4 @@
package com.zh.project0512.controller;
package com.zh.project0512.controller.manage;
import com.alibaba.fastjson.JSONObject;

@ -1,4 +1,4 @@
package com.zh.project0512.controller;
package com.zh.project0512.controller.manage;
import org.springframework.web.bind.annotation.RequestMapping;

@ -1,4 +1,4 @@
package com.zh.project0512.controller;
package com.zh.project0512.controller.manage;
import com.zh.project0512.service.IRewardRuleService;

@ -1,14 +1,10 @@
package com.zh.project0512.controller;
package com.zh.project0512.controller.manage;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zh.project0512.model.Reference;
import com.zh.project0512.model.RewardRule;
import com.zh.project0512.model.RewardRuleTemplate;
import com.zh.project0512.model.Task;
import com.zh.project0512.service.IRewardRuleService;
import com.zh.project0512.service.IRewardRuleTemplateService;
import com.zh.project0512.utils.MybatisPlusUtil;
@ -33,7 +29,6 @@ import javax.validation.constraints.Min;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;
/**

@ -1,4 +1,4 @@
package com.zh.project0512.controller;
package com.zh.project0512.controller.manage;
import com.alibaba.fastjson.JSONObject;

@ -1,4 +1,4 @@
package com.zh.project0512.controller;
package com.zh.project0512.controller.manage;
import org.springframework.web.bind.annotation.RequestMapping;

@ -1,4 +1,4 @@
package com.zh.project0512.controller;
package com.zh.project0512.controller.manage;
import com.alibaba.fastjson.JSONObject;
@ -54,6 +54,8 @@ public class TaskController {
@Autowired
private ITaskService taskService;
@Autowired
private IUserTaskService userTaskService;
@Autowired
private ITaskTagService taskTagService;
@Autowired
private ITaskBrandService taskBrandService;
@ -250,12 +252,23 @@ public class TaskController {
@Operation(summary = "详情")
@PostMapping("/detail")
public Result detail(@Validated @RequestBody DetTaskParam param) {
public Result detail(@Validated @RequestBody DetTaskParam param,@RequestHeader(value = "token",required = false) @Parameter(name = "登录token") String token) {
int id = param.getId();
Task task = taskService.getById(id);
if (null == task) {
return Result.fail(HttpStatusEnum.NOT_FOUND);
}
if(token !=null) {
task.setIsReceived(0);
Claims claims = new JwtUtil().parseJWT(token);
Integer userId = userService.selByOpenid(claims.getId()).getId();
QueryWrapper<UserTask> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("userId", userId).eq("taskId", id);
UserTask userTask = userTaskService.getOne(queryWrapper);
if (userTask != null) {
task.setIsReceived(1);
}
}
List tagList = taskTagService.selByTaskId(id);
List brandList = taskBrandService.selByTaskId(id);
List<Map> referenceList = taskReferenceService.listByTaskId(id);

@ -1,4 +1,4 @@
package com.zh.project0512.controller;
package com.zh.project0512.controller.manage;
import org.springframework.web.bind.annotation.RequestMapping;

@ -1,4 +1,4 @@
package com.zh.project0512.controller;
package com.zh.project0512.controller.manage;
import org.springframework.web.bind.annotation.RequestMapping;

@ -1,4 +1,4 @@
package com.zh.project0512.controller;
package com.zh.project0512.controller.manage;
import com.alibaba.fastjson.JSONObject;
@ -8,7 +8,6 @@ import com.zh.project0512.utils.MybatisPlusUtil;
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.Parameter;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.Data;

@ -1,4 +1,4 @@
package com.zh.project0512.controller;
package com.zh.project0512.controller.manage;
import com.alibaba.fastjson.JSONObject;

@ -1,4 +1,4 @@
package com.zh.project0512.controller;
package com.zh.project0512.controller.manage;
import com.alibaba.fastjson.JSONObject;

@ -1,4 +1,4 @@
package com.zh.project0512.controller;
package com.zh.project0512.controller.manage;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

@ -1,4 +1,4 @@
package com.zh.project0512.controller;
package com.zh.project0512.controller.manage;
import com.alibaba.fastjson.JSONObject;

@ -26,10 +26,10 @@
SELECT
t1.id,t1.title,t1.rewardRuleTemplateId,t1.subtitle,t1.start,t1.end,t1.status,t2.tagId,t2.title as
tagTitle,t3.brandId,t3.name as brandName,t3.hot,t3.hits
<!-- <if test='openid!=null'>-->
<if test='openid!=null'>
,(SELECT count(*)!=0 from userTask as t4,user as t5 WHERE t1.id = t4.taskId and t4.userId = t5.id and t5.openid
= #{openid} ) as isReceived
<!-- </if>-->
</if>
from task as t1
left JOIN ( SELECT taskTag.*,tag.title from tag,taskTag WHERE taskTag.tagId = tag.id ) AS t2
on t1.id =t2.taskId

Loading…
Cancel
Save