营养科普

This commit is contained in:
sxu 2025-05-13 13:26:41 +08:00
parent 026697fb2b
commit 71da77299b
7 changed files with 67 additions and 34 deletions

View File

@ -85,7 +85,7 @@ public class HealthPopularScienceController extends BaseController {
try { try {
return toAjax(healthPopularScienceService.insertHealthPopularScience(healthPopularScience)); return toAjax(healthPopularScienceService.insertHealthPopularScience(healthPopularScience));
} catch (Exception e) { } catch (Exception e) {
return error("系统错误, " + e.getMessage()); return error(e.getMessage());
} }
} }
@ -101,7 +101,7 @@ public class HealthPopularScienceController extends BaseController {
try { try {
return toAjax(healthPopularScienceService.updateHealthPopularScience(healthPopularScience)); return toAjax(healthPopularScienceService.updateHealthPopularScience(healthPopularScience));
} catch (Exception e) { } catch (Exception e) {
return error("系统错误, " + e.getMessage()); return error(e.getMessage());
} }
} }

View File

@ -40,5 +40,4 @@ public class HealthArticleChronic extends BaseEntity {
/** 是否删除 0-正常 2-删除 */ /** 是否删除 0-正常 2-删除 */
private Long delFlag; private Long delFlag;
} }

View File

