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.
147 lines
4.9 KiB
147 lines
4.9 KiB
package com.zh.project0512.controller;
|
|
|
|
|
|
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.Task;
|
|
import com.zh.project0512.model.TaskTag;
|
|
import com.zh.project0512.service.*;
|
|
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;
|
|
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.*;
|
|
|
|
import javax.validation.Valid;
|
|
import javax.validation.constraints.DecimalMin;
|
|
import javax.validation.constraints.Min;
|
|
import javax.validation.constraints.NotNull;
|
|
import java.util.*;
|
|
|
|
/**
|
|
* <p>
|
|
* 前端控制器
|
|
* </p>
|
|
*
|
|
* @author zh
|
|
* @since 2022-05-21
|
|
*/
|
|
@Tag(name="任务管理")
|
|
@Validated
|
|
@RestController
|
|
@RequestMapping("/task")
|
|
public class TaskController {
|
|
@Autowired
|
|
private ITaskService taskService;
|
|
@Autowired
|
|
private ITaskTagService taskTagService;
|
|
@Autowired
|
|
private ITaskBrandService taskBrandService;
|
|
@Autowired
|
|
private ITaskReferenceService taskReferenceService;
|
|
@Autowired
|
|
private IRewardRuleService rewardRuleService;
|
|
@Autowired
|
|
private IRewardRuleTemplateService rewardRuleTemplateService;
|
|
|
|
@Operation(summary = "新增")
|
|
@PostMapping("/add")
|
|
public Result add(@Validated @RequestBody Task task) {
|
|
taskService.save(task);
|
|
int id = task.getId();
|
|
taskTagService.addGroup(task.getTagList(), id);
|
|
taskBrandService.addGroup(task.getReferenceList(), id);
|
|
taskReferenceService.addGroup(task.getBrandList(), id);
|
|
return Result.success("添加完成");
|
|
}
|
|
|
|
@Data
|
|
static class DelTaskParam {
|
|
@NotNull(message = "id不能为空")
|
|
@Min(value = 1, message = "id最小值为1")
|
|
@Schema(title = "任务id")
|
|
private Integer id;
|
|
}
|
|
@Operation(summary = "删除")
|
|
@PostMapping("/del")
|
|
public Result del(@Validated @RequestBody DelTaskParam param) {
|
|
return MybatisPlusUtil.sqlResult(taskService.removeById(param.getId()), "删除");
|
|
}
|
|
|
|
@Operation(summary = "列表")
|
|
@PostMapping("/list")
|
|
public Result list(@RequestBody(required = false) JSONObject obj,
|
|
@RequestHeader(required = false,value="token") @Parameter(name="用户token",description = "关联用户信息") String token) {
|
|
Claims claims = new JwtUtil().parseJWT(token);
|
|
String openid = null;
|
|
if(claims != null){
|
|
openid =claims.getId();
|
|
}
|
|
IPage ipage = taskService.taskIdList(MybatisPlusUtil.SetPage(obj));
|
|
List taskIdList = ipage.getRecords();
|
|
if(taskIdList.size()>0){
|
|
ipage.setRecords(taskService.taskList(openid,taskIdList));
|
|
}
|
|
return Result.success(ipage);
|
|
}
|
|
|
|
@Data
|
|
static class DetTaskParam {
|
|
@NotNull(message = "id不能为空")
|
|
@Min(value = 1, message = "id最小值为1")
|
|
@Schema(title = "任务id")
|
|
private Integer id;
|
|
}
|
|
|
|
@Operation(summary = "详情")
|
|
@PostMapping("/detail")
|
|
public Result detail(@Validated @RequestBody DetTaskParam param) {
|
|
int id =param.getId();
|
|
Task task = taskService.getById(id);
|
|
if (null == task) {
|
|
return Result.fail(HttpStatusEnum.NOT_FOUND);
|
|
}
|
|
List tagList = taskTagService.selByTaskId(id);
|
|
List brandList = taskBrandService.selByTaskId(id);
|
|
List<Map> referenceList = taskReferenceService.listByTaskId(id);
|
|
List rewardRulesList = rewardRuleService.listByTemplateId(task.getRewardRuleTemplateId());
|
|
JSONObject obj = (JSONObject) JSONObject.toJSON(task);
|
|
obj.put("tagList", tagList);
|
|
obj.put("brandList", brandList);
|
|
obj.put("referenceList", referenceList);
|
|
obj.put("rewardRuleList", rewardRulesList);
|
|
return Result.success(obj);
|
|
}
|
|
|
|
// @Data
|
|
// static class StatusTaskParam {
|
|
// @NotNull(message = "id不能为空")
|
|
// @Min(value = 1, message = "id最小值为1")
|
|
// @Schema(title = "任务id")
|
|
// private Integer id;
|
|
// @Schema(title = "任务id")
|
|
// private Integer id;
|
|
// @Schema(title = "任务id")
|
|
// private Integer id;
|
|
// }
|
|
//
|
|
// @Operation(summary = "详情")
|
|
// @PostMapping("/detail")
|
|
// public Result detail(@Validated @RequestBody StatusTaskParam param) {
|
|
//
|
|
// }
|
|
}
|
|
|