From cb200c613d5df9be9309591af17848ec346595a0 Mon Sep 17 00:00:00 2001 From: zhangjinli Date: Thu, 9 Jun 2022 17:33:58 +0800 Subject: [PATCH] zh --- .../controller/manage/TaskController.java | 70 +++++++++---------- .../controller/wxApp/TaskUController.java | 40 +++++++++-- .../controller/wxApp/UserUController.java | 16 +++-- .../project0512/mapper/ReferenceMapper.java | 8 +-- .../com/zh/project0512/mapper/TaskMapper.java | 35 ++++++++-- .../zh/project0512/service/ITaskService.java | 6 +- .../serviceImpl/TaskServiceImpl.java | 15 ++-- src/main/resources/mapper/ReferenceMapper.xml | 8 +-- src/main/resources/mapper/TaskMapper.xml | 33 +++++++-- .../resources/mapper/UserReferenceMapper.xml | 38 ++++++++++ 10 files changed, 184 insertions(+), 85 deletions(-) create mode 100644 src/main/resources/mapper/UserReferenceMapper.xml diff --git a/src/main/java/com/zh/project0512/controller/manage/TaskController.java b/src/main/java/com/zh/project0512/controller/manage/TaskController.java index c46858f..95aff85 100644 --- a/src/main/java/com/zh/project0512/controller/manage/TaskController.java +++ b/src/main/java/com/zh/project0512/controller/manage/TaskController.java @@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.zh.project0512.annotation.tokenValid; +import com.zh.project0512.controller.wxApp.TaskUController; import com.zh.project0512.model.*; import com.zh.project0512.model.validatedDemo.TaskValidGroup1; import com.zh.project0512.model.validatedDemo.TaskValidGroup2; @@ -218,16 +219,40 @@ public class TaskController { return MybatisPlusUtil.sqlResult(taskService.removeById(param.getId()), "删除"); } + @Data + static class ListTParam { + private int pageNum; + private int pageSize; + @Schema(title = "任务状态") + private Integer status; + @Schema(title = "月份区间") + private Integer month; + @Schema(title = "tagId数组") + private List tagIdList; + @Schema(title = "brandId数组") + private List brandIdList; + @Schema(title = "任务名称关键词搜索") + private String keyword; + } @Operation(summary = "列表") @PostMapping("/list") - public Result list(@RequestBody(required = false) JSONObject obj, - @RequestHeader(required = false, value = "token") @Parameter(name = "用户token", description = "关联用户信息") String token) { - IPage ipage = taskService.taskIdList(MybatisPlusUtil.SetPage(obj)); - List taskIdList = ipage.getRecords(); - if (taskIdList.size() > 0) { - ipage.setRecords(taskService.taskList(new JwtUtil().parseOpenid(token), taskIdList)); + public Result list(@Validated @RequestBody ListTParam param){ + QueryWrapper qw = new QueryWrapper<>(); + if (null != param.getStatus()) { + qw.eq("t1.status", param.getStatus()); + } + if (null != param.getMonth()) { + qw.between("t1.creatAt", LocalDateTime.now().minusMonths(param.getMonth()),LocalDateTime.now()); + } + if (null != param.getKeyword()) { + qw.like("t1.title", param.getKeyword()); + } + IPage iPage = taskService.idList(MybatisPlusUtil.SetNumPage(param.getPageNum(), param.getPageSize()),param.getTagIdList(),param.getBrandIdList(), qw); + List list = iPage.getRecords(); + if (list.size() > 0) { + iPage.setRecords(taskService.list(null,list,param.getTagIdList(),param.getBrandIdList(), qw)); } - return Result.success(ipage); + return Result.success(iPage); } @Data @@ -237,37 +262,6 @@ public class TaskController { @Schema(title = "任务id") private Integer id; } -// -// @Operation(summary = "详情") -// @PostMapping("/detail") -// 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); -// } -// String openid = new JwtUtil().parseOpenid(token); -// if(openid !=null) { -// task.setIsReceived(0); -// Integer userId = userService.selByOpenid(openid).getId(); -// QueryWrapper 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 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); -// } @Operation(summary = "详情") @PostMapping("detail") diff --git a/src/main/java/com/zh/project0512/controller/wxApp/TaskUController.java b/src/main/java/com/zh/project0512/controller/wxApp/TaskUController.java index e64afa6..5ca2601 100644 --- a/src/main/java/com/zh/project0512/controller/wxApp/TaskUController.java +++ b/src/main/java/com/zh/project0512/controller/wxApp/TaskUController.java @@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.zh.project0512.annotation.tokenValid; +import com.zh.project0512.controller.manage.ReferenceController; import com.zh.project0512.model.*; import com.zh.project0512.model.validatedDemo.TaskValidGroup1; import com.zh.project0512.model.validatedDemo.TaskValidGroup2; @@ -62,16 +63,41 @@ public class TaskUController { @Autowired private ICustomerActionNoteService customerActionNoteService; + @Data + static class ListTParam { + private int pageNum; + private int pageSize; + @Schema(title = "任务状态") + private Integer status; + @Schema(title = "月份区间") + private Integer month; + @Schema(title = "tagId数组") + private List tagIdList; + @Schema(title = "brandId数组") + private List brandIdList; + @Schema(title = "任务名称关键词搜索") + private String keyword; + } @Operation(summary = "列表") @PostMapping("/list") - public Result list(@RequestBody(required = false) JSONObject obj, - @RequestHeader(required = false, value = "token") @Parameter(name = "用户token", description = "关联用户信息") String token) { - IPage ipage = taskService.taskIdList(MybatisPlusUtil.SetPage(obj)); - List taskIdList = ipage.getRecords(); - if (taskIdList.size() > 0) { - ipage.setRecords(taskService.taskList(new JwtUtil().parseOpenid(token), taskIdList)); + public Result list(@Validated @RequestBody ListTParam param, @RequestHeader(required = false, value = "token") @Parameter(name = "用户token", description = "关联用户信息") String token) { + QueryWrapper qw = new QueryWrapper<>(); + if (null != param.getStatus()) { + qw.eq("t1.status", param.getStatus()); + } + if (null != param.getMonth()) { + qw.between("t1.creatAt", LocalDateTime.now().minusMonths(param.getMonth()),LocalDateTime.now()); + } + if (null != param.getKeyword()) { + qw.like("t1.title", param.getKeyword()); + } + IPage iPage = taskService.idList(MybatisPlusUtil.SetNumPage(param.getPageNum(), param.getPageSize()),param.getTagIdList(),param.getBrandIdList(), qw); + List list = iPage.getRecords(); + if (list.size() > 0) { + System.out.println(list); + iPage.setRecords(taskService.list(new JwtUtil().parseOpenid(token),list,param.getTagIdList(),param.getBrandIdList(), qw)); } - return Result.success(ipage); + return Result.success(iPage); } @Data diff --git a/src/main/java/com/zh/project0512/controller/wxApp/UserUController.java b/src/main/java/com/zh/project0512/controller/wxApp/UserUController.java index 93e9903..ba67000 100644 --- a/src/main/java/com/zh/project0512/controller/wxApp/UserUController.java +++ b/src/main/java/com/zh/project0512/controller/wxApp/UserUController.java @@ -2,10 +2,13 @@ package com.zh.project0512.controller.wxApp; import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; +import com.zh.project0512.annotation.tokenValid; import com.zh.project0512.model.User; import com.zh.project0512.service.IUserService; import com.zh.project0512.utils.CoderUtil; import com.zh.project0512.utils.JwtUtil; +import com.zh.project0512.utils.MybatisPlusUtil; import com.zh.project0512.utils.WeChatUtil; import com.zh.project0512.utils.result.HttpStatusEnum; import com.zh.project0512.utils.result.Result; @@ -13,10 +16,7 @@ import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.beans.factory.annotation.Autowired; -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 java.time.LocalDateTime; import java.util.HashMap; @@ -94,5 +94,11 @@ public class UserUController { userService.save(u); return Result.success(u); } - + @PostMapping("/logout") + @tokenValid + public Result logout(@RequestHeader("token") @Parameter(name = "登录token") String token) { + UpdateWrapper uw = new UpdateWrapper<>(); + uw.eq("token",token).set("token",null).set("updateAt",LocalDateTime.now()); + return MybatisPlusUtil.sqlResult(userService.update(uw),"登出"); + } } diff --git a/src/main/java/com/zh/project0512/mapper/ReferenceMapper.java b/src/main/java/com/zh/project0512/mapper/ReferenceMapper.java index b3fbd82..31f5087 100644 --- a/src/main/java/com/zh/project0512/mapper/ReferenceMapper.java +++ b/src/main/java/com/zh/project0512/mapper/ReferenceMapper.java @@ -28,13 +28,13 @@ public interface ReferenceMapper extends BaseMapper { "WHERE t1.id "+ " " + - "and t1.id in (SELECT referenceId from referenceBrand WHERE referenceBrand.brandId in " + + "and t1.id in (SELECT referenceId from referenceTag WHERE referenceTag.tagId in " + "#{item} " + ")" + "" + " " + - "and t1.id in (SELECT referenceId from referenceTag WHERE referenceTag.tagId in " + + "and t1.id in (SELECT referenceId from referenceBrand WHERE referenceBrand.brandId in " + "#{item} " + ")" + "" + @@ -56,13 +56,13 @@ public interface ReferenceMapper extends BaseMapper { "WHERE t1.id "+ " " + - "and t1.id in (SELECT referenceId from referenceBrand WHERE referenceBrand.brandId in " + + "and t1.id in (SELECT referenceId from referenceTag WHERE referenceTag.tagId in " + "#{item} " + ")" + "" + " " + - "and t1.id in (SELECT referenceId from referenceTag WHERE referenceTag.tagId in " + + "and t1.id in (SELECT referenceId from referenceBrand WHERE referenceBrand.brandId in " + "#{item} " + ")" + "" + diff --git a/src/main/java/com/zh/project0512/mapper/TaskMapper.java b/src/main/java/com/zh/project0512/mapper/TaskMapper.java index bafb106..f5d495a 100644 --- a/src/main/java/com/zh/project0512/mapper/TaskMapper.java +++ b/src/main/java/com/zh/project0512/mapper/TaskMapper.java @@ -2,6 +2,7 @@ package com.zh.project0512.mapper; import com.baomidou.mybatisplus.core.conditions.Wrapper; import com.baomidou.mybatisplus.core.metadata.IPage; +import com.zh.project0512.model.Reference; import com.zh.project0512.model.Task; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import org.apache.ibatis.annotations.*; @@ -20,12 +21,32 @@ import java.util.Map; public interface TaskMapper extends BaseMapper { @Insert("insert into task (title,subtitle,start,end) values (#{title},#{subtitle},#{start},#{end})") int add(Task task); -// @Select("") -// IPage taskList(IPage page,String openid); - @Select("SELECT id from task") - IPage taskIdList(IPage iPage); - List taskList(String openid,List list); + @Select("") + IPage idList(IPage iPage, List tagIdList, List brandIdList, @Param("ew") Wrapper queryWrapper); + List list(String openid,List list, List tagIdList, List brandIdList, @Param("ew") Wrapper queryWrapper); Task detailById(String openid,int id); } diff --git a/src/main/java/com/zh/project0512/service/ITaskService.java b/src/main/java/com/zh/project0512/service/ITaskService.java index 2df30a8..7870974 100644 --- a/src/main/java/com/zh/project0512/service/ITaskService.java +++ b/src/main/java/com/zh/project0512/service/ITaskService.java @@ -2,6 +2,7 @@ package com.zh.project0512.service; import com.baomidou.mybatisplus.core.conditions.Wrapper; import com.baomidou.mybatisplus.core.metadata.IPage; +import com.zh.project0512.model.Reference; import com.zh.project0512.model.Task; import com.baomidou.mybatisplus.extension.service.IService; import org.apache.ibatis.annotations.Param; @@ -19,8 +20,7 @@ import java.util.Map; */ public interface ITaskService extends IService { public void add(Task task); - IPage selectPage(IPage page, @Param("ew") Wrapper queryWrapper); - IPage taskIdList(IPage iPage); - List taskList(String openid,List list); + IPage idList(IPage iPage, List tagIdList, List brandIdList, @Param("ew") Wrapper queryWrapper); + List list(String openid,List list, List tagIdList, List brandIdList, @Param("ew") Wrapper queryWrapper); Task detailById(String openid,int id); } diff --git a/src/main/java/com/zh/project0512/serviceImpl/TaskServiceImpl.java b/src/main/java/com/zh/project0512/serviceImpl/TaskServiceImpl.java index 72bbd24..513c728 100644 --- a/src/main/java/com/zh/project0512/serviceImpl/TaskServiceImpl.java +++ b/src/main/java/com/zh/project0512/serviceImpl/TaskServiceImpl.java @@ -2,6 +2,7 @@ package com.zh.project0512.serviceImpl; import com.baomidou.mybatisplus.core.conditions.Wrapper; import com.baomidou.mybatisplus.core.metadata.IPage; +import com.zh.project0512.model.Reference; import com.zh.project0512.model.Task; import com.zh.project0512.mapper.TaskMapper; import com.zh.project0512.service.ITaskService; @@ -29,17 +30,11 @@ public class TaskServiceImpl extends ServiceImpl implements IT public void add(Task task) { taskMapper.add(task); } - - public IPage selectPage(IPage page, @Param("ew") Wrapper queryWrapper) { - return taskMapper.selectPage(page, queryWrapper); - } - - public IPage taskIdList(IPage iPage) { - return taskMapper.taskIdList(iPage); + public IPage idList(IPage iPage, List tagIdList, List brandIdList, @Param("ew") Wrapper queryWrapper){ + return taskMapper.idList(iPage,tagIdList,brandIdList,queryWrapper); } - - public List taskList(String openid,List list) { - return taskMapper.taskList(openid,list); + public List list(String openid,List list, List tagIdList, List brandIdList, @Param("ew") Wrapper queryWrapper){ + return taskMapper.list(openid,list,tagIdList,brandIdList,queryWrapper); } public Task detailById(String openid,int id){ return taskMapper.detailById(openid,id); diff --git a/src/main/resources/mapper/ReferenceMapper.xml b/src/main/resources/mapper/ReferenceMapper.xml index 8040177..a70a517 100644 --- a/src/main/resources/mapper/ReferenceMapper.xml +++ b/src/main/resources/mapper/ReferenceMapper.xml @@ -25,12 +25,12 @@ right join referenceBrand as t4 on t1.id = t4.referenceId LEFT JOIN brand as t5 on t5.id = t4.brandId WHERE t1.id - and t1.id in (SELECT referenceId from referenceBrand WHERE referenceBrand.brandId in + and t1.id in (SELECT referenceId from referenceTag WHERE referenceTag.tagId in #{item} ) - and t1.id in (SELECT referenceId from referenceTag WHERE referenceTag.tagId in + and t1.id in (SELECT referenceId from referenceBrand WHERE referenceBrand.brandId in #{item} ) @@ -80,12 +80,12 @@ right join referenceBrand as t4 on t1.id = t4.referenceId LEFT JOIN brand as t5 on t5.id = t4.brandId WHERE t1.id - and t1.id in (SELECT referenceId from referenceBrand WHERE referenceBrand.brandId in + and t1.id in (SELECT referenceId from referenceTag WHERE referenceTag.tagId in #{item} ) - and t1.id in (SELECT referenceId from referenceTag WHERE referenceTag.tagId in + and t1.id in (SELECT referenceId from referenceBrand WHERE referenceBrand.brandId in #{item} ) diff --git a/src/main/resources/mapper/TaskMapper.xml b/src/main/resources/mapper/TaskMapper.xml index a3c3a9e..6cedcf7 100644 --- a/src/main/resources/mapper/TaskMapper.xml +++ b/src/main/resources/mapper/TaskMapper.xml @@ -19,21 +19,40 @@ - SELECT - t1.*,t2.tagId,t2.title as tagTitle,t3.brandId,t3.name as brandName + t1.*,t2.tagId,t3.title as tagTitle,t4.brandId,t5.name as brandName ,(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 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 - LEFT JOIN ( SELECT taskBrand.*,brand.name from brand,taskBrand WHERE taskBrand.brandId = brand.id ) as t3 - on t1.id = t3.taskId + + + + + LEFT JOIN taskTag as t2 on t1.id = t2.taskId LEFT JOIN tag as t3 on t3.id = t2.tagId + LEFT JOIN taskBrand as t4 on t1.id = t4.taskId LEFT JOIN brand as t5 on t5.id = t4.brandId WHERE t1.id in #{item} - ORDER BY t1.creatAt DESC + + and t1.id in (SELECT taskId from referenceTag WHERE referenceTag.tagId in + #{item} + ) + + + and t1.id in (SELECT referenceId from referenceBrand WHERE referenceBrand.brandId in + #{item} + + ) + + + + AND + + ${ew.SqlSegment} + + ORDER BY updateAt DESC,creatAt DESC + SELECT date_format(t1.creatAt, '%Y-%m-%d') dat, t1.*,t2.userId,t3.name + from reference as t1 + left join userReference as t2 on t1.id = t2.referenceId + left JOIN user as t3 on t3.id = t2.userId + where t3.openid = #{id} + and date_format(t1.creatAt, '%Y-%m-%d') in + #{item} + + + AND + + ${ew.SqlSegment} + + ORDER BY updateAt DESC,creatAt DESC + +