|
@@ -1,20 +1,18 @@
|
|
package com.dt.common.service.impl;
|
|
package com.dt.common.service.impl;
|
|
|
|
|
|
|
|
+
|
|
import cn.hutool.poi.excel.ExcelUtil;
|
|
import cn.hutool.poi.excel.ExcelUtil;
|
|
import cn.hutool.poi.excel.sax.handler.RowHandler;
|
|
import cn.hutool.poi.excel.sax.handler.RowHandler;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
-import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
-import com.dt.common.domain.Child;
|
|
|
|
-import com.dt.common.domain.FoodRecord;
|
|
|
|
-import com.dt.common.mapper.ChildMapper;
|
|
|
|
|
|
+import com.dt.care.dto.AgesNameDto;
|
|
|
|
+import com.dt.common.domain.*;
|
|
|
|
+import com.dt.common.mapper.*;
|
|
import com.dt.common.service.FoodRecordService;
|
|
import com.dt.common.service.FoodRecordService;
|
|
-import com.dt.common.mapper.FoodRecordMapper;
|
|
|
|
-import com.dt.user.mapper.UserMapper;
|
|
|
|
-import com.dt.user.pojo.User;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
import java.io.InputStream;
|
|
import java.io.InputStream;
|
|
@@ -29,104 +27,186 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|
@Service
|
|
@Service
|
|
@Slf4j
|
|
@Slf4j
|
|
public class FoodRecordServiceImpl extends ServiceImpl<FoodRecordMapper, FoodRecord>
|
|
public class FoodRecordServiceImpl extends ServiceImpl<FoodRecordMapper, FoodRecord>
|
|
- implements FoodRecordService {
|
|
|
|
|
|
+ implements FoodRecordService{
|
|
|
|
|
|
|
|
|
|
- @Resource
|
|
|
|
- private ChildMapper childMapper;
|
|
|
|
- @Resource
|
|
|
|
- private UserMapper userMapper;
|
|
|
|
|
|
|
|
- static AtomicInteger num = new AtomicInteger(0);
|
|
|
|
|
|
+ @Resource
|
|
|
|
+ private HxwVaccineCategoriesMapper hxwVaccineCategoriesMapper;
|
|
|
|
+ @Resource
|
|
|
|
+ private HxwVaccinesMapper hxwVaccinesMapper;
|
|
|
|
+ @Resource
|
|
|
|
+ private HxwVaccineExpertRelationsMapper hxwVaccineExpertRelationsMapper;
|
|
|
|
+ @Resource
|
|
|
|
+ private HxwVaccineExpertsMapper hxwVaccineExpertsMapper;
|
|
|
|
+ @Resource
|
|
|
|
+ private HxwVaccineDetailsMapper hxwVaccineDetailsMapper;
|
|
|
|
+ @Resource
|
|
|
|
+ private HxwVaccineDiscussionsMapper hxwVaccineDiscussionsMapper;
|
|
|
|
+ @Resource
|
|
|
|
+ private HxwVaccineContentModulesMapper hxwVaccineContentModulesMapper;
|
|
|
|
+// @Resource
|
|
|
|
+// private UserMapper userMapper;
|
|
|
|
|
|
- @Override
|
|
|
|
- public void leadIn(InputStream inputStream) {
|
|
|
|
- List<FoodRecord> list = new ArrayList<>();
|
|
|
|
- ExcelUtil.readBySax(inputStream, -1, createRowHandler(list));
|
|
|
|
- if (!CollectionUtils.isEmpty(list)) {
|
|
|
|
- batchAddFoodRecord(list);
|
|
|
|
- }
|
|
|
|
|
|
+ @Resource
|
|
|
|
+ private HxwKnowledgeArticlesMapper hxwKnowledgeArticlesMapper;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @Resource
|
|
|
|
+ private ChildMapper childMapper;
|
|
|
|
+ @Resource
|
|
|
|
+ private UserMapper userMapper;
|
|
|
|
+
|
|
|
|
+ static AtomicInteger num=new AtomicInteger(0);
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void leadIn(InputStream inputStream) {
|
|
|
|
+ List<FoodRecord> list=new ArrayList<>();
|
|
|
|
+ ExcelUtil.readBySax(inputStream, -1, createRowHandler(list));
|
|
|
|
+ if(!CollectionUtils.isEmpty(list)){
|
|
|
|
+ batchAddFoodRecord(list);
|
|
}
|
|
}
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
- public void batchAddFoodRecord(List<FoodRecord> list) {
|
|
|
|
|
|
+ public void batchAddFoodRecord(List<FoodRecord> list){
|
|
|
|
|
|
- for (FoodRecord foodRecord : list) {
|
|
|
|
- num.getAndIncrement();
|
|
|
|
|
|
+ for (FoodRecord foodRecord : list){
|
|
|
|
+ num.getAndIncrement();
|
|
try {
|
|
try {
|
|
addFoodRecord(foodRecord);
|
|
addFoodRecord(foodRecord);
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
- log.info("第" + num.get() + "行数据插入失败");
|
|
|
|
|
|
+ log.info("第"+num.get()+"行数据插入失败");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
- @Transactional(rollbackFor = {Exception.class, RuntimeException.class})
|
|
|
|
- public void addFoodRecord(FoodRecord foodRecord) {
|
|
|
|
- if (foodRecord != null) {
|
|
|
|
- this.baseMapper.insert(foodRecord);
|
|
|
|
- }
|
|
|
|
|
|
+ @Transactional(rollbackFor = {Exception.class, RuntimeException.class})
|
|
|
|
+ public void addFoodRecord(FoodRecord foodRecord){
|
|
|
|
+ if (foodRecord!=null){
|
|
|
|
+ this.baseMapper.insert(foodRecord);
|
|
}
|
|
}
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
- private RowHandler createRowHandler(List<FoodRecord> foodRecordList) {
|
|
|
|
- return new RowHandler() {
|
|
|
|
- @Override
|
|
|
|
- public void handle(int i, long l, List<Object> list) {
|
|
|
|
- if (l > 0) {
|
|
|
|
- String childName = list.get(0).toString();
|
|
|
|
- QueryWrapper<Child> wrapper = new QueryWrapper<>();
|
|
|
|
- wrapper.eq("name", childName);
|
|
|
|
- Child child = childMapper.selectOne(wrapper);
|
|
|
|
- if (child == null) {
|
|
|
|
- log.warn("第{}行数据被跳过:未找到姓名为【{}】的幼儿", l, childName);
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- Long id = child.getId();
|
|
|
|
- Date recordTime = (Date) list.get(1);
|
|
|
|
-
|
|
|
|
- Map<String, Integer> map = new HashMap<>();//将食谱名称映射成数字
|
|
|
|
- map.put("早餐", 0);
|
|
|
|
- map.put("上午加餐", 1);
|
|
|
|
- map.put("午餐", 2);
|
|
|
|
- map.put("下午加餐", 3);
|
|
|
|
- map.put("晚餐", 4);
|
|
|
|
-
|
|
|
|
- String goodName = list.get(2).toString();//食谱名称
|
|
|
|
- Integer mealType = map.get(goodName);//食谱名称对应的数字
|
|
|
|
- if (mealType == null) {
|
|
|
|
- mealType = 5;
|
|
|
|
- }
|
|
|
|
- String foodContent = list.get(3).toString();
|
|
|
|
- String amount = list.get(4).toString();
|
|
|
|
- String remark = list.get(5).toString();
|
|
|
|
- String username = list.get(6).toString();
|
|
|
|
- QueryWrapper<User> userWrapper = new QueryWrapper<>();
|
|
|
|
- userWrapper.eq("username", username);
|
|
|
|
- User user = userMapper.selectOne(userWrapper);
|
|
|
|
- if (user == null) {
|
|
|
|
- log.warn("第{}行数据被跳过:未找到名称为【{}】的记录人", l, username);
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- Long recorderId = user.getId();
|
|
|
|
- FoodRecord foodRecord = new FoodRecord();
|
|
|
|
- foodRecord.setChildId(id);
|
|
|
|
- foodRecord.setRecordTime(recordTime);
|
|
|
|
- foodRecord.setMealType(mealType);
|
|
|
|
- foodRecord.setFoodContent(foodContent);
|
|
|
|
- foodRecord.setAmount(amount);
|
|
|
|
- foodRecord.setRemark(remark);
|
|
|
|
- foodRecord.setRecorderId(recorderId);
|
|
|
|
- foodRecordList.add(foodRecord);
|
|
|
|
|
|
+
|
|
|
|
+ private RowHandler createRowHandler(List<FoodRecord> foodRecordList){
|
|
|
|
+ return new RowHandler() {
|
|
|
|
+ @Override
|
|
|
|
+ public void handle(int i, long l, List<Object> list) {
|
|
|
|
+ if(l>0){
|
|
|
|
+ String childName = list.get(0).toString();
|
|
|
|
+ QueryWrapper<Child> wrapper=new QueryWrapper<>();
|
|
|
|
+ wrapper.eq("name",childName);
|
|
|
|
+ Child child = childMapper.selectOne(wrapper);
|
|
|
|
+ if(child==null){
|
|
|
|
+ log.warn("第{}行数据被跳过:未找到姓名为【{}】的幼儿", l, childName);
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ Long id = child.getId();
|
|
|
|
+ Date recordTime = (Date) list.get(1);
|
|
|
|
+
|
|
|
|
+ Map<String,Integer> map=new HashMap<>();//将食谱名称映射成数字
|
|
|
|
+ map.put("早餐",0);
|
|
|
|
+ map.put("上午加餐",1);
|
|
|
|
+ map.put("午餐",2);
|
|
|
|
+ map.put("下午加餐",3);
|
|
|
|
+ map.put("晚餐",4);
|
|
|
|
+
|
|
|
|
+ String goodName = list.get(2).toString();//食谱名称
|
|
|
|
+ Integer mealType = map.get(goodName);//食谱名称对应的数字
|
|
|
|
+ if(mealType==null){
|
|
|
|
+ mealType=5;
|
|
}
|
|
}
|
|
|
|
+ String foodContent =list.get(3).toString();
|
|
|
|
+ String amount = list.get(4).toString();
|
|
|
|
+ String remark=list.get(5).toString();
|
|
|
|
+ String username = list.get(6).toString();
|
|
|
|
+ QueryWrapper<User> userWrapper=new QueryWrapper<>();
|
|
|
|
+ userWrapper.eq("username",username);
|
|
|
|
+ User user = userMapper.selectOne(userWrapper);
|
|
|
|
+ if (user==null){
|
|
|
|
+ log.warn("第{}行数据被跳过:未找到名称为【{}】的记录人", l, username);
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ Long recorderId = user.getId();
|
|
|
|
+ FoodRecord foodRecord=new FoodRecord();
|
|
|
|
+ foodRecord.setChildId(id);
|
|
|
|
+ foodRecord.setRecordTime(recordTime);
|
|
|
|
+ foodRecord.setMealType(mealType);
|
|
|
|
+ foodRecord.setFoodContent(foodContent);
|
|
|
|
+ foodRecord.setAmount(amount);
|
|
|
|
+ foodRecord.setRemark(remark);
|
|
|
|
+ foodRecord.setRecorderId(recorderId);
|
|
|
|
+ foodRecordList.add(foodRecord);
|
|
}
|
|
}
|
|
- };
|
|
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
|
+ };
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public HxwVaccines findByVaccinesDetails(AgesNameDto dto) {
|
|
|
|
+ QueryWrapper<HxwVaccines> wrapper=new QueryWrapper<>();
|
|
|
|
+ wrapper.eq("name",dto.getVaccinesName());
|
|
|
|
+ HxwVaccines hxwVaccines = hxwVaccinesMapper.selectOne(wrapper);//疫苗基本信息
|
|
|
|
+ Integer id = hxwVaccines.getId();//疫苗id
|
|
|
|
+ if (id!=null){
|
|
|
|
+ QueryWrapper<HxwVaccineExpertRelations> wrapper1=new QueryWrapper<>();
|
|
|
|
+ wrapper1.eq("vaccine_id",id);
|
|
|
|
+ HxwVaccineExpertRelations hxwVaccineExpertRelations = hxwVaccineExpertRelationsMapper.selectOne(wrapper1);
|
|
|
|
+ Integer expertId = hxwVaccineExpertRelations.getExpertId();//医生 id
|
|
|
|
+ QueryWrapper<HxwVaccineExperts> wrapper2=new QueryWrapper<>();
|
|
|
|
+ wrapper2.eq("id",expertId);
|
|
|
|
+ HxwVaccineExperts hxwVaccineExperts = hxwVaccineExpertsMapper.selectOne(wrapper2);
|
|
|
|
+ hxwVaccines.setExperts(hxwVaccineExperts);//设置医生信息
|
|
|
|
+ QueryWrapper<HxwVaccineDetails> wrapper3=new QueryWrapper<>();
|
|
|
|
+ wrapper3.eq("vaccine_id",id);
|
|
|
|
+ HxwVaccineDetails hxwVaccineDetails = hxwVaccineDetailsMapper.selectOne(wrapper3);
|
|
|
|
+ hxwVaccines.setDetails(hxwVaccineDetails);//设置疫苗详情信息
|
|
|
|
+ QueryWrapper<HxwVaccineDiscussions> wrapper4=new QueryWrapper<>();
|
|
|
|
+ wrapper4.eq("vaccine_id",id);
|
|
|
|
+ List<HxwVaccineDiscussions> hxwVaccineDiscussions = hxwVaccineDiscussionsMapper.selectList(wrapper4);
|
|
|
|
+ for (HxwVaccineDiscussions discussion : hxwVaccineDiscussions){
|
|
|
|
+ Integer userId = discussion.getUserId();
|
|
|
|
+ QueryWrapper<User> wrapper5=new QueryWrapper<>();
|
|
|
|
+ wrapper5.eq("id",userId);
|
|
|
|
+ User user = userMapper.selectOne(wrapper5);
|
|
|
|
+ discussion.setUser(user);
|
|
|
|
+ }
|
|
|
|
+ System.err.println("_-----------------"+hxwVaccineDiscussions);
|
|
|
|
+ hxwVaccines.setDiscussions(hxwVaccineDiscussions);//设置讨论信息
|
|
|
|
+ QueryWrapper<HxwVaccineContentModules> wrapper8=new QueryWrapper<>();
|
|
|
|
+ wrapper8.eq("vaccine_id",id);
|
|
|
|
+ List<HxwVaccineContentModules> hxwVaccineContentModules = hxwVaccineContentModulesMapper.selectList(wrapper8);
|
|
|
|
+ hxwVaccines.setContentModules(hxwVaccineContentModules);//设置内容模块信息
|
|
|
|
+ QueryWrapper<HxwKnowledgeArticles> wrapper6=new QueryWrapper<>();
|
|
|
|
+ wrapper6.eq("related_vaccine_id",id);
|
|
|
|
+ List<HxwKnowledgeArticles> hxwKnowledgeArticles = hxwKnowledgeArticlesMapper.selectList(wrapper6);
|
|
|
|
+ hxwVaccines.setArticles(hxwKnowledgeArticles);
|
|
|
|
+ return hxwVaccines;
|
|
|
|
+ }else {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
|
|
|
|
|