package com.cf.imes.module.system.api.application;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.cf.imes.module.system.dal.dataobject.application.ApplicationDO;
import com.cf.imes.module.system.service.application.ApplicationService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

import java.util.Map;

import static com.cf.imes.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.cf.imes.module.system.enums.ErrorCodeConstants.APPLICATION_NOT_EXISTS;

@RestController // 提供 RESTful API 接口，给 Feign 调用
@Validated
public class ApplicationApiImpl implements ApplicationApi{

    @Resource
    private ApplicationService applicationService;

    @Override
    public JSONObject getApplicationByOrganId(Long organId) {
//        获取数值
        ApplicationDO applicationDO = applicationService.getApplicationByOrganId(organId);
        if (applicationDO == null){
            throw exception(APPLICATION_NOT_EXISTS);
        }
//        数据转json
        JSONObject jsonObject = (JSONObject) JSONObject.toJSON(applicationDO);
        System.out.println(" jsonObject " + jsonObject);
        return jsonObject;
    }
}
