Esempio n. 1
0
 /**
  * 宠物信息新增和修改
  *
  * @param response
  * @param userName
  * @param petId
  * @param nickname
  * @param sex
  * @param breed
  * @param birthday
  * @param height
  * @param weight
  * @param district
  * @param placeOftenGo
  * @throws IOException
  */
 @RequestMapping(value = "/modify")
 public void modifyPetInfo(
     HttpServletResponse response,
     @RequestParam(value = "username") String userName,
     @RequestParam(value = "petid", required = false) String petId,
     @RequestParam(value = "nickname", defaultValue = "") String nickname,
     @RequestParam(value = "sex", defaultValue = "") String sex,
     @RequestParam(value = "breed", defaultValue = "") String breed,
     @RequestParam(value = "birthday", defaultValue = "0") String birthday,
     @RequestParam(value = "height", defaultValue = "") String height,
     @RequestParam(value = "weight", defaultValue = "") String weight,
     @RequestParam(value = "district", defaultValue = "") String district,
     @RequestParam(value = "placeoftengo", defaultValue = "") String placeOftenGo)
     throws IOException {
   IdBean petUpdateReturnBean = new IdBean();
   if (StringUtil.isNullOrEmpty(petId)) {
     if (!petInfoDao.hasPetInfo(userName)) {
       // create pet info
       long id =
           petInfoDao.createPetInfo(
               userName, nickname, sex, breed, birthday, height, weight, district, placeOftenGo);
       log.info("create pet id: " + id);
       if (id > 0) {
         petUpdateReturnBean.setResult("0");
         petUpdateReturnBean.setId(String.valueOf(id));
       } else {
         petUpdateReturnBean.setResult("4");
       }
     } else {
       petUpdateReturnBean.setResult("3"); // already has pet
     }
   } else {
     // save pet info
     int update =
         petInfoDao.updatePetInfo(
             petId,
             nickname,
             sex,
             breed,
             birthday,
             height,
             weight,
             district,
             placeOftenGo,
             null,
             null);
     if (update > 0) {
       petUpdateReturnBean.setResult("0");
       petUpdateReturnBean.setId(petId);
     } else {
       petUpdateReturnBean.setResult("1");
     }
   }
   response.getWriter().print(JSONUtil.toString(petUpdateReturnBean));
 }
Esempio n. 2
0
 /**
  * 绑定设备号
  *
  * @param response
  * @param userName
  * @param petId
  * @param deviceNo
  * @throws IOException
  */
 @RequestMapping(value = "/binddevice")
 public void bindPetDevice(
     HttpServletResponse response,
     @RequestParam(value = "username") String userName,
     @RequestParam(value = "petid") String petId,
     @RequestParam(value = "deviceno") String deviceNo)
     throws IOException {
   DeviceBindResult resultBean = new DeviceBindResult();
   if (StringUtil.isNullOrEmpty(deviceNo)) {
     resultBean.setResult("4"); // device id is empty
   } else if (StringUtil.isNullOrEmpty(petId)) {
     resultBean.setResult("5"); // pet id is empty
   } else {
     DeviceManager deviceManager = ContextLoader.getDeviceManager();
     try {
       resultBean = deviceManager.bindDevice(Integer.parseInt(petId), Long.parseLong(deviceNo));
       if ("0".equals(resultBean.getResult())) {
         petInfoDao.updatePetInfo(
             petId,
             null,
             null,
             null,
             null,
             null,
             null,
             null,
             null,
             String.valueOf(resultBean.getDevice_id()),
             resultBean.getDevice_password());
       }
     } catch (NumberFormatException e) {
       // TODO: handle exception
       resultBean.setResult("6"); //  not valid deviceno
     }
   }
   response.getWriter().print(JSONUtil.toString(resultBean));
 }