diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/nutrition/controller/HealthPopularScienceController.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/nutrition/controller/HealthPopularScienceController.java index 888e032..07fdeb6 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/nutrition/controller/HealthPopularScienceController.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/nutrition/controller/HealthPopularScienceController.java @@ -85,7 +85,7 @@ public class HealthPopularScienceController extends BaseController { try { return toAjax(healthPopularScienceService.insertHealthPopularScience(healthPopularScience)); } catch (Exception e) { - return error("系统错误, " + e.getMessage()); + return error(e.getMessage()); } } @@ -101,7 +101,7 @@ public class HealthPopularScienceController extends BaseController { try { return toAjax(healthPopularScienceService.updateHealthPopularScience(healthPopularScience)); } catch (Exception e) { - return error("系统错误, " + e.getMessage()); + return error(e.getMessage()); } } diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/nutrition/domain/HealthArticleChronic.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/nutrition/domain/HealthArticleChronic.java index a891fd3..df3573e 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/nutrition/domain/HealthArticleChronic.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/nutrition/domain/HealthArticleChronic.java @@ -40,5 +40,4 @@ public class HealthArticleChronic extends BaseEntity { /** 是否删除 0-正常 2-删除 */ private Long delFlag; - } diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/nutrition/domain/HealthPopularScience.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/nutrition/domain/HealthPopularScience.java index 427270b..e326975 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/nutrition/domain/HealthPopularScience.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/nutrition/domain/HealthPopularScience.java @@ -23,9 +23,6 @@ import com.bonus.common.core.web.domain.BaseEntity; public class HealthPopularScience extends BaseEntity { private static final long serialVersionUID = 1L; - /** 主键自增 */ - private Long id; - /** 文章id */ @Excel(name = "文章id") @ApiModelProperty(value = "文章id") @@ -85,6 +82,12 @@ public class HealthPopularScience extends BaseEntity { /** 是否删除 0-正常 2-删除 */ private Long delFlag; + @ApiModelProperty("慢性病id 多个用,分割") + private String chronicIds; + + @ApiModelProperty("慢性病名称 多个用,分割") + private String chronicNames; + public String getCoverPhoto() { return FileUrlUtil.getFileUrl(coverPhoto); } diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/nutrition/mapper/HealthArticleChronicMapper.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/nutrition/mapper/HealthArticleChronicMapper.java index c8f43dd..271865c 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/nutrition/mapper/HealthArticleChronicMapper.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/nutrition/mapper/HealthArticleChronicMapper.java @@ -57,4 +57,6 @@ public interface HealthArticleChronicMapper { * @return 结果 */ public int deleteHealthArticleChronicByIds(Long[] ids); + + public int deleteHealthArticleChronicByArticleId(Long articleId); } diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/nutrition/service/impl/HealthPopularScienceServiceImpl.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/nutrition/service/impl/HealthPopularScienceServiceImpl.java index e168329..cf1bed7 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/nutrition/service/impl/HealthPopularScienceServiceImpl.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/nutrition/service/impl/HealthPopularScienceServiceImpl.java @@ -1,8 +1,16 @@ package com.bonus.canteen.core.nutrition.service.impl; +import java.util.Arrays; import java.util.List; +import java.util.stream.Collectors; + +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.StrUtil; +import com.bonus.canteen.core.nutrition.domain.HealthArticleChronic; +import com.bonus.canteen.core.nutrition.mapper.HealthArticleChronicMapper; import com.bonus.common.core.exception.ServiceException; import com.bonus.common.core.utils.DateUtils; +import com.bonus.common.security.utils.SecurityUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.bonus.canteen.core.nutrition.mapper.HealthPopularScienceMapper; @@ -19,6 +27,8 @@ import com.bonus.canteen.core.nutrition.service.IHealthPopularScienceService; public class HealthPopularScienceServiceImpl implements IHealthPopularScienceService { @Autowired private HealthPopularScienceMapper healthPopularScienceMapper; + @Autowired + HealthArticleChronicMapper healthArticleChronicMapper; /** * 查询营养科普 @@ -51,10 +61,25 @@ public class HealthPopularScienceServiceImpl implements IHealthPopularScienceSer @Override public int insertHealthPopularScience(HealthPopularScience healthPopularScience) { healthPopularScience.setCreateTime(DateUtils.getNowDate()); + healthPopularScience.setCreateBy(SecurityUtils.getUsername()); try { - return healthPopularScienceMapper.insertHealthPopularScience(healthPopularScience); + int count = healthPopularScienceMapper.insertHealthPopularScience(healthPopularScience); + handleHealthArticles(healthPopularScience); + return count; } catch (Exception e) { - throw new ServiceException("错误信息描述, " + e.getMessage()); + throw new ServiceException("新增失败"); + } + } + + private void handleHealthArticles(HealthPopularScience healthPopularScience) { + List chronicIdList = StrUtil.isNotBlank(healthPopularScience.getChronicIds()) ? + Arrays.stream(healthPopularScience.getChronicIds().split(",")).map(Long::parseLong).collect(Collectors.toList()) : CollUtil.newArrayList(new Long[0]); + HealthArticleChronic vo = new HealthArticleChronic(); + for (Long chronicId : chronicIdList) { + vo.setArticleId(healthPopularScience.getArticleId()); + vo.setChronicId(chronicId); + vo.setChronicName(healthArticleChronicMapper.selectHealthArticleChronicById(chronicId).getChronicName()); + healthArticleChronicMapper.insertHealthArticleChronic(vo); } } @@ -67,10 +92,14 @@ public class HealthPopularScienceServiceImpl implements IHealthPopularScienceSer @Override public int updateHealthPopularScience(HealthPopularScience healthPopularScience) { healthPopularScience.setUpdateTime(DateUtils.getNowDate()); + healthPopularScience.setUpdateBy(SecurityUtils.getUsername()); try { - return healthPopularScienceMapper.updateHealthPopularScience(healthPopularScience); + int count = healthPopularScienceMapper.updateHealthPopularScience(healthPopularScience); + healthArticleChronicMapper.deleteHealthArticleChronicByArticleId(healthPopularScience.getArticleId()); + handleHealthArticles(healthPopularScience); + return count; } catch (Exception e) { - throw new ServiceException("错误信息描述, " + e.getMessage()); + throw new ServiceException("更新失败"); } } diff --git a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/nutrition/HealthArticleChronicMapper.xml b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/nutrition/HealthArticleChronicMapper.xml index 4a338c1..3280675 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/nutrition/HealthArticleChronicMapper.xml +++ b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/nutrition/HealthArticleChronicMapper.xml @@ -88,4 +88,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{id} + + + delete from health_article_chronic where article_id = #{articleId} + \ No newline at end of file diff --git a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/nutrition/HealthPopularScienceMapper.xml b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/nutrition/HealthPopularScienceMapper.xml index 637aa2d..aef705f 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/nutrition/HealthPopularScienceMapper.xml +++ b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/nutrition/HealthPopularScienceMapper.xml @@ -4,7 +4,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> - @@ -25,7 +24,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - select hps.id, hps.article_id, hps.article_title, hps.cover_photo, hps.article_type, hps.article_content, + select hps.article_id, hps.article_title, hps.cover_photo, hps.article_type, hps.article_content, hps.article_url, hps.if_visible, hps.hits, hps.if_pushed, hps.push_time, hps.summary, hps.del_flag, hps.create_by, hps.create_time, hps.update_by, hps.update_time, hps.remark, GROUP_CONCAT(hac.chronic_name ORDER BY hac.chronic_id desc ) AS chronic_names, @@ -51,29 +50,28 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" and hps.summary = #{summary} GROUP BY - hps.article_id, - hps.article_title, - hps.cover_photo, - hps.article_type, - hps.article_url, - hps.summary, - hps.if_visible, - hps.if_pushed, - hps.push_time, - hps.hits, - hps.create_time, - hps.update_time + hps.article_id, + hps.article_title, + hps.cover_photo, + hps.article_type, + hps.article_url, + hps.summary, + hps.if_visible, + hps.if_pushed, + hps.push_time, + hps.hits, + hps.create_time, + hps.update_time - + insert into health_popular_science - article_id, article_title, cover_photo, article_type, @@ -92,7 +90,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" remark, - #{articleId}, #{articleTitle}, #{coverPhoto}, #{articleType}, @@ -115,7 +112,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" update health_popular_science - article_id = #{articleId}, article_title = #{articleTitle}, cover_photo = #{coverPhoto}, article_type = #{articleType}, @@ -133,17 +129,17 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" update_time = #{updateTime}, remark = #{remark}, - where id = #{id} + where article_id = #{articleId} - delete from health_popular_science where id = #{id} + delete from health_popular_science where article_id = #{articleId} - delete from health_popular_science where id in - - #{id} + delete from health_popular_science where article_id in + + #{articleId} \ No newline at end of file