package nccloud.openapi.ic.m47;

import nc.bs.framework.common.NCLocator;
import nc.vo.ic.m47.entity.SubcontInVO;
import nc.vo.scmpub.res.billtype.ICBillType;
import nc.ws.opm.pub.utils.result.APIErrCodeEnum;
import nccloud.api.ic.m47.IAPISubcontInMaintain;
import nccloud.api.rest.utils.ResultMessageUtil;
import nccloud.openapi.ic.util.ICAPILocationVOUtils;
import nccloud.openapi.scmpub.pub.NCCPubRestResource;
import nccloud.openapi.scmpub.pub.TransferMapToVOTool;
import org.json.JSONString;

import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @Classname SubcontInResource
 * @Description TODO
 * @Version 1.0.0
 * @Date 2025/5/15 8:54
 * @Created by sdlizheng
 */
@Path("ic/subcontin")
public class SubcontInResource extends NCCPubRestResource {

    private static String HEADTABLE = "ic_subcontin_h";
    private static String BODYTABLE = "ic_subcontin_b";

    @POST
    @Path("operation/save")
    @Consumes({"application/json"})
    @Produces({"application/json"})
    public JSONString save(Map<String, Object> param) {
        List<Map<String, Object>> paramList = new ArrayList();
        paramList.add(param);
        JSONString result = this.save(paramList);
        return result;
    }
    @POST
    @Path("save")
    @Consumes({"application/json"})
    @Produces({"application/json"})
    public JSONString save(List<Map<String, Object>> paramList){
        try {
            for (Map<String, Object> map : paramList) {
                if (!map.containsKey(HEADTABLE) || !map.containsKey(BODYTABLE)) {
                    return ResultMessageUtil.exceptionToJSON("传入数据异常，参数要包含表头信息和表体信息", APIErrCodeEnum.BUSINESSEXCCODE.getCode());
                }
            }
            SubcontInVO[] save = NCLocator.getInstance().lookup(IAPISubcontInMaintain.class).save(paramList);
            return ResultMessageUtil.toJSON(save, "保存成功");
        }catch (Exception e){
            return ResultMessageUtil.exceptionToJSON(e);
        }

    }
}
