发表于: 2017-10-16 22:06:33

4 768


一.今天完成的主要事情

1.写好一个较为复杂的接口,查看内容详情接口

该接口主要复杂在需要通过messageId获取message对象,然后通过message对象获取userProductRelationId,接着再通过userProductRelationId获取userProductRelation对象,再通过userProductRelation对象获取productId和investmentId,最后通过这两个Id获取相应的对象,将数据拼装后返回.

在每一步都要判断出现获取的结果是否为空,获取的值是否正确等

该接口代码如下:

/**
* 13.查询用户消息详情
*
* @param
* @return
* @throws ServiceException
* @throws ServiceDaoException
*/
@RequestMapping(value = "/a/u/message/{id}", method = RequestMethod.GET)
public String getMessageJson(HttpServletRequest request,
HttpServletResponse response, ModelMap model, @PathVariable Long id)
throws Exception {

log.info("get data : id: " + id);

Message message;
Integer messageType;
Product product;
Investment investment = null;
Long uprId;
Long productId;
UserProductRelation userProductRelation;
List<Long> investmentIds;
List<Investment> investments;
try{
//通过Id获取消息详情
       message = messageService.getObjectById(id);
if (DataUtils.isNotNullOrEmpty(message)){
log.info("get message data is " + message);

messageType = message.getType();
log.info("get field type, type is: " + messageType);
if (DataUtils.isNullOrEmpty(messageType)){
log.info("Field type can not be NULL!");
model.addAttribute("code", 1);
return "/common/failure";
}

//如果是系统消息
           if (messageType == 0){

//通过系统消息获取用户产品关联表ID
               uprId = message.getUserProductRelationId();
log.info("get ubrId, ubrId : " + uprId);
if (DataUtils.isNullOrEmpty(uprId)){
log.info("Parameter ubrId can not be NULL!");
model.addAttribute("code", -40002);
return "/common/failure";
}

//获取用户产品关联表对象
               userProductRelation = userProductRelationService.getObjectById(uprId);
log.info("get userProductRelation, userProductRelation: " + userProductRelation);
if (DataUtils.isNullOrEmpty(userProductRelation)){
log.info("Couldn't find userProductRelation by ubrId, ubrId is:"  + uprId);
model.addAttribute("code", -30003);
return "/common/failure";
}

//通过用户产品关联表对象获取产品ID
               productId = userProductRelation.getProductId();
log.info("get productId, productId is: " + productId);
if (DataUtils.isNullOrEmpty(productId)){
log.info("Parameter productId can not be NULL");
model.addAttribute("code", -9000);
return "/common/failure";
}
//通过用户产品关联表ID获取投资记录ID
               investmentIds = investmentService.getInvestmentIdsByUprId(uprId, 0, Integer.MAX_VALUE);
log.info("get countInvestmentIdsByUprId size is " + investmentIds.size());
if (CollectionUtils.isEmpty(investmentIds)){
log.info("Parameter investmentIds can not be NULL");
model.addAttribute("code", -40000);
return "/common/failure";
}

//获取产品对象和投资记录对象
               product = productService.getObjectById(productId);
log.info("get product, product: " + product);
investments = investmentService.getObjectsByIds(investmentIds);
if (CollectionUtils.isNotEmpty(investments)){
investment = investments.get(0);
log.info("get investment data: " + investment);
}

model.addAttribute("code", 0);
model.addAttribute("product", product);
model.addAttribute("userProductRelation", userProductRelation);
model.addAttribute("investment", investment);

return "/polyFinance-business-service/message/json/autoMessageDetailJson";
} else if (messageType == 1){
model.addAttribute("code", 0);
model.addAttribute("message", message);

return "/polyFinance-business-service/message/json/publicMessageDetailJson";
} else {
model.addAttribute("code", -40003);
return "/common/failure";
}

} else {
log.info("Couldn't find message by id, id is: " + id);
model.addAttribute("code", 1);
model.addAttribute("id", id);
return "/data/json";
}

} catch(Throwable t){
t.printStackTrace();
log.info(t.getMessage());
log.info("get message data error, id is : " + id );
model.addAttribute("code", -1);
return "/common/failure";
}
}

2.学习动态查询语句的编写

要先写一个工具类,用于sql语句的拼装

public static Map<String, Object> getMessageListByUserIdsAndRecipient(List<Long> userIds, Integer recipient){
Map<String , Object> params = new HashedMap();

if (DataUtils.isNotNullOrEmpty(userIds)){
String ids = org.apache.commons.lang3.StringUtils.join(userIds, ",");
params.put("user_id & in ", "(" + ids + ")");
}
if (DataUtils.isNotNullOrEmpty(recipient)){
params.put("recipient & <= ", " '" + recipient + "'");
}

params.put("@order", "  create_at desc ");
params.put("@query", " id");

params.put("@table", " message ");

return params;
}

二.明天计划完成的事情

1.完成精品推荐story

2,如果有时间,继续进行下一个story中接口的编写

三.遇到的问题

暂无

四,收获

以上

五.项目进度情况

有延期风险


返回列表 返回列表
评论

    分享到