dcs 10 mesi fa
parent
commit
1149d06547

+ 87 - 0
virgo.api/src/main/java/com/bosshand/virgo/api/controller/FansController.java

@@ -0,0 +1,87 @@
+package com.bosshand.virgo.api.controller;
+
+import com.bosshand.virgo.api.model.Fans;
+import com.bosshand.virgo.api.service.FansService;
+import com.bosshand.virgo.core.response.Response;
+import com.bosshand.virgo.core.utils.ContextUtils;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@RestController
+@RequestMapping("fans")
+@Api(tags = {"关注粉丝"})
+public class FansController {
+
+    @Autowired
+    FansService fansService;
+
+    @ApiOperation("统计数量(fansCount:粉丝数量,attentionCount:关注数量, roomCount:房源数量)")
+    @RequestMapping(value = "/count", method = RequestMethod.GET)
+    public Response count() {
+        long userId = ContextUtils.getCurrentUser().getId();
+        int fansCount = fansService.getTotalCount(userId);
+        int attentionCount = fansService.getAttentionTotalCount(userId);
+        int roomCount = fansService.getRoomTotalCount(userId);
+        Map<String, Object> result = new HashMap<>();
+        result.put("roomCount", roomCount);
+        result.put("fansCount", fansCount);
+        result.put("attentionCount", attentionCount);
+        return Response.ok(result);
+    }
+
+    @ApiOperation("粉丝列表")
+    @RequestMapping(value = "/{currPage}/{pageSize}", method = RequestMethod.GET)
+    public Response list(@PathVariable int currPage, @PathVariable int pageSize) {
+        long userId = ContextUtils.getCurrentUser().getId();
+        int totalCount = fansService.getTotalCount(userId);
+        List<Fans> dataList = fansService.getLimit(userId, currPage, pageSize);
+        Map<String, Object> result = new HashMap<>();
+        result.put("dataList", dataList);
+        result.put("totalCount", totalCount);
+        return Response.ok(result);
+    }
+
+    @ApiOperation("关注列表")
+    @RequestMapping(value = "/attention/{currPage}/{pageSize}", method = RequestMethod.GET)
+    public Response attentionList(@PathVariable int currPage, @PathVariable int pageSize) {
+        long userId = ContextUtils.getCurrentUser().getId();
+        int totalCount = fansService.getAttentionTotalCount(userId);
+        List<Fans> dataList = fansService.getAttentionLimit(userId, currPage, pageSize);
+        Map<String, Object> result = new HashMap<>();
+        result.put("dataList", dataList);
+        result.put("totalCount", totalCount);
+        return Response.ok(result);
+    }
+
+
+    @ApiOperation("关注用户(userId:关注用户id)")
+    @RequestMapping(value = "/{userId}", method = RequestMethod.GET)
+    public Response insert(@PathVariable long userId) {
+        long fansUserId = ContextUtils.getCurrentUser().getId();
+        Fans fans = fansService.get(userId, fansUserId);
+        if (fans != null) {
+            return Response.fail(100001, "已经关注过了");
+        }
+        fansService.insert(userId, fansUserId);
+        return Response.ok();
+    }
+
+    @ApiOperation("取消关注用户(userId:关注用户id)")
+    @RequestMapping(value = "/{userId}", method = RequestMethod.DELETE)
+    public Response cancel(@PathVariable long userId) {
+        long fansUserId = ContextUtils.getCurrentUser().getId();
+        fansService.delete(userId, fansUserId);
+        return Response.ok();
+    }
+
+
+}

+ 8 - 0
virgo.api/src/main/java/com/bosshand/virgo/api/controller/ProjectItemTargetRoomController.java

