zhangjinli 3 years ago
parent 6dd4ca92a4
commit 8cdfd3d5bd

@ -10,7 +10,6 @@ import com.zh.project0512.service.IQywxDepartmentService;
import com.zh.project0512.service.IUserService;
import com.zh.project0512.utils.HttpUtil;
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.swagger.v3.oas.annotations.Operation;
@ -57,6 +56,7 @@ public class QYWXController {
String userid = res.getString("userid");
JSONObject res1 = httpUtil.qywxUser(access_token, userid);
Integer main_department = res1.getInteger("main_department");
JSONArray department = res1.getJSONArray("department");
if (null == userid || null == main_department) {
return Result.fail(HttpStatusEnum.CUSTOM_EXCEPTION, "获取企业用户信息失败");
}

@ -193,17 +193,32 @@ public class ReferenceController {
private Integer groupId;
@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(@Validated @RequestBody ListRParam param, @RequestHeader(value="token",required = false) @Parameter(name = "登录token") String token) {
QueryWrapper<Reference> queryWrapper = new QueryWrapper<>();
Integer groupId = param.groupId;
if(groupId != null){
queryWrapper.eq("groupId",groupId);
public Result list(@Validated @RequestBody ListRParam param) {
QueryWrapper<Reference> qw = new QueryWrapper<>();
if (null != param.getGroupId()) {
qw.eq("t1.groupId", param.getGroupId());
}
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 = referenceService.idList(MybatisPlusUtil.SetNumPage(param.getPageNum(), param.getPageSize()),param.getTagIdList(),param.getBrandIdList(), qw);
List list = iPage.getRecords();
if (list.size() > 0) {
iPage.setRecords(referenceService.list(null,list,param.getTagIdList(),param.getBrandIdList(), qw));
}
IPage iPage = referenceService.selectPage(MybatisPlusUtil.SetNumPage(param.getPageNum(), param.getPageSize()),queryWrapper,new JwtUtil().parseOpenid(token));
return Result.success(iPage);
}
@ -223,33 +238,5 @@ public class ReferenceController {
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;
@Schema(title = "素材分组id")
private Integer groupId;
@Schema(title = "月份区间")
private Integer month;
}
@Operation(summary = "按日期查询")
@PostMapping("/listByDay")
public Result detail(@Validated @RequestBody DetaPParam param,@RequestHeader(value="token",required = false) @Parameter(name = "登录token") String token) {
Claims claims = new JwtUtil().parseJWT(token);
LocalDateTime dayBegin = LocalDateTime.of(param.getDate().toLocalDate(), LocalTime.MIN);
LocalDateTime dayLast = LocalDateTime.of(param.getDate().toLocalDate(), LocalTime.MAX);
Integer groupId = param.groupId;
QueryWrapper<Reference> queryWrapper = new QueryWrapper<>();
if(groupId != null){
queryWrapper.eq("groupId",groupId);
}
queryWrapper.orderByDesc("creatAt");
queryWrapper.between("creatAt",dayBegin,dayLast);
List<Reference> list = referenceService.list(queryWrapper);
return Result.success(list);
}
}

@ -65,23 +65,38 @@ public class ReferenceUController {
private Integer groupId;
@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(@Validated @RequestBody ListRParam param, @RequestHeader(value = "token", required = false) @Parameter(name = "登录token") String token) {
QueryWrapper<Reference> queryWrapper = new QueryWrapper<>();
Integer groupId = param.groupId;
if (groupId != null) {
queryWrapper.eq("groupId", groupId);
QueryWrapper<Reference> qw = new QueryWrapper<>();
if (null != param.getGroupId()) {
qw.eq("t1.groupId", param.getGroupId());
}
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 = referenceService.idList(MybatisPlusUtil.SetNumPage(param.getPageNum(), param.getPageSize()),param.getTagIdList(),param.getBrandIdList(), qw);
List list = iPage.getRecords();
if (list.size() > 0) {
iPage.setRecords(referenceService.list(new JwtUtil().parseOpenid(token),list,param.getTagIdList(),param.getBrandIdList(), qw));
}
IPage iPage = referenceService.selectPage(MybatisPlusUtil.SetNumPage(param.getPageNum(), param.getPageSize()), queryWrapper, new JwtUtil().parseOpenid(token));
return Result.success(iPage);
}
@Operation(summary = "素材列表按日分组")
@PostMapping("/listByDay")
public Result list1(@Validated @RequestBody ListRParam param) {
public Result listByDay(@Validated @RequestBody ListRParam param, @RequestHeader(value = "token", required = false) @Parameter(name = "登录token") String token) {
QueryWrapper<Reference> qw = new QueryWrapper<>();
if (null != param.getGroupId()) {
qw.eq("t1.groupId", param.getGroupId());
@ -89,10 +104,13 @@ public class ReferenceUController {
if (null != param.getMonth()) {
qw.between("t1.creatAt", LocalDateTime.now().minusMonths(param.getMonth()),LocalDateTime.now());
}
IPage iPage = referenceService.dateList(MybatisPlusUtil.SetNumPage(param.getPageNum(), param.getPageSize()), qw);
if (null != param.getKeyword()) {
qw.like("t1.title", param.getKeyword());
}
IPage iPage = referenceService.dateList(MybatisPlusUtil.SetNumPage(param.getPageNum(), param.getPageSize()),param.getTagIdList(),param.getBrandIdList(), qw);
List list = iPage.getRecords();
if (list.size() > 0) {
iPage.setRecords(referenceService.referenceDateList(list, qw));
iPage.setRecords(referenceService.referenceDateList(new JwtUtil().parseOpenid(token),list,param.getTagIdList(),param.getBrandIdList(), qw));
}
return Result.success(iPage);
}

@ -82,37 +82,6 @@ public class TaskUController {
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")
public Result det( @RequestBody JSONObject obj,@RequestHeader(required = false, value = "token") @Parameter(name = "用户token", description = "关联用户信息") String token) {

@ -22,28 +22,62 @@ import java.util.Map;
* @since 2022-05-23
*/
public interface ReferenceMapper extends BaseMapper<Reference> {
@Select("<script>"+
"SELECT t1.*\n" +
"<if test='openid!=null'>\n" +
",(SELECT count(*)!=0 from userReference as t4,user as t5\n" +
"WHERE t1.id = t4.referenceId and t4.userId = t5.id and t5.openid = #{openid} ) as isCollected\n" +
"</if>\n" +
"from reference as t1\n" +
"${ew.customSqlSegment}"+
"ORDER BY t1.creatAt DESC"+
"</script>")
IPage<Reference> selectPage( IPage<Reference> page, @Param("ew") Wrapper<Reference> queryWrapper,String openid);
@Select("<script>" +
"SELECT t1.id " +
"from reference t1 " +
"WHERE t1.id "+
"<if test='tagIdList !=null and tagIdList.size()!=0'> " +
"and t1.id in (SELECT referenceId from referenceBrand WHERE referenceBrand.brandId in " +
"<foreach collection='tagIdList' index='index' item='item' open='(' separator=',' close=')'>#{item}</foreach> " +
")" +
"</if>" +
List<Map> list(String openid, JSONObject obj);
"<if test='brandIdList !=null and brandIdList.size()!=0'> " +
"and t1.id in (SELECT referenceId from referenceTag WHERE referenceTag.tagId 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<String> list, List<Integer> tagIdList, List<Integer> brandIdList, @Param("ew") Wrapper<Reference> queryWrapper);
@Select("<script>"+
@Select("<script>" +
"SELECT date_format(t1.creatAt, '%Y-%m-%d') dat " +
"from reference t1 " +
"${ew.customSqlSegment}"+
"WHERE t1.id "+
"<if test='tagIdList !=null and tagIdList.size()!=0'> " +
"and t1.id in (SELECT referenceId from referenceBrand WHERE referenceBrand.brandId 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 " +
"<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> " +
" group by dat " +
"ORDER BY dat DESC"+
"ORDER BY dat DESC" +
"</script>")
IPage<String> dateList(IPage iPage, @Param("ew") Wrapper<Reference> queryWrapper);
List<Map> referenceDateList(List<String> list, @Param("ew") Wrapper<Reference> queryWrapper);
IPage<String> dateList(IPage iPage, List<Integer> tagIdList, List<Integer> brandIdList, @Param("ew") Wrapper<Reference> queryWrapper);
List<Map> referenceDateList(String openid,List<String> list, List<Integer> tagIdList, List<Integer> brandIdList, @Param("ew") Wrapper<Reference> queryWrapper);
}

@ -21,9 +21,8 @@ import java.util.Map;
* @since 2022-05-23
*/
public interface IReferenceService extends IService<Reference> {
IPage<Reference> selectPage( IPage<Reference> page, @Param("ew") Wrapper<Reference> queryWrapper,String openid);
List<Map> list(String openid, JSONObject obj);
IPage<String> dateList(IPage iPage, @Param("ew") Wrapper<Reference> queryWrapper);
List referenceDateList(List<String> list, @Param("ew") Wrapper<Reference> queryWrapper);
IPage<Integer> idList(IPage iPage, List<Integer> tagIdList, List<Integer> brandIdList, @Param("ew") Wrapper<Reference> queryWrapper);
List<Map> list(String openid,List<String> list, List<Integer> tagIdList, List<Integer> brandIdList, @Param("ew") Wrapper<Reference> queryWrapper);
IPage<String> dateList(IPage iPage, List<Integer> tagIdList, List<Integer> brandIdList, @Param("ew") Wrapper<Reference> queryWrapper);
List referenceDateList(String openid,List<String> list,List<Integer> tagIdList,List<Integer> brandIdList, @Param("ew") Wrapper<Reference> queryWrapper);
}

@ -30,18 +30,16 @@ public class ReferenceServiceImpl extends ServiceImpl<ReferenceMapper, Reference
@Autowired
private ReferenceMapper referenceMapper;
public IPage<Reference> selectPage(IPage<Reference> page, @Param("ew") Wrapper<Reference> queryWrapper, String openid) {
return referenceMapper.selectPage(page, queryWrapper, openid);
public IPage<Integer> idList(IPage iPage, List<Integer> tagIdList, List<Integer> brandIdList, @Param("ew") Wrapper<Reference> queryWrapper){
return referenceMapper.idList(iPage,tagIdList,brandIdList,queryWrapper);
}
public List<Map> list(String openid, JSONObject obj) {
return referenceMapper.list(openid, obj);
public List<Map> list(String openid,List<String> list, List<Integer> tagIdList, List<Integer> brandIdList, @Param("ew") Wrapper<Reference> queryWrapper){
return referenceMapper.list(openid,list,tagIdList,brandIdList,queryWrapper);
}
public IPage<String> dateList(IPage iPage, @Param("ew") Wrapper<Reference> queryWrapper){
return referenceMapper.dateList(iPage,queryWrapper);
public IPage<String> dateList(IPage iPage, List<Integer> tagIdList, List<Integer> brandIdList, @Param("ew") Wrapper<Reference> queryWrapper){
return referenceMapper.dateList(iPage,tagIdList,brandIdList,queryWrapper);
}
public List referenceDateList(List<String> list, @Param("ew") Wrapper<Reference> queryWrapper) {
return referenceMapper.referenceDateList(list,queryWrapper);
public List referenceDateList(String openid,List<String> list,List<Integer> tagIdList,List<Integer> brandIdList, @Param("ew") Wrapper<Reference> queryWrapper) {
return referenceMapper.referenceDateList(openid,list,tagIdList,brandIdList,queryWrapper);
}
}

@ -1,6 +1,8 @@
<?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.ReferenceMapper">
<resultMap id="referenceMap" type="com.zh.project0512.model.Reference">
<id property="id" column="id"/>
<collection property="tagList" ofType="java.util.Map" autoMapping="false">
@ -13,34 +15,81 @@
</collection>
</resultMap>
<select id="list" resultMap="referenceMap">
SELECT t1.*
select t1.*,t2.tagId,t3.title as tagTitle,t4.brandId,t5.name as brandName
<if test='openid!=null'>
,(SELECT count(*)!=0 from userReference as t4,user as t5
WHERE t1.id = t4.referenceId and t4.userId = t5.id and t5.openid = #{openid} ) as isCollected
,(SELECT count(*)!=0 from userReference as ur,user as u
WHERE t1.id = ur.referenceId and ur.userId = u.id and u.openid = #{openid} ) as isCollected
</if>
from reference as t1
<if test='groupId !=null'>
where groupId = #{groupId}
right join referenceTag as t2 on t1.id = t2.referenceId LEFT JOIN tag as t3 on t3.id = t2.tagId
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
<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
<foreach collection="brandIdList" index="index" item="item" open="(" separator="," close=")">#{item}
</foreach>
)
</if>
ORDER BY t1.creatAt DESC
and t1.id 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>
<resultMap id="referenceDateMap" type="java.util.Map" autoMapping="false">
<id property="dat" column="dat"/>
<collection property="referenceList" ofType="java.util.Map" javaType="java.util.List">
<collection property="referenceList" ofType="java.util.Map" javaType="java.util.List" autoMapping="false">
<id column="id" property="id"/>
<result column="title" property="title"/>
<result column="type" property="type"/>
<result column="fileUrl" property="fileUrl"/>
<result column="coverUrl" property="coverUrl"/>
<result column="groupId" property="groupId"/>
<result column="creatAt" property="creatAt"/>
<result column="updateAt" property="updateAt"/>
<result column="isCollected" property="isCollected"/>
<collection property="tagList" ofType="java.util.Map" javaType="java.util.List" autoMapping="false">
<id column="tagId" property="id"/>
<result column="tagTitle" property="title"/>
</collection>
<collection property="brandList" ofType="java.util.Map" javaType="java.util.List" autoMapping="false">
<id column="brandId" property="id"/>
<result column="brandName" property="name"/>
</collection>
</collection>
</resultMap>
<select id="referenceDateList" resultMap="referenceDateMap">
<!-- select t1.*,t2.tagId,t3.title as tagTitle,t4.brandId,t5.name as brandName from reference as t1-->
<!-- right join referenceTag as t2 on t1.id = t2.referenceId LEFT JOIN tag as t3 on t3.id = t2.tagId-->
<!-- right join referenceBrand as t4 on t1.id = t4.referenceId LEFT JOIN brand as t5 on t5.id = t4.brandId-->
<!-- WHERE t1.id ORDER BY updateAt DESC,creatAt DESC-->
select date_format(t1.creatAt, '%Y-%m-%d') dat,t1.*,t2.tagId, t3.title as tagTitle,t4.brandId,t5.name as brandName
from reference t1,referenceTag t2,tag t3
WHERE
t3.id = t2.tagId and t2.referenceId = t1.id
select date_format(t1.creatAt, '%Y-%m-%d') dat,t1.*,t2.tagId,t3.title as tagTitle,t4.brandId,t5.name as
brandName
<if test='openid!=null'>
,(SELECT count(*)!=0 from userReference as ur,user as u
WHERE t1.id = ur.referenceId and ur.userId = u.id and u.openid = #{openid} ) as isCollected
</if>
from reference as t1
right join referenceTag as t2 on t1.id = t2.referenceId LEFT JOIN tag as t3 on t3.id = t2.tagId
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
<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
<foreach collection="brandIdList" index="index" item="item" open="(" separator="," close=")">#{item}
</foreach>
)
</if>
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'>

Loading…
Cancel
Save