重构代码(一)_JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > 重构代码(一)

重构代码(一)

 2014/11/22 12:22:53  liuheizi120  程序员俱乐部  我要评论(0)
  • 摘要:publicvoidtoCoin(ModelMapmodelMap,StringId,intstartIndex,HttpServletRequestrequest){//根据手机号获取会员idStringphone=request.getParameter("phone");//Id="";if(!("".equals(phone)||phone=="")&&(Id==""||"".equals(Id))){PhoneUsersPOpo=phoneUsersService
  • 标签:代码
public void toCoin(ModelMap modelMap, String Id, int startIndex,
HttpServletRequest request) {
// 根据手机号获取会员id

class="java" name="code">
String phone = request.getParameter("phone");
// Id = "";
if (!("".equals(phone) || phone == "") && (Id == "" || "".equals(Id))) {
PhoneUsersPO po = phoneUsersService.findByPhone(phone);
if (po == null) {
Id = "0";
modelMap.addAttribute("flag", "-1");
} else {
Id = po.getUserid() + "";
}
}
// 查询会员信息
PhoneUsersPO phoneUserpo = phoneUsersService.find(Id);
modelMap.addAttribute("phoneUserpo", phoneUserpo);

// 查询畅达币信息
AbstractWebserviceInvoker webserviceInvoker = new LcdCoinInfosHandler();
Map<String, Object> phoneCoinInfo = (Map<String, Object>) webserviceInvoker
.invoke(WebServiceConstant.getTicketNewPoint(),
"getMLcdCoinInfos", WebServiceConstant.getQname(),
new Object[] { Id });
modelMap.addAttribute("phoneCoinPO", phoneCoinInfo);

// 获取会员畅达币明细
Pages page = new Pages(startIndex);
Map<Object, Object> map = new HashMap<Object, Object>();
// map.put("startIndex", startIndex);
map.put("userid", Id);

String coinstutas = request.getParameter("coinstutas");
String startDate = request.getParameter("startDate");
String endDate = request.getParameter("endDate");
String details = request.getParameter("coinDetails");

String coinDetails = details == null ? details : details.trim();
map.put("coinstatus", coinstutas);
map.put("startDate", startDate);
map.put("endDate", endDate);
map.put("coinDetails", coinDetails);


map.put("page", page);

// / List<Map> temList = phoneCoinDetailsService.findByUserId1(map);
List<PhoneCoinDetailsVO> temList = phoneCoinDetailsService
.findUserCoinDetailNew(map);
page.setItems(temList);
// page.setTotalCount(phoneCoinDetailsService.countFindAllForPage1(map));
int coinCount = phoneCoinDetailsService.countUserCoinDetailNew(map);
page.setTotalCount(coinCount);

modelMap.addAttribute("page", page);
modelMap.addAttribute("coinstutas", coinstutas);
modelMap.addAttribute("startDate", startDate);
modelMap.addAttribute("endDate", endDate);
modelMap.addAttribute("coinDetails", coinDetails);
// modelMap.addAttribute("flag", "0");
}
重构后代码:
// 显示详细畅达币
public void toCoin(ModelMap modelMap, String id, int startIndex,
HttpServletRequest request) {
// 根据手机号获取会员id

String phone = request.getParameter("phone");
// Id = "";
if (!("".equals(phone) || phone == "") && (id == "" || "".equals(id))) {
PhoneUsersPO po = phoneUsersService.findByPhone(phone);
if (po == null) {
id = "0";
modelMap.addAttribute("flag", "-1");
} else {
id = po.getUserid() + "";
}
}
// 查询会员信息
PhoneUsersPO phoneUserpo = phoneUsersService.find(id);
modelMap.addAttribute("phoneUserpo", phoneUserpo);

// 查询畅达币信息
AbstractWebserviceInvoker webserviceInvoker = new LcdCoinInfosHandler();
@SuppressWarnings("unchecked")
Map<String, Object> phoneCoinInfo = (Map<String, Object>) webserviceInvoker
.invoke(WebServiceConstant.getTicketNewPoint(),
"getMLcdCoinInfos", WebServiceConstant.getQname(),
new Object[] { id });
modelMap.addAttribute("phoneCoinPO", phoneCoinInfo);
String coinstutas = request.getParameter("coinstutas");
String startDate = request.getParameter("startDate");
String endDate = request.getParameter("endDate");
String details = request.getParameter("coinDetails");
String coinDetails = details == null ? details : details.trim();

modelMap.addAttribute("coinstutas", coinstutas);
modelMap.addAttribute("startDate", startDate);
modelMap.addAttribute("endDate", endDate);
modelMap.addAttribute("coinDetails", coinDetails);

modelMap.addAttribute("page",
getUserCoinDetailsForMethodToCoin(startIndex,coinstutas, startDate,
endDate, details, id));
}

private Pages<PhoneCoinDetailsVO> getUserCoinDetailsForMethodToCoin(
int startIndex, String coinstutas, String startDate,
String endDate, String details, String userId) {
Pages<PhoneCoinDetailsVO> page = new Pages<PhoneCoinDetailsVO>(
startIndex);
Map<Object, Object> map = new HashMap<Object, Object>();
map.put("userid", userId);
map.put("coinDetails", details == null ? details : details.trim());
map.put("page", page);

List<PhoneCoinDetailsVO> temList = phoneCoinDetailsService
.findUserCoinDetailNew(map);
page.setItems(temList);
int coinCount = phoneCoinDetailsService.countUserCoinDetailNew(map);
page.setTotalCount(coinCount);
return page;
}
发表评论
用户名: 匿名