package com.foreverwin.mesnac.integration.controller;


import com.foreverwin.mesnac.integration.model.IntegrationLog;
import com.foreverwin.mesnac.integration.service.IntegrationLogService;
import com.foreverwin.modular.core.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 *
 * @author Leon.L
 * @since 2021-06-16
 */
@RestController
@RequestMapping("/Z-INTEGRATION-LOG")
public class IntegrationLogController {
    @Autowired
    private IntegrationLogService integrationLogService;
    @ResponseBody
    @PostMapping("redoSend")
    public R shopOrderRelease(@RequestBody List<IntegrationLog> integrationLogs) {
        StringBuffer stringBuffer = new StringBuffer("");
        for (IntegrationLog integrationLog: integrationLogs) {
            try {
                String str = integrationLogService.redoSend(integrationLog.getHandle());
                if (str != null){
                    stringBuffer.append(str + ";");
                }
            }catch (Exception e){
                return R.failed("重发失败：" + e.getMessage());
            }
        }
        if (stringBuffer.toString().equals("")){
            return R.ok();
        }
        return R.failed(stringBuffer);
    }

}