diff --git a/esua-epdc/epdc-module/epdc-news/epdc-news-client/src/main/java/com/elink/esua/epdc/dto/NewsDTO.java b/esua-epdc/epdc-module/epdc-news/epdc-news-client/src/main/java/com/elink/esua/epdc/dto/NewsDTO.java index 37825350b..77bf5bd10 100644 --- a/esua-epdc/epdc-module/epdc-news/epdc-news-client/src/main/java/com/elink/esua/epdc/dto/NewsDTO.java +++ b/esua-epdc/epdc-module/epdc-news/epdc-news-client/src/main/java/com/elink/esua/epdc/dto/NewsDTO.java @@ -73,6 +73,11 @@ public class NewsDTO implements Serializable { */ private String newsUpDownState; + /** + * 新闻是否发布 0否,1是 + */ + private String newsReleaseState; + /** * 新闻发布开始时间 */ @@ -91,7 +96,7 @@ public class NewsDTO implements Serializable { /** * 发布人部门ID */ - private String deptId; + private Long deptId; /** * 阅读量 diff --git a/esua-epdc/epdc-module/epdc-news/epdc-news-client/src/main/java/com/elink/esua/epdc/dto/NewsDepartmentDTO.java b/esua-epdc/epdc-module/epdc-news/epdc-news-client/src/main/java/com/elink/esua/epdc/dto/NewsDepartmentDTO.java new file mode 100644 index 000000000..f1bc42bdf --- /dev/null +++ b/esua-epdc/epdc-module/epdc-news/epdc-news-client/src/main/java/com/elink/esua/epdc/dto/NewsDepartmentDTO.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 qu qu@elink-cn.com + * @since v1.0.0 2019-09-06 + */ +@Data +public class NewsDepartmentDTO implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 主键 + */ + private String id; + + /** + * 新闻ID + */ + private String newsId; + + /** + * 部门ID + */ + private Long deptId; + + /** + * 乐观锁 + */ + private Integer revision; + + /** + * 创建人 + */ + private String createdBy; + + /** + * 创建时间 + */ + private Date createdTime; + + /** + * 更新人 + */ + private String updatedBy; + + /** + * 更新时间 + */ + private Date updatedTime; + + /** + * 删除标记 + */ + private String delFlag; + +} \ 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/controller/NewsController.java b/esua-epdc/epdc-module/epdc-news/epdc-news-server/src/main/java/com/elink/esua/epdc/controller/NewsController.java index 8749b8164..ede3779ef 100644 --- a/esua-epdc/epdc-module/epdc-news/epdc-news-server/src/main/java/com/elink/esua/epdc/controller/NewsController.java +++ b/esua-epdc/epdc-module/epdc-news/epdc-news-server/src/main/java/com/elink/esua/epdc/controller/NewsController.java @@ -97,5 +97,17 @@ public class NewsController { return new Result(); } + /** + * 发布新闻 + * @param dto + * @return + */ + @PostMapping() + public Result publishNews(@RequestBody NewsDTO dto){ + //效验数据 + ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class); + newsService.savePublishNews(dto); + return new Result(); + } } \ 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/controller/NewsDepartmentController.java b/esua-epdc/epdc-module/epdc-news/epdc-news-server/src/main/java/com/elink/esua/epdc/controller/NewsDepartmentController.java new file mode 100644 index 000000000..52470f0c5 --- /dev/null +++ b/esua-epdc/epdc-module/epdc-news/epdc-news-server/src/main/java/com/elink/esua/epdc/controller/NewsDepartmentController.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.NewsDepartmentDTO; +import com.elink.esua.epdc.excel.NewsDepartmentExcel; +import com.elink.esua.epdc.service.NewsDepartmentService; +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 qu qu@elink-cn.com + * @since v1.0.0 2019-09-06 + */ +@RestController +@RequestMapping("newsdepartment") +public class NewsDepartmentController { + + @Autowired + private NewsDepartmentService newsDepartmentService; + + @GetMapping("page") + public Result> page(@RequestParam Map params){ + PageData page = newsDepartmentService.page(params); + return new Result>().ok(page); + } + + @GetMapping("{id}") + public Result get(@PathVariable("id") String id){ + NewsDepartmentDTO data = newsDepartmentService.get(id); + return new Result().ok(data); + } + + @PostMapping + public Result save(@RequestBody NewsDepartmentDTO dto){ + //效验数据 + ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class); + newsDepartmentService.save(dto); + return new Result(); + } + + @PutMapping + public Result update(@RequestBody NewsDepartmentDTO dto){ + //效验数据 + ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class); + newsDepartmentService.update(dto); + return new Result(); + } + + @DeleteMapping + public Result delete(@RequestBody String[] ids){ + //效验数据 + AssertUtils.isArrayEmpty(ids, "id"); + newsDepartmentService.delete(ids); + return new Result(); + } + + @GetMapping("export") + public void export(@RequestParam Map params, HttpServletResponse response) throws Exception { + List list = newsDepartmentService.list(params); + ExcelUtils.exportExcelToTarget(response, null, list, NewsDepartmentExcel.class); + } + +} \ 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/dao/NewsDepartmentDao.java b/esua-epdc/epdc-module/epdc-news/epdc-news-server/src/main/java/com/elink/esua/epdc/dao/NewsDepartmentDao.java new file mode 100644 index 000000000..8a3dc786f --- /dev/null +++ b/esua-epdc/epdc-module/epdc-news/epdc-news-server/src/main/java/com/elink/esua/epdc/dao/NewsDepartmentDao.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.elink.esua.epdc.dao; + +import com.elink.esua.epdc.commons.mybatis.dao.BaseDao; +import com.elink.esua.epdc.entity.NewsDepartmentEntity; +import org.apache.ibatis.annotations.Mapper; + +/** + * 新闻部门关系表 + * + * @author qu qu@elink-cn.com + * @since v1.0.0 2019-09-06 + */ +@Mapper +public interface NewsDepartmentDao extends BaseDao { + + /** + * 修改的时候把该新闻的部门关联都清除 + * @param newsId + */ + void deleteByNewsId(String newsId); + +} \ 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/entity/NewsDepartmentEntity.java b/esua-epdc/epdc-module/epdc-news/epdc-news-server/src/main/java/com/elink/esua/epdc/entity/NewsDepartmentEntity.java new file mode 100644 index 000000000..5f54958b4 --- /dev/null +++ b/esua-epdc/epdc-module/epdc-news/epdc-news-server/src/main/java/com/elink/esua/epdc/entity/NewsDepartmentEntity.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 qu qu@elink-cn.com + * @since v1.0.0 2019-09-06 + */ +@Data +@EqualsAndHashCode(callSuper=false) +@TableName("epdc_news_department") +public class NewsDepartmentEntity extends BaseEpdcEntity { + + private static final long serialVersionUID = 1L; + + /** + * 新闻ID + */ + private String newsId; + + /** + * 部门ID + */ + private Long deptId; + +} \ 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/entity/NewsEntity.java b/esua-epdc/epdc-module/epdc-news/epdc-news-server/src/main/java/com/elink/esua/epdc/entity/NewsEntity.java index 9330e0416..e4b2cd051 100644 --- a/esua-epdc/epdc-module/epdc-news/epdc-news-server/src/main/java/com/elink/esua/epdc/entity/NewsEntity.java +++ b/esua-epdc/epdc-module/epdc-news/epdc-news-server/src/main/java/com/elink/esua/epdc/entity/NewsEntity.java @@ -17,6 +17,7 @@ package com.elink.esua.epdc.entity; +import cn.afterturn.easypoi.excel.annotation.Excel; import com.baomidou.mybatisplus.annotation.TableName; import com.elink.esua.epdc.commons.mybatis.entity.BaseEpdcEntity; @@ -91,7 +92,12 @@ public class NewsEntity extends BaseEpdcEntity { /** * 发布人部门ID */ - private String deptId; + private Long deptId; + + /** + * 新闻是否发布 0否,1是 + */ + private String newsReleaseState; /** * 阅读量 diff --git a/esua-epdc/epdc-module/epdc-news/epdc-news-server/src/main/java/com/elink/esua/epdc/excel/NewsDepartmentExcel.java b/esua-epdc/epdc-module/epdc-news/epdc-news-server/src/main/java/com/elink/esua/epdc/excel/NewsDepartmentExcel.java new file mode 100644 index 000000000..5f05490d1 --- /dev/null +++ b/esua-epdc/epdc-module/epdc-news/epdc-news-server/src/main/java/com/elink/esua/epdc/excel/NewsDepartmentExcel.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 qu qu@elink-cn.com + * @since v1.0.0 2019-09-06 + */ +@Data +public class NewsDepartmentExcel { + + @Excel(name = "主键") + private String id; + + @Excel(name = "新闻ID") + private String newsId; + + @Excel(name = "部门ID") + private String deptId; + + @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; + + @Excel(name = "删除标记") + private String delFlag; + + +} \ 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/excel/NewsExcel.java b/esua-epdc/epdc-module/epdc-news/epdc-news-server/src/main/java/com/elink/esua/epdc/excel/NewsExcel.java index 1f57f440c..eefc44680 100644 --- a/esua-epdc/epdc-module/epdc-news/epdc-news-server/src/main/java/com/elink/esua/epdc/excel/NewsExcel.java +++ b/esua-epdc/epdc-module/epdc-news/epdc-news-server/src/main/java/com/elink/esua/epdc/excel/NewsExcel.java @@ -55,6 +55,9 @@ public class NewsExcel { @Excel(name = "新闻上下线状态 0-下线,1-上线") private String newsUpDownState; + @Excel(name = "新闻是否发布 0否,1是") + private String newsReleaseState; + @Excel(name = "新闻发布开始时间") private Date newsReleaseStartTime; diff --git a/esua-epdc/epdc-module/epdc-news/epdc-news-server/src/main/java/com/elink/esua/epdc/redis/NewsDepartmentRedis.java b/esua-epdc/epdc-module/epdc-news/epdc-news-server/src/main/java/com/elink/esua/epdc/redis/NewsDepartmentRedis.java new file mode 100644 index 000000000..202df1c43 --- /dev/null +++ b/esua-epdc/epdc-module/epdc-news/epdc-news-server/src/main/java/com/elink/esua/epdc/redis/NewsDepartmentRedis.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 qu qu@elink-cn.com + * @since v1.0.0 2019-09-06 + */ +@Component +public class NewsDepartmentRedis { + @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/esua-epdc/epdc-module/epdc-news/epdc-news-server/src/main/java/com/elink/esua/epdc/service/NewsDepartmentService.java b/esua-epdc/epdc-module/epdc-news/epdc-news-server/src/main/java/com/elink/esua/epdc/service/NewsDepartmentService.java new file mode 100644 index 000000000..57a77e5d5 --- /dev/null +++ b/esua-epdc/epdc-module/epdc-news/epdc-news-server/src/main/java/com/elink/esua/epdc/service/NewsDepartmentService.java @@ -0,0 +1,109 @@ +/** + * 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.NewsDepartmentDTO; +import com.elink.esua.epdc.entity.NewsDepartmentEntity; + +import java.util.List; +import java.util.Map; + +/** + * 新闻部门关系表 + * + * @author qu qu@elink-cn.com + * @since v1.0.0 2019-09-06 + */ +public interface NewsDepartmentService extends BaseService { + + /** + * 默认分页 + * + * @param params + * @return PageData + * @author + * @date + */ + PageData page(Map params); + + /** + * 默认查询 + * + * @param params + * @return java.util.List + * @author + * @date + */ + List list(Map params); + + /** + * 单条查询 + * + * @param id + * @return NewsDepartmentDTO + * @author + * @date + */ + NewsDepartmentDTO get(String id); + + /** + * 默认保存 + * + * @param dto + * @return void + * @author + * @date + */ + void save(NewsDepartmentDTO dto); + + /** + * 默认更新 + * + * @param dto + * @return void + * @author + * @date + */ + void update(NewsDepartmentDTO dto); + + /** + * 批量删除 + * + * @param ids + * @return void + * @author + * @date + */ + void delete(String[] ids); + + /** + * 修改的时候把该新闻的部门关联都清除 + * @param newsId + */ + void deleteByNewsId(String newsId); + + + /** + * 保存所有网格 + * @param id + * @param newsGridList + */ + void save(String id, List newsGridList); +} \ 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/NewsService.java b/esua-epdc/epdc-module/epdc-news/epdc-news-server/src/main/java/com/elink/esua/epdc/service/NewsService.java index edff695be..0b084f5fc 100644 --- a/esua-epdc/epdc-module/epdc-news/epdc-news-server/src/main/java/com/elink/esua/epdc/service/NewsService.java +++ b/esua-epdc/epdc-module/epdc-news/epdc-news-server/src/main/java/com/elink/esua/epdc/service/NewsService.java @@ -105,6 +105,6 @@ public interface NewsService extends BaseService { */ void modifyOnLine(Map parmas); - + void savePublishNews(NewsDTO newsDTO); } \ 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/NewsDepartmentServiceImpl.java b/esua-epdc/epdc-module/epdc-news/epdc-news-server/src/main/java/com/elink/esua/epdc/service/impl/NewsDepartmentServiceImpl.java new file mode 100644 index 000000000..d681426b7 --- /dev/null +++ b/esua-epdc/epdc-module/epdc-news/epdc-news-server/src/main/java/com/elink/esua/epdc/service/impl/NewsDepartmentServiceImpl.java @@ -0,0 +1,131 @@ +/** + * 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 cn.hutool.core.collection.CollUtil; +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.constant.NumConstant; +import com.elink.esua.epdc.commons.tools.exception.RenException; +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.NewsDepartmentDao; +import com.elink.esua.epdc.dto.NewsDepartmentDTO; +import com.elink.esua.epdc.entity.NewsDepartmentEntity; +import com.elink.esua.epdc.entity.NoticeDepartmentEntity; +import com.elink.esua.epdc.redis.NewsDepartmentRedis; +import com.elink.esua.epdc.service.NewsDepartmentService; +import com.google.common.collect.Lists; +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.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +/** + * 新闻部门关系表 + * + * @author qu qu@elink-cn.com + * @since v1.0.0 2019-09-06 + */ +@Service +public class NewsDepartmentServiceImpl extends BaseServiceImpl implements NewsDepartmentService { + + @Autowired + private NewsDepartmentRedis newsDepartmentRedis; + + @Override + public PageData page(Map params) { + IPage page = baseDao.selectPage( + getPage(params, FieldConstant.CREATED_TIME, false), + getWrapper(params) + ); + return getPageData(page, NewsDepartmentDTO.class); + } + + @Override + public List list(Map params) { + List entityList = baseDao.selectList(getWrapper(params)); + + return ConvertUtils.sourceToTarget(entityList, NewsDepartmentDTO.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 NewsDepartmentDTO get(String id) { + NewsDepartmentEntity entity = baseDao.selectById(id); + return ConvertUtils.sourceToTarget(entity, NewsDepartmentDTO.class); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void save(NewsDepartmentDTO dto) { + NewsDepartmentEntity entity = ConvertUtils.sourceToTarget(dto, NewsDepartmentEntity.class); + insert(entity); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void update(NewsDepartmentDTO dto) { + NewsDepartmentEntity entity = ConvertUtils.sourceToTarget(dto, NewsDepartmentEntity.class); + updateById(entity); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void delete(String[] ids) { + // 逻辑删除(@TableLogic 注解) + baseDao.deleteBatchIds(Arrays.asList(ids)); + } + + @Override + public void deleteByNewsId(String newsId) { + baseDao.deleteByNewsId(newsId); + } + + @Override + public void save(String id, List newsGridList) { + if (StringUtils.isBlank(id) || CollUtil.isEmpty(newsGridList)) { + throw new RenException("保存通知网格信息失败"); + } + List list = new ArrayList<>(); + NewsDepartmentEntity entity; + for (Long gridId : newsGridList) { + entity = new NewsDepartmentEntity(); + entity.setNewsId(id); + entity.setDeptId(gridId); + list.add(entity); + } + this.insertBatch(list, NumConstant.TWENTY); + } + +} \ 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/NewsServiceImpl.java b/esua-epdc/epdc-module/epdc-news/epdc-news-server/src/main/java/com/elink/esua/epdc/service/impl/NewsServiceImpl.java index 878c0ce96..227bb2fda 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 @@ -17,17 +17,25 @@ package com.elink.esua.epdc.service.impl; +import cn.hutool.core.collection.CollUtil; 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.exception.RenException; import com.elink.esua.epdc.commons.tools.page.PageData; +import com.elink.esua.epdc.commons.tools.security.user.SecurityUser; +import com.elink.esua.epdc.commons.tools.security.user.UserDetail; 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.NewsDTO; import com.elink.esua.epdc.entity.NewsEntity; +import com.elink.esua.epdc.feign.AdminFeignClient; import com.elink.esua.epdc.redis.NewsRedis; +import com.elink.esua.epdc.service.NewsDepartmentService; import com.elink.esua.epdc.service.NewsService; +import com.google.common.collect.Lists; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -43,12 +51,20 @@ import java.util.Map; * @author qu qu@elink-cn.com * @since v1.0.0 2019-09-05 */ + + @Service public class NewsServiceImpl extends BaseServiceImpl implements NewsService { @Autowired private NewsRedis newsRedis; + @Autowired + private NewsDepartmentService newsDepartmentService; + + @Autowired + private AdminFeignClient adminFeignClient; + @Override public PageData page(Map params) { IPage page = baseDao.selectPage( @@ -85,6 +101,15 @@ public class NewsServiceImpl extends BaseServiceImpl implem return wrapper; } + /** + * @Description + * @Author qushutong + * @Date 2019/9/6 14:14 + * @Param + * @Return + * @Exception + * + */ @Override public NewsDTO get(String id) { NewsEntity entity = baseDao.selectById(id); @@ -128,4 +153,53 @@ public class NewsServiceImpl extends BaseServiceImpl implem updateById(entity); } + + @Override + public void savePublishNews(NewsDTO newsDTO) { + NewsEntity entity = ConvertUtils.sourceToTarget(newsDTO, NewsEntity.class); + entity.setNewsUpDownState("1"); + UserDetail user = SecurityUser.getUser(); + entity.setCreatorName(user.getRealName()); + entity.setDeptId(user.getDeptId()); + entity.setDeptName(user.getDeptName()); + entity.setNewsUpDownState("1"); + + // 通知所属部门id + Long newsDeptId = entity.getStreetId(); + // 能接收通知的所有网格的ID + List newsGridList = Lists.newArrayList(); + if (null != entity.getCommunityId()) { + newsDeptId = entity.getCommunityId(); + } + if (null != entity.getGridId()) { + newsDeptId = entity.getGridId(); + newsGridList.add(newsDeptId); + } + + if (!user.getDeptIdList().contains(newsDeptId)) { + throw new RenException("您没有操作此部门的数据权限"); + } + boolean isSave = true; + if (StringUtils.isNotBlank(newsDTO.getId())) { + isSave = false; + } + + if (isSave) { + insert(entity); + } else { + updateById(entity); + newsDepartmentService.deleteByNewsId(entity.getId()); + } + + if (CollUtil.isEmpty(newsGridList)) { + Result> adminResult = adminFeignClient.listGridIdByDeptPid(newsDeptId); + if (!adminResult.success() || CollUtil.isEmpty(adminResult.getData())) { + throw new RenException("获取部门信息失败"); + } + newsGridList = adminResult.getData(); + }else { + } + this.newsDepartmentService.save(entity.getId(), newsGridList); + } + } \ No newline at end of file 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 bddbd02b6..296a56cfe 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 @@ -32,6 +32,7 @@ + + DELETE FROM epdc_news_department WHERE NEWS_ID = #{newsId} + + + + \ No newline at end of file