浏览代码

修改创建新酒店后数据初始化产生的问题

许智捷 1 年之前
父节点
当前提交
9ce19285d1

+ 57 - 4
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/controller/BusHotelController.java

@@ -4,6 +4,7 @@ import cn.hutool.core.bean.BeanUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.core.toolkit.IdWorker;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
@@ -20,6 +21,9 @@ import org.jeecg.common.util.TokenUtils;
 import org.jeecg.modules.business.entity.*;
 import org.jeecg.modules.business.service.*;
 import org.jeecg.modules.business.util.MapUtil;
+import org.jeecg.modules.quartz.entity.QuartzJob;
+import org.jeecg.modules.quartz.service.IQuartzJobService;
+import org.jeecg.modules.quartz.service.impl.QuartzJobServiceImpl;
 import org.jeecg.modules.rooms.DTO.CesAllDayPriceRuleDto;
 import org.jeecg.modules.rooms.entity.CesHousePriceScheme;
 import org.jeecg.modules.rooms.service.CesAllDayPriceRuleServiceImpl;
@@ -94,6 +98,12 @@ public class BusHotelController extends JeecgController<BusHotel, IBusHotelServi
 	 @Resource
 	 CesHousePriceSchemeServiceImpl housePriceSchemeService;
 
+	 @Resource
+	 IBusRoomPayTypeService roomPayTypeService;
+
+	 @Resource
+	 IQuartzJobService quartzJobService;
+
 	/**
 	 * 分页列表查询
 	 *
@@ -162,9 +172,6 @@ public class BusHotelController extends JeecgController<BusHotel, IBusHotelServi
 		queryDict.eq(BusDict::getTenantId, "0");
 		List<BusDict> listDict = busDictService.list(queryDict);
 		if (listDict != null && listDict.size() > 0){
-//			for (BusDict busDict : listDict) {
-//
-//			}
 			List<BusDict> batchModels = new ArrayList<>();
 			listDict.forEach( item -> {
 				BusDict newModel = new BusDict();
@@ -181,6 +188,30 @@ public class BusHotelController extends JeecgController<BusHotel, IBusHotelServi
 			busDictService.saveBatch(batchModels);
 		}
 
+		//添加酒店后初始化收费方式
+		LambdaQueryWrapper<BusRoomPayType> queryPayType = new LambdaQueryWrapper<>();
+		queryPayType.eq(BusRoomPayType::getDelFlag, CommonConstant.DEL_FLAG_0.toString());
+		queryPayType.eq(BusRoomPayType::getHotelId, "0");
+		queryPayType.eq(BusRoomPayType::getTenantId, "0");
+		queryPayType.eq(BusRoomPayType::getIsMust, true);
+		List<BusRoomPayType> payTypeList = roomPayTypeService.list(queryPayType);
+		if (payTypeList != null && !payTypeList.isEmpty()){
+			List<BusRoomPayType> batchModels = new ArrayList<>();
+			payTypeList.forEach( item -> {
+				BusRoomPayType newModel = new BusRoomPayType();
+				newModel.setTenantId(busHotel.getTenantId());
+				newModel.setHotelId(busHotel.getId());
+				newModel.setName(item.getName());
+				newModel.setIsDeposit(item.getIsDeposit());
+				newModel.setIsClosing(item.getIsClosing());
+				newModel.setIsMust(item.getIsMust());
+				newModel.setStatus(item.getStatus());
+				newModel.setDelFlag(item.getDelFlag());
+				batchModels.add(newModel);
+			});
+			roomPayTypeService.saveBatch(batchModels);
+		}
+
 		//初始化打印模板
 		LambdaQueryWrapper<BusPrintTemplate> queryPrintTemplate = new LambdaQueryWrapper<BusPrintTemplate>();
 		queryPrintTemplate.eq(BusPrintTemplate::getDelFlag, CommonConstant.DEL_FLAG_0.toString());
@@ -478,6 +509,27 @@ public class BusHotelController extends JeecgController<BusHotel, IBusHotelServi
 			busParamXcxRoomService.save(newModel);
 		}
 
+		//定时任务
+		ArrayList<QuartzJob> quartzJobs = new ArrayList<>();
+		QuartzJob quartzJob1 = new QuartzJob();
+		quartzJob1.setDelFlag(CommonConstant.DEL_FLAG_0);
+		quartzJob1.setJobClassName("org.jeecg.modules.quartz.job.LivingRoomOrderFeeJob");
+		quartzJob1.setCronExpression("0 */1 * * * ?");
+		quartzJob1.setParameter(busHotel.getId());
+		quartzJob1.setStatus(CommonConstant.STATUS_DISABLE);
+
+		QuartzJob quartzJob2 = new QuartzJob();
+		quartzJob2.setDelFlag(CommonConstant.DEL_FLAG_0);
+		quartzJob2.setJobClassName("org.jeecg.modules.quartz.job.NightAuditJob");
+		quartzJob2.setCronExpression("0 00 06 * * ? ");
+		quartzJob2.setParameter(busHotel.getId());
+		quartzJob2.setStatus(CommonConstant.STATUS_DISABLE);
+		quartzJobs.add(quartzJob1);
+		quartzJobs.add(quartzJob2);
+		quartzJobService.saveBatch(quartzJobs);
+		quartzJobService.resumeJob(quartzJob1);
+		quartzJobService.resumeJob(quartzJob2);
+
 		//全天房计费规则
 		CesAllDayPriceRuleDto cesAllDayPriceRuleDto = new CesAllDayPriceRuleDto();
 		cesAllDayPriceRuleDto.setHotelId(busHotel.getId());
@@ -493,7 +545,7 @@ public class BusHotelController extends JeecgController<BusHotel, IBusHotelServi
 		cesAllDayPriceRuleDto.setDayTime("30");
 		cesAllDayPriceRuleDto.setInvalid(false);
 		cesAllDayPriceRuleService.modifyWholeDayUnifyPrice(cesAllDayPriceRuleDto);
-
+		// 基础房价方案 平日方案,周末方案,节假日方案
 		List<CesHousePriceScheme> priceSchemeList = new ArrayList<>(3);
 		CesHousePriceScheme priceScheme = new CesHousePriceScheme();
 		CesHousePriceScheme weekScheme = new CesHousePriceScheme();
@@ -516,6 +568,7 @@ public class BusHotelController extends JeecgController<BusHotel, IBusHotelServi
 
 	}
 
+
 	/**
 	 *  编辑
 	 *

+ 22 - 5
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/controller/BusNightTrialController.java

@@ -8,8 +8,11 @@ import java.util.stream.Collectors;
 import java.io.IOException;
 import java.io.UnsupportedEncodingException;
 import java.net.URLDecoder;
+import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import org.jeecg.common.api.vo.Result;
 import org.jeecg.common.constant.CommonConstant;
 import org.jeecg.common.exception.JeecgBootException;
@@ -27,6 +30,9 @@ import org.jeecg.modules.business.entity.BusDictItem;
 import org.jeecg.modules.business.entity.BusNightTrial;
 import org.jeecg.modules.business.entity.BusSalesPersonPost;
 import org.jeecg.modules.business.service.IBusNightTrialService;
+import org.jeecg.modules.business.util.DateTimeToCronUtils;
+import org.jeecg.modules.quartz.entity.QuartzJob;
+import org.jeecg.modules.quartz.service.IQuartzJobService;
 import org.jeecgframework.poi.excel.ExcelImportUtil;
 import org.jeecgframework.poi.excel.def.NormalExcelConstants;
 import org.jeecgframework.poi.excel.entity.ExportParams;
@@ -58,6 +64,8 @@ public class BusNightTrialController extends JeecgController<BusNightTrial, IBus
 	@Autowired
 	private IBusNightTrialService busNightTrialService;
 
+	 @Resource
+	 private IQuartzJobService quartzJobService;
 	/**
 	 * 分页列表查询
 	 *
@@ -149,10 +157,13 @@ public class BusNightTrialController extends JeecgController<BusNightTrial, IBus
 				 throw new JeecgBootException("当前登录人租户信息错误");
 			 }
 		 }
+		 QuartzJob job = quartzJobService.getOne(Wrappers.<QuartzJob>lambdaQuery()
+				 .eq(QuartzJob::getParameter, busNightTrial.getHotelId()).eq(QuartzJob::getTaskType, 1).last("limit 1"));
 		 if (busNightTrial.getId() != null && !busNightTrial.getId().equals("")){
 			 BusNightTrial editModel = busNightTrialService.getById(busNightTrial.getId());
 			 editModel.setAutoCheck(busNightTrial.getAutoCheck());
 			 busNightTrialService.updateById(editModel);
+			 boolean b = editModel.getAutoCheck() == 0 ? quartzJobService.pause(job) : quartzJobService.resumeJob(job);
 			 return Result.OK(editModel);
 		 }else{
 			 busNightTrial.setDelFlag(CommonConstant.DEL_FLAG_0);
@@ -160,17 +171,18 @@ public class BusNightTrialController extends JeecgController<BusNightTrial, IBus
 			 Time _time = Time.valueOf("06:00:00");
 			 busNightTrial.setSetNightTrialTime(_time);
 			 busNightTrialService.save(busNightTrial);
+			 quartzJobService.resumeJob(job);
 			 return Result.OK(busNightTrial);
 		 }
 	 }
 
 	 /**
-	  *  编辑
+	  *  时间编辑
 	  *
 	  * @param busNightTrial
 	  * @return
 	  */
-	 @AutoLog(value = "夜审设置-编辑")
+	 @AutoLog(value = "夜审设置-时间编辑")
 	 @ApiOperation(value="夜审设置-编辑", notes="夜审设置-编辑")
 	 //@RequiresPermissions("business:bus_night_trial_info:edit")
 	 @RequestMapping(value = "/editNightTrialTime", method = {RequestMethod.PUT,RequestMethod.POST})
@@ -183,29 +195,34 @@ public class BusNightTrialController extends JeecgController<BusNightTrial, IBus
 				 throw new JeecgBootException("当前登录人租户信息错误");
 			 }
 		 }
+		 QuartzJob job = quartzJobService.getOne(Wrappers.<QuartzJob>lambdaQuery()
+				 .eq(QuartzJob::getParameter, busNightTrial.getHotelId()).eq(QuartzJob::getTaskType, 1).last("limit 1"));
 //		 Time _time = Time.valueOf(busNightTrial.getSetNightTrialTime());
 //		 busNightTrial.setSetNightTrialTime(_time);
 		 if (busNightTrial.getId() != null && !busNightTrial.getId().equals("")){
 			 BusNightTrial editModel = busNightTrialService.getById(busNightTrial.getId());
 			 editModel.setSetNightTrialTime(busNightTrial.getSetNightTrialTime());
 			 busNightTrialService.updateById(editModel);
+			 job.setCronExpression(DateTimeToCronUtils.getCron(editModel.getSetNightTrialTime(), DateTimeToCronUtils.EVERYDAY));
+			 quartzJobService.resumeJob(job);
 			 return Result.OK(editModel);
-		 }else{
+		 } else {
 			 busNightTrial.setDelFlag(CommonConstant.DEL_FLAG_0);
 			 busNightTrial.setAutoHand(1);
 			 busNightTrial.setAutoCheck(1);
 			 busNightTrialService.save(busNightTrial);
+			 quartzJobService.resumeJob(job);
 			 return Result.OK(busNightTrial);
 		 }
 	 }
 
 	 /**
-	  *  编辑
+	  *  转脏房编辑
 	  *
 	  * @param busNightTrial
 	  * @return
 	  */
-	 @AutoLog(value = "夜审设置-编辑")
+	 @AutoLog(value = "夜审设置-转脏房编辑")
 	 @ApiOperation(value="夜审设置-编辑", notes="夜审设置-编辑")
 	 //@RequiresPermissions("business:bus_night_trial_info:edit")
 	 @RequestMapping(value = "/editAutoHand", method = {RequestMethod.PUT,RequestMethod.POST})

+ 14 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/controller/BusRoomPayTypeController.java

@@ -10,7 +10,9 @@ import java.net.URLDecoder;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import org.jeecg.common.api.vo.Result;
 import org.jeecg.common.constant.CommonConstant;
 import org.jeecg.common.exception.JeecgBootException;
@@ -154,6 +156,11 @@ public class BusRoomPayTypeController extends JeecgController<BusRoomPayType, IB
 				throw new JeecgBootException("当前登录人租户信息错误");
 			}
 		}
+		List<BusRoomPayType> payTypeList = busRoomPayTypeService.list(Wrappers.<BusRoomPayType>lambdaQuery().eq(BusRoomPayType::getName, busRoomPayType.getName())
+				.eq(BusRoomPayType::getHotelId, busRoomPayType.getHotelId()));
+		if (!payTypeList.isEmpty()){
+			return Result.error("支付方式已存在");
+		}
 		busRoomPayTypeService.save(busRoomPayType);
 		return Result.OK("添加成功!");
 	}
@@ -179,6 +186,9 @@ public class BusRoomPayTypeController extends JeecgController<BusRoomPayType, IB
 			}
 		}
 		BusRoomPayType editModel = busRoomPayTypeService.getById(busRoomPayType.getId());
+		if (editModel.getIsMust() && !StrUtil.equals(editModel.getName(), busRoomPayType.getName())){
+			return Result.error("基础支付方式不可修改名称");
+		}
 		editModel.setName(busRoomPayType.getName());
 		editModel.setIsDeposit(busRoomPayType.getIsDeposit());
 		editModel.setIsClosing(busRoomPayType.getIsClosing());
@@ -199,6 +209,10 @@ public class BusRoomPayTypeController extends JeecgController<BusRoomPayType, IB
 	//@RequiresPermissions("business:bus_room_pay_type_info:delete")
 	@DeleteMapping(value = "/delete")
 	public Result<String> delete(@RequestParam(name="id",required=true) String id) {
+		BusRoomPayType payType = busRoomPayTypeService.getById(id);
+		if (payType.getIsMust()){
+			return Result.error("基础支付方式不可删除");
+		}
 		busRoomPayTypeService.removeById(id);
 		return Result.OK("删除成功!");
 	}

+ 4 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/entity/BusRoomPayType.java

@@ -88,6 +88,10 @@ public class BusRoomPayType implements Serializable {
     @ApiModelProperty(value = "更新时间")
     private Date updateTime;
 
+    /**不可删除的*/
+    @ApiModelProperty(value = "不可删除的")
+    private Boolean isMust;
+
     @TableField(exist = false)
     private BigDecimal amount;
 

+ 174 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/util/DateTimeToCronUtils.java

@@ -0,0 +1,174 @@
+package org.jeecg.modules.business.util;
+
+import cn.hutool.core.date.DateUtil;
+
+import java.text.SimpleDateFormat;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.util.Date;
+
+public class DateTimeToCronUtils {
+
+    /**
+     * 每年format格式
+     */
+    public static final String YEAR = "ss mm HH dd MM ? yyyy";
+
+    /**
+     * 每周format格式
+     */
+    public static final String MONDAY = "ss mm HH ? * 1";
+    public static final String TUESDAY = "ss mm HH ? * 2";
+    public static final String WEDNESDAY = "ss mm HH ? * 3";
+    public static final String THURSDAY = "ss mm HH ? * 4";
+    public static final String FRIDAY = "ss mm HH ? * 5";
+    public static final String SATURDAY = "ss mm HH ? * 6";
+    public static final String SUNDAY = "ss mm HH ? * 7";
+
+    /**
+     * 每天format格式
+     */
+    public static final String EVERYDAY = "ss mm HH * * ?";
+
+    /**
+     * 间隔-每天format格式
+     */
+    public static final String INTERVAL_DAY = "0 0 0 1/param * ? ";
+
+    /**
+     * 间隔-每小时format格式
+     */
+    public static final String INTERVAL_HOUR = "0 0 0/param * * ?";
+
+    /**
+     * 间隔-每分钟format格式
+     */
+    public static final String INTERVAL_MINUTE = "0 0/param * * * ? ";
+
+    /**
+     * LocalDateTime格式化为String
+     *
+     * @param date       LocalDateTime
+     * @param dateFormat format格式
+     * @return String
+     * @author longwei
+     */
+    public static String formatDateByPattern(LocalDateTime date, String dateFormat) {
+        return DateUtil.format(date, dateFormat);
+    }
+
+    /**
+     * date格式化为String
+     *
+     * @param date       date
+     * @param dateFormat format格式
+     * @return String
+     * @author longwei
+     */
+    public static String formatDateByPattern(Date date, String dateFormat) {
+        SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
+        String formatTimeStr = null;
+        if (date != null) {
+            formatTimeStr = sdf.format(date);
+        }
+        return formatTimeStr;
+    }
+
+    /**
+     * 时间转换Cron表达式
+     *
+     * @param date       date
+     * @param dateFormat format格式
+     * @return Cron表达式
+     * @author longwei
+     */
+    public static String getCron(Date date, String dateFormat) {
+        return formatDateByPattern(date, dateFormat);
+    }
+
+    /**
+     * 时间转换Cron表达式
+     *
+     * @param date       date
+     * @param dateFormat format格式
+     * @return Cron表达式
+     * @author longwei
+     */
+    public static String getCron(LocalDateTime date, String dateFormat) {
+        return formatDateByPattern(date, dateFormat);
+    }
+
+    /**
+     * 间隔天转换Cron表达式
+     *
+     * @param param 天
+     * @return Cron表达式
+     * @author longwei
+     */
+    public static String getIntervalDayCron(String param) {
+        return INTERVAL_DAY.replace("param", param);
+    }
+
+    /**
+     * 间隔小时转换Cron表达式
+     *
+     * @param param 小时
+     * @return Cron表达式
+     * @author longwei
+     */
+    public static String getIntervalHourCron(String param) {
+        return INTERVAL_HOUR.replace("param", param);
+    }
+
+    /**
+     * 间隔分钟转换Cron表达式
+     *
+     * @param param 分钟
+     * @return Cron表达式
+     * @author longwei
+     */
+    public static String getIntervalMinuteCron(String param) {
+        return INTERVAL_MINUTE.replace("param", param);
+    }
+
+    public static void main(String[] args) {
+        Date date = new Date();
+
+        String cron = getCron(date, YEAR);
+        System.out.println("date-每年执行一次" + cron);
+
+        cron = getCron(date, MONDAY);
+        System.out.println("date-每周一执行" + cron);
+
+        cron = getCron(date, EVERYDAY);
+        System.out.println("date-每天执行" + cron);
+
+
+        System.out.println("------------------------------");
+
+        LocalDateTime localDateTime = LocalDateTime.now();
+
+        cron = getCron(localDateTime, YEAR);
+        System.out.println("localDateTime-每年执行一次" + cron);
+
+        cron = getCron(localDateTime, MONDAY);
+        System.out.println("localDateTime-每周一执行" + cron);
+
+        cron = getCron(localDateTime, EVERYDAY);
+        System.out.println("localDateTime-每天执行" + cron);
+
+        LocalDate localDate = LocalDate.now();
+        LocalDateTime dateTime = localDate.atTime(13, 14);
+        cron = getCron(dateTime, EVERYDAY);
+        System.out.println("localDateTime-每天指定时间执行" + cron);
+
+        cron = getIntervalDayCron("1");
+        System.out.println("localDateTime-间隔1天执行" + cron);
+
+        cron = getIntervalHourCron("2");
+        System.out.println("localDateTime-间隔2小时执行" + cron);
+
+        cron = getIntervalMinuteCron("5");
+        System.out.println("localDateTime-间隔5分钟执行" + cron);
+    }
+}

+ 3 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/quartz/entity/QuartzJob.java

@@ -58,5 +58,8 @@ public class QuartzJob implements Serializable {
 	@Excel(name="状态",width=15,dicCode="quartz_status")
 	@Dict(dicCode = "quartz_status")
 	private java.lang.Integer status;
+	/**类型 1夜审*/
+	@Excel(name="类型",width=15,dicCode="task_type")
+	private java.lang.Integer taskType;
 
 }

+ 1 - 1
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/quartz/service/IQuartzJobService.java

@@ -63,5 +63,5 @@ public interface IQuartzJobService extends IService<QuartzJob> {
 	 * @param quartzJob
 	 * @throws SchedulerException
 	 */
-	void pause(QuartzJob quartzJob);
+	boolean pause(QuartzJob quartzJob);
 }

+ 2 - 2
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/quartz/service/impl/QuartzJobServiceImpl.java

@@ -122,10 +122,10 @@ public class QuartzJobServiceImpl extends ServiceImpl<QuartzJobMapper, QuartzJob
 
 	@Override
 	@Transactional(rollbackFor = JeecgBootException.class)
-	public void pause(QuartzJob quartzJob){
+	public boolean pause(QuartzJob quartzJob){
 		schedulerDelete(quartzJob.getId());
 		quartzJob.setStatus(CommonConstant.STATUS_DISABLE);
-		this.updateById(quartzJob);
+		return this.updateById(quartzJob);
 	}
 
 	/**

+ 8 - 4
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/rooms/controller/CesHouseLongRentSchemeController.java

@@ -2,6 +2,7 @@ package org.jeecg.modules.rooms.controller;
 
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.util.StrUtil;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import io.swagger.annotations.Api;
@@ -58,13 +59,16 @@ public class CesHouseLongRentSchemeController extends JeecgController<CesHouseLo
         return Result.ok("修改成功");
     }
 
-    @AutoLog(value = "新增房价方案")
-    @ApiOperation(value="新增房价方案", notes="新增房价方案")
+    @AutoLog(value = "查询房价方案")
+    @ApiOperation(value="查询房价方案", notes="查询房价方案")
     @GetMapping(value = "/page")
     public Result<Page<CesHouseLongRentScheme>> page(@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
-                                                     @RequestParam(name="pageSize", defaultValue="10") Integer pageSize){
+                                                     @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
+                                                     String hotelId){
         Page<CesHouseLongRentScheme> page = new Page<>(pageNo, pageSize);
-        Page<CesHouseLongRentScheme> houseLongRentSchemePage = service.page(page);
+        LambdaQueryWrapper<CesHouseLongRentScheme> queryWrapper = new LambdaQueryWrapper<>();
+        queryWrapper.eq(CesHouseLongRentScheme::getHotelId, hotelId);
+        Page<CesHouseLongRentScheme> houseLongRentSchemePage = service.page(page, queryWrapper);
         houseLongRentSchemePage.getRecords().forEach(e -> {
             List<CesHouseLongRentCharge> list = houseLongRentChargeService.list(Wrappers.<CesHouseLongRentCharge>lambdaQuery()
                     .eq(CesHouseLongRentCharge::getSchemeId, e.getId()).isNull(CesHouseLongRentCharge::getLivingOrderId));