|
@@ -1,7 +1,13 @@
|
|
package org.dromara.web.service.impl;
|
|
package org.dromara.web.service.impl;
|
|
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
|
+import cn.hutool.core.map.MapUtil;
|
|
|
|
+import cn.hutool.core.util.ObjUtil;
|
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
|
+import cn.idev.excel.FastExcel;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
+import org.dromara.common.core.domain.R;
|
|
import org.dromara.common.core.utils.MapstructUtils;
|
|
import org.dromara.common.core.utils.MapstructUtils;
|
|
import org.dromara.common.core.utils.StringUtils;
|
|
import org.dromara.common.core.utils.StringUtils;
|
|
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
|
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
|
@@ -10,17 +16,29 @@ import org.dromara.common.mybatis.core.page.PageQuery;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import org.dromara.system.domain.SysDiseaseLabel;
|
|
|
|
+import org.dromara.system.domain.bo.SysDiseaseLabelBo;
|
|
|
|
+import org.dromara.system.domain.vo.SysDeptVo;
|
|
|
|
+import org.dromara.system.domain.vo.SysDiseaseLabelVo;
|
|
|
|
+import org.dromara.system.service.ISysDeptService;
|
|
|
|
+import org.dromara.system.service.ISysDictDataService;
|
|
|
|
+import org.dromara.system.service.ISysDiseaseLabelService;
|
|
|
|
+import org.dromara.web.domain.ProductCategory;
|
|
import org.dromara.web.domain.ProductNutrition;
|
|
import org.dromara.web.domain.ProductNutrition;
|
|
|
|
+import org.dromara.web.domain.TreatmentUser;
|
|
|
|
+import org.dromara.web.domain.bo.BatchProductNuyritionBo;
|
|
import org.dromara.web.domain.bo.ProductNutritionBo;
|
|
import org.dromara.web.domain.bo.ProductNutritionBo;
|
|
|
|
+import org.dromara.web.domain.vo.ProductCategoryVo;
|
|
import org.dromara.web.domain.vo.ProductNutritionVo;
|
|
import org.dromara.web.domain.vo.ProductNutritionVo;
|
|
import org.dromara.web.mapper.ProductNutritionMapper;
|
|
import org.dromara.web.mapper.ProductNutritionMapper;
|
|
|
|
+import org.dromara.web.service.IProductCategoryService;
|
|
import org.dromara.web.service.IProductNutritionService;
|
|
import org.dromara.web.service.IProductNutritionService;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
|
|
-import java.util.List;
|
|
|
|
-import java.util.Map;
|
|
|
|
-import java.util.Collection;
|
|
|
|
|
|
+import java.util.*;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 营养产品信息Service业务层处理
|
|
* 营养产品信息Service业务层处理
|
|
@@ -35,6 +53,15 @@ public class ProductNutritionServiceImpl implements IProductNutritionService {
|
|
|
|
|
|
private final ProductNutritionMapper baseMapper;
|
|
private final ProductNutritionMapper baseMapper;
|
|
|
|
|
|
|
|
+ private final ISysDeptService deptService;
|
|
|
|
+
|
|
|
|
+ private final ISysDictDataService dictDataService;
|
|
|
|
+
|
|
|
|
+ private final IProductCategoryService categoryService;
|
|
|
|
+
|
|
|
|
+ private final ISysDiseaseLabelService diseaseLabelService;
|
|
|
|
+
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 查询营养产品信息
|
|
* 查询营养产品信息
|
|
*
|
|
*
|
|
@@ -43,7 +70,88 @@ public class ProductNutritionServiceImpl implements IProductNutritionService {
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
public ProductNutritionVo queryById(Long id) {
|
|
public ProductNutritionVo queryById(Long id) {
|
|
- return baseMapper.selectVoById(id);
|
|
|
|
|
|
+ ProductNutritionVo nutritionVo = baseMapper.selectVoById(id);
|
|
|
|
+ if (null != nutritionVo) {
|
|
|
|
+ String categoryIdsStr = nutritionVo.getProductCategory();
|
|
|
|
+ if (StringUtils.isNotBlank(categoryIdsStr)) {//处理产品分类
|
|
|
|
+ List<String> categoryNames = Arrays.stream(categoryIdsStr.split(",")).map(String::trim).filter(StringUtils::isNotBlank).map(cateId -> {
|
|
|
|
+ try {
|
|
|
|
+ return categoryService.queryById(Long.parseLong(cateId));
|
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ }).filter(Objects::nonNull).map(ProductCategoryVo::getCategoryName).filter(StringUtils::isNotBlank).collect(Collectors.toList());
|
|
|
|
+ if (!categoryNames.isEmpty()) {
|
|
|
|
+ nutritionVo.setProductCategory(String.join(",", categoryNames));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ String labelIdsStr = nutritionVo.getProductLabel();
|
|
|
|
+ String contraindicationLabelIdsStr = nutritionVo.getContraindicationLabel();
|
|
|
|
+
|
|
|
|
+ // 处理产品标签
|
|
|
|
+ if (StringUtils.isNotBlank(labelIdsStr)) {
|
|
|
|
+ List<String> labelNames = Arrays.stream(labelIdsStr.split(",")).map(String::trim).filter(StringUtils::isNotBlank).map(labelid -> {
|
|
|
|
+ try {
|
|
|
|
+ return diseaseLabelService.queryById(Long.parseLong(labelid));
|
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ }).filter(Objects::nonNull).map(SysDiseaseLabelVo::getLabelName).filter(StringUtils::isNotBlank).collect(Collectors.toList());
|
|
|
|
+
|
|
|
|
+ if (!labelNames.isEmpty()) {
|
|
|
|
+ nutritionVo.setProductLabel(String.join(",", labelNames));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 处理禁忌标签
|
|
|
|
+ if (StringUtils.isNotBlank(contraindicationLabelIdsStr)) {
|
|
|
|
+ List<String> contraindicationLabelNames = Arrays.stream(contraindicationLabelIdsStr.split(",")).map(String::trim).filter(StringUtils::isNotBlank).map(labelId -> {
|
|
|
|
+ try {
|
|
|
|
+ return diseaseLabelService.queryById(Long.parseLong(labelId));
|
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ }).filter(Objects::nonNull).map(SysDiseaseLabelVo::getLabelName).filter(StringUtils::isNotBlank).collect(Collectors.toList());
|
|
|
|
+
|
|
|
|
+ if (!contraindicationLabelNames.isEmpty()) {
|
|
|
|
+ nutritionVo.setContraindicationLabel(String.join(",", contraindicationLabelNames));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ String departmentIdsStr = nutritionVo.getApplicableDepartment();
|
|
|
|
+ if (StringUtils.isNotBlank(departmentIdsStr)) {
|
|
|
|
+ List<String> departmentGroups = new ArrayList<>();
|
|
|
|
+ // 按分号分组
|
|
|
|
+ String[] groups = departmentIdsStr.split(";");
|
|
|
|
+ Long deptId = null;
|
|
|
|
+ SysDeptVo deptVo = null;
|
|
|
|
+ for (String group : groups) {
|
|
|
|
+ List<String> groupNames = new ArrayList<>();
|
|
|
|
+ String[] deptIds = group.split(",");
|
|
|
|
+
|
|
|
|
+ for (String deptIdStr : deptIds) {
|
|
|
|
+ try {
|
|
|
|
+ deptId = Long.parseLong(deptIdStr.trim());
|
|
|
|
+ deptVo = deptService.selectDeptById(deptId);
|
|
|
|
+ if (deptVo != null && StringUtils.isNotBlank(deptVo.getDeptName())) {
|
|
|
|
+ groupNames.add(deptVo.getDeptName());
|
|
|
|
+ }
|
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
|
+ // 记录日志或处理异常
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (!groupNames.isEmpty()) {
|
|
|
|
+ departmentGroups.add(String.join("/", groupNames));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (!departmentGroups.isEmpty()) {
|
|
|
|
+ nutritionVo.setApplicableDepartment(String.join(",", departmentGroups));
|
|
|
|
+ } else {
|
|
|
|
+ nutritionVo.setApplicableDepartment("");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return nutritionVo;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -79,10 +187,10 @@ public class ProductNutritionServiceImpl implements IProductNutritionService {
|
|
categoryIds = String.join(",", bo.getProductCategoryList());
|
|
categoryIds = String.join(",", bo.getProductCategoryList());
|
|
}
|
|
}
|
|
LambdaQueryWrapper<ProductNutrition> lqw = Wrappers.lambdaQuery();
|
|
LambdaQueryWrapper<ProductNutrition> lqw = Wrappers.lambdaQuery();
|
|
- lqw.orderByAsc(ProductNutrition::getId);
|
|
|
|
- lqw.like(StringUtils.isNotBlank(bo.getProductName()), ProductNutrition::getProductName, bo.getProductName());
|
|
|
|
- lqw.like(StringUtils.isNotBlank(bo.getProductCode()), ProductNutrition::getProductCode, bo.getProductName());
|
|
|
|
- lqw.eq(StringUtils.isNotBlank(bo.getProductCode()), ProductNutrition::getProductCode, bo.getProductCode());
|
|
|
|
|
|
+ lqw.orderByDesc(ProductNutrition::getCreateTime);
|
|
|
|
+ if (StringUtils.isNotBlank(bo.getProductName())) {
|
|
|
|
+ lqw.and(wrapper -> wrapper.like(ProductNutrition::getProductName, bo.getProductName()).or().like(ProductNutrition::getProductCode, bo.getProductName()).or());
|
|
|
|
+ }
|
|
if (StringUtils.isNotBlank(categoryIds)) {
|
|
if (StringUtils.isNotBlank(categoryIds)) {
|
|
lqw.eq(ProductNutrition::getProductCategory, categoryIds);
|
|
lqw.eq(ProductNutrition::getProductCategory, categoryIds);
|
|
}
|
|
}
|
|
@@ -98,6 +206,29 @@ public class ProductNutritionServiceImpl implements IProductNutritionService {
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
public Boolean insertByBo(ProductNutritionBo bo) {
|
|
public Boolean insertByBo(ProductNutritionBo bo) {
|
|
|
|
+ String categoryIds = null;
|
|
|
|
+ String productLabel = null;
|
|
|
|
+ String contraindicationLabel = null;
|
|
|
|
+ if (bo.getProductCategoryList() != null && !bo.getProductCategoryList().isEmpty()) {
|
|
|
|
+ categoryIds = String.join(",", bo.getProductCategoryList());
|
|
|
|
+ }
|
|
|
|
+ bo.setProductCategory(categoryIds);
|
|
|
|
+ String applicableDepartment = null;
|
|
|
|
+ if (bo.getApplicableDepartmentList() != null && !bo.getApplicableDepartmentList().isEmpty()) {
|
|
|
|
+ applicableDepartment = bo.getApplicableDepartmentList().stream().map(array -> String.join(",", array)).collect(Collectors.joining(";"));
|
|
|
|
+ }
|
|
|
|
+ bo.setApplicableDepartment(applicableDepartment);
|
|
|
|
+ if (bo.getProductLabelList() != null && !bo.getProductLabelList().isEmpty()) {
|
|
|
|
+ List<String> labelIds = bo.getProductLabelList().stream().map(labelBo -> labelBo.getLabelId().toString()).collect(Collectors.toList());
|
|
|
|
+ productLabel = String.join(",", labelIds);
|
|
|
|
+ }
|
|
|
|
+ bo.setProductLabel(productLabel);
|
|
|
|
+ if (bo.getContraindicationLabelList() != null && !bo.getContraindicationLabelList().isEmpty()) {
|
|
|
|
+ List<String> labelIds = bo.getContraindicationLabelList().stream().map(labelBo -> labelBo.getLabelId().toString()).collect(Collectors.toList());
|
|
|
|
+ contraindicationLabel = String.join(",", labelIds);
|
|
|
|
+ }
|
|
|
|
+ bo.setContraindicationLabel(contraindicationLabel);
|
|
|
|
+
|
|
ProductNutrition add = MapstructUtils.convert(bo, ProductNutrition.class);
|
|
ProductNutrition add = MapstructUtils.convert(bo, ProductNutrition.class);
|
|
validEntityBeforeSave(add);
|
|
validEntityBeforeSave(add);
|
|
boolean flag = baseMapper.insert(add) > 0;
|
|
boolean flag = baseMapper.insert(add) > 0;
|
|
@@ -120,6 +251,30 @@ public class ProductNutritionServiceImpl implements IProductNutritionService {
|
|
return baseMapper.updateById(update) > 0;
|
|
return baseMapper.updateById(update) > 0;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 批量修改
|
|
|
|
+ *
|
|
|
|
+ * @param nutritionBo 营养产品信息
|
|
|
|
+ * @return 是否修改成功
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public Boolean batchUpdateNutrition(BatchProductNuyritionBo nutritionBo) {
|
|
|
|
+ Integer result = 0;
|
|
|
|
+ ProductNutritionVo nutritionVo = null;
|
|
|
|
+ if (null != nutritionBo && !nutritionBo.getIds().isEmpty()) {
|
|
|
|
+ for (Long id : nutritionBo.getIds()) {
|
|
|
|
+ nutritionVo = this.queryById(id);
|
|
|
|
+ if (null != nutritionVo) {
|
|
|
|
+ nutritionVo.setShelfLifeReminder(nutritionBo.getShelfLifeReminder());
|
|
|
|
+ nutritionVo.setLicenseExpiryReminder(nutritionBo.getLicenseExpiryReminder());
|
|
|
|
+ ProductNutrition nutrition = MapstructUtils.convert(nutritionVo, ProductNutrition.class);
|
|
|
|
+ result = baseMapper.updateById(nutrition);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return result > 0;
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 保存前的数据校验
|
|
* 保存前的数据校验
|
|
*/
|
|
*/
|
|
@@ -141,4 +296,51 @@ public class ProductNutritionServiceImpl implements IProductNutritionService {
|
|
}
|
|
}
|
|
return baseMapper.deleteByIds(ids) > 0;
|
|
return baseMapper.deleteByIds(ids) > 0;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public R<?> importExcel(MultipartFile file) throws Exception {
|
|
|
|
+ if (ObjUtil.isNull(file)) {
|
|
|
|
+ return R.fail("请选择文件!");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ List<Map<Integer, String>> excelList = FastExcel.read(file.getInputStream()).headRowNumber(3).sheet().doReadSync();
|
|
|
|
+
|
|
|
|
+ log.info("开始导入数据");
|
|
|
|
+ if (CollUtil.isEmpty(excelList)) {
|
|
|
|
+ return R.fail("读取数据为空!");
|
|
|
|
+ }
|
|
|
|
+ log.info("size:" + excelList.size());
|
|
|
|
+
|
|
|
|
+ Map<String, String> labelMap = MapUtil.newHashMap(excelList.size());
|
|
|
|
+ dictDataService.selectMapByType("product_manufacturer").getData().forEach((k, v) -> {
|
|
|
|
+ labelMap.put(v.getDictLabel(), k);
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ List<ProductNutrition> nutritionList = new ArrayList<>();
|
|
|
|
+ StringBuilder builder = new StringBuilder();
|
|
|
|
+ excelList.forEach(v -> {
|
|
|
|
+ if (MapUtil.isEmpty(v) || v.size() != 3) {
|
|
|
|
+ builder.append(nutritionList.size() + 4).append("、");
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ ProductNutrition nutrition = new ProductNutrition();
|
|
|
|
+ /* nutrition.setLabelCode(v.get(0));
|
|
|
|
+ nutrition.setLabelName(v.get(1));
|
|
|
|
+ nutrition.setProductCategory(labelMap.get(v.get(2)));
|
|
|
|
+ if (StrUtil.isBlank(nutrition.getCategory()) || StrUtil.isBlank(nutrition.getLabelCode())
|
|
|
|
+ || StrUtil.isBlank(nutrition.getLabelName())) {
|
|
|
|
+ builder.append(nutritionList.size() + 4).append("、");
|
|
|
|
+ return;
|
|
|
|
+ }*/
|
|
|
|
+ nutritionList.add(nutrition);
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ if (builder.length() == 0) {
|
|
|
|
+ baseMapper.insertBatch(nutritionList);
|
|
|
|
+ } else {
|
|
|
|
+ return R.fail("以下行数据不完整:" + builder);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return R.ok("导入成功!");
|
|
|
|
+ }
|
|
}
|
|
}
|