Java tutorial
package com.sc.web; import com.sc.service.SaleService; import com.sc.utils.GetResult; import com.sc.utils.JWT; import com.sc.utils.Result; import com.sc.utils.Token; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; 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.RestController; import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartHttpServletRequest; import javax.servlet.http.HttpServletRequest; import java.util.List; import java.util.Objects; /** * SaleController * Created by valora on 2017/5/9. */ @RestController @Api("Sale") public class SaleController { private final static String URL = "/api/Sale/"; private final JWT jwt; private final SaleService saleService; @Autowired public SaleController(JWT jwt, SaleService saleService) { this.jwt = jwt; this.saleService = saleService; } @RequestMapping(value = URL + "SendApplicationCode", method = RequestMethod.GET) @ApiOperation("????") @ApiImplicitParam(name = "phone", value = "??", required = true, dataType = "Integer", paramType = "query") public Result sendApplocationCode(@RequestParam("phone") Long phone) { return saleService.sendApplocationCodeS(phone, 1); } @RequestMapping(value = URL + "UserApplication", method = RequestMethod.POST) @ApiOperation("(){token,phone?,shopname??address?,lon?,lat,pwd?,pwdagain?,cardno???personname??,contactname???contactphone??telephone?,pax?,{??name:card,name:store,???name:license}") public Result userApplication(HttpServletRequest request, @RequestParam("card") MultipartFile[] cardFiles, @RequestParam("store") MultipartFile[] storeFiles, @RequestParam("license") MultipartFile[] licenseFiles) { String token = request.getParameter("token"); String address = request.getParameter("address"); String pwd = request.getParameter("pwd"); String pwdagain = request.getParameter("pwdagain"); String cardno = request.getParameter("cardno"); String phone1 = request.getParameter("phone"); Long phone = Long.valueOf(request.getParameter("phone")); String lon1 = request.getParameter("lon"); Double lon = Double.valueOf(request.getParameter("lon")); String lat1 = request.getParameter("lat"); Double lat = Double.valueOf(request.getParameter("lat")); String shopname = request.getParameter("shopname"); String personname = request.getParameter("personname"); String contactname = request.getParameter("contactname"); String contactphone = request.getParameter("contactphone"); String telephone = request.getParameter("telephone"); String pax = request.getParameter("pax"); Token tk = jwt.checkJWT(token); if (tk == null) { return GetResult.toJson(101, null, null, null, 0); } if (StringUtils.isBlank(address) || StringUtils.isBlank(pwd) || StringUtils.isBlank(pwdagain) || StringUtils.isBlank(cardno) || StringUtils.isBlank(phone1) || StringUtils.isBlank(lon1) || StringUtils.isBlank(lat1)) { return GetResult.toJson(38, null, null, null, 0); } if (!Objects.equals(pwd, pwdagain)) { return GetResult.toJson(55, null, null, null, 0); } return saleService.UserApplication(tk.getUserId(), phone, address, lon, lat, pwd, cardno, shopname, personname, contactname, contactphone, telephone, pax, cardFiles, storeFiles, licenseFiles); } @RequestMapping(value = URL + "SellerApplication", method = RequestMethod.POST) @ApiOperation("(){token,phone?,code??,shopname??address?,lon?,lat,pwd?,pwdagain?,cardno???personname??,contactname???contactphone??telephone?,pax?,{??name:card,name:store,???name:license}") public Result sellerApplication(HttpServletRequest request, @RequestParam("card") MultipartFile[] cardFiles, @RequestParam("store") MultipartFile[] storeFiles, @RequestParam("license") MultipartFile[] licenseFiles) { String token = request.getParameter("token"); String address = request.getParameter("address"); String pwd = request.getParameter("pwd"); String pwdagain = request.getParameter("pwdagain"); String cardno = request.getParameter("cardno"); String phone1 = request.getParameter("phone"); Long phone = Long.valueOf(request.getParameter("phone")); String lon1 = request.getParameter("lon"); Double lon = Double.valueOf(request.getParameter("lon")); Double lat = Double.valueOf(request.getParameter("lat")); String lat1 = request.getParameter("lat"); String companyname = request.getParameter("companyname"); String personname = request.getParameter("personname"); String contactname = request.getParameter("contactname"); String contactphone = request.getParameter("contactphone"); String telephone = request.getParameter("telephone"); String pax = request.getParameter("pax"); Token tk = jwt.checkJWT(token); if (tk == null) { return GetResult.toJson(101, null, null, null, 0); } if (StringUtils.isBlank(address) || StringUtils.isBlank(pwd) || StringUtils.isBlank(pwdagain) || StringUtils.isBlank(cardno) || StringUtils.isBlank(phone1) || StringUtils.isBlank(lon1) || StringUtils.isBlank(lat1)) { return GetResult.toJson(38, null, null, null, 0); } if (!Objects.equals(pwd, pwdagain)) { return GetResult.toJson(55, null, null, null, 0); } return saleService.SellerApplication(tk.getUserId(), phone, address, lon, lat, pwd, cardno, companyname, personname, contactname, contactphone, telephone, pax, cardFiles, storeFiles, licenseFiles); } @RequestMapping(value = URL + "QueryUsersByMap", method = RequestMethod.GET) @ApiOperation("???2") @ApiImplicitParams({ @ApiImplicitParam(name = "token", value = "", required = true, dataType = "String", paramType = "query"), @ApiImplicitParam(name = "lon", value = "?", required = true, dataType = "Double", paramType = "query"), @ApiImplicitParam(name = "lat", value = "", required = true, dataType = "Double", paramType = "query"), @ApiImplicitParam(name = "distance", value = "?020.01", required = true, dataType = "Double", paramType = "query") }) public Result queryUsersByMap(@RequestParam("token") String token, @RequestParam("lon") Double lon, @RequestParam("lat") Double lat, @RequestParam("distance") Double distance) { Token tk = jwt.checkJWT(token); if (tk == null) { return GetResult.toJson(101, null, null, null, 0); } else { return saleService.QueryUsersByMap(tk.getUserId(), lon, lat, distance); } } @RequestMapping(value = URL + "QuerySellersByMap", method = RequestMethod.GET) @ApiOperation("???2") @ApiImplicitParams({ @ApiImplicitParam(name = "token", value = "", required = true, dataType = "String", paramType = "query"), @ApiImplicitParam(name = "lon", value = "?", required = true, dataType = "Double", paramType = "query"), @ApiImplicitParam(name = "lat", value = "", required = true, dataType = "Double", paramType = "query"), @ApiImplicitParam(name = "distance", value = "?020.01", required = true, dataType = "Double", paramType = "query") }) public Result querySellersByMap(@RequestParam("token") String token, @RequestParam("lon") Double lon, @RequestParam("lat") Double lat, @RequestParam("distance") Double distance) { Token tk = jwt.checkJWT(token); if (tk == null) { return GetResult.toJson(101, null, null, null, 0); } else { return saleService.QuerySellerByMap(tk.getUserId(), lon, lat, distance); } } @RequestMapping(value = URL + "QueryUsersByAdminId", method = RequestMethod.GET) @ApiOperation("") @ApiImplicitParams({ @ApiImplicitParam(name = "token", value = "", required = true, dataType = "String", paramType = "query"), @ApiImplicitParam(name = "pageNum", value = "?", required = true, dataType = "Integer", paramType = "query"), @ApiImplicitParam(name = "pageSize", value = "??", required = true, dataType = "Integer", paramType = "query") }) public Result queryUsersByAdminId(@RequestParam("token") String token, @RequestParam(value = "pageSize", defaultValue = "1") Integer pageSize, @RequestParam(value = "pageNum", defaultValue = "10") Integer pageNum) { Token tk = jwt.checkJWT(token); if (tk == null) { return GetResult.toJson(101, null, null, null, 0); } return saleService.queryUsersByAdminId(tk.getUserId(), pageNum, pageSize); } @RequestMapping(value = URL + "QuerySellersByAdminId", method = RequestMethod.GET) @ApiOperation("") @ApiImplicitParams({ @ApiImplicitParam(name = "token", value = "", required = true, dataType = "String", paramType = "query"), @ApiImplicitParam(name = "pageNum", value = "?", required = true, dataType = "Integer", paramType = "query"), @ApiImplicitParam(name = "pageSize", value = "??", required = true, dataType = "Integer", paramType = "query") }) public Result QuerySellersByAdminId(@RequestParam("token") String token, @RequestParam(value = "pageSize", defaultValue = "1") Integer pageSize, @RequestParam(value = "pageNum", defaultValue = "10") Integer pageNum) { Token tk = jwt.checkJWT(token); if (tk == null) { return GetResult.toJson(101, null, null, null, 0); } return saleService.querySellersByAdminId(tk.getUserId(), pageNum, pageSize); } @RequestMapping(value = URL + "SendRetrieveCode", method = RequestMethod.GET) @ApiOperation("?????") @ApiImplicitParam(name = "phone", value = "??", required = true, dataType = "Integer", paramType = "query") public Result sendRetrieveCode(@RequestParam("phone") Long phone) { return saleService.sendApplocationCodeS(phone, 4); } @RequestMapping(value = URL + "ResettingPassword", method = RequestMethod.GET) @ApiOperation("??") @ApiImplicitParams({ @ApiImplicitParam(name = "phone", value = "?", required = true, dataType = "Long", paramType = "query"), @ApiImplicitParam(name = "code", value = "??", required = true, dataType = "Integer", paramType = "query"), @ApiImplicitParam(name = "newpassword", value = "?", required = true, dataType = "String", paramType = "query"), @ApiImplicitParam(name = "confirmpassword", value = "?", required = true, dataType = "String", paramType = "query") }) public Result resettingPassword(@RequestParam("phone") Long phone, @RequestParam("code") Integer code, @RequestParam("newpassword") String newpassword, @RequestParam("confirmpassword") String confirmpassword) { if (newpassword.isEmpty() || confirmpassword.isEmpty()) { return GetResult.toJson(38, null, null, null, 0); } if (!newpassword.equals(confirmpassword)) { return GetResult.toJson(39, null, null, null, 0); } return saleService.ResettingPassword(phone, code, newpassword); } @RequestMapping(value = URL + "SendBackAccountCode", method = RequestMethod.GET) @ApiOperation("??????") @ApiImplicitParam(name = "phone", value = "??", required = true, dataType = "Integer", paramType = "query") public Result sendBackAccountCode(@RequestParam("phone") Long phone) { return saleService.sendApplocationCodeS(phone, 1); } @RequestMapping(value = URL + "BackAccount", method = RequestMethod.GET) @ApiOperation("?") @ApiImplicitParams({ @ApiImplicitParam(name = "phone", value = "??", required = true, dataType = "Long", paramType = "query"), @ApiImplicitParam(name = "code", value = "??", required = true, dataType = "Integer", paramType = "query") }) public Result backAccount(@RequestParam("phone") Long phone, @RequestParam("code") Integer code) { return saleService.BackAccount(phone, code); } }