java接口对接——别人调用我们接口获取数据

java接口对接——别人调用我们接口获取数据,我们需要在我们系统中开发几个接口,给对方接口规范文档,包括访问我们的接口地址,以及入参名称和格式,还有我们的返回的状态的情况,

接口代码:

package com.xx.xxx.yzyhentity.action;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;

import org.atmosphere.plugin.redis.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xxx.basic.auditproject.auditprojectmaterial.domain.AuditProjectMaterial;
import com.xxx.common.util.JsonUtils;
import com.xxx.core.xxxFrameDsManager;
import com.xxx.core.dao.CommonDao;
import com.xxx.core.grammar.Record;
import com.xxx.database.jdbc.config.SplitTableConfig;
import com.xxx.frame.service.attach.entity.FrameAttachInfo;
import com.xxx.frame.service.metadata.code.api.ICodeItemsService;
import com.xxx.frame.service.metadata.code.entity.CodeItems;
import com.xxx.frame.service.metadata.sharding.util.ShardingUtil;
import com.xxx.ycsrh.api.AuditBkaccFeedback;

@RestController
@RequestMapping("bkacc")
public class RestfulToSzzwzx
{

    @Autowired
    private ICodeItemsService iCodeItemsService;

    /**
     * 政务中心获取股东信息接口
     * @param param
     * @return
     * @exception/throws [违例类型] [违例说明]
     * @see [类、类#方法、类#成员]
     */

    @SuppressWarnings("unused")
    @RequestMapping(value = "/getSZzwzxOpenShareHolders", method = RequestMethod.POST)
    public String getSZzwzxOpenShareHolders(@RequestBody String param) {
        //返回JSON值
        JSONObject userareaJson = new JSONObject();
        String result = "";
        try {
            xxxFrameDsManager.begin(null);
            // 参数转化为json对象
            JSONObject jsonObject = (JSONObject) JSONObject.parse(param);
            // 时间格式化
            SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            // token验证
            String token = jsonObject.getString("token");
            if (GXConstant.checkToken(token)) {
                JSONObject params = (JSONObject) jsonObject.get("params");
                // 业务标识(与开户申请时推送的ywguid一致)
                String ywguid = params.getString("ywguid");
                // 获取股东信息列表
//                List<Record> listGD = iShareform.getGDTableInfo(ywguid);
                List<Record> listGD = null;
                if (listGD != null && listGD.size() > 0) {
                    JSONArray jsonArray = new JSONArray();
                    for (Record rec : listGD) {
                        JSONObject gdJson = new JSONObject();
                        // 股东姓名
                        gdJson.put("shareholdernmae", rec.get("Ctrl1"));
                        // 证件类型
                        String idtype = rec.get("Ctrl2"); 
                        if(StringUtil.isNotBlank(idtype)){
                            CodeItems codeItems = iCodeItemsService.getCodeItemByCodeName("内资企业身份证件类型", idtype);
                            if(codeItems!=null && StringUtil.isNotBlank(codeItems.getDmAbr1())){ 
                                gdJson.put("idtype", codeItems.getDmAbr1());
                                
                            }
                            else{
                                gdJson.put("idtype", idtype); 
                            } 
                        }
                        
                        // 证件号码 
                        gdJson.put("idno", rec.get("Ctrl3"));
                        // 出资时间
                        gdJson.put("contributivedate", sdf2.format(rec.get("Ctrl4")));
                        // 出资方式
                        gdJson.put("contributivetype", rec.get("Ctrl9"));
                        // 认缴出资额
                        gdJson.put("contributivenum", rec.get("Ctrl5"));
                        // 认缴出资比例
                        gdJson.put("contributivepercent", rec.get("Ctrl7"));
                        jsonArray.add(gdJson);
                        userareaJson.put("userarea", jsonArray);
                    }
                    result = JsonUtils.zwdtRestReturn("1", "获取股东信息接口调用成功!", userareaJson);
                } else {
                    result = JsonUtils.zwdtRestReturn("0", "接口调用成功,但未查到相关股东数据信息!", userareaJson);
                }
            } else {
                result = JsonUtils.zwdtRestReturn("0", "接口调用失败,原因是:token验证失败!", userareaJson);
            }

        }
        catch (Exception e) {
            e.printStackTrace();
            xxxFrameDsManager.rollback();
            result = JsonUtils.zwdtRestReturn("0", "接口调用失败,原因是:" + e.toString(), userareaJson);
        }
        finally {
            xxxFrameDsManager.close();
        }
        return result;
    }

