diff --git a/esua-epdc/epdc-module/epdc-api/epdc-api-server/src/main/java/com/elink/esua/epdc/service/impl/NewsServiceImpl.java b/esua-epdc/epdc-module/epdc-api/epdc-api-server/src/main/java/com/elink/esua/epdc/service/impl/NewsServiceImpl.java index 47347ee1..4b02746b 100644 --- a/esua-epdc/epdc-module/epdc-api/epdc-api-server/src/main/java/com/elink/esua/epdc/service/impl/NewsServiceImpl.java +++ b/esua-epdc/epdc-module/epdc-api/epdc-api-server/src/main/java/com/elink/esua/epdc/service/impl/NewsServiceImpl.java @@ -53,6 +53,8 @@ public class NewsServiceImpl implements NewsService { return new Result().ok(new ArrayList()); } formDto.setDeptId(userDetail.getGridId()); + // 判断新闻 用户是否已读 + formDto.setUserId(userDetail.getUserId()); return newsFeignClient.listNews(formDto); } diff --git a/esua-epdc/epdc-module/epdc-news/epdc-news-client/src/main/java/com/elink/esua/epdc/dto/NewsUserReadDTO.java b/esua-epdc/epdc-module/epdc-news/epdc-news-client/src/main/java/com/elink/esua/epdc/dto/NewsUserReadDTO.java new file mode 100644 index 00000000..9edc6780 --- /dev/null +++ b/esua-epdc/epdc-module/epdc-news/epdc-news-client/src/main/java/com/elink/esua/epdc/dto/NewsUserReadDTO.java @@ -0,0 +1,81 @@ +/** + * 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.elink.esua.epdc.dto; + +import java.io.Serializable; +import java.util.Date; +import lombok.Data; + + +/** + * 用户已读新闻表 + * + * @author zhangyong + * @since v1.0.0 2020-05-15 + */ +@Data +public class NewsUserReadDTO implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * ID + */ + private String id; + + /** + * 用户ID + */ + private String userId; + + /** + * 新闻ID + */ + private String newsId; + + /** + * 删除标识 0-否,1-是 + */ + private String delFlag; + + /** + * 乐观锁 + */ + private Integer revision; + + /** + * 创建人 + */ + private String createdBy; + + /** + * 创建时间 + */ + private Date createdTime; + + /** + * 更新人 + */ + private String updatedBy; + + /** + * 更新时间 + */ + private Date updatedTime; + +} diff --git a/esua-epdc/epdc-module/epdc-news/epdc-news-client/src/main/java/com/elink/esua/epdc/dto/epdc/form/EpdcNewsListFromDTO.java b/esua-epdc/epdc-module/epdc-news/epdc-news-client/src/main/java/com/elink/esua/epdc/dto/epdc/form/EpdcNewsListFromDTO.java index 9d33656d..37f0b63e 100644 --- a/esua-epdc/epdc-module/epdc-news/epdc-news-client/src/main/java/com/elink/esua/epdc/dto/epdc/form/EpdcNewsListFromDTO.java +++ b/esua-epdc/epdc-module/epdc-news/epdc-news-client/src/main/java/com/elink/esua/epdc/dto/epdc/form/EpdcNewsListFromDTO.java @@ -35,4 +35,8 @@ public class EpdcNewsListFromDTO implements Serializable { @NotBlank(message = "时间戳不能为空") private String timestamp; + /** + * 用户ID + */ + private String userId; } diff --git a/esua-epdc/epdc-module/epdc-news/epdc-news-client/src/main/java/com/elink/esua/epdc/dto/epdc/result/EpdcNewsListResultDTO.java b/esua-epdc/epdc-module/epdc-news/epdc-news-client/src/main/java/com/elink/esua/epdc/dto/epdc/result/EpdcNewsListResultDTO.java index 86c06581..9d3d503a 100644 --- a/esua-epdc/epdc-module/epdc-news/epdc-news-client/src/main/java/com/elink/esua/epdc/dto/epdc/result/EpdcNewsListResultDTO.java +++ b/esua-epdc/epdc-module/epdc-news/epdc-news-client/src/main/java/com/elink/esua/epdc/dto/epdc/result/EpdcNewsListResultDTO.java @@ -21,4 +21,9 @@ public class EpdcNewsListResultDTO implements Serializable { private String deptName; private String newsCategoryName; private String newsImageUrl; + + /** + * 是否已读(0-否,1-是) + */ + private String readFlag; } diff --git a/esua-epdc/epdc-module/epdc-news/epdc-news-server/src/main/java/com/elink/esua/epdc/controller/NewsUserReadController.java b/esua-epdc/epdc-module/epdc-news/epdc-news-server/src/main/java/com/elink/esua/epdc/controller/NewsUserReadController.java new file mode 100644 index 00000000..9d0a1df5 --- /dev/null +++ b/esua-epdc/epdc-module/epdc-news/epdc-news-server/src/main/java/com/elink/esua/epdc/controller/NewsUserReadController.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.elink.esua.epdc.controller; + +import com.elink.esua.epdc.commons.tools.page.PageData; +import com.elink.esua.epdc.commons.tools.utils.ExcelUtils; +import com.elink.esua.epdc.commons.tools.utils.Result; +import com.elink.esua.epdc.commons.tools.validator.AssertUtils; +import com.elink.esua.epdc.commons.tools.validator.ValidatorUtils; +import com.elink.esua.epdc.commons.tools.validator.group.AddGroup; +import com.elink.esua.epdc.commons.tools.validator.group.UpdateGroup; +import com.elink.esua.epdc.commons.tools.validator.group.DefaultGroup; +import com.elink.esua.epdc.dto.NewsUserReadDTO; +import com.elink.esua.epdc.excel.NewsUserReadExcel; +import com.elink.esua.epdc.service.NewsUserReadService; +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 zhangyong + * @since v1.0.0 2020-05-15 + */ +@RestController +@RequestMapping("newsuserread") +public class NewsUserReadController { + + @Autowired + private NewsUserReadService newsUserReadService; + + @GetMapping("page") + public Result> page(@RequestParam Map params){ + PageData page = newsUserReadService.page(params); + return new Result>().ok(page); + } + + @GetMapping("{id}") + public Result get(@PathVariable("id") String id){ + NewsUserReadDTO data = newsUserReadService.get(id); + return new Result().ok(data); + } + + @PostMapping + public Result save(@RequestBody NewsUserReadDTO dto){ + //效验数据 + ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class); + newsUserReadService.save(dto); + return new Result(); + } + + @PutMapping + public Result update(@RequestBody NewsUserReadDTO dto){ + //效验数据 + ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class); + newsUserReadService.update(dto); + return new Result(); + } + + @DeleteMapping + public Result delete(@RequestBody String[] ids){ + //效验数据 + AssertUtils.isArrayEmpty(ids, "id"); + newsUserReadService.delete(ids); + return new Result(); + } + + @GetMapping("export") + public void export(@RequestParam Map params, HttpServletResponse response) throws Exception { + List list = newsUserReadService.list(params); + ExcelUtils.exportExcelToTarget(response, null, list, NewsUserReadExcel.class); + } + +} diff --git a/esua-epdc/epdc-module/epdc-news/epdc-news-server/src/main/java/com/elink/esua/epdc/dao/NewsUserReadDao.java b/esua-epdc/epdc-module/epdc-news/epdc-news-server/src/main/java/com/elink/esua/epdc/dao/NewsUserReadDao.java new file mode 100644 index 00000000..b681c6bf --- /dev/null +++ b/esua-epdc/epdc-module/epdc-news/epdc-news-server/src/main/java/com/elink/esua/epdc/dao/NewsUserReadDao.java @@ -0,0 +1,42 @@ +/** + * 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.elink.esua.epdc.dao; + +import com.elink.esua.epdc.commons.mybatis.dao.BaseDao; +import com.elink.esua.epdc.dto.epdc.form.EpdcNewsDetailFormDTO; +import com.elink.esua.epdc.entity.NewsUserReadEntity; +import org.apache.ibatis.annotations.Mapper; + +/** + * 用户已读新闻表 + * + * @author zhangyong + * @since v1.0.0 2020-05-15 + */ +@Mapper +public interface NewsUserReadDao extends BaseDao { + + /** + * 判断当前新闻,用户是否已读 + * @param formDto + * @return int + * @Author zhangyong + * @Date 10:40 2020-05-15 + **/ + int selectCountNewsIsRead(EpdcNewsDetailFormDTO formDto); +} diff --git a/esua-epdc/epdc-module/epdc-news/epdc-news-server/src/main/java/com/elink/esua/epdc/entity/NewsUserReadEntity.java b/esua-epdc/epdc-module/epdc-news/epdc-news-server/src/main/java/com/elink/esua/epdc/entity/NewsUserReadEntity.java new file mode 100644 index 00000000..99093023 --- /dev/null +++ b/esua-epdc/epdc-module/epdc-news/epdc-news-server/src/main/java/com/elink/esua/epdc/entity/NewsUserReadEntity.java @@ -0,0 +1,51 @@ +/** + * 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.elink.esua.epdc.entity; + +import com.baomidou.mybatisplus.annotation.TableName; + +import com.elink.esua.epdc.commons.mybatis.entity.BaseEpdcEntity; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.util.Date; + +/** + * 用户已读新闻表 + * + * @author zhangyong + * @since v1.0.0 2020-05-15 + */ +@Data +@EqualsAndHashCode(callSuper=false) +@TableName("epdc_news_user_read") +public class NewsUserReadEntity extends BaseEpdcEntity { + + private static final long serialVersionUID = 1L; + + /** + * 用户ID + */ + private String userId; + + /** + * 新闻ID + */ + private String newsId; + +} diff --git a/esua-epdc/epdc-module/epdc-news/epdc-news-server/src/main/java/com/elink/esua/epdc/excel/NewsUserReadExcel.java b/esua-epdc/epdc-module/epdc-news/epdc-news-server/src/main/java/com/elink/esua/epdc/excel/NewsUserReadExcel.java new file mode 100644 index 00000000..d4c3fc42 --- /dev/null +++ b/esua-epdc/epdc-module/epdc-news/epdc-news-server/src/main/java/com/elink/esua/epdc/excel/NewsUserReadExcel.java @@ -0,0 +1,62 @@ +/** + * 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.elink.esua.epdc.excel; + +import cn.afterturn.easypoi.excel.annotation.Excel; +import lombok.Data; + +import java.util.Date; + +/** + * 用户已读新闻表 + * + * @author zhangyong + * @since v1.0.0 2020-05-15 + */ +@Data +public class NewsUserReadExcel { + + @Excel(name = "ID") + private String id; + + @Excel(name = "用户ID") + private String userId; + + @Excel(name = "新闻ID") + private String newsId; + + @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; + + +} diff --git a/esua-epdc/epdc-module/epdc-news/epdc-news-server/src/main/java/com/elink/esua/epdc/redis/NewsUserReadRedis.java b/esua-epdc/epdc-module/epdc-news/epdc-news-server/src/main/java/com/elink/esua/epdc/redis/NewsUserReadRedis.java new file mode 100644 index 00000000..79f3cfc7 --- /dev/null +++ b/esua-epdc/epdc-module/epdc-news/epdc-news-server/src/main/java/com/elink/esua/epdc/redis/NewsUserReadRedis.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.elink.esua.epdc.redis; + +import com.elink.esua.epdc.commons.tools.redis.RedisUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +/** + * 用户已读新闻表 + * + * @author zhangyong + * @since v1.0.0 2020-05-15 + */ +@Component +public class NewsUserReadRedis { + @Autowired + private RedisUtils redisUtils; + + public void delete(Object[] ids) { + + } + + public void set(){ + + } + + public String get(String id){ + return null; + } + +} diff --git a/esua-epdc/epdc-module/epdc-news/epdc-news-server/src/main/java/com/elink/esua/epdc/service/NewsUserReadService.java b/esua-epdc/epdc-module/epdc-news/epdc-news-server/src/main/java/com/elink/esua/epdc/service/NewsUserReadService.java new file mode 100644 index 00000000..59a48e1e --- /dev/null +++ b/esua-epdc/epdc-module/epdc-news/epdc-news-server/src/main/java/com/elink/esua/epdc/service/NewsUserReadService.java @@ -0,0 +1,105 @@ +/** + * 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.elink.esua.epdc.service; + +import com.elink.esua.epdc.commons.mybatis.service.BaseService; +import com.elink.esua.epdc.commons.tools.page.PageData; +import com.elink.esua.epdc.dto.NewsUserReadDTO; +import com.elink.esua.epdc.dto.epdc.form.EpdcNewsDetailFormDTO; +import com.elink.esua.epdc.entity.NewsUserReadEntity; + +import java.util.List; +import java.util.Map; + +/** + * 用户已读新闻表 + * + * @author zhangyong + * @since v1.0.0 2020-05-15 + */ +public interface NewsUserReadService extends BaseService { + + /** + * 默认分页 + * + * @param params + * @return PageData + * @author generator + * @date 2020-05-15 + */ + PageData page(Map params); + + /** + * 默认查询 + * + * @param params + * @return java.util.List + * @author generator + * @date 2020-05-15 + */ + List list(Map params); + + /** + * 单条查询 + * + * @param id + * @return NewsUserReadDTO + * @author generator + * @date 2020-05-15 + */ + NewsUserReadDTO get(String id); + + /** + * 默认保存 + * + * @param dto + * @return void + * @author generator + * @date 2020-05-15 + */ + void save(NewsUserReadDTO dto); + + /** + * 默认更新 + * + * @param dto + * @return void + * @author generator + * @date 2020-05-15 + */ + void update(NewsUserReadDTO dto); + + /** + * 批量删除 + * + * @param ids + * @return void + * @author generator + * @date 2020-05-15 + */ + void delete(String[] ids); + + /** + * 判断当前新闻,用户是否已读 + * @param formDto + * @return int + * @Author zhangyong + * @Date 10:40 2020-05-15 + **/ + int countNewsIsRead(EpdcNewsDetailFormDTO formDto); +} diff --git a/esua-epdc/epdc-module/epdc-news/epdc-news-server/src/main/java/com/elink/esua/epdc/service/impl/NewsServiceImpl.java b/esua-epdc/epdc-module/epdc-news/epdc-news-server/src/main/java/com/elink/esua/epdc/service/impl/NewsServiceImpl.java index ac65c9f8..57dab940 100644 --- a/esua-epdc/epdc-module/epdc-news/epdc-news-server/src/main/java/com/elink/esua/epdc/service/impl/NewsServiceImpl.java +++ b/esua-epdc/epdc-module/epdc-news/epdc-news-server/src/main/java/com/elink/esua/epdc/service/impl/NewsServiceImpl.java @@ -31,14 +31,12 @@ import com.elink.esua.epdc.commons.tools.utils.ConvertUtils; import com.elink.esua.epdc.commons.tools.constant.FieldConstant; import com.elink.esua.epdc.commons.tools.utils.Result; import com.elink.esua.epdc.dao.NewsDao; -import com.elink.esua.epdc.dto.BannerDTO; -import com.elink.esua.epdc.dto.NewsDTO; -import com.elink.esua.epdc.dto.NewsUserAttitudeDTO; -import com.elink.esua.epdc.dto.ParentAndAllDeptDTO; +import com.elink.esua.epdc.dto.*; import com.elink.esua.epdc.dto.epdc.form.EpdcNewsDetailFormDTO; import com.elink.esua.epdc.dto.epdc.result.EpdcNewsListResultDTO; import com.elink.esua.epdc.entity.BannerEntity; import com.elink.esua.epdc.entity.NewsUserAttitudeEntity; +import com.elink.esua.epdc.entity.NewsUserReadEntity; import com.elink.esua.epdc.enums.AppNewsLikeEnum; import com.elink.esua.epdc.dto.epdc.form.EpdcNewsBrowseFromDTO; import com.elink.esua.epdc.dto.epdc.form.EpdcNewsListFromDTO; @@ -80,6 +78,9 @@ public class NewsServiceImpl extends BaseServiceImpl implem @Autowired private BannerService bannerService; + @Autowired + private NewsUserReadService newsUserReadService; + @Override public PageData page(Map params) { IPage page = baseDao.selectPage( @@ -316,9 +317,31 @@ public class NewsServiceImpl extends BaseServiceImpl implem EpdcNewsDetailResultDTO epdcNewsDetailResultDTO = baseDao.selectOneAppNewsDetail(formDto); String oldContent = epdcNewsDetailResultDTO.getNewsContent(); epdcNewsDetailResultDTO.setNewsContent("

