通知中心接口

This commit is contained in:
张松 2025-04-07 10:05:00 +08:00
parent 1b2551dfb1
commit b45a2bd82f
8 changed files with 347 additions and 0 deletions

View File

@ -0,0 +1,72 @@
package com.czg.controller.admin;
import com.czg.account.entity.SyncNotice;
import com.czg.account.service.SyncNoticeService;
import com.czg.product.dto.SyncNoticeReadDTO;
import com.czg.resp.CzgResult;
import com.czg.sa.StpKit;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
/**
* @author Administrator
*/
@RestController
@RequestMapping("/admin/syncNotice")
public class SyncNoticeController {
@Resource
private SyncNoticeService syncNoticeService;
/**
* 通知消息列表
* @param name 名称
* @param startTime 起始时间
* @param endTime 结束时间
* @param type 0-商品 1-耗材
* @param isRead 0-未读 1-已读
* @return 分页数据
*/
@GetMapping
public CzgResult<Page<SyncNotice>> page(@RequestParam(required = false) String name, @RequestParam(required = false) String startTime,
@RequestParam(required = false) String endTime, @RequestParam(required = false) Integer type,
@RequestParam(required = false) Integer isRead) {
return CzgResult.success(syncNoticeService.pageInfo(StpKit.USER.getShopId(), name, startTime, endTime, type, isRead));
}
/**
* 详情
* @param id id
* @return 详细信息
*/
@GetMapping("/detail")
public CzgResult<SyncNotice> detail(@RequestParam Long id) {
return CzgResult.success(syncNoticeService.getOne(new QueryWrapper().eq(SyncNotice::getShopId, StpKit.USER.getShopId()).eq(SyncNotice::getId, id)));
}
/**
* 已读消息
* @return 是否成功
*/
@PutMapping("/read")
public CzgResult<Boolean> read(@RequestBody @Validated SyncNoticeReadDTO syncNoticeReadDTO) {
return CzgResult.success(syncNoticeService.read(StpKit.USER.getShopId(), syncNoticeReadDTO));
}
/**
* 消息统计
* @return 消息记录数
*/
@PutMapping("/count")
public CzgResult<Long> count(@RequestParam Integer isRead) {
QueryWrapper queryWrapper = new QueryWrapper().eq(SyncNotice::getShopId, StpKit.USER.getShopId());
queryWrapper.eq(SyncNotice::getIsRead, isRead);
return CzgResult.success(syncNoticeService.count(queryWrapper));
}
}

View File

@ -0,0 +1,64 @@
package com.czg.account.dto;
import java.io.Serializable;
import java.time.LocalDateTime;
import com.alibaba.fastjson2.annotation.JSONField;
import java.io.Serial;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* 实体类
*
* @author zs
* @since 2025-04-07
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class SyncNoticeDTO implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
private Long id;
/**
* 商品名称或耗材名称
*/
private String name;
/**
* 来源id
*/
private Long sourceId;
/**
* 操作用户id
*/
private Long sysUserId;
/**
* 通知类型 0 商品变动 1 耗材变动
*/
private Integer type;
/**
* 是否已读1已读
*/
private Integer isRead;
/**
* 店铺id
*/
private Long shopId;
/**
* 创建时间
*/
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime createTime;
}

View File

@ -0,0 +1,73 @@
package com.czg.account.entity;
import com.mybatisflex.annotation.Column;
import com.mybatisflex.annotation.Id;
import com.mybatisflex.annotation.KeyType;
import com.mybatisflex.annotation.Table;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.io.Serial;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* 实体类
*
* @author zs
* @since 2025-04-07
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Table("tb_sync_notice")
public class SyncNotice implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
@Id(keyType = KeyType.Auto)
private Long id;
/**
* 商品名称或耗材名称
*/
private String name;
/**
* 来源id
*/
private Long sourceId;
/**
* 操作用户id
*/
private Long sysUserId;
/**
* 通知类型 0 商品变动 1 耗材变动
*/
private Integer type;
/**
* 是否已读1已读
*/
private Integer isRead;
/**
* 店铺id
*/
private Long shopId;
/**
* 创建时间
*/
@Column(onInsertValue = "now()")
private LocalDateTime createTime;
private LocalDateTime readTime;
}

