package com.ruoyi.project.dc.accidentInformation.controller; import com.alibaba.fastjson.JSON; import com.ruoyi.common.constant.DualControlConstants; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.poi.ExcelUtil; import com.ruoyi.framework.aspectj.lang.annotation.Log; import com.ruoyi.framework.aspectj.lang.enums.BusinessType; import com.ruoyi.framework.config.RuoYiConfig; import com.ruoyi.framework.web.controller.BaseController; import com.ruoyi.framework.web.domain.AjaxResult; import com.ruoyi.framework.web.page.TableDataInfo; import com.ruoyi.project.dc.accidentInformation.domain.AccidentInformation; import com.ruoyi.project.dc.accidentInformation.service.IAccidentInformationService; import com.ruoyi.project.enumerate.DcAttachmentTypeEnum; import com.ruoyi.project.system.attachment.domain.Attachment; import com.ruoyi.project.system.attachment.service.IAttachmentService; import com.ruoyi.project.system.user.domain.User; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.*; import java.util.Date; import java.util.List; /** * 事故信息Controller * * @author wm * @date 2020-12-07 */ @Controller @RequestMapping("/dc/accidentInformation") public class AccidentInformationController extends BaseController { private String prefix = "dc/accidentInformation"; @Autowired private IAccidentInformationService accidentInformationService; @Autowired private IAttachmentService attachmentService; @RequiresPermissions("dc:accidentInformation:view") @GetMapping() public String accidentInformation() { return prefix + "/accidentInformation"; } /** * 查询事故信息列表 */ @RequiresPermissions("dc:accidentInformation:list") @PostMapping("/list") @ResponseBody public TableDataInfo list(AccidentInformation accidentInformation) { startPage(); User user = getSysUser(); accidentInformation.setCompanyId(user.getCompanyId()); List list = accidentInformationService.selectAccidentInformationList(accidentInformation); return getDataTable(list); } /** * 导出事故信息列表 */ @RequiresPermissions("dc:accidentInformation:export") @Log(title = "事故信息", businessType = BusinessType.EXPORT) @PostMapping("/export") @ResponseBody public AjaxResult export(AccidentInformation accidentInformation) { User user = getSysUser(); accidentInformation.setCompanyId(user.getCompanyId()); List list = accidentInformationService.selectAccidentInformationList(accidentInformation); ExcelUtil util = new ExcelUtil(AccidentInformation.class); return util.exportExcel(list, "accidentInformation"); } /** * 新增事故信息 */ @GetMapping("/add") public String add() { return prefix + "/add"; } /** * 新增保存事故信息 */ @RequiresPermissions("dc:accidentInformation:add") @Log(title = "事故信息", businessType = BusinessType.INSERT) @PostMapping("/add") @ResponseBody public AjaxResult addSave(AccidentInformation accidentInformation) { User user = getSysUser(); accidentInformation.setCompanyId(user.getCompanyId()); int addNum = accidentInformationService.insertAccidentInformation(accidentInformation); //处理新增的附件 String ownedFile = accidentInformation.getAccidentOwnedFile(); if(StringUtils.isNotEmpty(ownedFile)&&addNum>0) { List attachmentList = JSON.parseArray(ownedFile, Attachment.class); if (attachmentList.size() > 0) { for (Attachment attachment : attachmentList) { attachment.setFileJoinId(accidentInformation.getAccidentId()); attachment.setAttachmentType(DcAttachmentTypeEnum.Third_Party_Testing.getType()); attachment.setCompanyId(user.getCompanyId()); attachment.setCreateBy(user.getUserName()); attachment.setCreateUserId(user.getUserId()); attachment.setCreateTime(new Date()); attachmentService.insertAttachment(attachment); } } } return toAjax(addNum); } /** * 修改事故信息 */ @GetMapping("/edit/{accidentId}") public String edit(@PathVariable("accidentId") Long accidentId, ModelMap mmap) { AccidentInformation accidentInformation = accidentInformationService.selectAccidentInformationById(accidentId); mmap.put("accidentInformation", accidentInformation); Attachment attachment = new Attachment(); attachment.setFileJoinId(accidentId); attachment.setAttachmentType(DcAttachmentTypeEnum.Third_Party_Testing.getType()); List attachmentList = attachmentService.selectAttachmentList(attachment); mmap.put("fileList",attachmentList); mmap.put("serviceDomainName", DualControlConstants.SERVICE_DOMAIN_NAME); return prefix + "/edit"; } /** * 事故信息详情 */ @GetMapping("/detail/{accidentId}") public String detail(@PathVariable("accidentId") Long accidentId, ModelMap mmap) { AccidentInformation accidentInformation = accidentInformationService.selectAccidentInformationById(accidentId); mmap.put("accidentInformation", accidentInformation); Attachment attachment = new Attachment(); attachment.setFileJoinId(accidentId); attachment.setAttachmentType(DcAttachmentTypeEnum.Third_Party_Testing.getType()); List attachmentList = attachmentService.selectAttachmentList(attachment); mmap.put("fileList",attachmentList); mmap.put("serviceDomainName", DualControlConstants.SERVICE_DOMAIN_NAME); return prefix + "/edit"; } /** * 修改保存事故信息 */ @RequiresPermissions("dc:accidentInformation:edit") @Log(title = "事故信息", businessType = BusinessType.UPDATE) @PostMapping("/edit") @ResponseBody public AjaxResult editSave(AccidentInformation accidentInformation) { User user = getSysUser(); accidentInformation.setCompanyId(user.getCompanyId()); int updateNum = accidentInformationService.updateAccidentInformation(accidentInformation); //处理新增的附件 String ownedFile = accidentInformation.getAccidentOwnedFile(); if(StringUtils.isNotEmpty(ownedFile)&&updateNum>0) { List attachmentList = JSON.parseArray(ownedFile, Attachment.class); if (attachmentList.size() > 0) { for (Attachment attachment : attachmentList) { attachment.setFileJoinId(accidentInformation.getAccidentId()); attachment.setAttachmentType(DcAttachmentTypeEnum.Third_Party_Testing.getType()); attachment.setCompanyId(user.getCompanyId()); attachment.setCreateBy(user.getUserName()); attachment.setCreateUserId(user.getUserId()); attachment.setCreateTime(new Date()); attachmentService.insertAttachment(attachment); } } } return toAjax(updateNum); } /** * 删除事故信息 */ @RequiresPermissions("dc:accidentInformation:remove") @Log(title = "事故信息", businessType = BusinessType.DELETE) @PostMapping( "/remove") @ResponseBody public AjaxResult remove(String ids) { return toAjax(accidentInformationService.deleteAccidentInformationByIds(ids)); } }