From 08eb63a8e80e99d086bac51d838f772fba05fc6e Mon Sep 17 00:00:00 2001 From: wangpengfei <1928057482@qq.com> Date: Wed, 31 Jan 2024 08:44:41 +0800 Subject: [PATCH] 1/31 --- .../CannotReserveDictionary.java | 26 +++++++ .../CannotReserveDictionaryDto.java | 23 ++++++ .../CannotReserveDictionaryQuery.java | 15 ++++ .../CannotReserveDictionaryVo.java | 25 +++++++ .../CannotReserveDictionaryMapper.java | 24 ++++++ .../CannotReserveDictionaryMapper.xml | 25 +++++++ .../CannotReserveDictionaryRest.java | 51 +++++++++++++ .../CannotReserveDictionaryService.java | 75 +++++++++++++++++++ .../yythmall/biz/scheduled/scheduledRest.java | 48 ++++++++++++ 9 files changed, 312 insertions(+) create mode 100644 src/main/java/com/yxt/yythmall/api/cannotreservedictionary/CannotReserveDictionary.java create mode 100644 src/main/java/com/yxt/yythmall/api/cannotreservedictionary/CannotReserveDictionaryDto.java create mode 100644 src/main/java/com/yxt/yythmall/api/cannotreservedictionary/CannotReserveDictionaryQuery.java create mode 100644 src/main/java/com/yxt/yythmall/api/cannotreservedictionary/CannotReserveDictionaryVo.java create mode 100644 src/main/java/com/yxt/yythmall/biz/cannotreservedictionary/CannotReserveDictionaryMapper.java create mode 100644 src/main/java/com/yxt/yythmall/biz/cannotreservedictionary/CannotReserveDictionaryMapper.xml create mode 100644 src/main/java/com/yxt/yythmall/biz/cannotreservedictionary/CannotReserveDictionaryRest.java create mode 100644 src/main/java/com/yxt/yythmall/biz/cannotreservedictionary/CannotReserveDictionaryService.java diff --git a/src/main/java/com/yxt/yythmall/api/cannotreservedictionary/CannotReserveDictionary.java b/src/main/java/com/yxt/yythmall/api/cannotreservedictionary/CannotReserveDictionary.java new file mode 100644 index 0000000..1419344 --- /dev/null +++ b/src/main/java/com/yxt/yythmall/api/cannotreservedictionary/CannotReserveDictionary.java @@ -0,0 +1,26 @@ +package com.yxt.yythmall.api.cannotreservedictionary; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.annotations.ApiModel; +import lombok.Data; + +import java.util.Date; +import java.util.UUID; + +/** + * @author wangpengfei + * @date 2023/11/21 15:06 + */ +@ApiModel(value = "不能预约时间字典", description = "不能预约时间字典") +@TableName("cannot_reserve_dictionary") +@Data +public class CannotReserveDictionary { + private String id; + private String sid = UUID.randomUUID().toString(); + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + private Date createTime; + private String remarks; + private String unavailableTime; + +} diff --git a/src/main/java/com/yxt/yythmall/api/cannotreservedictionary/CannotReserveDictionaryDto.java b/src/main/java/com/yxt/yythmall/api/cannotreservedictionary/CannotReserveDictionaryDto.java new file mode 100644 index 0000000..455a8e9 --- /dev/null +++ b/src/main/java/com/yxt/yythmall/api/cannotreservedictionary/CannotReserveDictionaryDto.java @@ -0,0 +1,23 @@ +package com.yxt.yythmall.api.cannotreservedictionary; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.yxt.common.core.dto.Dto; +import io.swagger.annotations.ApiModel; +import lombok.Data; + +import java.util.Date; + +/** + * @author wangpengfei + * @date 2023/11/21 15:13 + */ +@ApiModel(value = "不能预约时间字典 数据传输对象", description = "不能预约时间字典 数据传输对象") +@Data +public class CannotReserveDictionaryDto implements Dto { + private String id; + private String sid ; + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + private Date createTime; + private String remarks; + private String unavailableTime; +} diff --git a/src/main/java/com/yxt/yythmall/api/cannotreservedictionary/CannotReserveDictionaryQuery.java b/src/main/java/com/yxt/yythmall/api/cannotreservedictionary/CannotReserveDictionaryQuery.java new file mode 100644 index 0000000..6d87331 --- /dev/null +++ b/src/main/java/com/yxt/yythmall/api/cannotreservedictionary/CannotReserveDictionaryQuery.java @@ -0,0 +1,15 @@ +package com.yxt.yythmall.api.cannotreservedictionary; + +import com.yxt.common.core.query.Query; +import io.swagger.annotations.ApiModel; +import lombok.Data; + +/** + * @author wangpengfei + * @date 2023/11/21 15:31 + */ +@ApiModel(value = "不能预约时间字典 查询条件", description = "不能预约时间字典 查询条件") +@Data +public class CannotReserveDictionaryQuery implements Query { + +} diff --git a/src/main/java/com/yxt/yythmall/api/cannotreservedictionary/CannotReserveDictionaryVo.java b/src/main/java/com/yxt/yythmall/api/cannotreservedictionary/CannotReserveDictionaryVo.java new file mode 100644 index 0000000..cf4f26b --- /dev/null +++ b/src/main/java/com/yxt/yythmall/api/cannotreservedictionary/CannotReserveDictionaryVo.java @@ -0,0 +1,25 @@ +package com.yxt.yythmall.api.cannotreservedictionary; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.yxt.common.core.vo.Vo; +import io.swagger.annotations.ApiModel; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.Date; + +/** + * @author wangpengfei + * @date 2023/11/21 15:12 + */ +@Data +@ApiModel(value = "不能预约时间字典 视图数据对象", description = "不能预约时间字典 视图数据对象") +@NoArgsConstructor +public class CannotReserveDictionaryVo implements Vo { + private String id; + private String sid ; + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + private Date createTime; + private String remarks; + private String unavailableTime; +} diff --git a/src/main/java/com/yxt/yythmall/biz/cannotreservedictionary/CannotReserveDictionaryMapper.java b/src/main/java/com/yxt/yythmall/biz/cannotreservedictionary/CannotReserveDictionaryMapper.java new file mode 100644 index 0000000..56e1f33 --- /dev/null +++ b/src/main/java/com/yxt/yythmall/biz/cannotreservedictionary/CannotReserveDictionaryMapper.java @@ -0,0 +1,24 @@ +package com.yxt.yythmall.biz.cannotreservedictionary; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.core.toolkit.Constants; +import com.yxt.yythmall.api.cannotreservedictionary.CannotReserveDictionary; +import com.yxt.yythmall.api.cannotreservedictionary.CannotReserveDictionaryVo; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * @author wangpengfei + * @date 2023/11/23 10:36 + */ +@Mapper +public interface CannotReserveDictionaryMapper extends BaseMapper { + + IPage pageList(IPage page, @Param(Constants.WRAPPER) QueryWrapper qw); + + List getNotices (@Param("now") String now); +} diff --git a/src/main/java/com/yxt/yythmall/biz/cannotreservedictionary/CannotReserveDictionaryMapper.xml b/src/main/java/com/yxt/yythmall/biz/cannotreservedictionary/CannotReserveDictionaryMapper.xml new file mode 100644 index 0000000..65b308b --- /dev/null +++ b/src/main/java/com/yxt/yythmall/biz/cannotreservedictionary/CannotReserveDictionaryMapper.xml @@ -0,0 +1,25 @@ + + + + + + + + + \ No newline at end of file diff --git a/src/main/java/com/yxt/yythmall/biz/cannotreservedictionary/CannotReserveDictionaryRest.java b/src/main/java/com/yxt/yythmall/biz/cannotreservedictionary/CannotReserveDictionaryRest.java new file mode 100644 index 0000000..e3ddaf8 --- /dev/null +++ b/src/main/java/com/yxt/yythmall/biz/cannotreservedictionary/CannotReserveDictionaryRest.java @@ -0,0 +1,51 @@ +package com.yxt.yythmall.biz.cannotreservedictionary; + +import com.yxt.common.core.query.PagerQuery; +import com.yxt.common.core.result.ResultBean; +import com.yxt.common.core.vo.PagerVo; +import com.yxt.yythmall.api.cannotreservedictionary.CannotReserveDictionaryDto; +import com.yxt.yythmall.api.cannotreservedictionary.CannotReserveDictionaryQuery; +import com.yxt.yythmall.api.cannotreservedictionary.CannotReserveDictionaryVo; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +/** + * @author wangpengfei + * @date 2023/11/23 10:35 + */ +@Api(tags = "公告记录表") +@RestController +@RequestMapping("CannotReserveDictionary") +public class CannotReserveDictionaryRest { + @Autowired + CannotReserveDictionaryService NoticeService; + + + @ApiOperation("分页列表") + @PostMapping("/pageList") + public ResultBean> pageList(@RequestBody PagerQuery pq){ + return NoticeService.pageList(pq); + } + @ApiOperation("修改或保存") + @PostMapping("/saveOrUpdate") + public ResultBean saveOrUpdate(@RequestBody CannotReserveDictionaryDto dto){ + return NoticeService.saveOrUpdate(dto); + } + @ApiOperation("初始化") + @GetMapping("/noticeInit/{sid}") + public ResultBean noticeInit(@PathVariable("sid")String sid){ + return NoticeService.noticeInit(sid); + } + @ApiOperation("是否显示") + @GetMapping("/isDisplayed/{sid}/{state}") + public ResultBean isDisplayed(@PathVariable("sid")String sid,@PathVariable("state")String state){ + return NoticeService.isDisplayed(sid,state); + } + @ApiOperation("是否显示") + @GetMapping("/getNotice") + public ResultBean getNotice(){ + return NoticeService.getNotice(); + } +} diff --git a/src/main/java/com/yxt/yythmall/biz/cannotreservedictionary/CannotReserveDictionaryService.java b/src/main/java/com/yxt/yythmall/biz/cannotreservedictionary/CannotReserveDictionaryService.java new file mode 100644 index 0000000..9a58420 --- /dev/null +++ b/src/main/java/com/yxt/yythmall/biz/cannotreservedictionary/CannotReserveDictionaryService.java @@ -0,0 +1,75 @@ +package com.yxt.yythmall.biz.cannotreservedictionary; + +import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.date.DateTime; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.yxt.common.base.service.MybatisBaseService; +import com.yxt.common.base.utils.PagerUtil; +import com.yxt.common.base.utils.StringUtils; +import com.yxt.common.core.query.PagerQuery; +import com.yxt.common.core.result.ResultBean; +import com.yxt.common.core.vo.PagerVo; +import com.yxt.yythmall.api.cannotreservedictionary.CannotReserveDictionary; +import com.yxt.yythmall.api.cannotreservedictionary.CannotReserveDictionaryDto; +import com.yxt.yythmall.api.cannotreservedictionary.CannotReserveDictionaryQuery; +import com.yxt.yythmall.api.cannotreservedictionary.CannotReserveDictionaryVo; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.List; + +/** + * @author wangpengfei + * @date 2023/11/23 10:36 + */ +@Service +public class CannotReserveDictionaryService extends MybatisBaseService { + + public ResultBean> pageList(PagerQuery pq) { + ResultBean rb = new ResultBean(); + CannotReserveDictionaryQuery query = pq.getParams(); + IPage page = PagerUtil.queryToPage(pq); + QueryWrapper qw = new QueryWrapper<>(); + IPage pagging = baseMapper.pageList(page, qw); + PagerVo p = PagerUtil.pageToVo(pagging, null); + return rb.success().setData(p); + } + @Transactional(rollbackFor = Exception.class) + public ResultBean saveOrUpdate(CannotReserveDictionaryDto dto) { + ResultBean rb = ResultBean.fireFail(); + if (StringUtils.isNotBlank(dto.getSid())) { + CannotReserveDictionary notice = fetchBySid(dto.getSid()); + BeanUtil.copyProperties(dto, notice, "id", "sid"); + notice.setCreateTime(new DateTime()); + baseMapper.updateById(notice); + } else { + CannotReserveDictionary notice = new CannotReserveDictionary(); + BeanUtil.copyProperties(dto, notice, "id", "sid"); + notice.setCreateTime(new DateTime()); + baseMapper.insert(notice); + } + return rb.success().setData("成功"); + } + + public ResultBean noticeInit(String sid) { + ResultBean rb = ResultBean.fireFail(); + CannotReserveDictionary entity = fetchBySid(sid); + return rb.success().setData(entity); + } + public ResultBean isDisplayed(String sid,String state) { + ResultBean rb = ResultBean.fireFail(); + CannotReserveDictionary entity = fetchBySid(sid); + baseMapper.updateById(entity); + return rb.success().setData("成功"); + } + public ResultBean getNotice() { + ResultBean rb = ResultBean.fireFail(); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + List noticeVos= baseMapper.getNotices(sdf.format(new Date())); + return rb.success().setData(noticeVos); + } + +} diff --git a/src/main/java/com/yxt/yythmall/biz/scheduled/scheduledRest.java b/src/main/java/com/yxt/yythmall/biz/scheduled/scheduledRest.java index 79f86bd..8f9e015 100644 --- a/src/main/java/com/yxt/yythmall/biz/scheduled/scheduledRest.java +++ b/src/main/java/com/yxt/yythmall/biz/scheduled/scheduledRest.java @@ -2,6 +2,9 @@ package com.yxt.yythmall.biz.scheduled; import cn.hutool.core.date.DateUtil; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; +import com.yxt.yythmall.api.cannotreservedictionary.CannotReserveDictionary; +import com.yxt.yythmall.api.cannotreservedictionary.CannotReserveDictionaryDto; import com.yxt.yythmall.api.empcard.EmpCard; import com.yxt.yythmall.api.empcardgift.EmpCardGift; import com.yxt.yythmall.api.empcardgift.EmpCardGiftVo; @@ -10,6 +13,7 @@ import com.yxt.yythmall.api.lpkgiftcard.LpkGiftCard; import com.yxt.yythmall.api.lpkreserveorder.LpkReserveOrderVo; import com.yxt.yythmall.api.vegecallerreservedetails.VegeCellarReserveDetails; import com.yxt.yythmall.api.vegecallerreserveorder.VegeCellarReserveOrder; +import com.yxt.yythmall.biz.cannotreservedictionary.CannotReserveDictionaryService; import com.yxt.yythmall.biz.empcard.EmpCardMapper; import com.yxt.yythmall.biz.empcardgift.EmpCardGiftMapper; import com.yxt.yythmall.biz.lpkgiftbag.LpkGiftBagService; @@ -22,9 +26,14 @@ import org.springframework.scheduling.annotation.Scheduled; import org.springframework.web.bind.annotation.RestController; import java.text.SimpleDateFormat; +import java.time.DayOfWeek; +import java.time.LocalDate; +import java.time.Period; import java.util.ArrayList; +import java.util.Comparator; import java.util.Date; import java.util.List; +import java.util.stream.Collectors; /** * @author wangpengfei @@ -46,6 +55,9 @@ public class scheduledRest { VegeCellarReserveOrderService vegeCellarReserveOrderService; @Autowired VegeCellarReserveDetailsService vegeCellarReserveDetailsService; + @Autowired + CannotReserveDictionaryService cannotReserveDictionaryService; + @Scheduled(cron = "0 0 1 * * ? ") // @Scheduled(cron = "0 * * * * ? ") public void updateIsItInvalid() { @@ -202,4 +214,40 @@ public class scheduledRest { } vegeCellarReserveOrderService.updateBatchById(vegeCellarReserveOrders); } + @Scheduled(cron = "0 0 0 1 1 ? ") +// @Scheduled(cron = "0 * * * * ? ") + public void cannotReserve(){ + Date date =new Date(); + SimpleDateFormat sdf1 =new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + String nowDate =sdf1.format(date); + String endDate= sdf1.format(DateUtil.offsetMonth(date,12)); + LocalDate now = DateUtil.parse(nowDate).toSqlDate().toLocalDate(); + LocalDate endD = DateUtil.parse(endDate).toSqlDate().toLocalDate(); + List reserveDictionaries=new ArrayList<>(); + // 第一个星期六 + LocalDate saturday = now.with(DayOfWeek.SATURDAY); + do { + CannotReserveDictionary e=new CannotReserveDictionary(); + e.setUnavailableTime(saturday.toString()); + reserveDictionaries.add(e); + // 迭代一个星期 + saturday = saturday.plus(Period.ofDays(7)); + } while (saturday.compareTo(endD) < 1); + // 第一个星期天 + LocalDate sunday = now.with(DayOfWeek.SUNDAY); + do { + CannotReserveDictionary e=new CannotReserveDictionary(); + e.setUnavailableTime(sunday.toString()); + reserveDictionaries.add(e); + // 迭代一个星期 + sunday = sunday.plus(Period.ofDays(7)); + } while (sunday.compareTo(endD) < 1); + String nextYear = DateUtil.offsetMonth(new Date(), 12).toString(); + int y = DateUtil.year(DateUtil.parse(nextYear)); + CannotReserveDictionary e=new CannotReserveDictionary(); + e.setUnavailableTime(String.valueOf(y) + "-01-01"); + reserveDictionaries.add(e); + reserveDictionaries = reserveDictionaries.stream().sorted(Comparator.comparing(CannotReserveDictionary::getUnavailableTime)).collect(Collectors.toList()); + cannotReserveDictionaryService.saveBatch(reserveDictionaries); + } }