|
|
@@ -1,11 +1,38 @@
|
|
|
package org.jeecg.modules.medical.service.impl;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.shiro.SecurityUtils;
|
|
|
+import org.jeecg.common.exception.JeecgBootException;
|
|
|
+import org.jeecg.common.system.query.QueryGenerator;
|
|
|
+import org.jeecg.common.system.vo.DictDto;
|
|
|
+import org.jeecg.common.system.vo.LoginUser;
|
|
|
+import org.jeecg.common.util.oConvertUtils;
|
|
|
+import org.jeecg.modules.medical.common.bo.ExportRuleTitleDTO;
|
|
|
import org.jeecg.modules.medical.entity.MedicalInsRuleProject;
|
|
|
import org.jeecg.modules.medical.mapper.MedicalInsRuleProjectMapper;
|
|
|
import org.jeecg.modules.medical.service.IMedicalInsRuleProjectService;
|
|
|
+import org.jeecg.modules.system.service.ISysDictService;
|
|
|
+import org.jeecgframework.poi.excel.annotation.Excel;
|
|
|
+import org.jeecgframework.poi.excel.def.NormalExcelConstants;
|
|
|
+import org.jeecgframework.poi.excel.entity.ExportParams;
|
|
|
+import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
|
|
|
+import org.jeecgframework.poi.util.PoiPublicUtil;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
+import org.springframework.web.servlet.ModelAndView;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.lang.reflect.Array;
|
|
|
+import java.lang.reflect.Field;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* @Description: medical_ins_rule_project
|
|
|
@@ -13,7 +40,96 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
* @Date: 2023-05-09 14:39:13
|
|
|
* @Version: V1.0
|
|
|
*/
|
|
|
+@Slf4j
|
|
|
@Service
|
|
|
+@RequiredArgsConstructor(onConstructor = @__(@Autowired))
|
|
|
public class MedicalInsRuleProjectServiceImpl extends ServiceImpl<MedicalInsRuleProjectMapper, MedicalInsRuleProject> implements IMedicalInsRuleProjectService {
|
|
|
|
|
|
+ @Value("${jeecg.path.upload}")
|
|
|
+ private String upLoadPath;
|
|
|
+
|
|
|
+ private final ISysDictService sysDictService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ModelAndView exportTemplateXls(HttpServletRequest request, MedicalInsRuleProject object, Class<MedicalInsRuleProject> clazz, String title) {
|
|
|
+
|
|
|
+
|
|
|
+ ExportRuleTitleDTO exportRuleTitle = baseMapper.selectTitleNameById(object.getId());
|
|
|
+ if (null == exportRuleTitle) {
|
|
|
+ log.error("根据规则id={},获取不到规则表头配置", object.getId());
|
|
|
+ throw new JeecgBootException("找不到规则表头");
|
|
|
+ }
|
|
|
+ List<String> reserveList = new ArrayList<>();
|
|
|
+ if (StringUtils.hasText(exportRuleTitle.getSelectedRoles())) {
|
|
|
+ String[] split = exportRuleTitle.getSelectedRoles().split(",");
|
|
|
+ if (split.length > 0) {
|
|
|
+ // 获取标头
|
|
|
+ List<DictDto> dictDtos = sysDictService.queryDictByKeys(new ArrayList<>(Arrays.asList(split)));
|
|
|
+ if (!CollectionUtils.isEmpty(dictDtos)) {
|
|
|
+ reserveList = dictDtos.stream().map(DictDto::getText).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ title = exportRuleTitle.getRuleName();
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ // Step.1 组装查询条件
|
|
|
+ QueryWrapper<MedicalInsRuleProject> queryWrapper = QueryGenerator.initQueryWrapper(object, request.getParameterMap());
|
|
|
+ LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
|
|
+
|
|
|
+ // 过滤选中数据
|
|
|
+ String selections = request.getParameter("selections");
|
|
|
+ if (oConvertUtils.isNotEmpty(selections)) {
|
|
|
+ List<String> selectionList = Arrays.asList(selections.split(","));
|
|
|
+ queryWrapper.in("id",selectionList);
|
|
|
+ }
|
|
|
+ // Step.2 获取导出数据
|
|
|
+ List<MedicalInsRuleProject> exportList = this.list(queryWrapper);
|
|
|
+
|
|
|
+ // Step.3 AutoPoi 导出Excel
|
|
|
+ ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
|
|
|
+ //此处设置的filename无效 ,前端会重更新设置一下
|
|
|
+ mv.addObject(NormalExcelConstants.FILE_NAME, title);
|
|
|
+ mv.addObject(NormalExcelConstants.CLASS, clazz);
|
|
|
+ List<Map<String, Object>> maps = new ArrayList<Map<String, Object>>();
|
|
|
+ Map<String, Object> item = new HashMap<>();
|
|
|
+ item.put("projectCode", "项目编号");
|
|
|
+ maps.add(item);
|
|
|
+
|
|
|
+ Field[] fields = PoiPublicUtil.getClassFields(object.getClass());
|
|
|
+ List<String> ignoreField = new ArrayList<>();
|
|
|
+ if (fields != null) {
|
|
|
+ for (Field field : fields) {
|
|
|
+ Excel annotation = field.getAnnotation(Excel.class);
|
|
|
+ if (null != annotation) {
|
|
|
+ String name = annotation.name();
|
|
|
+ if (StringUtils.hasText(name)) {
|
|
|
+ ignoreField.add(name);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (StringUtils.hasText(exportRuleTitle.getSelectedRoles())) {
|
|
|
+ if (!CollectionUtils.isEmpty(reserveList)) {
|
|
|
+ List<String> finalReserveList = reserveList;
|
|
|
+ ignoreField = ignoreField.stream().filter(ignoreItem -> !finalReserveList.contains(ignoreItem)).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+// mv.addObject("mapList", maps);
|
|
|
+ //update-begin--Author:liusq Date:20210126 for:图片导出报错,ImageBasePath未设置--------------------
|
|
|
+ ExportParams exportParams=new ExportParams(title + "模板", "导出人:" + sysUser.getRealname(), title);
|
|
|
+ exportParams.setImageBasePath(upLoadPath);
|
|
|
+// String[] array = (String[]) ignoreField.stream().map(String::valueOf).toArray();
|
|
|
+ String[] array1 = ignoreField.toArray(new String[0]);
|
|
|
+ //设置哪些字段不导出
|
|
|
+ exportParams.setExclusions(array1);
|
|
|
+ //update-end--Author:liusq Date:20210126 for:图片导出报错,ImageBasePath未设置----------------------
|
|
|
+ mv.addObject(NormalExcelConstants.PARAMS,exportParams);
|
|
|
+ mv.addObject(NormalExcelConstants.DATA_LIST, exportList);
|
|
|
+ return mv;
|
|
|
+ }
|
|
|
}
|