修复聊天功能

This commit is contained in:
gxwebsoft
2024-04-28 21:10:21 +08:00
parent 84bf417062
commit 69891d133d
17 changed files with 492 additions and 7 deletions

View File

@@ -16,6 +16,7 @@ import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
/**
@@ -95,10 +96,17 @@ public class ChatMessageController extends BaseController {
@ApiOperation("批量添加聊天消息表")
@PostMapping("/batch")
public ApiResult<?> saveBatch(@RequestBody List<ChatMessage> list) {
if (chatMessageService.saveBatch(list)) {
return success("添加成功");
final ArrayList<ChatMessage> saveData = new ArrayList<>();
list.forEach(d -> {
d.setFormUserId(getLoginUserId());
saveData.add(d);
});
if(!saveData.isEmpty()){
if (chatMessageService.saveBatch(saveData)) {
return success("发送成功");
}
}
return fail("添加失败");
return fail("发送失败");
}
@PreAuthorize("hasAuthority('sys:chatMessage:update')")

View File

@@ -7,10 +7,12 @@ import com.gxwebsoft.common.core.exception.BusinessException;
import com.gxwebsoft.common.core.web.*;
import com.gxwebsoft.common.system.entity.Company;
import com.gxwebsoft.common.system.entity.User;
import com.gxwebsoft.common.system.entity.UserCollection;
import com.gxwebsoft.common.system.mapper.CompanyMapper;
import com.gxwebsoft.common.system.param.CompanyParam;
import com.gxwebsoft.common.system.service.CompanyService;
import com.gxwebsoft.common.system.service.TenantService;
import com.gxwebsoft.common.system.service.UserCollectionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
@@ -19,7 +21,10 @@ import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
/**
* 企业信息控制器
@@ -37,10 +42,31 @@ public class CompanyController extends BaseController {
private TenantService tenantService;
@Resource
private CompanyMapper companyMapper;
@Resource
private UserCollectionService userCollectionService;
@ApiOperation("分页查询企业信息不限租户")
@GetMapping("/pageAll")
public ApiResult<PageResult<Company>> pageAll(CompanyParam param) {
final User loginUser = getLoginUser();
if(loginUser != null){
// 我的收藏
final List<UserCollection> myFocus = userCollectionService.list(new LambdaQueryWrapper<UserCollection>().eq(UserCollection::getUserId, getLoginUserId()));
if (!CollectionUtils.isEmpty(myFocus)) {
final Set<Integer> collect = myFocus.stream().map(UserCollection::getTid).collect(Collectors.toSet());
if (param.getVersion() != null && param.getVersion().equals(99)) {
param.setVersion(null);
param.setCompanyIds(collect);
}
final PageResult<Company> result = companyService.pageRelAll(param);
System.out.println("collect = " + collect);
result.getList().forEach(d -> {
d.setCollection(collect.contains(d.getCompanyId()));
});
return success(result);
}
}
// 使用关联查询
return success(companyService.pageRelAll(param));
}

View File

@@ -507,8 +507,15 @@ public class MainController extends BaseController {
company.setCompanyLogo("/logo.svg");
company.setPhone(phone);
company.setMembers(20);
company.setServerUrl("https://server.gxwebosoft.com");
company.setModulesUrl("https://modules.gxwebosoft.com");
company.setServerUrl("https://server.gxwebsoft.com");
company.setModulesUrl("https://modules.gxwebsoft.com");
company.setSocketUrl("wss://server.gxwebsoft.com");
company.setAdminUrl("http://".concat(tenant.getTenantId().toString()).concat(".adm.wsdns.cn"));
company.setMerchantUrl("http://".concat(tenant.getTenantId().toString()).concat(".m.wsdns.cn"));
company.setWebsiteUrl("http://".concat(tenant.getTenantId().toString()).concat(".wsdns.cn"));
company.setH5Code("http://".concat(tenant.getTenantId().toString()).concat(".h5.wsdns.cn"));
company.setAndroidUrl("http://".concat(tenant.getTenantId().toString()).concat(".android.wsdns.cn"));
company.setIosUrl("http://".concat(tenant.getTenantId().toString()).concat(".ios.wsdns.cn"));
company.setVersion(10);
company.setIndustryParent("");
company.setIndustryChild("");
@@ -519,6 +526,7 @@ public class MainController extends BaseController {
company.setUsers(2);
company.setClicks(1L);
company.setLikes(0L);
company.setTid(tenant.getTenantId());
company.setCompanyType("企业");
company.setEmail(user.getEmail());
company.setUserId(admin.getUserId());

View File

@@ -0,0 +1,136 @@
package com.gxwebsoft.common.system.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.gxwebsoft.common.core.web.BaseController;
import com.gxwebsoft.common.system.entity.User;
import com.gxwebsoft.common.system.service.UserCollectionService;
import com.gxwebsoft.common.system.entity.UserCollection;
import com.gxwebsoft.common.system.param.UserCollectionParam;
import com.gxwebsoft.common.core.web.ApiResult;
import com.gxwebsoft.common.core.web.PageResult;
import com.gxwebsoft.common.core.web.PageParam;
import com.gxwebsoft.common.core.web.BatchParam;
import com.gxwebsoft.common.core.annotation.OperationLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
/**
* 我的收藏控制器
*
* @author 科技小王子
* @since 2024-04-28 18:08:32
*/
@Api(tags = "我的收藏管理")
@RestController
@RequestMapping("/api/system/user-collection")
public class UserCollectionController extends BaseController {
@Resource
private UserCollectionService userCollectionService;
@PreAuthorize("hasAuthority('sys:userCollection:list')")
@ApiOperation("分页查询我的收藏")
@GetMapping("/page")
public ApiResult<PageResult<UserCollection>> page(UserCollectionParam param) {
// 使用关联查询
return success(userCollectionService.pageRel(param));
}
@PreAuthorize("hasAuthority('sys:userCollection:list')")
@ApiOperation("查询全部我的收藏")
@GetMapping()
public ApiResult<List<UserCollection>> list(UserCollectionParam param) {
// 使用关联查询
return success(userCollectionService.listRel(param));
}
@PreAuthorize("hasAuthority('sys:userCollection:list')")
@ApiOperation("根据id查询我的收藏")
@GetMapping("/{id}")
public ApiResult<UserCollection> get(@PathVariable("id") Integer id) {
// 使用关联查询
return success(userCollectionService.getByIdRel(id));
}
@PreAuthorize("hasAuthority('sys:userCollection:save')")
@OperationLog
@ApiOperation("添加和取消收藏")
@PostMapping()
public ApiResult<?> save(@RequestBody UserCollection userCollection) {
// 记录当前登录用户id
User loginUser = getLoginUser();
if (loginUser != null) {
userCollection.setUserId(loginUser.getUserId());
userCollection.setTid(userCollection.getTid());
final UserCollection one = userCollectionService.getOne(new LambdaQueryWrapper<UserCollection>().eq(UserCollection::getUserId, loginUser.getUserId()).eq(UserCollection::getTid, userCollection.getTid()).last("limit 1"));
if (one != null) {
userCollectionService.removeById(one.getId());
return success("已取消收藏");
}
if (userCollectionService.save(userCollection)) {
return success("已添加收藏");
}
}
return fail("添加失败");
}
@PreAuthorize("hasAuthority('sys:userCollection:update')")
@OperationLog
@ApiOperation("修改我的收藏")
@PutMapping()
public ApiResult<?> update(@RequestBody UserCollection userCollection) {
if (userCollectionService.updateById(userCollection)) {
return success("修改成功");
}
return fail("修改失败");
}
@PreAuthorize("hasAuthority('sys:userCollection:remove')")
@OperationLog
@ApiOperation("删除我的收藏")
@DeleteMapping("/{id}")
public ApiResult<?> remove(@PathVariable("id") Integer id) {
if (userCollectionService.removeById(id)) {
return success("删除成功");
}
return fail("删除失败");
}
@PreAuthorize("hasAuthority('sys:userCollection:save')")
@OperationLog
@ApiOperation("批量添加我的收藏")
@PostMapping("/batch")
public ApiResult<?> saveBatch(@RequestBody List<UserCollection> list) {
if (userCollectionService.saveBatch(list)) {
return success("添加成功");
}
return fail("添加失败");
}
@PreAuthorize("hasAuthority('sys:userCollection:update')")
@OperationLog
@ApiOperation("批量修改我的收藏")
@PutMapping("/batch")
public ApiResult<?> removeBatch(@RequestBody BatchParam<UserCollection> batchParam) {
if (batchParam.update(userCollectionService, "id")) {
return success("修改成功");
}
return fail("修改失败");
}
@PreAuthorize("hasAuthority('sys:userCollection:remove')")
@OperationLog
@ApiOperation("批量删除我的收藏")
@DeleteMapping("/batch")
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
if (userCollectionService.removeByIds(ids)) {
return success("删除成功");
}
return fail("删除失败");
}
}