@ -23,9 +23,6 @@ import com.bonus.common.core.web.domain.BaseEntity;
public class HealthPopularScience extends BaseEntity { public class HealthPopularScience extends BaseEntity {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/** 主键自增 */
private Long id;
/** 文章id */ /** 文章id */
@Excel(name = "文章id") @Excel(name = "文章id")
@ApiModelProperty(value = "文章id") @ApiModelProperty(value = "文章id")
@ -85,6 +82,12 @@ public class HealthPopularScience extends BaseEntity {
/** 是否删除 0-正常 2-删除 */ /** 是否删除 0-正常 2-删除 */
private Long delFlag; private Long delFlag;
@ApiModelProperty("慢性病id 多个用,分割")
private String chronicIds;
@ApiModelProperty("慢性病名称 多个用,分割")
private String chronicNames;
public String getCoverPhoto() { public String getCoverPhoto() {
return FileUrlUtil.getFileUrl(coverPhoto); return FileUrlUtil.getFileUrl(coverPhoto);
} }

View File

@ -57,4 +57,6 @@ public interface HealthArticleChronicMapper {
* @return 结果 * @return 结果
*/ */
public int deleteHealthArticleChronicByIds(Long[] ids); public int deleteHealthArticleChronicByIds(Long[] ids);
public int deleteHealthArticleChronicByArticleId(Long articleId);
} }

View File

@ -1,8 +1,16 @@
package com.bonus.canteen.core.nutrition.service.impl; package com.bonus.canteen.core.nutrition.service.impl;
import java.util.Arrays;
import java.util.List; 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.exception.ServiceException;
import com.bonus.common.core.utils.DateUtils; import com.bonus.common.core.utils.DateUtils;
import com.bonus.common.security.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.bonus.canteen.core.nutrition.mapper.HealthPopularScienceMapper; 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 { public class HealthPopularScienceServiceImpl implements IHealthPopularScienceService {
@Autowired @Autowired
private HealthPopularScienceMapper healthPopularScienceMapper; private HealthPopularScienceMapper healthPopularScienceMapper;
@Autowired
HealthArticleChronicMapper healthArticleChronicMapper;
/** /**
* 查询营养科普 * 查询营养科普
@ -51,10 +61,25 @@ public class HealthPopularScienceServiceImpl implements IHealthPopularScienceSer
@Override @Override
public int insertHealthPopularScience(HealthPopularScience healthPopularScience) { public int insertHealthPopularScience(HealthPopularScience healthPopularScience) {
healthPopularScience.setCreateTime(DateUtils.getNowDate()); healthPopularScience.setCreateTime(DateUtils.getNowDate());
healthPopularScience.setCreateBy(SecurityUtils.getUsername());
try { try {
return healthPopularScienceMapper.insertHealthPopularScience(healthPopularScience); int count = healthPopularScienceMapper.insertHealthPopularScience(healthPopularScience);
handleHealthArticles(healthPopularScience);
return count;
} catch (Exception e) { } catch (Exception e) {
throw new ServiceException("错误信息描述, " + e.getMessage()); throw new ServiceException("新增失败");
}
}
private void handleHealthArticles(HealthPopularScience healthPopularScience) {
List<Long> 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 @Override
public int updateHealthPopularScience(HealthPopularScience healthPopularScience) { public int updateHealthPopularScience(HealthPopularScience healthPopularScience) {
healthPopularScience.setUpdateTime(DateUtils.getNowDate()); healthPopularScience.setUpdateTime(DateUtils.getNowDate());
healthPopularScience.setUpdateBy(SecurityUtils.getUsername());
try { try {
return healthPopularScienceMapper.updateHealthPopularScience(healthPopularScience); int count = healthPopularScienceMapper.updateHealthPopularScience(healthPopularScience);
healthArticleChronicMapper.deleteHealthArticleChronicByArticleId(healthPopularScience.getArticleId());
handleHealthArticles(healthPopularScience);
return count;
} catch (Exception e) { } catch (Exception e) {
throw new ServiceException("错误信息描述, " + e.getMessage()); throw new ServiceException("更新失败");
} }
} }

View File

@ -88,4 +88,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
#{id} #{id}
</foreach> </foreach>
</delete> </delete>
<delete id="deleteHealthArticleChronicByArticleId" parameterType="Long">
delete from health_article_chronic where article_id = #{articleId}
</delete>
</mapper> </mapper>

View File

@ -4,7 +4,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.bonus.canteen.core.nutrition.mapper.HealthPopularScienceMapper"> <mapper namespace="com.bonus.canteen.core.nutrition.mapper.HealthPopularScienceMapper">
<resultMap type="com.bonus.canteen.core.nutrition.domain.HealthPopularScience" id="HealthPopularScienceResult"> <resultMap type="com.bonus.canteen.core.nutrition.domain.HealthPopularScience" id="HealthPopularScienceResult">
<result property="id" column="id" />
<result property="articleId" column="article_id" /> <result property="articleId" column="article_id" />
<result property="articleTitle" column="article_title" /> <result property="articleTitle" column="article_title" />
<result property="coverPhoto" column="cover_photo" /> <result property="coverPhoto" column="cover_photo" />
@ -25,7 +24,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</resultMap> </resultMap>
<sql id="selectHealthPopularScienceVo"> <sql id="selectHealthPopularScienceVo">
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.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, 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, GROUP_CONCAT(hac.chronic_name ORDER BY hac.chronic_id desc ) AS chronic_names,
@ -67,13 +66,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectHealthPopularScienceById" parameterType="Long" resultMap="HealthPopularScienceResult"> <select id="selectHealthPopularScienceById" parameterType="Long" resultMap="HealthPopularScienceResult">
<include refid="selectHealthPopularScienceVo"/> <include refid="selectHealthPopularScienceVo"/>
where hps.id = #{id} where hps.article_id = #{articleId}
</select> </select>
<insert id="insertHealthPopularScience" parameterType="com.bonus.canteen.core.nutrition.domain.HealthPopularScience" useGeneratedKeys="true" keyProperty="id"> <insert id="insertHealthPopularScience" parameterType="com.bonus.canteen.core.nutrition.domain.HealthPopularScience" useGeneratedKeys="true" keyProperty="articleId">
insert into health_popular_science insert into health_popular_science
<trim prefix="(" suffix=")" suffixOverrides=","> <trim prefix="(" suffix=")" suffixOverrides=",">
<if test="articleId != null">article_id,</if>
<if test="articleTitle != null and articleTitle != ''">article_title,</if> <if test="articleTitle != null and articleTitle != ''">article_title,</if>
<if test="coverPhoto != null">cover_photo,</if> <if test="coverPhoto != null">cover_photo,</if>
<if test="articleType != null">article_type,</if> <if test="articleType != null">article_type,</if>
@ -92,7 +90,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="remark != null">remark,</if> <if test="remark != null">remark,</if>
</trim> </trim>
<trim prefix="values (" suffix=")" suffixOverrides=","> <trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="articleId != null">#{articleId},</if>
<if test="articleTitle != null and articleTitle != ''">#{articleTitle},</if> <if test="articleTitle != null and articleTitle != ''">#{articleTitle},</if>
<if test="coverPhoto != null">#{coverPhoto},</if> <if test="coverPhoto != null">#{coverPhoto},</if>
<if test="articleType != null">#{articleType},</if> <if test="articleType != null">#{articleType},</if>
@ -115,7 +112,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<update id="updateHealthPopularScience" parameterType="com.bonus.canteen.core.nutrition.domain.HealthPopularScience"> <update id="updateHealthPopularScience" parameterType="com.bonus.canteen.core.nutrition.domain.HealthPopularScience">
update health_popular_science update health_popular_science
<trim prefix="SET" suffixOverrides=","> <trim prefix="SET" suffixOverrides=",">
<if test="articleId != null">article_id = #{articleId},</if>
<if test="articleTitle != null and articleTitle != ''">article_title = #{articleTitle},</if> <if test="articleTitle != null and articleTitle != ''">article_title = #{articleTitle},</if>
<if test="coverPhoto != null">cover_photo = #{coverPhoto},</if> <if test="coverPhoto != null">cover_photo = #{coverPhoto},</if>
<if test="articleType != null">article_type = #{articleType},</if> <if test="articleType != null">article_type = #{articleType},</if>
@ -133,17 +129,17 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="updateTime != null">update_time = #{updateTime},</if> <if test="updateTime != null">update_time = #{updateTime},</if>
<if test="remark != null">remark = #{remark},</if> <if test="remark != null">remark = #{remark},</if>
</trim> </trim>
where id = #{id} where article_id = #{articleId}
</update> </update>
<delete id="deleteHealthPopularScienceById" parameterType="Long"> <delete id="deleteHealthPopularScienceById" parameterType="Long">
delete from health_popular_science where id = #{id} delete from health_popular_science where article_id = #{articleId}
</delete> </delete>
<delete id="deleteHealthPopularScienceByIds" parameterType="String"> <delete id="deleteHealthPopularScienceByIds" parameterType="String">
delete from health_popular_science where id in delete from health_popular_science where article_id in
<foreach item="id" collection="array" open="(" separator="," close=")"> <foreach item="articleId" collection="array" open="(" separator="," close=")">
#{id} #{articleId}
</foreach> </foreach>
</delete> </delete>
</mapper> </mapper>