lzy 3 days ago
parent
commit
6e0b8232db

+ 0 - 1
Marketplace/src/main/java/com/dt/child/controller/ChildController.java

@@ -22,7 +22,6 @@ public class ChildController {
 
 //    添加幼儿
     @RequestMapping("addChild")
-    @NonLoginRequired
     public Result addChild(@RequestBody @Valid Child child, @RequestHeader("token") String token) {
         Long userId = TokenUtils.getUserId(token);
         child.setUserId(userId);

+ 29 - 0
Marketplace/src/main/java/com/dt/child/controller/FoodController.java

@@ -0,0 +1,29 @@
+package com.dt.child.controller;
+
+import com.dt.child.dto.SelFoodDto;
+import com.dt.child.service.LzyFoodService;
+import com.dt.vo.Result;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.annotation.Resource;
+import javax.validation.Valid;
+
+@RestController
+@RequestMapping("food")
+public class FoodController {
+
+    @Resource
+    private LzyFoodService lzyFoodService;
+
+
+    @PostMapping("selFood")
+    public Result selFood(@RequestBody @Valid SelFoodDto selFoodDto) {
+        return lzyFoodService.selFood(selFoodDto);
+    }
+
+
+
+}

+ 27 - 0
Marketplace/src/main/java/com/dt/child/controller/LzyTypeController.java

@@ -0,0 +1,27 @@
+package com.dt.child.controller;
+
+import com.dt.child.service.LzyTypeService;
+import com.dt.vo.Result;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.annotation.Resource;
+
+@RequestMapping("type")
+@RestController
+public class LzyTypeController {
+
+    @Resource
+    private LzyTypeService lzyTypeService;
+
+    @PostMapping("selType")
+    public Result selType()
+    {
+        return lzyTypeService.selType();
+    }
+
+
+
+
+}

+ 108 - 0
Marketplace/src/main/java/com/dt/child/dao/LzyFood.java

@@ -0,0 +1,108 @@
+package com.dt.child.dao;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import java.io.Serializable;
+import lombok.Data;
+
+/**
+ * 
+ * @TableName lzy_food
+ */
+@TableName(value ="lzy_food")
+@Data
+public class LzyFood implements Serializable {
+    /**
+     * 主键
+     */
+    @TableId
+    private Long id;
+
+    /**
+     * 名字
+     */
+    private String name;
+
+    /**
+     * 图片
+     */
+    private String img;
+
+    /**
+     * 标题
+     */
+    private String title;
+
+    /**
+     * 浏览量
+     */
+    private Integer previewCount;
+
+    /**
+     * 点赞量
+     */
+    private Integer saves;
+
+    /**
+     * 类型id
+     */
+    private Long typeId;
+
+    @TableField(exist = false)
+    private static final long serialVersionUID = 1L;
+
+    @Override
+    public boolean equals(Object that) {
+        if (this == that) {
+            return true;
+        }
+        if (that == null) {
+            return false;
+        }
+        if (getClass() != that.getClass()) {
+            return false;
+        }
+        LzyFood other = (LzyFood) that;
+        return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
+            && (this.getName() == null ? other.getName() == null : this.getName().equals(other.getName()))
+            && (this.getImg() == null ? other.getImg() == null : this.getImg().equals(other.getImg()))
+            && (this.getTitle() == null ? other.getTitle() == null : this.getTitle().equals(other.getTitle()))
+            && (this.getPreviewCount() == null ? other.getPreviewCount() == null : this.getPreviewCount().equals(other.getPreviewCount()))
+            && (this.getSaves() == null ? other.getSaves() == null : this.getSaves().equals(other.getSaves()))
+            && (this.getTypeId() == null ? other.getTypeId() == null : this.getTypeId().equals(other.getTypeId()));
+    }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
+        result = prime * result + ((getName() == null) ? 0 : getName().hashCode());
+        result = prime * result + ((getImg() == null) ? 0 : getImg().hashCode());
+        result = prime * result + ((getTitle() == null) ? 0 : getTitle().hashCode());
+        result = prime * result + ((getPreviewCount() == null) ? 0 : getPreviewCount().hashCode());
+        result = prime * result + ((getSaves() == null) ? 0 : getSaves().hashCode());
+        result = prime * result + ((getTypeId() == null) ? 0 : getTypeId().hashCode());
+        return result;
+    }
+
+    @Override
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        sb.append(getClass().getSimpleName());
+        sb.append(" [");
+        sb.append("Hash = ").append(hashCode());
+        sb.append(", id=").append(id);
+        sb.append(", name=").append(name);
+        sb.append(", img=").append(img);
+        sb.append(", title=").append(title);
+        sb.append(", previewCount=").append(previewCount);
+        sb.append(", saves=").append(saves);
+        sb.append(", typeId=").append(typeId);
+        sb.append(", serialVersionUID=").append(serialVersionUID);
+        sb.append("]");
+        return sb.toString();
+    }
+}

+ 76 - 0
Marketplace/src/main/java/com/dt/child/dao/LzyType.java

