Commit ca0c0e9d by liushuangwu

LoveChatController

1 parent 272fc736
package com.pipihelper.project.controller;
import com.pipihelper.project.feishu.bo.LoveChatVO;
import com.pipihelper.project.feishu.service.LoveChatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
@RequestMapping("/api/v1/love-chat")
public class LoveChatController {
@Autowired
private LoveChatService loveChatService;
@PostMapping(value = "list")
public List<LoveChatVO> list(@RequestParam(value = "title", required = false) String title,
@RequestParam("pageNum") Integer pageNum,
@RequestParam("pageSize") Integer pageSize) {
return loveChatService.list(title, pageNum, pageSize);
}
}
package com.pipihelper.project.feishu.bo;
import lombok.Data;
import java.util.List;
@Data
public class LoveChatVO {
private Integer id;
private String title;
private List<LoveChatDetail> loveChatDetails;
@Data
public static class LoveChatDetail {
private Integer type;
private String text;
}
}
......@@ -18,6 +18,7 @@ import com.pipihelper.project.feishu.dto.msg.FeiShuMsgDTO;
import com.pipihelper.project.feishu.entity.Employee;
import com.pipihelper.project.feishu.entity.LastMaxPain;
import com.pipihelper.project.feishu.entity.Pain;
import com.pipihelper.project.feishu.service.ChatMessageService;
import com.pipihelper.project.feishu.service.EmployeeService;
import com.pipihelper.project.feishu.service.FeiShuApiService;
import com.pipihelper.project.feishu.service.FeiShuEventService;
......@@ -72,6 +73,8 @@ public class FeiShuEventController {
@Autowired
private EmployeeService employeeService;
@Autowired
private ChatMessageService chatMessageService;
@Autowired
private LastMaxPainService lastMaxPainService;
@Autowired
private PainService painService;
......@@ -221,6 +224,8 @@ public class FeiShuEventController {
@PostMapping("/employee-list")
public Object event() {
employeeService.uprsetAllEmployee();
chatMessageService.deleteAll();
for (Integer floor : Lists.newArrayList(14)) {
LastMaxPain maxPain = lastMaxPainService.findByFloor(floor);
int startEmployeeId = 0;
......
package com.pipihelper.project.feishu.dao;
import com.pipihelper.project.feishu.entity.LoveChat;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
@Mapper
public interface LoveChatDao {
List<LoveChat> findList(@Param(value = "title") String title);
}
package com.pipihelper.project.feishu.entity;
import lombok.Data;
@Data
public class LoveChat {
private Integer id;
private String title;
private String content;
private Integer isDelete;
}
package com.pipihelper.project.feishu.service;
import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageHelper;
import com.pipihelper.project.feishu.bo.LoveChatVO;
import com.pipihelper.project.feishu.dao.LoveChatDao;
import com.pipihelper.project.feishu.entity.LoveChat;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
@Service
public class LoveChatService {
@Autowired
private LoveChatDao loveChatDao;
public List<LoveChatVO> list(String title, Integer pageNum, Integer pageSize) {
if(StringUtils.isBlank(title)){
title = null;
}
PageHelper.startPage(pageNum, pageSize);
List<LoveChat> chatList = loveChatDao.findList(title);
if (CollectionUtil.isEmpty(chatList)) {
return new ArrayList<>();
}
return chatList.stream().map(it -> {
LoveChatVO loveChatVO = new LoveChatVO();
loveChatVO.setTitle(it.getTitle());
loveChatVO.setId(it.getId());
List<SpeedContent> speedContentList = JSON.parseArray(it.getContent(), SpeedContent.class);
loveChatVO.setLoveChatDetails(speedContentList.stream().map(speedContent -> {
LoveChatVO.LoveChatDetail chatDetail = new LoveChatVO.LoveChatDetail();
chatDetail.setType("me".equals(speedContent.getObject()) ? 1 : 2);
chatDetail.setText(speedContent.getPlan());
return chatDetail;
}).collect(Collectors.toList()));
return loveChatVO;
}).collect(Collectors.toList());
}
@Data
private static class SpeedContent {
private String object;
private String plan;
}
}
<?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.pipihelper.project.feishu.dao.LoveChatDao">
<resultMap id="ChatMessageResultMap" type="com.pipihelper.project.feishu.entity.LoveChat">
<id column="id" property="id"/>
<result column="title" property="title"/>
<result column="content" property="content"/>
<result column="is_delete" property="isDelete"/>
</resultMap>
<!-- <resultMap id="BuffConfigResultBOMap" type="com.pipihelper.project.feishu.entity.Deployee"
extends="ChatMessageResultMap">
</resultMap>-->
<sql id="Base_Column_List">
id,title,content,is_delete
</sql>
<select id="findList" resultMap="ChatMessageResultMap">
SELECT
<include refid="Base_Column_List"/>
FROM t_love_chat
<where>
is_delete = 0
<if test="title != null">
and title like '%${title}%'
</if>
</where>
</select>
</mapper>
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!