package cn.besteam.modules.medical.controller; import java.io.IOException; import java.net.URLEncoder; import java.util.*; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import cn.besteam.common.aspect.annotation.OpenApi; import cn.besteam.common.util.DateUtil; import cn.besteam.modules.medical.dto.MwBusinessApprovalDTO; import cn.besteam.modules.medical.dto.MwBusinessApprovalHandleDTO; import cn.besteam.modules.medical.service.IMwBusinessApprovalHandleService; import cn.besteam.modules.medical.vo.MwBusinessApprovalHandleVO; import cn.besteam.modules.medical.vo.MwBusinessApprovalVO; import cn.hutool.poi.excel.ExcelUtil; import cn.hutool.poi.excel.ExcelWriter; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import cn.besteam.common.api.vo.Result; import cn.besteam.common.aspect.annotation.AutoLog; import cn.besteam.modules.medical.entity.MwBusinessApproval; import cn.besteam.modules.medical.service.IMwBusinessApprovalService; import lombok.Data; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import com.baomidou.mybatisplus.core.metadata.IPage; import lombok.extern.slf4j.Slf4j; /** * @Title: Controller * @Description: 审批记录 * @author: besteam * @date: 2022-02-09 * @version: V1.0 */ @RestController @RequestMapping("/medical/mwBusinessApproval") @Slf4j @Api(description = "审批记录") public class MwBusinessApprovalController { @Autowired private IMwBusinessApprovalService mwBusinessApprovalService; @Autowired private IMwBusinessApprovalHandleService mwBusinessApprovalHandleService; /** * 分页列表查询 * @param mwBusinessApprovalDTO * @param pageNo * @param pageSize * @param req * @return */ @GetMapping(value = "/list") @ApiOperation(value = "获取审批记录数据列表", notes = "获取所有审批记录数据列表", produces = "application/json") public Result> queryPageList(MwBusinessApprovalDTO mwBusinessApprovalDTO, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, HttpServletRequest req) { IPage result=mwBusinessApprovalService.queryPageList(pageNo, pageSize,mwBusinessApprovalDTO); return Result.ok(result); } /** * 立即审核 * @param dto * @return */ @PostMapping(value = "/audit") @AutoLog(value = "审批记录-审核") @ApiOperation(value = "审批记录-审核", notes = "审批记录-审核", produces = "application/json") public Result audit(@RequestBody MwBusinessApprovalHandleDTO dto) { return Result.ok(mwBusinessApprovalHandleService.businessApprovalHandle(dto)); } /** * 通过id查询审批记处理记录数据 * @param approvalId * @return */ @GetMapping(value = "/queryHandleList") @ApiOperation(value = "通过id查询审批记处理记录数据", notes = "通过id查询审批记处理记录数据", produces = "application/json") public Result> queryHandleList(@RequestParam(name="id",required=true) Integer approvalId) { List list = mwBusinessApprovalHandleService.getBusinessApprovalHandleList(approvalId); return Result.ok(list); } /*=====医废追溯导出--开始=======*/ private static Map headerMapList = new LinkedHashMap<>(); static { //申请机构、申请时间、申请人、联系电话、申请内容、申请说明、审批状态 headerMapList.put("hospitalName", "申请机构"); headerMapList.put("createTime", "申请时间"); headerMapList.put("userName", "申请人"); headerMapList.put("userPhone", "联系电话"); headerMapList.put("applyContent", "申请内容"); headerMapList.put("applyMark", "申请说明"); headerMapList.put("status", "审批状态"); } @Data private static class MwCollectionExportListVO { private String hospitalName=""; private String createTime=""; private String userName=""; private String userPhone=""; private String applyContent=""; private String applyMark=""; private String status=""; } @GetMapping("/listExport") @OpenApi @ApiOperation(value = "审批数据导出", notes = "审批数据导出", produces = "application/json") public void listExport(HttpServletResponse response, MwBusinessApprovalDTO dto) throws IOException { List list=mwBusinessApprovalService.queryPageList( dto); List voList = new ArrayList<>(); for (MwBusinessApprovalVO businessApprovalVO : list) { MwCollectionExportListVO vo=new MwCollectionExportListVO(); BeanUtils.copyProperties(businessApprovalVO, vo); //性质(1=院内站点,2=院外站点) if (businessApprovalVO.getStatus().equals(0)) { vo.setStatus("未审批"); } else if (businessApprovalVO.getStatus().equals(1)) { vo.setStatus("通过"); }else if (businessApprovalVO.getStatus().equals(2)) { vo.setStatus("未通过"); } vo.setCreateTime(DateUtil.formatTime(businessApprovalVO.getCreateTime(), "yyyy-MM-dd HH:mm:ss")); voList.add(vo); } ExcelWriter writer = ExcelUtil.getWriter(true); writer.renameSheet("审批数据信息"); writer.setColumnWidth(0, 30); writer.setColumnWidth(1, 30); writer.setColumnWidth(2, 30); writer.setColumnWidth(3, 30); writer.setColumnWidth(4, 30); writer.setColumnWidth(5, 30); writer.setColumnWidth(6, 30); writer.setHeaderAlias(headerMapList); writer.write(voList); // String fileName = "审批数据信息"; response.setContentType("application/octet-stream;charset=utf-8"); response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8") + ".xlsx"); //response.setContentType("application/octet-stream"); // 响应内容格式 writer.flush(response.getOutputStream()); writer.close(); } /** * 添加 * @param mwBusinessApproval * @return */ @PostMapping(value = "/add") @AutoLog(value = "添加审批记录") @ApiOperation(value = "添加审批记录", notes = "添加审批记录", produces = "application/json") public Result add(@RequestBody MwBusinessApproval mwBusinessApproval) { Result result = new Result(); try { mwBusinessApprovalService.save(mwBusinessApproval); result.success("添加成功!"); } catch (Exception e) { log.error("", e); result.error500("操作失败"); } return result; } /** * 编辑 * @param mwBusinessApproval * @return */ @PostMapping(value = "/edit") @AutoLog(value = "编辑审批记录") @ApiOperation(value = "编辑审批记录", notes = "编辑审批记录", produces = "application/json") public Result edit(@RequestBody MwBusinessApproval mwBusinessApproval) { Result result = new Result(); MwBusinessApproval mwBusinessApprovalEntity = mwBusinessApprovalService.getById(mwBusinessApproval.getId()); if(mwBusinessApprovalEntity==null) { result.error500("未找到对应实体"); }else { boolean ok = mwBusinessApprovalService.updateById(mwBusinessApproval); //TODO 返回false说明什么? if(ok) { result.success("修改成功!"); } } return result; } /** * 通过id删除 * @param id * @return */ @PostMapping(value = "/delete") @AutoLog(value = "删除审批记录") @ApiOperation(value = "删除审批记录", notes = "删除审批记录", produces = "application/json") public Result delete(@RequestParam(name="id",required=true) String id) { Result result = new Result(); MwBusinessApproval mwBusinessApproval = mwBusinessApprovalService.getById(id); if(mwBusinessApproval==null) { result.error500("未找到对应实体"); }else { boolean ok = mwBusinessApprovalService.removeById(id); if(ok) { result.success("删除成功!"); } } return result; } /** * 批量删除 * @param ids * @return */ @PostMapping(value = "/deleteBatch") @AutoLog(value = "批量删除审批记录") @ApiOperation(value = "批量删除审批记录", notes = "批量删除审批记录", produces = "application/json") public Result deleteBatch(@RequestParam(name="ids",required=true) String ids) { Result result = new Result(); if(ids==null || "".equals(ids.trim())) { result.error500("参数不识别!"); }else { this.mwBusinessApprovalService.removeByIds(Arrays.asList(ids.split(","))); result.success("删除成功!"); } return result; } }