@@ -0,0 +1,76 @@
+package com.dt.child.dao;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import java.io.Serializable;
+import lombok.Data;
+
+/**
+ * 
+ * @TableName lzy_type
+ */
+@TableName(value ="lzy_type")
+@Data
+public class LzyType implements Serializable {
+    /**
+     * 主键
+     */
+    @TableId
+    private Long id;
+
+    /**
+     * 名字
+     */
+    private String name;
+
+    /**
+     * 标题
+     */
+    private String title;
+
+    @TableField(exist = false)
+    private static final long serialVersionUID = 1L;
+
+    @Override
+    public boolean equals(Object that) {
+        if (this == that) {
+            return true;
+        }
+        if (that == null) {
+            return false;
+        }
+        if (getClass() != that.getClass()) {
+            return false;
+        }
+        LzyType other = (LzyType) that;
+        return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
+            && (this.getName() == null ? other.getName() == null : this.getName().equals(other.getName()))
+            && (this.getTitle() == null ? other.getTitle() == null : this.getTitle().equals(other.getTitle()));
+    }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
+        result = prime * result + ((getName() == null) ? 0 : getName().hashCode());
+        result = prime * result + ((getTitle() == null) ? 0 : getTitle().hashCode());
+        return result;
+    }
+
+    @Override
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        sb.append(getClass().getSimpleName());
+        sb.append(" [");
+        sb.append("Hash = ").append(hashCode());
+        sb.append(", id=").append(id);
+        sb.append(", name=").append(name);
+        sb.append(", title=").append(title);
+        sb.append(", serialVersionUID=").append(serialVersionUID);
+        sb.append("]");
+        return sb.toString();
+    }
+}

+ 12 - 0
Marketplace/src/main/java/com/dt/child/dto/SelFoodDto.java

@@ -0,0 +1,12 @@
+package com.dt.child.dto;
+
+import lombok.Data;
+
+import javax.validation.constraints.NotNull;
+
+@Data
+public class SelFoodDto {
+    @NotNull
+    private Long id;
+
+}

+ 20 - 0
Marketplace/src/main/java/com/dt/child/mapper/LzyFoodMapper.java

@@ -0,0 +1,20 @@
+package com.dt.child.mapper;
+
+import com.dt.child.dao.LzyFood;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Mapper;
+
+/**
+* @author lzy
+* @description 针对表【lzy_food】的数据库操作Mapper
+* @createDate 2025-07-03 20:13:59
+* @Entity com.dt.child.dao.LzyFood
+*/
+@Mapper
+public interface LzyFoodMapper extends BaseMapper<LzyFood> {
+
+}
+
+
+
+

+ 20 - 0
Marketplace/src/main/java/com/dt/child/mapper/LzyTypeMapper.java

@@ -0,0 +1,20 @@
+package com.dt.child.mapper;
+
+import com.dt.child.dao.LzyType;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Mapper;
+
+/**
+* @author lzy
+* @description 针对表【lzy_type】的数据库操作Mapper
+* @createDate 2025-07-03 20:13:59
+* @Entity com.dt.child.dao.LzyType
+*/
+@Mapper
+public interface LzyTypeMapper extends BaseMapper<LzyType> {
+
+}
+
+
+
+

+ 18 - 0
Marketplace/src/main/java/com/dt/child/service/LzyFoodService.java

@@ -0,0 +1,18 @@
+package com.dt.child.service;
+
+import com.dt.child.dao.LzyFood;
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.dt.child.dto.SelFoodDto;
+import com.dt.vo.Result;
+
+/**
+* @author lzy
+* @description 针对表【lzy_food】的数据库操作Service
+* @createDate 2025-07-03 20:13:59
+*/
+public interface LzyFoodService extends IService<LzyFood> {
+
+//    查询食物
+    Result selFood(SelFoodDto selFoodDto);
+
+}

+ 19 - 0
Marketplace/src/main/java/com/dt/child/service/LzyTypeService.java

@@ -0,0 +1,19 @@
+package com.dt.child.service;
+
+import com.dt.child.dao.LzyType;
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.dt.vo.Result;
+
+/**
+* @author lzy
+* @description 针对表【lzy_type】的数据库操作Service
+* @createDate 2025-07-03 20:13:59
+*/
+public interface LzyTypeService extends IService<LzyType> {
+
+//  查询标题
+    Result selType();
+
+
+
+}

+ 61 - 0
Marketplace/src/main/java/com/dt/child/service/impl/LzyFoodServiceImpl.java

