zjh
2024-01-24 aa33bb96ba9f14b16c6c7832e21bfbd88983ba6d
ltkj-admin/src/main/java/com/ltkj/web/controller/app/ReservationController.java
@@ -1,11 +1,14 @@
package com.ltkj.web.controller.app;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.google.common.base.Joiner;
import com.ltkj.common.core.controller.BaseController;
import com.ltkj.common.core.domain.AjaxResult;
import com.ltkj.common.task.TaskService;
import com.ltkj.common.utils.StringUtils;
import com.ltkj.framework.config.MatchUtils;
import com.ltkj.framework.config.UserHoder;
@@ -15,6 +18,8 @@
import com.ltkj.mall.service.IMallTimeConfigService;
import com.ltkj.system.service.ISysConfigService;
import com.ltkj.web.config.redis.OrderDelayService;
import com.ltkj.web.config.task.TjReservationTask;
import com.ltkj.web.wxUtils.WxUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
@@ -24,10 +29,7 @@
import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.*;
/**
 * @Author: 西安路泰科技有限公司
@@ -56,8 +58,10 @@
    private IMallTimeConfigService mallTimeConfigService;
    @Resource
    private ISysConfigService configService;
    @Resource
    private OrderDelayService delayService;
//    @Resource
//    private OrderDelayService delayService;
    @Autowired
    private TaskService taskService;
    @PostMapping
    @ApiOperation(value = "个人预约")
@@ -106,7 +110,9 @@
            tjReservation.setProIds(join);
        }
        if (reservationService.save(tjReservation)) {
            delayService.reservation(tjReservation.getId());
            taskService.addTask(new TjReservationTask(tjReservation.getId(),
                    DateUtil.between(new Date(),DateUtil.endOfDay(tjReservation.getReservationTime()), DateUnit.MS)));
            TjCustomer one = customerService.getOne(new LambdaQueryWrapper<TjCustomer>().eq(TjCustomer::getCusIdcard,tjReservation.getIdCard()));
            if(null !=one){
@@ -153,6 +159,47 @@
                config.setNowNum(config.getNowNum()-1);
                mallTimeConfigService.updateById(config);
            }
            //发订单信息给wx订阅服务消息————————————————start————————————————————————————————————————
            Map<String, Object> res = new HashMap<>();
            res.put("touser",wxuser.getOpenid());
            res.put("template_id","M4K_BNVG7g4hOAcrIDO18ux8KOTneHeNide5GdPW3kc");
            res.put("page","pages/mine/index");
            res.put("miniprogram_state","trial");
            //订阅消息参数值
            JSONObject data = new JSONObject();
            JSONObject name1 = new JSONObject();
            name1.put("value",tjReservation.getName());
            data.put("thing1", name1);
            JSONObject amount3 = new JSONObject();
            amount3.put("value", "体检中心");
            data.put("thing2", amount3);
            JSONObject time4 = new JSONObject();
            String dateFormat = DateUtil.format(tjReservation.getReservationTime(), "yyyy-MM-dd");
            time4.put("value", dateFormat);
            data.put("time4", time4);
            final TjPackage byId = packageService.getById(tjReservation.getPacId());
            if (byId!=null){
                JSONObject thing5 = new JSONObject();
                thing5.put("value",byId.getPacName());
                data.put("thing5", thing5);
            }else {
                JSONObject thing5 = new JSONObject();
                thing5.put("value","未知");
                data.put("thing5", thing5);
            }
            JSONObject thing6 = new JSONObject();
            thing6.put("value", "体检前一天请您进清淡饮食,勿饮酒!");
            data.put("thing6", thing6);
            WxUtil.sendCommonSubscribeMessage(res,data);
            //发订单信息给wx订阅服务消息————————————————end————————————————————————————————————————
            return AjaxResult.success("预约成功!!!",tjReservation.getId());
        }
        return AjaxResult.error("预约失败");
@@ -162,10 +209,16 @@
    @ApiOperation(value = "撤销个人预约")
    @Transactional
    public AjaxResult cusDeletedReservation(@RequestBody TjReservation reservation) {
        LambdaQueryWrapper<TjReservation> wq = new LambdaQueryWrapper<>();
        wq.eq(TjReservation::getIdCard, reservation.getIdCard());
        wq.eq(TjReservation::getIsExpire, 2);
        TjReservation one = reservationService.getOne(wq);
        Wxuser wxuser = UserHoder.getWxuser();
//        LambdaQueryWrapper<TjReservation> wq = new LambdaQueryWrapper<>();
//        wq.eq(TjReservation::getIdCard, reservation.getIdCard());
//        wq.eq(TjReservation::getIsExpire, 2);
//        TjReservation one = reservationService.getOne(wq);
        if (reservation.getId()==null){
            return AjaxResult.success("出错了,请联系工作人员!");
        }
        taskService.removeTask(new TjReservationTask(reservation.getId()));
        TjReservation one = reservationService.getById(reservation.getId());
        if (null != one) {
            String isPays = configService.selectConfigByKey("isPay");
            if(null !=isPays  && isPays.equals("true") ){
@@ -181,7 +234,47 @@
            transitionService.deletedTbTransitionByCusId(reservation.getIdCard());
            reservationService.removeById(one);
            return AjaxResult.success();
            //发订单信息给wx订阅服务消息————————————————start————————————————————————————————————————
            Map<String, Object> res = new HashMap<>();
            res.put("touser",wxuser.getOpenid());
            res.put("template_id","X467Xtd8HnFDNk-IoT0ChcdoBnClLZJQQwP7DMztYQ8");
            res.put("page","pages/mine/index");
            res.put("miniprogram_state","trial");
            //订阅消息参数值
            JSONObject data = new JSONObject();
            JSONObject amount3 = new JSONObject();
            amount3.put("value", "体检中心");
            data.put("thing3", amount3);
            JSONObject name1 = new JSONObject();
            name1.put("value",reservation.getName());
            data.put("name1", name1);
            final TjPackage byId = packageService.getById(reservation.getPacId());
            if (byId!=null){
                JSONObject thing5 = new JSONObject();
                thing5.put("value",byId.getPacName());
                data.put("thing4", thing5);
            }else {
                JSONObject thing5 = new JSONObject();
                thing5.put("value","未知");
                data.put("thing4", thing5);
            }
            JSONObject time4 = new JSONObject();
            String dateFormat = DateUtil.format(reservation.getReservationTime(), "yyyy-MM-dd");
            time4.put("value", dateFormat);
            data.put("date2", time4);
            JSONObject thing6 = new JSONObject();
            thing6.put("value", "您已成功取消本次预约,欢迎再次使用!");
            data.put("thing5", thing6);
            WxUtil.sendCommonSubscribeMessage(res,data);
            //发订单信息给wx订阅服务消息————————————————end————————————————————————————————————————
            return AjaxResult.success("取消成功");
        }
        return AjaxResult.success("暂无预约信息");
    }
@@ -249,7 +342,12 @@
            mallTimeConfigService.updateById(config1);
            one.setReservationTime(tjReservation.getReservationTime());
            reservationService.updateById(one);
            if (reservationService.updateById(one)) {
                taskService.removeTask(new TjReservationTask(tjReservation.getId()));
                taskService.addTask(new TjReservationTask(tjReservation.getId(),
                        DateUtil.between(new Date(),DateUtil.endOfDay(tjReservation.getReservationTime()), DateUnit.MS)));
            }
            return AjaxResult.success("操作成功");
        }
        return AjaxResult.error("预约不存在或已超时 不可修改!");