@RequestMapping("createAccount")
@ResponseBody
public ModelAndView createAccount(HttpServletRequest httpServletRequest,HttpServletResponse httpServletResponse) throws Exception {
ModelAndView result =this.getAutoView();
List<SysCity> cityList = new ArrayList<>();
/* List<SysCity> cityList = sysCityService.getCityList();*/
//角色
String selectValue = httpServletRequest.getParameter("selectValue");
//城市名称
String superior = httpServletRequest.getParameter("superior");
//系统类型
String systemNum = httpServletRequest.getParameter("systemNum");
//查询城市名称和id号的对应表 生成json对象 避免在for循环中进行数据库操作
SysCity sysCity1 = new SysCity(100000,"北京市");
SysCity sysCity2 = new SysCity(530000,"大连市");
SysCity sysCity3 = new SysCity(540000,"沈阳市");
cityList.add(sysCity1);
cityList.add(sysCity2);
cityList.add(sysCity3);
//定义一个stringbuffer
StringBuffer jsonStrAll = new StringBuffer("[");
for (SysCity sysCity:cityList){
jsonStrAll.append("{"+"\""+"cityId"+"\""+":"+"\""+sysCity.getId()+"\""+","+"\""+"cityName"+"\""+":"+"\""+sysCity.getCityName()+"\""+"},");
}
String jsonstr = jsonStrAll.substring(0,jsonStrAll.length()-1);
if (!"".equals(jsonstr)){
jsonstr=jsonstr+"]";
}
JSONArray json =JSONArray.fromObject(jsonstr);
String cityNum ="";
List list = new LinkedList();
String[] strings = superior.split(",");
if (json.size()>0){
for (int i=0;i<json.size();i++){
//遍历json数组 转化为json对象
JSONObject job = json.getJSONObject(i);
for (int j=0;j<strings.length;j++){
if (job.get("cityName").equals(strings[j])){
cityNum= (String) job.get("cityId");
list.add(cityNum);
}
}
}
}
int systemValue = SystemTypeEnum.chooseType(systemNum).getValue();
List userIdList = new LinkedList();
for (Object str : list){
//生成三位流水号
int random = (int)(Math.random()*900)+100;
String a = String.valueOf(systemValue);
String b = (String) str;
String c = String.valueOf(random);
String userId = a+b+c;
userIdList.add(userId);
}
//获取当前时间
Date date = new Date();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd:hh:mm:ss");
String format = dateFormat.format(date);
result.addObject("userIdList",userIdList);
return result;
}
网友评论