package digital.laboratory.platform.entrustment.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import digital.laboratory.platform.common.core.util.R;
import digital.laboratory.platform.othersys.dto.EntrustQueryParams;
import digital.laboratory.platform.entrustment.entity.EntrustOfThirdSys;
import digital.laboratory.platform.entrustment.entity.Entrustment;
import digital.laboratory.platform.entrustment.service.*;
import digital.laboratory.platform.sys.feign.RemoteDictionaryService;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName SynchronizeDataController
 * @Description 用于将第三方禁毒数据进行同步和回写的操作
 * @Author xy
 * @Date 2023/6/05 9:07
 * @Version 1.0
 **/
@RestController
@RequestMapping("/papp/entrustment/synchronizeData")
@RequiredArgsConstructor
@Api(value = "数据同步处理接口", tags = "数据同步处理接口")
public class SynchronizeDataController {
    private  final RemoteDictionaryService remoteDictionaryService;//字典接口
    private  final SynchronizeDataService  synchronizeDataService;
    //获取数据接口全部写到这里
    /**
     * 获取远程系统中的委托数据接口
     * @return
     */
    @GetMapping("/getRemoteEntrustData")
    public R handleRemoteData(String entrustStatus) {
        String requestEntrustStatus=StringUtils.isNotBlank(entrustStatus)?entrustStatus:"provinceAuditing";
        return R.ok(synchronizeDataService.synEntrustDataToMyServer(requestEntrustStatus,"SubCenter"),"数据同步完成");
    }
    //省级审核接口 //分中心审核
    @GetMapping("/provinceAudit")
    public  R provinceAudit(String userFlag,String entrustID){
        //String entrustID="WEFHTXRoQXdVRmM5K1U0N1U0NGI2NUFoMzZOQUhzaTE=";
        //String userFlag="Province";//Province或者SubCenter
        String dataPath="/api/identify/entrust/{entrustId}/acceptAudit";
        //String auditOrAccept="Audit";
        try {
            return R.ok(synchronizeDataService.auditEntrustByProvinceOrCenter(userFlag,dataPath,entrustID,"success",
                    "",""),"操作成功");
        }catch (Exception e)
        {
            e.printStackTrace();
            return R.ok("","处理失败");
        }

    }
    //新增加一个接口用于同步已受理的数据
    @GetMapping("/getRemoteAcceptedEntrustData")
    public R getRemoteAcceptedEntrustData(EntrustQueryParams entrustQueryParams) {
        //String requestEntrustStatus=StringUtils.isNotBlank(entrustStatus)?entrustStatus:"provinceAuditing";
        //return R.ok(synchronizeDataService.synEntrustDataToMyServer(requestEntrustStatus,"SubCenter"),"数据同步完成");
        return R.ok(synchronizeDataService.synAcceptedEntrustDataToMyServer(entrustQueryParams),"数据同步完成");
        //return R.ok(entrustQueryParams);
    }
    //分中心受理接口
    @GetMapping("/subCenterAccept")
    public  R subCenterAccept() throws JsonProcessingException {
        String entrustID="WEFHTXRoQXdVRmM5K1U0N1U0NGI2NUFoMzZOQUhzaTE=";
        String dataPath="/api/identify/entrust/{entrustId}/accept";
        Entrustment selfEntrust=new Entrustment();
        EntrustOfThirdSys thirdSysEntrust=new EntrustOfThirdSys();
        return R.ok(synchronizeDataService.subCenterAccept(dataPath,selfEntrust,thirdSysEntrust),"操作成功");
    }
    //分中心上传鉴定数据接口
    @GetMapping("/subCenterUploadData")
    public  R subCenterUploadData(){
        String dataPath="/api/identify/entrust/{entrustId}/analysis";
        String entrustId="";
        return R.ok(synchronizeDataService.submitIdentifyResult(dataPath,entrustId),"操作成功");
    }
}
