package com.rongwei.savecheck.controller;

import com.rongwei.rwcommon.base.R;
import com.rongwei.rwcommon.utils.StringUtils;
import com.rongwei.sfcommon.sys.service.SynchronizationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 危险同步
 *
 * @author chglee
 * @email 1992lcg@163.com
 * @date 2020-07-17 09:33:23
 */
@RestController
@RequestMapping("/sync")
@Slf4j
public class SynchronizationController {

    @Autowired
    private SynchronizationService riskSynchronizationList;

    /**
     * 四色图和分布信息同步
     *
     */
    @PostMapping("/fourColor/upload")
    public R riskSynchronizationList(@RequestBody List<String> ids) {
        try {
            riskSynchronizationList.fourColorSynchronizationList(ids);
            return R.ok();
        } catch (Exception e) {
            e.printStackTrace();
            log.error(StringUtils.spliceErrorMsg(e), e.fillInStackTrace());
            return R.error();
        }
    }

    /**
     * 单元、事件和措施信息同步
     *
     */
    @PostMapping("/unit/upload")
    public R UnitSynchronizationList(@RequestBody List<String> ids) {
        try {
            riskSynchronizationList.unitSynchronizationList(ids);
            return R.ok();
        } catch (Exception e) {
            e.printStackTrace();
            log.error(StringUtils.spliceErrorMsg(e), e.fillInStackTrace());
            return R.error();
        }
    }

    /**
     * 安全维护信息同步
     *
     */
    @PostMapping("/safeMaintenance/upload")
    public R SafeMaintenanceSynchronizationList(@RequestBody List<String> ids) {
        try {
            riskSynchronizationList.safeMaintenanceSynchronizationList(ids);
            return R.ok();
        } catch (Exception e) {
            e.printStackTrace();
            log.error(StringUtils.spliceErrorMsg(e), e.fillInStackTrace());
            return R.error();
        }
    }

    /**
     * 安全检查记录信息同步
     *
     */
    @PostMapping("/safeRecord/upload")
    public R SafeRecordSynchronizationList(@RequestBody List<String> ids) {
        try {
            riskSynchronizationList.safeRecordSynchronizationList(ids);
            return R.ok();
        } catch (Exception e) {
            e.printStackTrace();
            log.error(StringUtils.spliceErrorMsg(e), e.fillInStackTrace());
            return R.error();
        }
    }
}
