发表于: 2017-12-19 23:02:00
2 634
今天完成的事情:完成查看投资记录接口
//查看投资记录 接口
@RequestMapping(value = "/a/u/invest/{uid}/search", method = RequestMethod.GET)
public String getInvestIdsByStatusAndUserIdJsonList(HttpServletRequest request,
HttpServletResponse response, ModelMap model,
Integer page, Integer size,
@PathVariable Long uid, String mobile,
String productName, Long minInterestBeginAt,
Long maxInterestBeginAt, String name,
Integer status, Long minInterestEndAt,
Long maxInterestEndAt)
throws Exception {
if (page == null) {
page = 1;
}
if (size == null) {
size = 10;
}
int start = (page - 1) * size;
if (start < 0) {
start = 0;
}
log.info("pageList : page= " + start + " , size=" + size);
try {
User user = userService.getObjectById(uid);
List<Invest> invests = new ArrayList<>();
Map<Long, Product> productHashMap = new HashMap<>();
Map<String, Object> map = UserUtil.getInvestList(mobile, name, productName,
minInterestBeginAt, maxInterestBeginAt, status, minInterestEndAt, maxInterestEndAt, uid,
false);
List<Long> ids = investService.getIdsByDynamicCondition(Invest.class, map, start, size);
if (CollectionUtils.isEmpty(ids)) {
log.info(" get user " + uid + " invest ids ,size is 0 ");
}
else {
log.info(" get user " + uid + " invest ids is: " + ids);
invests = investService.getObjectsByIds(ids);
List<Long> productIds = new ArrayList<>();
for (Invest invest : invests) {
productIds.add(invest.getPid());
}
log.info("productIds is: " + productIds );
if (productIds.size() > 0) {
List<Product> products = productService.getObjectsByIds(productIds);
log.info("products size is: " + products.size()) ;
for (int i = 0; i < products.size(); i++) {
Product product = products.get(i);
productHashMap.put(product.getId(), product);
}
}
}
map = UserUtil.getInvestList(mobile, name, productName, minInterestBeginAt,
maxInterestBeginAt, status, minInterestEndAt, maxInterestEndAt, uid,
true);
BigInteger total = (BigInteger) investService.getObjectByDynamicCondition(Invest.class, map,
0, Integer.MAX_VALUE);
log.info("get user " + uid + " invest total is " + total);
int totalPage = 1;
if (null != total) {
if (total.intValue() > 0) {
totalPage = (((total.intValue() - 1)) / (size)) + 1;
}
}
model.addAttribute("code", 0);
model.addAttribute("page", page);
model.addAttribute("size", size);
model.addAttribute("total", total);
model.addAttribute("totalPage", totalPage);
model.addAttribute("productHashMap", productHashMap);
model.addAttribute("user", user);
model.addAttribute("investList", invests);
}
catch (Throwable t) {
log.error(t.getMessage());
log.error("get invest list error", t);
model.addAttribute("code", -1);
}
return "/polyfinance-crimestory-business-service/invest/json/investListJson";
}
明天计划的事情:完成实名认证接口
遇到的问题:代码写的太慢 一点都不熟练
收获:java中的开方Math.sqrt(n)函数和平方{a的b次方Math.pow(a, b)}
实际上是调用的c的函数库
而java本身也可以 实现 如下 求开方的倒数
float InvSqrt(float x)
{
float xhalf = 0.5f*x;
int i = *(int*)&x; // get bits for floating VALUE
i = 0x5f375a86- (i>>1); // gives initial guess y0
x = *(float*)&i; // convert bits BACK to float
x = x*(1.5f-xhalf*x*x); // Newton step, repeating increases accuracy
x = x*(1.5f-xhalf*x*x); // Newton step, repeating increases accuracy
x = x*(1.5f-xhalf*x*x); // Newton step, repeating increases accuracy
return 1/x;
} 0x5f375a86 这个常量十分 玄奇
java 中的instanceof 运算符是用来在运行时指出对象是否是特定类的一个实例。instanceof通过返回一个布尔值来指出,这个对象是否是这个特定类或者是它的子类的一个实例。
用法:
result = object instanceof class
参数:
Result:布尔类型。
Object:必选项。任意对象表达式。
Class:必选项。任意已定义的对象类。
说明:
如果 object 是 class 的一个实例,则 instanceof 运算符返回 true。如果 object 不是指定类的一个实例,或者 object 是 null,则返回 false。
评论