package com.securitycontrol.background.service.impl;

import com.securitycontrol.background.mapper.EarlyWarningsRecordMapper;
import com.securitycontrol.background.service.EarlyWarningsRecordService;
import com.securitycontrol.entity.background.vo.EarlyWarningsRecordVo;
import com.securitycontrol.common.core.web.domain.AjaxResult;
import com.securitycontrol.common.security.utils.SecurityUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import javax.annotation.Resource;
import java.util.*;

/**
 * 施工质量 - 预警记录
 * @author lsun
 */
@Service(value = "EarlyWarningsRecordService")
@Slf4j
public class EarlyWarningsRecordServiceImpl implements EarlyWarningsRecordService {

    @Resource(name = "EarlyWarningsRecordMapper")
    private EarlyWarningsRecordMapper mapper;

    @Override
    public List<EarlyWarningsRecordVo> getEarlyWarningRecordLists(EarlyWarningsRecordVo dto) {
        List<EarlyWarningsRecordVo> list = new ArrayList<>();
        list = mapper.getEarlyWarningsRecordLists(dto);
        return list;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public AjaxResult updEarly(EarlyWarningsRecordVo vo) {
        String userId = SecurityUtils.getLoginUser().getUserid() +"";
        vo.setUserId(userId);
        try {
            mapper.updEarly(vo);
        } catch (Exception e) {
            log.error("预警处置", e);
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return AjaxResult.error();
        }
        return AjaxResult.success();
    }

}