View File

@ -0,0 +1,31 @@
package com.czg.account.service;
import com.czg.product.dto.SyncNoticeReadDTO;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.service.IService;
import com.czg.account.entity.SyncNotice;
import java.util.List;
/**
* 服务层
*
* @author zs
* @since 2025-04-07
*/
public interface SyncNoticeService extends IService<SyncNotice> {
/**
* 添加消息
* @param shopId 店铺id
* @param sysUserId 操作用户id
* @param name 商品/耗材名称
* @param id 商品/耗材id
* @param type 0-商品 1-耗材
*/
void addNotice(Long shopId, Long sysUserId, String name, Long id, Integer type);
Page<SyncNotice> pageInfo(Long shopId, String name, String startTime, String endTime, Integer type, Integer isRead);
Boolean read(Long shopId, SyncNoticeReadDTO syncNoticeReadDTO);
}

View File

@ -0,0 +1,18 @@
package com.czg.product.dto;
import jakarta.validation.constraints.NotEmpty;
import lombok.Data;
import java.util.List;
/**
* @author Administrator
*/
@Data
public class SyncNoticeReadDTO {
/**
* 消息id
*/
@NotEmpty
private List<Long> noticeIdList;
}

View File

@ -0,0 +1,14 @@
package com.czg.service.account.mapper;
import com.mybatisflex.core.BaseMapper;
import com.czg.account.entity.SyncNotice;
/**
* 映射层
*
* @author zs
* @since 2025-04-07
*/
public interface SyncNoticeMapper extends BaseMapper<SyncNotice> {
}

View File

@ -0,0 +1,68 @@
package com.czg.service.account.service.impl;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.czg.product.dto.SyncNoticeReadDTO;
import com.czg.utils.PageUtil;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.czg.account.entity.SyncNotice;
import com.czg.account.service.SyncNoticeService;
import com.czg.service.account.mapper.SyncNoticeMapper;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* 服务层实现
*
* @author zs
* @since 2025-04-07
*/
@Service
public class SyncNoticeServiceImpl extends ServiceImpl<SyncNoticeMapper, SyncNotice> implements SyncNoticeService {
@Override
public void addNotice(Long shopId, Long sysUserId, String name, Long id, Integer type) {
SyncNotice syncNotice = new SyncNotice();
syncNotice.setShopId(shopId);
syncNotice.setSysUserId(sysUserId);
syncNotice.setName(name);
syncNotice.setSourceId(id);
syncNotice.setType(type);
save(syncNotice);
}
@Override
public Page<SyncNotice> pageInfo(Long shopId, String name, String startTime, String endTime, Integer type, Integer isRead) {
QueryWrapper queryWrapper = new QueryWrapper().eq(SyncNotice::getShopId, shopId);
if (StrUtil.isNotBlank(name)) {
queryWrapper.like(SyncNotice::getName, name);
}
if (StrUtil.isNotBlank(startTime)) {
queryWrapper.ge(SyncNotice::getCreateTime, startTime);
}
if (StrUtil.isNotBlank(endTime)) {
queryWrapper.le(SyncNotice::getCreateTime, endTime);
}
queryWrapper.eq(SyncNotice::getType, type);
queryWrapper.eq(SyncNotice::getIsRead, isRead);
queryWrapper.orderBy(SyncNotice::getCreateTime, false);
return page(PageUtil.buildPage(), queryWrapper);
}
@Override
public Boolean read(Long shopId, SyncNoticeReadDTO syncNoticeReadDTO) {
List<SyncNotice> listed = list(new QueryWrapper().eq(SyncNotice::getShopId, shopId).in(SyncNotice::getId, syncNoticeReadDTO.getNoticeIdList()));
listed.forEach(item -> {
if (item.getIsRead() == 0) {
item.setIsRead(1);
item.setReadTime(DateUtil.date().toLocalDateTime());
}
});
return updateBatch(listed);
}
}

View File

@ -0,0 +1,7 @@
<?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.czg.service.account.mapper.SyncNoticeMapper">
</mapper>