用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字
云代码 - java代码库

RentBikeServiceImpl.java

2017-03-08 作者: 知行合一心举报

[java]代码库

package com.liang.bike.service.rent;

import com.liang.bike.bean.base.BikeBase;
import com.liang.bike.bean.base.OrderBase;
import com.liang.bike.bean.base.UserBase;
import com.liang.bike.dao.base.*;
import com.liang.bike.enumeration.BikeStatusEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by Administrator on 2017/2/23.
 */
@Service
public class RentBikeServiceImpl implements IRentBikeService {

    @Autowired
    private UserMapper userMapper;

    @Autowired
    private BikeMapper bikeMapper;

    @Autowired
    private BikeBaseMapper bikeBaseMapper;

    @Autowired
    private OrderBaseMapper orderBaseMapper;

    @Autowired
    private OrderMapper orderMapper;

    public UserBase selectUserByUserPhone(UserBase userBase) {
        return userMapper.selectUserByUserPhone(userBase);
    }

    public BikeBase selectBikeByBikeNo(BikeBase bikeBase) {
        return bikeMapper.selectBikeByBikeNo(bikeBase);
    }

    /**
     * 修改自行车使用状态及使用次数
     *
     * @param params
     * @return
     */
    public int updateBikeByStatusTotal(Map<String, Object> params) {
        return bikeMapper.updateBikeStatusTotal(params);
    }

    public void generateOrder(OrderBase orderBase) {
        orderBaseMapper.insertSelective(orderBase);
    }

    /**
     * 租借自行车
     *
     * @param bikeBase
     * @return
     */
    @Transactional
    public void rentBike(BikeBase bikeBase, UserBase userBase) throws Exception {
        //修改自行车使用状态
        Map<String, Object> params = new HashMap<String, Object>();
        Long bikeNo = bikeBase.getBikeNo();
        String bikeStatus = BikeStatusEnum.USING.getKey();
        Long useTotal = bikeBase.getUseTotal();
        Long useTotalAddOne = useTotal + 1;
        String updateBy = userBase.getUserPhone();
        Date updateDate = new Date();
        params.put("bikeNo", bikeNo);
        params.put("bikeStatus", bikeStatus);
        params.put("useTotal", useTotal);
        params.put("useTotalAddOne", useTotalAddOne);
        params.put("updateBy", updateBy);
        params.put("updateDate", updateDate);
        int i = this.updateBikeByStatusTotal(params);
        if (i == 0) {
            throw new Exception("租借自行车失败RentBikeServiceImpl.rentBike");
        }

        OrderBase orderBase = new OrderBase();
        orderBase.setUserId(userBase.getUserId());
        orderBase.setBikeId(bikeBase.getBikeId());
        orderBase.setCreateBy(userBase.getUserPhone());
        orderBase.setCreateDate(new Date());
        orderBase.setUpdateBy(userBase.getUserPhone());
        orderBase.setUpdateDate(new Date());
        orderBase.setReturnBy("");
        this.generateOrder(orderBase);
    }

    @Override
    public OrderBase selectOrder(OrderBase orderBase) {
        return orderMapper.selectOrder(orderBase);
    }

    @Override
    @Transactional
    public void finishOrder(OrderBase orderBase) {
        orderBaseMapper.updateByPrimaryKeySelective(orderBase);
        BikeBase bikeBase = new BikeBase();
        bikeBase.setBikeStatus(BikeStatusEnum.FREE.getKey());
        bikeBase.setBikeId(orderBase.getBikeId());
        bikeBaseMapper.updateByPrimaryKeySelective(bikeBase);
    }
}


网友评论    (发表评论)


发表评论:

评论须知:

  • 1、评论每次加2分,每天上限为30;
  • 2、请文明用语,共同创建干净的技术交流环境;
  • 3、若被发现提交非法信息,评论将会被删除,并且给予扣分处理,严重者给予封号处理;
  • 4、请勿发布广告信息或其他无关评论,否则将会删除评论并扣分,严重者给予封号处理。


扫码下载

加载中,请稍后...

输入口令后可复制整站源码

加载中,请稍后...