!133 食材添加信息

Merge pull request !133 from 德仔/develop
This commit is contained in:
德仔
2021-03-16 20:10:50 +08:00
committed by Gitee
22 changed files with 983 additions and 591 deletions

View File

@ -0,0 +1,27 @@
package com.stdiet.custom.domain;
import lombok.Data;
import java.util.Date;
@Data
public class SysIngredentFile {
Long id;
Long igdId;
String fileUrl;
String fileName;
Integer delFlag;
String createBy;
Date createTime;
String updateBy;
Date updateTime;
}

View File

@ -6,6 +6,7 @@ import lombok.Data;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
/**
* 食材对象 sys_ingredient
@ -15,8 +16,6 @@ import java.util.Date;
*/
@Data
public class SysIngredient {
private static final long serialVersionUID = 1L;
/**
* id
*/
@ -107,4 +106,11 @@ public class SysIngredient {
private Long[] notRecIds;
/**
* 食材信息
*/
private String info;
private List<SysIngredentFile> imgList;
}

View File

@ -1,6 +1,8 @@
package com.stdiet.custom.mapper;
import java.util.List;
import com.stdiet.custom.domain.SysIngredentFile;
import com.stdiet.custom.domain.SysIngredient;
import com.stdiet.custom.domain.SysIngredientNotRec;
import com.stdiet.custom.domain.SysIngredientRec;
@ -80,4 +82,6 @@ public interface SysIngredientMapper
* @return
*/
public SysIngredient selectSysIngredientByName(@Param("name") String name);
int batchInsertIngredientImage(List<SysIngredentFile> list);
}

View File