View File

@@ -136,7 +136,7 @@ public class Company implements Serializable {
@ApiModelProperty(value = "主控端节点")
private String serverUrl;
@ApiModelProperty(value = "模块服务器节点")
@ApiModelProperty(value = "模块节点")
private String modulesUrl;
@ApiModelProperty(value = "重定向节点")
@@ -148,6 +148,27 @@ public class Company implements Serializable {
@ApiModelProperty(value = "socket合法域名")
private String socketUrl;
@ApiModelProperty(value = "总后台管理入口")
private String adminUrl;
@ApiModelProperty(value = "商户端管理入口")
private String merchantUrl;
@ApiModelProperty(value = "默认网站URL")
private String websiteUrl;
@ApiModelProperty(value = "微信小程序二维码")
private String mpWeixinCode;
@ApiModelProperty(value = "H5端应用二维码")
private String h5Code;
@ApiModelProperty(value = "安卓APP二维码")
private String androidUrl;
@ApiModelProperty(value = "苹果APP二维码")
private String iosUrl;
@ApiModelProperty(value = "应用类型")
private String appType;
@@ -185,6 +206,9 @@ public class Company implements Serializable {
@ApiModelProperty("商户ID")
private Integer merchantId;
@ApiModelProperty(value = "租户ID")
private Integer tid;
@ApiModelProperty(value = "租户id")
private Integer tenantId;
@@ -208,4 +232,7 @@ public class Company implements Serializable {
@TableField(exist = false)
private Object config;
@ApiModelProperty(value = "是否已收藏")
private Boolean collection;
}

View File

@@ -0,0 +1,44 @@
package com.gxwebsoft.common.system.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import java.time.LocalDateTime;
import java.io.Serializable;
import java.util.Date;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* 我的收藏
*
* @author 科技小王子
* @since 2024-04-28 18:08:32
*/
@Data
@EqualsAndHashCode(callSuper = false)
@ApiModel(value = "UserCollection对象", description = "我的收藏")
@TableName("sys_user_collection")
public class UserCollection implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "主键ID")
@TableId(value = "id", type = IdType.AUTO)
private Integer id;
@ApiModelProperty(value = "租户ID")
private Integer tid;
@ApiModelProperty(value = "用户ID")
private Integer userId;
@ApiModelProperty(value = "租户id")
private Integer tenantId;
@ApiModelProperty(value = "注册时间")
private Date createTime;
}

View File

@@ -0,0 +1,37 @@
package com.gxwebsoft.common.system.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.gxwebsoft.common.system.entity.UserCollection;
import com.gxwebsoft.common.system.param.UserCollectionParam;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* 我的收藏Mapper
*
* @author 科技小王子
* @since 2024-04-28 18:08:32
*/
public interface UserCollectionMapper extends BaseMapper<UserCollection> {
/**
* 分页查询
*
* @param page 分页对象
* @param param 查询参数
* @return List<UserCollection>
*/
List<UserCollection> selectPageRel(@Param("page") IPage<UserCollection> page,
@Param("param") UserCollectionParam param);
/**
* 查询全部
*
* @param param 查询参数
* @return List<User>
*/
List<UserCollection> selectListRel(@Param("param") UserCollectionParam param);
}

View File

@@ -54,6 +54,14 @@
<if test="param.createTimeEnd != null">
AND a.create_time &lt;= #{param.createTimeEnd}
</if>
<if test="param.keywords != null">
AND (
a.content LIKE CONCAT('%', #{param.keywords}, '%')
OR b.nickname LIKE CONCAT('%', #{param.keywords}, '%')
OR b.phone LIKE CONCAT('%', #{param.keywords}, '%')
OR b.real_name LIKE CONCAT('%', #{param.keywords}, '%')
)
</if>
</where>
</sql>

View File

@@ -113,6 +113,12 @@
<if test="param.merchantId != null">
AND a.merchant_id = #{param.merchantId}
</if>
<if test="param.companyIds != null">
AND a.company_id IN
<foreach collection="param.companyIds" item="item" separator="," open="(" close=")">
#{item}
</foreach>
</if>
<if test="param.keywords != null">
AND (a.company_name LIKE CONCAT('%', #{param.keywords}, '%')
OR a.short_name LIKE CONCAT('%', #{param.keywords}, '%')

View File

@@ -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.gxwebsoft.common.system.mapper.UserCollectionMapper">
<!-- 关联查询sql -->
<sql id="selectSql">
SELECT a.*
FROM sys_user_collection a
<where>
<if test="param.id != null">
AND a.id = #{param.id}
</if>
<if test="param.tid != null">
AND a.tid = #{param.tid}
</if>
<if test="param.userId != null">
AND a.user_id = #{param.userId}
</if>
<if test="param.createTimeStart != null">
AND a.create_time &gt;= #{param.createTimeStart}
</if>
<if test="param.createTimeEnd != null">
AND a.create_time &lt;= #{param.createTimeEnd}
</if>
</where>
</sql>
<!-- 分页查询 -->
<select id="selectPageRel" resultType="com.gxwebsoft.common.system.entity.UserCollection">
<include refid="selectSql"></include>
</select>
<!-- 查询全部 -->
<select id="selectListRel" resultType="com.gxwebsoft.common.system.entity.UserCollection">
<include refid="selectSql"></include>
</select>
</mapper>

View File

@@ -6,9 +6,12 @@ import com.gxwebsoft.common.core.annotation.QueryType;
import com.gxwebsoft.common.core.web.BaseParam;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.models.auth.In;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.Set;
/**
* 聊天消息表查询参数
*
@@ -67,4 +70,7 @@ public class ChatMessageParam extends BaseParam {
@QueryField(type = QueryType.EQ)
private Integer deleted;
@ApiModelProperty(value = "接收人ID集合")
private Set<Integer> toUserIds;
}

View File

@@ -1,5 +1,6 @@
package com.gxwebsoft.common.system.param;
import com.baomidou.mybatisplus.annotation.TableField;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.gxwebsoft.common.core.annotation.QueryField;
import com.gxwebsoft.common.core.annotation.QueryType;
@@ -9,6 +10,8 @@ import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.Set;
/**
* 企业信息查询参数
*
@@ -143,4 +146,8 @@ public class CompanyParam extends BaseParam {
@QueryField(type = QueryType.EQ)
private String appName;
@ApiModelProperty(value = "企业id集合")
@TableField(exist = false)
private Set<Integer> companyIds;
}

View File

@@ -0,0 +1,37 @@
package com.gxwebsoft.common.system.param;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.gxwebsoft.common.core.annotation.QueryField;
import com.gxwebsoft.common.core.annotation.QueryType;
import com.gxwebsoft.common.core.web.BaseParam;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* 我的收藏查询参数
*
* @author 科技小王子
* @since 2024-04-28 18:08:32
*/
@Data
@EqualsAndHashCode(callSuper = false)
@JsonInclude(JsonInclude.Include.NON_NULL)
@ApiModel(value = "UserCollectionParam对象", description = "我的收藏查询参数")
public class UserCollectionParam extends BaseParam {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "主键ID")
@QueryField(type = QueryType.EQ)
private Integer id;
@ApiModelProperty(value = "租户ID")
@QueryField(type = QueryType.EQ)
private Integer tid;
@ApiModelProperty(value = "用户ID")
@QueryField(type = QueryType.EQ)
private Integer userId;
}

View File

@@ -0,0 +1,42 @@
package com.gxwebsoft.common.system.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.gxwebsoft.common.core.web.PageResult;
import com.gxwebsoft.common.system.entity.UserCollection;
import com.gxwebsoft.common.system.param.UserCollectionParam;
import java.util.List;
/**
* 我的收藏Service
*
* @author 科技小王子
* @since 2024-04-28 18:08:32
*/
public interface UserCollectionService extends IService<UserCollection> {
/**
* 分页关联查询
*
* @param param 查询参数
* @return PageResult<UserCollection>
*/
PageResult<UserCollection> pageRel(UserCollectionParam param);
/**
* 关联查询全部
*
* @param param 查询参数
* @return List<UserCollection>
*/
List<UserCollection> listRel(UserCollectionParam param);
/**
* 根据id查询
*
* @param id 主键ID
* @return UserCollection
*/
UserCollection getByIdRel(Integer id);
}

View File

@@ -1,7 +1,10 @@
package com.gxwebsoft.common.system.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.common.system.entity.Company;
import com.gxwebsoft.common.system.mapper.TenantMapper;
import com.gxwebsoft.common.system.service.CompanyService;
import com.gxwebsoft.common.system.service.TenantService;
import com.gxwebsoft.common.system.entity.Tenant;
import com.gxwebsoft.common.system.param.TenantParam;
@@ -9,6 +12,7 @@ import com.gxwebsoft.common.core.web.PageParam;
import com.gxwebsoft.common.core.web.PageResult;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
/**
@@ -20,6 +24,9 @@ import java.util.List;
@Service
public class TenantServiceImpl extends ServiceImpl<TenantMapper, Tenant> implements TenantService {
@Resource
private CompanyService companyService;
@Override
public PageResult<Tenant> pageRel(TenantParam param) {
PageParam<Tenant, TenantParam> page = new PageParam<>(param);

View File

@@ -0,0 +1,47 @@
package com.gxwebsoft.common.system.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.common.system.mapper.UserCollectionMapper;
import com.gxwebsoft.common.system.service.UserCollectionService;
import com.gxwebsoft.common.system.entity.UserCollection;
import com.gxwebsoft.common.system.param.UserCollectionParam;
import com.gxwebsoft.common.core.web.PageParam;
import com.gxwebsoft.common.core.web.PageResult;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* 我的收藏Service实现
*
* @author 科技小王子
* @since 2024-04-28 18:08:32
*/
@Service
public class UserCollectionServiceImpl extends ServiceImpl<UserCollectionMapper, UserCollection> implements UserCollectionService {
@Override
public PageResult<UserCollection> pageRel(UserCollectionParam param) {
PageParam<UserCollection, UserCollectionParam> page = new PageParam<>(param);
//page.setDefaultOrder("create_time desc");
List<UserCollection> list = baseMapper.selectPageRel(page, param);
return new PageResult<>(list, page.getTotal());
}
@Override
public List<UserCollection> listRel(UserCollectionParam param) {
List<UserCollection> list = baseMapper.selectListRel(param);
// 排序
PageParam<UserCollection, UserCollectionParam> page = new PageParam<>();
//page.setDefaultOrder("create_time desc");
return page.sortRecords(list);
}
@Override
public UserCollection getByIdRel(Integer id) {
UserCollectionParam param = new UserCollectionParam();
param.setId(id);
return param.getOne(baseMapper.selectListRel(param));
}
}

View File

@@ -68,7 +68,8 @@ public class SysGenerator {
// "sys_website",
// "sys_website_field",
// "sys_white_domain"
// "sys_order"
// "sys_order",
"sys_user_collection"
};
// 需要去除的表前缀
private static final String[] TABLE_PREFIX = new String[]{