package com.engine.htxc.cggl.web;

import com.alibaba.fastjson.JSON;
import com.engine.common.util.ServiceUtil;
import com.engine.htxc.cggl.service.CgglService;
import com.engine.htxc.cggl.service.impl.CgglServiceImpl;
import com.engine.htxc.common.EcologyResponseDTO;
import lombok.extern.slf4j.Slf4j;
import weaver.workflow.logging.Logger;
import weaver.workflow.logging.LoggerFactory;

import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import java.util.HashMap;
import java.util.Map;


/**
 * @Title: ecology-9
 * @Company: 泛微软件
 * @author: K1810039
 * @version: 1.0
 * @CreateDate: 2022-08-25 16:12
 * @Description:
 * @ModifyLog:
 **/
@Slf4j
public class CgglAction {
    CgglService getService(){
        return (CgglService) ServiceUtil.getService(CgglServiceImpl.class);
    }
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @POST
    @Path("/convertLxxm")
    @Produces({MediaType.TEXT_PLAIN})
    public String convertLxxm(Map<String, Object> paramsMap){
        logger.info("it立项action参数："+paramsMap);
        Map<String, Object> apidatas = new HashMap<String, Object>();
        logger.info("----convertLxxm-----");
        try{
            //Map<String,Object> param = ParamUtil.request2Map(request);
            apidatas = getService().insertLxxm(paramsMap);
            apidatas.put("api_status", true);
        }catch (Exception e) {
            e.printStackTrace();
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
        }
        return JSON.toJSONString(apidatas);
    }

    @POST
    @Path("/convertCgxm")
    @Produces({MediaType.TEXT_PLAIN})
    public String convertCgxm(Map<String, Object> paramsMap){
        logger.info("采购项目action参数："+paramsMap);
        Map<String, Object> apidatas = new HashMap<String, Object>();
        logger.info("----convertCgxm-----");
        try{
            apidatas = getService().insertCgxm(paramsMap);
            apidatas.put("api_status", true);
        }catch (Exception e) {
            e.printStackTrace();
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
        }
        return JSON.toJSONString(apidatas);
    }

    @POST
    @Path("/itcgConvertCgxm")
    @Produces({MediaType.TEXT_PLAIN})
    public String itcgConvertCgxm(Map<String, Object> paramsMap){
        logger.info("it采购转建模action参数："+paramsMap);
        Map<String, Object> apidatas = new HashMap<String, Object>();
        logger.info("----itcgConvertCgxm-----");
        try{
            apidatas = getService().itcgInsertCgxm(paramsMap);
            apidatas.put("api_status", true);
        }catch (Exception e) {
            e.printStackTrace();
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
        }
        return JSON.toJSONString(apidatas);
    }

    @GET
    @Path("/getModeUrl")
    @Produces({MediaType.TEXT_PLAIN})
    public String getModeUrl(){
        Map<String, Object> apidatas = new HashMap<String, Object>();
        log.info("----getModeUrl----");
        try{
            String url = getService().getModeUrl();
            log.info("返回数据：[{}]",url);
            return EcologyResponseDTO.successJson(url);
        }catch (Exception e) {
            log.error("getModeUrl接口异常:",e);
            return EcologyResponseDTO.failJson("接口异常请检查");
        }
    }

}

