Merge branch 'develop' of https://github.com/wangtianrui/NutritionMaster into develop
This commit is contained in:
31
README.md
31
README.md
@@ -164,12 +164,35 @@
|
|||||||
|
|
||||||
* 用户职业BMI分类 3多动,2中等,1少动 先 `getUser`获取到用户的职业名字.然后`getOccupation`获取到该职业的BMI分类
|
* 用户职业BMI分类 3多动,2中等,1少动 先 `getUser`获取到用户的职业名字.然后`getOccupation`获取到该职业的BMI分类
|
||||||
|
|
||||||
* 动态改变用户已吃的营养元素的量: 在用户表添加element参数,每周清空一次,每吃一个菜就记录一下
|
* 动态改变用户已吃的营养元素的量: 在用户表添加element参数,每周自动清空一次
|
||||||
|
|
||||||
* 获取用户本周已摄入的营养元素的量: `getUser`得到当前用户的信息,解析后用`MyUser`的`getEaten_elements()`获取到Element对象.里面有各种元素信息
|
* Map的可选参数: `[calorie,carbohydrate,fat ,protein,cellulose,vitaminA,vitaminB1,vitaminB2,vitaminB6,vitaminC,vitaminE,carotene,cholesterol,Mg,Ca,Fe,Zn,Cu,Mn,K ,P ,Na,Se,niacin ,thiamine]`
|
||||||
* 每吃一个菜就post一下
|
|
||||||
|
|
||||||

|
```java
|
||||||
|
public static void main(String[] args) {
|
||||||
|
//只传入变动的参数就行.
|
||||||
|
//比如 这顿饭摄入了100卡路里,10脂肪.就这样写.
|
||||||
|
Map<String, Double> params = new HashMap<>();
|
||||||
|
params.put("calorie", 100.0);
|
||||||
|
params.put("fat", 10.0);
|
||||||
|
|
||||||
|
//第一个参数是username,第二个参数是摄入的营养元素值.可以看函数的源码,有注释
|
||||||
|
WebUtil.getInstance().eatenElements("test5", params, new Callback() {
|
||||||
|
@Override
|
||||||
|
public void onFailure(Call call, IOException e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResponse(Call call, Response response) throws IOException {
|
||||||
|
System.out.println(new Gson().fromJson(response.body().string(), MyUser.class));
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
* 获取用户本周已摄入的营养元素的量: `getUser`得到当前用户的信息,解析后用`MyUser`的`getEaten_elements()`获取到Element对象.里面有各种元素信息
|
||||||
|
|
||||||
* **用户的浏览历史: 添加用户和菜谱的多对多关系**
|
* **用户的浏览历史: 添加用户和菜谱的多对多关系**
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
package com.example.ninefourone.nutritionmaster.bean;
|
package com.example.ninefourone.nutritionmaster.bean;
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class FoodMenu implements Serializable {
|
public class FoodMenu {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* flavor : 五香味
|
* flavor : 五香味
|
||||||
@@ -20,6 +20,7 @@ public class FoodMenu implements Serializable {
|
|||||||
private String flavor;
|
private String flavor;
|
||||||
private float calorie;
|
private float calorie;
|
||||||
private String name;
|
private String name;
|
||||||
|
private int is_breakfast;
|
||||||
private String technology;
|
private String technology;
|
||||||
private String image_url;
|
private String image_url;
|
||||||
private String practice;
|
private String practice;
|
||||||
@@ -33,6 +34,7 @@ public class FoodMenu implements Serializable {
|
|||||||
"flavor='" + flavor + '\'' +
|
"flavor='" + flavor + '\'' +
|
||||||
", calorie=" + calorie +
|
", calorie=" + calorie +
|
||||||
", name='" + name + '\'' +
|
", name='" + name + '\'' +
|
||||||
|
", is_breakfast=" + is_breakfast +
|
||||||
", technology='" + technology + '\'' +
|
", technology='" + technology + '\'' +
|
||||||
", image_url='" + image_url + '\'' +
|
", image_url='" + image_url + '\'' +
|
||||||
", practice='" + practice + '\'' +
|
", practice='" + practice + '\'' +
|
||||||
@@ -42,6 +44,14 @@ public class FoodMenu implements Serializable {
|
|||||||
'}';
|
'}';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getIs_breakfast() {
|
||||||
|
return is_breakfast;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIs_breakfast(int is_breakfast) {
|
||||||
|
this.is_breakfast = is_breakfast;
|
||||||
|
}
|
||||||
|
|
||||||
public String getFlavor() {
|
public String getFlavor() {
|
||||||
return flavor;
|
return flavor;
|
||||||
}
|
}
|
||||||
@@ -114,7 +124,7 @@ public class FoodMenu implements Serializable {
|
|||||||
this.menuclassification_set = menuclassification_set;
|
this.menuclassification_set = menuclassification_set;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class ElementsBean implements Serializable{
|
public static class ElementsBean {
|
||||||
/**
|
/**
|
||||||
* id : 3940
|
* id : 3940
|
||||||
* calorie : 183
|
* calorie : 183
|
||||||
@@ -412,7 +422,7 @@ public class FoodMenu implements Serializable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class CookQuantityBean implements Serializable{
|
public static class CookQuantityBean {
|
||||||
/**
|
/**
|
||||||
* menu : 五香酥鱼
|
* menu : 五香酥鱼
|
||||||
* quantity : 500
|
* quantity : 500
|
||||||
@@ -459,4 +469,3 @@ public class FoodMenu implements Serializable {
|
|||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -398,17 +398,20 @@ public class WebUtil {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户吃了一个菜,更新用户本周已吃摄入的营养元素的量
|
* 用户吃了一个菜,更新用户本周已吃摄入的营养元素的量
|
||||||
|
* 传入这顿饭摄入的营养量
|
||||||
* 返回当前user的最新信息,用MyUser类解析json
|
* 返回当前user的最新信息,用MyUser类解析json
|
||||||
*
|
|
||||||
* @param username
|
|
||||||
* @param menuName
|
|
||||||
*/
|
*/
|
||||||
public void eatenMenu(String username, String menuName, Callback callback) {
|
public void eatenElements(String username, Map<String, Double> elements, Callback callback) {
|
||||||
String url = "http://120.77.182.38/myuser/eaten_menu/";
|
String url = "http://120.77.182.38/myuser/eaten_menu/";
|
||||||
RequestBody formBody = new FormBody.Builder()
|
FormBody.Builder builder = new FormBody.Builder();
|
||||||
.add("username", username)
|
//构造RequestBody参数
|
||||||
.add("menu_name", menuName)
|
for (Map.Entry<String, Double> entry : elements.entrySet()) {
|
||||||
.build();
|
String key = entry.getKey();
|
||||||
|
double value = entry.getValue();
|
||||||
|
builder.add(key, String.valueOf(value));
|
||||||
|
}
|
||||||
|
builder.add("username", username);
|
||||||
|
RequestBody formBody = builder.build();
|
||||||
Request request = new Request.Builder()
|
Request request = new Request.Builder()
|
||||||
.url(url)
|
.url(url)
|
||||||
.post(formBody)
|
.post(formBody)
|
||||||
|
|||||||
Reference in New Issue
Block a user