package com.persagy.adm.server.delivery.controller;

import com.alibaba.fastjson.JSONObject;
import com.persagy.adm.server.delivery.service.AdmDeliverPlanService;
import com.persagy.adm.steward.basic.utils.RSAUtils;
import com.persagy.adm.steward.entity.ProjectDeliverReq;
import com.persagy.dmp.common.model.response.CommonResult;
import com.persagy.dmp.common.utils.ResultHelper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
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.ArrayList;
import java.util.List;

/**
 * 02-交付计划入口
 * 后端服务名:adm-server
 * @author : lijie
 * Update By 2022/1/12 14:01
 */
@RestController
@RequestMapping("/deliver/plan")
@RequiredArgsConstructor
@Slf4j
public class AdmDeliverPlanController {

    private final AdmDeliverPlanService admDeliverPlanService;

    @Value("${adm.rsa.privateKey}")
    private String privateKey;

    /**
     * 020101-交付计划-处理BOSS产生的交付计划
     * @param projectDeliverReqStr : 交付计划信息
     * @return : com.persagy.dmp.common.model.response.CommonResult<java.util.List<java.lang.Void>>
     * @author : lijie
     * Update By 2022/1/14 17:22
     */
    @PostMapping(value = "/relayDeliverPlan")
    public CommonResult<List<Void>> relayDeliverPlan(@RequestBody String projectDeliverReqStr) {
        //todo 测试
        String decode = RSAUtils.decode(projectDeliverReqStr, privateKey);
        log.info("接受BOSS产生的交付计划入参：{}"+decode);
        ProjectDeliverReq projectDeliverReq = JSONObject.parseObject(decode, ProjectDeliverReq.class);
        admDeliverPlanService.relayDeliverPlan(projectDeliverReq);
        return ResultHelper.multi(new ArrayList<>());
    }


}
