uniapp开发app框架在提升开发效率中的独特优势与应用探索
520
2022-11-15
controller类写法参考
package com.lenovo.lps.psb.simdevice.web;import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.multipart.MultipartHttpServletRequest;import com.lenovo.lps.hds.shared.exception.HadesException; import com.lenovo.lps.psb.simdevice.domain.Account; import com.lenovo.lps.psb.simdevice.domain.CloudFile; import com.lenovo.lps.psb.simdevice.domain.Deposit; import com.lenovo.lps.psb.simdevice.domain.E2EContact; import com.lenovo.lps.psb.simdevice.service.AccountService; import com.lenovo.lps.psb.simdevice.service.CloudFileService; import com.lenovo.lps.psb.simdevice.service.PushService2; import com.lenovo.lps.psb.simdevice.service.exception.PushFaildException; import com.lenovo.lps.psb.simdevice.web.upload.UploadException; import com.lenovo.lps.psb.simdevice.web.upload.UploadUtils;@Controller public class AdminController { private static final Logger logger = LoggerFactory.getLogger(WebController.class); @Autowired private AccountService accountService; @Autowired private PushService2 pushService; @Autowired private CloudFileService cloudFileService; @RequestMapping(value = "/admin/login.htm",method=RequestMethod.GET) public String login(){ return "admin/login"; } @RequestMapping(value = "/admin/login.action",method=RequestMethod.POST) public String login(Account account,ModelMap modeMap){ if(StringUtils.isBlank(account.getId()) ){ modeMap.addAttribute("error", "请输入用户名"); return "admin/login"; } if(StringUtils.isBlank(account.getPassword())){ modeMap.addAttribute("error", "请输入密码"); return "admin/login"; } Account logindAccount = accountService.login(account.getId(), account.getPassword()); if(logindAccount==null){ modeMap.addAttribute("error", "用户名或密码无效"); return "admin/login"; } return "admin/broadcast"; } @RequestMapping(value = "/admin/broadcast.htm",method=RequestMethod.GET) public String broadcast(ModelMap modeMap){ modeMap.addAttribute("contacts", accountService.getContacts()); return "admin/broadcast"; } @RequestMapping(value = "/admin/broadcast.htm",method=RequestMethod.POST) public String broadcast( @RequestParam(value="targets",defaultValue="") String targets, @RequestParam(value="otherTargets",defaultValue="") String otherTargets, MultipartHttpServletRequest request,ModelMap modeMap){ logger.info("/admin/broadcast.htm"); System.out.println(targets); Deposit deposit = new Deposit(); String[] phonenumbers = otherTargets.split(","); String[] contactids = targets.split(","); try { UploadUtils.upload(deposit, request); modeMap.addAttribute("result",pushService.push(deposit, contactids,phonenumbers)); return "admin/broadcastResult"; } catch (UploadException e) { modeMap.addAttribute("contacts", accountService.getContacts()); modeMap.addAttribute("error", e.getMessage()); return "admin/broadcast"; } catch (PushFaildException e) { modeMap.addAttribute("contacts", accountService.getContacts()); modeMap.addAttribute("error", "推送失败。错误代码: PushFaildException:" + e.getErrorCode()); return "admin/broadcast"; } } @RequestMapping(value = "/admin/e2ePreviewPush",produces="application/json;charset=utf-8") public @ResponseBody String e2ePreviewPush(Deposit deposit){ return null; } @RequestMapping(value = "/admin/pushlink",method=RequestMethod.POST,produces="text/json;charset=utf-8") public @ResponseBody String pushlink(@RequestParam(value="description",defaultValue="") String description,@RequestParam(value="neverExpired",defaultValue="true") boolean neverExpired,MultipartHttpServletRequest request,ModelMap modeMap){ CloudFile cloudfile; try { cloudfile = UploadUtils.parseFile(request); cloudfile.setAs_pushlink(true); cloudfile.setDescription(description); if(neverExpired){ cloudfile.setExpired(CloudFile.NEVER_EXPIRED); } try { cloudFileService.save(cloudfile,null); } catch (HadesException e) { return AjaxResult.errorJson("生成推送链接失败(服务器内部错误)"); } cloudfile.setData(null); return AjaxResult.successJson(cloudfile); } catch (UploadException e) { return AjaxResult.errorJson(e.getMessage()); } } @RequestMapping(value = "/pushlink/{id}.htm",method=RequestMethod.GET) public String visitPushlink(@PathVariable String id,ModelMap modeMap){ try { long pushlinkId = Long.valueOf(id); modeMap.addAttribute("result", cloudFileService.getCloudFile(pushlinkId)); } catch (NumberFormatException e) { logger.info("Invalid pushlink id:" + id); } return "visitPushlink"; } @RequestMapping(value = "/admin/sendUpdate",produces="application/json;charset=utf-8") public @ResponseBody String sendUpdate(){ try { pushService.sendUpdate(); } catch (Exception e) { e.printStackTrace(); return AjaxResult.errorJson(e.toString()); } return AjaxResult.successJson("OK"); } @RequestMapping(value = "/admin/contacts",produces="application/json;charset=utf-8") public String contacts(ModelMap modeMap){ modeMap.addAttribute("contacts", accountService.getContacts()); return "admin/contacts"; } @RequestMapping(value = "/admin/addContact",produces="application/json;charset=utf-8") public @ResponseBody String addContact(E2EContact contact){ accountService.addContact(contact); return AjaxResult.successJson(contact); } @RequestMapping(value = "/admin/delContact",produces="application/json;charset=utf-8") public @ResponseBody String addContact(long contactid){ accountService.delContact(contactid); return AjaxResult.successJson("OK"); } }
package com.lenovo.lps.psb.simdevice.web;import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody;import com.lenovo.lps.psb.simdevice.domain.Device; import com.lenovo.lps.psb.simdevice.domain.DeviceState; import com.lenovo.lps.psb.simdevice.domain.PhoneNumber; import com.lenovo.lps.psb.simdevice.service.ApkService; import com.lenovo.lps.psb.simdevice.service.DeviceService; import com.lenovo.lps.psb.simdevice.service.PushService2;@Controller public class DeviceController { private static final Logger logger = LoggerFactory.getLogger(DeviceController.class); @Autowired private DeviceService deviceService; @Autowired private ApkService apkService; @Autowired private PushService2 pushService; /** * 进行设备注册(更新PT) * @param device * @param resp * @return */ @RequestMapping(value = "/reg",produces="application/json;charset=utf-8") public @ResponseBody String register(Device device, @RequestParam(value="phonenumber",defaultValue="")String phonenumber, @RequestParam(value="imsi",defaultValue="")String imsi, @RequestParam(value="version",defaultValue="")String version) { logger.info("Client Requesting: /reg:" + device.toString()); //兼容处理,当device未提交设备摘要时,使用穿越号作为摘要 if(device.getDigest()==null){ device.setDigest(device.getDeviceid()); } Device deviceInDb = deviceService.save(device); if(StringUtils.isNotBlank(phonenumber)){ PhoneNumber phoneNumber = new PhoneNumber(); phoneNumber.setPhonenumber(phonenumber); phoneNumber.setImsi(imsi); phoneNumber.setBind_device(deviceInDb.getDeviceid()); deviceService.save(phoneNumber); } DeviceState deviceState = deviceService.getBind(deviceInDb.getDeviceid()); try{ int v = Integer.parseInt(version); if(apkService.getApkInfo().getVersion() > v && deviceState!=null){ deviceState.setUpdate(DeviceState.UDATE_STATE_TRUE); } }catch(Exception ignor){} return AjaxResult.successJson(deviceState); } /** * 检查设备是否存在 * @param deviceid * @return */ @RequestMapping(value = "/validateDeviceid",produces="application/json;charset=utf-8") public @ResponseBody String validateDeviceid(@RequestParam(value="clientid",defaultValue="")String clientid,@RequestParam(value="deviceid",defaultValue="")String deviceid) { //兼容处理(兼容deviceid参数): if(StringUtils.isBlank(deviceid)){ if(StringUtils.isBlank(clientid)) return AjaxResult.errorJson("请填写有效的穿越号或手机号"); else deviceid = clientid; } if(clientid.matches("1\\d{10}")){ return AjaxResult.successJson("ok"); }else if(deviceService.getDevice(clientid)!=null){ return AjaxResult.successJson("ok"); } return AjaxResult.errorJson("请填写有效的穿越号或手机号"); } @RequestMapping(value = "/getBind",produces="application/json;charset=utf-8") public @ResponseBody String getBind(@RequestParam("deviceid")String deviceid) { return AjaxResult.successJson(deviceService.getBind(deviceid)); } /** * 获取图标 * @return */ @RequestMapping(value = "/icons") public String getIconsXml(){ return "icons"; } /** * 电话号码绑定 * @param deviceid * @return */ @RequestMapping(value = "/bindPhonenumber",produces="application/json;charset=utf-8") public @ResponseBody String validateClientid(PhoneNumber phonenumber,@RequestParam("vcode")String vcode) { if(deviceService.bind(phonenumber, vcode)){ return AjaxResult.successJson(deviceService.getBind(phonenumber.getBind_device())); }else{ return AjaxResult.errorJson("验证码错误"); } } /** * 获取验证码 * @param deviceid * @return */ @RequestMapping(value = "/verifyCode",produces="application/json;charset=utf-8") public @ResponseBody String verifyCode(PhoneNumber phonenumber) { deviceService.sendVerifyCode(phonenumber); return AjaxResult.successJson("ok"); } @RequestMapping(value = "/unbind",produces="application/json;charset=utf-8") public @ResponseBody String unbind(PhoneNumber phonenumber) { deviceService.unbind(phonenumber); return AjaxResult.successJson("ok"); } }
package com.lenovo.lps.psb.simdevice.web;import java.io.IOException;import javax.servlet.org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping;import com.lenovo.lps.psb.simdevice.domain.ApkInfo; import com.lenovo.lps.psb.simdevice.service.ApkService;@Controller public class DownloadController { @Autowired private ApkService apkService; @RequestMapping(value = "/downloadApk.htm") public void downloadApk(HttpServletResponse response){ response.setCharacterEncoding("UTF-8"); try { ApkInfo apkInfo = apkService.getApkInfo(); response.setContentType("application/vnd.android.package-archive; charset=UTF-8"); response.setHeader("Content-Disposition", "attachment; filename=" + apkInfo.getName()); response.setContentLength(apkInfo.getData().length); response.getOutputStream().write(apkInfo.getData()); response.flushBuffer(); response.getOutputStream().flush(); response.getOutputStream().close(); } catch (IOException e1) { response.setStatus(HttpServletResponse.SC_NOT_FOUND); } } }
package com.lenovo.lps.psb.simdevice.web;import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody;import com.lenovo.lps.psb.simdevice.domain.Feedback; import com.lenovo.lps.psb.simdevice.service.FeedbackService;@Controller public class FeedBackController { @Autowired private FeedbackService feedbackService; @RequestMapping(value = "/feedback",produces="application/json;charset=utf-8") public @ResponseBody String feedback(Feedback feedback){ feedbackService.postFeedBack(feedback); return AjaxResult.successJson("OK"); } }
package com.lenovo.lps.psb.simdevice.web;import javax.servlet.org.eclipse.jetty.util.log.Log; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.multipart.MultipartHttpServletRequest;import com.lenovo.lps.psb.simdevice.domain.Deposit; import com.lenovo.lps.psb.simdevice.service.PushService2; import com.lenovo.lps.psb.simdevice.service.exception.PushFaildException; import com.lenovo.lps.psb.simdevice.web.upload.UploadException; import com.lenovo.lps.psb.simdevice.web.upload.UploadUtils;@Controller public class PushController { private static final Logger logger = LoggerFactory.getLogger(PushController.class); static{ AdminPassManager.changePass(); } @Autowired private PushService2 pushService2; @RequestMapping(value = "/pushfile",produces="application/json;charset=utf-8") public @ResponseBody String pushFile(Deposit deposit,MultipartHttpServletRequest request){ Log.info("Client Requesting: /pushfile"); deposit.setSource(Deposit.SRC_UPLOAD); try { UploadUtils.upload(deposit,request); } catch (UploadException e) { logger.info("文件上传失败",e); return AjaxResult.errorJson(e.getMessage()); } return push(deposit); } @RequestMapping(value = "/push",produces="application/json;charset=utf-8") public @ResponseBody String push(Deposit deposit){ Log.info("Client Requesting: /push"); try { pushService2.push(deposit); } catch (PushFaildException e) { if(e.getErrorCode()==PushFaildException.DEVICE_NOT_EXIST){ return AjaxResult.errorJson("无效的推送目标:" + deposit.getClientId()); } e.printStackTrace(); logger.info("推送失败PushFaildException:"+e.getErrorCode()); return AjaxResult.errorJson("推送失败,请稍后重试."); } catch (Exception e) { e.printStackTrace(); logger.info("推送失败",e); return AjaxResult.errorJson("推送失败,请稍后重试."); } if(deposit.getPushstate()==Deposit.PUSH_STATE_FIALD){ return AjaxResult.errorJson("推送失败,请稍后重试."); } if(deposit.getPushstate()==Deposit.PUSH_STATE_NEVER){ return AjaxResult.errorJson("手机未就绪,请检查您的手机是否安装了联想穿越."); } return AjaxResult.successJson(null); } @RequestMapping(value = "/countor",produces="text/plain;charset=utf-8") public @ResponseBody String showCount(){ return pushService2.getCountorInfo(); } @RequestMapping(value = "/sys",produces="text/plain;charset=utf-8",method = RequestMethod.POST) public @ResponseBody String sendSystemMessage(Deposit deposit, @RequestParam("password") String password ,MultipartHttpServletRequest request ,HttpServletResponse response){ Log.info("Client Requesting: /sys"); deposit.setSource(Deposit.SRC_SYS); logger.info("============== Admin send system message =============="); if(AdminPassManager.check(password)){ logger.info("Check Password : pass"); try { deposit.setClientId(null); UploadUtils.upload(deposit,request); pushService2.push(deposit); return "success!"; } catch(UploadException e){ logger.warn("推送失败",e); return AjaxResult.errorJson(e.getMessage()); } catch (Exception e) { logger.warn("推送失败",e); return AjaxResult.errorJson("推送失败."); } } logger.warn("Check Password : faild"); return "Invalid password"; } @RequestMapping(value = "/push2me",produces="text/plain;charset=utf-8") public @ResponseBody String push2me(@RequestParam("deviceid") String deviceid){ pushService2.push2me(deviceid); return AjaxResult.successJson("OK"); }
package com.lenovo.lps.psb.simdevice.web;import java.io.UnsupportedEncodingException; import java-.URLEncoder;import org.eclipse.jetty.util.log.Log; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.multipart.MultipartHttpServletRequest;import com.lenovo.lps.psb.simdevice.domain.Deposit; import com.lenovo.lps.psb.simdevice.service.PushService2; import com.lenovo.lps.psb.simdevice.service.exception.PushFaildException; import com.lenovo.lps.psb.simdevice.web.upload.UploadException; import com.lenovo.lps.psb.simdevice.web.upload.UploadUtils;@Controller public class WebController { private static final Logger logger = LoggerFactory.getLogger(WebController.class); @Autowired private PushService2 pushService2; @RequestMapping(value = "/index.htm") public String index(){ return "main2"; } @RequestMapping(value = "/addon.htm") public String addon(){ return "addon"; } @RequestMapping(value = "/client.htm") public String client(){ return "client"; } @RequestMapping(value = "/help.htm") public String help(){ return "help"; } // @RequestMapping(value = "/pushFile.htm",method=RequestMethod.POST) // public String pushFile(Deposit deposit,MultipartHttpServletRequest request,ModelMap modeMap){ // logger.info("PushFile from web."); // deposit.setSource(Deposit.SRC_UPLOAD); // boolean hasfile = false; // try { // hasfile = UploadUtils.parseFile(deposit,request); // logger.debug("parseFile success:" + deposit.getName()); // } catch (MaxUploadSizeExceededException e) { // logger.debug("Push file faild:文件大小超过限制"); // modeMap.addAttribute("file_error", "文件大小超过限制(最大可上传10M)"); // return "pushFile"; // } catch (IOException e) { // logger.debug("Push file faild:文件上传失败"); // modeMap.addAttribute("file_error", "文件上传失败"); // return "pushFile"; // } // // if(!hasfile){ // logger.debug("Push file faild:不能发送空文件"); // modeMap.addAttribute("file_error", "不能发送空文件"); // return "pushFile"; // }else{ // try { // pushService2.push(deposit); // } catch (PushFaildException e) { // logger.info("PushFaildException:" + e.getErrorCode()); // logger.info("推送失败",e.getMessage()); // e.printStackTrace(); // if(e.getErrorCode()==PushFaildException.DEVICE_NOT_EXIST){ // modeMap.addAttribute("global_error", "穿越号不存在"); // return "pushFile"; // }else{ // modeMap.addAttribute("global_error", "推送失败,请稍后重试"); // return "pushFile"; // } // }catch (Exception e) { // modeMap.addAttribute("error", "推送失败请稍后再试"); // return "pushFile"; // } // } // if(deposit.getPushstate()==Deposit.PUSH_STATE_COMPLETE){ // modeMap.addAttribute("success", "文件已经发送到你的手机."); // }else if(deposit.getPushstate()==Deposit.PUSH_STATE_NEVER){ // modeMap.addAttribute("success","手机未就绪,请检查您的手机是否安装了联想穿越."); // }else if(deposit.getPushstate()==Deposit.PUSH_STATE_FIALD){ // modeMap.addAttribute("success","推送失败,请稍后重试"); // }else if(deposit.getPushstate()==Deposit.PUSH_STATE_SMSIMPORT_COMPLETE){ // modeMap.addAttribute("success","您发发送的内容已暂存在服务器,请查收短信并通过短信链接安装联想穿越客户端,查看该内容"); // } // return "pushFile"; // } @RequestMapping(value = "/pushFile.htm",method=RequestMethod.POST) public String pushFile2(Deposit deposit,MultipartHttpServletRequest request){ logger.info("pushFile.htm(POST)"); RequestCostUtils.printProcessCost(request); try { RequestCostUtils.start(request, "uploadFile"); UploadUtils.upload(deposit, request); RequestCostUtils.printProcessCost(request); } catch (UploadException e) { deposit.setPushstate(Deposit.PUSH_STATE_NEVER); return buildRedirectPath(deposit,e.getMessage()); } RequestCostUtils.start(request, "pushFile"); String result = push(deposit); RequestCostUtils.printProcessCost(request); return result; } @RequestMapping(value = "/commonpush.htm",method=RequestMethod.POST) public String push(Deposit deposit){ Log.info("Client Requesting: /commonpush.htm"); String error = null; try { pushService2.push(deposit); } catch (PushFaildException e) { if(e.getErrorCode()==PushFaildException.DEVICE_NOT_EXIST){ error = "无效的推送目标:" + deposit.getClientId(); }else{ e.printStackTrace(); logger.info("推送失败PushFaildException:"+e.getErrorCode()); error = "PushFaildException:"+e.getErrorCode(); } } catch (Exception e) { e.printStackTrace(); logger.info("推送失败",e); error = "服务器内部错误"; } if(deposit.getPushstate()==Deposit.PUSH_STATE_FIALD){ error = "消息已暂存,请确定您的手机链接网络并启动了联想穿越,以便接受消息"; } if(deposit.getPushstate()==Deposit.PUSH_STATE_NEVER){ error = "消息已暂存,请确定您的手机链接网络并启动了联想穿越,以便接受消息"; } return buildRedirectPath(deposit,error); } private String buildRedirectPath(Deposit deposit,String error){ StringBuilder sb = new StringBuilder(); sb.append("redirect:index.htm"); if(deposit!=null){ sb.append("?clientId=").append(deposit.getClientId()); sb.append("&source=").append(deposit.getSource()); sb.append("&pushState=").append(deposit.getPushstate()); if(error!=null){ try { sb.append("&error=").append(URLEncoder.encode(error, "utf-8")); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } } return sb.toString(); } @RequestMapping(value = "/smsLink.htm",method=RequestMethod.GET) public String smsLink(){ return "smsLink"; } @RequestMapping(value = "/favplug/pushWindow.htm") public String pushWindow(@RequestParam("url") String url ,@RequestParam("name") String name, ModelMap modeMap){ modeMap.addAttribute("url", url); modeMap.addAttribute("name", name); return "favplug/pushWindow"; } @RequestMapping(value = "/smsDownloadlink",produces="application/json;charset=utf-8") public @ResponseBody String smsDownloadlink(@RequestParam("phonenumber")String phonenumber,@RequestParam("bind") boolean bind) { if(pushService2.smsDownloadlink(phonenumber,bind)){ return AjaxResult.successJson("OK"); }else{ return AjaxResult.errorJson("发送短信失败"); } } }
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~