按發貨單查詢終端數量(request.getParameter("")String轉int)

ZHOU_VIP發表於2018-09-17

 request.getParameter("")String轉int:

/**
 * 按發貨單查詢終端數量介面
 * 
 * @param request
 * @param response
 * @return
 * @throws Exception
 */
@RequestMapping(value="/dev/querydevnumbyord", method=RequestMethod.GET)
@ResponseBody
public APIResponse querydevnumbyord(HttpServletRequest request) throws Exception {
	String tokenStr = request.getParameter("token");
	String ordno = request.getParameter("ordNo");
	String devs = request.getParameter("devstatus");
	int devstatus = -1;
	if(devs !=null && !devs.trim().equals("")){
		devstatus = Integer.parseInt(devs.trim());
	}
	logger.info("queryDev: token="+tokenStr+", ordno="+ordno);
	APIResponse apiRsp = this.checkApiToken(tokenStr);
	if(apiRsp.getResult() != APIResponse.RET_CODE_OK){
		return apiRsp;
	}
	User user = (User)(apiRsp.getData());
	boolean hasOpRight = this.extAuthService.checkOpRight(user.getUSERID(), Constants.OPCODE_OSM_DEV_QRY);
	if(hasOpRight == false){
		return APIResponse.error("許可權不足,裝置查詢失敗!");
	}	
	try {
		int devnum = this.devService.countOsmDevByOrdNoAndState(ordno,devstatus);
		return APIResponse.ok(devnum);
	}catch(Exception ex){
		logger.error("queryDev failed!", ex);
		return APIResponse.error(ex.getMessage());
	}
}


//按發貨單查詢終端數量
public int countOsmDevByOrdNoAndState(String ordno,int devstatus) throws Exception;


@Override
public int countOsmDevByOrdNoAndState(String ordno,int devstatus) throws Exception {
	return this.devMapper.countOsmDevByOrdNoAndState(ordno,devstatus);
}


// 按運單及狀態查詢裝置數量.(devstate = -1 表示不參與過濾)
public int countOsmDevByOrdNoAndState(@Param("ordno") String ordno, @Param("devstate") int devstate) throws Exception;

<select id="countOsmDevByOrdNoAndState" resultType="java.lang.Integer">
	 SELECT count(t.DEVEUI) AS devnum 
	   FROM osmdb.t_osm_dev t, osmdb.t_osm_order_dev r  
	  WHERE r.ORDNO = #{ordno, jdbcType=VARCHAR} 
		AND r.DEVEUI = t.DEVEUI 
	  <if test='devstate != -1 '>
		 AND t.DEVSTATUS = #{devstate, jdbcType=INTEGER} 
	  </if>
</select>

還有這種類似寫法可以參考:

String batch = request.getParameter("batch");
String offset = request.getParameter("offset");
batch = (batch == null || batch.trim().equals("")) ? "5000" : batch.trim();
offset = (offset == null || offset.trim().equals("")) ? "0" : offset.trim();

 

 

 

 

相關文章