zhangjinli 3 years ago
parent 8cdfd3d5bd
commit cb200c613d

@ -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<Integer> tagIdList;
@Schema(title = "brandId数组")
private List<Integer> 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<Reference> 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<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);
// 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")

@ -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<Integer> tagIdList;
@Schema(title = "brandId数组")
private List<Integer> 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<Reference> 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

@ -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<User> uw = new UpdateWrapper<>();
uw.eq("token",token).set("token",null).set("updateAt",LocalDateTime.now());
return MybatisPlusUtil.sqlResult(userService.update(uw),"登出");
}
}

@ -28,13 +28,13 @@ public interface ReferenceMapper extends BaseMapper<Reference> {
"WHERE t1.id "+
"<if test='tagIdList !=null and tagIdList.size()!=0'> " +
"and t1.id in (SELECT referenceId from referenceBrand WHERE referenceBrand.brandId in " +
"and t1.id in (SELECT referenceId from referenceTag WHERE referenceTag.tagId in " +
"<foreach collection='tagIdList' index='index' item='item' open='(' separator=',' close=')'>#{item}</foreach> " +
")" +
"</if>" +
"<if test='brandIdList !=null and brandIdList.size()!=0'> " +
"and t1.id in (SELECT referenceId from referenceTag WHERE referenceTag.tagId in " +
"and t1.id in (SELECT referenceId from referenceBrand WHERE referenceBrand.brandId in " +
"<foreach collection='brandIdList' index='index' item='item' open='(' separator=',' close=')'>#{item}</foreach> " +
")" +
"</if>" +
@ -56,13 +56,13 @@ public interface ReferenceMapper extends BaseMapper<Reference> {
"WHERE t1.id "+
"<if test='tagIdList !=null and tagIdList.size()!=0'> " +
"and t1.id in (SELECT referenceId from referenceBrand WHERE referenceBrand.brandId in " +
"and t1.id in (SELECT referenceId from referenceTag WHERE referenceTag.tagId in " +
"<foreach collection='tagIdList' index='index' item='item' open='(' separator=',' close=')'>#{item}</foreach> " +
")" +
"</if>" +
"<if test='brandIdList !=null and brandIdList.size()!=0'> " +
"and t1.id in (SELECT referenceId from referenceTag WHERE referenceTag.tagId in " +
"and t1.id in (SELECT referenceId from referenceBrand WHERE referenceBrand.brandId in " +
"<foreach collection='brandIdList' index='index' item='item' open='(' separator=',' close=')'>#{item}</foreach> " +
")" +
"</if>" +

@ -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<Task> {
@Insert("insert into task (title,subtitle,start,end) values (#{title},#{subtitle},#{start},#{end})")
int add(Task task);
// @Select("<script>"+
// " SELECT t1.* <if test='openid!=null'> ,(SELECT count(*)!=0 from userTask as t2,user as t3 WHERE t1.id = t2.taskId and t2.userId = t3.id and t3.openid = #{openid} ) as isReceived </if> from task as t1"
// +"</script>")
// IPage<Task> taskList(IPage<Task> page,String openid);
@Select("SELECT id from task")
IPage<Integer> taskIdList(IPage iPage);
List<Task> taskList(String openid,List<Integer> list);
@Select("<script>" +
"SELECT t1.id " +
"from task t1 " +
"WHERE t1.id "+
"<if test='tagIdList !=null and tagIdList.size()!=0'> " +
"and t1.id in (SELECT taskId from taskTag WHERE taskTag.tagId in " +
"<foreach collection='tagIdList' index='index' item='item' open='(' separator=',' close=')'>#{item}</foreach> " +
")" +
"</if>" +
"<if test='brandIdList !=null and brandIdList.size()!=0'> " +
"and t1.id in (SELECT taskId from taskBrand WHERE taskBrand.brandId in " +
"<foreach collection='brandIdList' index='index' item='item' open='(' separator=',' close=')'>#{item}</foreach> " +
")" +
"</if>" +
"<if test='ew != null'>" +
"<if test='ew.nonEmptyOfWhere'>" +
"AND " +
"</if> " +
"${ew.SqlSegment}" +
"</if> " +
"ORDER BY t1.updateAt DESC,t1.creatAt DESC" +
"</script>")
IPage<Integer> idList(IPage iPage, List<Integer> tagIdList, List<Integer> brandIdList, @Param("ew") Wrapper<Reference> queryWrapper);
List<Map> list(String openid,List<Integer> list, List<Integer> tagIdList, List<Integer> brandIdList, @Param("ew") Wrapper<Reference> queryWrapper);
Task detailById(String openid,int id);
}

@ -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<Task> {
public void add(Task task);
IPage<Task> selectPage(IPage<Task> page, @Param("ew") Wrapper<Task> queryWrapper);
IPage<Integer> taskIdList(IPage iPage);
List<Task> taskList(String openid,List<Integer> list);
IPage<Integer> idList(IPage iPage, List<Integer> tagIdList, List<Integer> brandIdList, @Param("ew") Wrapper<Reference> queryWrapper);
List<Map> list(String openid,List<Integer> list, List<Integer> tagIdList, List<Integer> brandIdList, @Param("ew") Wrapper<Reference> queryWrapper);
Task detailById(String openid,int id);
}

@ -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<TaskMapper, Task> implements IT
public void add(Task task) {
taskMapper.add(task);
}
public IPage<Task> selectPage(IPage<Task> page, @Param("ew") Wrapper<Task> queryWrapper) {
return taskMapper.selectPage(page, queryWrapper);
}
public IPage<Integer> taskIdList(IPage iPage) {
return taskMapper.taskIdList(iPage);
public IPage<Integer> idList(IPage iPage, List<Integer> tagIdList, List<Integer> brandIdList, @Param("ew") Wrapper<Reference> queryWrapper){
return taskMapper.idList(iPage,tagIdList,brandIdList,queryWrapper);
}
public List<Task> taskList(String openid,List<Integer> list) {
return taskMapper.taskList(openid,list);
public List<Map> list(String openid,List<Integer> list, List<Integer> tagIdList, List<Integer> brandIdList, @Param("ew") Wrapper<Reference> queryWrapper){
return taskMapper.list(openid,list,tagIdList,brandIdList,queryWrapper);
}
public Task detailById(String openid,int id){
return taskMapper.detailById(openid,id);

@ -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
<if test="tagIdList !=null and tagIdList.size()!=0 ">
and t1.id in (SELECT referenceId from referenceBrand WHERE referenceBrand.brandId in
and t1.id in (SELECT referenceId from referenceTag WHERE referenceTag.tagId in
<foreach collection="tagIdList" index="index" item="item" open="(" separator="," close=")">#{item}</foreach>
)
</if>
<if test="brandIdList !=null and brandIdList.size()!=0 ">
and t1.id in (SELECT referenceId from referenceTag WHERE referenceTag.tagId in
and t1.id in (SELECT referenceId from referenceBrand WHERE referenceBrand.brandId in
<foreach collection="brandIdList" index="index" item="item" open="(" separator="," close=")">#{item}
</foreach>
)
@ -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
<if test="tagIdList !=null and tagIdList.size()!=0 ">
and t1.id in (SELECT referenceId from referenceBrand WHERE referenceBrand.brandId in
and t1.id in (SELECT referenceId from referenceTag WHERE referenceTag.tagId in
<foreach collection="tagIdList" index="index" item="item" open="(" separator="," close=")">#{item}</foreach>
)
</if>
<if test="brandIdList !=null and brandIdList.size()!=0 ">
and t1.id in (SELECT referenceId from referenceTag WHERE referenceTag.tagId in
and t1.id in (SELECT referenceId from referenceBrand WHERE referenceBrand.brandId in
<foreach collection="brandIdList" index="index" item="item" open="(" separator="," close=")">#{item}
</foreach>
)

@ -19,21 +19,40 @@
<result column="referenceCoverUrl" property="coverUrl"/>
</collection>
</resultMap>
<select id="taskList" resultMap="taskListMap">
<select id="list" resultMap="taskListMap">
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
<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>
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 ( 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
<foreach collection="list" index="index" item="item" open="(" separator="," close=")">#{item}</foreach>
ORDER BY t1.creatAt DESC
<if test="tagIdList !=null and tagIdList.size()!=0 ">
and t1.id in (SELECT taskId from referenceTag WHERE referenceTag.tagId in
<foreach collection="tagIdList" index="index" item="item" open="(" separator="," close=")">#{item}</foreach>
)
</if>
<if test="brandIdList !=null and brandIdList.size()!=0 ">
and t1.id in (SELECT referenceId from referenceBrand WHERE referenceBrand.brandId in
<foreach collection="brandIdList" index="index" item="item" open="(" separator="," close=")">#{item}
</foreach>
)
</if>
<if test='ew != null'>
<if test='ew.nonEmptyOfWhere'>
AND
</if>
${ew.SqlSegment}
</if>
ORDER BY updateAt DESC,creatAt DESC
</select>
<select id="detailById" resultMap="taskListMap">
SELECT

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.zh.project0512.mapper.UserReferenceMapper">
<resultMap id="UserReferenceListMap" type="com.zh.project0512.model.UserReference">
<id property="id" column="id"/>
<collection property="tagList" ofType="java.util.Map" autoMapping="false">
<id column="tagId" property="id"/>
<result column="tagTitle" property="title"/>
</collection>
<collection property="brandList" ofType="java.util.Map" autoMapping="false">
<id column="brandId" property="id"/>
<result column="brandName" property="name"/>
</collection>
<collection property="referenceList" ofType="java.util.Map" autoMapping="false">
<id column="referenceId" property="id"/>
<result column="referenceTitle" property="title"/>
<result column="referenceType" property="type"/>
<result column="referenceFileUrl" property="fileUrl"/>
<result column="referenceCoverUrl" property="coverUrl"/>
</collection>
</resultMap>
<select id="list" resultMap="UserReferenceListMap">
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
<foreach collection="list" index="index" item="item" open="(" separator="," close=")">#{item}</foreach>
<if test='ew != null'>
<if test='ew.nonEmptyOfWhere'>
AND
</if>
${ew.SqlSegment}
</if>
ORDER BY updateAt DESC,creatAt DESC
</select>
</mapper>
Loading…
Cancel
Save