From daa0689f265aa58bdef454e773babfa6329f329d Mon Sep 17 00:00:00 2001 From: zhaoqifeng Date: Tue, 7 Apr 2020 14:28:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E7=9B=B8=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../commons/tools/constant/FieldConstant.java | 3 +- .../java/com/epmet/dto/UserMessageDTO.java | 107 ++++++++++++++++ .../controller/UserMessageController.java | 94 ++++++++++++++ .../java/com/epmet/dao/UserMessageDao.java | 39 ++++++ .../com/epmet/entity/UserMessageEntity.java | 73 +++++++++++ .../com/epmet/excel/UserMessageExcel.java | 77 ++++++++++++ .../com/epmet/redis/UserMessageRedis.java | 47 +++++++ .../com/epmet/service/UserMessageService.java | 104 ++++++++++++++++ .../service/impl/UserMessageServiceImpl.java | 116 ++++++++++++++++++ .../main/resources/mapper/UserMessageDao.xml | 27 ++++ 10 files changed, 686 insertions(+), 1 deletion(-) create mode 100644 epmet-module/epmet-message/epmet-message-client/src/main/java/com/epmet/dto/UserMessageDTO.java create mode 100644 epmet-module/epmet-message/epmet-message-server/src/main/java/com/epmet/controller/UserMessageController.java create mode 100644 epmet-module/epmet-message/epmet-message-server/src/main/java/com/epmet/dao/UserMessageDao.java create mode 100644 epmet-module/epmet-message/epmet-message-server/src/main/java/com/epmet/entity/UserMessageEntity.java create mode 100644 epmet-module/epmet-message/epmet-message-server/src/main/java/com/epmet/excel/UserMessageExcel.java create mode 100644 epmet-module/epmet-message/epmet-message-server/src/main/java/com/epmet/redis/UserMessageRedis.java create mode 100644 epmet-module/epmet-message/epmet-message-server/src/main/java/com/epmet/service/UserMessageService.java create mode 100644 epmet-module/epmet-message/epmet-message-server/src/main/java/com/epmet/service/impl/UserMessageServiceImpl.java create mode 100644 epmet-module/epmet-message/epmet-message-server/src/main/resources/mapper/UserMessageDao.xml diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/constant/FieldConstant.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/constant/FieldConstant.java index b2d467d6f4..d99374d1b0 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/constant/FieldConstant.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/constant/FieldConstant.java @@ -49,6 +49,7 @@ public interface FieldConstant { String GRID_ID = "GRID_ID"; String GRID_ID_HUMP = "gridId"; - + String USER_ID = "USER_ID"; + String USER_ID_HUMP = "userId"; } diff --git a/epmet-module/epmet-message/epmet-message-client/src/main/java/com/epmet/dto/UserMessageDTO.java b/epmet-module/epmet-message/epmet-message-client/src/main/java/com/epmet/dto/UserMessageDTO.java new file mode 100644 index 0000000000..f8b887c240 --- /dev/null +++ b/epmet-module/epmet-message/epmet-message-client/src/main/java/com/epmet/dto/UserMessageDTO.java @@ -0,0 +1,107 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.dto; + +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + + +/** + * 用户消息表 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2020-04-07 + */ +@Data +public class UserMessageDTO implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 主键 + */ + private String id; + + /** + * 客户id + */ + private String customerId; + + /** + * app=resi时,此列为gridId,其他情况暂定 * + */ + private String gridId; + + /** + * 对应用户id + */ + private String userId; + + /** + * 消息通知对象:居民端用户resi、政府端工作人员gov、运营端工作人员oper + */ + private String app; + + /** + * 消息标题 + */ + private String title; + + /** + * 消息通知内容 + */ + private String messageContent; + + /** + * read已读、unread未读 + */ + private String readFlag; + + /** + * 删除标记 0:未删除,1:已删除 + */ + private String delFlag; + + /** + * 乐观锁 + */ + private Integer revision; + + /** + * 创建人(发布消息的人) + */ + private String createdBy; + + /** + * 创建时间 + */ + private Date createdTime; + + /** + * 更新人 + */ + private String updatedBy; + + /** + * 更新时间 + */ + private Date updatedTime; + +} \ No newline at end of file diff --git a/epmet-module/epmet-message/epmet-message-server/src/main/java/com/epmet/controller/UserMessageController.java b/epmet-module/epmet-message/epmet-message-server/src/main/java/com/epmet/controller/UserMessageController.java new file mode 100644 index 0000000000..ad77e7ea2a --- /dev/null +++ b/epmet-module/epmet-message/epmet-message-server/src/main/java/com/epmet/controller/UserMessageController.java @@ -0,0 +1,94 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.controller; + +import com.epmet.commons.tools.page.PageData; +import com.epmet.commons.tools.utils.ExcelUtils; +import com.epmet.commons.tools.utils.Result; +import com.epmet.commons.tools.validator.AssertUtils; +import com.epmet.commons.tools.validator.ValidatorUtils; +import com.epmet.commons.tools.validator.group.AddGroup; +import com.epmet.commons.tools.validator.group.UpdateGroup; +import com.epmet.commons.tools.validator.group.DefaultGroup; +import com.epmet.dto.UserMessageDTO; +import com.epmet.excel.UserMessageExcel; +import com.epmet.service.UserMessageService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletResponse; +import java.util.List; +import java.util.Map; + + +/** + * 用户消息表 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2020-04-07 + */ +@RestController +@RequestMapping("usermessage") +public class UserMessageController { + + @Autowired + private UserMessageService userMessageService; + + @GetMapping("page") + public Result> page(@RequestParam Map params){ + PageData page = userMessageService.page(params); + return new Result>().ok(page); + } + + @GetMapping("{id}") + public Result get(@PathVariable("id") String id){ + UserMessageDTO data = userMessageService.get(id); + return new Result().ok(data); + } + + @PostMapping + public Result save(@RequestBody UserMessageDTO dto){ + //效验数据 + ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class); + userMessageService.save(dto); + return new Result(); + } + + @PutMapping + public Result update(@RequestBody UserMessageDTO dto){ + //效验数据 + ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class); + userMessageService.update(dto); + return new Result(); + } + + @DeleteMapping + public Result delete(@RequestBody String[] ids){ + //效验数据 + AssertUtils.isArrayEmpty(ids, "id"); + userMessageService.delete(ids); + return new Result(); + } + + @GetMapping("export") + public void export(@RequestParam Map params, HttpServletResponse response) throws Exception { + List list = userMessageService.list(params); + ExcelUtils.exportExcelToTarget(response, null, list, UserMessageExcel.class); + } + +} \ No newline at end of file diff --git a/epmet-module/epmet-message/epmet-message-server/src/main/java/com/epmet/dao/UserMessageDao.java b/epmet-module/epmet-message/epmet-message-server/src/main/java/com/epmet/dao/UserMessageDao.java new file mode 100644 index 0000000000..01c3898318 --- /dev/null +++ b/epmet-module/epmet-message/epmet-message-server/src/main/java/com/epmet/dao/UserMessageDao.java @@ -0,0 +1,39 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.dao; + +import com.epmet.commons.mybatis.dao.BaseDao; +import com.epmet.entity.UserMessageEntity; +import org.apache.ibatis.annotations.Mapper; + +/** + * 用户消息表 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2020-04-07 + */ +@Mapper +public interface UserMessageDao extends BaseDao { + /** + * 更新阅读状态为已读 + * + * @param entity 参数 + */ + void updateReadFlag(UserMessageEntity entity); + +} \ No newline at end of file diff --git a/epmet-module/epmet-message/epmet-message-server/src/main/java/com/epmet/entity/UserMessageEntity.java b/epmet-module/epmet-message/epmet-message-server/src/main/java/com/epmet/entity/UserMessageEntity.java new file mode 100644 index 0000000000..db267d9fd7 --- /dev/null +++ b/epmet-module/epmet-message/epmet-message-server/src/main/java/com/epmet/entity/UserMessageEntity.java @@ -0,0 +1,73 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.entity; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.epmet.commons.mybatis.entity.BaseEpmetEntity; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * 用户消息表 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2020-04-07 + */ +@Data +@EqualsAndHashCode(callSuper=false) +@TableName("user_message") +public class UserMessageEntity extends BaseEpmetEntity { + + private static final long serialVersionUID = 1L; + + /** + * 客户id + */ + private String customerId; + + /** + * app=resi时,此列为gridId,其他情况暂定 * + */ + private String gridId; + + /** + * 对应用户id + */ + private String userId; + + /** + * 消息通知对象:居民端用户resi、政府端工作人员gov、运营端工作人员oper + */ + private String app; + + /** + * 消息标题 + */ + private String title; + + /** + * 消息通知内容 + */ + private String messageContent; + + /** + * read已读、unread未读 + */ + private String readFlag; + +} diff --git a/epmet-module/epmet-message/epmet-message-server/src/main/java/com/epmet/excel/UserMessageExcel.java b/epmet-module/epmet-message/epmet-message-server/src/main/java/com/epmet/excel/UserMessageExcel.java new file mode 100644 index 0000000000..8dbbf8249c --- /dev/null +++ b/epmet-module/epmet-message/epmet-message-server/src/main/java/com/epmet/excel/UserMessageExcel.java @@ -0,0 +1,77 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.excel; + +import cn.afterturn.easypoi.excel.annotation.Excel; +import lombok.Data; + +import java.util.Date; + +/** + * 用户消息表 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2020-04-07 + */ +@Data +public class UserMessageExcel { + + @Excel(name = "主键") + private String id; + + @Excel(name = "客户id") + private String customerId; + + @Excel(name = "app=resi时,此列为gridId,其他情况暂定 *") + private String gridId; + + @Excel(name = "对应用户id") + private String userId; + + @Excel(name = "消息通知对象:居民端用户resi、政府端工作人员gov、运营端工作人员oper") + private String app; + + @Excel(name = "消息标题") + private String title; + + @Excel(name = "消息通知内容") + private String messageContent; + + @Excel(name = "read已读、unread未读") + private String readFlag; + + @Excel(name = "删除标记 0:未删除,1:已删除") + private String delFlag; + + @Excel(name = "乐观锁") + private Integer revision; + + @Excel(name = "创建人(发布消息的人)") + private String createdBy; + + @Excel(name = "创建时间") + private Date createdTime; + + @Excel(name = "更新人") + private String updatedBy; + + @Excel(name = "更新时间") + private Date updatedTime; + + +} \ No newline at end of file diff --git a/epmet-module/epmet-message/epmet-message-server/src/main/java/com/epmet/redis/UserMessageRedis.java b/epmet-module/epmet-message/epmet-message-server/src/main/java/com/epmet/redis/UserMessageRedis.java new file mode 100644 index 0000000000..090a4ac0f9 --- /dev/null +++ b/epmet-module/epmet-message/epmet-message-server/src/main/java/com/epmet/redis/UserMessageRedis.java @@ -0,0 +1,47 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.redis; + +import com.epmet.commons.tools.redis.RedisUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +/** + * 用户消息表 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2020-04-07 + */ +@Component +public class UserMessageRedis { + @Autowired + private RedisUtils redisUtils; + + public void delete(Object[] ids) { + + } + + public void set(){ + + } + + public String get(String id){ + return null; + } + +} \ No newline at end of file diff --git a/epmet-module/epmet-message/epmet-message-server/src/main/java/com/epmet/service/UserMessageService.java b/epmet-module/epmet-message/epmet-message-server/src/main/java/com/epmet/service/UserMessageService.java new file mode 100644 index 0000000000..6739dc7f8d --- /dev/null +++ b/epmet-module/epmet-message/epmet-message-server/src/main/java/com/epmet/service/UserMessageService.java @@ -0,0 +1,104 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.service; + +import com.epmet.commons.mybatis.service.BaseService; +import com.epmet.commons.tools.page.PageData; +import com.epmet.commons.tools.utils.Result; +import com.epmet.dto.UserMessageDTO; +import com.epmet.entity.UserMessageEntity; + +import java.util.List; +import java.util.Map; + +/** + * 用户消息表 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2020-04-07 + */ +public interface UserMessageService extends BaseService { + + /** + * 默认分页 + * + * @param params + * @return PageData + * @author generator + * @date 2020-04-07 + */ + PageData page(Map params); + + /** + * 默认查询 + * + * @param params + * @return java.util.List + * @author generator + * @date 2020-04-07 + */ + List list(Map params); + + /** + * 单条查询 + * + * @param id + * @return UserMessageDTO + * @author generator + * @date 2020-04-07 + */ + UserMessageDTO get(String id); + + /** + * 默认保存 + * + * @param dto + * @return void + * @author generator + * @date 2020-04-07 + */ + void save(UserMessageDTO dto); + + /** + * 默认更新 + * + * @param dto + * @return void + * @author generator + * @date 2020-04-07 + */ + void update(UserMessageDTO dto); + + /** + * 批量删除 + * + * @param ids + * @return void + * @author generator + * @date 2020-04-07 + */ + void delete(String[] ids); + + /** + * 全部已读 + * + * @param messageDTO 参数 + * @return Result + */ + Result allRead(UserMessageDTO messageDTO); +} \ No newline at end of file diff --git a/epmet-module/epmet-message/epmet-message-server/src/main/java/com/epmet/service/impl/UserMessageServiceImpl.java b/epmet-module/epmet-message/epmet-message-server/src/main/java/com/epmet/service/impl/UserMessageServiceImpl.java new file mode 100644 index 0000000000..2d01201a4a --- /dev/null +++ b/epmet-module/epmet-message/epmet-message-server/src/main/java/com/epmet/service/impl/UserMessageServiceImpl.java @@ -0,0 +1,116 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; +import com.epmet.commons.tools.page.PageData; +import com.epmet.commons.tools.utils.ConvertUtils; +import com.epmet.commons.tools.constant.FieldConstant; +import com.epmet.commons.tools.utils.Result; +import com.epmet.dao.UserMessageDao; +import com.epmet.dto.UserMessageDTO; +import com.epmet.entity.UserMessageEntity; +import com.epmet.redis.UserMessageRedis; +import com.epmet.service.UserMessageService; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +/** + * 用户消息表 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2020-04-07 + */ +@Service +public class UserMessageServiceImpl extends BaseServiceImpl implements UserMessageService { + + @Autowired + private UserMessageRedis userMessageRedis; + + @Override + public PageData page(Map params) { + IPage page = baseDao.selectPage( + getPage(params, FieldConstant.CREATED_TIME, false), + getWrapper(params) + ); + return getPageData(page, UserMessageDTO.class); + } + + @Override + public List list(Map params) { + List entityList = baseDao.selectList(getWrapper(params)); + + return ConvertUtils.sourceToTarget(entityList, UserMessageDTO.class); + } + + private QueryWrapper getWrapper(Map params) { + String id = (String) params.get(FieldConstant.ID_HUMP); + String communityId = (String) params.get(FieldConstant.COMMUNITY_ID_HUMP); + String gridId = (String) params.get(FieldConstant.GRID_ID_HUMP); + String userId = (String) params.get(FieldConstant.USER_ID_HUMP); + + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq(StringUtils.isNotBlank(id), FieldConstant.ID, id) + .eq(StringUtils.isNotBlank(communityId), FieldConstant.COMMUNITY_ID, communityId) + .eq(StringUtils.isNotBlank(gridId), FieldConstant.GRID_ID, gridId) + .eq(StringUtils.isNotBlank(userId), FieldConstant.USER_ID, userId); + + return wrapper; + } + + @Override + public UserMessageDTO get(String id) { + UserMessageEntity entity = baseDao.selectById(id); + return ConvertUtils.sourceToTarget(entity, UserMessageDTO.class); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void save(UserMessageDTO dto) { + UserMessageEntity entity = ConvertUtils.sourceToTarget(dto, UserMessageEntity.class); + insert(entity); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void update(UserMessageDTO dto) { + UserMessageEntity entity = ConvertUtils.sourceToTarget(dto, UserMessageEntity.class); + updateById(entity); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void delete(String[] ids) { + // 逻辑删除(@TableLogic 注解) + baseDao.deleteBatchIds(Arrays.asList(ids)); + } + + @Override + public Result allRead(UserMessageDTO messageDTO) { + return null; + } + +} \ No newline at end of file diff --git a/epmet-module/epmet-message/epmet-message-server/src/main/resources/mapper/UserMessageDao.xml b/epmet-module/epmet-message/epmet-message-server/src/main/resources/mapper/UserMessageDao.xml new file mode 100644 index 0000000000..381f748093 --- /dev/null +++ b/epmet-module/epmet-message/epmet-message-server/src/main/resources/mapper/UserMessageDao.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file