From 359e994097e991a170b0a5d23d745bae84e7d23f Mon Sep 17 00:00:00 2001 From: liquanyu Date: Wed, 9 May 2018 17:40:35 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=93=E9=87=8D=E8=90=A5=E5=85=BB=E9=85=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lyms/platform/biz/BasicConfigServiceTest.java | 79 ++++++++-- .../com/lyms/platform/common/utils/ExcelUtil.java | 54 ++++++- .../java/com/lyms/platform/beans/SerialIdEnum.java | 1 + .../platform/pojo/WeightManageConfigModel.java | 167 +++++++++++++++++++++ 4 files changed, 288 insertions(+), 13 deletions(-) create mode 100644 platform-dal/src/main/java/com/lyms/platform/pojo/WeightManageConfigModel.java diff --git a/platform-biz-patient-service/src/main/java/com/lyms/platform/biz/BasicConfigServiceTest.java b/platform-biz-patient-service/src/main/java/com/lyms/platform/biz/BasicConfigServiceTest.java index 59a8bfa..84d8c73 100644 --- a/platform-biz-patient-service/src/main/java/com/lyms/platform/biz/BasicConfigServiceTest.java +++ b/platform-biz-patient-service/src/main/java/com/lyms/platform/biz/BasicConfigServiceTest.java @@ -23,6 +23,10 @@ import com.lyms.platform.common.utils.*; import com.lyms.platform.pojo.*; import com.lyms.platform.query.*; import com.qiniu.util.Json; +import jxl.Cell; +import jxl.Sheet; +import jxl.Workbook; +import jxl.read.biff.BiffException; import org.apache.commons.codec.binary.Base64; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.NameValuePair; @@ -785,27 +789,82 @@ public class BasicConfigServiceTest { } - public static void weightMange() + public static void weightMange(String fileName) { + + WeightManageConfigModel model = new WeightManageConfigModel(); + File file = new File(fileName); + Workbook wb = null; try { - List list = FileUtils.readLines(new File("F:\\体重与营养管理1.csv")); - for (String line : list) { - if (line != null) { - String[] array = line.split(","); - System.out.println(array.length); - for (int i = 0; i < array.length ;i++ ) - { - System.out.println("--->"+array[i]); + wb = Workbook.getWorkbook(file); + Sheet[] sheets = wb.getSheets(); + + for(Sheet s : sheets){ + System.out.println(s.getName() + " : "); + int rows = s.getRows(); + if(rows > 0){ + //遍历每行 + for(int i = 1 ;i < rows ; i++){ + Cell[] cells = s.getRow(i); + if(cells.length > 0){ + //遍历每行中的每列 + for (int j = 0 ; j < cells.length ; j ++) + { + String str = cells[j].getContents().trim(); + switch (j) + { + case 0: + model.setWeek(str); + case 1: + model.setExample(str); + case 2: + model.setBreakfast(str); + case 3: + model.setBreakfastAdd(str); + case 4: + model.setLunch(str); + case 5: + model.setLunchAdd(str); + case 6: + model.setDinner(str); + case 7: + model.setDinnerAdd(str); + case 8: + model.setVegetable(str); + case 9 : + model.setFoodMaterial(str); + case 10: + List list = Arrays.asList(str.split("\n")); + model.setMakeMethod(list); + case 11: + model.setWeightType(str); + case 12: + List list1 = Arrays.asList(str.split("\n")); + model.setSuggests(list1); + } + } + + } } } } + ApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:/spring/applicationContext_biz_patient1.xml"); + MongoTemplate mongoTemplate + = (MongoTemplate) applicationContext.getBean("mongoTemplate"); + mongoTemplate.getDb().authenticate("platform", "platform123".toCharArray()); + + mongoTemplate.save(model); + System.out.println(model); } catch (IOException e) { e.printStackTrace(); + } catch (BiffException e) { + e.printStackTrace(); } + } public static void main(String[] args) { - weightMange(); + weightMange("F:\\1.xls"); } public static void addBaby(ApplicationContext applicationContext) { diff --git a/platform-common/src/main/java/com/lyms/platform/common/utils/ExcelUtil.java b/platform-common/src/main/java/com/lyms/platform/common/utils/ExcelUtil.java index 3cead64..de6f483 100644 --- a/platform-common/src/main/java/com/lyms/platform/common/utils/ExcelUtil.java +++ b/platform-common/src/main/java/com/lyms/platform/common/utils/ExcelUtil.java @@ -3,14 +3,15 @@ package com.lyms.platform.common.utils; import java.io.File; import java.io.IOException; import java.io.OutputStream; -import java.util.Iterator; -import java.util.List; -import java.util.Map; +import java.util.*; +import jxl.Cell; +import jxl.Sheet; import jxl.Workbook; import jxl.format.Colour; import jxl.format.UnderlineStyle; +import jxl.read.biff.BiffException; import jxl.write.Label; import jxl.write.WritableCellFormat; import jxl.write.WritableFont; @@ -191,6 +192,53 @@ public class ExcelUtil return out; } + public static void readExcl(String fileName) + { + File file = new File(fileName); + Workbook wb = null; + try { + wb = Workbook.getWorkbook(file); + Sheet[] sheets = wb.getSheets(); + + for(Sheet s : sheets){ + System.out.println(s.getName() + " : "); + int rows = s.getRows(); + if(rows > 0){ + //遍历每行 + for(int i = 1 ;i < rows ; i++){ + Cell[] cells = s.getRow(i); + if(cells.length > 0){ + //遍历每行中的每列 + for (int j = 0 ; j < cells.length ; j ++) + { + String str = cells[j].getContents().trim(); + if (j == 10 || j == 12) + { + List list = Arrays.asList(str.split("\n")); + System.out.println(j+"=content="+list); + } + else + { + System.out.println(j+"=content="+str); + } + + } + + } + } + } + } + } catch (IOException e) { + e.printStackTrace(); + } catch (BiffException e) { + e.printStackTrace(); + } + + } + + public static void main(String[] args) { + ExcelUtil.readExcl("F:\\1.xls"); + } } diff --git a/platform-dal/src/main/java/com/lyms/platform/beans/SerialIdEnum.java b/platform-dal/src/main/java/com/lyms/platform/beans/SerialIdEnum.java index 2ba8923..8252621 100644 --- a/platform-dal/src/main/java/com/lyms/platform/beans/SerialIdEnum.java +++ b/platform-dal/src/main/java/com/lyms/platform/beans/SerialIdEnum.java @@ -6,6 +6,7 @@ package com.lyms.platform.beans; public enum SerialIdEnum { AntenatalExaminationModel("AntenatalExaminationModel", 97531000010L), AntExChuModel("AntExChuModel", 97531000020L), + WeightManageConfigModel("WeightManageConfigModel", 97534000020L), OperateLogModel("OperateLogModel", 97531000121L), AntExRecordModel("AntExRecordModel", 97531000030L), ArchiveData("ArchiveData", 97531000040L), diff --git a/platform-dal/src/main/java/com/lyms/platform/pojo/WeightManageConfigModel.java b/platform-dal/src/main/java/com/lyms/platform/pojo/WeightManageConfigModel.java new file mode 100644 index 0000000..78eb430 --- /dev/null +++ b/platform-dal/src/main/java/com/lyms/platform/pojo/WeightManageConfigModel.java @@ -0,0 +1,167 @@ +package com.lyms.platform.pojo; + +import com.lyms.platform.beans.SerialIdEnum; +import com.lyms.platform.common.result.BaseModel; +import org.springframework.data.mongodb.core.mapping.Document; + +import java.util.Date; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +/** + * 体重营养管理基础配置数据模型 + * + */ +@Document(collection = "lyms_weight_config") +public class WeightManageConfigModel extends BaseModel { + + private static final long serialVersionUID = SerialIdEnum.WeightManageConfigModel.getCid(); + private String id; + private String week;//孕周 + private String example;//营养食谱举例 + private String breakfast;//早餐 + private String breakfastAdd;//上午加餐 + private String lunch;//午餐 + private String lunchAdd;//下午加餐 + private String dinner;//晚餐 + private String dinnerAdd;//晚加餐 + + private String vegetable;//菜名称 + private String foodMaterial; //食材 + private List makeMethod;//制作方法 + private String weightType;//体重类型 + private List suggests;//建议 + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getWeek() { + return week; + } + + public void setWeek(String week) { + this.week = week; + } + + public String getExample() { + return example; + } + + public void setExample(String example) { + this.example = example; + } + + public String getBreakfast() { + return breakfast; + } + + public void setBreakfast(String breakfast) { + this.breakfast = breakfast; + } + + public String getBreakfastAdd() { + return breakfastAdd; + } + + public void setBreakfastAdd(String breakfastAdd) { + this.breakfastAdd = breakfastAdd; + } + + public String getLunch() { + return lunch; + } + + public void setLunch(String lunch) { + this.lunch = lunch; + } + + public String getLunchAdd() { + return lunchAdd; + } + + public void setLunchAdd(String lunchAdd) { + this.lunchAdd = lunchAdd; + } + + public String getDinner() { + return dinner; + } + + public void setDinner(String dinner) { + this.dinner = dinner; + } + + public String getDinnerAdd() { + return dinnerAdd; + } + + public void setDinnerAdd(String dinnerAdd) { + this.dinnerAdd = dinnerAdd; + } + + public String getVegetable() { + return vegetable; + } + + public void setVegetable(String vegetable) { + this.vegetable = vegetable; + } + + public String getFoodMaterial() { + return foodMaterial; + } + + public void setFoodMaterial(String foodMaterial) { + this.foodMaterial = foodMaterial; + } + + public List getMakeMethod() { + return makeMethod; + } + + public void setMakeMethod(List makeMethod) { + this.makeMethod = makeMethod; + } + + public String getWeightType() { + return weightType; + } + + public void setWeightType(String weightType) { + this.weightType = weightType; + } + + public List getSuggests() { + return suggests; + } + + public void setSuggests(List suggests) { + this.suggests = suggests; + } + + @Override + public String toString() { + return "WeightManageConfigModel{" + + "id='" + id + '\'' + + ", week='" + week + '\'' + + ", example='" + example + '\'' + + ", breakfast='" + breakfast + '\'' + + ", breakfastAdd='" + breakfastAdd + '\'' + + ", lunch='" + lunch + '\'' + + ", lunchAdd='" + lunchAdd + '\'' + + ", dinner='" + dinner + '\'' + + ", dinnerAdd='" + dinnerAdd + '\'' + + ", vegetable='" + vegetable + '\'' + + ", foodMaterial=" + foodMaterial + + ", makeMethod=" + makeMethod + + ", weightType='" + weightType + '\'' + + ", suggests='" + suggests + '\'' + + '}'; + } +} -- 1.8.3.1