首页>代码>基于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;
        }
    }


}
最近下载更多
小松哥11  LV3 2024年10月24日
wuying8208  LV15 2024年10月23日
微信网友_6917967074955264  LV2 2024年3月30日
微信网友_6900009262157824  LV1 2024年3月9日
WBelong  LV8 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日
最近浏览更多
lkke23047  LV1 5月28日
niuwa666 4月3日
暂无贡献等级
ryadmin123  LV2 2月11日
Mhgfhjyrf  LV3 2024年12月9日
zolscy  LV24 2024年11月28日
微笑刺客  LV21 2024年11月22日
小松哥11  LV3 2024年10月24日
wuying8208  LV15 2024年10月23日
3339790961 2024年9月6日
暂无贡献等级
yyhrhv  LV8 2024年9月3日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友