From f4233054dd24083b644f4bf71cac09720e08d1c5 Mon Sep 17 00:00:00 2001 From: xiangpei <xiangpei@timesnew.cn> Date: 星期日, 07 四月 2024 17:09:24 +0800 Subject: [PATCH] 通知接口 --- ycl-pojo/src/main/java/com/ycl/platform/domain/vo/NotifyVO.java | 50 ++++++ ycl-server/src/main/java/com/ycl/platform/mapper/NotifyMapper.java | 19 ++ ycl-server/src/main/java/com/ycl/platform/service/impl/NotifyServiceImpl.java | 145 ++++++++++++++++++ ycl-server/src/main/java/com/ycl/platform/service/NotifyService.java | 65 ++++++++ ycl-server/src/main/resources/mapper/zgyw/NotifyMapper.xml | 18 ++ ycl-pojo/src/main/java/com/ycl/platform/domain/query/NotifyQuery.java | 23 ++ ycl-pojo/src/main/java/com/ycl/platform/domain/entity/Notify.java | 50 ++++++ ycl-pojo/src/main/java/com/ycl/platform/domain/form/NotifyForm.java | 60 +++++++ 8 files changed, 430 insertions(+), 0 deletions(-) diff --git a/ycl-pojo/src/main/java/com/ycl/platform/domain/entity/Notify.java b/ycl-pojo/src/main/java/com/ycl/platform/domain/entity/Notify.java new file mode 100644 index 0000000..978f139 --- /dev/null +++ b/ycl-pojo/src/main/java/com/ycl/platform/domain/entity/Notify.java @@ -0,0 +1,50 @@ +package com.ycl.platform.domain.entity; + +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableName; +import com.ycl.platform.base.AbsEntity; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.experimental.Accessors; + +/** + * 閫氱煡 + * + * @author xp + * @since 2024-04-07 + */ +@Data +@Accessors(chain = true) +@TableName("t_notify") +@ApiModel(value = "Notify瀵硅薄", description = "閫氱煡") +public class Notify extends AbsEntity { + + private static final long serialVersionUID = 1L; + + @ApiModelProperty("閫氱煡绫诲瀷") + @TableField("notify_type") + private String notifyType; + + @ApiModelProperty("閫氱煡鍐呭") + @TableField("content") + private String content; + + @ApiModelProperty("閫氱煡璋�") + @TableField("notify_who") + private Integer notifyWho; + + @ApiModelProperty("宸茶") + @TableField("readed") + private String readed; + + @ApiModelProperty("绱ф��") + @TableField("urgent") + private String urgent; + + @ApiModelProperty("宸ュ崟ID") + @TableField("work_order_id") + private Integer workOrderId; + + +} diff --git a/ycl-pojo/src/main/java/com/ycl/platform/domain/form/NotifyForm.java b/ycl-pojo/src/main/java/com/ycl/platform/domain/form/NotifyForm.java new file mode 100644 index 0000000..08b7e0a --- /dev/null +++ b/ycl-pojo/src/main/java/com/ycl/platform/domain/form/NotifyForm.java @@ -0,0 +1,60 @@ +package com.ycl.platform.domain.form; + +import com.ycl.system.domain.group.Update; +import com.ycl.system.domain.group.Add; +import com.ycl.platform.base.AbsForm; +import com.ycl.platform.domain.entity.Notify; +import java.time.LocalDateTime; +import org.springframework.beans.BeanUtils; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; +import org.springframework.lang.NonNull; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.experimental.Accessors; + +/** + * 閫氱煡琛ㄥ崟 + * + * @author xp + * @since 2024-04-07 + */ +@Data +@Accessors(chain = true) +@ApiModel(value = "Notify琛ㄥ崟", description = "閫氱煡琛ㄥ崟") +public class NotifyForm extends AbsForm { + + @NotBlank(message = "閫氱煡绫诲瀷涓嶈兘涓虹┖", groups = {Add.class, Update.class}) + @ApiModelProperty("閫氱煡绫诲瀷") + private String notifyType; + + @NotBlank(message = "閫氱煡鍐呭涓嶈兘涓虹┖", groups = {Add.class, Update.class}) + @ApiModelProperty("閫氱煡鍐呭") + private String content; + + @NotNull(message = "閫氱煡璋佷笉鑳戒负绌�", groups = {Add.class, Update.class}) + @ApiModelProperty("閫氱煡璋�") + private Integer notifyWho; + + @NotBlank(message = "宸茶涓嶈兘涓虹┖", groups = {Add.class, Update.class}) + @ApiModelProperty("宸茶") + private String readed; + + @NotBlank(message = "绱ф�ヤ笉鑳戒负绌�", groups = {Add.class, Update.class}) + @ApiModelProperty("绱ф��") + private String urgent; + + @NotNull(message = "宸ュ崟ID涓嶈兘涓虹┖", groups = {Add.class, Update.class}) + @ApiModelProperty("宸ュ崟ID") + private Integer workOrderId; + + public static Notify getEntityByForm(@NonNull NotifyForm form, Notify entity) { + if(entity == null) { + entity = new Notify(); + } + BeanUtils.copyProperties(form, entity); + return entity; + } + +} diff --git a/ycl-pojo/src/main/java/com/ycl/platform/domain/query/NotifyQuery.java b/ycl-pojo/src/main/java/com/ycl/platform/domain/query/NotifyQuery.java new file mode 100644 index 0000000..f4731aa --- /dev/null +++ b/ycl-pojo/src/main/java/com/ycl/platform/domain/query/NotifyQuery.java @@ -0,0 +1,23 @@ +package com.ycl.platform.domain.query; + +import com.ycl.platform.base.AbsQuery; +import java.util.List; +import org.springframework.lang.NonNull; +import jakarta.validation.constraints.NotBlank; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.experimental.Accessors; + +/** + * 閫氱煡鏌ヨ + * + * @author xp + * @since 2024-04-07 + */ +@Data +@Accessors(chain = true) +@ApiModel(value = "Notify鏌ヨ", description = "閫氱煡鏌ヨ") +public class NotifyQuery extends AbsQuery { +} + diff --git a/ycl-pojo/src/main/java/com/ycl/platform/domain/vo/NotifyVO.java b/ycl-pojo/src/main/java/com/ycl/platform/domain/vo/NotifyVO.java new file mode 100644 index 0000000..fbe8397 --- /dev/null +++ b/ycl-pojo/src/main/java/com/ycl/platform/domain/vo/NotifyVO.java @@ -0,0 +1,50 @@ +package com.ycl.platform.domain.vo; + +import com.ycl.platform.base.AbsVo; +import com.ycl.platform.domain.entity.Notify; +import java.util.List; +import java.time.LocalDateTime; +import org.springframework.lang.NonNull; +import org.springframework.beans.BeanUtils; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.experimental.Accessors; + +/** + * 閫氱煡灞曠ず + * + * @author xp + * @since 2024-04-07 + */ +@Data +@Accessors(chain = true) +public class NotifyVO extends AbsVo { + + /** 閫氱煡绫诲瀷 */ + private String notifyType; + + /** 閫氱煡鍐呭 */ + private String content; + + /** 閫氱煡璋� */ + private Integer notifyWho; + + /** 宸茶 */ + private String readed; + + /** 绱ф�� */ + private String urgent; + + /** 宸ュ崟ID */ + private Integer workOrderId; + + public static NotifyVO getVoByEntity(@NonNull Notify entity, NotifyVO vo) { + if(vo == null) { + vo = new NotifyVO(); + } + BeanUtils.copyProperties(entity, vo); + return vo; + } + +} diff --git a/ycl-server/src/main/java/com/ycl/platform/mapper/NotifyMapper.java b/ycl-server/src/main/java/com/ycl/platform/mapper/NotifyMapper.java new file mode 100644 index 0000000..92912d8 --- /dev/null +++ b/ycl-server/src/main/java/com/ycl/platform/mapper/NotifyMapper.java @@ -0,0 +1,19 @@ +package com.ycl.platform.mapper; + +import com.ycl.platform.domain.entity.Notify; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.ycl.platform.domain.vo.NotifyVO; +import com.ycl.platform.domain.form.NotifyForm; +import java.util.List; +import org.apache.ibatis.annotations.Mapper; + +/** + * 閫氱煡 Mapper 鎺ュ彛 + * + * @author xp + * @since 2024-04-07 + */ +@Mapper +public interface NotifyMapper extends BaseMapper<Notify> { + +} diff --git a/ycl-server/src/main/java/com/ycl/platform/service/NotifyService.java b/ycl-server/src/main/java/com/ycl/platform/service/NotifyService.java new file mode 100644 index 0000000..f337a35 --- /dev/null +++ b/ycl-server/src/main/java/com/ycl/platform/service/NotifyService.java @@ -0,0 +1,65 @@ +package com.ycl.platform.service; + +import com.ycl.platform.domain.entity.Notify; +import com.baomidou.mybatisplus.extension.service.IService; +import com.ycl.system.Result; +import com.ycl.platform.domain.form.NotifyForm; +import com.ycl.platform.domain.query.NotifyQuery; +import java.util.List; + +/** + * 閫氱煡 鏈嶅姟绫� + * + * @author xp + * @since 2024-04-07 + */ +public interface NotifyService extends IService<Notify> { + + /** + * 娣诲姞 + * @param form + * @return + */ + Result add(NotifyForm form); + + /** + * 淇敼 + * @param form + * @return + */ + Result update(NotifyForm form); + + /** + * 鎵归噺鍒犻櫎 + * @param ids + * @return + */ + Result remove(List<String> ids); + + /** + * id鍒犻櫎 + * @param id + * @return + */ + Result removeById(String id); + + /** + * 鍒嗛〉鏌ヨ + * @param query + * @return + */ + Result page(NotifyQuery query); + + /** + * 鏍规嵁id鏌ユ壘 + * @param id + * @return + */ + Result detail(String id); + + /** + * 鍒楄〃 + * @return + */ + Result all(); +} diff --git a/ycl-server/src/main/java/com/ycl/platform/service/impl/NotifyServiceImpl.java b/ycl-server/src/main/java/com/ycl/platform/service/impl/NotifyServiceImpl.java new file mode 100644 index 0000000..b42ff8f --- /dev/null +++ b/ycl-server/src/main/java/com/ycl/platform/service/impl/NotifyServiceImpl.java @@ -0,0 +1,145 @@ +package com.ycl.platform.service.impl; + +import com.ycl.platform.domain.entity.Notify; +import com.ycl.platform.mapper.NotifyMapper; +import com.ycl.platform.service.NotifyService; +import com.ycl.system.Result; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.ycl.platform.domain.form.NotifyForm; +import com.ycl.platform.domain.vo.NotifyVO; +import com.ycl.platform.domain.query.NotifyQuery; +import java.util.List; +import org.apache.commons.lang3.StringUtils; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.ycl.system.page.PageUtil; +import org.springframework.stereotype.Service; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.beans.BeanUtils; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.Assert; +import java.util.ArrayList; +import java.util.stream.Collectors; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; +import lombok.RequiredArgsConstructor; + +/** + * 閫氱煡 鏈嶅姟瀹炵幇绫� + * + * @author xp + * @since 2024-04-07 + */ +@Service +@RequiredArgsConstructor +public class NotifyServiceImpl extends ServiceImpl<NotifyMapper, Notify> implements NotifyService { + + private final NotifyMapper notifyMapper; + + /** + * 娣诲姞 + * @param form + * @return + */ + @Override + public Result add(NotifyForm form) { + Notify entity = NotifyForm.getEntityByForm(form, null); + if(baseMapper.insert(entity) > 0) { + return Result.ok("娣诲姞鎴愬姛"); + } + return Result.error("娣诲姞澶辫触"); + } + + /** + * 淇敼 + * @param form + * @return + */ + @Override + public Result update(NotifyForm form) { + + Notify entity = baseMapper.selectById(form.getId()); + + // 涓虹┖鎶汭llegalArgumentException锛屽仛鍏ㄥ眬寮傚父澶勭悊 + Assert.notNull(entity, "璁板綍涓嶅瓨鍦�"); + BeanUtils.copyProperties(form, entity); + if (baseMapper.updateById(entity) > 0) { + return Result.ok("淇敼鎴愬姛"); + } + return Result.error("淇敼澶辫触"); + } + + /** + * 鎵归噺鍒犻櫎 + * @param ids + * @return + */ + @Override + public Result remove(List<String> ids) { + if(baseMapper.deleteBatchIds(ids) > 0) { + return Result.ok("鍒犻櫎鎴愬姛"); + } + return Result.error("鍒犻櫎澶辫触"); + } + + /** + * id鍒犻櫎 + * @param id + * @return + */ + @Override + public Result removeById(String id) { + if(baseMapper.deleteById(id) > 0) { + return Result.ok("鍒犻櫎鎴愬姛"); + } + return Result.error("鍒犻櫎澶辫触"); + } + + /** + * 鍒嗛〉鏌ヨ + * @param query + * @return + */ + @Override + public Result page(NotifyQuery query) { + + IPage<Notify> page = new LambdaQueryChainWrapper<>(baseMapper) + .orderByDesc(Notify::getCreateTime) + .page(PageUtil.getPage(query, Notify.class)); + + List<NotifyVO> vos = page.getRecords().stream() + .map( + entity -> NotifyVO.getVoByEntity(entity, null) + ) + .collect(Collectors.toList()); + return Result.ok().data(vos).total(page.getTotal()); + } + + /** + * 鏍规嵁id鏌ユ壘 + * @param id + * @return + */ + @Override + public Result detail(String id) { + + Notify entity = baseMapper.selectById(id); + Assert.notNull(entity, "璁板綍涓嶅瓨鍦�"); + NotifyVO vo = NotifyVO.getVoByEntity(entity, null); + return Result.ok().data(vo); + } + + /** + * 鍒楄〃 + * @return + */ + @Override + public Result all() { + List<Notify> entities = baseMapper.selectList(null); + List<NotifyVO> vos = entities.stream() + .map( + entity -> NotifyVO.getVoByEntity(entity, null) + ) + .collect(Collectors.toList()); + return Result.ok().data(vos); + } +} diff --git a/ycl-server/src/main/resources/mapper/zgyw/NotifyMapper.xml b/ycl-server/src/main/resources/mapper/zgyw/NotifyMapper.xml new file mode 100644 index 0000000..3d6cd46 --- /dev/null +++ b/ycl-server/src/main/resources/mapper/zgyw/NotifyMapper.xml @@ -0,0 +1,18 @@ +<?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.ycl.platform.mapper.NotifyMapper"> + + <!-- 閫氱敤鏌ヨ鏄犲皠缁撴灉 --> + <resultMap id="BaseResultMap" type="com.ycl.platform.domain.vo.NotifyVO"> + <result column="id" property="id" /> + <result column="create_time" property="createTime" /> + <result column="update_time" property="updateTime" /> + <result column="notify_type" property="notifyType" /> + <result column="content" property="content" /> + <result column="notify_who" property="notifyWho" /> + <result column="readed" property="readed" /> + <result column="urgent" property="urgent" /> + <result column="work_order_id" property="workOrderId" /> + </resultMap> + +</mapper> -- Gitblit v1.8.0