法务部学习笔记.md

公司学习笔记

  1. Mysql 让主键 归0:  TRUNCATE TABLE TableName

  2. 数量类,金额类字段类型设计设计为decimal,防止丢失精度,在java中对应bigdecimal

  3. ```
    //主键
    @TableId
    private Long id;
    //自动添加时间
    @TableField(fill = FieldFill.INSERT)
    private Date createTime;
    //自动更新时间
    @TableField(fill = FieldFill.INSERT_UPDATE)
    private Date updateTime;

    1
    2
    4. 跨服务调取
    在bms项目中查询customer中的数据库信息

//BMS中
//CustomerVipService
@FeignClient(name = ServiceNameConstants.CUSTOMER_SERVICE, fallbackFactory = CustomerManagerServiceFallbackFactory.class, decode404 = true)
public interface CustomerVipService {
@GetMapping(“/vipCustomer/vip”)
Integer getVipLimitByCustomerId(@RequestParam(“customerId”) Integer customerId);
}
//CustomerVipServiceFallbackFactory
public class CustomerVipServiceFallbackFactory implements FallbackFactory {
@Override
public CustomerVipService create(Throwable throwable) {
return new CustomerVipService() {
@Override
public Integer getVipLimitByCustomerId(Integer customerId) {
return 0;
}
};
}
}
//customer中
@ApiOperation(value = “根据用户ID查询vip限制合同下载份数”)
@GetMapping(“/vipCustomer/vip”)
public Integer findVipLimitByUid(@RequestParam(“customerId”) Integer customerId) {
VipCustomer vipCustomer = vipCustomerService.getOne(new QueryWrapper().eq(“customer_id”, customerId).eq(“is_del”, false));

    if(vipCustomer==null){
        return 0;
    }
    Vip vip=new Vip();
    vip.setId(Long.valueOf(vipCustomer.getVipId()));
    vip=vipService.getById(vip);
    return vip.getDayLimit();
}
1
5. redis使用
  redisRepository.setExpire("file_customer:date_"+DateUtil.format(new Date(),"yyyy-MM-dd")+":c_id_"+fileCustomerList.getCustomerId(),i,86400);
1
2
3
4
6. 格式化时间:` DateUtil.format(new Date(),"yyyy-MM-dd")`
7. 含有service的方法如果不写在service中,需要写在方法所调类中
8. 同时传入多个参数,有可不传入的,应放弃resultful风格。
9. map流遍历:

Collection orderProducts = orderProductService.list(new QueryWrapper().eq(“order_id”,order.getId()));
Long finalCustomerIdTemp = customerIdTemp;
List<Map<String,Object>> list = orderProducts.stream().map(orderProduct -> {
Map<String,Object> packageDetail = new HashMap<String,Object>();
packageDetail.put(“customerId”, finalCustomerIdTemp);
packageDetail.put(“productId”,orderProduct.getProductId());
packageDetail.put(“productName”,orderProduct.getProductName());
packageDetail.put(“isSend”,orderProduct.isSend());
packageDetail.put(“unit”,orderProduct.getUnit());
packageDetail.put(“num”,orderProduct.getNum());
return packageDetail;
}).collect(Collectors.toList());
```