diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/ehs/EhsEnterpriseController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/ehs/EhsEnterpriseController.java index 0781827..2787f7f 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/ehs/EhsEnterpriseController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/ehs/EhsEnterpriseController.java @@ -2,7 +2,14 @@ package com.ruoyi.web.controller.ehs; import java.util.List; import java.util.Arrays; +import java.util.stream.Collectors; import javax.servlet.http.HttpServletResponse; + +import com.ruoyi.common.core.domain.entity.SysDept; +import com.ruoyi.common.core.domain.entity.SysDictData; +import com.ruoyi.ehsRescueTeam.domain.RescueTeamImportTemplate; +import com.ruoyi.system.service.ISysDeptService; +import com.ruoyi.system.service.ISysDictDataService; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; @@ -23,6 +30,7 @@ import com.ruoyi.ehsEnterprise.domain.EhsEnterprise; import com.ruoyi.ehsEnterprise.service.IEhsEnterpriseService; import com.ruoyi.common.utils.poi.ExcelUtil; import com.ruoyi.common.core.page.TableDataInfo; +import org.springframework.web.multipart.MultipartFile; /** * 企业基本信息Controller @@ -37,7 +45,8 @@ public class EhsEnterpriseController extends BaseController { @Autowired private IEhsEnterpriseService ehsEnterpriseService; - + @Autowired + private ISysDictDataService dictDataService; /** * 查询企业基本信息列表 */ @@ -108,4 +117,19 @@ public class EhsEnterpriseController extends BaseController { return toAjax(ehsEnterpriseService.removeByIds(Arrays.asList(enterpriseIds))); } + @PostMapping("/importTemplate") + public void importTemplate(HttpServletResponse response) throws Exception { + ExcelUtil util = new ExcelUtil(EhsEnterprise.class); + util.importComboTemplateExcel(response, "企业信息信息数据"); + } + /** + * 批量导入 + */ + @PostMapping("/importData") + public AjaxResult importHubManage(MultipartFile file, Boolean updateSupport) throws Exception { + ExcelUtil util = new ExcelUtil<>(EhsEnterprise.class); + List list = util.importExcel(file.getInputStream()); + String message = ehsEnterpriseService.importEnterprise(list, updateSupport); + return AjaxResult.success(message); + } } diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/ehs/EhsHiddenDangerController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/ehs/EhsHiddenDangerController.java index bf569ec..4238016 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/ehs/EhsHiddenDangerController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/ehs/EhsHiddenDangerController.java @@ -5,6 +5,7 @@ import java.util.Arrays; import javax.servlet.http.HttpServletResponse; import com.ruoyi.common.utils.StringUtils; +import com.ruoyi.ehsRisk.domain.EhsRisk; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; @@ -25,6 +26,7 @@ import com.ruoyi.ehsHiddenDanger.domain.EhsHiddenDanger; import com.ruoyi.ehsHiddenDanger.service.IEhsHiddenDangerService; import com.ruoyi.common.utils.poi.ExcelUtil; import com.ruoyi.common.core.page.TableDataInfo; +import org.springframework.web.multipart.MultipartFile; /** * 隐患信息Controller @@ -62,7 +64,7 @@ public class EhsHiddenDangerController extends BaseController { List list = ehsHiddenDangerService.selectEhsHiddenDangerList(ehsHiddenDanger); ExcelUtil util = new ExcelUtil(EhsHiddenDanger.class); - util.exportExcel(response, list, "隐患信息数据"); + util.exportExcel(response, list, "隐患信息数据", "隐患信息数据"); } /** @@ -139,4 +141,33 @@ public class EhsHiddenDangerController extends BaseController { return toAjax(ehsHiddenDangerService.assistEhsHiddenDanger(ehsHiddenDanger)); } + + @PostMapping("/importTemplate") + public void importTemplate(HttpServletResponse response) throws Exception { + ExcelUtil util = new ExcelUtil(EhsHiddenDanger.class); + util.importComboTemplateExcel(response, "隐患信息数据"); + } + /** + * 批量导入 + */ + @PostMapping("/importData") + public AjaxResult importHubManage(MultipartFile file, Boolean updateSupport) throws Exception { + ExcelUtil util = new ExcelUtil<>(EhsHiddenDanger.class); + List list = util.importExcel(file.getInputStream()); + String message = ehsHiddenDangerService.importHiddenDanger(list, updateSupport); + return AjaxResult.success(message); + } + + /** + * + * @return + * @throws Exception + */ + @PostMapping("/selectEhsHiddenDangerOverTime") + public AjaxResult selectEhsHiddenDangerOverTime(MultipartFile file, Boolean updateSupport) throws Exception { + ExcelUtil util = new ExcelUtil<>(EhsHiddenDanger.class); + List list = util.importExcel(file.getInputStream()); + String message = ehsHiddenDangerService.importHiddenDanger(list, updateSupport); + return AjaxResult.success(message); + } } diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/ehs/EhsMaterialController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/ehs/EhsMaterialController.java index 1224ca5..cde4ccd 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/ehs/EhsMaterialController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/ehs/EhsMaterialController.java @@ -3,6 +3,8 @@ package com.ruoyi.ehsMaterial.controller; import java.util.List; import java.util.Arrays; import javax.servlet.http.HttpServletResponse; + +import com.ruoyi.ehsRisk.domain.EhsRisk; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; @@ -23,6 +25,7 @@ import com.ruoyi.ehsMaterial.domain.EhsMaterial; import com.ruoyi.ehsMaterial.service.IEhsMaterialService; import com.ruoyi.common.utils.poi.ExcelUtil; import com.ruoyi.common.core.page.TableDataInfo; +import org.springframework.web.multipart.MultipartFile; /** * 物资信息包含 通用应急救援装备”“防汛抗旱应急救援装备”“森林防灭火应急救援装备”“救灾物资”Controller @@ -108,4 +111,20 @@ public class EhsMaterialController extends BaseController { return toAjax(ehsMaterialService.removeByIds(Arrays.asList(materialIds))); } + + @PostMapping("/importTemplate") + public void importTemplate(HttpServletResponse response) throws Exception { + ExcelUtil util = new ExcelUtil(EhsMaterial.class); + util.importComboTemplateExcel(response, "物资信息数据"); + } + /** + * 批量导入 + */ + @PostMapping("/importData/{classType}") + public AjaxResult importHubManage(@PathVariable String classType,MultipartFile file, Boolean updateSupport) throws Exception { + ExcelUtil util = new ExcelUtil<>(EhsMaterial.class); + List list = util.importExcel(file.getInputStream()); + String message = ehsMaterialService.importMaterial(list,classType, updateSupport); + return AjaxResult.success(message); + } } \ No newline at end of file diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/ehs/EhsRiskController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/ehs/EhsRiskController.java index c380c34..989ec6c 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/ehs/EhsRiskController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/ehs/EhsRiskController.java @@ -3,6 +3,8 @@ package com.ruoyi.web.controller.ehs; import java.util.List; import java.util.Arrays; import javax.servlet.http.HttpServletResponse; + +import com.ruoyi.ehsEnterprise.domain.EhsEnterprise; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; @@ -23,6 +25,7 @@ import com.ruoyi.ehsRisk.domain.EhsRisk; import com.ruoyi.ehsRisk.service.IEhsRiskService; import com.ruoyi.common.utils.poi.ExcelUtil; import com.ruoyi.common.core.page.TableDataInfo; +import org.springframework.web.multipart.MultipartFile; /** * 风险信息Controller @@ -60,7 +63,7 @@ public class EhsRiskController extends BaseController { List list = ehsRiskService.selectEhsRiskList(ehsRisk); ExcelUtil util = new ExcelUtil(EhsRisk.class); - util.exportExcel(response, list, "风险信息数据"); + util.exportExcel(response, list, "风险信息数据", "风险信息数据"); } /** @@ -108,4 +111,19 @@ public class EhsRiskController extends BaseController { return toAjax(ehsRiskService.removeByIds(Arrays.asList(riskIds))); } + @PostMapping("/importTemplate") + public void importTemplate(HttpServletResponse response) throws Exception { + ExcelUtil util = new ExcelUtil(EhsRisk.class); + util.importComboTemplateExcel(response, "风险信息信息数据"); + } + /** + * 批量导入 + */ + @PostMapping("/importData") + public AjaxResult importHubManage(MultipartFile file, Boolean updateSupport) throws Exception { + ExcelUtil util = new ExcelUtil<>(EhsRisk.class); + List list = util.importExcel(file.getInputStream()); + String message = ehsRiskService.importRisk(list, updateSupport); + return AjaxResult.success(message); + } } diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/ehs/MaterialClassMasterController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/ehs/MaterialClassMasterController.java new file mode 100644 index 0000000..0114f86 --- /dev/null +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/ehs/MaterialClassMasterController.java @@ -0,0 +1,201 @@ +package com.ruoyi.web.controller.ehs; + +import java.io.*; +import java.util.ArrayList; +import java.util.List; +import javax.servlet.http.HttpServletResponse; + +import cn.hutool.json.JSONArray; +import cn.hutool.json.JSONUtil; +import com.alibaba.fastjson2.JSONObject; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.ruoyi.materialClass.domain.MaterialClass; +import com.ruoyi.materialClass.domain.MaterialClassSub; +import com.ruoyi.materialClass.service.IMaterialClassSubService; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import com.ruoyi.common.annotation.Log; +import com.ruoyi.common.core.controller.BaseController; +import com.ruoyi.common.core.domain.AjaxResult; +import com.ruoyi.common.enums.BusinessType; +import com.ruoyi.materialClass.domain.MaterialClassMaster; +import com.ruoyi.materialClass.service.IMaterialClassMasterService; +import com.ruoyi.common.utils.poi.ExcelUtil; +import com.ruoyi.common.core.page.TableDataInfo; + +/** + * 物资分类一级分类Controller + * + * @author ruoyi + * @date 2024-01-05 + */ +@Api(tags="物资分类一级分类管理") +@RestController +@RequestMapping("/materialClass/materialClassMaster") +public class MaterialClassMasterController extends BaseController +{ + @Autowired + private IMaterialClassMasterService materialClassMastService; + @Autowired + private IMaterialClassSubService materialClassSubService; +/** + * 查询物资分类一级分类列表 + */ +@PreAuthorize("@ss.hasPermi('materialClass:materialClassMaster:list')") +@GetMapping("/list") + public TableDataInfo list(MaterialClassMaster materialClassMast) + { + startPage(); + List list = materialClassMastService.selectMaterialClassMastList(materialClassMast); + return getDataTable(list); + } + + /** + * 导出物资分类一级分类列表 + */ + @PreAuthorize("@ss.hasPermi('materialClass:materialClassMaster:export')") + @Log(title = "物资分类一级分类", businessType = BusinessType.EXPORT) + @PostMapping("/export") + public void export(HttpServletResponse response, MaterialClassMaster materialClassMast) + { + List list = materialClassMastService.selectMaterialClassMastList(materialClassMast); + ExcelUtil util = new ExcelUtil(MaterialClassMaster.class); + util.exportExcel(response, list, "物资分类一级分类数据"); + } + + /** + * 获取物资分类一级分类详细信息 + */ + @PreAuthorize("@ss.hasPermi('materialClass:materialClassMaster:query')") + @GetMapping(value = "/{classMastId}") + public AjaxResult getInfo(@PathVariable("classMastId") String classMastId) + { + return success(materialClassMastService.selectMaterialClassMastByClassMastId(classMastId)); + } + + /** + * 新增物资分类一级分类 + */ + @ApiOperation("新增物资分类一级分类") + @PreAuthorize("@ss.hasPermi('materialClass:materialClassMaster:add')") + @Log(title = "物资分类一级分类", businessType = BusinessType.INSERT) + @PostMapping + public AjaxResult add(@RequestBody MaterialClassMaster materialClassMast) + { + return toAjax(materialClassMastService.insertMaterialClassMast(materialClassMast)); + } + + /** + * 修改物资分类一级分类 + */ + @ApiOperation("修改物资分类一级分类") + @PreAuthorize("@ss.hasPermi('materialClass:materialClassMaster:edit')") + @Log(title = "物资分类一级分类", businessType = BusinessType.UPDATE) + @PutMapping + public AjaxResult edit(@RequestBody MaterialClassMaster materialClassMast) + { + return toAjax(materialClassMastService.updateMaterialClassMast(materialClassMast)); + } + + /** + * 删除物资分类一级分类 + */ + @ApiOperation("删除物资分类一级分类") + @PreAuthorize("@ss.hasPermi('materialClass:materialClassMaster:remove')") + @Log(title = "物资分类一级分类", businessType = BusinessType.DELETE) + @DeleteMapping("/{ids}") + public AjaxResult remove(@PathVariable String[] ids) + { + return toAjax(materialClassMastService.deleteMaterialClassMastByClassMastIds(ids)); + } + + /** + * 删除物资分类一级分类 + */ + @ApiOperation("获取分类的json字符串") + @GetMapping(value = "/getMaterialClassJson/{id}") + public String getMaterialClassJson(@PathVariable String id) throws JsonProcessingException { + MaterialClassMaster msm = new MaterialClassMaster(); + msm.setClassMastType(id); + List list = materialClassMastService.selectMaterialClassMastList(msm); + List mcList = new ArrayList<>(); + for(MaterialClassMaster mcm :list){ + MaterialClass mc = new MaterialClass(); + mc.setLabel(mcm.getClassNameMast()); + mc.setValue(mcm.getClassMastId()); + MaterialClassSub mcs = new MaterialClassSub(); + mcs.setMastId(mcm.getId()); + List sublist = materialClassSubService.selectMaterialClassSubList(mcs); + List mcSubList = new ArrayList<>(); + for(MaterialClassSub mcss:sublist){ + MaterialClass mcsub = new MaterialClass(); + mcsub.setLabel(mcss.getClassNameSub()); + mcsub.setValue(mcss.getClassSubId()); + mcSubList.add(mcsub); + } + mc.setChildren(mcSubList); + mcList.add(mc); + } + //String jsion = JSONUtil.toJsonStr(list); + ObjectMapper objectMapper = new ObjectMapper(); + String jsonStr = objectMapper.writeValueAsString(mcList); + System.out.println(jsonStr); + return jsonStr; + } + @ApiOperation("获取分类的json字符串") + @PostMapping(value = "/setMaterialClassJson") + public String setMaterialClassJson(MaterialClassMaster materialClassMaster) throws IOException { + String jsonStr = materialClassMaster.getClassNameMast(); + /*for(MaterialClass mc :mcList){ + MaterialClassMaster mcm = new MaterialClassMaster(); + mcm.setClassMastType(id); + mcm.setClassMastId(mc.getValue()); + mcm.setClassNameMast(mc.getLabel()); + }*/ + for(int m=2;m<=8;m++) { + InputStreamReader isr = new InputStreamReader(new FileInputStream("C:\\materialClass"+m+".json"), "utf8"); + BufferedReader br = new BufferedReader(isr); + StringBuffer resposeBuffer = new StringBuffer(""); + String lineTxt = null; + String s = ""; + //将文件内容全部拼接到 字符串s + while ((lineTxt = br.readLine()) != null) { + s += lineTxt; + } + JSONArray array = (JSONArray) JSONUtil.parseArray(s); // 将JSON字符串转换为JSONArray对象 + + for (int i = 0; i < array.size(); i++) { + cn.hutool.json.JSONObject obj = array.getJSONObject(i); + MaterialClassMaster mcm = new MaterialClassMaster(); + mcm.setClassMastType(String.valueOf(m)); + mcm.setClassMastId(obj.getStr("value")); + mcm.setClassNameMast(obj.getStr("label")); + materialClassMastService.insertMaterialClassMast(mcm); + JSONArray subArray = obj.getJSONArray("children"); + for (int j = 0; j < subArray.size(); j++) { + cn.hutool.json.JSONObject subObj = subArray.getJSONObject(j); + MaterialClassSub sub = new MaterialClassSub(); + sub.setClassMastId(obj.getStr("value")); + sub.setClassSubId(subObj.getStr("value")); + sub.setClassNameSub(subObj.getStr("label")); + sub.setClassMastType(mcm.getClassMastType()); + sub.setMastId(mcm.getId()); + materialClassSubService.save(sub); + } + } + } + return "ok"; + } + +} diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/BaseEntity.java b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/BaseEntity.java index 5b75c06..d0fe9be 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/BaseEntity.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/BaseEntity.java @@ -37,7 +37,7 @@ public class BaseEntity implements Serializable @TableField(fill = FieldFill.INSERT) private Long deptId; /** 上报部门 */ - @Excel(name = "上报部门") + @Excel(name = "上报部门" , type = Excel.Type.EXPORT) @TableField(exist = false) private String deptName; /** 创建时间 */ @@ -63,8 +63,9 @@ public class BaseEntity implements Serializable @TableField(exist = false) @JsonInclude(JsonInclude.Include.NON_EMPTY) private Map params; - - +/** 请求参数 */ + @TableField(exist = false) + private Integer classCount; public Map getParams() diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java index 6f45d5b..8529ce4 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java @@ -5,9 +5,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.lang.reflect.ParameterizedType; +import java.lang.reflect.*; import java.math.BigDecimal; import java.text.DecimalFormat; import java.time.LocalDate; @@ -24,6 +22,8 @@ import java.util.Set; import java.util.UUID; import java.util.stream.Collectors; import javax.servlet.http.HttpServletResponse; + +import com.ruoyi.common.core.domain.entity.SysDictData; import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.RegExUtils; import org.apache.commons.lang3.reflect.FieldUtils; @@ -589,6 +589,7 @@ public class ExcelUtil importTemplateExcel(response, sheetName, StringUtils.EMPTY); } + /** * 对list数据源将其里面的数据导入到excel表单 * @@ -1755,4 +1756,91 @@ public class ExcelUtil } return method; } + + /** + * 设置指定字段的下拉列表 + * @param param 字段名称 + * @param list 下拉列表内容 + * @param clazz 类 + * @throws Exception + */ + public static void setCombo(String param, List list, Class clazz) throws Exception { + // 通过反射 获取目标实体类的属性成员-即办公室号号字段 + Field file = clazz.getDeclaredField(param); + // 获取该字段的上叫Excel的注解 + Excel annotation = file.getAnnotation(Excel.class); + InvocationHandler h = Proxy.getInvocationHandler(annotation); + Field hField = h.getClass().getDeclaredField("memberValues"); + // 设置私有可访问 + hField.setAccessible(true); + Map memberValues = (Map) hField.get(h); + // 集合转数组 + String[] combo = list.toArray(new String[list.size()]); + // 修改属性值 + memberValues.put("combo", combo); + } + /** + * 将dictType readConverterExp 导出带下拉列表 + * @param response + * @param sheetName + */ + public void importComboTemplateExcel(HttpServletResponse response, String sheetName)throws Exception + { + response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); + response.setCharacterEncoding("utf-8"); + this.init(null, sheetName, title, Type.IMPORT); + setCombo(); + exportExcel(response); + } + /** + * 将所有excel注解为 dictType 和 readConverterExp 的转换为下拉列表 + * @throws Exception + */ + private void setCombo() throws Exception { + for (Object[] os : fields) { + Field field = (Field) os[0]; //字段属性 + Excel excel = (Excel) os[1]; //combo dicttype 等excel注解属性 + if(StringUtils.isNotEmpty( excel.dictType())){ + List dicDucation = DictUtils.getDictCache( excel.dictType()).stream().map(SysDictData::getDictLabel).collect(Collectors.toList()); + InvocationHandler h = Proxy.getInvocationHandler(os[1]); + Field hField = h.getClass().getDeclaredField("memberValues"); + // 设置私有可访问 + hField.setAccessible(true); + Map memberValues = (Map) hField.get(h); + // 集合转数组 + String[] combo = dicDucation.toArray(new String[dicDucation.size()]); + // 修改属性值 + memberValues.put("combo", combo); + }else if(StringUtils.isNotEmpty( excel.readConverterExp())){ + String[] temp = excel.readConverterExp().split(","); + String[] combo = new String[temp.length]; + for(int i=0;i +{ + private static final Logger log = LoggerFactory.getLogger(ExcelUtil_bak.class); + + public static final String FORMULA_REGEX_STR = "=|-|\\+|@"; + + public static final String[] FORMULA_STR = { "=", "-", "+", "@" }; + + /** + * 用于dictType属性数据存储,避免重复查缓存 + */ + public Map sysDictMap = new HashMap(); + + /** + * Excel sheet最大行数,默认65536 + */ + public static final int sheetSize = 65536; + + /** + * 工作表名称 + */ + private String sheetName; + + /** + * 导出类型(EXPORT:导出数据;IMPORT:导入模板) + */ + private Type type; + + /** + * 工作薄对象 + */ + private Workbook wb; + + /** + * 工作表对象 + */ + private Sheet sheet; + + /** + * 样式列表 + */ + private Map styles; + + /** + * 导入导出数据列表 + */ + private List list; + + /** + * 注解列表 + */ + private List fields; + + /** + * 当前行号 + */ + private int rownum; + + /** + * 标题 + */ + private String title; + + /** + * 最大高度 + */ + private short maxHeight; + + /** + * 合并后最后行数 + */ + private int subMergedLastRowNum = 0; + + /** + * 合并后开始行数 + */ + private int subMergedFirstRowNum = 1; + + /** + * 对象的子列表方法 + */ + private Method subMethod; + + /** + * 对象的子列表属性 + */ + private List subFields; + + /** + * 统计列表 + */ + private Map statistics = new HashMap(); + + /** + * 数字格式 + */ + private static final DecimalFormat DOUBLE_FORMAT = new DecimalFormat("######0.00"); + + /** + * 实体对象 + */ + public Class clazz; + + /** + * 需要排除列属性 + */ + public String[] excludeFields; + + public ExcelUtil_bak(Class clazz) + { + this.clazz = clazz; + } + + /** + * 隐藏Excel中列属性 + * + * @param fields 列属性名 示例[单个"name"/多个"id","name"] + * @throws Exception + */ + public void hideColumn(String... fields) + { + this.excludeFields = fields; + } + + public void init(List list, String sheetName, String title, Type type) + { + if (list == null) + { + list = new ArrayList(); + } + this.list = list; + this.sheetName = sheetName; + this.type = type; + this.title = title; + createExcelField(); + createWorkbook(); + createTitle(); + createSubHead(); + } + + /** + * 创建excel第一行标题 + */ + public void createTitle() + { + if (StringUtils.isNotEmpty(title)) + { + subMergedFirstRowNum++; + subMergedLastRowNum++; + int titleLastCol = this.fields.size() - 1; + if (isSubList()) + { + titleLastCol = titleLastCol + subFields.size() - 1; + } + Row titleRow = sheet.createRow(rownum == 0 ? rownum++ : 0); + titleRow.setHeightInPoints(30); + Cell titleCell = titleRow.createCell(0); + titleCell.setCellStyle(styles.get("title")); + titleCell.setCellValue(title); + sheet.addMergedRegion(new CellRangeAddress(titleRow.getRowNum(), titleRow.getRowNum(), titleRow.getRowNum(), titleLastCol)); + } + } + + /** + * 创建对象的子列表名称 + */ + public void createSubHead() + { + if (isSubList()) + { + subMergedFirstRowNum++; + subMergedLastRowNum++; + Row subRow = sheet.createRow(rownum); + int excelNum = 0; + for (Object[] objects : fields) + { + Excel attr = (Excel) objects[1]; + Cell headCell1 = subRow.createCell(excelNum); + headCell1.setCellValue(attr.name()); + headCell1.setCellStyle(styles.get(StringUtils.format("header_{}_{}", attr.headerColor(), attr.headerBackgroundColor()))); + excelNum++; + } + int headFirstRow = excelNum - 1; + int headLastRow = headFirstRow + subFields.size() - 1; + if (headLastRow > headFirstRow) + { + sheet.addMergedRegion(new CellRangeAddress(rownum, rownum, headFirstRow, headLastRow)); + } + rownum++; + } + } + + /** + * 对excel表单默认第一个索引名转换成list + * + * @param is 输入流 + * @return 转换后集合 + */ + public List importExcel(InputStream is) + { + List list = null; + try + { + list = importExcel(is, 0); + } + catch (Exception e) + { + log.error("导入Excel异常{}", e.getMessage()); + throw new UtilException(e.getMessage()); + } + finally + { + IOUtils.closeQuietly(is); + } + return list; + } + + /** + * 对excel表单默认第一个索引名转换成list + * + * @param is 输入流 + * @param titleNum 标题占用行数 + * @return 转换后集合 + */ + public List importExcel(InputStream is, int titleNum) throws Exception + { + return importExcel(StringUtils.EMPTY, is, titleNum); + } + + /** + * 对excel表单指定表格索引名转换成list + * + * @param sheetName 表格索引名 + * @param titleNum 标题占用行数 + * @param is 输入流 + * @return 转换后集合 + */ + public List importExcel(String sheetName, InputStream is, int titleNum) throws Exception + { + this.type = Type.IMPORT; + this.wb = WorkbookFactory.create(is); + List list = new ArrayList(); + // 如果指定sheet名,则取指定sheet中的内容 否则默认指向第1个sheet + Sheet sheet = StringUtils.isNotEmpty(sheetName) ? wb.getSheet(sheetName) : wb.getSheetAt(0); + if (sheet == null) + { + throw new IOException("文件sheet不存在"); + } + boolean isXSSFWorkbook = !(wb instanceof HSSFWorkbook); + Map pictures; + if (isXSSFWorkbook) + { + pictures = getSheetPictures07((XSSFSheet) sheet, (XSSFWorkbook) wb); + } + else + { + pictures = getSheetPictures03((HSSFSheet) sheet, (HSSFWorkbook) wb); + } + // 获取最后一个非空行的行下标,比如总行数为n,则返回的为n-1 + int rows = sheet.getLastRowNum(); + if (rows > 0) + { + // 定义一个map用于存放excel列的序号和field. + Map cellMap = new HashMap(); + // 获取表头 + Row heard = sheet.getRow(titleNum); + for (int i = 0; i < heard.getPhysicalNumberOfCells(); i++) + { + Cell cell = heard.getCell(i); + if (StringUtils.isNotNull(cell)) + { + String value = this.getCellValue(heard, i).toString(); + cellMap.put(value, i); + } + else + { + cellMap.put(null, i); + } + } + // 有数据时才处理 得到类的所有field. + List fields = this.getFields(); + Map fieldsMap = new HashMap(); + for (Object[] objects : fields) + { + Excel attr = (Excel) objects[1]; + Integer column = cellMap.get(attr.name()); + if (column != null) + { + fieldsMap.put(column, objects); + } + } + for (int i = titleNum + 1; i <= rows; i++) + { + // 从第2行开始取数据,默认第一行是表头. + Row row = sheet.getRow(i); + // 判断当前行是否是空行 + if (isRowEmpty(row)) + { + continue; + } + T entity = null; + for (Map.Entry entry : fieldsMap.entrySet()) + { + Object val = this.getCellValue(row, entry.getKey()); + + // 如果不存在实例则新建. + entity = (entity == null ? clazz.newInstance() : entity); + // 从map中得到对应列的field. + Field field = (Field) entry.getValue()[0]; + Excel attr = (Excel) entry.getValue()[1]; + // 取得类型,并根据对象类型设置值. + Class fieldType = field.getType(); + if (String.class == fieldType) + { + String s = Convert.toStr(val); + if (StringUtils.endsWith(s, ".0")) + { + val = StringUtils.substringBefore(s, ".0"); + } + else + { + String dateFormat = field.getAnnotation(Excel.class).dateFormat(); + if (StringUtils.isNotEmpty(dateFormat)) + { + val = parseDateToStr(dateFormat, val); + } + else + { + val = Convert.toStr(val); + } + } + } + else if ((Integer.TYPE == fieldType || Integer.class == fieldType) && StringUtils.isNumeric(Convert.toStr(val))) + { + val = Convert.toInt(val); + } + else if ((Long.TYPE == fieldType || Long.class == fieldType) && StringUtils.isNumeric(Convert.toStr(val))) + { + val = Convert.toLong(val); + } + else if (Double.TYPE == fieldType || Double.class == fieldType) + { + val = Convert.toDouble(val); + } + else if (Float.TYPE == fieldType || Float.class == fieldType) + { + val = Convert.toFloat(val); + } + else if (BigDecimal.class == fieldType) + { + val = Convert.toBigDecimal(val); + } + else if (Date.class == fieldType) + { + if (val instanceof String) + { + val = DateUtils.parseDate(val); + } + else if (val instanceof Double) + { + val = DateUtil.getJavaDate((Double) val); + } + } + else if (Boolean.TYPE == fieldType || Boolean.class == fieldType) + { + val = Convert.toBool(val, false); + } + if (StringUtils.isNotNull(fieldType)) + { + String propertyName = field.getName(); + if (StringUtils.isNotEmpty(attr.targetAttr())) + { + propertyName = field.getName() + "." + attr.targetAttr(); + } + if (StringUtils.isNotEmpty(attr.readConverterExp())) + { + val = reverseByExp(Convert.toStr(val), attr.readConverterExp(), attr.separator()); + } + else if (StringUtils.isNotEmpty(attr.dictType())) + { + val = reverseDictByExp(Convert.toStr(val), attr.dictType(), attr.separator()); + } + else if (!attr.handler().equals(ExcelHandlerAdapter.class)) + { + val = dataFormatHandlerAdapter(val, attr, null); + } + else if (ColumnType.IMAGE == attr.cellType() && StringUtils.isNotEmpty(pictures)) + { + PictureData image = pictures.get(row.getRowNum() + "_" + entry.getKey()); + if (image == null) + { + val = ""; + } + else + { + byte[] data = image.getData(); + val = FileUtils.writeImportBytes(data); + } + } + ReflectUtils.invokeSetter(entity, propertyName, val); + } + } + list.add(entity); + } + } + return list; + } + + /** + * 对list数据源将其里面的数据导入到excel表单 + * + * @param list 导出数据集合 + * @param sheetName 工作表的名称 + * @return 结果 + */ + public AjaxResult exportExcel(List list, String sheetName) + { + return exportExcel(list, sheetName, StringUtils.EMPTY); + } + + /** + * 对list数据源将其里面的数据导入到excel表单 + * + * @param list 导出数据集合 + * @param sheetName 工作表的名称 + * @param title 标题 + * @return 结果 + */ + public AjaxResult exportExcel(List list, String sheetName, String title) + { + this.init(list, sheetName, title, Type.EXPORT); + return exportExcel(); + } + + /** + * 对list数据源将其里面的数据导入到excel表单 + * + * @param response 返回数据 + * @param list 导出数据集合 + * @param sheetName 工作表的名称 + * @return 结果 + */ + public void exportExcel(HttpServletResponse response, List list, String sheetName) + { + exportExcel(response, list, sheetName, StringUtils.EMPTY); + } + + /** + * 对list数据源将其里面的数据导入到excel表单 + * + * @param response 返回数据 + * @param list 导出数据集合 + * @param sheetName 工作表的名称 + * @param title 标题 + * @return 结果 + */ + public void exportExcel(HttpServletResponse response, List list, String sheetName, String title) + { + response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); + response.setCharacterEncoding("utf-8"); + this.init(list, sheetName, title, Type.EXPORT); + exportExcel(response); + } + + /** + * 对list数据源将其里面的数据导入到excel表单 + * + * @param sheetName 工作表的名称 + * @return 结果 + */ + public AjaxResult importTemplateExcel(String sheetName) + { + return importTemplateExcel(sheetName, StringUtils.EMPTY); + } + + /** + * 对list数据源将其里面的数据导入到excel表单 + * + * @param sheetName 工作表的名称 + * @param title 标题 + * @return 结果 + */ + public AjaxResult importTemplateExcel(String sheetName, String title) + { + this.init(null, sheetName, title, Type.IMPORT); + return exportExcel(); + } + + /** + * 对list数据源将其里面的数据导入到excel表单 + * + * @param sheetName 工作表的名称 + * @return 结果 + */ + public void importTemplateExcel(HttpServletResponse response, String sheetName) + { + importTemplateExcel(response, sheetName, StringUtils.EMPTY); + } + + /** + * 对list数据源将其里面的数据导入到excel表单 + * + * @param sheetName 工作表的名称 + * @param title 标题 + * @return 结果 + */ + public void importTemplateExcel(HttpServletResponse response, String sheetName, String title) + { + response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); + response.setCharacterEncoding("utf-8"); + this.init(null, sheetName, title, Type.IMPORT); + exportExcel(response); + } + + /** + * 对list数据源将其里面的数据导入到excel表单 + * + * @return 结果 + */ + public void exportExcel(HttpServletResponse response) + { + try + { + writeSheet(); + wb.write(response.getOutputStream()); + } + catch (Exception e) + { + log.error("导出Excel异常{}", e.getMessage()); + } + finally + { + IOUtils.closeQuietly(wb); + } + } + + /** + * 对list数据源将其里面的数据导入到excel表单 + * + * @return 结果 + */ + public AjaxResult exportExcel() + { + OutputStream out = null; + try + { + writeSheet(); + String filename = encodingFilename(sheetName); + out = new FileOutputStream(getAbsoluteFile(filename)); + wb.write(out); + return AjaxResult.success(filename); + } + catch (Exception e) + { + log.error("导出Excel异常{}", e.getMessage()); + throw new UtilException("导出Excel失败,请联系网站管理员!"); + } + finally + { + IOUtils.closeQuietly(wb); + IOUtils.closeQuietly(out); + } + } + + /** + * 创建写入数据到Sheet + */ + public void writeSheet() + { + // 取出一共有多少个sheet. + int sheetNo = Math.max(1, (int) Math.ceil(list.size() * 1.0 / sheetSize)); + for (int index = 0; index < sheetNo; index++) + { + createSheet(sheetNo, index); + + // 产生一行 + Row row = sheet.createRow(rownum); + int column = 0; + // 写入各个字段的列头名称 + for (Object[] os : fields) + { + Field field = (Field) os[0]; + Excel excel = (Excel) os[1]; + if (Collection.class.isAssignableFrom(field.getType())) + { + for (Field subField : subFields) + { + Excel subExcel = subField.getAnnotation(Excel.class); + this.createHeadCell(subExcel, row, column++); + } + } + else + { + this.createHeadCell(excel, row, column++); + } + } + if (Type.EXPORT.equals(type)) + { + fillExcelData(index, row); + addStatisticsRow(); + } + } + } + + /** + * 填充excel数据 + * + * @param index 序号 + * @param row 单元格行 + */ + @SuppressWarnings("unchecked") + public void fillExcelData(int index, Row row) + { + int startNo = index * sheetSize; + int endNo = Math.min(startNo + sheetSize, list.size()); + int rowNo = (1 + rownum) - startNo; + for (int i = startNo; i < endNo; i++) + { + rowNo = isSubList() ? (i > 1 ? rowNo + 1 : rowNo + i) : i + 1 + rownum - startNo; + row = sheet.createRow(rowNo); + // 得到导出对象. + T vo = (T) list.get(i); + Collection subList = null; + if (isSubList()) + { + if (isSubListValue(vo)) + { + subList = getListCellValue(vo); + subMergedLastRowNum = subMergedLastRowNum + subList.size(); + } + else + { + subMergedFirstRowNum++; + subMergedLastRowNum++; + } + } + int column = 0; + for (Object[] os : fields) + { + Field field = (Field) os[0]; + Excel excel = (Excel) os[1]; + if (Collection.class.isAssignableFrom(field.getType()) && StringUtils.isNotNull(subList)) + { + boolean subFirst = false; + for (Object obj : subList) + { + if (subFirst) + { + rowNo++; + row = sheet.createRow(rowNo); + } + List subFields = FieldUtils.getFieldsListWithAnnotation(obj.getClass(), Excel.class); + int subIndex = 0; + for (Field subField : subFields) + { + if (subField.isAnnotationPresent(Excel.class)) + { + subField.setAccessible(true); + Excel attr = subField.getAnnotation(Excel.class); + this.addCell(attr, row, (T) obj, subField, column + subIndex); + } + subIndex++; + } + subFirst = true; + } + this.subMergedFirstRowNum = this.subMergedFirstRowNum + subList.size(); + } + else + { + this.addCell(excel, row, vo, field, column++); + } + } + } + } + + /** + * 创建表格样式 + * + * @param wb 工作薄对象 + * @return 样式列表 + */ + private Map createStyles(Workbook wb) + { + // 写入各条记录,每条记录对应excel表中的一行 + Map styles = new HashMap(); + CellStyle style = wb.createCellStyle(); + style.setAlignment(HorizontalAlignment.CENTER); + style.setVerticalAlignment(VerticalAlignment.CENTER); + Font titleFont = wb.createFont(); + titleFont.setFontName("Arial"); + titleFont.setFontHeightInPoints((short) 16); + titleFont.setBold(true); + style.setFont(titleFont); + styles.put("title", style); + + style = wb.createCellStyle(); + style.setAlignment(HorizontalAlignment.CENTER); + style.setVerticalAlignment(VerticalAlignment.CENTER); + style.setBorderRight(BorderStyle.THIN); + style.setRightBorderColor(IndexedColors.GREY_50_PERCENT.getIndex()); + style.setBorderLeft(BorderStyle.THIN); + style.setLeftBorderColor(IndexedColors.GREY_50_PERCENT.getIndex()); + style.setBorderTop(BorderStyle.THIN); + style.setTopBorderColor(IndexedColors.GREY_50_PERCENT.getIndex()); + style.setBorderBottom(BorderStyle.THIN); + style.setBottomBorderColor(IndexedColors.GREY_50_PERCENT.getIndex()); + Font dataFont = wb.createFont(); + dataFont.setFontName("Arial"); + dataFont.setFontHeightInPoints((short) 10); + style.setFont(dataFont); + styles.put("data", style); + + style = wb.createCellStyle(); + style.setAlignment(HorizontalAlignment.CENTER); + style.setVerticalAlignment(VerticalAlignment.CENTER); + Font totalFont = wb.createFont(); + totalFont.setFontName("Arial"); + totalFont.setFontHeightInPoints((short) 10); + style.setFont(totalFont); + styles.put("total", style); + + styles.putAll(annotationHeaderStyles(wb, styles)); + + styles.putAll(annotationDataStyles(wb)); + + return styles; + } + + /** + * 根据Excel注解创建表格头样式 + * + * @param wb 工作薄对象 + * @return 自定义样式列表 + */ + private Map annotationHeaderStyles(Workbook wb, Map styles) + { + Map headerStyles = new HashMap(); + for (Object[] os : fields) + { + Excel excel = (Excel) os[1]; + String key = StringUtils.format("header_{}_{}", excel.headerColor(), excel.headerBackgroundColor()); + if (!headerStyles.containsKey(key)) + { + CellStyle style = wb.createCellStyle(); + style.cloneStyleFrom(styles.get("data")); + style.setAlignment(HorizontalAlignment.CENTER); + style.setVerticalAlignment(VerticalAlignment.CENTER); + style.setFillForegroundColor(excel.headerBackgroundColor().index); + style.setFillPattern(FillPatternType.SOLID_FOREGROUND); + Font headerFont = wb.createFont(); + headerFont.setFontName("Arial"); + headerFont.setFontHeightInPoints((short) 10); + headerFont.setBold(true); + headerFont.setColor(excel.headerColor().index); + style.setFont(headerFont); + headerStyles.put(key, style); + } + } + return headerStyles; + } + + /** + * 根据Excel注解创建表格列样式 + * + * @param wb 工作薄对象 + * @return 自定义样式列表 + */ + private Map annotationDataStyles(Workbook wb) + { + Map styles = new HashMap(); + for (Object[] os : fields) + { + Excel excel = (Excel) os[1]; + String key = StringUtils.format("data_{}_{}_{}", excel.align(), excel.color(), excel.backgroundColor()); + if (!styles.containsKey(key)) + { + CellStyle style = wb.createCellStyle(); + style.setAlignment(excel.align()); + style.setVerticalAlignment(VerticalAlignment.CENTER); + style.setBorderRight(BorderStyle.THIN); + style.setRightBorderColor(IndexedColors.GREY_50_PERCENT.getIndex()); + style.setBorderLeft(BorderStyle.THIN); + style.setLeftBorderColor(IndexedColors.GREY_50_PERCENT.getIndex()); + style.setBorderTop(BorderStyle.THIN); + style.setTopBorderColor(IndexedColors.GREY_50_PERCENT.getIndex()); + style.setBorderBottom(BorderStyle.THIN); + style.setBottomBorderColor(IndexedColors.GREY_50_PERCENT.getIndex()); + style.setFillPattern(FillPatternType.SOLID_FOREGROUND); + style.setFillForegroundColor(excel.backgroundColor().getIndex()); + Font dataFont = wb.createFont(); + dataFont.setFontName("Arial"); + dataFont.setFontHeightInPoints((short) 10); + dataFont.setColor(excel.color().index); + style.setFont(dataFont); + styles.put(key, style); + } + } + return styles; + } + + /** + * 创建单元格 + */ + public Cell createHeadCell(Excel attr, Row row, int column) + { + // 创建列 + Cell cell = row.createCell(column); + // 写入列信息 + cell.setCellValue(attr.name()); + setDataValidation(attr, row, column); + cell.setCellStyle(styles.get(StringUtils.format("header_{}_{}", attr.headerColor(), attr.headerBackgroundColor()))); + if (isSubList()) + { + // 填充默认样式,防止合并单元格样式失效 + sheet.setDefaultColumnStyle(column, styles.get(StringUtils.format("data_{}_{}_{}", attr.align(), attr.color(), attr.backgroundColor()))); + if (attr.needMerge()) + { + sheet.addMergedRegion(new CellRangeAddress(rownum - 1, rownum, column, column)); + } + } + return cell; + } + + /** + * 设置单元格信息 + * + * @param value 单元格值 + * @param attr 注解相关 + * @param cell 单元格信息 + */ + public void setCellVo(Object value, Excel attr, Cell cell) + { + if (ColumnType.STRING == attr.cellType()) + { + String cellValue = Convert.toStr(value); + // 对于任何以表达式触发字符 =-+@开头的单元格,直接使用tab字符作为前缀,防止CSV注入。 + if (StringUtils.startsWithAny(cellValue, FORMULA_STR)) + { + cellValue = RegExUtils.replaceFirst(cellValue, FORMULA_REGEX_STR, "\t$0"); + } + if (value instanceof Collection && StringUtils.equals("[]", cellValue)) + { + cellValue = StringUtils.EMPTY; + } + cell.setCellValue(StringUtils.isNull(cellValue) ? attr.defaultValue() : cellValue + attr.suffix()); + } + else if (ColumnType.NUMERIC == attr.cellType()) + { + if (StringUtils.isNotNull(value)) + { + cell.setCellValue(StringUtils.contains(Convert.toStr(value), ".") ? Convert.toDouble(value) : Convert.toInt(value)); + } + } + else if (ColumnType.IMAGE == attr.cellType()) + { + ClientAnchor anchor = new XSSFClientAnchor(0, 0, 0, 0, (short) cell.getColumnIndex(), cell.getRow().getRowNum(), (short) (cell.getColumnIndex() + 1), cell.getRow().getRowNum() + 1); + String imagePath = Convert.toStr(value); + if (StringUtils.isNotEmpty(imagePath)) + { + byte[] data = ImageUtils.getImage(imagePath); + getDrawingPatriarch(cell.getSheet()).createPicture(anchor, + cell.getSheet().getWorkbook().addPicture(data, getImageType(data))); + } + } + } + + /** + * 获取画布 + */ + public static Drawing getDrawingPatriarch(Sheet sheet) + { + if (sheet.getDrawingPatriarch() == null) + { + sheet.createDrawingPatriarch(); + } + return sheet.getDrawingPatriarch(); + } + + /** + * 获取图片类型,设置图片插入类型 + */ + public int getImageType(byte[] value) + { + String type = FileTypeUtils.getFileExtendName(value); + if ("JPG".equalsIgnoreCase(type)) + { + return Workbook.PICTURE_TYPE_JPEG; + } + else if ("PNG".equalsIgnoreCase(type)) + { + return Workbook.PICTURE_TYPE_PNG; + } + return Workbook.PICTURE_TYPE_JPEG; + } + + /** + * 创建表格样式 + */ + public void setDataValidation(Excel attr, Row row, int column) + { + if (attr.name().indexOf("注:") >= 0) + { + sheet.setColumnWidth(column, 6000); + } + else + { + // 设置列宽 + sheet.setColumnWidth(column, (int) ((attr.width() + 0.72) * 256)); + } + if (StringUtils.isNotEmpty(attr.prompt()) || attr.combo().length > 0) + { + if (attr.combo().length > 15 || StringUtils.join(attr.combo()).length() > 255) + { + // 如果下拉数大于15或字符串长度大于255,则使用一个新sheet存储,避免生成的模板下拉值获取不到 + setXSSFValidationWithHidden(sheet, attr.combo(), attr.prompt(), 1, 100, column, column); + } + else + { + // 提示信息或只能选择不能输入的列内容. + setPromptOrValidation(sheet, attr.combo(), attr.prompt(), 1, 100, column, column); + } + } + } + + /** + * 添加单元格 + */ + public Cell addCell(Excel attr, Row row, T vo, Field field, int column) + { + Cell cell = null; + try + { + // 设置行高 + row.setHeight(maxHeight); + // 根据Excel中设置情况决定是否导出,有些情况需要保持为空,希望用户填写这一列. + if (attr.isExport()) + { + // 创建cell + cell = row.createCell(column); + if (isSubListValue(vo) && getListCellValue(vo).size() > 1 && attr.needMerge()) + { + CellRangeAddress cellAddress = new CellRangeAddress(subMergedFirstRowNum, subMergedLastRowNum, column, column); + sheet.addMergedRegion(cellAddress); + } + cell.setCellStyle(styles.get(StringUtils.format("data_{}_{}_{}", attr.align(), attr.color(), attr.backgroundColor()))); + + // 用于读取对象中的属性 + Object value = getTargetValue(vo, field, attr); + String dateFormat = attr.dateFormat(); + String readConverterExp = attr.readConverterExp(); + String separator = attr.separator(); + String dictType = attr.dictType(); + if (StringUtils.isNotEmpty(dateFormat) && StringUtils.isNotNull(value)) + { + cell.setCellValue(parseDateToStr(dateFormat, value)); + } + else if (StringUtils.isNotEmpty(readConverterExp) && StringUtils.isNotNull(value)) + { + cell.setCellValue(convertByExp(Convert.toStr(value), readConverterExp, separator)); + } + else if (StringUtils.isNotEmpty(dictType) && StringUtils.isNotNull(value)) + { + if (!sysDictMap.containsKey(dictType + value)) + { + String lable = convertDictByExp(Convert.toStr(value), dictType, separator); + sysDictMap.put(dictType + value, lable); + } + cell.setCellValue(sysDictMap.get(dictType + value)); + } + else if (value instanceof BigDecimal && -1 != attr.scale()) + { + cell.setCellValue((((BigDecimal) value).setScale(attr.scale(), attr.roundingMode())).doubleValue()); + } + else if (!attr.handler().equals(ExcelHandlerAdapter.class)) + { + cell.setCellValue(dataFormatHandlerAdapter(value, attr, cell)); + } + else + { + // 设置列类型 + setCellVo(value, attr, cell); + } + addStatisticsData(column, Convert.toStr(value), attr); + } + } + catch (Exception e) + { + log.error("导出Excel失败{}", e); + } + return cell; + } + + /** + * 设置 POI XSSFSheet 单元格提示或选择框 + * + * @param sheet 表单 + * @param textlist 下拉框显示的内容 + * @param promptContent 提示内容 + * @param firstRow 开始行 + * @param endRow 结束行 + * @param firstCol 开始列 + * @param endCol 结束列 + */ + public void setPromptOrValidation(Sheet sheet, String[] textlist, String promptContent, int firstRow, int endRow, + int firstCol, int endCol) + { + DataValidationHelper helper = sheet.getDataValidationHelper(); + DataValidationConstraint constraint = textlist.length > 0 ? helper.createExplicitListConstraint(textlist) : helper.createCustomConstraint("DD1"); + CellRangeAddressList regions = new CellRangeAddressList(firstRow, endRow, firstCol, endCol); + DataValidation dataValidation = helper.createValidation(constraint, regions); + if (StringUtils.isNotEmpty(promptContent)) + { + // 如果设置了提示信息则鼠标放上去提示 + dataValidation.createPromptBox("", promptContent); + dataValidation.setShowPromptBox(true); + } + // 处理Excel兼容性问题 + if (dataValidation instanceof XSSFDataValidation) + { + dataValidation.setSuppressDropDownArrow(true); + dataValidation.setShowErrorBox(true); + } + else + { + dataValidation.setSuppressDropDownArrow(false); + } + sheet.addValidationData(dataValidation); + } + + /** + * 设置某些列的值只能输入预制的数据,显示下拉框(兼容超出一定数量的下拉框). + * + * @param sheet 要设置的sheet. + * @param textlist 下拉框显示的内容 + * @param promptContent 提示内容 + * @param firstRow 开始行 + * @param endRow 结束行 + * @param firstCol 开始列 + * @param endCol 结束列 + */ + public void setXSSFValidationWithHidden(Sheet sheet, String[] textlist, String promptContent, int firstRow, int endRow, int firstCol, int endCol) + { + String hideSheetName = "combo_" + firstCol + "_" + endCol; + Sheet hideSheet = wb.createSheet(hideSheetName); // 用于存储 下拉菜单数据 + for (int i = 0; i < textlist.length; i++) + { + hideSheet.createRow(i).createCell(0).setCellValue(textlist[i]); + } + // 创建名称,可被其他单元格引用 + Name name = wb.createName(); + name.setNameName(hideSheetName + "_data"); + name.setRefersToFormula(hideSheetName + "!$A$1:$A$" + textlist.length); + DataValidationHelper helper = sheet.getDataValidationHelper(); + // 加载下拉列表内容 + DataValidationConstraint constraint = helper.createFormulaListConstraint(hideSheetName + "_data"); + // 设置数据有效性加载在哪个单元格上,四个参数分别是:起始行、终止行、起始列、终止列 + CellRangeAddressList regions = new CellRangeAddressList(firstRow, endRow, firstCol, endCol); + // 数据有效性对象 + DataValidation dataValidation = helper.createValidation(constraint, regions); + if (StringUtils.isNotEmpty(promptContent)) + { + // 如果设置了提示信息则鼠标放上去提示 + dataValidation.createPromptBox("", promptContent); + dataValidation.setShowPromptBox(true); + } + // 处理Excel兼容性问题 + if (dataValidation instanceof XSSFDataValidation) + { + dataValidation.setSuppressDropDownArrow(true); + dataValidation.setShowErrorBox(true); + } + else + { + dataValidation.setSuppressDropDownArrow(false); + } + + sheet.addValidationData(dataValidation); + // 设置hiddenSheet隐藏 + wb.setSheetHidden(wb.getSheetIndex(hideSheet), true); + } + + /** + * 解析导出值 0=男,1=女,2=未知 + * + * @param propertyValue 参数值 + * @param converterExp 翻译注解 + * @param separator 分隔符 + * @return 解析后值 + */ + public static String convertByExp(String propertyValue, String converterExp, String separator) + { + StringBuilder propertyString = new StringBuilder(); + String[] convertSource = converterExp.split(","); + for (String item : convertSource) + { + String[] itemArray = item.split("="); + if (StringUtils.containsAny(propertyValue, separator)) + { + for (String value : propertyValue.split(separator)) + { + if (itemArray[0].equals(value)) + { + propertyString.append(itemArray[1] + separator); + break; + } + } + } + else + { + if (itemArray[0].equals(propertyValue)) + { + return itemArray[1]; + } + } + } + return StringUtils.stripEnd(propertyString.toString(), separator); + } + + /** + * 反向解析值 男=0,女=1,未知=2 + * + * @param propertyValue 参数值 + * @param converterExp 翻译注解 + * @param separator 分隔符 + * @return 解析后值 + */ + public static String reverseByExp(String propertyValue, String converterExp, String separator) + { + StringBuilder propertyString = new StringBuilder(); + String[] convertSource = converterExp.split(","); + for (String item : convertSource) + { + String[] itemArray = item.split("="); + if (StringUtils.containsAny(propertyValue, separator)) + { + for (String value : propertyValue.split(separator)) + { + if (itemArray[1].equals(value)) + { + propertyString.append(itemArray[0] + separator); + break; + } + } + } + else + { + if (itemArray[1].equals(propertyValue)) + { + return itemArray[0]; + } + } + } + return StringUtils.stripEnd(propertyString.toString(), separator); + } + + /** + * 解析字典值 + * + * @param dictValue 字典值 + * @param dictType 字典类型 + * @param separator 分隔符 + * @return 字典标签 + */ + public static String convertDictByExp(String dictValue, String dictType, String separator) + { + return DictUtils.getDictLabel(dictType, dictValue, separator); + } + + /** + * 反向解析值字典值 + * + * @param dictLabel 字典标签 + * @param dictType 字典类型 + * @param separator 分隔符 + * @return 字典值 + */ + public static String reverseDictByExp(String dictLabel, String dictType, String separator) + { + return DictUtils.getDictValue(dictType, dictLabel, separator); + } + + /** + * 数据处理器 + * + * @param value 数据值 + * @param excel 数据注解 + * @return + */ + public String dataFormatHandlerAdapter(Object value, Excel excel, Cell cell) + { + try + { + Object instance = excel.handler().newInstance(); + Method formatMethod = excel.handler().getMethod("format", new Class[] { Object.class, String[].class, Cell.class, Workbook.class }); + value = formatMethod.invoke(instance, value, excel.args(), cell, this.wb); + } + catch (Exception e) + { + log.error("不能格式化数据 " + excel.handler(), e.getMessage()); + } + return Convert.toStr(value); + } + + /** + * 合计统计信息 + */ + private void addStatisticsData(Integer index, String text, Excel entity) + { + if (entity != null && entity.isStatistics()) + { + Double temp = 0D; + if (!statistics.containsKey(index)) + { + statistics.put(index, temp); + } + try + { + temp = Double.valueOf(text); + } + catch (NumberFormatException e) + { + } + statistics.put(index, statistics.get(index) + temp); + } + } + + /** + * 创建统计行 + */ + public void addStatisticsRow() + { + if (statistics.size() > 0) + { + Row row = sheet.createRow(sheet.getLastRowNum() + 1); + Set keys = statistics.keySet(); + Cell cell = row.createCell(0); + cell.setCellStyle(styles.get("total")); + cell.setCellValue("合计"); + + for (Integer key : keys) + { + cell = row.createCell(key); + cell.setCellStyle(styles.get("total")); + cell.setCellValue(DOUBLE_FORMAT.format(statistics.get(key))); + } + statistics.clear(); + } + } + + /** + * 编码文件名 + */ + public String encodingFilename(String filename) + { + filename = UUID.randomUUID() + "_" + filename + ".xlsx"; + return filename; + } + + /** + * 获取下载路径 + * + * @param filename 文件名称 + */ + public String getAbsoluteFile(String filename) + { + String downloadPath = RuoYiConfig.getDownloadPath() + filename; + File desc = new File(downloadPath); + if (!desc.getParentFile().exists()) + { + desc.getParentFile().mkdirs(); + } + return downloadPath; + } + + /** + * 获取bean中的属性值 + * + * @param vo 实体对象 + * @param field 字段 + * @param excel 注解 + * @return 最终的属性值 + * @throws Exception + */ + private Object getTargetValue(T vo, Field field, Excel excel) throws Exception + { + Object o = field.get(vo); + if (StringUtils.isNotEmpty(excel.targetAttr())) + { + String target = excel.targetAttr(); + if (target.contains(".")) + { + String[] targets = target.split("[.]"); + for (String name : targets) + { + o = getValue(o, name); + } + } + else + { + o = getValue(o, target); + } + } + return o; + } + + /** + * 以类的属性的get方法方法形式获取值 + * + * @param o + * @param name + * @return value + * @throws Exception + */ + private Object getValue(Object o, String name) throws Exception + { + if (StringUtils.isNotNull(o) && StringUtils.isNotEmpty(name)) + { + Class clazz = o.getClass(); + Field field = clazz.getDeclaredField(name); + field.setAccessible(true); + o = field.get(o); + } + return o; + } + + /** + * 得到所有定义字段 + */ + private void createExcelField() + { + this.fields = getFields(); + this.fields = this.fields.stream().sorted(Comparator.comparing(objects -> ((Excel) objects[1]).sort())).collect(Collectors.toList()); + this.maxHeight = getRowHeight(); + } + + /** + * 获取字段注解信息 + */ + public List getFields() + { + List fields = new ArrayList(); + List tempFields = new ArrayList<>(); + tempFields.addAll(Arrays.asList(clazz.getSuperclass().getDeclaredFields())); + tempFields.addAll(Arrays.asList(clazz.getDeclaredFields())); + for (Field field : tempFields) + { + if (!ArrayUtils.contains(this.excludeFields, field.getName())) + { + // 单注解 + if (field.isAnnotationPresent(Excel.class)) + { + Excel attr = field.getAnnotation(Excel.class); + if (attr != null && (attr.type() == Type.ALL || attr.type() == type)) + { + field.setAccessible(true); + fields.add(new Object[] { field, attr }); + } + if (Collection.class.isAssignableFrom(field.getType())) + { + subMethod = getSubMethod(field.getName(), clazz); + ParameterizedType pt = (ParameterizedType) field.getGenericType(); + Class subClass = (Class) pt.getActualTypeArguments()[0]; + this.subFields = FieldUtils.getFieldsListWithAnnotation(subClass, Excel.class); + } + } + + // 多注解 + if (field.isAnnotationPresent(Excels.class)) + { + Excels attrs = field.getAnnotation(Excels.class); + Excel[] excels = attrs.value(); + for (Excel attr : excels) + { + if (!ArrayUtils.contains(this.excludeFields, field.getName() + "." + attr.targetAttr()) + && (attr != null && (attr.type() == Type.ALL || attr.type() == type))) + { + field.setAccessible(true); + fields.add(new Object[] { field, attr }); + } + } + } + } + } + return fields; + } + + /** + * 根据注解获取最大行高 + */ + public short getRowHeight() + { + double maxHeight = 0; + for (Object[] os : this.fields) + { + Excel excel = (Excel) os[1]; + maxHeight = Math.max(maxHeight, excel.height()); + } + return (short) (maxHeight * 20); + } + + /** + * 创建一个工作簿 + */ + public void createWorkbook() + { + this.wb = new SXSSFWorkbook(500); + this.sheet = wb.createSheet(); + wb.setSheetName(0, sheetName); + this.styles = createStyles(wb); + } + + /** + * 创建工作表 + * + * @param sheetNo sheet数量 + * @param index 序号 + */ + public void createSheet(int sheetNo, int index) + { + // 设置工作表的名称. + if (sheetNo > 1 && index > 0) + { + this.sheet = wb.createSheet(); + this.createTitle(); + wb.setSheetName(index, sheetName + index); + } + } + + /** + * 获取单元格值 + * + * @param row 获取的行 + * @param column 获取单元格列号 + * @return 单元格值 + */ + public Object getCellValue(Row row, int column) + { + if (row == null) + { + return row; + } + Object val = ""; + try + { + Cell cell = row.getCell(column); + if (StringUtils.isNotNull(cell)) + { + if (cell.getCellType() == CellType.NUMERIC || cell.getCellType() == CellType.FORMULA) + { + val = cell.getNumericCellValue(); + if (DateUtil.isCellDateFormatted(cell)) + { + val = DateUtil.getJavaDate((Double) val); // POI Excel 日期格式转换 + } + else + { + if ((Double) val % 1 != 0) + { + val = new BigDecimal(val.toString()); + } + else + { + val = new DecimalFormat("0").format(val); + } + } + } + else if (cell.getCellType() == CellType.STRING) + { + val = cell.getStringCellValue(); + } + else if (cell.getCellType() == CellType.BOOLEAN) + { + val = cell.getBooleanCellValue(); + } + else if (cell.getCellType() == CellType.ERROR) + { + val = cell.getErrorCellValue(); + } + + } + } + catch (Exception e) + { + return val; + } + return val; + } + + /** + * 判断是否是空行 + * + * @param row 判断的行 + * @return + */ + private boolean isRowEmpty(Row row) + { + if (row == null) + { + return true; + } + for (int i = row.getFirstCellNum(); i < row.getLastCellNum(); i++) + { + Cell cell = row.getCell(i); + if (cell != null && cell.getCellType() != CellType.BLANK) + { + return false; + } + } + return true; + } + + /** + * 获取Excel2003图片 + * + * @param sheet 当前sheet对象 + * @param workbook 工作簿对象 + * @return Map key:图片单元格索引(1_1)String,value:图片流PictureData + */ + public static Map getSheetPictures03(HSSFSheet sheet, HSSFWorkbook workbook) + { + Map sheetIndexPicMap = new HashMap(); + List pictures = workbook.getAllPictures(); + if (!pictures.isEmpty()) + { + for (HSSFShape shape : sheet.getDrawingPatriarch().getChildren()) + { + HSSFClientAnchor anchor = (HSSFClientAnchor) shape.getAnchor(); + if (shape instanceof HSSFPicture) + { + HSSFPicture pic = (HSSFPicture) shape; + int pictureIndex = pic.getPictureIndex() - 1; + HSSFPictureData picData = pictures.get(pictureIndex); + String picIndex = anchor.getRow1() + "_" + anchor.getCol1(); + sheetIndexPicMap.put(picIndex, picData); + } + } + return sheetIndexPicMap; + } + else + { + return sheetIndexPicMap; + } + } + + /** + * 获取Excel2007图片 + * + * @param sheet 当前sheet对象 + * @param workbook 工作簿对象 + * @return Map key:图片单元格索引(1_1)String,value:图片流PictureData + */ + public static Map getSheetPictures07(XSSFSheet sheet, XSSFWorkbook workbook) + { + Map sheetIndexPicMap = new HashMap(); + for (POIXMLDocumentPart dr : sheet.getRelations()) + { + if (dr instanceof XSSFDrawing) + { + XSSFDrawing drawing = (XSSFDrawing) dr; + List shapes = drawing.getShapes(); + for (XSSFShape shape : shapes) + { + if (shape instanceof XSSFPicture) + { + XSSFPicture pic = (XSSFPicture) shape; + XSSFClientAnchor anchor = pic.getPreferredSize(); + CTMarker ctMarker = anchor.getFrom(); + String picIndex = ctMarker.getRow() + "_" + ctMarker.getCol(); + sheetIndexPicMap.put(picIndex, pic.getPictureData()); + } + } + } + } + return sheetIndexPicMap; + } + + /** + * 格式化不同类型的日期对象 + * + * @param dateFormat 日期格式 + * @param val 被格式化的日期对象 + * @return 格式化后的日期字符 + */ + public String parseDateToStr(String dateFormat, Object val) + { + if (val == null) + { + return ""; + } + String str; + if (val instanceof Date) + { + str = DateUtils.parseDateToStr(dateFormat, (Date) val); + } + else if (val instanceof LocalDateTime) + { + str = DateUtils.parseDateToStr(dateFormat, DateUtils.toDate((LocalDateTime) val)); + } + else if (val instanceof LocalDate) + { + str = DateUtils.parseDateToStr(dateFormat, DateUtils.toDate((LocalDate) val)); + } + else + { + str = val.toString(); + } + return str; + } + + /** + * 是否有对象的子列表 + */ + public boolean isSubList() + { + return StringUtils.isNotNull(subFields) && subFields.size() > 0; + } + + /** + * 是否有对象的子列表,集合不为空 + */ + public boolean isSubListValue(T vo) + { + return StringUtils.isNotNull(subFields) && subFields.size() > 0 && StringUtils.isNotNull(getListCellValue(vo)) && getListCellValue(vo).size() > 0; + } + + /** + * 获取集合的值 + */ + public Collection getListCellValue(Object obj) + { + Object value; + try + { + value = subMethod.invoke(obj, new Object[] {}); + } + catch (Exception e) + { + return new ArrayList(); + } + return (Collection) value; + } + + /** + * 获取对象的子列表方法 + * + * @param name 名称 + * @param pojoClass 类对象 + * @return 子列表方法 + */ + public Method getSubMethod(String name, Class pojoClass) + { + StringBuffer getMethodName = new StringBuffer("get"); + getMethodName.append(name.substring(0, 1).toUpperCase()); + getMethodName.append(name.substring(1)); + Method method = null; + try + { + method = pojoClass.getMethod(getMethodName.toString(), new Class[] {}); + } + catch (Exception e) + { + log.error("获取对象异常{}", e.getMessage()); + } + return method; + } +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/ehsEnterprise/domain/EhsEnterprise.java b/ruoyi-system/src/main/java/com/ruoyi/ehsEnterprise/domain/EhsEnterprise.java index 7cb3eea..45202b7 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/ehsEnterprise/domain/EhsEnterprise.java +++ b/ruoyi-system/src/main/java/com/ruoyi/ehsEnterprise/domain/EhsEnterprise.java @@ -67,7 +67,7 @@ public class EhsEnterprise extends BaseEntity private String businessProjects; /** 企业现状(0停业、1正常经营) */ - @Excel(name = "企业现状", readConverterExp = "0=停业、1正常经营") + @Excel(name = "企业现状", readConverterExp = "0=停业,1=正常经营") private String enterpriseStatus; /** 分管安全副职姓名 */ @@ -78,10 +78,10 @@ public class EhsEnterprise extends BaseEntity @Excel(name = "分管安全副职电话") private String safetyManagerTel; - @Excel(name = "行政区域") + @Excel(name = "行政区域", dictType = "area_id") private String areaId; - @Excel(name = "经济类型") + @Excel(name = "经济类型" , dictType = "economic_type") private String economicType; - @Excel(name = "企业规模") + @Excel(name = "企业规模", dictType = "enterprise_scale") private String enterpriseScale; } diff --git a/ruoyi-system/src/main/java/com/ruoyi/ehsEnterprise/service/IEhsEnterpriseService.java b/ruoyi-system/src/main/java/com/ruoyi/ehsEnterprise/service/IEhsEnterpriseService.java index e880e85..c456af8 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/ehsEnterprise/service/IEhsEnterpriseService.java +++ b/ruoyi-system/src/main/java/com/ruoyi/ehsEnterprise/service/IEhsEnterpriseService.java @@ -3,6 +3,7 @@ package com.ruoyi.ehsEnterprise.service; import java.util.List; import com.baomidou.mybatisplus.extension.service.IService; import com.ruoyi.ehsEnterprise.domain.EhsEnterprise; +import com.ruoyi.ehsRisk.domain.EhsRisk; /** * 企业基本信息Service接口 @@ -27,5 +28,5 @@ public interface IEhsEnterpriseService extends IService { * @return 企业基本信息集合 */ public List selectEhsEnterpriseList(EhsEnterprise ehsEnterprise); - + public String importEnterprise(List riskList, Boolean isUpdateSupport ); } diff --git a/ruoyi-system/src/main/java/com/ruoyi/ehsEnterprise/service/impl/EhsEnterpriseServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/ehsEnterprise/service/impl/EhsEnterpriseServiceImpl.java index 9560304..503e66f 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/ehsEnterprise/service/impl/EhsEnterpriseServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/ehsEnterprise/service/impl/EhsEnterpriseServiceImpl.java @@ -3,7 +3,10 @@ package com.ruoyi.ehsEnterprise.service.impl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.ruoyi.common.exception.ServiceException; import com.ruoyi.common.utils.SecurityUtils; +import com.ruoyi.common.utils.bean.BeanValidators; +import com.ruoyi.ehsRisk.domain.EhsRisk; import org.springframework.stereotype.Service; import org.springframework.beans.factory.annotation.Autowired; import com.ruoyi.common.utils.StringUtils; @@ -13,6 +16,8 @@ import com.ruoyi.ehsEnterprise.mapper.EhsEnterpriseMapper; import com.ruoyi.ehsEnterprise.domain.EhsEnterprise; import com.ruoyi.ehsEnterprise.service.IEhsEnterpriseService; +import javax.validation.Validator; + /** * 企业基本信息Service业务层处理 * @@ -24,7 +29,8 @@ public class EhsEnterpriseServiceImpl extends ServiceImpl list, Boolean isUpdateSupport ) + { + if (StringUtils.isNull(list) || list.size() == 0) + { + throw new ServiceException("导入数据不能为空!"); + } + int successNum = 0; + int failureNum = 0; + StringBuilder successMsg = new StringBuilder(); + StringBuilder failureMsg = new StringBuilder(); + int i =0; + for (EhsEnterprise obj : list) + { + i++; + try + { + BeanValidators.validateWithException(validator, obj); + ehsEnterpriseMapper.insert(obj); + successNum++; + successMsg.append("
" + successNum + "、第 " + i + " 行记录导入成功"); + } + catch (Exception e) + { + failureNum++; + String msg = "
" + failureNum + "、第 " +i + " 行记录导入失败:"; + failureMsg.append(msg + e.getMessage()); + log.error(msg, e); + } + } + if (failureNum > 0) + { + failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:"); + throw new ServiceException(failureMsg.toString()); + } + else + { + successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条,数据如下:"); + } + return successMsg.toString(); + } private LambdaQueryWrapper buildQueryWrapper(EhsEnterprise query) { Map params = query.getParams(); LambdaQueryWrapper lqw = Wrappers.lambdaQuery(); diff --git a/ruoyi-system/src/main/java/com/ruoyi/ehsHiddenDanger/domain/EhsHiddenDanger.java b/ruoyi-system/src/main/java/com/ruoyi/ehsHiddenDanger/domain/EhsHiddenDanger.java index d47af5e..609ba6a 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/ehsHiddenDanger/domain/EhsHiddenDanger.java +++ b/ruoyi-system/src/main/java/com/ruoyi/ehsHiddenDanger/domain/EhsHiddenDanger.java @@ -38,7 +38,7 @@ public class EhsHiddenDanger extends BaseEntity private String enterpriseName; /** 企业现状(0停业、1正常经营) */ - @Excel(name = "企业现状", readConverterExp = "0=停业、1正常经营") + @Excel(name = "企业现状", readConverterExp = "0=停业,1=正常经营") private String enterpriseStatus; /** 行业 字典 */ @@ -54,11 +54,11 @@ public class EhsHiddenDanger extends BaseEntity private Date checkTime; /** 排查方式 */ - @Excel(name = "排查方式") + @Excel(name = "排查方式", dictType = "check_type") private String checkType; /** 隐患照片 */ - @Excel(name = "隐患照片") + // @Excel(name = "隐患照片" ) private String hiddenDangerImg; /** 整改措施 */ @@ -66,7 +66,7 @@ public class EhsHiddenDanger extends BaseEntity private String rectifyMeasure; /** 整改进度 */ - @Excel(name = "整改进度") + @Excel(name = "整改进度", dictType = "hidden_danger_status") private String status; /** 整改时间 */ @@ -78,7 +78,7 @@ public class EhsHiddenDanger extends BaseEntity private String principalName; /** 整改照片 */ - @Excel(name = "整改照片") + //@Excel(name = "整改照片") private String rectifyImg; /** 监管部门 */ @@ -90,21 +90,21 @@ public class EhsHiddenDanger extends BaseEntity private String regulatoryName; /** 隐患级别 */ - @Excel(name = "隐患级别") + @Excel(name = "隐患级别", dictType = "hidden_danger_grade" ) private String hiddenDangerGrade; /** 隐患类型 */ - @Excel(name = "隐患类型") + @Excel(name = "隐患类型", dictType = "hidden_danger_type") private String hiddenDangerType; /** 标签 */ - @Excel(name = "标签") + //@Excel(name = "标签") private String hiddenDangerLabel; - @Excel(name = "是否督办") + @Excel(name = "是否督办" , dictType = "ehs_yes_no") private Long isSupervise; - @Excel(name = "协办部门列表") + //@Excel(name = "协办部门列表" , type = Excel.Type.EXPORT) private String assistDept; @Excel(name = "督办结果") @@ -118,6 +118,7 @@ public class EhsHiddenDanger extends BaseEntity private String assistDeptName; @TableField(exist = false) + //@Excel(name = "标签", dictType = "hidden_danger_label") private String[] hiddenDangerLabelArray; @Excel(name = "整改期限", width = 30, dateFormat = "yyyy-MM-dd") @@ -127,13 +128,19 @@ public class EhsHiddenDanger extends BaseEntity @Excel(name = "整改资金") private BigDecimal rectifyMoney; - @Excel(name = "行政区域") + @Excel(name = "行政区域", dictType = "area_id") private String areaId; - @Excel(name = "经济类型") + @Excel(name = "经济类型" , dictType = "economic_type") private String economicType; - @Excel(name = "企业规模") + @Excel(name = "企业规模", dictType = "enterprise_scale") private String enterpriseScale; - + @Excel(name = "是否乡镇(街道)", dictType = "ehs_yes_no") + private String isTowns; @TableField(exist = false) private String isOverTime;//是否超时未整改 + @Excel(name = "标签") + @TableField(exist = false) + private String hiddenDangerLabelName;//是否超时未整改 + @TableField(exist = false) + private Integer overTime;//是否超时未整改 } diff --git a/ruoyi-system/src/main/java/com/ruoyi/ehsHiddenDanger/mapper/EhsHiddenDangerMapper.java b/ruoyi-system/src/main/java/com/ruoyi/ehsHiddenDanger/mapper/EhsHiddenDangerMapper.java index 964e327..47a94a7 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/ehsHiddenDanger/mapper/EhsHiddenDangerMapper.java +++ b/ruoyi-system/src/main/java/com/ruoyi/ehsHiddenDanger/mapper/EhsHiddenDangerMapper.java @@ -18,7 +18,7 @@ public interface EhsHiddenDangerMapper extends BaseMapper { * @return 隐患信息 */ public EhsHiddenDanger selectEhsHiddenDangerByHiddenDangerId(Long hiddenDangerId); - + public EhsHiddenDanger selectEhsHiddenDangerOverTime(EhsHiddenDanger ehsHiddenDanger); /** * 查询隐患信息列表 * diff --git a/ruoyi-system/src/main/java/com/ruoyi/ehsHiddenDanger/service/IEhsHiddenDangerService.java b/ruoyi-system/src/main/java/com/ruoyi/ehsHiddenDanger/service/IEhsHiddenDangerService.java index aca5dcd..097943a 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/ehsHiddenDanger/service/IEhsHiddenDangerService.java +++ b/ruoyi-system/src/main/java/com/ruoyi/ehsHiddenDanger/service/IEhsHiddenDangerService.java @@ -3,6 +3,7 @@ package com.ruoyi.ehsHiddenDanger.service; import java.util.List; import com.baomidou.mybatisplus.extension.service.IService; import com.ruoyi.ehsHiddenDanger.domain.EhsHiddenDanger; +import com.ruoyi.ehsRisk.domain.EhsRisk; /** * 隐患信息Service接口 @@ -39,4 +40,8 @@ public interface IEhsHiddenDangerService extends IService { * @param ehsHiddenDanger 部门ID组 */ public int assistEhsHiddenDanger(EhsHiddenDanger ehsHiddenDanger); + + public String importHiddenDanger(List list, Boolean isUpdateSupport ); + + public EhsHiddenDanger selectEhsHiddenDangerOverTime(EhsHiddenDanger ehsHiddenDanger); } diff --git a/ruoyi-system/src/main/java/com/ruoyi/ehsHiddenDanger/service/impl/EhsHiddenDangerServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/ehsHiddenDanger/service/impl/EhsHiddenDangerServiceImpl.java index cc8e3a9..f08da89 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/ehsHiddenDanger/service/impl/EhsHiddenDangerServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/ehsHiddenDanger/service/impl/EhsHiddenDangerServiceImpl.java @@ -5,7 +5,11 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.ruoyi.common.core.domain.entity.SysDept; import com.ruoyi.common.core.text.Convert; +import com.ruoyi.common.exception.ServiceException; +import com.ruoyi.common.utils.DictUtils; import com.ruoyi.common.utils.SecurityUtils; +import com.ruoyi.common.utils.bean.BeanValidators; +import com.ruoyi.ehsRisk.domain.EhsRisk; import org.springframework.stereotype.Service; import org.springframework.beans.factory.annotation.Autowired; import com.ruoyi.common.utils.StringUtils; @@ -15,6 +19,8 @@ import com.ruoyi.ehsHiddenDanger.mapper.EhsHiddenDangerMapper; import com.ruoyi.ehsHiddenDanger.domain.EhsHiddenDanger; import com.ruoyi.ehsHiddenDanger.service.IEhsHiddenDangerService; +import javax.validation.Validator; + /** * 隐患信息Service业务层处理 * @@ -26,7 +32,8 @@ public class EhsHiddenDangerServiceImpl extends ServiceImpl list, Boolean isUpdateSupport ) + { + if (StringUtils.isNull(list) || list.size() == 0) + { + throw new ServiceException("导入用户数据不能为空!"); + } + int successNum = 0; + int failureNum = 0; + StringBuilder successMsg = new StringBuilder(); + StringBuilder failureMsg = new StringBuilder(); + int i =0; + for (EhsHiddenDanger obj : list) + { + i++; + try + { + BeanValidators.validateWithException(validator, obj); + if(StringUtils.isNotEmpty(obj.getHiddenDangerLabelName()) ){ + String s = DictUtils.getDictValue("hidden_danger_label", obj.getHiddenDangerLabelName(), ","); + obj.setHiddenDangerLabel(s); + } + ehsHiddenDangerMapper.insert(obj); + successNum++; + successMsg.append("
" + successNum + "、第 " + i + " 行记录导入成功"); + } + catch (Exception e) + { + failureNum++; + String msg = "
" + failureNum + "、第 " +i + " 行记录导入失败:"; + failureMsg.append(msg + e.getMessage()); + log.error(msg, e); + } + } + if (failureNum > 0) + { + failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:"); + throw new ServiceException(failureMsg.toString()); + } + else + { + successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条,数据如下:"); + } + return successMsg.toString(); + } + + public EhsHiddenDanger selectEhsHiddenDangerOverTime(EhsHiddenDanger ehsHiddenDanger){ + return ehsHiddenDangerMapper.selectEhsHiddenDangerOverTime(ehsHiddenDanger); + } } diff --git a/ruoyi-system/src/main/java/com/ruoyi/ehsMaterial/domain/EhsMaterial.java b/ruoyi-system/src/main/java/com/ruoyi/ehsMaterial/domain/EhsMaterial.java index d43b182..751d419 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/ehsMaterial/domain/EhsMaterial.java +++ b/ruoyi-system/src/main/java/com/ruoyi/ehsMaterial/domain/EhsMaterial.java @@ -31,11 +31,11 @@ public class EhsMaterial extends BaseEntity private Long materialId; /** 性质 */ - @Excel(name = "性质") + @Excel(name = "性质", readConverterExp = "1=自储,2=社会代储") private Long materialType; /** 类别 */ - @Excel(name = "类别") + @Excel(name = "物资分类", dictType = "material_class_fast") private Long classFirst; /** 类别 */ @@ -66,7 +66,8 @@ public class EhsMaterial extends BaseEntity @Excel(name = "联系电话") private String tel; /** 上报部门 */ - @Excel(name = "待处理出库") + // @Excel(name = "待处理出库") + @TableField(exist = false) private String sendQuantity; diff --git a/ruoyi-system/src/main/java/com/ruoyi/ehsMaterial/service/IEhsMaterialService.java b/ruoyi-system/src/main/java/com/ruoyi/ehsMaterial/service/IEhsMaterialService.java index fba5c66..6386543 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/ehsMaterial/service/IEhsMaterialService.java +++ b/ruoyi-system/src/main/java/com/ruoyi/ehsMaterial/service/IEhsMaterialService.java @@ -3,6 +3,7 @@ package com.ruoyi.ehsMaterial.service; import java.util.List; import com.baomidou.mybatisplus.extension.service.IService; import com.ruoyi.ehsMaterial.domain.EhsMaterial; +import com.ruoyi.ehsRisk.domain.EhsRisk; /** * 物资信息包含 通用应急救援装备”“防汛抗旱应急救援装备”“森林防灭火应急救援装备”“救灾物资”Service接口 @@ -27,5 +28,6 @@ public interface IEhsMaterialService extends IService { * @return 物资信息包含 通用应急救援装备”“防汛抗旱应急救援装备”“森林防灭火应急救援装备”“救灾物资”集合 */ public List selectEhsMaterialList(EhsMaterial ehsMaterial); + public String importMaterial(List list,String classType, Boolean isUpdateSupport); } diff --git a/ruoyi-system/src/main/java/com/ruoyi/ehsMaterial/service/impl/EhsMaterialServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/ehsMaterial/service/impl/EhsMaterialServiceImpl.java index 15b49f1..6e89273 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/ehsMaterial/service/impl/EhsMaterialServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/ehsMaterial/service/impl/EhsMaterialServiceImpl.java @@ -3,16 +3,27 @@ package com.ruoyi.ehsMaterial.service.impl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.ruoyi.common.exception.ServiceException; import com.ruoyi.common.utils.SecurityUtils; +import com.ruoyi.common.utils.bean.BeanValidators; +import com.ruoyi.ehsRisk.domain.EhsRisk; +import com.ruoyi.materialClass.domain.MaterialClassMaster; +import com.ruoyi.materialClass.domain.MaterialClassSub; +import com.ruoyi.materialClass.mapper.MaterialClassMasterMapper; +import com.ruoyi.materialClass.mapper.MaterialClassSubMapper; import org.springframework.stereotype.Service; import org.springframework.beans.factory.annotation.Autowired; import com.ruoyi.common.utils.StringUtils; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; + import com.ruoyi.ehsMaterial.mapper.EhsMaterialMapper; import com.ruoyi.ehsMaterial.domain.EhsMaterial; import com.ruoyi.ehsMaterial.service.IEhsMaterialService; +import javax.validation.Validator; + /** * 物资信息包含 通用应急救援装备”“防汛抗旱应急救援装备”“森林防灭火应急救援装备”“救灾物资”Service业务层处理 * @@ -24,7 +35,10 @@ public class EhsMaterialServiceImpl extends ServiceImpl list,String classType, Boolean isUpdateSupport) + { + if (StringUtils.isNull(list) || list.size() == 0) + { + throw new ServiceException("导入用户数据不能为空!"); + } + int successNum = 0; + int failureNum = 0; + StringBuilder successMsg = new StringBuilder(); + StringBuilder failureMsg = new StringBuilder(); + MaterialClassSub msm = new MaterialClassSub(); + msm.setClassMastType(classType); + List mlist = materialClassSubMapper.selectMaterialClassSubList(msm); + Map map = mlist.stream() + .collect(Collectors.toMap(MaterialClassSub::getClassNameSub, MaterialClassSub::getClassSubId)); + int i =0; + for (EhsMaterial obj : list) + { + i++; + try + { + if(StringUtils.isNotEmpty(obj.getMaterialName()) && map.containsKey(obj.getMaterialName())) { + BeanValidators.validateWithException(validator, obj); + String SbuId = map.get(obj.getMaterialName()); + String mSid = SbuId.split("-")[0]; + obj.setClassSecond(mSid); + obj.setMaterialName(SbuId); + ehsMaterialMapper.insert(obj); + successNum++; + successMsg.append("
" + successNum + "、第 " + i + " 行记录导入成功"); + }else{ + failureNum++; + String msg = "
" + failureNum + "、第 " +i + " 行记录导入失败,物资名称未找到或为空:"+obj.getMaterialName(); + failureMsg.append( msg); + } + } + catch (Exception e) + { + failureNum++; + String msg = "
" + failureNum + "、第 " +i + " 行记录导入失败:"; + failureMsg.append(msg + e.getMessage()); + log.error(msg, e); + } + } + if (failureNum > 0) + { + failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:"); + throw new ServiceException(failureMsg.toString()); + } + else + { + successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条,数据如下:"); + } + return successMsg.toString(); + } } diff --git a/ruoyi-system/src/main/java/com/ruoyi/ehsRisk/domain/EhsRisk.java b/ruoyi-system/src/main/java/com/ruoyi/ehsRisk/domain/EhsRisk.java index 48172de..04fb368 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/ehsRisk/domain/EhsRisk.java +++ b/ruoyi-system/src/main/java/com/ruoyi/ehsRisk/domain/EhsRisk.java @@ -31,15 +31,15 @@ public class EhsRisk extends BaseEntity private Long riskId; /** 风险点等级 */ - @Excel(name = "风险点等级") + @Excel(name = "风险点等级" , dictType = "risk_grade") private Long riskGrade; /** 风险点类型 字典 */ - @Excel(name = "风险点类型 字典 ") + @Excel(name = "风险点类型" , dictType = "risk_report_address_type") private String reportAddressType; /** 风险点位置,用分号“;”分隔 */ - @Excel(name = "风险点位置,用分号“;”分隔") + @Excel(name = "风险点位置") private String riskLocation; /** 风险点概况 */ @@ -47,7 +47,7 @@ public class EhsRisk extends BaseEntity private String riskDesc; /** 涉及群众数量,用分号“;”分隔 */ - @Excel(name = "涉及群众数量,用分号“;”分隔") + @Excel(name = "涉及群众数量") private String peopleQuantity; /** 抢险救援物资保障地点 */ diff --git a/ruoyi-system/src/main/java/com/ruoyi/ehsRisk/service/IEhsRiskService.java b/ruoyi-system/src/main/java/com/ruoyi/ehsRisk/service/IEhsRiskService.java index a1c90c8..8c28c6d 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/ehsRisk/service/IEhsRiskService.java +++ b/ruoyi-system/src/main/java/com/ruoyi/ehsRisk/service/IEhsRiskService.java @@ -2,6 +2,7 @@ package com.ruoyi.ehsRisk.service; import java.util.List; import com.baomidou.mybatisplus.extension.service.IService; +import com.ruoyi.common.core.domain.entity.SysUser; import com.ruoyi.ehsRisk.domain.EhsRisk; /** @@ -27,5 +28,5 @@ public interface IEhsRiskService extends IService { * @return 风险信息集合 */ public List selectEhsRiskList(EhsRisk ehsRisk); - + public String importRisk(List riskList, Boolean isUpdateSupport); } diff --git a/ruoyi-system/src/main/java/com/ruoyi/ehsRisk/service/impl/EhsRiskServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/ehsRisk/service/impl/EhsRiskServiceImpl.java index fe58778..87c1c48 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/ehsRisk/service/impl/EhsRiskServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/ehsRisk/service/impl/EhsRiskServiceImpl.java @@ -3,6 +3,10 @@ package com.ruoyi.ehsRisk.service.impl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.ruoyi.common.core.domain.entity.SysUser; +import com.ruoyi.common.exception.ServiceException; +import com.ruoyi.common.utils.SecurityUtils; +import com.ruoyi.common.utils.bean.BeanValidators; import org.springframework.stereotype.Service; import org.springframework.beans.factory.annotation.Autowired; import com.ruoyi.common.utils.StringUtils; @@ -12,6 +16,8 @@ import com.ruoyi.ehsRisk.mapper.EhsRiskMapper; import com.ruoyi.ehsRisk.domain.EhsRisk; import com.ruoyi.ehsRisk.service.IEhsRiskService; +import javax.validation.Validator; + /** * 风险信息Service业务层处理 * @@ -23,7 +29,8 @@ public class EhsRiskServiceImpl extends ServiceImpl impl @Autowired private EhsRiskMapper ehsRiskMapper; - + @Autowired + protected Validator validator; /** * 查询风险信息 * @@ -66,7 +73,54 @@ public class EhsRiskServiceImpl extends ServiceImpl impl { return ehsRiskMapper.selectEhsRiskList(ehsRisk); } - + /** + * 导入用户数据 + * + * @param list 数据列表 + * @param isUpdateSupport 是否更新支持,如果已存在,则进行更新数据 + * @return 结果 + */ + @Override + public String importRisk(List list, Boolean isUpdateSupport ) + { + if (StringUtils.isNull(list) || list.size() == 0) + { + throw new ServiceException("导入用户数据不能为空!"); + } + int successNum = 0; + int failureNum = 0; + StringBuilder successMsg = new StringBuilder(); + StringBuilder failureMsg = new StringBuilder(); + int i =0; + for (EhsRisk risk : list) + { + i++; + try + { + BeanValidators.validateWithException(validator, risk); + ehsRiskMapper.insert(risk); + successNum++; + successMsg.append("
" + successNum + "、第 " + i + " 行记录导入成功"); + } + catch (Exception e) + { + failureNum++; + String msg = "
" + failureNum + "、第 " +i + " 行记录导入失败:"; + failureMsg.append(msg + e.getMessage()); + log.error(msg, e); + } + } + if (failureNum > 0) + { + failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:"); + throw new ServiceException(failureMsg.toString()); + } + else + { + successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条,数据如下:"); + } + return successMsg.toString(); + } private LambdaQueryWrapper buildQueryWrapper(EhsRisk query) { Map params = query.getParams(); diff --git a/ruoyi-system/src/main/java/com/ruoyi/materialClass/domain/MaterialClass.java b/ruoyi-system/src/main/java/com/ruoyi/materialClass/domain/MaterialClass.java new file mode 100644 index 0000000..9dedec6 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/materialClass/domain/MaterialClass.java @@ -0,0 +1,13 @@ +package com.ruoyi.materialClass.domain; + +import lombok.Data; + +import java.util.List; + +@Data +public class MaterialClass { + private String value; + private String label; + List children; +} + diff --git a/ruoyi-system/src/main/java/com/ruoyi/materialClass/domain/MaterialClassMaster.java b/ruoyi-system/src/main/java/com/ruoyi/materialClass/domain/MaterialClassMaster.java new file mode 100644 index 0000000..fe3465b --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/materialClass/domain/MaterialClassMaster.java @@ -0,0 +1,49 @@ +package com.ruoyi.materialClass.domain; + +import java.util.List; +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.ToString; +import lombok.experimental.Accessors; +import com.ruoyi.common.annotation.Excel; +import com.ruoyi.common.core.domain.BaseEntity; + +/** + * 物资分类一级分类对象 material_class_master + * + * @author ruoyi + * @date 2024-01-05 + */ +@Data +@ToString +@NoArgsConstructor +@Accessors(chain = true) +@TableName("material_class_master") +public class MaterialClassMaster extends BaseEntity +{ + private static final long serialVersionUID = 1L; + + /** 分类编号 */ + @Excel(name = "分类编号") + private String classMastId; + + /** 主键 */ + @TableId(type= IdType.AUTO) + private Long id; + + /** 分类的大类 */ + @Excel(name = "分类的大类") + private String classMastType; + + /** 分类名称 */ + @Excel(name = "分类名称") + private String classNameMast; + + /** 物资分类-二级分类信息 */ + @TableField(exist = false) + private List materialClassSubList; +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/materialClass/domain/MaterialClassSub.java b/ruoyi-system/src/main/java/com/ruoyi/materialClass/domain/MaterialClassSub.java new file mode 100644 index 0000000..57a4521 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/materialClass/domain/MaterialClassSub.java @@ -0,0 +1,52 @@ +package com.ruoyi.materialClass.domain; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.ToString; +import lombok.experimental.Accessors; +import com.ruoyi.common.annotation.Excel; +import com.ruoyi.common.core.domain.BaseEntity; + +/** + * 物资分类-二级分类对象 material_class_sub + * + * @author ruoyi + * @date 2024-01-05 + */ +@Data +@ToString +@NoArgsConstructor +@Accessors(chain = true) +@TableName("material_class_sub") +//@ApiModel(value = "MaterialClassSub", description = "物资分类-二级分类实体") +public class MaterialClassSub extends BaseEntity +{ + private static final long serialVersionUID = 1L; + + /** 二级分类主键 */ + @Excel(name = "二级分类主键") + // @ApiModelProperty("二级分类主键") + private String classSubId; + /** 分类的大类 */ + @Excel(name = "分类的大类") + private String classMastType; + /** 上级分类主键 */ + @Excel(name = "上级分类主键") + // @ApiModelProperty("上级分类主键") + private String classMastId; + // @ApiModelProperty("上级分类主键") + private Long mastId; + /** 二级分类名称 */ + @Excel(name = "二级分类名称") + // @ApiModelProperty("二级分类名称") + private String classNameSub; + + /** 主键 */ + @TableId(type= IdType.AUTO) + // @ApiModelProperty("主键") + private Long id; + +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/materialClass/mapper/MaterialClassMasterMapper.java b/ruoyi-system/src/main/java/com/ruoyi/materialClass/mapper/MaterialClassMasterMapper.java new file mode 100644 index 0000000..fe54a9c --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/materialClass/mapper/MaterialClassMasterMapper.java @@ -0,0 +1,45 @@ +package com.ruoyi.materialClass.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.ruoyi.materialClass.domain.MaterialClassMaster; +import java.util.List; + +/** + * 物资分类一级分类Mapper接口 + * + * @author ruoyi + * @date 2024-01-05 + */ +public interface MaterialClassMasterMapper extends BaseMapper { + /** + * 查询物资分类一级分类 + * + * @param classMastId 物资分类一级分类主键 + * @return 物资分类一级分类 + */ + public MaterialClassMaster selectMaterialClassMastByClassMastId(String classMastId); + + /** + * 查询物资分类一级分类列表 + * + * @param materialClassMast 物资分类一级分类 + * @return 物资分类一级分类集合 + */ + public List selectMaterialClassMastList(MaterialClassMaster materialClassMast); + + /** + * 删除物资分类一级分类信息 + * + * @param classMastId 物资分类一级分类主键 + * @return 结果 + *//* + int deleteMaterialClassSubByClassMastId(@Param("classMastId")String classMastId); + + *//** + * 批量新增物资分类-二级分类 + * + * @param materialClassSubList 物资分类-二级分类列表 + * @return 结果 + *//* + int batchInsertMaterialClassSub(List materialClassSubList);*/ +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/materialClass/mapper/MaterialClassSubMapper.java b/ruoyi-system/src/main/java/com/ruoyi/materialClass/mapper/MaterialClassSubMapper.java new file mode 100644 index 0000000..f6c0d81 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/materialClass/mapper/MaterialClassSubMapper.java @@ -0,0 +1,31 @@ +package com.ruoyi.materialClass.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.ruoyi.materialClass.domain.MaterialClassSub; +import java.util.List; + +/** + * 物资分类-二级分类Mapper接口 + * + * @author ruoyi + * @date 2024-01-04 + */ +public interface MaterialClassSubMapper extends BaseMapper { + /** + * 查询物资分类-二级分类 + * + * @param classSubId 物资分类-二级分类主键 + * @return 物资分类-二级分类 + */ + public MaterialClassSub selectMaterialClassSubByClassSubId(String classSubId); + + /** + * 查询物资分类-二级分类列表 + * + * @param materialClassSub 物资分类-二级分类 + * @return 物资分类-二级分类集合 + */ + public List selectMaterialClassSubList(MaterialClassSub materialClassSub); + + public int deleteMaterialClassSubByClassMastId(String classMastId); +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/materialClass/service/IMaterialClassMasterService.java b/ruoyi-system/src/main/java/com/ruoyi/materialClass/service/IMaterialClassMasterService.java new file mode 100644 index 0000000..126800d --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/materialClass/service/IMaterialClassMasterService.java @@ -0,0 +1,64 @@ +package com.ruoyi.materialClass.service; + +import java.util.List; +import com.baomidou.mybatisplus.extension.service.IService; +import com.ruoyi.materialClass.domain.MaterialClassMaster; + +/** + * 物资分类一级分类Service接口 + * + * @author ruoyi + * @date 2024-01-05 + */ +public interface IMaterialClassMasterService extends IService { + + /** + * 查询物资分类一级分类 + * + * @param classMastId 物资分类一级分类主键 + * @return 物资分类一级分类 + */ + public MaterialClassMaster selectMaterialClassMastByClassMastId(String classMastId); + + /** + * 查询物资分类一级分类列表 + * + * @param materialClassMast 物资分类一级分类 + * @return 物资分类一级分类集合 + */ + public List selectMaterialClassMastList(MaterialClassMaster materialClassMast); + + + + /** + * 新增物资分类一级分类 + * + * @param materialClassMast 物资分类一级分类 + * @return 结果 + */ + public int insertMaterialClassMast(MaterialClassMaster materialClassMast); + + /** + * 修改物资分类一级分类 + * + * @param materialClassMast 物资分类一级分类 + * @return 结果 + */ + public int updateMaterialClassMast(MaterialClassMaster materialClassMast); + + /** + * 批量删除物资分类一级分类 + * + * @param classMastIds 需要删除的物资分类一级分类主键集合 + * @return 结果 + */ + public int deleteMaterialClassMastByClassMastIds(String[] classMastIds); + + /** + * 删除物资分类一级分类信息 + * + * @param classMastId 物资分类一级分类主键 + * @return 结果 + */ + public int deleteMaterialClassMastByClassMastId(String classMastId); +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/materialClass/service/IMaterialClassSubService.java b/ruoyi-system/src/main/java/com/ruoyi/materialClass/service/IMaterialClassSubService.java new file mode 100644 index 0000000..c22558c --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/materialClass/service/IMaterialClassSubService.java @@ -0,0 +1,31 @@ +package com.ruoyi.materialClass.service; + +import java.util.List; +import com.baomidou.mybatisplus.extension.service.IService; +import com.ruoyi.materialClass.domain.MaterialClassSub; + +/** + * 物资分类-二级分类Service接口 + * + * @author ruoyi + * @date 2024-01-04 + */ +public interface IMaterialClassSubService extends IService { + + /** + * 查询物资分类-二级分类 + * + * @param classSubId 物资分类-二级分类主键 + * @return 物资分类-二级分类 + */ + public MaterialClassSub selectMaterialClassSubByClassSubId(String classSubId); + + /** + * 查询物资分类-二级分类列表 + * + * @param materialClassSub 物资分类-二级分类 + * @return 物资分类-二级分类集合 + */ + public List selectMaterialClassSubList(MaterialClassSub materialClassSub); + +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/materialClass/service/impl/MaterialClassMasterServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/materialClass/service/impl/MaterialClassMasterServiceImpl.java new file mode 100644 index 0000000..232c08d --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/materialClass/service/impl/MaterialClassMasterServiceImpl.java @@ -0,0 +1,157 @@ +package com.ruoyi.materialClass.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.ruoyi.materialClass.mapper.MaterialClassSubMapper; +import org.springframework.stereotype.Service; +import org.springframework.beans.factory.annotation.Autowired; +import com.ruoyi.common.utils.StringUtils; +import java.util.List; +import java.util.Map; + import java.util.Arrays; + import org.springframework.transaction.annotation.Transactional; + import com.ruoyi.materialClass.domain.MaterialClassSub; +import com.ruoyi.materialClass.mapper.MaterialClassMasterMapper; +import com.ruoyi.materialClass.domain.MaterialClassMaster; +import com.ruoyi.materialClass.service.IMaterialClassMasterService; + +/** + * 物资分类一级分类Service业务层处理 + * + * @author ruoyi + * @date 2024-01-05 + */ +@Service +public class MaterialClassMasterServiceImpl extends ServiceImpl implements IMaterialClassMasterService { + + @Autowired + private MaterialClassMasterMapper materialClassMastMapper; + @Autowired + private MaterialClassSubMapper materialClassSubMapper; + /** + * 查询物资分类一级分类 + * + * @param classMastId 物资分类一级分类主键 + * @return 物资分类一级分类 + */ + @Override + public MaterialClassMaster selectMaterialClassMastByClassMastId(String classMastId) + { + MaterialClassMaster materialClassMaster = materialClassMastMapper.selectMaterialClassMastByClassMastId(classMastId); + /*MaterialClassSub sub = new MaterialClassSub(); + sub.setClassMastId(materialClassMaster.getClassMastId()); + List subs = materialClassSubMapper.selectMaterialClassSubList(sub); + materialClassMaster.setMaterialClassSubList(subs);*/ + return materialClassMaster; + } + + /** + * 查询物资分类一级分类列表 + * + * @param materialClassMast 物资分类一级分类 + * @return 物资分类一级分类 + */ + @Override + public List selectMaterialClassMastList(MaterialClassMaster materialClassMast) + { + return materialClassMastMapper.selectMaterialClassMastList(materialClassMast); + } + + /** + * 新增物资分类一级分类 + * + * @param materialClassMast 物资分类一级分类 + * @return 结果 + */ + @Transactional + @Override + public int insertMaterialClassMast(MaterialClassMaster materialClassMast) + { + int rows = materialClassMastMapper.insert(materialClassMast); + insertMaterialClassSub(materialClassMast); + return rows; + } + + /** + * 修改物资分类一级分类 + * + * @param materialClassMast 物资分类一级分类 + * @return 结果 + */ + @Transactional + @Override + public int updateMaterialClassMast(MaterialClassMaster materialClassMast) + { + materialClassSubMapper.deleteMaterialClassSubByClassMastId( materialClassMast.getId().toString()); + insertMaterialClassSub(materialClassMast); + return materialClassMastMapper.updateById(materialClassMast); + } + + /** + * 批量删除物资分类一级分类 + * + * @param classMastIds 需要删除的物资分类一级分类主键 + * @return 结果 + */ + @Transactional + @Override + public int deleteMaterialClassMastByClassMastIds(String[] classMastIds) + { + List classMastIdList = Arrays.asList(classMastIds); + for (String classMastId : classMastIdList) { + materialClassSubMapper.deleteMaterialClassSubByClassMastId(classMastId); + } + return materialClassMastMapper.deleteBatchIds(classMastIdList); + } + + /** + * 删除物资分类一级分类信息 + * + * @param classMastId 物资分类一级分类主键 + * @return 结果 + */ + @Transactional + @Override + public int deleteMaterialClassMastByClassMastId(String classMastId) + { + materialClassSubMapper.deleteMaterialClassSubByClassMastId(classMastId); + return materialClassMastMapper.deleteById(classMastId); + } + + /** + * 新增物资分类-二级分类信息 + * + * @param materialClassMast 物资分类一级分类对象 + */ + private void insertMaterialClassSub(MaterialClassMaster materialClassMast) + { + List materialClassSubList = materialClassMast.getMaterialClassSubList(); + String classMastId = materialClassMast.getClassMastId(); + Long mastId = materialClassMast.getId(); + String classMastType = materialClassMast.getClassMastType(); + if (StringUtils.isNotNull(materialClassSubList)) { + for (MaterialClassSub materialClassSub : materialClassSubList) { + materialClassSub.setClassMastId(classMastId); + materialClassSub.setMastId(mastId); + materialClassSub.setClassMastType(classMastType); + materialClassSubMapper.insert(materialClassSub); + } + //materialClassMastMapper.batchInsertMaterialClassSub(materialClassSubList); + } + } + + private LambdaQueryWrapper buildQueryWrapper(MaterialClassMaster query) { + Map params = query.getParams(); + LambdaQueryWrapper lqw = Wrappers.lambdaQuery(); + lqw.eq(StringUtils.isNotBlank(query.getClassMastId()), MaterialClassMaster::getClassMastId, query.getClassMastId()); + lqw.eq(StringUtils.isNotBlank(query.getClassMastType()), MaterialClassMaster::getClassMastType, query.getClassMastType()); + lqw.eq(StringUtils.isNotBlank(query.getClassNameMast()), MaterialClassMaster::getClassNameMast, query.getClassNameMast()); + lqw.orderByDesc(MaterialClassMaster::getCreateTime); + lqw.eq(query.getDeptId() != null, MaterialClassMaster::getDeptId, query.getDeptId()); + lqw.eq(query.getCreateUserId() != null, MaterialClassMaster::getCreateUserId, query.getCreateUserId()); + lqw.eq(query.getUpdateUserId() != null, MaterialClassMaster::getUpdateUserId, query.getUpdateUserId()); + return lqw; + } + +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/materialClass/service/impl/MaterialClassSubServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/materialClass/service/impl/MaterialClassSubServiceImpl.java new file mode 100644 index 0000000..df62cc5 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/materialClass/service/impl/MaterialClassSubServiceImpl.java @@ -0,0 +1,60 @@ +package com.ruoyi.materialClass.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import org.springframework.stereotype.Service; +import org.springframework.beans.factory.annotation.Autowired; +import com.ruoyi.common.utils.StringUtils; +import java.util.List; +import java.util.Map; +import com.ruoyi.materialClass.mapper.MaterialClassSubMapper; +import com.ruoyi.materialClass.domain.MaterialClassSub; +import com.ruoyi.materialClass.service.IMaterialClassSubService; + +/** + * 物资分类-二级分类Service业务层处理 + * + * @author ruoyi + * @date 2024-01-04 + */ +@Service +public class MaterialClassSubServiceImpl extends ServiceImpl implements IMaterialClassSubService { + + @Autowired + private MaterialClassSubMapper materialClassSubMapper; + + /** + * 查询物资分类-二级分类 + * + * @param classSubId 物资分类-二级分类主键 + * @return 物资分类-二级分类 + */ + @Override + public MaterialClassSub selectMaterialClassSubByClassSubId(String classSubId) + { + return materialClassSubMapper.selectMaterialClassSubByClassSubId(classSubId); + } + + /** + * 查询物资分类-二级分类列表 + * + * @param materialClassSub 物资分类-二级分类 + * @return 物资分类-二级分类 + */ + @Override + public List selectMaterialClassSubList(MaterialClassSub materialClassSub) + { + return materialClassSubMapper.selectMaterialClassSubList(materialClassSub); + } + + + private LambdaQueryWrapper buildQueryWrapper(MaterialClassSub query) { + Map params = query.getParams(); + LambdaQueryWrapper lqw = Wrappers.lambdaQuery(); + lqw.eq(StringUtils.isNotBlank(query.getClassMastId()), MaterialClassSub::getClassMastId, query.getClassMastId()); + lqw.like(StringUtils.isNotBlank(query.getClassNameSub()), MaterialClassSub::getClassNameSub, query.getClassNameSub()); + return lqw; + } + +} diff --git a/ruoyi-system/src/main/resources/mapper/ehs/EhsHiddenDangerMapper.xml b/ruoyi-system/src/main/resources/mapper/ehs/EhsHiddenDangerMapper.xml index 922f7cd..c023b25 100644 --- a/ruoyi-system/src/main/resources/mapper/ehs/EhsHiddenDangerMapper.xml +++ b/ruoyi-system/src/main/resources/mapper/ehs/EhsHiddenDangerMapper.xml @@ -23,6 +23,7 @@ + @@ -31,14 +32,14 @@ + - select h.*, d.dept_name, - (SELECT GROUP_CONCAT( ft.dept_name SEPARATOR ';' ) FROM - sys_dept ft where FIND_IN_SET( ft.DEPT_ID, h.assist_dept ))assist_dept_name - from ehs_hidden_danger h - left join sys_dept d on h.dept_id = d.dept_id + SELECT h.*, d.dept_name, DATEDIFF(h.rectify_term_time ,ifnull(h.rectify_time,CURDATE()) ) over_time, + ( SELECT GROUP_CONCAT( ft.dept_name SEPARATOR ';' ) FROM sys_dept ft WHERE FIND_IN_SET( ft.DEPT_ID, h.assist_dept ) ) assist_dept_name , + ( SELECT GROUP_CONCAT( dd.dict_label SEPARATOR ';' ) FROM (select * from sys_dict_data where dict_type = 'hidden_danger_label' ) dd WHERE FIND_IN_SET(dd.dict_value, h.hidden_danger_label ) ) hidden_danger_label_name +FROM ehs_hidden_danger h LEFT JOIN sys_dept d ON h.dept_id = d.dept_id - + update ehs_hidden_danger set is_supervise = 1 where hidden_danger_id in diff --git a/ruoyi-system/src/main/resources/mapper/ehs/EhsRiskMapper.xml b/ruoyi-system/src/main/resources/mapper/ehs/EhsRiskMapper.xml index 508a20e..86119c5 100644 --- a/ruoyi-system/src/main/resources/mapper/ehs/EhsRiskMapper.xml +++ b/ruoyi-system/src/main/resources/mapper/ehs/EhsRiskMapper.xml @@ -35,12 +35,14 @@ - select risk_id, risk_grade, report_address_type, risk_location, risk_desc, people_quantity, materials_addr, materials_quantity, life_addr, resettle_addr, village_name, village_duties, village_tel, village_name1, village_duties1, village_tel1, create_by, create_time, update_by, update_time, remark, dept_id, create_user_id, update_user_id, inspection_name, inspection_duties, inspection_tel from ehs_risk + select e.*, d.dept_name from ehs_risk e + left join sys_dept d on e.dept_id = d.dept_id + + + and class_mast_id = #{classMastId} + and class_mast_type = #{classMastType} + and class_name_mast = #{classNameMast} + and dept_id = #{deptId} + and create_user_id = #{createUserId} + and update_user_id = #{updateUserId} + + + + + + + + + \ No newline at end of file diff --git a/ruoyi-system/src/main/resources/mapper/ehs/MaterialClassSubMapper.xml b/ruoyi-system/src/main/resources/mapper/ehs/MaterialClassSubMapper.xml new file mode 100644 index 0000000..fe8dc7e --- /dev/null +++ b/ruoyi-system/src/main/resources/mapper/ehs/MaterialClassSubMapper.xml @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + + + + + + select class_sub_id, class_mast_id, class_name_sub from material_class_sub + + + + + + + + delete + from material_class_sub + where mast_id = #{classMastId} + + + + \ No newline at end of file diff --git a/ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml b/ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml index eca3694..7058c7f 100644 --- a/ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml +++ b/ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml @@ -57,7 +57,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" diff --git a/ruoyi-ui/src/api/ehs/materialClassMaster.js b/ruoyi-ui/src/api/ehs/materialClassMaster.js new file mode 100644 index 0000000..ae6ee81 --- /dev/null +++ b/ruoyi-ui/src/api/ehs/materialClassMaster.js @@ -0,0 +1,62 @@ +import request from '@/utils/request' + +// 查询物资分类一级分类列表 +export function listMaterialClass(query) { + return request({ + url: '/materialClass/materialClassMaster/list', + method: 'get', + params: query + }) +} + +// 查询物资分类一级分类详细 +export function getMaterialClass(classMastId) { + return request({ + url: '/materialClass/materialClassMaster/' + classMastId, + method: 'get' + }) +} + +// 新增物资分类一级分类 +export function addMaterialClass(data) { + return request({ + url: '/materialClass/materialClassMaster', + method: 'post', + data: data + }) +} + +// 修改物资分类一级分类 +export function updateMaterialClass(data) { + return request({ + url: '/materialClass/materialClassMaster', + method: 'put', + data: data + }) +} + +// 删除物资分类一级分类 +export function delMaterialClass(classMastId) { + return request({ + url: '/materialClass/materialClassMaster/' + classMastId, + method: 'delete' + }) +} + + +// 按大类获取json +export function getMaterialClassJson(typeId) { + return request({ + url: '/materialClass/materialClassMaster/getMaterialClassJson/' + typeId, + method: 'get' + }) +} + +// 根据json保存 +export function setMaterialClassJson(data) { + return request({ + url: '/materialClass/materialClassMaster/setMaterialClassJson' , + method: 'post', + params: data + }) +} diff --git a/ruoyi-ui/src/api/ehs/materialClassSub.js b/ruoyi-ui/src/api/ehs/materialClassSub.js new file mode 100644 index 0000000..6e7de24 --- /dev/null +++ b/ruoyi-ui/src/api/ehs/materialClassSub.js @@ -0,0 +1,44 @@ +import request from '@/utils/request' + +// 查询物资分类-二级分类列表 +export function listMaterialClass(query) { + return request({ + url: '/materialClass/materialClassSub/list', + method: 'get', + params: query + }) +} + +// 查询物资分类-二级分类详细 +export function getMaterialClass(classSubId) { + return request({ + url: '/materialClass/materialClassSub/' + classSubId, + method: 'get' + }) +} + +// 新增物资分类-二级分类 +export function addMaterialClass(data) { + return request({ + url: '/materialClass/materialClassSub', + method: 'post', + data: data + }) +} + +// 修改物资分类-二级分类 +export function updateMaterialClass(data) { + return request({ + url: '/materialClass/materialClassSub', + method: 'put', + data: data + }) +} + +// 删除物资分类-二级分类 +export function delMaterialClass(classSubId) { + return request({ + url: '/materialClass/materialClassSub/' + classSubId, + method: 'delete' + }) +} diff --git a/ruoyi-ui/src/assets/materialClass.json b/ruoyi-ui/src/assets/materialClass.json index a341b93..c23b2a5 100644 --- a/ruoyi-ui/src/assets/materialClass.json +++ b/ruoyi-ui/src/assets/materialClass.json @@ -25,6 +25,21 @@ }, { "value": "v1-8", "label": "救生绳" + }, { + "value": "v1-9", + "label": "爆闪警示灯" + }, { + "value": "v1-10", + "label": "防爆微型警示灯" + }, { + "value": "v1-11", + "label": "电锯" + }, { + "value": "v1-12", + "label": "免洗胶" + }, { + "value": "v1-13", + "label": "电动喷雾器" } ] }, @@ -61,6 +76,24 @@ }, { "value": "v2-10", "label": "呼吸器充填泵" + }, { + "value": "v2-11", + "label": "手摇报警器" + }, { + "value": "v2-12", + "label": "防护服" + }, { + "value": "v2-13", + "label": "头盔" + }, { + "value": "v2-15", + "label": "口罩" + }, { + "value": "v2-14", + "label": "酒精" + }, { + "value": "v2-16", + "label": "应急救援包" } ] }, @@ -82,6 +115,9 @@ }, { "value": "v3-5", "label": "卫星电话" + }, { + "value": "v3-6", + "label": "双模对讲机" } ] }, @@ -106,6 +142,30 @@ }, { "value": "v4-6", "label": "照明灯具" + }, { + "value": "v4-7", + "label": "水泵" + }, { + "value": "v4-8", + "label": "泵车" + }, { + "value": "v4-9", + "label": "自动升降照明灯" + }, { + "value": "v4-10", + "label": "智能应急物资管理柜" + }, { + "value": "v4-11", + "label": "车载搜救灯" + }, { + "value": "v4-12", + "label": "LED大功率灯" + }, { + "value": "v4-13", + "label": "高杆电灯" + }, { + "value": "v4-14", + "label": "发电车" } ] } diff --git a/ruoyi-ui/src/assets/materialClass2.json b/ruoyi-ui/src/assets/materialClass2.json index 0d34956..5f29ed0 100644 --- a/ruoyi-ui/src/assets/materialClass2.json +++ b/ruoyi-ui/src/assets/materialClass2.json @@ -16,6 +16,21 @@ }, { "value": "v1-5", "label": "无土沙袋" + }, { + "value": "v1-6", + "label": "组合式防护板" + }, { + "value": "v1-7", + "label": "子堤(组合式防护板)" + }, { + "value": "v1-8", + "label": "铁丝" + }, { + "value": "v1-9", + "label": "铁丝网" + }, { + "value": "v1-10", + "label": "电缆" } ] }, @@ -46,6 +61,12 @@ }, { "value": "v2-8", "label": "管涌探测仪" + }, { + "value": "v2-9", + "label": "打桩机" + }, { + "value": "v2-10", + "label": "抽水机" } ] }, @@ -79,6 +100,12 @@ }, { "value": "v3-9", "label": "潜水设备" + }, { + "value": "v3-10", + "label": "水面漂浮救生绳" + }, { + "value": "v3-11", + "label": "防汛套装应急包" } ] }, diff --git a/ruoyi-ui/src/assets/materialClass3.json b/ruoyi-ui/src/assets/materialClass3.json index f082a26..3147b83 100644 --- a/ruoyi-ui/src/assets/materialClass3.json +++ b/ruoyi-ui/src/assets/materialClass3.json @@ -124,6 +124,9 @@ }, { "value": "v4-17", "label": "手电" + }, { + "value": "v4-18", + "label": "风力灭火器" } ] }, diff --git a/ruoyi-ui/src/assets/materialClass4.json b/ruoyi-ui/src/assets/materialClass4.json index 63f8e7f..013b5ed 100644 --- a/ruoyi-ui/src/assets/materialClass4.json +++ b/ruoyi-ui/src/assets/materialClass4.json @@ -16,6 +16,24 @@ }, { "value": "v1-5", "label": "睡袋" + }, { + "value": "v1-6", + "label": "新帐篷" + }, { + "value": "v1-7", + "label": "旧帐篷" + }, { + "value": "v1-8", + "label": "新床" + }, { + "value": "v1-9", + "label": "旧床" + }, { + "value": "v1-10", + "label": "黑金刚(四脚帐篷)" + }, { + "value": "v1-11", + "label": "凳子" } ] }, { @@ -54,6 +72,9 @@ }, { "value": "v2-11", "label": "雨鞋" + }, { + "value": "v2-12", + "label": "被服包" } ] }, { @@ -89,6 +110,15 @@ }, { "value": "v3-10", "label": "救生圈" + }, { + "value": "v3-11", + "label": "电暖炉" + }, { + "value": "v3-12", + "label": "电油汀" + }, { + "value": "v3-13", + "label": "旧油汀" } ] }, { @@ -121,6 +151,9 @@ }, { "value": "v4-9", "label": "火腿肠" + }, { + "value": "v4-10", + "label": "中药饮品" } ] } diff --git a/ruoyi-ui/src/components/FileUploadNoFileType/index.vue b/ruoyi-ui/src/components/FileUploadNoFileType/index.vue deleted file mode 100644 index c7f6b0a..0000000 --- a/ruoyi-ui/src/components/FileUploadNoFileType/index.vue +++ /dev/null @@ -1,216 +0,0 @@ - - - - - diff --git a/ruoyi-ui/src/components/TopNav/index.vue b/ruoyi-ui/src/components/TopNav/index.vue index cbed273..daca9e2 100644 --- a/ruoyi-ui/src/components/TopNav/index.vue +++ b/ruoyi-ui/src/components/TopNav/index.vue @@ -124,6 +124,7 @@ export default { }, // 菜单选择事件 handleSelect(key, keyPath) { + console.log(key) this.currentIndex = key; const route = this.routers.find(item => item.path === key); if (this.ishttp(key)) { diff --git a/ruoyi-ui/src/settings.js b/ruoyi-ui/src/settings.js index 6a0b09f..fd24806 100644 --- a/ruoyi-ui/src/settings.js +++ b/ruoyi-ui/src/settings.js @@ -12,7 +12,7 @@ module.exports = { /** * 是否显示顶部导航 */ - topNav: false, + topNav: true, /** * 是否显示 tagsView diff --git a/ruoyi-ui/src/views/ehs/ehsEnterprise/index.vue b/ruoyi-ui/src/views/ehs/ehsEnterprise/index.vue index 829670a..efe1a47 100644 --- a/ruoyi-ui/src/views/ehs/ehsEnterprise/index.vue +++ b/ruoyi-ui/src/views/ehs/ehsEnterprise/index.vue @@ -11,14 +11,7 @@ /> - - - + + + + + diff --git a/ruoyi-ui/src/views/ehs/ehsExamples/index.vue b/ruoyi-ui/src/views/ehs/ehsExamples/index.vue index 73718ad..fdc6b13 100644 --- a/ruoyi-ui/src/views/ehs/ehsExamples/index.vue +++ b/ruoyi-ui/src/views/ehs/ehsExamples/index.vue @@ -132,9 +132,10 @@ border height="396" > + - + diff --git a/ruoyi-ui/src/views/ehs/ehsHiddenDanger/index.vue b/ruoyi-ui/src/views/ehs/ehsHiddenDanger/index.vue index 8ff5087..ae05430 100644 --- a/ruoyi-ui/src/views/ehs/ehsHiddenDanger/index.vue +++ b/ruoyi-ui/src/views/ehs/ehsHiddenDanger/index.vue @@ -12,10 +12,10 @@ /> - + @@ -40,6 +40,27 @@ /> + + + + + + + + + + + --> - - - - - - - + + + + + + + + + + 搜索 重置 @@ -164,7 +207,7 @@ v-hasPermi="['ehsHiddenDanger:ehsHiddenDanger:add']" >新增 - + 导出 + + 导入 + - + - - - + + + + + + + + + - - + - - - - - @@ -251,11 +306,32 @@ + + - - - - + - + @@ -554,10 +675,12 @@ import { listEhsHiddenDanger, getEhsHiddenDanger, delEhsHiddenDanger, addEhsHidd superviseEhsHiddenDanger,assistEhsHiddenDanger } from "@/api/ehs/ehsHiddenDanger"; import {listAllDept } from "@/api/system/dept"; import enterpriseSelect from "./enterpriseSelect" +import importUpload from "@/components/upload/upload"; export default { name: "EhsHiddenDanger", - dicts: ['hidden_danger_type', 'hidden_danger_grade', 'hidden_danger_label', 'enterprise_type','enterprise_scale','economic_type','area_id', "hidden_danger_status"], - components:{ enterpriseSelect }, + dicts: ['hidden_danger_type', 'hidden_danger_grade', 'hidden_danger_label', 'enterprise_type','enterprise_scale', + 'economic_type','area_id', "hidden_danger_status","check_type", "ehs_yes_no"], + components:{ importUpload,enterpriseSelect }, data() { return { // 遮罩层 @@ -578,6 +701,7 @@ export default { title: "", // 是否显示弹出层 open: false, + isReadOnly:false,//form表单是否可以编辑,新增、修改可以编辑、明细是只读 //是否显示部门列表查询条件 deptShow: false, //所有部门列表字典 @@ -620,18 +744,33 @@ export default { hiddenDangerType: null, hiddenDangerLabel: null, hiddenDangerLabelArray:null, + isTowns:null, + overTime:null }, + alertState: [{ + value: '7', + label: '7天预警' + }, { + value: '3', + label: '3天预警' + }, { + value: '0', + label: '逾期告警' + }], // 表单参数 form: {}, formAssist:{}, // 表单校验 rules: { - enterpriseName: [ { type: 'string',required: true,message: "隐患所在单位必填", trigger: 'blur'}], + enterpriseName: [ { type: 'string',required: true,message: "单位名称必填", trigger: 'blur'}], enterpriseType: [ { type: 'string',required: true,message: "行业必须选择", trigger: 'blur'}], enterpriseStatus: [ { type: 'string',required: true,message: "企业现状必须选择", trigger: 'blur'}], hiddenDangerDesc: [ { type: 'string',required: true,message: "隐患情况必填", trigger: 'blur'}], checkTime: [ { required: true,message: "排查时间必填", trigger: 'blur'}], rectifyTermTime: [ { required: true,message: "整改期限必填", trigger: 'blur'}], + checkType: [ { required: true,message: "排查方式必须选择", trigger: 'blur'}], + /* isTowns: [ { required: true,message: "是否乡镇(街道必须选择", trigger: 'blur'}],*/ + status: [ { required: true,message: "整改进度必须选择", trigger: 'blur'}], /*rectifyMeasure: [ { type: 'string',required: true,message: "整改措施必填", trigger: 'blur'}], rectifyTime: [ { type: 'date',required: true,message: "整改时间必填", trigger: 'blur'}], hiddenDangerGrade: [ { type: 'string',required: true,message: "隐患级别必填", trigger: 'blur'}], @@ -644,12 +783,12 @@ export default { areaId: [ { required: true, message: "不能为空", trigger: "change" } ], - economicType: [ +/* economicType: [ { required: true, message: "不能为空", trigger: "change" } - ], - enterpriseScale: [ + ],*/ + /* enterpriseScale: [ { required: true, message: "不能为空", trigger: "change" } - ], + ],*/ }, pickerOptions: { shortcuts: [{ @@ -744,6 +883,8 @@ export default { areaId:null, economicType:null, enterpriseScale:null, + isTowns:null, + }; this.resetForm("form"); }, @@ -769,11 +910,13 @@ export default { handleAdd() { this.reset(); this.open = true; + this.isReadOnly = false; this.title = "添加隐患信息"; }, /** 修改按钮操作 */ - handleUpdate(row) { + handleUpdate(row,isReadOnly) { this.reset(); + this.isReadOnly = isReadOnly; const hiddenDangerId = row.hiddenDangerId || this.ids getEhsHiddenDanger(hiddenDangerId).then(response => { this.form = response.data; @@ -784,6 +927,7 @@ export default { this.title = "修改隐患信息"; }); }, + /** 提交按钮 */ submitForm() { this.$refs["form"].validate(valid => { @@ -810,7 +954,7 @@ export default { /** 删除按钮操作 */ handleDelete(row) { const hiddenDangerIds = row.hiddenDangerId || this.ids; - this.$modal.confirm('是否确认删除隐患信息编号为"' + hiddenDangerIds + '"的数据项?').then(function() { + this.$modal.confirm('是否确认删除选中的隐患的数据项?').then(function() { return delEhsHiddenDanger(hiddenDangerIds); }).then(() => { this.getList(); @@ -821,7 +965,7 @@ export default { handleExport() { this.download('ehsHiddenDanger/ehsHiddenDanger/export', { ...this.queryParams - }, `ehsHiddenDanger_${new Date().getTime()}.xlsx`) + }, `风险信息_${new Date().getTime()}.xls`) }, openEnterprise() { @@ -911,13 +1055,50 @@ export default { this.$alert(row.superviseResult, '督办反馈', { confirmButtonText: '确定', callback: action => { - this.$message({ + /*this.$message({ type: 'info', message: `action: ${ action }` - }); + });*/ } }); }, + /** 批量导入 */ + handleImport() { + console.log(this.$refs.uploadRef.upload); + this.$refs.uploadRef.upload.open = true; + this.$refs.uploadRef.upload.title = "应急救援队伍导入"; + this.$refs.uploadRef.upload.url = + process.env.VUE_APP_BASE_API + "/ehsHiddenDanger/ehsHiddenDanger/importData"; + }, + /** 导入成功 */ + upLoadOk() { + // console.log("导入成功") + this.getList(); + }, + tableRowClassName({row, rowIndex}) { + if(row.status==0 ||status==5){ + if (row.overTime <0 ) { + return 'warning-row'; + } else if (row.overTime > 3 && row.overTime <= 7) { + return 'warning7-row'; + } else if (row.overTime > 0 && rowIndex <= 3) { + return 'warning3-row'; + } + } + return ''; + }, } }; + diff --git a/ruoyi-ui/src/views/ehs/ehsHiddenDanger/indexAssist.vue b/ruoyi-ui/src/views/ehs/ehsHiddenDanger/indexAssist.vue index 3789955..2ad056f 100644 --- a/ruoyi-ui/src/views/ehs/ehsHiddenDanger/indexAssist.vue +++ b/ruoyi-ui/src/views/ehs/ehsHiddenDanger/indexAssist.vue @@ -12,10 +12,10 @@ /> - + @@ -122,7 +122,7 @@ - + diff --git a/ruoyi-ui/src/views/ehs/materialClass/indexSub.vue b/ruoyi-ui/src/views/ehs/materialClass/indexSub.vue new file mode 100644 index 0000000..d51aca0 --- /dev/null +++ b/ruoyi-ui/src/views/ehs/materialClass/indexSub.vue @@ -0,0 +1,259 @@ + + + diff --git a/ruoyi-ui/src/views/index.vue b/ruoyi-ui/src/views/index.vue index 44c3d94..a8cc5e4 100644 --- a/ruoyi-ui/src/views/index.vue +++ b/ruoyi-ui/src/views/index.vue @@ -257,6 +257,12 @@ }, created() { this.getIndexDetails(); + this.$alert('这是一段内容', '标题名称', { + confirmButtonText: '确定', + callback: action => { + //this.$router.push({ path: "ehs/ehsHiddenDanger/index" }); + } + }); }, methods: { parseTime, diff --git a/ruoyi-ui/src/views/login.vue b/ruoyi-ui/src/views/login.vue index 78445ec..d99f3e9 100644 --- a/ruoyi-ui/src/views/login.vue +++ b/ruoyi-ui/src/views/login.vue @@ -5,8 +5,8 @@
-

中华人民共和国应急管理部

-

Ministry of Emergency Management of the People's Republic of China

+

唐河县应急管理平台

+

对党忠诚 纪律严明

@@ -15,16 +15,16 @@
{{ currentTime }} - -

{{ currentDayOfWeek }}

-

{{ currentDate }}

+ +

{{ currentDayOfWeek }}

+

{{ currentDate }}

- + \ No newline at end of file +