TTInfoServiceImpl.java 1.28 KB
package com.bsth.service.schedule;

import com.bsth.common.ResponseCode;
import com.bsth.entity.schedule.TTInfo;
import com.bsth.repository.schedule.TTInfoRepository;
import com.bsth.service.impl.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.stereotype.Service;

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

/**
 * Created by xu on 16/5/12.
 */
@Service
@Transactional
public class TTInfoServiceImpl extends BaseServiceImpl<TTInfo, Long> implements TTInfoService {
    @Autowired
    private TTInfoRepository ttInfoRepository;

    @Override
    public Map<String, Object> delete(Long aLong) {
        TTInfo ttInfo = ttInfoRepository.findOne(aLong);
        ttInfo.setIsCancel(true);

        Map<String, Object> map = new HashMap<>();
        try{
            ttInfoRepository.save(ttInfo);
            map.put("status", ResponseCode.SUCCESS);
        }catch(DataIntegrityViolationException de){
            map.put("status", ResponseCode.ERROR);
            map.put("msg", "“完整性约束”校验失败,请检查要删除的对象是否存在外键约束");
        }
        return map;
    }
}