" + oldContent + "
"); + + // 查看新闻详情时,判断是否要插入新闻已读表 + this.isInsertNewsRead(formDto); return new Result().ok(epdcNewsDetailResultDTO); } + /** + * 查看新闻详情时,判断是否要插入新闻已读表 + * @param formDto + * @return void + * @Author zhangyong + * @Date 10:47 2020-05-15 + **/ + private void isInsertNewsRead(EpdcNewsDetailFormDTO formDto){ + // 查看新闻详情时,判断是否是第一次查看本条新闻 + int readCount = newsUserReadService.countNewsIsRead(formDto); + // 是插入新闻已读表 + if (readCount == 0){ + NewsUserReadDTO dto = new NewsUserReadDTO(); + dto.setNewsId(formDto.getNewsId()); + dto.setUserId(formDto.getUserId()); + newsUserReadService.save(dto); + } + // 否无操作 + } @Override @Transactional(rollbackFor = Exception.class) public Result modifyStatement(EpdcNewsStatementFromDTO statementFromDto) { @@ -540,4 +563,4 @@ public class NewsServiceImpl extends BaseServiceImpl implem return entities; } -} \ No newline at end of file +} diff --git a/esua-epdc/epdc-module/epdc-news/epdc-news-server/src/main/java/com/elink/esua/epdc/service/impl/NewsUserReadServiceImpl.java b/esua-epdc/epdc-module/epdc-news/epdc-news-server/src/main/java/com/elink/esua/epdc/service/impl/NewsUserReadServiceImpl.java new file mode 100644 index 00000000..26b619e0 --- /dev/null +++ b/esua-epdc/epdc-module/epdc-news/epdc-news-server/src/main/java/com/elink/esua/epdc/service/impl/NewsUserReadServiceImpl.java @@ -0,0 +1,110 @@ +/** + * 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.elink.esua.epdc.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.elink.esua.epdc.commons.mybatis.service.impl.BaseServiceImpl; +import com.elink.esua.epdc.commons.tools.page.PageData; +import com.elink.esua.epdc.commons.tools.utils.ConvertUtils; +import com.elink.esua.epdc.commons.tools.constant.FieldConstant; +import com.elink.esua.epdc.dao.NewsUserReadDao; +import com.elink.esua.epdc.dto.NewsUserReadDTO; +import com.elink.esua.epdc.dto.epdc.form.EpdcNewsDetailFormDTO; +import com.elink.esua.epdc.entity.NewsUserReadEntity; +import com.elink.esua.epdc.redis.NewsUserReadRedis; +import com.elink.esua.epdc.service.NewsUserReadService; +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 zhangyong + * @since v1.0.0 2020-05-15 + */ +@Service +public class NewsUserReadServiceImpl extends BaseServiceImpl implements NewsUserReadService { + + @Autowired + private NewsUserReadRedis newsUserReadRedis; + + @Override + public PageData page(Map params) { + IPage page = baseDao.selectPage( + getPage(params, FieldConstant.CREATED_TIME, false), + getWrapper(params) + ); + return getPageData(page, NewsUserReadDTO.class); + } + + @Override + public List list(Map params) { + List entityList = baseDao.selectList(getWrapper(params)); + + return ConvertUtils.sourceToTarget(entityList, NewsUserReadDTO.class); + } + + private QueryWrapper getWrapper(Map params){ + String id = (String)params.get(FieldConstant.ID_HUMP); + + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq(StringUtils.isNotBlank(id), FieldConstant.ID, id); + + return wrapper; + } + + @Override + public NewsUserReadDTO get(String id) { + NewsUserReadEntity entity = baseDao.selectById(id); + return ConvertUtils.sourceToTarget(entity, NewsUserReadDTO.class); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void save(NewsUserReadDTO dto) { + NewsUserReadEntity entity = ConvertUtils.sourceToTarget(dto, NewsUserReadEntity.class); + insert(entity); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void update(NewsUserReadDTO dto) { + NewsUserReadEntity entity = ConvertUtils.sourceToTarget(dto, NewsUserReadEntity.class); + updateById(entity); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void delete(String[] ids) { + // 逻辑删除(@TableLogic 注解) + baseDao.deleteBatchIds(Arrays.asList(ids)); + } + + @Override + public int countNewsIsRead(EpdcNewsDetailFormDTO formDto) { + return baseDao.selectCountNewsIsRead(formDto); + } + +} diff --git a/esua-epdc/epdc-module/epdc-news/epdc-news-server/src/main/resources/mapper/NewsDao.xml b/esua-epdc/epdc-module/epdc-news/epdc-news-server/src/main/resources/mapper/NewsDao.xml index 67f27f5e..36912547 100644 --- a/esua-epdc/epdc-module/epdc-news/epdc-news-server/src/main/resources/mapper/NewsDao.xml +++ b/esua-epdc/epdc-module/epdc-news/epdc-news-server/src/main/resources/mapper/NewsDao.xml @@ -19,11 +19,18 @@ en.NEWS_RELEASE_START_TIME AS newsStartTime, SUBSTRING_INDEX(en.ALL_DEPT_NAMES,'-',-1) AS deptName, nc.CATEGORY_NAME AS newsCategoryName, - en.NEWS_IMAGE_URL AS newsImageUrl + en.NEWS_IMAGE_URL AS newsImageUrl, + CASE + WHEN r.ID is NULL THEN + 0 + ELSE + 1 + END readFlag FROM epdc_news en LEFT JOIN epdc_news_category nc ON en.NEWS_CATERORY_ID = nc.ID RIGHT JOIN epdc_news_department ed ON en.ID = ed.NEWS_ID + LEFT JOIN epdc_news_user_read r ON en.ID = r.NEWS_ID AND r.USER_ID = #{userId} WHERE ed.DEPT_ID = #{deptId} AND en.NEWS_RELEASE_START_TIME <= STR_TO_DATE( #{timestamp}, '%Y-%m-%d %H:%i:%s' ) @@ -149,4 +156,4 @@ UPDATE epdc_news SET DEPT_NAME = #{newDeptName}, UPDATED_TIME = NOW() WHERE DEPT_ID = #{deptId} - \ No newline at end of file + diff --git a/esua-epdc/epdc-module/epdc-news/epdc-news-server/src/main/resources/mapper/NewsUserReadDao.xml b/esua-epdc/epdc-module/epdc-news/epdc-news-server/src/main/resources/mapper/NewsUserReadDao.xml new file mode 100644 index 00000000..7a22ae21 --- /dev/null +++ b/esua-epdc/epdc-module/epdc-news/epdc-news-server/src/main/resources/mapper/NewsUserReadDao.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + +