zhangjinli 3 years ago
parent 4a539d0b09
commit 618718c1cb

@ -8,15 +8,20 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.additional.query.impl.LambdaQueryChainWrapper;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.zh.project0512.annotation.tokenValid;
import com.zh.project0512.model.*;
import com.zh.project0512.service.IReferenceBrandService;
import com.zh.project0512.service.IReferenceGroupService;
import com.zh.project0512.service.IReferenceService;
import com.zh.project0512.service.IReferenceTagService;
import com.zh.project0512.utils.FileTypeUtil;
import com.zh.project0512.utils.JwtUtil;
import com.zh.project0512.utils.MybatisPlusUtil;
import com.zh.project0512.utils.result.HttpStatusEnum;
import com.zh.project0512.utils.result.Result;
import io.jsonwebtoken.Claims;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Schema;
@ -24,17 +29,14 @@ import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -203,7 +205,9 @@ public class ReferenceController {
@Operation(summary = "素材列表")
@PostMapping("/list")
public Result list(@Validated @RequestBody ListRParam param) {
@tokenValid
public Result list(@Validated @RequestBody ListRParam param,@RequestHeader("token") @Parameter(name = "登录token") String token) {
Claims claims = new JwtUtil().parseJWT(token);
QueryWrapper<Reference> queryWrapper = new QueryWrapper<>();
JSONObject obj = new JSONObject();
obj.put("pageNum",param.getPageNum());
@ -218,7 +222,7 @@ public class ReferenceController {
}
@Data
static class DetTaskParam {
static class DetPParam {
@NotNull(message = "id不能为空")
@Min(value = 1, message = "id最小值为1")
@Schema(title = "素材id")
@ -227,10 +231,27 @@ public class ReferenceController {
@Operation(summary = "详情")
@PostMapping("/detail")
public Result detail(@Validated @RequestBody TaskController.DetTaskParam param) {
public Result detail(@Validated @RequestBody DetPParam param) {
int id =param.getId();
Reference reference = referenceService.getById(id);
return reference != null ? Result.success(reference.setBrandList(referenceBrandService.selByReferenceId(id)).setTagList(referenceTagService.selByReferenceId(id))) : Result.fail(HttpStatusEnum.NOT_FOUND);
}
@Data
static class DetaPParam {
@NotNull(message = "日期不能为空")
@Schema(title = "日期")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern="yyyy-MM-dd HH:mm:ss")
private LocalDateTime date;
}
@Operation(summary = "按日期查询")
@PostMapping("/date")
public Result detail(@Validated @RequestBody DetaPParam param) {
LocalDateTime dayBegin = LocalDateTime.of(param.getDate().toLocalDate(), LocalTime.MIN);
LocalDateTime dayLast = LocalDateTime.of(param.getDate().toLocalDate(), LocalTime.MAX);
List<Reference> list = referenceService.lambdaQuery().between(Reference::getCreatAt, dayBegin, dayLast).list();
return Result.success(list);
}
}

@ -2,12 +2,17 @@ package com.zh.project0512.controller;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.zh.project0512.annotation.tokenValid;
import com.zh.project0512.model.*;
import com.zh.project0512.service.*;
import com.zh.project0512.utils.FileTypeUtil;
import com.zh.project0512.utils.JwtUtil;
import com.zh.project0512.utils.MybatisPlusUtil;
import com.zh.project0512.utils.result.HttpStatusEnum;
@ -77,6 +82,123 @@ public class TaskController {
@Schema(title = "任务id")
private Integer id;
}
@Data
static class AddTaskTagParam {
@NotNull(message = "id不能为空")
@Min(value = 1, message = "id最小值为1")
@Schema(title = "任务id")
private Integer id;
@NotNull(message = "tagId不能为空")
@Min(value = 1, message = "tagId最小值为1")
@Schema(title = "标签id")
private Integer tagId;
}
@Operation(summary = "新增任务标签")
@PostMapping("/addTag")
public Result addTag(@Validated @RequestBody AddTaskTagParam param) {
Integer taskId = param.getId();
Integer tagId = param.getTagId();
if (null != taskTagService.getMap(Wrappers.<TaskTag>query().lambda().eq(TaskTag::getTaskId, taskId).eq(TaskTag::getTagId, tagId))) {
return Result.success("数据已存在");
}
taskTagService.saveOrUpdate(new TaskTag().setTaskId(taskId).setTagId(tagId));
return Result.success("添加完成");
}
@Data
static class AddTaskBrandParam {
@NotNull(message = "id不能为空")
@Min(value = 1, message = "id最小值为1")
@Schema(title = "任务id")
private Integer id;
@NotNull(message = "brandId不能为空")
@Min(value = 1, message = "brandId最小值为1")
@Schema(title = "品牌id")
private Integer brandId;
}
@Operation(summary = "新增任务品牌")
@PostMapping("/addBrand")
public Result addBrand(@Validated @RequestBody AddTaskBrandParam param) {
Integer taskId = param.getId();
Integer brandId = param.getBrandId();
if (null != taskBrandService.getMap(Wrappers.<TaskBrand>query().lambda().eq(TaskBrand::getTaskId, taskId).eq(TaskBrand::getBrandId, brandId))) {
return Result.success("数据已存在");
}
taskBrandService.saveOrUpdate(new TaskBrand().setTaskId(taskId).setBrandId(brandId).setCreatAt(LocalDateTime.now()));
return Result.success("添加完成");
}
@Data
static class DelTaskTagParam {
@NotNull(message = "id不能为空")
@Min(value = 1, message = "id最小值为1")
@Schema(title = "任务id")
private Integer id;
@NotNull(message = "tagId不能为空")
@Min(value = 1, message = "tagId最小值为1")
@Schema(title = "标签id")
private Integer tagId;
}
@Operation(summary = "删除任务标签")
@PostMapping("/delTag")
public Result delTag(@Validated @RequestBody DelTaskTagParam param) {
return MybatisPlusUtil.sqlResult(taskTagService.remove(Wrappers.<TaskTag>query().lambda().eq(TaskTag::getTaskId, param.getId()).eq(TaskTag::getTagId, param.getTagId())), "删除");
}
@Data
static class DelTaskBrandParam {
@NotNull(message = "id不能为空")
@Min(value = 1, message = "id最小值为1")
@Schema(title = "任务id")
private Integer id;
@NotNull(message = "brandId不能为空")
@Min(value = 1, message = "brandId最小值为1")
@Schema(title = "品牌id")
private Integer brandId;
}
@Operation(summary = "删除任务品牌")
@PostMapping("/delBrand")
public Result delBrand(@Validated @RequestBody DelTaskBrandParam param) {
return MybatisPlusUtil.sqlResult(taskBrandService.remove(Wrappers.<TaskBrand>query().lambda().eq(TaskBrand::getTaskId, param.getId()).eq(TaskBrand::getBrandId, param.getBrandId())), "删除");
}
@Data
static class UpdTaskParam {
@NotNull(message = "id不能为空")
@Min(value = 1, message = "id最小值为1")
@Schema(title = "任务id")
private Integer id;
@Schema(title = "标题")
private String title;
@Schema(title = "副标题")
private String subtitle;
@Schema(title = "封面图片地址")
private String coverUrl;
@Schema(title="开始时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime start;
@Schema(title="结束时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime end;
@Schema(title="奖励模版id")
private Integer rewardRuleTemplateId;
}
@Operation(summary = "更新")
@PostMapping("/upd")
public Result upd(@Validated @RequestBody UpdTaskParam param) {
int id = param.getId();
Task task = new Task().setTitle(param.getTitle());
// .setSubtitle(param.getSubtitle()).setCoverUrl(param.getCoverUrl())
// .setStart(param.getStart()).setEnd(param.getEnd()).setRewardRuleTemplateId(param.getRewardRuleTemplateId()).setUpdateAt(LocalDateTime.now());
UpdateWrapper<Task> updateWrapper = new UpdateWrapper<>();
updateWrapper.eq("id", id);
return MybatisPlusUtil.sqlResult(taskService.update(task, updateWrapper), "修改");
}
@Operation(summary = "删除")
@PostMapping("/del")

@ -17,6 +17,6 @@ import org.apache.ibatis.annotations.Select;
* @since 2022-05-23
*/
public interface ReferenceMapper extends BaseMapper<Reference> {
// @Select("select t1.* ,t2.tagId from reference t1 left join referenceTag t2 on t1.id = t2.referenceId")
// @Select("select t1.* ,t2.tagId from reference t1 left join referenceTag t2 on t1.id = t2.referenceId ORDER BY creatAt DESC")
IPage<Reference> selectPage(IPage<Reference> page, @Param("ew") Wrapper<Reference> queryWrapper);
}

@ -85,6 +85,14 @@ public class Task extends Model {
@TableField("rewardRuleTemplateId")
private int rewardRuleTemplateId;
@TableField("creatAt")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime creatAt;
@TableField("updateAt")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime updateAt;
@Schema(title="标签列表")
@TableField(exist = false)
private List tagList;

Loading…
Cancel
Save