@ -1,7 +1,9 @@
package com.stdiet.custom.service.impl;
import com.stdiet.common.utils.DateUtils;
import com.stdiet.common.utils.SecurityUtils;
import com.stdiet.common.utils.StringUtils;
import com.stdiet.custom.domain.SysIngredentFile;
import com.stdiet.custom.domain.SysIngredient;
import com.stdiet.custom.domain.SysIngredientNotRec;
import com.stdiet.custom.domain.SysIngredientRec;
@ -60,24 +62,35 @@ public class SysIngredientServiceImpl implements ISysIngredientService {
insertRecommand(sysIngredient);
//
insertNotRecommand(sysIngredient);
//
if (StringUtils.isNotNull(sysIngredient.getImgList())) {
List<SysIngredentFile> fileList = sysIngredient.getImgList();
for (SysIngredentFile file : fileList) {
file.setId(sysIngredient.getId());
file.setCreateBy(SecurityUtils.getUsername());
file.setCreateTime(DateUtils.getNowDate());
}
sysIngredientMapper.batchInsertIngredientImage(fileList);
}
return rows;
}
/**
* 新增推荐标签
*
* @param ingredient
*/
public void insertRecommand(SysIngredient ingredient) {
Long[] recIds = ingredient.getRecIds();
if(StringUtils.isNotNull(recIds)) {
if (StringUtils.isNotNull(recIds)) {
List<SysIngredientRec> list = new ArrayList<SysIngredientRec>();
for(Long recId: recIds) {
for (Long recId : recIds) {
SysIngredientRec rec = new SysIngredientRec();
rec.setIngredientId(ingredient.getId());
rec.setRecommandId(recId);
list.add(rec);
}
if(list.size() > 0) {
if (list.size() > 0) {
sysIngredientMapper.batchIngredientRec(list);
}
}
@ -85,19 +98,20 @@ public class SysIngredientServiceImpl implements ISysIngredientService {
/**
* 新增不推荐标签
*
* @param ingredient
*/
public void insertNotRecommand(SysIngredient ingredient) {
Long[] notRecIds = ingredient.getNotRecIds();
if(StringUtils.isNotNull(notRecIds)) {
if (StringUtils.isNotNull(notRecIds)) {
List<SysIngredientNotRec> list = new ArrayList<SysIngredientNotRec>();
for(Long recId: notRecIds) {
for (Long recId : notRecIds) {
SysIngredientNotRec notRec = new SysIngredientNotRec();
notRec.setIngredientId(ingredient.getId());
notRec.setRecommandId(recId);
list.add(notRec);
}
if(list.size() > 0) {
if (list.size() > 0) {
sysIngredientMapper.batchIngredientNotRec(list);
}
}
@ -148,11 +162,12 @@ public class SysIngredientServiceImpl implements ISysIngredientService {
/**
* 根据食材名称查询食材信息
*
* @param name
* @return
*/
@Override
public SysIngredient selectSysIngredientByName(String name){
public SysIngredient selectSysIngredientByName(String name) {
return sysIngredientMapper.selectSysIngredientByName(name);
}
}

View File

@ -37,6 +37,7 @@
where del_flag = 0
<if test="name != null and name != ''"> and name like concat('%', #{name}, '%')</if>
<if test="phone != null and phone != ''"> and phone like concat('%', #{phone}, '%')</if>
<if test="fansChannel != null "> and fans_channel = #{fansChannel}</if>
order by create_time desc
</select>

View File

@ -5,21 +5,23 @@
<mapper namespace="com.stdiet.custom.mapper.SysIngredientMapper">
<resultMap type="SysIngredient" id="SysIngredientResult">
<result property="id" column="id" />
<result property="name" column="name" />
<result property="type" column="type" />
<result property="proteinRatio" column="protein_ratio" />
<result property="fatRatio" column="fat_ratio" />
<result property="carbonRatio" column="carbon_ratio" />
<result property="area" column="area" />
<result property="remark" column="remark" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
<result property="rec" column="rec" />
<result property="notRec" column="not_rec" />
<result property="reviewStatus" column="review_status" />
<result property="id" column="id"/>
<result property="name" column="name"/>
<result property="type" column="type"/>
<result property="proteinRatio" column="protein_ratio"/>
<result property="fatRatio" column="fat_ratio"/>
<result property="carbonRatio" column="carbon_ratio"/>
<result property="area" column="area"/>
<result property="remark" column="remark"/>
<result property="createBy" column="create_by"/>
<result property="createTime" column="create_time"/>
<result property="updateBy" column="update_by"/>
<result property="updateTime" column="update_time"/>
<result property="rec" column="rec"/>
<result property="notRec" column="not_rec"/>
<result property="reviewStatus" column="review_status"/>
<result property="info" column="info"/>
<association property="imgList" column="id" select="selectIngredentFileById"/>
</resultMap>
<sql id="selectSysIngredientVo">
@ -43,44 +45,44 @@
<sql id="selectSysIngredientByPhyVo">
SELECT * FROM sys_ingredient igd
RIGHT JOIN(
SELECT * FROM(
SELECT DISTINCT(ingredient_id) as id FROM sys_ingredient_rec
<where>
<if test="recIds != null">
physical_signs_id in
<foreach collection="recIds" item="item" index="index" open="(" separator="," close=")">
#{item}
</foreach>
</if>
</where>
) recId
LEFT JOIN (
SELECT ingredient_id as id, GROUP_CONCAT(name SEPARATOR ',') rec FROM(
SELECT physical_signs_id as id, ingredient_id
FROM sys_ingredient_rec
) rec JOIN sys_physical_signs phy USING(id)
GROUP BY id
) recM USING(id)
INNER JOIN (
SELECT * FROM(
SELECT DISTINCT(ingredient_id) as id FROM sys_ingredient_not_rec
<where>
<if test="notRecIds != null">
physical_signs_id in
<foreach collection="notRecIds" item="item" index="index" open="(" separator="," close=")">
#{item}
</foreach>
</if>
</where>
) notRecId
LEFT JOIN (
SELECT ingredient_id as id, GROUP_CONCAT(name SEPARATOR ',') not_rec FROM(
SELECT physical_signs_id as id, ingredient_id
FROM sys_ingredient_not_rec
) notRec JOIN sys_physical_signs phy USING(id)
GROUP BY id
) notRecM USING(id)
) notRecT USING(id)
SELECT * FROM(
SELECT DISTINCT(ingredient_id) as id FROM sys_ingredient_rec
<where>
<if test="recIds != null">
physical_signs_id in
<foreach collection="recIds" item="item" index="index" open="(" separator="," close=")">
#{item}
</foreach>
</if>
</where>
) recId
LEFT JOIN (
SELECT ingredient_id as id, GROUP_CONCAT(name SEPARATOR ',') rec FROM(
SELECT physical_signs_id as id, ingredient_id
FROM sys_ingredient_rec
) rec JOIN sys_physical_signs phy USING(id)
GROUP BY id
) recM USING(id)
INNER JOIN (
SELECT * FROM(
SELECT DISTINCT(ingredient_id) as id FROM sys_ingredient_not_rec
<where>
<if test="notRecIds != null">
physical_signs_id in
<foreach collection="notRecIds" item="item" index="index" open="(" separator="," close=")">
#{item}
</foreach>
</if>
</where>
) notRecId
LEFT JOIN (
SELECT ingredient_id as id, GROUP_CONCAT(name SEPARATOR ',') not_rec FROM(
SELECT physical_signs_id as id, ingredient_id
FROM sys_ingredient_not_rec
) notRec JOIN sys_physical_signs phy USING(id)
GROUP BY id
) notRecM USING(id)
) notRecT USING(id)
) recT USING(id)
</sql>
@ -97,10 +99,10 @@
</otherwise>
</choose>
<where>
<if test="name != null and name != ''"> and name like concat('%', #{name}, '%')</if>
<if test="type != null and type != ''"> and type = #{type}</if>
<if test="area != null and area != ''"> and area = #{area}</if>
<if test="reviewStatus != null and reviewStatus != ''"> and review_status = #{reviewStatus}</if>
<if test="name != null and name != ''">and name like concat('%', #{name}, '%')</if>
<if test="type != null and type != ''">and type = #{type}</if>
<if test="area != null and area != ''">and area = #{area}</if>
<if test="reviewStatus != null and reviewStatus != ''">and review_status = #{reviewStatus}</if>
</where>
</select>
@ -124,6 +126,7 @@
<if test="updateBy != null">update_by,</if>
<if test="updateTime != null">update_time,</if>
<if test="reviewStatus != null">review_status,</if>
<if test="info != null">info,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="name != null">#{name},</if>
@ -138,17 +141,18 @@
<if test="updateBy != null">#{updateBy},</if>
<if test="updateTime != null">#{updateTime},</if>
<if test="reviewStatus != null">#{reviewStatus},</if>
<if test="info != null">#{info},</if>
</trim>
</insert>
<insert id="batchIngredientRec" >
<insert id="batchIngredientRec">
insert into sys_ingredient_rec(ingredient_id, physical_signs_id) values
<foreach collection="list" separator="," item="item" index="index">
(#{item.ingredientId},#{item.recommandId})
</foreach>
</insert>
<insert id="batchIngredientNotRec" >
<insert id="batchIngredientNotRec">
insert into sys_ingredient_not_rec(ingredient_id, physical_signs_id) values
<foreach collection="list" separator="," item="item" index="index">
(#{item.ingredientId},#{item.notRecommandId})
@ -192,6 +196,7 @@
<if test="updateBy != null">update_by = #{updateBy},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
<if test="reviewStatus != null">review_status = #{reviewStatus},</if>
<if test="info != null">info = #{info},</if>
</trim>
where id = #{id}
</update>
@ -213,4 +218,28 @@
where name = #{name} limit 1
</select>
<!-- 添加食材图片-->
<insert id="batchInsertIngredientImage">
insert into sys_ingredient_file(igd_id, file_url, file_name, create_by, create_time, update_by, update_time )
values
<foreach collection="list" separator="," item="item" index="index">
(#{item.ingredientId},#{item.fileUrl},#{item.fileName},#{item.createBy},#{item.createTime},#{item.updateBy},#{item.updateTime})
</foreach>
</insert>
<resultMap id="SysIngredentFileResult" type="SysIngredentFile">
<result property="id" column="id"/>
<result property="fileName" column="file_name"/>
<result property="fileUrl" column="file_url"/>
</resultMap>
<!-- 查找图片-->
<select id="selectIngredentFileById" parameterType="Long" resultMap="SysIngredentFileResult">
select id, file_url, file_name from sys_ingredent_file where igd_id = #{id} and del_flag = 0
</select>
<!-- 删除图片记录-->
<update id="deleteIngredentFileById" parameterType="Long">
update sys_ingredent_file set del_flag=1 where id=#{id}
</update>
</mapper>