    /**
     *  市政务中心获取开户申请材料接口
     *  @param param
     *  @return    
     * @exception/throws [违例类型] [违例说明]
     * @see [类、类#方法、类#成员]
     */
    @RequestMapping(value = "/getSZzwzxOpenAcountMaterials", method = RequestMethod.POST)
    public String getSZzwzxOpenAcountMaterials(@RequestBody String param) {
        // 返回JSON值
        JSONObject userareaJson = new JSONObject();
        // 材料内son
        JSONObject materialJson = new JSONObject();
        String result = "";
        try {
            xxxFrameDsManager.begin(null);
            // 参数转化为json对象
            JSONObject jsonObject = (JSONObject) JSONObject.parse(param);
            // token验证
            String token = jsonObject.getString("token");
            if (GXConstant.checkToken(token)) {
                boolean flag = false;
                JSONObject params = (JSONObject) jsonObject.get("params");
                JSONArray materialsArray = new JSONArray();
                // 业务标识(与开户申请时推送的ywguid一致)
                String ywguid = params.getString("ywguid");
                if (StringUtil.isNotBlank(ywguid)) {
                    
                    // 获取流程提交得材料
                    SplitTableConfig conf = ShardingUtil.getSplitTableConfig("audit_project_material");
                    CommonDao fbMaterialDao = CommonDao.getInstance(conf);
                    String sql = "SELECT * FROM audit_project_material WHERE PROJECTGUID='"+ywguid+"' AND status >10 ";
                    List<AuditProjectMaterial>  projectMaterialList = new ArrayList<AuditProjectMaterial>();
                    projectMaterialList = fbMaterialDao.findList(sql, AuditProjectMaterial.class);
                    if(projectMaterialList != null && projectMaterialList.size()>0){
                        for(AuditProjectMaterial auditProjectMaterial : projectMaterialList){
                            
                            // 获取流程提交得材料附件
                            String sql2 = "SELECT * FROM frame_attachinfo WHERE CLIENGGUID = '"+auditProjectMaterial.getCliengguid()+"';";
                            List<FrameAttachInfo> attachInfoList = CommonDao.getInstance().findList(sql2, FrameAttachInfo.class);
                            if (attachInfoList != null && attachInfoList.size() > 0) {
                                // 材料内Json
                                JSONObject fileinfoJson = new JSONObject();
                                fileinfoJson.put("materialname", auditProjectMaterial.getTaskmaterial());
                                fileinfoJson.put("filesource", "窗口上传");
                                JSONArray jsonArray = new JSONArray();
                                for (FrameAttachInfo attachinfo : attachInfoList) {
                                    JSONObject certJson = new JSONObject();
                                    // 附件下载地址
                                    String loadUrl = "http://service.snd.gov.cn/zwfwf9test/gxqzwfw/rest/frame/pages/basic/attach/attachAction/getContent?attachGuid="
                                            + attachinfo.getAttachGuid() + "&isCommondto=true";
                                    // 材料名称
                                    certJson.put("filename", attachinfo.getAttachFileName());
                                    // 材料内容
                                    certJson.put("filecontent", loadUrl);
                                    jsonArray.add(certJson);
                                }
                                fileinfoJson.put("fileinfos", jsonArray);
                                materialsArray.add(fileinfoJson);
                                flag = true;
                            }
                        }
                    }

                    materialJson.put("materials", materialsArray);
                    userareaJson.put("userarea", materialJson);
                    if (flag) {
                        result = JsonUtils.zwdtRestReturn("1", "获取申报材料接口调用成功!", userareaJson);
                    } else {
                        result = JsonUtils.zwdtRestReturn("0", "接口调用失败,原因是:未查到相关申报材料数据信息!", userareaJson);
                    }

                } else {
                    result = JsonUtils.zwdtRestReturn("0", "接口调用失败,原因是:未查到相关办件数据信息!", userareaJson);
                }
            }
            else {
                result = JsonUtils.zwdtRestReturn("0", "接口调用失败,原因是:token验证失败!", userareaJson);
            }
        }
        catch (Exception e) {
            e.printStackTrace();
            xxxFrameDsManager.rollback();
            result = JsonUtils.zwdtRestReturn("0", "接口调用失败,原因是:" + e.toString(), userareaJson);
        }
        finally {
            xxxFrameDsManager.close();
        }
        return result;
    }
    
