package com.taover.ai.controller.api; import java.io.BufferedReader; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import org.apache.commons.lang.StringUtils; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import com.taover.ai.bean.normal.ResponseAddress; import com.taover.ai.service.AddressService; import com.taover.util.bean.ResultInfo; import com.taover.util.bean.UtilResultInfo; import net.sf.json.JSONObject; @RestController("api.address") @RequestMapping("/api/address") public class AddressController { @Resource private AddressService addressService; /** * @apiDefine ResultInfo * @apiSuccess {string} * @apiSuccessExample {json} Success-Response: * { * code:ok, * error:null * } * @apiError ThrowException 出现异常 * @apiErrorExample * { * code:fail, * error:null exception * } */ /** * @api {GET} /v1/address/ 查询ssid对应的demo * @apiDescription 查询ssid对应demo数据 * * @apiGroup Demo * @apiName get实体数据 * @apiVersion 1.0.0 * @apiHeader Authorization * * @apiUse ResultInfo */ @RequestMapping("/pcdDetail") public ResponseAddress pcdDetail(HttpServletRequest request){ String address = request.getParameter("address"); JSONObject addressJson = this.getRequestBody(request); if(StringUtils.isNotEmpty(address)){ return this.addressService.pcdAddress(address); }else if(addressJson != null && addressJson.containsKey("address")){ String jsonAddress = addressJson.optString("address"); if(StringUtils.isNotEmpty(jsonAddress)){ return this.addressService.pcdAddress(jsonAddress); } } return ResponseAddress.createFail("没有检测到地址信息"); } private JSONObject getRequestBody(HttpServletRequest request){ try { BufferedReader reader = request.getReader(); String tempLine = reader.readLine(); StringBuffer sb = new StringBuffer(); while(tempLine != null){ sb.append(tempLine); tempLine = reader.readLine(); } return JSONObject.fromObject(sb.toString()); } catch (Exception e) { return null; } } /** * @api {POST} /v1/demo 创建demo * @apiDescription 创建demo * * @apiGroup Demo * @apiName get实体数据 * @apiVersion 1.0.0 * @apiHeader Authorization * * @apiUse ResultInfo */ @PostMapping public ResultInfo post(HttpServletRequest request){ return UtilResultInfo.getSuccess("post success"); } /** * @api {DELETE} /v1/demo/{ssid} 删除ssid对应的demo * @apiDescription 删除ssid对应demo数据 * * @apiGroup Demo * @apiName 删除实体数据 * @apiVersion 1.0.0 * @apiHeader Authorization * * @apiUse ResultInfo */ @DeleteMapping("/{ssid}") public ResultInfo delete(String ssid){ return UtilResultInfo.getSuccess("delete success"); } /** * @api {PUT} /v1/demo/{ssid} 修改demo数据 * @apiDescription 修改demo数据 * * @apiGroup Demo * @apiName 修改实体数据 * @apiVersion 1.0.0 * @apiHeader Authorization * * @apiUse ResultInfo */ @PutMapping("/{ssid}") public ResultInfo put(String ssid, HttpServletRequest request){ return UtilResultInfo.getSuccess("put for ssid success"); } }