@RequestMapping("/findAllProduct")
@ResponseBody
public Object findAllProduct(String callback) {
List<ProductInfo> productList = productService.findAllProduct();
for (ProductInfo productInfo : productList) {
productInfo.setSpecName(productService.findSpecById(productInfo.getProduct_unit()).getSpec_name());
productInfo.setProduct_typeName(productTypeService.findProductTypeById(productInfo.getProduct_type()).getPtype_name());
}
/*ArrayList<ProductInfo> arrayList = new ArrayList<>();
for (int i = 0; i < 10; i++) {
arrayList.add(productList.get(i));
}
System.out.println(arrayList.size());*/
List<ProductType> productTypeList = productTypeService.findAllProductType();
int allCount = productService.findProductCount();
int notShelfCount = productService.findProductNotShelf();
int shelfCount = productService.findProductShelf();
List<ProductInfo> productListNoShelf = productService.findProductNoShelf();
for (ProductInfo productInfo : productListNoShelf) {
productInfo.setSpecName(productService.findSpecById(productInfo.getProduct_unit()).getSpec_name());
productInfo.setProduct_typeName(productTypeService.findProductTypeById(productInfo.getProduct_type()).getPtype_name());
}
List<ProductInfo> productListShelf = productService.findProductIsShelf();
for (ProductInfo productInfo : productListShelf) {
productInfo.setSpecName(productService.findSpecById(productInfo.getProduct_unit()).getSpec_name());
productInfo.setProduct_typeName(productTypeService.findProductTypeById(productInfo.getProduct_type()).getPtype_name());
}
/*ArrayList<Object> list = new ArrayList<>();
list.add(productList);
list.add(productListShelf);
list.add(productListNoShelf);
list.add(productTypeList);
list.add(allCount);
list.add(shelfCount);
list.add(notShelfCount);*/
JsonNodeFactory factory = new JsonNodeFactory(false);
ObjectMapper mapper = new ObjectMapper();
ObjectNode obj= factory.objectNode();
try {
String jsonList1 = mapper.writeValueAsString(productList);
String jsonList2 = mapper.writeValueAsString(productListShelf);
String jsonList3 = mapper.writeValueAsString(productListNoShelf);
String jsonList4 = mapper.writeValueAsString(productTypeList);
String jsonList5 = mapper.writeValueAsString(allCount);
String jsonList6 = mapper.writeValueAsString(shelfCount);
String jsonList7 = mapper.writeValueAsString(notShelfCount);
obj.put("code", "0");
obj.put("msg", "成功!");
obj.put("productList", jsonList1);
obj.put("productListShelf", jsonList2);
obj.put("productListNoShelf", jsonList3);
obj.put("productTypeList", jsonList4);
obj.put("allCount", jsonList5);
obj.put("shelfCount", jsonList6);
obj.put("notShelfCount", jsonList7);
} catch (Exception e) {
obj.put("code", "1");
obj.put("msg", "失败!");
obj.put("data", "[]");
e.printStackTrace();
}
MappingJacksonValue jacksonValue = new MappingJacksonValue(obj);
jacksonValue.setJsonpFunction(callback);
return jacksonValue;
}
@ResponseBody
public Object findAllProduct(String callback) {
List<ProductInfo> productList = productService.findAllProduct();
for (ProductInfo productInfo : productList) {
productInfo.setSpecName(productService.findSpecById(productInfo.getProduct_unit()).getSpec_name());
productInfo.setProduct_typeName(productTypeService.findProductTypeById(productInfo.getProduct_type()).getPtype_name());
}
/*ArrayList<ProductInfo> arrayList = new ArrayList<>();
for (int i = 0; i < 10; i++) {
arrayList.add(productList.get(i));
}
System.out.println(arrayList.size());*/
List<ProductType> productTypeList = productTypeService.findAllProductType();
int allCount = productService.findProductCount();
int notShelfCount = productService.findProductNotShelf();
int shelfCount = productService.findProductShelf();
List<ProductInfo> productListNoShelf = productService.findProductNoShelf();
for (ProductInfo productInfo : productListNoShelf) {
productInfo.setSpecName(productService.findSpecById(productInfo.getProduct_unit()).getSpec_name());
productInfo.setProduct_typeName(productTypeService.findProductTypeById(productInfo.getProduct_type()).getPtype_name());
}
List<ProductInfo> productListShelf = productService.findProductIsShelf();
for (ProductInfo productInfo : productListShelf) {
productInfo.setSpecName(productService.findSpecById(productInfo.getProduct_unit()).getSpec_name());
productInfo.setProduct_typeName(productTypeService.findProductTypeById(productInfo.getProduct_type()).getPtype_name());
}
/*ArrayList<Object> list = new ArrayList<>();
list.add(productList);
list.add(productListShelf);
list.add(productListNoShelf);
list.add(productTypeList);
list.add(allCount);
list.add(shelfCount);
list.add(notShelfCount);*/
JsonNodeFactory factory = new JsonNodeFactory(false);
ObjectMapper mapper = new ObjectMapper();
ObjectNode obj= factory.objectNode();
try {
String jsonList1 = mapper.writeValueAsString(productList);
String jsonList2 = mapper.writeValueAsString(productListShelf);
String jsonList3 = mapper.writeValueAsString(productListNoShelf);
String jsonList4 = mapper.writeValueAsString(productTypeList);
String jsonList5 = mapper.writeValueAsString(allCount);
String jsonList6 = mapper.writeValueAsString(shelfCount);
String jsonList7 = mapper.writeValueAsString(notShelfCount);
obj.put("code", "0");
obj.put("msg", "成功!");
obj.put("productList", jsonList1);
obj.put("productListShelf", jsonList2);
obj.put("productListNoShelf", jsonList3);
obj.put("productTypeList", jsonList4);
obj.put("allCount", jsonList5);
obj.put("shelfCount", jsonList6);
obj.put("notShelfCount", jsonList7);
} catch (Exception e) {
obj.put("code", "1");
obj.put("msg", "失败!");
obj.put("data", "[]");
e.printStackTrace();
}
MappingJacksonValue jacksonValue = new MappingJacksonValue(obj);
jacksonValue.setJsonpFunction(callback);
return jacksonValue;
}