营养科普
This commit is contained in:
parent
026697fb2b
commit
71da77299b
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -40,5 +40,4 @@ public class HealthArticleChronic extends BaseEntity {
|
|||
/** 是否删除 0-正常 2-删除 */
|
||||
private Long delFlag;
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,4 +57,6 @@ public interface HealthArticleChronicMapper {
|
|||
* @return 结果
|
||||
*/
|
||||
public int deleteHealthArticleChronicByIds(Long[] ids);
|
||||
|
||||
public int deleteHealthArticleChronicByArticleId(Long articleId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<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
|
||||
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("更新失败");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -88,4 +88,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
#{id}
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
<delete id="deleteHealthArticleChronicByArticleId" parameterType="Long">
|
||||
delete from health_article_chronic where article_id = #{articleId}
|
||||
</delete>
|
||||
</mapper>
|
||||
|
|
@ -4,7 +4,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.bonus.canteen.core.nutrition.mapper.HealthPopularScienceMapper">
|
||||
<resultMap type="com.bonus.canteen.core.nutrition.domain.HealthPopularScience" id="HealthPopularScienceResult">
|
||||
<result property="id" column="id" />
|
||||
<result property="articleId" column="article_id" />
|
||||
<result property="articleTitle" column="article_title" />
|
||||
<result property="coverPhoto" column="cover_photo" />
|
||||
|
|
@ -25,7 +24,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
</resultMap>
|
||||
|
||||
<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.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"
|
|||
<if test="summary != null and summary != ''"> and hps.summary = #{summary}</if>
|
||||
</where>
|
||||
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
|
||||
</select>
|
||||
|
||||
<select id="selectHealthPopularScienceById" parameterType="Long" resultMap="HealthPopularScienceResult">
|
||||
<include refid="selectHealthPopularScienceVo"/>
|
||||
where hps.id = #{id}
|
||||
where hps.article_id = #{articleId}
|
||||
</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
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="articleId != null">article_id,</if>
|
||||
<if test="articleTitle != null and articleTitle != ''">article_title,</if>
|
||||
<if test="coverPhoto != null">cover_photo,</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>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="articleId != null">#{articleId},</if>
|
||||
<if test="articleTitle != null and articleTitle != ''">#{articleTitle},</if>
|
||||
<if test="coverPhoto != null">#{coverPhoto},</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 health_popular_science
|
||||
<trim prefix="SET" suffixOverrides=",">
|
||||
<if test="articleId != null">article_id = #{articleId},</if>
|
||||
<if test="articleTitle != null and articleTitle != ''">article_title = #{articleTitle},</if>
|
||||
<if test="coverPhoto != null">cover_photo = #{coverPhoto},</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="remark != null">remark = #{remark},</if>
|
||||
</trim>
|
||||
where id = #{id}
|
||||
where article_id = #{articleId}
|
||||
</update>
|
||||
|
||||
<delete id="deleteHealthPopularScienceById" parameterType="Long">
|
||||
delete from health_popular_science where id = #{id}
|
||||
delete from health_popular_science where article_id = #{articleId}
|
||||
</delete>
|
||||
|
||||
<delete id="deleteHealthPopularScienceByIds" parameterType="String">
|
||||
delete from health_popular_science where id in
|
||||
<foreach item="id" collection="array" open="(" separator="," close=")">
|
||||
#{id}
|
||||
delete from health_popular_science where article_id in
|
||||
<foreach item="articleId" collection="array" open="(" separator="," close=")">
|
||||
#{articleId}
|
||||
</foreach>
|
||||
</delete>
|
||||
</mapper>
|
||||
Loading…
Reference in New Issue