RerunServiceImpl.java 1.33 KB
package com.bsth.service.schedule;

import com.bsth.common.ResponseCode;
import com.bsth.entity.schedule.rule.RerunRule;
import com.bsth.repository.schedule.RerunRuleRepository;
import com.bsth.service.impl.BaseServiceImpl;
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/10/20.
 */
@Service
public class RerunServiceImpl extends BaseServiceImpl<RerunRule, Long> implements RerunService {

    @Autowired
    private RerunRuleRepository rerunRuleRepository;

    @Override
    @Transactional
    public Map<String, Object> delete(Long aLong) {
        // 获取带作废的数据
        RerunRule rerunRule = rerunRuleRepository.findOne(aLong);

        toogleIsCancel(rerunRule);

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

        return map;

    }

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