diff --git a/esua-epdc/epdc-commons/epdc-commons-tools/src/main/java/com/elink/esua/epdc/commons/tools/utils/IdentityNoUtils.java b/esua-epdc/epdc-commons/epdc-commons-tools/src/main/java/com/elink/esua/epdc/commons/tools/utils/IdentityNoUtils.java index 7305e818d..c03eb060d 100644 --- a/esua-epdc/epdc-commons/epdc-commons-tools/src/main/java/com/elink/esua/epdc/commons/tools/utils/IdentityNoUtils.java +++ b/esua-epdc/epdc-commons/epdc-commons-tools/src/main/java/com/elink/esua/epdc/commons/tools/utils/IdentityNoUtils.java @@ -211,9 +211,10 @@ public class IdentityNoUtils implements Serializable { } //判断出生年月 int year = Integer.parseInt(iDCardNo.substring(6, 10)); - int month = Integer.parseInt(iDCardNo.substring(10, 12)); - int day = Integer.parseInt(iDCardNo.substring(12, 14)); - String birthDay = year + "-" + month + "-" + day; + String strMonth = iDCardNo.substring(10, 12); + String strDay = iDCardNo.substring(12, 14); + + String birthDay = year + "-" + strMonth + "-" + strDay; if (isStrDate(birthDay) == false) { return "身份证生日无效"; } @@ -221,9 +222,11 @@ public class IdentityNoUtils implements Serializable { if ((now.getYear() - year) > 150 || now.isBefore(LocalDate.parse(birthDay))) { return "身份证生日不在有效范围"; } + int month = Integer.parseInt(strMonth); if (month > 12 || month == 0) { return "身份证月份无效"; } + int day = Integer.parseInt(strDay); if (day > 31 || day == 0) { return "身份证日期无效"; } diff --git a/esua-epdc/epdc-module/epdc-api/epdc-api-server/src/main/java/com/elink/esua/epdc/service/impl/AppUserServiceImpl.java b/esua-epdc/epdc-module/epdc-api/epdc-api-server/src/main/java/com/elink/esua/epdc/service/impl/AppUserServiceImpl.java index 5213158b5..e4aedd756 100644 --- a/esua-epdc/epdc-module/epdc-api/epdc-api-server/src/main/java/com/elink/esua/epdc/service/impl/AppUserServiceImpl.java +++ b/esua-epdc/epdc-module/epdc-api/epdc-api-server/src/main/java/com/elink/esua/epdc/service/impl/AppUserServiceImpl.java @@ -357,7 +357,9 @@ public class AppUserServiceImpl implements AppUserService { } catch (WxErrorException e) { log.error("->[getMaOpenId]::error[{}]", "解析微信code失败"); } - if (null == wxMaJscode2SessionResult || StringUtils.isBlank(wxMaJscode2SessionResult.getUnionid())) { + if (null == wxMaJscode2SessionResult) { + throw new RenException("解析微信用户信息失败"); + } else if (StringUtils.isBlank(wxMaJscode2SessionResult.getUnionid())) { throw new RenException("解析微信用户信息失败"); } return wxMaJscode2SessionResult; 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 37f6f6ca1..c2c22df99 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 @@ -66,7 +66,7 @@ public class NewsDTO implements Serializable { private String newsImageUrl; /** - * 新闻上下线状态 0-下线,1-上线 + * 新闻上下线状态 默认是0 手动下线是1 */ private String newsUpDownState; 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 ebc8a3139..b8e8ff732 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 @@ -46,40 +46,24 @@ import java.util.Map; @RestController @RequestMapping("news") public class NewsController { - + @Autowired private NewsService newsService; @GetMapping("page") - public Result> page(@RequestParam Map params){ + public Result> page(@RequestParam Map params) { PageData page = newsService.page(params); return new Result>().ok(page); } @GetMapping("{id}") - public Result get(@PathVariable("id") String id){ + public Result get(@PathVariable("id") String id) { NewsDTO data = newsService.get(id); return new Result().ok(data); } - /*** - * @Description 存草稿 - * @Author qushutong - * @Date 2019/9/6 16:23 - * @Param [dto] - * @Return com.elink.esua.epdc.commons.tools.utils.Result - * @Exception - * - */ - @PostMapping - public Result save(@RequestBody NewsDTO dto){ - //效验数据 - ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class); - newsService.save(dto); - return new Result(); - } @PutMapping - public Result update(@RequestBody NewsDTO dto){ + public Result update(@RequestBody NewsDTO dto) { //效验数据 ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class); newsService.update(dto); @@ -87,7 +71,7 @@ public class NewsController { } @DeleteMapping - public Result delete(@RequestBody String[] ids){ + public Result delete(@RequestBody String[] ids) { //效验数据 AssertUtils.isArrayEmpty(ids, "id"); newsService.delete(ids); @@ -101,37 +85,56 @@ public class NewsController { } @PostMapping("modifyOnLine") - public Result modifyOnLine(@RequestBody Map parmas){ + public Result modifyOnLine(@RequestBody Map parmas) { boolean b = newsService.modifyOnLine(parmas); - if(b){ + if (b) { return new Result(); } return new Result().error("下线失败 请刷新界面"); } /** - * 发布新闻 + * 新增新闻到草稿(存草稿) + * + * @param dto + * @return com.elink.esua.epdc.commons.tools.utils.Result + * @author qushutong + * @date 2019/9/6 16:23 + */ + @PostMapping + public Result saveToDrafts(@RequestBody NewsDTO dto) { + //效验数据 + ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class); + newsService.saveToDrafts(dto); + return new Result(); + } + + /** + * 新增新闻(直接发布) + * * @param dto - * @return + * @return com.elink.esua.epdc.commons.tools.utils.Result + * @author qushutong + * @date 2019/9/6 16:23 */ @PostMapping("publish") - public Result publishNews(@RequestBody NewsDTO dto){ + public Result publishNews(@RequestBody NewsDTO dto) { //效验数据 ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class); newsService.savePublishNews(dto); return new Result(); } - /*** - * @Description 草稿箱发布 - * @Author qushutong - * @Date 2019/9/6 20:35 - * @Param [] - * @Return com.elink.esua.epdc.commons.tools.utils.Result - * @Exception + + /** + * 点击发布,从草稿箱发布新闻 * + * @param id 新闻ID + * @return com.elink.esua.epdc.commons.tools.utils.Result + * @author qushutong + * @date 2019/9/6 20:35 */ @PostMapping("draftsPublishNews/{id}") - public Result draftsPublishNews(@PathVariable String id){ + public Result draftsPublishNews(@PathVariable String id) { newsService.modifyDraftsPublic(id); return new Result(); } 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 759fbc74b..295bd6e59 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 @@ -177,4 +177,14 @@ public interface NewsService extends BaseService { * @date 2019/9/17 19:21 */ Result newsToBanner(String newsId); + + /** + * 新增新闻到草稿(存草稿) + * + * @param dto + * @return void + * @author qushutong + * @date 2019/9/6 16:23 + */ + void saveToDrafts(NewsDTO dto); } 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 98300253c..aa4e06db6 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 @@ -33,12 +33,9 @@ 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.NewsDepartmentDTO; import com.elink.esua.epdc.dto.NewsUserAttitudeDTO; 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.NewsDepartmentEntity; import com.elink.esua.epdc.entity.NewsUserAttitudeEntity; import com.elink.esua.epdc.enums.AppNewsLikeEnum; import com.elink.esua.epdc.dto.epdc.form.EpdcNewsBrowseFromDTO; @@ -134,25 +131,23 @@ public class NewsServiceImpl extends BaseServiceImpl implem @Transactional(rollbackFor = Exception.class) public void save(NewsDTO dto) { NewsEntity entity = ConvertUtils.sourceToTarget(dto, NewsEntity.class); - //默认是0 手动下线是1 - entity.setNewsUpDownState(YesOrNoEnum.NO.value()); - UserDetail user = SecurityUser.getUser(); - entity.setCreatorName(user.getRealName()); - entity.setDeptId(user.getDeptId()); - entity.setDeptName(user.getDeptName()); - entity.setLikeNumber(NumConstant.ZERO); - entity.setUnLikeNumber(NumConstant.ZERO); - entity.setReadingAmount(NumConstant.ZERO); - //存草稿 - entity.setNewsReleaseState(YesOrNoEnum.YES.value()); insert(entity); } + @Override + @Transactional(rollbackFor = Exception.class) + public void saveToDrafts(NewsDTO newsDto) { + saveOrUpdateNews(newsDto, YesOrNoEnum.YES.value()); + } + @Override @Transactional(rollbackFor = Exception.class) public void update(NewsDTO dto) { - NewsEntity entity = ConvertUtils.sourceToTarget(dto, NewsEntity.class); - updateById(entity); + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq(FieldConstant.ID, dto.getId()) + .select("NEWS_UP_DOWN_STATE"); + NewsEntity entity = this.baseDao.selectOne(wrapper); + this.saveOrUpdateNews(dto, entity.getNewsReleaseState()); } @Override @@ -166,77 +161,87 @@ public class NewsServiceImpl extends BaseServiceImpl implem @Override public int checkCountByCategoryId(String categoryId) { - return baseDao.selectCountByCategoryId(categoryId); } @Override public boolean modifyOnLine(Map parmas) { String id = parmas.get("id"); - String onLineState = parmas.get("onLineState"); - NewsDTO newsDTO = get(id); - //判断下是不是上线 是的话才执行 - if (YesOrNoEnum.NO.value().equals(newsDTO.getNewsUpDownState())) { - newsDTO.setNewsUpDownState(YesOrNoEnum.YES.value()); - NewsEntity entity = ConvertUtils.sourceToTarget(newsDTO, NewsEntity.class); - updateById(entity); - return true; + NewsDTO newsDto = get(id); + // 新闻上下线状态 默认是0 手动下线是1 + if (null == newsDto || YesOrNoEnum.YES.value().equals(newsDto.getNewsUpDownState())) { + // 新闻不存在或已下线 + return false; } - return false; + NewsEntity entity = new NewsEntity(); + entity.setId(id); + entity.setNewsUpDownState(YesOrNoEnum.YES.value()); + updateById(entity); + return true; } - @Override public void savePublishNews(NewsDTO newsDTO) { + saveOrUpdateNews(newsDTO, YesOrNoEnum.NO.value()); + } - - publishNews(newsDTO, YesOrNoEnum.NO.value()); + @Override + public void modifyDraftsPublic(String id) { + saveOrUpdateNews(this.get(id), YesOrNoEnum.NO.value()); } - private void publishNews(NewsDTO newsDTO, String newsReleaseState) { - NewsEntity entity = ConvertUtils.sourceToTarget(newsDTO, NewsEntity.class); - //发布的时候 默认是0 手动下线 为1 - entity.setNewsUpDownState(YesOrNoEnum.NO.value()); + /** + * 新闻的数据库操作 + * + * @param newsDto 新闻数据传输对象 + * @param newsReleaseState 是否是草稿箱操作(存草稿或草稿箱中修改操作) + * @return void + * @author qushutong + * @date + */ + private void saveOrUpdateNews(NewsDTO newsDto, String newsReleaseState) { + NewsEntity entity = ConvertUtils.sourceToTarget(newsDto, NewsEntity.class); UserDetail user = SecurityUser.getUser(); - entity.setCreatorName(user.getRealName()); - entity.setDeptId(user.getDeptId()); - entity.setDeptName(user.getDeptName()); - entity.setLikeNumber(NumConstant.ZERO); - entity.setUnLikeNumber(NumConstant.ZERO); - entity.setReadingAmount(NumConstant.ZERO); //是不是草稿箱 entity.setNewsReleaseState(newsReleaseState); boolean isSave = true; - if (StringUtils.isNotBlank(newsDTO.getId())) { + if (StringUtils.isBlank(newsDto.getId())) { + // 新增操作时,保存创建人,创建人部门信息。 + entity.setCreatorName(user.getRealName()); + entity.setDeptId(user.getDeptId()); + entity.setDeptName(user.getDeptName()); + // 初始化互动数 + entity.setLikeNumber(NumConstant.ZERO); + entity.setUnLikeNumber(NumConstant.ZERO); + entity.setReadingAmount(NumConstant.ZERO); + // 发布的时候 默认是0 手动下线 为1 + entity.setNewsUpDownState(YesOrNoEnum.NO.value()); + } else { isSave = false; } - //草稿箱的新增和更新 + // 通知所属部门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("您没有操作此部门的数据权限"); + } + //草稿箱操作 if (YesOrNoEnum.YES.value().equals(newsReleaseState)) { if (isSave) { insert(entity); } else { updateById(entity); - newsDepartmentService.deleteByNewsId(entity.getId()); } } else { - // 通知所属部门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("您没有操作此部门的数据权限"); - } - - if (CollUtil.isEmpty(newsGridList)) { Result> adminResult = adminFeignClient.listGridIdByDeptPid(newsDeptId); if (!adminResult.success() || CollUtil.isEmpty(adminResult.getData())) { @@ -254,13 +259,6 @@ public class NewsServiceImpl extends BaseServiceImpl implem } } - @Override - public void modifyDraftsPublic(String id) { - NewsDTO newsDTO = get(id); - publishNews(newsDTO, YesOrNoEnum.NO.value()); - - } - @Override public Result> listNews(EpdcNewsListFromDTO formDto) {