@@ -0,0 +1,61 @@
+package com.dt.child.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.dt.child.dao.LzyFood;
+import com.dt.child.dao.LzyType;
+import com.dt.child.dto.SelFoodDto;
+import com.dt.child.mapper.LzyTypeMapper;
+import com.dt.child.service.LzyFoodService;
+import com.dt.child.mapper.LzyFoodMapper;
+import com.dt.child.vo.FoodVo;
+import com.dt.vo.Result;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import javax.annotation.Resource;
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+* @author lzy
+* @description 针对表【lzy_food】的数据库操作Service实现
+* @createDate 2025-07-03 20:13:59
+*/
+@Service
+public class LzyFoodServiceImpl extends ServiceImpl<LzyFoodMapper, LzyFood>
+    implements LzyFoodService{
+
+
+    @Resource
+    private LzyTypeMapper lzyTypeMapper;
+
+//    查询食物
+    @Override
+    @Transactional
+    public Result selFood(SelFoodDto selFoodDto) {
+        LzyType lzyType = lzyTypeMapper.selectById(selFoodDto.getId());
+        if (lzyTypeMapper==null){
+            return Result.Err(null, "没有此分类");
+        }
+        FoodVo foodVo=new FoodVo();
+        foodVo.setTitle(lzyType.getTitle());
+        List<LzyFood> lzyFoods = this.baseMapper.selectList(new LambdaQueryWrapper<LzyFood>().eq(LzyFood::getTypeId, selFoodDto.getId()));
+        if (lzyFoods==null){
+            return Result.ok("没有食物","没有食物");
+        }
+        List<LzyFood> collect = lzyFoods.stream().collect(Collectors.toList());
+        foodVo.setFoods(collect);
+        return Result.ok(foodVo,"查询成功");
+    }
+
+
+
+
+
+
+}
+
+
+
+

+ 59 - 0
Marketplace/src/main/java/com/dt/child/service/impl/LzyTypeServiceImpl.java

@@ -0,0 +1,59 @@
+package com.dt.child.service.impl;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.dt.child.dao.LzyType;
+import com.dt.child.service.LzyTypeService;
+import com.dt.child.mapper.LzyTypeMapper;
+import com.dt.child.vo.TypeVo;
+import com.dt.vo.Result;
+import org.springframework.stereotype.Service;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+* @author lzy
+* @description 针对表【lzy_type】的数据库操作Service实现
+* @createDate 2025-07-03 20:13:59
+*/
+@Service
+public class LzyTypeServiceImpl extends ServiceImpl<LzyTypeMapper, LzyType>
+    implements LzyTypeService{
+//  查询标题
+    @Override
+    public Result selType() {
+        List<LzyType> lzyTypes = this.baseMapper.selectList(null);
+
+        List<TypeVo> collect = new ArrayList<>();
+        for (LzyType lzyType : lzyTypes){
+            TypeVo typeVo = new TypeVo();
+            typeVo.setId(lzyType.getId());
+            typeVo.setName(lzyType.getName());
+            collect.add(typeVo);
+        }
+        return Result.ok(collect,"查询成功");
+    }
+
+
+
+//    查询食谱
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+}
+
+
+
+

+ 17 - 0
Marketplace/src/main/java/com/dt/child/vo/FoodVo.java

@@ -0,0 +1,17 @@
+package com.dt.child.vo;
+
+import com.dt.child.dao.LzyFood;
+import lombok.Data;
+
+import java.util.List;
+
+@Data
+public class FoodVo {
+
+    private String title;
+
+
+    private List<LzyFood> foods;
+
+
+}

+ 13 - 0
Marketplace/src/main/java/com/dt/child/vo/TypeVo.java

@@ -0,0 +1,13 @@
+package com.dt.child.vo;
+
+import lombok.Data;
+
+@Data
+public class TypeVo {
+
+//    id
+    private Long id;
+//    名字
+    private String name;
+
+}

+ 0 - 1
Marketplace/src/main/java/com/dt/common/domain/Child.java

@@ -52,7 +52,6 @@ public class Child {
     /**
      * 所属班级/分组ID
      */
-    @NotNull(message = "所属班级不能为空")
     private Long groupId;
 
     /**

+ 22 - 0
Marketplace/src/main/resources/mapper/LzyFoodMapper.xml

@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper
+        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.dt.child.mapper.LzyFoodMapper">
+
+    <resultMap id="BaseResultMap" type="com.dt.child.dao.LzyFood">
+            <id property="id" column="id" jdbcType="BIGINT"/>
+            <result property="name" column="name" jdbcType="VARCHAR"/>
+            <result property="img" column="img" jdbcType="VARCHAR"/>
+            <result property="title" column="title" jdbcType="VARCHAR"/>
+            <result property="previewCount" column="preview count" jdbcType="INTEGER"/>
+            <result property="saves" column="saves" jdbcType="INTEGER"/>
+            <result property="typeId" column="type_id" jdbcType="BIGINT"/>
+    </resultMap>
+
+    <sql id="Base_Column_List">
+        id,name,img,
+        title,preview count,saves,
+        type_id
+    </sql>
+</mapper>

+ 16 - 0
Marketplace/src/main/resources/mapper/LzyTypeMapper.xml

@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper
+        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.dt.child.mapper.LzyTypeMapper">
+
+    <resultMap id="BaseResultMap" type="com.dt.child.dao.LzyType">
+            <id property="id" column="id" jdbcType="BIGINT"/>
+            <result property="name" column="name" jdbcType="VARCHAR"/>
+            <result property="title" column="title" jdbcType="VARCHAR"/>
+    </resultMap>
+
+    <sql id="Base_Column_List">
+        id,name,title
+    </sql>
+</mapper>