package com.engine.common.web;


import com.engine.common.service.CommonService;
import com.engine.common.service.impl.CommonServiceImpl;
import com.engine.common.util.ApiReturnTools;
import com.engine.common.util.ParamUtil;
import com.engine.common.util.ServiceUtil;
import lombok.extern.slf4j.Slf4j;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
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.Context;
import java.util.Map;

@Slf4j
public class CommonAction {


    private CommonService basicsetService = ServiceUtil.getService(CommonServiceImpl.class);

    /**
     * tableName  表名
     * columns    查询的列名
     * conditions 查询条件
     * orderby 排序及limit
     * @return
     */
    @GET
    @Path("/queryCommon")
    @Produces({"text/plain"})
    public String getBasicSetInformation(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        try {
            Map<String,Object> paramMap = ParamUtil.request2Map(request);
            Map<String,Object> dataMap = basicsetService.queryCommon(paramMap);
            return ApiReturnTools.success(dataMap);
        }catch (Exception e){
            log.error("sync fund status fail,catch error: [{}]",e);
            return ApiReturnTools.error("200","查询失败");
        }
    }

//    /**
//     * @return
//     */
//    @POST
//    @Path("/updateCommon")
//    @Produces({"text/plain"})
//    public String updateCommon(@Context HttpServletRequest request, @Context HttpServletResponse response) {
//        try {
//            Map<String,Object> paramMap = ParamUtil.request2Map(request);
//            Map<String,Object> dataMap = basicsetService.updateCommon(paramMap);
//            return ApiReturnTools.success(dataMap);
//        }catch (Exception e){
//            log.error("sync fund status fail,catch error: [{}]",e);
//            return ApiReturnTools.error("500","修改失败");
//        }
//    }
    /**
     * @return
     */
    @POST
    @Path("/insertCommon")
    @Produces({"text/plain"})
    public String insertCommon(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        try {
            Map<String,Object> paramMap = ParamUtil.request2Map(request);
            Map<String,Object> dataMap = basicsetService.insertCommon(paramMap);
            return ApiReturnTools.success(dataMap);
        }catch (Exception e){
            log.error("sync fund status fail,catch error: [{}]",e);
            return ApiReturnTools.error("500","新增");
        }
    }



}
