|
@@ -1,303 +0,0 @@
|
|
-package shop.alien.entity.device.service.impl;
|
|
|
|
-
|
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
-import com.nlf.calendar.Lunar;
|
|
|
|
-import com.nlf.calendar.Solar;
|
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
|
-import shop.alien.entity.device.entity.MsgImportantDate;
|
|
|
|
-import shop.alien.entity.device.entity.MsgImportantDateDto;
|
|
|
|
-import shop.alien.entity.device.mapper.MsgImportantDateMapper;
|
|
|
|
-import shop.alien.entity.device.service.MsgImportantDateService;
|
|
|
|
-
|
|
|
|
-import java.time.LocalDate;
|
|
|
|
-import java.time.LocalDateTime;
|
|
|
|
-import java.time.format.DateTimeFormatter;
|
|
|
|
-import java.time.temporal.ChronoUnit;
|
|
|
|
-import java.util.ArrayList;
|
|
|
|
-import java.util.Comparator;
|
|
|
|
-import java.util.List;
|
|
|
|
-
|
|
|
|
-/**
|
|
|
|
- * <p>
|
|
|
|
- * 消息重要日期提醒 服务实现类
|
|
|
|
- * </p>
|
|
|
|
- *
|
|
|
|
- * @author ssk
|
|
|
|
- * @since 2024-04-12
|
|
|
|
- */
|
|
|
|
-@Service
|
|
|
|
-public class MsgImportantDateServiceImpl extends ServiceImpl<MsgImportantDateMapper, MsgImportantDate> implements MsgImportantDateService {
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 根据用户id查询重要日期
|
|
|
|
- *
|
|
|
|
- * @param userId 用户id
|
|
|
|
- * @return List<MsgImportantDate>
|
|
|
|
- */
|
|
|
|
- @Override
|
|
|
|
- public List<MsgImportantDateDto> getDate(String userId) {
|
|
|
|
- LambdaQueryWrapper<MsgImportantDate> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
- lambdaQueryWrapper.eq(MsgImportantDate::getDeleteFlag, 0);
|
|
|
|
- lambdaQueryWrapper.in(MsgImportantDate::getUserId, userId);
|
|
|
|
- List<MsgImportantDate> list = this.list(lambdaQueryWrapper);
|
|
|
|
- List<MsgImportantDateDto> sortList = new ArrayList<>();
|
|
|
|
- //添加所有日期
|
|
|
|
- for (MsgImportantDate msgImportantDate : list) {
|
|
|
|
- MsgImportantDateDto msgImportantDateDto;
|
|
|
|
- //提醒选项(0:全部提醒,1:农历,2:新历)
|
|
|
|
- if (msgImportantDate.getRemindWith() == 0) {
|
|
|
|
- //旧日期
|
|
|
|
- MsgImportantDateDto oldDate = new MsgImportantDateDto();
|
|
|
|
- oldDate.setId(msgImportantDate.getId());
|
|
|
|
- oldDate.setDateName(msgImportantDate.getDateName() + "(农历)");
|
|
|
|
- oldDate.setOldDate(msgImportantDate.getOldDate());
|
|
|
|
- sortList.add(oldDate);
|
|
|
|
- //新日期
|
|
|
|
- MsgImportantDateDto newDate = new MsgImportantDateDto();
|
|
|
|
- newDate.setId(msgImportantDate.getId());
|
|
|
|
- newDate.setDateName(msgImportantDate.getDateName() + "(阳历)");
|
|
|
|
- newDate.setNewDate(msgImportantDate.getNewDate());
|
|
|
|
- sortList.add(newDate);
|
|
|
|
- } else if (msgImportantDate.getRemindWith() == 1) {
|
|
|
|
- msgImportantDateDto = new MsgImportantDateDto();
|
|
|
|
- msgImportantDateDto.setId(msgImportantDate.getId());
|
|
|
|
- msgImportantDateDto.setDateName(msgImportantDate.getDateName() + "(农历)");
|
|
|
|
- msgImportantDateDto.setOldDate(msgImportantDate.getOldDate());
|
|
|
|
- sortList.add(msgImportantDateDto);
|
|
|
|
- } else {
|
|
|
|
- msgImportantDateDto = new MsgImportantDateDto();
|
|
|
|
- msgImportantDateDto.setId(msgImportantDate.getId());
|
|
|
|
- msgImportantDateDto.setDateName(msgImportantDate.getDateName() + "(阳历)");
|
|
|
|
- msgImportantDateDto.setNewDate(msgImportantDate.getNewDate());
|
|
|
|
- sortList.add(msgImportantDateDto);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- String yearStr = LocalDateTime.now().toString().substring(0, 4);
|
|
|
|
- for (MsgImportantDateDto msgImportantDateDto : sortList) {
|
|
|
|
- //农历日期计算
|
|
|
|
- if (msgImportantDateDto.getDateName().contains("农历")) {
|
|
|
|
- //农历转公历
|
|
|
|
- int month = Integer.parseInt(msgImportantDateDto.getOldDate().substring(5, 7));
|
|
|
|
- int day = Integer.parseInt(msgImportantDateDto.getOldDate().substring(8, 10));
|
|
|
|
- Lunar lunar = Lunar.fromYmd(Integer.parseInt(yearStr), month, day);
|
|
|
|
- Solar solar = lunar.getSolar();
|
|
|
|
- String convertNewDate = solar.toString();//今年阳历日期(农历转)
|
|
|
|
- String date = msgImportantDateDto.getOldDate();
|
|
|
|
- String thisYearOldDate = yearStr + date.substring(4);//今年农历日期
|
|
|
|
- msgImportantDateDto.setOldDate(thisYearOldDate);
|
|
|
|
- msgImportantDateDto.setNewDate(convertNewDate);
|
|
|
|
- LocalDate thisYearNewDate = LocalDate.of(Integer.parseInt(convertNewDate.substring(0, 4)), Integer.parseInt(convertNewDate.substring(5, 7)), Integer.parseInt(convertNewDate.substring(8, 10)));
|
|
|
|
- //判断转阳历是否过去
|
|
|
|
- if (thisYearNewDate.isBefore(LocalDate.now())) {
|
|
|
|
- //今年的过完了, 计算明年的
|
|
|
|
- int nextYear = Integer.parseInt(yearStr) + 1;
|
|
|
|
- //明年农历日期
|
|
|
|
- thisYearOldDate = nextYear + date.substring(4);
|
|
|
|
- msgImportantDateDto.setOldDate(thisYearOldDate);
|
|
|
|
- Lunar newlunar = Lunar.fromYmd(Integer.parseInt(thisYearOldDate.substring(0, 4)), Integer.parseInt(thisYearOldDate.substring(5, 7)), Integer.parseInt(thisYearOldDate.substring(8, 10)));
|
|
|
|
- Solar newsolar = newlunar.getSolar();
|
|
|
|
- msgImportantDateDto.setNewDate(newsolar.toString());
|
|
|
|
- }
|
|
|
|
- //下一个农历转阳历的日期和今天的天数
|
|
|
|
- Lunar nextLunar = Lunar.fromYmd(Integer.parseInt(thisYearOldDate.substring(0, 4)), Integer.parseInt(thisYearOldDate.substring(5, 7)), Integer.parseInt(thisYearOldDate.substring(8, 10)));
|
|
|
|
- Solar nextSolar = nextLunar.getSolar();
|
|
|
|
- String nextConvertNewDate = nextSolar.toString();//下一个农历转阳历日期
|
|
|
|
- LocalDate parseDate = LocalDate.parse(nextConvertNewDate, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
|
|
|
- long between = ChronoUnit.DAYS.between(LocalDate.now(), parseDate);
|
|
|
|
- msgImportantDateDto.setRemainingDays(Integer.parseInt(String.valueOf(between)));
|
|
|
|
- } else {
|
|
|
|
- //阳历日期
|
|
|
|
- String date = msgImportantDateDto.getNewDate();
|
|
|
|
- String thisYearStr = yearStr + date.substring(4);
|
|
|
|
- msgImportantDateDto.setNewDate(thisYearStr);
|
|
|
|
- LocalDate thisYear = LocalDate.of(Integer.parseInt(yearStr), Integer.parseInt(date.substring(5, 7)), Integer.parseInt(date.substring(8, 10)));
|
|
|
|
- if (thisYear.isBefore(LocalDate.now())) {
|
|
|
|
- //今年的过完了, 计算明年的
|
|
|
|
- int nextYear = Integer.parseInt(yearStr) + 1;
|
|
|
|
- thisYearStr = nextYear + date.substring(4);
|
|
|
|
- }
|
|
|
|
- LocalDate parseDate = LocalDate.parse(thisYearStr, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
|
|
|
- long between = ChronoUnit.DAYS.between(LocalDate.now(), parseDate);
|
|
|
|
- msgImportantDateDto.setRemainingDays(Integer.parseInt(String.valueOf(between)));
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- //排序倒数日期
|
|
|
|
- sortList.sort(Comparator.comparing(MsgImportantDateDto::getRemainingDays));
|
|
|
|
- return sortList;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 获取最近三年的重要日期
|
|
|
|
- *
|
|
|
|
- * @param userId 用户id
|
|
|
|
- * @return List<MsgImportantDate>
|
|
|
|
- */
|
|
|
|
- @Override
|
|
|
|
- public List<MsgImportantDateDto> getRecentlyThreeYearsImportantDate(String userId) {
|
|
|
|
- List<MsgImportantDateDto> resultList = new ArrayList<>();
|
|
|
|
- LambdaQueryWrapper<MsgImportantDate> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
- lambdaQueryWrapper.eq(MsgImportantDate::getDeleteFlag, 0);
|
|
|
|
- lambdaQueryWrapper.eq(MsgImportantDate::getUserId, userId);
|
|
|
|
- List<MsgImportantDate> importantDateList = this.list(lambdaQueryWrapper);
|
|
|
|
- List<MsgImportantDateDto> thisYear = new ArrayList<>();
|
|
|
|
- //添加所有日期
|
|
|
|
- for (MsgImportantDate msgImportantDate : importantDateList) {
|
|
|
|
- MsgImportantDateDto msgImportantDateDto = new MsgImportantDateDto();
|
|
|
|
- //提醒选项(0:全部提醒,1:农历,2:新历)
|
|
|
|
- if (msgImportantDate.getRemindWith() == 0) {
|
|
|
|
- //农历
|
|
|
|
- MsgImportantDateDto oldDate = new MsgImportantDateDto();
|
|
|
|
- oldDate.setDateName(msgImportantDate.getDateName());
|
|
|
|
- oldDate.setOldDate(msgImportantDate.getOldDate());
|
|
|
|
- thisYear.add(oldDate);
|
|
|
|
- //阳历
|
|
|
|
- MsgImportantDateDto newDate = new MsgImportantDateDto();
|
|
|
|
- newDate.setDateName(msgImportantDate.getDateName());
|
|
|
|
- newDate.setNewDate(msgImportantDate.getNewDate());
|
|
|
|
- thisYear.add(newDate);
|
|
|
|
- } else if (msgImportantDate.getRemindWith() == 1) {
|
|
|
|
- //农历
|
|
|
|
- msgImportantDateDto.setDateName(msgImportantDate.getDateName());
|
|
|
|
- msgImportantDateDto.setOldDate(msgImportantDate.getOldDate());
|
|
|
|
- thisYear.add(msgImportantDateDto);
|
|
|
|
- } else if (msgImportantDate.getRemindWith() == 2) {
|
|
|
|
- //阳历
|
|
|
|
- msgImportantDateDto.setDateName(msgImportantDate.getDateName());
|
|
|
|
- msgImportantDateDto.setNewDate(msgImportantDate.getNewDate());
|
|
|
|
- thisYear.add(msgImportantDateDto);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- //获取今年年份
|
|
|
|
- int yearStr = Integer.parseInt(LocalDateTime.now().toString().substring(0, 4));
|
|
|
|
- //农历转阳历,并添加今年和明年的日期
|
|
|
|
- List<MsgImportantDateDto> lastYear = new ArrayList<>();
|
|
|
|
- List<MsgImportantDateDto> nextYear = new ArrayList<>();
|
|
|
|
- //thisYear(0000农历, 今年阳历);
|
|
|
|
- for (MsgImportantDateDto msgImportantDateDto : thisYear) {
|
|
|
|
- //农历
|
|
|
|
- if (msgImportantDateDto.getOldDate() != null) {
|
|
|
|
- int month = Integer.parseInt(msgImportantDateDto.getOldDate().substring(5, 7));
|
|
|
|
- int day = Integer.parseInt(msgImportantDateDto.getOldDate().substring(8, 10));
|
|
|
|
- //今年农历
|
|
|
|
- msgImportantDateDto.setOldDate(yearStr + "-" + addZero(month) + "-" + addZero(day));
|
|
|
|
- //今年阳历
|
|
|
|
- msgImportantDateDto.setNewDate(convertNewDate(yearStr, month, day));
|
|
|
|
- //去年
|
|
|
|
- MsgImportantDateDto msgImportantDateLast = new MsgImportantDateDto();
|
|
|
|
- msgImportantDateLast.setDateName(msgImportantDateDto.getDateName());
|
|
|
|
- //去年农历
|
|
|
|
- msgImportantDateLast.setOldDate(yearStr - 1 + "-" + addZero(month) + "-" + addZero(day));
|
|
|
|
- //去年阳历
|
|
|
|
- msgImportantDateLast.setNewDate(convertNewDate(yearStr - 1, month, day));
|
|
|
|
- lastYear.add(msgImportantDateLast);
|
|
|
|
- //明年
|
|
|
|
- MsgImportantDateDto msgImportantDateNext = new MsgImportantDateDto();
|
|
|
|
- msgImportantDateNext.setDateName(msgImportantDateDto.getDateName());
|
|
|
|
- //明年农历
|
|
|
|
- msgImportantDateNext.setOldDate(yearStr + 1 + "-" + addZero(month) + "-" + addZero(day));
|
|
|
|
- //明年阳历
|
|
|
|
- msgImportantDateNext.setNewDate(convertNewDate(yearStr + 1, month, day));
|
|
|
|
- nextYear.add(msgImportantDateNext);
|
|
|
|
- } else if (msgImportantDateDto.getNewDate() != null) {
|
|
|
|
- //阳历
|
|
|
|
- int month = Integer.parseInt(msgImportantDateDto.getNewDate().substring(5, 7));
|
|
|
|
- int day = Integer.parseInt(msgImportantDateDto.getNewDate().substring(8, 10));
|
|
|
|
- //今年阳历
|
|
|
|
- msgImportantDateDto.setNewDate(yearStr + "-" + addZero(month) + "-" + addZero(day));
|
|
|
|
- //去年
|
|
|
|
- MsgImportantDateDto msgImportantDateLast = new MsgImportantDateDto();
|
|
|
|
- msgImportantDateLast.setDateName(msgImportantDateDto.getDateName());
|
|
|
|
- msgImportantDateLast.setNewDate(yearStr - 1 + "-" + addZero(month) + "-" + addZero(day));
|
|
|
|
- lastYear.add(msgImportantDateLast);
|
|
|
|
- //明年
|
|
|
|
- MsgImportantDateDto msgImportantDateNext = new MsgImportantDateDto();
|
|
|
|
- msgImportantDateNext.setDateName(msgImportantDateDto.getDateName());
|
|
|
|
- msgImportantDateNext.setNewDate(yearStr + 1 + "-" + addZero(month) + "-" + addZero(day));
|
|
|
|
- nextYear.add(msgImportantDateNext);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- resultList.addAll(lastYear);
|
|
|
|
- resultList.addAll(thisYear);
|
|
|
|
- resultList.addAll(nextYear);
|
|
|
|
- return resultList;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 添加重要日期
|
|
|
|
- *
|
|
|
|
- * @param userId 用户id
|
|
|
|
- * @param dateName 日期名称
|
|
|
|
- * @param oldDate 农历日期
|
|
|
|
- * @param newDate 阳历日期
|
|
|
|
- * @param remindWith 提醒选项(0:全部提醒,1:农历,2:新历,3:不提醒)
|
|
|
|
- * @return boolean
|
|
|
|
- */
|
|
|
|
- @Override
|
|
|
|
- public boolean addImportantDate(String userId, String dateName, String oldDate, String newDate, Integer remindWith) {
|
|
|
|
- MsgImportantDate msgImportantDate = new MsgImportantDate();
|
|
|
|
- String[] split = userId.split(",");
|
|
|
|
- if (split.length > 1) {
|
|
|
|
- userId = split[0];
|
|
|
|
- }
|
|
|
|
- msgImportantDate.setUserId(Integer.parseInt(userId));
|
|
|
|
- msgImportantDate.setDateName(dateName);
|
|
|
|
- String[] oldDateList = getList(oldDate);
|
|
|
|
- msgImportantDate.setOldDate("0000-" + addZero(Integer.parseInt(oldDateList[1])) + "-" + addZero(Integer.parseInt(oldDateList[2])));
|
|
|
|
- String[] newDateList = getList(newDate);
|
|
|
|
- msgImportantDate.setNewDate("0000-" + addZero(Integer.parseInt(newDateList[1])) + "-" + addZero(Integer.parseInt(newDateList[2])));
|
|
|
|
- msgImportantDate.setRemindWith(remindWith);
|
|
|
|
- msgImportantDate.setCreatedUserId(Integer.parseInt(userId));
|
|
|
|
- return this.save(msgImportantDate);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 删除重要日期
|
|
|
|
- *
|
|
|
|
- * @param id 表id
|
|
|
|
- * @return boolean
|
|
|
|
- */
|
|
|
|
- @Override
|
|
|
|
- public boolean deleteMsg(Integer id) {
|
|
|
|
- return this.removeById(id);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 农历转阳历
|
|
|
|
- *
|
|
|
|
- * @param year 年
|
|
|
|
- * @param month 月
|
|
|
|
- * @param day 日
|
|
|
|
- * @return 阳历日期
|
|
|
|
- */
|
|
|
|
- private String convertNewDate(Integer year, Integer month, Integer day) {
|
|
|
|
- Lunar lunar = Lunar.fromYmd(year, month, day);
|
|
|
|
- Solar solar = lunar.getSolar();
|
|
|
|
- return solar.toString();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 判断小于十则加0
|
|
|
|
- *
|
|
|
|
- * @param num 数字
|
|
|
|
- * @return string
|
|
|
|
- */
|
|
|
|
- private String addZero(int num) {
|
|
|
|
- if (num < 10) {
|
|
|
|
- return "0" + num;
|
|
|
|
- }
|
|
|
|
- return num + "";
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 用-分割
|
|
|
|
- *
|
|
|
|
- * @param str 字符串
|
|
|
|
- * @return 数组
|
|
|
|
- */
|
|
|
|
- private String[] getList(String str) {
|
|
|
|
- return str.split("-");
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-}
|
|
|