feat:搭建工程
This commit is contained in:
13
src/main/java/com/cxx/food/FoodHubServiceApplication.java
Normal file
13
src/main/java/com/cxx/food/FoodHubServiceApplication.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package com.cxx.food;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class FoodHubServiceApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(FoodHubServiceApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
100
src/main/java/com/cxx/food/controller/FoodController.java
Normal file
100
src/main/java/com/cxx/food/controller/FoodController.java
Normal file
@@ -0,0 +1,100 @@
|
||||
package com.cxx.food.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.cxx.food.dto.*;
|
||||
import com.cxx.food.service.FoodService;
|
||||
import com.cxx.food.vo.FoodQueryVo;
|
||||
import com.fasterxml.jackson.annotation.JsonView;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/food")
|
||||
@Tag(name = "美食记录")
|
||||
public class FoodController {
|
||||
@Resource
|
||||
private FoodService foodService;
|
||||
|
||||
@Operation(summary = "新增美食菜谱")
|
||||
@PostMapping("/recipe")
|
||||
public Boolean addFoodRecipe(@RequestBody @JsonView(WriteView.class) @Validated FoodRecipeDto foodRecipeDto) {
|
||||
return foodService.addFoodRecipe(foodRecipeDto);
|
||||
}
|
||||
|
||||
@Operation(summary = "更新美食菜谱")
|
||||
@PutMapping("/recipe/{id}")
|
||||
public Boolean updateFoodRecipe(@PathVariable("id") long id,
|
||||
@RequestBody @JsonView(WriteView.class) FoodRecipeDto foodRecipeDto) {
|
||||
return foodService.updateFoodRecipe(id, foodRecipeDto);
|
||||
}
|
||||
|
||||
@Operation(summary = "删除美食菜谱")
|
||||
@DeleteMapping("/recipe/{id}")
|
||||
public Boolean deleteFoodRecipe(@PathVariable("id") long id) {
|
||||
return foodService.deleteFoodRecipe(id);
|
||||
}
|
||||
|
||||
@Operation(summary = "分页查询美食菜谱")
|
||||
@GetMapping("/recipe/page")
|
||||
public IPage<FoodSummaryDto> queryFoodSummary(@RequestParam("currentPage") Integer currentPage,
|
||||
@RequestParam("pageSize") Integer pageSize,
|
||||
FoodQueryVo foodQueryVo) {
|
||||
return foodService.queryFoodSummary(currentPage, pageSize, foodQueryVo);
|
||||
}
|
||||
|
||||
@Operation(summary = "查询美食")
|
||||
@GetMapping("/recipe/{id}")
|
||||
public @JsonView(ReadView.class) FoodRecipeDto queryFoodRecipe(@PathVariable("id") long id) {
|
||||
return foodService.queryFoodRecipe(id);
|
||||
}
|
||||
|
||||
@Operation(summary = "查询所有美食名称")
|
||||
@GetMapping("/recipe/name")
|
||||
public List<String> queryFoodName() {
|
||||
return foodService.queryFoodName();
|
||||
}
|
||||
|
||||
@Operation(summary = "新增美食成果")
|
||||
@PostMapping("/record")
|
||||
public Boolean addFoodRecord(@RequestBody @JsonView(WriteView.class) @Validated FoodRecordDto foodRecordDto) {
|
||||
return foodService.addFoodRecord(foodRecordDto);
|
||||
}
|
||||
|
||||
@Operation(summary = "更新美食成果")
|
||||
@PutMapping("/record/{id}")
|
||||
public Boolean updateFoodRecord(@PathVariable("id") long id,
|
||||
@RequestBody @JsonView(WriteView.class) FoodRecordDto foodRecordDto) {
|
||||
return foodService.updateFoodRecord(id, foodRecordDto);
|
||||
}
|
||||
|
||||
@Operation(summary = "删除美食成果")
|
||||
@DeleteMapping("/record/{id}")
|
||||
public Boolean deleteFoodRecord(@PathVariable("id") long id) {
|
||||
return foodService.deleteFoodRecord(id);
|
||||
}
|
||||
|
||||
@Operation(summary = "查询美食记录")
|
||||
@GetMapping("/record")
|
||||
public @JsonView(ReadView.class) List<FoodRecordDto> queryFoodRecord(@RequestParam("startDate") String startDate,
|
||||
@RequestParam("endDate") String endDate) {
|
||||
return foodService.queryFoodRecord(startDate, endDate);
|
||||
}
|
||||
|
||||
@Operation(summary = "查询美食类别")
|
||||
@GetMapping("/category")
|
||||
public List<String> queryFoodCategory() {
|
||||
return foodService.queryFoodCategory();
|
||||
}
|
||||
|
||||
@Operation(summary = "查询美食统计")
|
||||
@GetMapping("/stats")
|
||||
public FoodStatsDto queryFoodStats() {
|
||||
return foodService.queryFoodStats();
|
||||
}
|
||||
}
|
||||
|
||||
28
src/main/java/com/cxx/food/controller/SessionController.java
Normal file
28
src/main/java/com/cxx/food/controller/SessionController.java
Normal file
@@ -0,0 +1,28 @@
|
||||
package com.cxx.food.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaIgnore;
|
||||
import com.cxx.food.dto.SessionDto;
|
||||
import com.cxx.food.service.SessionService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/session")
|
||||
@Tag(name = "会话管理")
|
||||
public class SessionController {
|
||||
@Resource
|
||||
private SessionService sessionService;
|
||||
|
||||
@Operation(summary = "创建会话")
|
||||
@PostMapping("")
|
||||
@SaIgnore
|
||||
public SessionDto createSession(@RequestParam("name") String name,
|
||||
@RequestParam("password") String password) {
|
||||
return sessionService.create(name, password);
|
||||
}
|
||||
}
|
||||
33
src/main/java/com/cxx/food/dao/FoodDao.java
Normal file
33
src/main/java/com/cxx/food/dao/FoodDao.java
Normal file
@@ -0,0 +1,33 @@
|
||||
package com.cxx.food.dao;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.cxx.food.dto.*;
|
||||
import com.cxx.food.vo.FoodQueryVo;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface FoodDao {
|
||||
FoodRecipeDto queryFoodRecipe(@Param("id") Long id);
|
||||
|
||||
IPage<FoodSummaryDto> queryFoodSummary(IPage<FoodSummaryDto> page,
|
||||
@Param("query") FoodQueryVo foodQueryVo);
|
||||
|
||||
List<FoodRecordDto> queryFoodRecordById(@Param("id") Long id);
|
||||
|
||||
List<FoodRecordDto> queryFoodRecord(@Param("startDate") String startDate,
|
||||
@Param("endDate") String endDate);
|
||||
|
||||
FoodStatsDto queryFoodStats();
|
||||
|
||||
List<String> queryFoodCategory();
|
||||
|
||||
void insertFoodMaterial(@Param("foodId") Long foodId,
|
||||
@Param("list") List<FoodMaterialDto> list);
|
||||
|
||||
void insertFoodStep(@Param("foodId") Long foodId,
|
||||
@Param("list") List<FoodStepDto> list);
|
||||
|
||||
}
|
||||
23
src/main/java/com/cxx/food/dto/FoodMaterialDto.java
Normal file
23
src/main/java/com/cxx/food/dto/FoodMaterialDto.java
Normal file
@@ -0,0 +1,23 @@
|
||||
package com.cxx.food.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonView;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@JsonView(PlainView.class)
|
||||
public class FoodMaterialDto {
|
||||
@Schema(description = "id")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "食材类型")
|
||||
private String type;
|
||||
|
||||
@Schema(description = "食材名称")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "食材分量")
|
||||
private String amount;
|
||||
}
|
||||
43
src/main/java/com/cxx/food/dto/FoodRecipeDto.java
Normal file
43
src/main/java/com/cxx/food/dto/FoodRecipeDto.java
Normal file
@@ -0,0 +1,43 @@
|
||||
package com.cxx.food.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonView;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.hibernate.validator.constraints.Range;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@JsonView(PlainView.class)
|
||||
public class FoodRecipeDto {
|
||||
@Schema(description = "id")
|
||||
@JsonView(ReadView.class)
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "美食名称")
|
||||
@NotBlank(message = "名称不能为空")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "美食菜系")
|
||||
private String category;
|
||||
|
||||
@Schema(description = "推荐指数")
|
||||
@Range(min = 0, max = 5, message = "推荐指数在0-5之间")
|
||||
private Integer recommendRate;
|
||||
|
||||
@Schema(description = "美食食材")
|
||||
private List<FoodMaterialDto> materialList;
|
||||
|
||||
@Schema(description = "美食步骤")
|
||||
private List<FoodStepDto> stepList;
|
||||
|
||||
@Schema(description = "美食成果")
|
||||
@JsonView(ReadView.class)
|
||||
private List<FoodRecordDto> recordList;
|
||||
|
||||
@Schema(description = "备注")
|
||||
private String remark;
|
||||
}
|
||||
32
src/main/java/com/cxx/food/dto/FoodRecordDto.java
Normal file
32
src/main/java/com/cxx/food/dto/FoodRecordDto.java
Normal file
@@ -0,0 +1,32 @@
|
||||
package com.cxx.food.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.fasterxml.jackson.annotation.JsonView;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@JsonView(PlainView.class)
|
||||
public class FoodRecordDto {
|
||||
@Schema(description = "id")
|
||||
@JsonView(ReadView.class)
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "名称")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "分类")
|
||||
@JsonView(ReadView.class)
|
||||
private String category;
|
||||
|
||||
@Schema(description = "完成时间")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
|
||||
private Date date;
|
||||
|
||||
@Schema(description = "成果图片")
|
||||
private String imageUrl;
|
||||
}
|
||||
19
src/main/java/com/cxx/food/dto/FoodStatsDto.java
Normal file
19
src/main/java/com/cxx/food/dto/FoodStatsDto.java
Normal file
@@ -0,0 +1,19 @@
|
||||
package com.cxx.food.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class FoodStatsDto {
|
||||
@Schema(description = "菜谱总数")
|
||||
private Integer recipeCount;
|
||||
|
||||
@Schema(description = "菜谱类别")
|
||||
private Integer categoryCount;
|
||||
|
||||
@Schema(description = "做菜次数")
|
||||
private Integer workCount;
|
||||
}
|
||||
23
src/main/java/com/cxx/food/dto/FoodStepDto.java
Normal file
23
src/main/java/com/cxx/food/dto/FoodStepDto.java
Normal file
@@ -0,0 +1,23 @@
|
||||
package com.cxx.food.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonView;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@JsonView(PlainView.class)
|
||||
public class FoodStepDto {
|
||||
@Schema(description = "id")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "顺序")
|
||||
private Integer sort;
|
||||
|
||||
@Schema(description = "步骤内容")
|
||||
private String content;
|
||||
|
||||
@Schema(description = "步骤图片")
|
||||
private String imageUrl;
|
||||
}
|
||||
26
src/main/java/com/cxx/food/dto/FoodSummaryDto.java
Normal file
26
src/main/java/com/cxx/food/dto/FoodSummaryDto.java
Normal file
@@ -0,0 +1,26 @@
|
||||
package com.cxx.food.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class FoodSummaryDto {
|
||||
@Schema(description = "id")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "美食名称")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "美食类型")
|
||||
private String category;
|
||||
|
||||
@Schema(description = "推荐指数")
|
||||
private Integer recommendRate;
|
||||
|
||||
@Schema(description = "美食记录")
|
||||
private List<FoodRecordDto> recordList;
|
||||
}
|
||||
4
src/main/java/com/cxx/food/dto/PlainView.java
Normal file
4
src/main/java/com/cxx/food/dto/PlainView.java
Normal file
@@ -0,0 +1,4 @@
|
||||
package com.cxx.food.dto;
|
||||
|
||||
public interface PlainView {
|
||||
}
|
||||
4
src/main/java/com/cxx/food/dto/ReadView.java
Normal file
4
src/main/java/com/cxx/food/dto/ReadView.java
Normal file
@@ -0,0 +1,4 @@
|
||||
package com.cxx.food.dto;
|
||||
|
||||
public interface ReadView extends PlainView {
|
||||
}
|
||||
14
src/main/java/com/cxx/food/dto/SessionDto.java
Normal file
14
src/main/java/com/cxx/food/dto/SessionDto.java
Normal file
@@ -0,0 +1,14 @@
|
||||
package com.cxx.food.dto;
|
||||
|
||||
import cn.dev33.satoken.stp.SaTokenInfo;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class SessionDto {
|
||||
@Schema(description = "令牌")
|
||||
private SaTokenInfo saToken;
|
||||
}
|
||||
|
||||
4
src/main/java/com/cxx/food/dto/WriteView.java
Normal file
4
src/main/java/com/cxx/food/dto/WriteView.java
Normal file
@@ -0,0 +1,4 @@
|
||||
package com.cxx.food.dto;
|
||||
|
||||
public interface WriteView extends PlainView {
|
||||
}
|
||||
24
src/main/java/com/cxx/food/entity/FoodMaterial.java
Normal file
24
src/main/java/com/cxx/food/entity/FoodMaterial.java
Normal file
@@ -0,0 +1,24 @@
|
||||
package com.cxx.food.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.cxx.framework.data.AbstractIdEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("food_material")
|
||||
public class FoodMaterial extends AbstractIdEntity {
|
||||
@TableField("food_id")
|
||||
private Long foodId;
|
||||
|
||||
@TableField("type")
|
||||
private String type;
|
||||
|
||||
@TableField("name")
|
||||
private String name;
|
||||
|
||||
@TableField("amount")
|
||||
private String amount;
|
||||
}
|
||||
24
src/main/java/com/cxx/food/entity/FoodRecipe.java
Normal file
24
src/main/java/com/cxx/food/entity/FoodRecipe.java
Normal file
@@ -0,0 +1,24 @@
|
||||
package com.cxx.food.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.cxx.framework.data.AbstractEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("food_recipe")
|
||||
public class FoodRecipe extends AbstractEntity {
|
||||
@TableField("name")
|
||||
private String name;
|
||||
|
||||
@TableField("category")
|
||||
private String category;
|
||||
|
||||
@TableField("recommend_rate")
|
||||
private Integer recommendRate;
|
||||
|
||||
@TableField("remark")
|
||||
private String remark;
|
||||
}
|
||||
23
src/main/java/com/cxx/food/entity/FoodRecord.java
Normal file
23
src/main/java/com/cxx/food/entity/FoodRecord.java
Normal file
@@ -0,0 +1,23 @@
|
||||
package com.cxx.food.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.cxx.framework.data.AbstractIdEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("food_record")
|
||||
public class FoodRecord extends AbstractIdEntity {
|
||||
@TableField("food_id")
|
||||
private Long foodId;
|
||||
|
||||
@TableField("date")
|
||||
private Date date;
|
||||
|
||||
@TableField("image_url")
|
||||
private String imageUrl;
|
||||
}
|
||||
24
src/main/java/com/cxx/food/entity/FoodStep.java
Normal file
24
src/main/java/com/cxx/food/entity/FoodStep.java
Normal file
@@ -0,0 +1,24 @@
|
||||
package com.cxx.food.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.cxx.framework.data.AbstractIdEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("food_step")
|
||||
public class FoodStep extends AbstractIdEntity {
|
||||
@TableField("food_id")
|
||||
private Long foodId;
|
||||
|
||||
@TableField("sort")
|
||||
private Integer sort;
|
||||
|
||||
@TableField("content")
|
||||
private String content;
|
||||
|
||||
@TableField("image_url")
|
||||
private String imageUrl;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.cxx.food.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.cxx.food.entity.FoodMaterial;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface FoodMaterialMapper extends BaseMapper<FoodMaterial> {
|
||||
}
|
||||
9
src/main/java/com/cxx/food/mapper/FoodRecipeMapper.java
Normal file
9
src/main/java/com/cxx/food/mapper/FoodRecipeMapper.java
Normal file
@@ -0,0 +1,9 @@
|
||||
package com.cxx.food.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.cxx.food.entity.FoodRecipe;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface FoodRecipeMapper extends BaseMapper<FoodRecipe> {
|
||||
}
|
||||
9
src/main/java/com/cxx/food/mapper/FoodRecordMapper.java
Normal file
9
src/main/java/com/cxx/food/mapper/FoodRecordMapper.java
Normal file
@@ -0,0 +1,9 @@
|
||||
package com.cxx.food.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.cxx.food.entity.FoodRecord;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface FoodRecordMapper extends BaseMapper<FoodRecord> {
|
||||
}
|
||||
9
src/main/java/com/cxx/food/mapper/FoodStepMapper.java
Normal file
9
src/main/java/com/cxx/food/mapper/FoodStepMapper.java
Normal file
@@ -0,0 +1,9 @@
|
||||
package com.cxx.food.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.cxx.food.entity.FoodStep;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface FoodStepMapper extends BaseMapper<FoodStep> {
|
||||
}
|
||||
37
src/main/java/com/cxx/food/service/FoodService.java
Normal file
37
src/main/java/com/cxx/food/service/FoodService.java
Normal file
@@ -0,0 +1,37 @@
|
||||
package com.cxx.food.service;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.cxx.food.dto.FoodRecipeDto;
|
||||
import com.cxx.food.dto.FoodRecordDto;
|
||||
import com.cxx.food.dto.FoodStatsDto;
|
||||
import com.cxx.food.dto.FoodSummaryDto;
|
||||
import com.cxx.food.vo.FoodQueryVo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface FoodService {
|
||||
Boolean addFoodRecipe(FoodRecipeDto foodRecipeDto);
|
||||
|
||||
Boolean updateFoodRecipe(Long id, FoodRecipeDto foodRecipeDto);
|
||||
|
||||
Boolean deleteFoodRecipe(Long id);
|
||||
|
||||
Boolean addFoodRecord(FoodRecordDto foodRecordDto);
|
||||
|
||||
Boolean updateFoodRecord(Long id, FoodRecordDto foodRecordDto);
|
||||
|
||||
Boolean deleteFoodRecord(Long id);
|
||||
|
||||
FoodRecipeDto queryFoodRecipe(Long id);
|
||||
|
||||
IPage<FoodSummaryDto> queryFoodSummary(Integer currentPage, Integer pageSize, FoodQueryVo foodQueryVo);
|
||||
|
||||
List<FoodRecordDto> queryFoodRecord(String startDate, String endDate);
|
||||
|
||||
List<String> queryFoodName();
|
||||
|
||||
List<String> queryFoodCategory();
|
||||
|
||||
FoodStatsDto queryFoodStats();
|
||||
}
|
||||
8
src/main/java/com/cxx/food/service/SessionService.java
Normal file
8
src/main/java/com/cxx/food/service/SessionService.java
Normal file
@@ -0,0 +1,8 @@
|
||||
package com.cxx.food.service;
|
||||
|
||||
|
||||
import com.cxx.food.dto.SessionDto;
|
||||
|
||||
public interface SessionService {
|
||||
SessionDto create(String name, String password);
|
||||
}
|
||||
200
src/main/java/com/cxx/food/service/impl/FoodServiceImpl.java
Normal file
200
src/main/java/com/cxx/food/service/impl/FoodServiceImpl.java
Normal file
@@ -0,0 +1,200 @@
|
||||
package com.cxx.food.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.cxx.food.dao.FoodDao;
|
||||
import com.cxx.food.dto.*;
|
||||
import com.cxx.food.entity.FoodMaterial;
|
||||
import com.cxx.food.entity.FoodRecipe;
|
||||
import com.cxx.food.entity.FoodRecord;
|
||||
import com.cxx.food.entity.FoodStep;
|
||||
import com.cxx.food.mapper.FoodMaterialMapper;
|
||||
import com.cxx.food.mapper.FoodRecipeMapper;
|
||||
import com.cxx.food.mapper.FoodRecordMapper;
|
||||
import com.cxx.food.mapper.FoodStepMapper;
|
||||
import com.cxx.food.service.FoodService;
|
||||
import com.cxx.food.vo.FoodQueryVo;
|
||||
import com.cxx.framework.web.CustomException;
|
||||
import com.github.yitter.idgen.YitIdHelper;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class FoodServiceImpl implements FoodService {
|
||||
@Resource
|
||||
private FoodDao foodDao;
|
||||
|
||||
@Resource
|
||||
private FoodRecipeMapper foodRecipeMapper;
|
||||
|
||||
@Resource
|
||||
private FoodMaterialMapper foodMaterialMapper;
|
||||
|
||||
@Resource
|
||||
private FoodStepMapper foodStepMapper;
|
||||
|
||||
@Resource
|
||||
private FoodRecordMapper foodRecordMapper;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public Boolean addFoodRecipe(FoodRecipeDto foodRecipeDto) {
|
||||
LambdaQueryWrapper<FoodRecipe> queryWrapper = new LambdaQueryWrapper<>();
|
||||
if (foodRecipeMapper.exists(queryWrapper.eq(FoodRecipe::getName, foodRecipeDto.getName()))) {
|
||||
throw new CustomException("该菜谱已经存在");
|
||||
}
|
||||
|
||||
FoodRecipe foodRecipe = new FoodRecipe();
|
||||
BeanUtils.copyProperties(foodRecipeDto, foodRecipe);
|
||||
foodRecipeMapper.insert(foodRecipe);
|
||||
resetFoodRecipe(foodRecipe.getId(), foodRecipeDto);
|
||||
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public Boolean updateFoodRecipe(Long id, FoodRecipeDto foodRecipeDto) {
|
||||
if (foodRecipeMapper.selectById(id) == null) {
|
||||
throw new CustomException("该菜谱不存在");
|
||||
}
|
||||
|
||||
FoodRecipe foodRecipe = new FoodRecipe();
|
||||
BeanUtils.copyProperties(foodRecipeDto, foodRecipe);
|
||||
foodRecipe.setId(id);
|
||||
foodRecipeMapper.updateById(foodRecipe);
|
||||
resetFoodRecipe(foodRecipe.getId(), foodRecipeDto);
|
||||
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public Boolean deleteFoodRecipe(Long id) {
|
||||
foodRecipeMapper.deleteById(id);
|
||||
foodMaterialMapper.delete(Wrappers.lambdaQuery(FoodMaterial.class).eq(FoodMaterial::getFoodId, id));
|
||||
foodStepMapper.delete(Wrappers.lambdaQuery(FoodStep.class).eq(FoodStep::getFoodId, id));
|
||||
foodRecordMapper.delete(Wrappers.lambdaQuery(FoodRecord.class).eq(FoodRecord::getFoodId, id));
|
||||
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean addFoodRecord(FoodRecordDto foodRecordDto) {
|
||||
LambdaQueryWrapper<FoodRecipe> queryWrapper = new LambdaQueryWrapper<>();
|
||||
FoodRecipe foodRecipe = foodRecipeMapper.selectOne(queryWrapper.eq(FoodRecipe::getName, foodRecordDto.getName()));
|
||||
if (foodRecipe == null) {
|
||||
throw new CustomException("该菜谱不存在");
|
||||
}
|
||||
|
||||
FoodRecord foodRecord = new FoodRecord();
|
||||
foodRecord.setFoodId(foodRecipe.getId());
|
||||
BeanUtils.copyProperties(foodRecordDto, foodRecord);
|
||||
foodRecordMapper.insert(foodRecord);
|
||||
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean updateFoodRecord(Long id, FoodRecordDto foodRecordDto) {
|
||||
if (foodRecordMapper.selectById(id) == null) {
|
||||
throw new CustomException("该成果不存在");
|
||||
}
|
||||
|
||||
FoodRecord foodRecord = new FoodRecord();
|
||||
BeanUtils.copyProperties(foodRecordDto, foodRecord);
|
||||
foodRecord.setId(id);
|
||||
foodRecordMapper.updateById(foodRecord);
|
||||
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean deleteFoodRecord(Long id) {
|
||||
foodRecordMapper.deleteById(id);
|
||||
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
private void resetFoodRecipe(Long id, FoodRecipeDto foodRecipeDto) {
|
||||
foodMaterialMapper.delete(Wrappers.lambdaQuery(FoodMaterial.class).eq(FoodMaterial::getFoodId, id));
|
||||
foodStepMapper.delete(Wrappers.lambdaQuery(FoodStep.class).eq(FoodStep::getFoodId, id));
|
||||
|
||||
insertFoodMaterial(id, foodRecipeDto.getMaterialList());
|
||||
insertFoodStep(id, foodRecipeDto.getStepList());
|
||||
}
|
||||
|
||||
private void insertFoodMaterial(Long foodId, List<FoodMaterialDto> foodMaterialList) {
|
||||
if (foodMaterialList.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
foodMaterialList.forEach((item) -> {
|
||||
item.setId(YitIdHelper.nextId());
|
||||
});
|
||||
foodDao.insertFoodMaterial(foodId, foodMaterialList);
|
||||
}
|
||||
|
||||
private void insertFoodStep(Long foodId, List<FoodStepDto> foodStepList) {
|
||||
if (foodStepList.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
foodStepList.forEach((item) -> {
|
||||
item.setId(YitIdHelper.nextId());
|
||||
});
|
||||
foodDao.insertFoodStep(foodId, foodStepList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FoodRecipeDto queryFoodRecipe(Long id) {
|
||||
if (foodRecipeMapper.selectById(id) == null) {
|
||||
throw new CustomException("该美食不存在");
|
||||
}
|
||||
|
||||
return foodDao.queryFoodRecipe(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPage<FoodSummaryDto> queryFoodSummary(Integer currentPage, Integer pageSize, FoodQueryVo foodQueryVo) {
|
||||
// 这里只能先对主表进行分页 然后在查询子表信息
|
||||
// 不能使用Left Join关联表查询,因为这里是一对多数据,关联查询会导致数据有重复
|
||||
// 从而导致page计算错误(会把重复的数据当成多条记录,实际上只有1条记录)
|
||||
IPage<FoodSummaryDto> foodSummaryPage = foodDao.queryFoodSummary(new Page<>(currentPage, pageSize), foodQueryVo);
|
||||
List<FoodSummaryDto> foodSummaryList = foodSummaryPage.getRecords();
|
||||
for (FoodSummaryDto foodSummary : foodSummaryList) {
|
||||
foodSummary.setRecordList(foodDao.queryFoodRecordById(foodSummary.getId()));
|
||||
}
|
||||
|
||||
foodSummaryPage.setRecords(foodSummaryList);
|
||||
return foodSummaryPage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FoodRecordDto> queryFoodRecord(String startDate, String endDate) {
|
||||
return foodDao.queryFoodRecord(startDate, endDate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> queryFoodName() {
|
||||
return foodRecipeMapper.selectList(null)
|
||||
.stream().map(FoodRecipe::getName).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> queryFoodCategory() {
|
||||
return foodDao.queryFoodCategory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FoodStatsDto queryFoodStats() {
|
||||
return foodDao.queryFoodStats();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.cxx.food.service.impl;
|
||||
|
||||
|
||||
import cn.dev33.satoken.secure.BCrypt;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.cxx.food.dto.SessionDto;
|
||||
import com.cxx.food.service.SessionService;
|
||||
import com.cxx.framework.web.CustomException;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
||||
@Service
|
||||
public class SessionServiceImpl implements SessionService {
|
||||
|
||||
@Override
|
||||
public SessionDto create(String name, String password) {
|
||||
SessionDto sessionDto = new SessionDto();
|
||||
StpUtil.login(name);
|
||||
sessionDto.setSaToken(StpUtil.getTokenInfo());
|
||||
|
||||
return sessionDto;
|
||||
}
|
||||
}
|
||||
13
src/main/java/com/cxx/food/vo/FoodQueryVo.java
Normal file
13
src/main/java/com/cxx/food/vo/FoodQueryVo.java
Normal file
@@ -0,0 +1,13 @@
|
||||
|
||||
package com.cxx.food.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class FoodQueryVo {
|
||||
@Schema(description = "美食类别")
|
||||
private String category;
|
||||
}
|
||||
10
src/main/resources/application-dev.yml
Normal file
10
src/main/resources/application-dev.yml
Normal file
@@ -0,0 +1,10 @@
|
||||
spring:
|
||||
datasource:
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://127.0.0.1:3306/sweet_hut?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=UTF-8&useSSL=false
|
||||
username: cxx
|
||||
password: 123456
|
||||
|
||||
file:
|
||||
path: D:\\temp\\
|
||||
log-path: D:\\temp\\
|
||||
9
src/main/resources/application-docker.yml
Normal file
9
src/main/resources/application-docker.yml
Normal file
@@ -0,0 +1,9 @@
|
||||
spring:
|
||||
datasource:
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://mysql:3306/sweet_hut?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=UTF-8&useSSL=false
|
||||
username: docker
|
||||
password: 19940822Cxx
|
||||
|
||||
file:
|
||||
path: /upload-file/
|
||||
10
src/main/resources/application-prod.yml
Normal file
10
src/main/resources/application-prod.yml
Normal file
@@ -0,0 +1,10 @@
|
||||
spring:
|
||||
datasource:
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://127.0.0.1:3306/sweet_hut?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=UTF-8&useSSL=false
|
||||
username: cxx
|
||||
password: 19940822Cxx@1213
|
||||
|
||||
file:
|
||||
path: /root/docker/upload-file/
|
||||
log-path: /root/service/logs/
|
||||
23
src/main/resources/application.yml
Normal file
23
src/main/resources/application.yml
Normal file
@@ -0,0 +1,23 @@
|
||||
server:
|
||||
port: 8090
|
||||
|
||||
spring:
|
||||
application:
|
||||
name: @project.artifactId@
|
||||
version: @project.version@
|
||||
profiles:
|
||||
active: dev
|
||||
|
||||
# mybatis plus mapper路径
|
||||
mybatis-plus:
|
||||
# mybatis plus
|
||||
mapper-locations: classpath*:/mapper/**/*.xml
|
||||
configuration:
|
||||
log-impl:
|
||||
org.apache.ibatis.logging.stdout.StdOutImpl
|
||||
|
||||
web-starter:
|
||||
base-package: com.cxx.food
|
||||
|
||||
aes:
|
||||
secret-key: "sG5p7t9wBdKnPqRsUvYx2D5F8H9JmQ=2"
|
||||
144
src/main/resources/mapper/FoodMapper.xml
Normal file
144
src/main/resources/mapper/FoodMapper.xml
Normal file
@@ -0,0 +1,144 @@
|
||||
<?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.cxx.food.dao.FoodDao">
|
||||
<resultMap id="foodRecipeResultMap" type="com.cxx.food.dto.FoodRecipeDto">
|
||||
<id property="id" column="id"/>
|
||||
<result property="name" column="name"/>
|
||||
<result property="category" column="category"/>
|
||||
<result property="recommendRate" column="recommendRate"/>
|
||||
<result property="remark" column="remark"/>
|
||||
<collection property="materialList" ofType="com.cxx.food.dto.FoodMaterialDto"
|
||||
column="id" select="queryFoodMaterial">
|
||||
</collection>
|
||||
<collection property="stepList" ofType="com.cxx.food.dto.FoodStepDto"
|
||||
column="id" select="queryFoodStep">
|
||||
</collection>
|
||||
<collection property="recordList" ofType="com.cxx.food.dto.FoodRecordDto"
|
||||
column="id" select="queryFoodRecordById">
|
||||
</collection>
|
||||
</resultMap>
|
||||
|
||||
<resultMap id="foodMaterialResultMap" type="com.cxx.food.dto.FoodMaterialDto">
|
||||
<id property="id" column="id"/>
|
||||
<result property="type" column="type"/>
|
||||
<result property="name" column="name"/>
|
||||
<result property="amount" column="amount"/>
|
||||
</resultMap>
|
||||
|
||||
<resultMap id="foodStepResultMap" type="com.cxx.food.dto.FoodStepDto">
|
||||
<id property="id" column="id"/>
|
||||
<result property="sort" column="sort"/>
|
||||
<result property="content" column="content"/>
|
||||
<result property="imageUrl" column="imageUrl"/>
|
||||
</resultMap>
|
||||
|
||||
<resultMap id="foodRecordResultMap" type="com.cxx.food.dto.FoodRecordDto">
|
||||
<id property="id" column="id"/>
|
||||
<result property="date" column="date"/>
|
||||
<result property="imageUrl" column="imageUrl"/>
|
||||
</resultMap>
|
||||
|
||||
<resultMap id="foodSummaryResultMap" type="com.cxx.food.dto.FoodSummaryDto">
|
||||
<id property="id" column="id"/>
|
||||
<result property="name" column="name"/>
|
||||
<result property="category" column="category"/>
|
||||
<result property="recommendRate" column="recommendRate"/>
|
||||
<collection property="recordList" ofType="com.cxx.food.dto.FoodRecordDto">
|
||||
<id property="id" column="workId"/>
|
||||
<result property="date" column="recordDate"/>
|
||||
<result property="person" column="recordPerson"/>
|
||||
<result property="imageUrl" column="workImageUrl"/>
|
||||
</collection>
|
||||
</resultMap>
|
||||
|
||||
<select id="queryFoodMaterial" resultMap="foodMaterialResultMap">
|
||||
SELECT id AS id,
|
||||
type AS type,
|
||||
name AS name,
|
||||
amount AS amount
|
||||
FROM food_material
|
||||
WHERE food_id = #{id}
|
||||
</select>
|
||||
|
||||
<select id="queryFoodStep" resultMap="foodStepResultMap">
|
||||
SELECT id AS id,
|
||||
sort AS sort,
|
||||
content AS content,
|
||||
image_url AS imageUrl
|
||||
FROM food_step
|
||||
WHERE food_id = #{id}
|
||||
ORDER BY sort
|
||||
</select>
|
||||
|
||||
<select id="queryFoodRecordById" resultMap="foodRecordResultMap">
|
||||
SELECT id AS id,
|
||||
date AS date,
|
||||
image_url AS imageUrl
|
||||
FROM food_record
|
||||
WHERE food_id = #{id}
|
||||
ORDER BY date DESC
|
||||
</select>
|
||||
|
||||
<select id="queryFoodRecord" resultType="com.cxx.food.dto.FoodRecordDto">
|
||||
SELECT a.id AS id,
|
||||
b.name AS name,
|
||||
b.category AS category,
|
||||
a.date AS date,
|
||||
a.image_url AS imageUrl
|
||||
FROM food_record AS a
|
||||
LEFT JOIN food_recipe AS b ON a.food_id = b.id
|
||||
WHERE a.date <![CDATA[ >=]]> STR_TO_DATE(#{startDate}, '%Y-%m-%d')
|
||||
AND a.date <![CDATA[ <=]]> STR_TO_DATE(#{endDate}, '%Y-%m-%d')
|
||||
ORDER BY date DESC
|
||||
</select>
|
||||
|
||||
<select id="queryFoodRecipe" resultMap="foodRecipeResultMap">
|
||||
SELECT a.id AS id,
|
||||
a.name AS name,
|
||||
a.category AS category,
|
||||
a.recommend_rate AS recommendRate,
|
||||
a.remark AS remake
|
||||
FROM food_recipe a
|
||||
WHERE a.id = #{id}
|
||||
</select>
|
||||
|
||||
<select id="queryFoodSummary" resultMap="foodSummaryResultMap">
|
||||
SELECT a.id AS id,
|
||||
a.name AS name,
|
||||
a.category AS category,
|
||||
a.recommend_rate AS recommendRate
|
||||
FROM food_recipe a
|
||||
<where>
|
||||
<if test="query.category != null and query.category != ''">
|
||||
a.category = #{query.category}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="queryFoodStats" resultType="com.cxx.food.dto.FoodStatsDto">
|
||||
SELECT COUNT(DISTINCT a.name) AS recipeCount,
|
||||
COUNT(DISTINCT a.category) AS categoryCount,
|
||||
COUNT(b.id) AS workCount
|
||||
FROM food_recipe a
|
||||
LEFT JOIN food_record b ON a.id = b.food_id
|
||||
</select>
|
||||
|
||||
<select id="queryFoodCategory" resultType="string">
|
||||
SELECT DISTINCT a.category AS category
|
||||
FROM food_recipe a
|
||||
</select>
|
||||
|
||||
<insert id="insertFoodMaterial">
|
||||
INSERT INTO food_material (id, food_id, type, name, amount) VALUES
|
||||
<foreach collection="list" item="item" separator=",">
|
||||
(#{item.id}, #{foodId}, #{item.type}, #{item.name}, #{item.amount})
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
<insert id="insertFoodStep">
|
||||
INSERT INTO food_step (id, food_id, sort, content, image_url) VALUES
|
||||
<foreach collection="list" item="item" separator=",">
|
||||
(#{item.id}, #{foodId}, #{item.sort}, #{item.content}, #{item.imageUrl})
|
||||
</foreach>
|
||||
</insert>
|
||||
</mapper>
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.cxx.food;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
class FoodHubServiceApplicationTests {
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user