论坛首页 Java企业应用论坛

重构代码(一)

浏览 978 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2014-11-22  
public void toCoin(ModelMap modelMap, String Id, int startIndex,
HttpServletRequest request) {
// 根据手机号获取会员id

<pre name="code" class="java"></pre>String phone = request.getParameter("phone");
// Id = "";
if (!("".equals(phone) || phone == "") &amp;&amp; (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&lt;String, Object&gt; phoneCoinInfo = (Map&lt;String, Object&gt;) webserviceInvoker
.invoke(WebServiceConstant.getTicketNewPoint(),
"getMLcdCoinInfos", WebServiceConstant.getQname(),
new Object[] { Id });
modelMap.addAttribute("phoneCoinPO", phoneCoinInfo);

// 获取会员畅达币明细
Pages page = new Pages(startIndex);
Map&lt;Object, Object&gt; map = new HashMap&lt;Object, Object&gt;();
// 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&lt;Map&gt; temList = phoneCoinDetailsService.findByUserId1(map);
List&lt;PhoneCoinDetailsVO&gt; 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 == "") &amp;&amp; (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&lt;String, Object&gt; phoneCoinInfo = (Map&lt;String, Object&gt;) 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&lt;PhoneCoinDetailsVO&gt; getUserCoinDetailsForMethodToCoin(
int startIndex, String coinstutas, String startDate,
String endDate, String details, String userId) {
Pages&lt;PhoneCoinDetailsVO&gt; page = new Pages&lt;PhoneCoinDetailsVO&gt;(
startIndex);
Map&lt;Object, Object&gt; map = new HashMap&lt;Object, Object&gt;();
map.put("userid", userId);
map.put("coinDetails", details == null ? details : details.trim());
map.put("page", page);

List&lt;PhoneCoinDetailsVO&gt; temList = phoneCoinDetailsService
.findUserCoinDetailNew(map);
page.setItems(temList);
int coinCount = phoneCoinDetailsService.countUserCoinDetailNew(map);
page.setTotalCount(coinCount);
return page;
}
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics