package com.sunyo.wlpt.dispatch.controller; import com.github.pagehelper.PageInfo; import com.sunyo.wlpt.dispatch.domain.DispatchNote; import com.sunyo.wlpt.dispatch.domain.VehicleInfo; import com.sunyo.wlpt.dispatch.response.ResultJson; import com.sunyo.wlpt.dispatch.service.DispatchNoteService; import com.sunyo.wlpt.dispatch.service.VehicleInfoService; import com.sunyo.wlpt.dispatch.utils.DateTimeUtils; import com.sunyo.wlpt.dispatch.utils.GetUUID; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.propertyeditors.CustomDateEditor; import org.springframework.web.bind.WebDataBinder; import org.springframework.web.bind.annotation.*; import java.text.SimpleDateFormat; import java.util.Date; /** * @author 子诚 * Description: * 时间:2020/4/24 20:30 */ @CrossOrigin @Api(value = "调度记录信息,业务", tags = "业务管理——车辆调度记录信息") @RequestMapping("dispatch/dispatchNote") @RestController public class DispatchNoteController { @Autowired private DispatchNoteService dispatchNoteService; @Autowired private VehicleInfoService vehicleInfoService; @ApiOperation("分页查询,调度记录信息列表") @GetMapping("/selectDispatchNoteList") public ResultJson<PageInfo> selectDispatchNoteList( @ApiParam(name = "userName", value = "用户姓名", required = false) @RequestParam(value = "userName", required = false) String userName, @ApiParam(name = "userMobile", value = "用户联系方式", required = false) @RequestParam(value = "userMobile", required = false) String userMobile, @ApiParam(name = "dispatchType", value = "业务类型", required = false) @RequestParam(value = "dispatchType", required = false) String dispatchType, @ApiParam(name = "gmtCreate", value = "任务创建时间", required = false) @RequestParam(value = "gmtCreate", required = false) Date gmtCreate, @ApiParam(name = "endTime", value = "任务结束时间", required = false) @RequestParam(value = "endTime", required = false) Date endTime, @ApiParam(name = "status", value = "调度记录表状态:1.完成状态;2.执行状态;3、取消(撤销)状态", required = false) @RequestParam(value = "status", required = false) String status, @ApiParam(name = "pageNum", value = "第几页,默认为第一页", required = false) @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum, @ApiParam(name = "pageSize", value = "每页数量,默认10条", required = false) @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) { ResultJson<PageInfo> result = new ResultJson<>(); DispatchNote dispatchNote = new DispatchNote(); /** * 用户端查询,需要四个参数: * 1.用户姓名(前端必填);2.用户电话(前端必填);3.业务类型;4.创建时间 * * 管理员端查询,需要六个参数(没有必填): * 1.用户姓名;2.用户电话;3.创建时间;4.完成时间 * 5.业务类型;6.记录状态 */ //获取参数,用户姓名 dispatchNote.setUserName(userName); //获取参数,用户联系方式 dispatchNote.setUserMobile(userMobile); //获取参数,业务类型 dispatchNote.setDispatchType(dispatchType); //获取参数,创建时间 dispatchNote.setGmtCreate(gmtCreate); //获取参数,记录表状态 dispatchNote.setStatus(status); //获取参数,任务结束(完成)时间 dispatchNote.setEndTime(endTime); PageInfo pageInfo = dispatchNoteService.selectDispatchNoteList(dispatchNote, pageNum, pageSize); if (pageInfo.getTotal() > 0) { result.setData(pageInfo); result.setMsg("查询调度记录,成功"); } else { result.setCode("400"); result.setMsg("查询调度记录,失败"); } return result; } @ApiOperation("删除调度记录信息") @DeleteMapping("/deleteDispatchNote") public ResultJson<DispatchNote> deleteDispatchNote(@RequestBody DispatchNote dispatchNote) { ResultJson<DispatchNote> result = new ResultJson<>(); /** * 如果调度记录为执行状态("2") * 则将对应车辆的状态,修改为空闲状态("1"),并设置开始空闲时间 */ String status = "2"; if (status.equals(dispatchNote.getStatus())) { String licensePlateNumber = dispatchNote.getLicensePlateNumber(); //根据车牌号查询到车辆信息 VehicleInfo vehicleInfo = vehicleInfoService.selectByLPN(licensePlateNumber); //设置车辆信息表,为空闲状态(1) vehicleInfo.setVehicleStatus("1"); //设置车辆信息,开始空闲时间 vehicleInfo.setFreetime(new Date()); //根据主键,选择性修改 vehicleInfoService.updateByPrimaryKeySelective(vehicleInfo); } int num = dispatchNoteService.deleteByPrimaryKey(dispatchNote.getId()); if (num > 0) { result.setMsg("删除调度记录信息,成功"); } else { result.setCode("400"); result.setMsg("删除调度记录信息,失败"); } return result; } @ApiOperation("编辑调度记录信息") @PutMapping("/updateDispatchNote") public ResultJson<DispatchNote> updateDispatchNote(@RequestBody DispatchNote dispatchNote) { ResultJson<DispatchNote> result = new ResultJson<>(); //设置调度记录,操作类型,修改(2) dispatchNote.setOperation("2"); int num = dispatchNoteService.updateByPrimaryKeySelective(dispatchNote); if (num > 0) { result.setMsg("修改调度记录信息,成功"); } else { result.setCode("400"); result.setMsg("修改调度记录信息,失败"); } return result; } @ApiOperation("增加调度记录信息") @PostMapping("/insertDispatchNote") public ResultJson<DispatchNote> insertDispatchNote(@RequestBody DispatchNote dispatchNote) { ResultJson<DispatchNote> result = new ResultJson<>(); //设置调度记录,id值(uuid) dispatchNote.setId(GetUUID.getuuid()); //设置调度记录,车辆数量为1辆 dispatchNote.setVehicleNumber(1); //设置调度记录,操作类型,新增(1) dispatchNote.setOperation("1"); int num = dispatchNoteService.insertSelective(dispatchNote); if (num > 0) { result.setMsg("添加调度记录信息,成功"); } else { result.setCode("400"); result.setMsg("添加调度记录信息,失败"); } return result; } @InitBinder public void initBinder(WebDataBinder binder) { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); dateFormat.setLenient(false); binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true)); } }