首页>代码>基于ssm+layui开发汽车租赁管理系统 >/carRental/src/main/java/com/alfred/bus/controller/RentController.java
package com.alfred.bus.controller;

import com.alfred.bus.domain.Customer;
import com.alfred.bus.mapper.CustomerMapper;
import com.alfred.bus.service.CustomerService;
import com.alfred.bus.service.RentService;
import com.alfred.bus.vo.RentVo;
import com.alfred.sys.constant.SysConstant;
import com.alfred.sys.domain.User;
import com.alfred.sys.utils.DataGridView;
import com.alfred.sys.utils.RandomUtils;
import com.alfred.sys.utils.ResultObj;
import com.alfred.sys.utils.WebUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 *汽车出租管理的控制器
 * @author Alfred
 * @date 2020/3/5 12:24
 */
@RestController
@RequestMapping("rent")
public class RentController {

    @Autowired
    private RentService rentService;

    @Autowired
    private CustomerService customerService;

    /**
     *检查身份证号是否存在
     * @param rentVo
     * @return
     */
    @RequestMapping("checkCustomerExist")
    public ResultObj checkCustomerExist(RentVo rentVo){
        Customer customer = customerService.queryCustomerByIdentity(rentVo.getIdentity());
        if(customer!=null){
            return ResultObj.STATUS_TRUE;
        }else {
            return ResultObj.STATUS_FALSE;
        }

    }

    /**
     * 初始化添加出租单的表单的数据
     * @param rentVo
     * @return
     */
    @RequestMapping("initRentFrom")
    public RentVo initRentFrom(RentVo rentVo){
    //生成出租单号
    rentVo.setRentid(RandomUtils.createRandomStringUseTime(SysConstant.CAR_ORDER_CZ));
    //设置起租时间
    rentVo.setBegindate(new Date());
    //设置操作员
    User user = (User) WebUtils.getHttpSession().getAttribute("user");
    rentVo.setOpername(user.getRealname());
    return rentVo;
    }
    /**
     * 保存出租单信息
     * @param rentVo
     * @return
     */
    @RequestMapping("saveRent")
    public ResultObj saveRent(RentVo rentVo) {
        try {
            //设置创建时间
            rentVo.setCreatetime(new Date());
            //设置归还状态
            rentVo.setRentflag(SysConstant.RENT_BACK_FALSE);
            //保存
            this.rentService.addRent(rentVo);
            return ResultObj.ADD_SUCCESS;
        } catch (Exception e) {
            e.printStackTrace();
            return ResultObj.ADD_ERROR;
        }
    }

    /******************出租单管理*******************/
    /**
     * 查询
     */
    @RequestMapping("loadAllRent")
    public DataGridView loadAllRent(RentVo rentVo){
        return this.rentService.queryAllRent(rentVo);
    }

    /**
     * 删除出租单信息
     * @param rentVo
     * @return
     */
    @RequestMapping("deleteRent")
    public ResultObj deleteRent(RentVo rentVo){
        try {
            //删除
            this.rentService.deleteRent(rentVo.getRentid());
            return ResultObj.DELETE_SUCCESS;
        }catch (Exception e){
            e.printStackTrace();
            return ResultObj.DELETE_ERROR;
        }
    }

    /**
     * 修改出租单信息
     * @param rentVo
     * @return
     */
    @RequestMapping("updateRent")
    public ResultObj updateRent(RentVo rentVo){
        try {
            //修改
            this.rentService.updateRent(rentVo);
            return ResultObj.UPDATE_SUCCESS;
        }catch (Exception e){
            e.printStackTrace();
            return ResultObj.UPDATE_ERROR;
        }
    }


}
最近下载更多
WBelong  LV7 2023年12月25日
dzlwindy  LV8 2023年12月18日
angel_yy  LV2 2023年8月11日
homework333  LV1 2023年7月10日
sunshinemenfolk  LV4 2023年7月5日
GJQ123  LV4 2023年6月5日
飞翔的面包片  LV12 2023年5月8日
daviskren  LV2 2023年4月17日
最近浏览更多
全栈小白  LV33 3月26日
songsmm  LV1 3月11日
zzynbnb 3月9日
暂无贡献等级
eagerwujin  LV4 3月5日
暂无贡献等级
admin_z  LV22 1月29日
雪小鼬 1月3日
暂无贡献等级
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友