MENU

[泛微二开] API接口开发(录入客户是否重复检测by电话)

• 2024 年 08 月 13 日 • 阅读: 498 • 泛微OA

客户重复检测API接口的请求文档:


客户重复检测API接口文档

1. 接口概述

  • 接口名称: 客户重复检测
  • 接口路径: /customerCheck
  • 请求方式: GET
  • 请求格式: application/json
  • 功能描述: 该接口用于检测数据库中是否存在与传入的电话号码相同的客户记录。

2. 请求参数

参数名类型必填说明
phoneString要检测的电话号码

示例请求

GET /api/customerCheck?phone=12345678901

3. 返回参数

参数名类型说明
isValidBoolean检查是否通过(true:客户不存在,false:客户已存在或查询失败)
msgString检查结果的描述信息或失败原因

4. 返回结果示例

4.1. 检查通过 (客户不存在)

{
  "isValid": true,
  "msg": "客户不存在"
}

4.2. 检查不通过 (客户已存在)

{
  "isValid": false,
  "msg": "客户已存在"
}

4.3. 检查失败 (电话号码为空)

{
  "isValid": false,
  "msg": "电话号码不能为空"
}

4.4. 数据库查询出错

{
  "isValid": false,
  "msg": "数据库查询出错: <错误信息>"
}

5. 状态码

  • 200 OK: 请求成功,返回JSON格式的检查结果。
  • 400 Bad Request: 请求参数不正确(如电话号码为空)。
  • 500 Internal Server Error: 服务器内部错误(如数据库查询失败)。

6. 注意事项

  • 请确保传入的 phone 参数为有效的电话号码。
  • 该接口不区分电话号码的格式,如需要,可以在业务层进行格式校验。

java代码实现

package com.api.ones.khgl;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import com.alibaba.fastjson.JSONObject;
import weaver.conn.RecordSet;

/**
 * <h1>客户重复检测API</h1>
 * <p>用于检测数据库中是否存在重复的客户信息。</p>
 *
 * <p>create: 2024/08/13</p>
 *
 * <p></p>
 *
 * @author Oneszhang
 */
@Path("/customerCheck")
public class CustomerCheckApi {

    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public Response checkCustomer(@QueryParam("phone") String phone) {
        JSONObject jsonResponse = new JSONObject();

        if (phone == null || phone.isEmpty()) {
            jsonResponse.put("isValid", false);
            jsonResponse.put("msg", "电话号码不能为空");
            return Response.status(Response.Status.BAD_REQUEST).entity(jsonResponse.toString()).build();
        }

        try {
            RecordSet rs = new RecordSet();
            String sql = "SELECT count(*) as count FROM uf_khgl WHERE lxfs = ?";
            rs.executeQuery(sql, phone);

            if (rs.next()) {
                int count = rs.getInt("count");
                if (count > 0) {
                    jsonResponse.put("isValid", false);
                    jsonResponse.put("msg", "客户已存在");
                } else {
                    jsonResponse.put("isValid", true);
                    jsonResponse.put("msg", "客户不存在,检验通过");
                }
            } else {
                jsonResponse.put("isValid", false);
                jsonResponse.put("msg", "查询失败");
            }
        } catch (Exception e) {
            jsonResponse.put("isValid", false);
            jsonResponse.put("msg", "数据库查询出错: " + e.getMessage());
        }

        return Response.ok(jsonResponse.toString()).build();
    }
}
返回文章列表 打赏
本页链接的二维码
打赏二维码