CarDeviceServiceImpl.java 1.34 KB
package com.bsth.service.impl;

import com.bsth.common.ResponseCode;
import com.bsth.entity.CarDevice;
import com.bsth.entity.schedule.rule.RerunRule;
import com.bsth.repository.CarDeviceRepository;
import com.bsth.service.CarDeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by xu on 16/6/15.
 */
@Service
public class CarDeviceServiceImpl extends BaseServiceImpl<CarDevice, Long> implements CarDeviceService {

    @Autowired
    private CarDeviceRepository carDeviceRepository;

    @Transactional
    @Override
    public Map<String, Object> delete(Long aLong) {
        // 获取作废数据
        CarDevice carDevice = carDeviceRepository.findOne(aLong);

        toogleIsCancel(carDevice);

        Map<String, Object> map = new HashMap<>();
        map.put("status", ResponseCode.SUCCESS);

        return map;
    }

    /**
     * 撤销/作废切换。
     * @param rerunRule
     */
    private void toogleIsCancel(CarDevice carDevice) {
        boolean isCancel = carDevice.getIsCancel();
        if (isCancel) {
            carDevice.setIsCancel(false);
        } else {
            carDevice.setIsCancel(true);
        }
    }
}