@@ -29,6 +29,14 @@ public class ProjectItemTargetRoomController {
     @Autowired
     RoomService roomService;
 
+    @ApiOperation("当前用户(负责人)下房源列表")
+    @RequestMapping(value = "/count/{currPage}/{pageSize}", method = RequestMethod.GET)
+    public Response list(@PathVariable int currPage, @PathVariable int pageSize) {
+        ProjectItemTargetRoom room = new ProjectItemTargetRoom();
+        room.setChargePersonId(ContextUtils.getCurrentUser().getId());
+        return getResponse(currPage, pageSize, room);
+    }
+
     @ApiOperation("查询")
     @RequestMapping(value = "/query", method = RequestMethod.POST)
     public Response queryList(@RequestBody ProjectItemTargetRoom projectItemTargetRoom) {

+ 33 - 4
virgo.api/src/main/java/com/bosshand/virgo/api/controller/RoomController.java

@@ -1,9 +1,7 @@
 package com.bosshand.virgo.api.controller;
 
-import com.bosshand.virgo.api.model.RoomCollection;
-import com.bosshand.virgo.api.model.RoomEvaluate;
-import com.bosshand.virgo.api.model.RoomReservation;
-import com.bosshand.virgo.api.model.RoomVisitor;
+import com.bosshand.virgo.api.model.*;
+import com.bosshand.virgo.api.service.ProjectItemTargetRoomService;
 import com.bosshand.virgo.api.service.RoomService;
 import com.bosshand.virgo.core.response.Response;
 import com.bosshand.virgo.core.utils.ContextUtils;
@@ -12,6 +10,7 @@ import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -24,6 +23,9 @@ public class RoomController {
     @Autowired
     RoomService roomService;
 
+    @Autowired
+    ProjectItemTargetRoomService projectItemTargetRoomService;
+
     @ApiOperation("获取访客记录")
     @RequestMapping(value = "/visitor/{currPage}/{pageSize}", method = RequestMethod.POST)
     public Response list(@RequestBody RoomVisitor roomVisitor, @PathVariable int currPage, @PathVariable int pageSize) {
@@ -65,6 +67,33 @@ public class RoomController {
         return Response.ok();
     }
 
+    @ApiOperation("当前用户收藏房源数量(collectionCount:收藏数量)")
+    @RequestMapping(value = "/collection/count", method = RequestMethod.GET)
+    public Response count() {
+        long userId = ContextUtils.getCurrentUser().getId();
+        int collectionCount = roomService.getTotalCount(userId);
+        Map<String, Object> result = new HashMap<>();
+        result.put("collectionCount", collectionCount);
+        return Response.ok(result);
+    }
+
+    @ApiOperation("当前用户收藏房源列表")
+    @RequestMapping(value = "/collection/{currPage}/{pageSize}", method = RequestMethod.GET)
+    public Response list(@PathVariable int currPage, @PathVariable int pageSize) {
+        long userId = ContextUtils.getCurrentUser().getId();
+        int totalCount = roomService.getTotalCount(userId);
+        List<RoomCollection> list = roomService.getLimit(userId, currPage, pageSize);
+
+        List<Long> ids = new ArrayList<>();
+        list.forEach(ls -> ids.add(ls.getProjectItemTargetRoomId()));
+        List<ProjectItemTargetRoom> dataList = projectItemTargetRoomService.getIds(ids);
+        Map<String, Object> result = new HashMap<>();
+        result.put("dataList", dataList);
+        result.put("totalCount", totalCount);
+        return Response.ok(result);
+    }
+
+
     @ApiOperation("获取房源评价")
     @RequestMapping(value = "/evaluate/{currPage}/{pageSize}", method = RequestMethod.POST)
     public Response list(@RequestBody RoomEvaluate roomEvaluate, @PathVariable int currPage, @PathVariable int pageSize) {

+ 26 - 0
virgo.api/src/main/java/com/bosshand/virgo/api/dao/FansDao.java

@@ -0,0 +1,26 @@
+package com.bosshand.virgo.api.dao;
+
+import com.bosshand.virgo.api.model.Fans;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+@Mapper
+public interface FansDao {
+
+    int insert(Fans fans);
+
+    int delete(long userId, long fansUserId);
+
+    Fans get(long userId, long fansUserId);
+
+    int getTotalCount(long userId);
+
+    List<Fans> getLimit(@Param("userId") long userId, @Param("currIndex") int currIndex, @Param("pageSize") int pageSize);
+
+    int getAttentionTotalCount(long userId);
+
+    List<Fans> getAttentionLimit(long userId, int currIndex, int pageSize);
+
+}

+ 2 - 0
virgo.api/src/main/java/com/bosshand/virgo/api/dao/ProjectItemTargetRoomDao.java

@@ -27,4 +27,6 @@ public interface ProjectItemTargetRoomDao {
 
     int deleteByProjectId(long projectId);
 
+    List<ProjectItemTargetRoom> getIds(List<Long> ids);
+
 }

+ 8 - 0
virgo.api/src/main/java/com/bosshand/virgo/api/dao/RoomCollectionDao.java

@@ -2,6 +2,9 @@ package com.bosshand.virgo.api.dao;
 
 import com.bosshand.virgo.api.model.RoomCollection;
 import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
 
 @Mapper
 public interface RoomCollectionDao {
@@ -11,4 +14,9 @@ public interface RoomCollectionDao {
     RoomCollection get(long projectItemTargetRoomId, long userId);
 
     int delete(long projectItemTargetRoomId, long userId);
+
+    int getTotalCount(long userId);
+
+    List<RoomCollection> getLimit(@Param("userId") long userId, @Param("currIndex") int currIndex, @Param("pageSize") int pageSize);
+
 }

+ 88 - 0
virgo.api/src/main/java/com/bosshand/virgo/api/model/Fans.java

@@ -0,0 +1,88 @@
+package com.bosshand.virgo.api.model;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+
+import java.util.Date;
+
+/**
+ * 粉丝关注
+ */
+public class Fans {
+
+    private long id;
+
+    /**
+     * 时间
+     */
+    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
+    private Date date;
+
+    /**
+     * 用户id
+     */
+    private long userId;
+
+    /**
+     * 粉丝id
+     */
+    private long fansUserId;
+
+    /**
+     * 粉丝名称
+     */
+    private String fansUserName;
+
+    /**
+     * 粉丝头像
+     */
+    private String fansUserPortrait;
+
+
+    public long getId() {
+        return id;
+    }
+
+    public void setId(long id) {
+        this.id = id;
+    }
+
+    public Date getDate() {
+        return date;
+    }
+
+    public void setDate(Date date) {
+        this.date = date;
+    }
+
+    public long getUserId() {
+        return userId;
+    }
+
+    public void setUserId(long userId) {
+        this.userId = userId;
+    }
+
+    public long getFansUserId() {
+        return fansUserId;
+    }
+
+    public void setFansUserId(long fansUserId) {
+        this.fansUserId = fansUserId;
+    }
+
+    public String getFansUserName() {
+        return fansUserName;
+    }
+
+    public void setFansUserName(String fansUserName) {
+        this.fansUserName = fansUserName;
+    }
+
+    public String getFansUserPortrait() {
+        return fansUserPortrait;
+    }
+
+    public void setFansUserPortrait(String fansUserPortrait) {
+        this.fansUserPortrait = fansUserPortrait;
+    }
+}

+ 62 - 0
virgo.api/src/main/java/com/bosshand/virgo/api/service/FansService.java

@@ -0,0 +1,62 @@
+package com.bosshand.virgo.api.service;
+
+import com.bosshand.virgo.api.dao.FansDao;
+import com.bosshand.virgo.api.dao.ProjectItemTargetRoomDao;
+import com.bosshand.virgo.api.model.Fans;
+import com.bosshand.virgo.api.model.ProjectItemTargetRoom;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+@Service
+public class FansService {
+
+    @Autowired
+    FansDao fansDao;
+
+    @Autowired
+    ProjectItemTargetRoomDao projectItemTargetRoomDao;
+
+    public int insert(long userId, long fansUserId) {
+        Fans fans = new Fans();
+        fans.setUserId(userId);
+        fans.setFansUserId(fansUserId);
+        return fansDao.insert(fans);
+    }
+
+    public int delete(long userId, long fansUserId) {
+        return fansDao.delete(userId, fansUserId);
+    }
+
+    public Fans get(long userId, long fansUserId) {
+        return fansDao.get(userId, fansUserId);
+    }
+
+    public int getTotalCount(long userId) {
+        return fansDao.getTotalCount(userId);
+    }
+
+    public List<Fans> getLimit(long userId, int currPage, int pageSize) {
+        int currIndex = (currPage - 1) * pageSize;
+        return fansDao.getLimit(userId, currIndex, pageSize);
+    }
+
+    public int getAttentionTotalCount(long userId) {
+        return fansDao.getAttentionTotalCount(userId);
+    }
+
+    public int getRoomTotalCount(long userId) {
+        ProjectItemTargetRoom room = new ProjectItemTargetRoom();
+        room.setChargePersonId(userId);
+        return projectItemTargetRoomDao.getTotalCount(room);
+    }
+
+    public List<Fans> getAttentionLimit(long userId, int currPage, int pageSize) {
+        int currIndex = (currPage - 1) * pageSize;
+        return fansDao.getAttentionLimit(userId, currIndex, pageSize);
+    }
+
+
+
+}

+ 22 - 6
virgo.api/src/main/java/com/bosshand/virgo/api/service/ProjectItemTargetRoomService.java

@@ -7,6 +7,7 @@ import com.bosshand.virgo.core.utils.StringUtil;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -84,19 +85,34 @@ public class ProjectItemTargetRoomService {
         return tag;
     }
 
+    private void setDtoName(ProjectItemTargetRoom room) {
+        Project project = this.getProject(room.getProjectId());
+        room.setProjectName(project.getName());
+        room.setCoordinates(project.getCoordinates());
+        room.setSupportingFacilities(project.getSupportingFacilities());
+        room.setProjectItemName(this.getProjectItem(room.getProjectItemId()).getName());
+        room.setProjectItemTargetName(this.getProjectItemTarget(room.getProjectItemTargetId()).getName());
+    }
+
     public ProjectItemTargetRoom get(long id) {
         ProjectItemTargetRoom room = projectItemTargetRoomDao.get(id);
         if(room != null){
-            Project project = this.getProject(room.getProjectId());
-            room.setProjectName(project.getName());
-            room.setCoordinates(project.getCoordinates());
-            room.setSupportingFacilities(project.getSupportingFacilities());
-            room.setProjectItemName(this.getProjectItem(room.getProjectItemId()).getName());
-            room.setProjectItemTargetName(this.getProjectItemTarget(room.getProjectItemTargetId()).getName());
+            setDtoName(room);
         }
         return room;
     }
 
+    public List<ProjectItemTargetRoom> getIds(List<Long> ids) {
+        if (ids.size() > 0) {
+            List<ProjectItemTargetRoom> list = projectItemTargetRoomDao.getIds(ids);
+            for (ProjectItemTargetRoom room : list) {
+                setDtoName(room);
+            }
+            return list;
+        }
+        return new ArrayList<>();
+    }
+
     public int getTotalCount(ProjectItemTargetRoom project) {
         return projectItemTargetRoomDao.getTotalCount(project);
     }

+ 9 - 0
virgo.api/src/main/java/com/bosshand/virgo/api/service/RoomService.java

@@ -59,6 +59,15 @@ public class RoomService {
         return roomCollectionDao.get(projectItemTargetRoomId, userId);
     }
 
+    public int getTotalCount(long userId) {
+        return roomCollectionDao.getTotalCount(userId);
+    }
+
+    public List<RoomCollection> getLimit(long userId, int currPage, int pageSize) {
+        int currIndex = (currPage - 1) * pageSize;
+        return roomCollectionDao.getLimit(userId, currIndex, pageSize);
+    }
+
     /**
      * 房源评价
      */

+ 44 - 0
virgo.api/src/main/resources/mapper/FansMapper.xml

@@ -0,0 +1,44 @@
+<?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.bosshand.virgo.api.dao.FansDao">
+
+    <resultMap type="com.bosshand.virgo.api.model.Fans" id="result">
+        <id column="id" property="id"/>
+        <result column="date" property="date"/>
+        <result column="userId" property="userId"/>
+        <result column="fansUserId" property="fansUserId"/>
+        <result column="fansUserName" property="fansUserName"/>
+        <result column="fansUserPortrait" property="fansUserPortrait"/>
+    </resultMap>
+
+    <insert id="insert" parameterType="com.bosshand.virgo.api.model.Fans" useGeneratedKeys="true" keyProperty="id">
+        INSERT INTO fans(`fansUserId`, `userId`, `date`) VALUES (#{fansUserId}, #{userId}, now())
+    </insert>
+
+    <delete id="delete">
+        DELETE FROM fans WHERE userId = #{userId} and fansUserId = #{fansUserId}
+    </delete>
+
+    <select id="get" resultMap="result">
+        SELECT * FROM fans where userId = #{userId} and fansUserId = #{fansUserId}
+    </select>
+
+    <select id="getTotalCount" parameterType="com.bosshand.virgo.api.model.Fans" resultType="Integer">
+        SELECT count(*) FROM fans where userId = #{userId}
+    </select>
+
+    <select id="getLimit" resultMap="result">
+        SELECT a.*, b.name as fansUserName, b.portrait as fansUserPortrait FROM fans a LEFT JOIN mgr_user b ON a.fansUserId = b.id
+        where a.userId = #{userId} order by a.date desc limit #{currIndex} , #{pageSize}
+    </select>
+
+    <select id="getAttentionTotalCount" parameterType="com.bosshand.virgo.api.model.Fans" resultType="Integer">
+        SELECT count(*) FROM fans where fansUserId = #{userId}
+    </select>
+
+    <select id="getAttentionLimit" resultMap="result">
+        SELECT a.*, b.name as fansUserName, b.portrait as fansUserPortrait FROM fans a LEFT JOIN mgr_user b ON a.userId = b.id
+        where a.fansUserId = #{userId} order by a.date desc limit #{currIndex} , #{pageSize}
+    </select>
+
+</mapper>

+ 8 - 0
virgo.api/src/main/resources/mapper/ProjectItemTargetRoomMapper.xml

@@ -44,6 +44,14 @@
         where a.id=#{id}
     </select>
 
+    <select id="getIds" resultMap="projectItemTargetRoomResult">
+        <include refid="ProjectItemTargetRoomQuery"/>
+        where a.id in
+        <foreach collection="list" item="id" index="index" open="(" close=")" separator=",">
+            #{id}
+        </foreach>
+    </select>
+
     <select id="getProjectItemTargetId" resultMap="projectItemTargetRoomResult">
         <include refid="ProjectItemTargetRoomQuery"/>
         where a.projectItemTargetId=#{projectItemTargetId}

+ 8 - 0
virgo.api/src/main/resources/mapper/RoomCollectionMapper.xml

@@ -21,4 +21,12 @@
         DELETE FROM room_collection WHERE projectItemTargetRoomId = #{projectItemTargetRoomId} and userId = #{userId}
     </delete>
 
+    <select id="getTotalCount" parameterType="com.bosshand.virgo.api.model.Fans" resultType="Integer">
+        SELECT count(*) FROM room_collection where userId = #{userId}
+    </select>
+
+    <select id="getLimit" resultMap="result">
+        SELECT * FROM room_collection where userId = #{userId} order by date desc limit #{currIndex} , #{pageSize}
+    </select>
+
 </mapper>