    /**
     *  录入市里返回得银行开户反馈信息
     *  @param param
     *  @return    
     */
    @RequestMapping(value = "/pushSZzwzxOpenAcountResult", method = RequestMethod.POST)
    public String pushSZzwzxOpenAcountResult(@RequestBody String param) {
         
        String result = "";
        try {
            xxxFrameDsManager.begin(null);
            // 参数转化为json对象
            JSONObject jsonObject = (JSONObject) JSONObject.parse(param);
            //时间格式化
            //SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            //token验证
            String token = jsonObject.getString("token");
            if (GXConstant.checkToken(token)) { 
                JSONObject params = (JSONObject) jsonObject.get("params");
                // 业务标识(与开户申请时推送的ywguid一致)
                String ywguid = params.getString("ywguid");
                // 银行名称
                String bankname = params.getString("bankname");
                // 银行编号
                String bankno = params.getString("bankno");
                // 账户名称
                String accountname = params.getString("accountname");
                // 账号
                String accountnum = params.getString("accountnum");
                // 开户日期
                Date accountdate = params.getDate("accountdate");
                // 是否同意开户
                String isallow = params.getString("isallow");
                // 银行开户审核意见
                String bankopnion = params.getString("bankopnion");
                // 商业银行开户审核时间
                Date bankopniondate = params.getDate("bankopniondate");
                String sql = "SELECT * FROM AUDIT_BKACC_FEEDBACK WHERE YWGUID ='"+ywguid+"' ";
                AuditBkaccFeedback auditBkaccFeedback = CommonDao.getInstance().find(sql, AuditBkaccFeedback.class);
                int flag = 1;
                if(auditBkaccFeedback == null){
                    auditBkaccFeedback = new AuditBkaccFeedback();
                    auditBkaccFeedback.setRowguid(UUID.randomUUID().toString());
                    auditBkaccFeedback.setOperatedate(new Date());
                    auditBkaccFeedback.setYwguid(ywguid);
                    flag = 0;
                }
                
                if(StringUtil.isNotBlank(bankno)){
                    auditBkaccFeedback.setBankno(bankno);
                }else{
                    return result = JsonUtils.zwdtRestReturn("0", "接口调用失败,原因是:银行编号(bankno)为空!", ""); 
                }
                
                if(StringUtil.isNotBlank(bankname)){
                    auditBkaccFeedback.setBankname(bankname);
                } 
                
                if(StringUtil.isNotBlank(accountname)){
                    auditBkaccFeedback.setAccountname(accountname);
                } 
                
                if(StringUtil.isNotBlank(accountnum)){
                    auditBkaccFeedback.setAccountnum(accountnum);
                }  
                
                if(StringUtil.isNotBlank(accountdate)){
                    auditBkaccFeedback.setAccountdate(accountdate);
                }
                /*else{
                    return result = JsonUtils.zwdtRestReturn("0", "接口调用失败,原因是:开户日期(accountdate)为空!", ""); 
                }*/
                
                if(StringUtil.isNotBlank(isallow)){
                    auditBkaccFeedback.setIsalllow(isallow);
                }else{
                    return result = JsonUtils.zwdtRestReturn("0", "接口调用失败,原因是:是否同意开户(isallow)为空!", ""); 
                }
                
                if(StringUtil.isNotBlank(bankopnion)){
                    auditBkaccFeedback.setBankopinion(bankopnion);
                }else{
                    return result = JsonUtils.zwdtRestReturn("0", "接口调用失败,原因是:银行开户审核意见(bankopnion)为空!", ""); 
                }
                
                if(StringUtil.isNotBlank(bankopniondate)){
                    auditBkaccFeedback.setBankopniondate(bankopniondate);
                }
                if(flag == 0){
                    CommonDao.getInstance().insert(auditBkaccFeedback);
                } else {
                    CommonDao.getInstance().update(auditBkaccFeedback);
                }
                 
                result = JsonUtils.zwdtRestReturn("1", "接口调用成功,反馈信息已录入!", "");
            } else {
                return result = JsonUtils.zwdtRestReturn("0", "接口调用失败,原因是:token验证失败!", "");
            }

        }
        catch (Exception e) {
            e.printStackTrace();
            xxxFrameDsManager.rollback();
            result = JsonUtils.zwdtRestReturn("0", "接口调用失败,原因是:" + e.toString(), "");
        }
        finally {
            xxxFrameDsManager.close();
        } 
        return result;
    }

}

给对方的接口地址就是 域名+工程名+rest+类注解+方法注解,我们系统运行着就可以了,给对方调用,开发过程中需要两边联调,可以用postman等工具进行来回接口的调用和数据的互相推送调试完成即可;

猜你喜欢

转载自www.cnblogs.com/wmqiang/p/10500769.html
今日推荐