i国网-一周菜谱
This commit is contained in:
parent
111dcfa568
commit
80886a9b69
|
|
@ -4,6 +4,7 @@ import com.bonus.common.houqin.constant.GlobalConstants;
|
||||||
|
|
||||||
import java.time.DayOfWeek;
|
import java.time.DayOfWeek;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.time.temporal.TemporalAdjusters;
|
import java.time.temporal.TemporalAdjusters;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
@ -11,6 +12,8 @@ import java.util.List;
|
||||||
|
|
||||||
public class DateUtil {
|
public class DateUtil {
|
||||||
|
|
||||||
|
static DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||||
|
|
||||||
public static List<LocalDate> getLastWeekDate() {
|
public static List<LocalDate> getLastWeekDate() {
|
||||||
List<LocalDate> objects = new ArrayList<>();
|
List<LocalDate> objects = new ArrayList<>();
|
||||||
LocalDate sunday = LocalDate.now().with(TemporalAdjusters.nextOrSame(DayOfWeek.SUNDAY));
|
LocalDate sunday = LocalDate.now().with(TemporalAdjusters.nextOrSame(DayOfWeek.SUNDAY));
|
||||||
|
|
@ -40,4 +43,29 @@ public class DateUtil {
|
||||||
return dateHashMap;
|
return dateHashMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取给定日期所在周的日期(周一到周日)
|
||||||
|
* @param date 给定的日期
|
||||||
|
* @return 包含周一到周日的日期列表
|
||||||
|
*/
|
||||||
|
public static List<LocalDate> getWeekDates(LocalDate date) {
|
||||||
|
List<LocalDate> weekDates = new ArrayList<>();
|
||||||
|
// 找到本周的周一
|
||||||
|
LocalDate monday = date.with(DayOfWeek.MONDAY);
|
||||||
|
// 添加周一到周日的日期
|
||||||
|
for (int i = 0; i < 7; i++) {
|
||||||
|
weekDates.add(monday.plusDays(i));
|
||||||
|
}
|
||||||
|
return weekDates;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
LocalDate givenDate = LocalDate.of(2025, 7, 4);
|
||||||
|
List<LocalDate> weekDates = getWeekDates(givenDate);
|
||||||
|
System.out.println(givenDate.getYear());
|
||||||
|
for (LocalDate date : weekDates) {
|
||||||
|
System.out.println(date.format(formatter) + " (" + date.getDayOfWeek() + ")");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,9 @@ import java.time.LocalDate;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class WeekRecipeDTO {
|
public class WeekRecipeDTO {
|
||||||
|
@ApiModelProperty(value = "食堂id")
|
||||||
|
private Long canteenId;
|
||||||
|
|
||||||
@ApiModelProperty(value = "菜单日期")
|
@ApiModelProperty(value = "菜单日期")
|
||||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||||
private LocalDate menuDate;
|
private LocalDate menuDate;
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,8 @@ public class WeekRecipeDetailVO {
|
||||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||||
private LocalDate menuDate;
|
private LocalDate menuDate;
|
||||||
|
|
||||||
|
private Long recipeId;
|
||||||
|
|
||||||
@ApiModelProperty(value = "餐次(早中晚)")
|
@ApiModelProperty(value = "餐次(早中晚)")
|
||||||
private int mealType;
|
private int mealType;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package com.bonus.canteen.core.zhhq.mapper;
|
package com.bonus.canteen.core.zhhq.mapper;
|
||||||
|
|
||||||
|
import com.bonus.canteen.core.zhhq.domain.WeekRecipeDetailVO;
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -12,5 +13,7 @@ import java.util.Set;
|
||||||
* @date 2025-05-25
|
* @date 2025-05-25
|
||||||
*/
|
*/
|
||||||
public interface ZhhqCookRecipeMapper {
|
public interface ZhhqCookRecipeMapper {
|
||||||
|
public List<Long> selectWeekRecipeList();
|
||||||
|
|
||||||
|
public List<WeekRecipeDetailVO> selectWeekRecipeDetail(@Param("weekDates") List<LocalDate> weekDates, @Param("recipeIds") List<Long> recipeIds);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,10 @@
|
||||||
package com.bonus.canteen.core.zhhq.service.impl;
|
package com.bonus.canteen.core.zhhq.service.impl;
|
||||||
|
|
||||||
|
import com.bonus.canteen.core.basic.domain.BasicCanteen;
|
||||||
|
import com.bonus.canteen.core.basic.mapper.BasicCanteenMapper;
|
||||||
|
import com.bonus.canteen.core.common.utils.DateUtil;
|
||||||
import com.bonus.canteen.core.zhhq.domain.WeekRecipeDTO;
|
import com.bonus.canteen.core.zhhq.domain.WeekRecipeDTO;
|
||||||
|
import com.bonus.canteen.core.zhhq.domain.WeekRecipeDetailVO;
|
||||||
import com.bonus.canteen.core.zhhq.domain.WeekRecipeVO;
|
import com.bonus.canteen.core.zhhq.domain.WeekRecipeVO;
|
||||||
import com.bonus.canteen.core.zhhq.mapper.ZhhqCookRecipeMapper;
|
import com.bonus.canteen.core.zhhq.mapper.ZhhqCookRecipeMapper;
|
||||||
import com.bonus.canteen.core.zhhq.service.IZhhqCookRecipeService;
|
import com.bonus.canteen.core.zhhq.service.IZhhqCookRecipeService;
|
||||||
|
|
@ -24,11 +28,26 @@ import java.util.stream.Collectors;
|
||||||
@Service
|
@Service
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class ZhhqCookRecipeServiceImpl implements IZhhqCookRecipeService {
|
public class ZhhqCookRecipeServiceImpl implements IZhhqCookRecipeService {
|
||||||
|
@Autowired
|
||||||
|
private BasicCanteenMapper basicCanteenMapper;
|
||||||
@Autowired
|
@Autowired
|
||||||
private ZhhqCookRecipeMapper zhhqCookRecipeMapper;
|
private ZhhqCookRecipeMapper zhhqCookRecipeMapper;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public WeekRecipeVO getWeekRecipeDetailList(WeekRecipeDTO dto) {
|
public WeekRecipeVO getWeekRecipeDetailList(WeekRecipeDTO dto) {
|
||||||
return null;
|
WeekRecipeVO weekRecipeVO = new WeekRecipeVO();
|
||||||
|
weekRecipeVO.setRecipeName("周菜谱");
|
||||||
|
BasicCanteen basicCanteen = basicCanteenMapper.selectBasicCanteenByCanteenId(dto.getCanteenId());
|
||||||
|
weekRecipeVO.setCanteenName(basicCanteen.getCanteenName());
|
||||||
|
List<LocalDate> weekDates = DateUtil.getWeekDates(dto.getMenuDate());
|
||||||
|
weekRecipeVO.setRecipeYear(dto.getMenuDate().getYear());
|
||||||
|
weekRecipeVO.setStartDate(weekDates.get(0));
|
||||||
|
weekRecipeVO.setEndDate(weekDates.get(weekDates.lastIndexOf(weekDates)));
|
||||||
|
//查询一周菜谱详情
|
||||||
|
List<Long> recipeIds = zhhqCookRecipeMapper.selectWeekRecipeList();
|
||||||
|
List<WeekRecipeDetailVO> recipeDetails = zhhqCookRecipeMapper.selectWeekRecipeDetail(weekDates, recipeIds);
|
||||||
|
//组装原料及营养信息
|
||||||
|
weekRecipeVO.setRecipeDetails(recipeDetails);
|
||||||
|
return weekRecipeVO;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,74 @@
|
||||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
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.zhhq.mapper.ZhhqCookRecipeMapper">
|
<mapper namespace="com.bonus.canteen.core.zhhq.mapper.ZhhqCookRecipeMapper">
|
||||||
|
<resultMap id="WeekRecipeDetailVO" type="com.bonus.canteen.core.zhhq.domain.WeekRecipeDetailVO">
|
||||||
|
<result property="mealType" column="mealtime_type"/>
|
||||||
|
<result property="typeName" column="type_name"/>
|
||||||
|
<result property="cookName" column="dishes_name"/>
|
||||||
|
<result property="recommendType" column="recommend_flag"/>
|
||||||
|
<result property="price" column="dishes_price"/>
|
||||||
|
<result property="cookPic" column="dishes_img_url"/>
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
|
<select id="selectWeekRecipeList" resultType="Long">
|
||||||
|
select
|
||||||
|
mr.recipe_id
|
||||||
|
from
|
||||||
|
cook_recipe_bind_app mar
|
||||||
|
left join cook_recipe mr on mar.recipe_id = mr.recipe_id
|
||||||
|
left join basic_canteen bc on bc.canteen_id = mr.canteen_id
|
||||||
|
where
|
||||||
|
bind_type = 3 and mr.canteen_id = #{canteenId}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="selectWeekRecipeDetail" resultMap="WeekRecipeDetailVO">
|
||||||
|
select
|
||||||
|
mrd.mealtime_type,
|
||||||
|
if(md.meal_type = 2, 2, mdt.dishes_type_id) as type_id,
|
||||||
|
if(md.meal_type = 2, '套餐', mdt.dishes_type_name) as type_name,
|
||||||
|
md.dishes_id as base_dishes_id,
|
||||||
|
md.dishes_id,
|
||||||
|
md.dishes_name,
|
||||||
|
md.intro,
|
||||||
|
md.image_url as dishes_img_url,
|
||||||
|
mrd.recipe_detail_id as detail_id,
|
||||||
|
m.remanent_num,
|
||||||
|
m.limit_num,
|
||||||
|
m.price as dishes_price,
|
||||||
|
m.sale_price as pref_price,
|
||||||
|
ac.canteen_id,
|
||||||
|
ac.canteen_name,
|
||||||
|
ass.stall_id,
|
||||||
|
ass.stall_name,
|
||||||
|
m.size_type,
|
||||||
|
m.recommend_flag
|
||||||
|
from
|
||||||
|
cook_recipe_detail mrd
|
||||||
|
inner join cook_recipe_dishes m on mrd.recipe_detail_id = m.recipe_detail_id
|
||||||
|
inner join cook_dishes md on m.dishes_id = md.dishes_id
|
||||||
|
inner join cook_dishes_type mdt on md.type_id = mdt.dishes_type_id
|
||||||
|
inner join cook_recipe mr on mrd.recipe_id = mr.recipe_id
|
||||||
|
left join cook_dishes_sale_record mdsr on md.dishes_id = mdsr.dishes_id
|
||||||
|
and mr.stall_id = mdsr.stall_id
|
||||||
|
and mdsr.sale_month = month(curdate())
|
||||||
|
left join basic_canteen ac on mr.canteen_id = ac.canteen_id
|
||||||
|
left join basic_stall ass on mr.stall_id = ass.stall_id
|
||||||
|
where
|
||||||
|
1 = 1
|
||||||
|
<if test="weekDates != null and weekDates.size() > 0">
|
||||||
|
and mrd.apply_date in
|
||||||
|
<foreach collection="weekDates" item="applyDate" open="(" separator="," close=")">
|
||||||
|
#{applyDate}
|
||||||
|
</foreach>
|
||||||
|
</if>
|
||||||
|
<if test="recipeIds != null and recipeIds.size() > 0">
|
||||||
|
and mrd.recipe_id in
|
||||||
|
<foreach collection="recipeIds" item="recipeId" open="(" separator="," close=")">
|
||||||
|
#{recipeId}
|
||||||
|
</foreach>
|
||||||
|
</if>
|
||||||
|
order by
|
||||||
|
md.dishes_id asc
|
||||||
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue