package com.huaheng.pc.receipt.reservation.controller; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.huaheng.common.utils.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.huaheng.common.support.Convert; import com.huaheng.common.utils.StringUtils; import com.huaheng.framework.aspectj.lang.annotation.Log; import com.huaheng.framework.aspectj.lang.constant.BusinessType; import com.huaheng.framework.web.controller.BaseController; import com.huaheng.framework.web.domain.AjaxResult; import com.huaheng.framework.web.page.PageDomain; import com.huaheng.framework.web.page.TableDataInfo; import com.huaheng.framework.web.page.TableSupport; import com.huaheng.pc.receipt.receiptHeader.domain.ReceiptHeader; import com.huaheng.pc.receipt.receiptHeader.service.ReceiptHeaderService; import com.huaheng.pc.receipt.reservation.domain.Reservation; import com.huaheng.pc.receipt.reservation.service.ReservationService; import com.huaheng.pc.shipment.shipmentHeader.domain.ShipmentHeader; import com.huaheng.pc.shipment.shipmentHeader.service.ShipmentHeaderService; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @ApiModel(value = "预约") @RequestMapping("/reservation") @Controller public class ReservationController extends BaseController { @Resource private ReservationService reservationService; @Resource private ReceiptHeaderService receiptHeaderService; @Resource private ShipmentHeaderService shipmentHeaderService; private String prefix = "receipt/reservation"; @RequiresPermissions("reservation:view") @GetMapping() public String reservation() { return prefix + "/reservation"; } @GetMapping("/selectWarehouse") public String selectWarehouse() { return prefix + "/selectWarehouse"; } @RequiresPermissions("reservation:view") @GetMapping("/view/{warehouseCode}") public String view(@PathVariable("warehouseCode") String warehouseCode, ModelMap modelMap) { LocalDate date2 = LocalDate.now(); List<LocalDate> localDateList = new ArrayList<>(); for (int i = 0; i < 7; i++) { localDateList.add(date2.plusDays(i)); } modelMap.put("localDateList", localDateList); modelMap.put("warehouseCode", warehouseCode); return prefix + "/view"; } /** * 查询预约 */ @RequiresPermissions("reservation:list") @Log(title = "预约-预约查讯", operating = "预约查讯", action = BusinessType.GRANT) @PostMapping("/list") @ResponseBody @ApiOperation("预约查询接口") public TableDataInfo list(Reservation reservation, String begin, String end) { LambdaQueryWrapper<Reservation> lambdaQueryWrapper = Wrappers.lambdaQuery(); PageDomain pageDomain = TableSupport.buildPageRequest(); Integer pageNum = pageDomain.getPageNum(); Integer pageSize = pageDomain.getPageSize(); lambdaQueryWrapper.like(StringUtils.isNotEmpty(reservation.getCarPlate()), Reservation::getCarPlate, reservation.getCarPlate()) .like(StringUtils.isNotEmpty(reservation.getName()), Reservation::getName, reservation.getName()) .eq(StringUtils.isNotEmpty(reservation.getStatus()), Reservation::getStatus, reservation.getStatus()) .like(StringUtils.isNotEmpty(reservation.getCode()), Reservation::getCode, reservation.getCode()) .lt(StringUtils.isNotEmpty(begin), Reservation::getBeginTime, begin) .gt(StringUtils.isNotEmpty(end), Reservation::getEndTime, end) .eq(StringUtils.isNotEmpty(reservation.getStationCode()), Reservation::getStationCode, reservation.getStationCode()); if (StringUtils.isNotNull(pageNum) && StringUtils.isNotNull(pageSize)) { /** * 使用分页查询 */ Page<Reservation> page = new Page<>(pageNum, pageSize); IPage<Reservation> iPage = reservationService.page(page, lambdaQueryWrapper); return getMpDataTable(iPage.getRecords(), iPage.getTotal()); } else { List<Reservation> list = reservationService.list(lambdaQueryWrapper); return getDataTable(list); } } /** * 删除预约单 */ @ApiOperation(value="删除预约单", notes="删除预约单", httpMethod = "POST") @RequiresPermissions("receipt:receiptHeader:remove") @Log(title = "预约-预约列表 ",operating = "预约单删除", action = BusinessType.UPDATE) @PostMapping("/remove") @ResponseBody public AjaxResult remove(@ApiParam(name = "id", value = "预约头表id字符串")String ids){ if (StringUtils.isNull(ids)){ return AjaxResult.error("id为空"); } return toAjax(reservationService.removeByIds(Arrays.asList(Convert.toIntArray(ids)))); } /** * 新增预约 */ @GetMapping("/add/{warehouseCode}/{date}/{time1}/{time2}") public String add(@PathVariable("warehouseCode") String warehouseCode, @PathVariable("date") String date, @PathVariable("time1") String time1, @PathVariable("time2")String time2, ModelMap modelMap) { DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd"); LocalDate localDate = LocalDate.parse(date, fmt); DateTimeFormatter fmt1 = DateTimeFormatter.ofPattern("HH:mm"); LocalTime beginTime = LocalTime.parse(time1, fmt1); LocalTime endTime = LocalTime.parse(time2, fmt1); DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); modelMap.put("warehouseCode", warehouseCode); modelMap.put("beginTime", LocalDateTime.of(localDate, beginTime)); modelMap.put("endTime", LocalDateTime.of(localDate, endTime)); return prefix + "/add"; } /** * 新增保存预约 */ @ApiOperation(value = "新增预约 ", notes = "新增预约 ", httpMethod = "POST") @Log(title = "预约 ", operating = "新增预约 ", action = BusinessType.INSERT) @PostMapping("/add") @ResponseBody public AjaxResult addSave(Reservation reservation, String time1, String time2) { DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss"); reservation.setBeginTime(LocalDateTime.parse(time1)); reservation.setEndTime(LocalDateTime.parse(time2)); return toAjax(reservationService.save(reservation)); } /** * 修改预约 */ @GetMapping("/edit/{id}") public String edit(@PathVariable("id") Integer id, ModelMap mmap) { Reservation reservation = reservationService.getById(id); mmap.put("reservation", reservation); return prefix + "/edit"; } /** * 修改保存预约 */ @ApiOperation(value = "修改预约", notes = "修改预约", httpMethod = "POST") @RequiresPermissions("reservation:edit") @Log(title = "预约 ", operating = "修改预约 ", action = BusinessType.UPDATE) @PostMapping("/edit") @ResponseBody public AjaxResult editSave(Reservation reservation) { return toAjax(reservationService.updateById(reservation)); } @ApiOperation(value = "修改预约状态", notes = "修改预约状态", httpMethod = "POST") @RequiresPermissions("reservation:change") @PostMapping("/change") public AjaxResult changeStatus(Integer id, String status) { LambdaUpdateWrapper<Reservation> updateWrapper = Wrappers.lambdaUpdate(); updateWrapper.eq(Reservation::getId, id) .set(Reservation::getStatus, status); return toAjax(reservationService.update(updateWrapper)); } @ResponseBody @GetMapping("/reservation") public AjaxResult reservation(String localDate, String warehouseCode) { DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd"); LocalDate date2 = LocalDate.parse(localDate, fmt); return AjaxResult.success(reservationService.reservationTime(date2, warehouseCode)); } }