package cn.besteam.modules.medical.controller;
|
|
import java.io.IOException;
|
import java.math.RoundingMode;
|
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.constant.CommonConstant;
|
import cn.besteam.common.constant.MedicalWasteEnum;
|
import cn.besteam.common.util.DateUtil;
|
import cn.besteam.modules.medical.dto.MwCollectRecordOpsDTO;
|
import cn.besteam.modules.medical.vo.MwCollectRecordVO;
|
import cn.besteam.modules.medical.vo.MwCollectionAmendantRecordVO;
|
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.common.util.oConvertUtils;
|
import cn.besteam.modules.medical.entity.MwCollectionAmendantRecord;
|
import cn.besteam.modules.medical.service.IMwCollectionAmendantRecordService;
|
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.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import lombok.extern.slf4j.Slf4j;
|
|
/**
|
* @Title: Controller
|
* @Description: 医废修改记录
|
* @author: besteam
|
* @date: 2022-02-14
|
* @version: V1.0
|
*/
|
@RestController
|
@RequestMapping("/medical/mwCollectionAmendantRecord")
|
@Slf4j
|
@Api(description = "医废修改记录")
|
public class MwCollectionAmendantRecordController {
|
|
@Autowired
|
private IMwCollectionAmendantRecordService mwCollectionAmendantRecordService;
|
|
/**
|
* 分页列表查询
|
* @param mwCollectionAmendantRecord
|
* @param pageNo
|
* @param pageSize
|
* @param req
|
* @return
|
*/
|
@GetMapping(value = "/list")
|
@ApiOperation(value = "获取医废修改记录数据列表", notes = "获取所有医废修改记录数据列表", produces = "application/json")
|
public Result<IPage<MwCollectionAmendantRecord>> queryPageList(MwCollectionAmendantRecord mwCollectionAmendantRecord, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, HttpServletRequest req) {
|
|
Result<IPage<MwCollectionAmendantRecord>> result = new Result<IPage<MwCollectionAmendantRecord>>();
|
QueryWrapper<MwCollectionAmendantRecord> queryWrapper = new QueryWrapper<MwCollectionAmendantRecord>(mwCollectionAmendantRecord);
|
Page<MwCollectionAmendantRecord> page = new Page<MwCollectionAmendantRecord>(pageNo, pageSize);
|
//排序逻辑 处理
|
String column = req.getParameter("column");
|
String order = req.getParameter("order");
|
if(oConvertUtils.isNotEmpty(column) && oConvertUtils.isNotEmpty(order)) {
|
if("asc".equals(order)) {
|
queryWrapper.orderByAsc(oConvertUtils.camelToUnderline(column));
|
}else {
|
queryWrapper.orderByDesc(oConvertUtils.camelToUnderline(column));
|
}
|
}else{
|
queryWrapper.orderByAsc("create_time");
|
}
|
IPage<MwCollectionAmendantRecord> pageList = mwCollectionAmendantRecordService.page(page, queryWrapper);
|
//log.debug("查询当前页:"+pageList.getCurrent());
|
//log.debug("查询当前页数量:"+pageList.getSize());
|
//log.debug("查询结果数量:"+pageList.getRecords().size());
|
//log.debug("数据总数:"+pageList.getTotal());
|
result.setSuccess(true);
|
result.setResult(pageList);
|
return result;
|
}
|
|
/**
|
* 添加
|
* @param mwCollectionAmendantRecord
|
* @return
|
*/
|
@PostMapping(value = "/add")
|
@AutoLog(value = "添加医废修改记录")
|
@ApiOperation(value = "添加医废修改记录", notes = "添加医废修改记录", produces = "application/json")
|
public Result<MwCollectionAmendantRecord> add(@RequestBody MwCollectionAmendantRecord mwCollectionAmendantRecord) {
|
|
Result<MwCollectionAmendantRecord> result = new Result<MwCollectionAmendantRecord>();
|
try {
|
mwCollectionAmendantRecordService.save(mwCollectionAmendantRecord);
|
result.success("添加成功!");
|
} catch (Exception e) {
|
log.error("", e);
|
result.error500("操作失败");
|
}
|
return result;
|
}
|
|
/**
|
* 编辑
|
* @param mwCollectionAmendantRecord
|
* @return
|
*/
|
@PostMapping(value = "/edit")
|
@AutoLog(value = "编辑医废修改记录")
|
@ApiOperation(value = "编辑医废修改记录", notes = "编辑医废修改记录", produces = "application/json")
|
public Result<MwCollectionAmendantRecord> edit(@RequestBody MwCollectionAmendantRecord mwCollectionAmendantRecord) {
|
|
Result<MwCollectionAmendantRecord> result = new Result<MwCollectionAmendantRecord>();
|
MwCollectionAmendantRecord mwCollectionAmendantRecordEntity = mwCollectionAmendantRecordService.getById(mwCollectionAmendantRecord.getId());
|
if(mwCollectionAmendantRecordEntity==null) {
|
result.error500("未找到对应实体");
|
}else {
|
boolean ok = mwCollectionAmendantRecordService.updateById(mwCollectionAmendantRecord);
|
//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<MwCollectionAmendantRecord> delete(@RequestParam(name="id",required=true) String id) {
|
|
Result<MwCollectionAmendantRecord> result = new Result<MwCollectionAmendantRecord>();
|
MwCollectionAmendantRecord mwCollectionAmendantRecord = mwCollectionAmendantRecordService.getById(id);
|
if(mwCollectionAmendantRecord==null) {
|
result.error500("未找到对应实体");
|
}else {
|
boolean ok = mwCollectionAmendantRecordService.removeById(id);
|
if(ok) {
|
result.success("删除成功!");
|
}
|
}
|
|
return result;
|
}
|
|
/**
|
* 批量删除
|
* @param ids
|
* @return
|
*/
|
@PostMapping(value = "/deleteBatch")
|
@AutoLog(value = "批量删除医废修改记录")
|
@ApiOperation(value = "批量删除医废修改记录", notes = "批量删除医废修改记录", produces = "application/json")
|
public Result<MwCollectionAmendantRecord> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
|
|
Result<MwCollectionAmendantRecord> result = new Result<MwCollectionAmendantRecord>();
|
if(ids==null || "".equals(ids.trim())) {
|
result.error500("参数不识别!");
|
}else {
|
this.mwCollectionAmendantRecordService.removeByIds(Arrays.asList(ids.split(",")));
|
result.success("删除成功!");
|
}
|
return result;
|
}
|
|
/**
|
* 通过id查询
|
* @param id
|
* @return
|
*/
|
@GetMapping(value = "/queryById")
|
@ApiOperation(value = "通过id查询医废修改记录", notes = "通过id查询医废修改记录", produces = "application/json")
|
public Result<MwCollectionAmendantRecord> queryById(@RequestParam(name="id",required=true) String id) {
|
|
Result<MwCollectionAmendantRecord> result = new Result<MwCollectionAmendantRecord>();
|
MwCollectionAmendantRecord mwCollectionAmendantRecord = mwCollectionAmendantRecordService.getById(id);
|
if(mwCollectionAmendantRecord==null) {
|
result.error500("未找到对应实体");
|
}else {
|
result.setResult(mwCollectionAmendantRecord);
|
result.setSuccess(true);
|
}
|
return result;
|
}
|
|
|
@GetMapping(value = "/listHistory")
|
@ApiOperation(value = "医废修改记录列表", notes = "医废修改记录列表", produces = "application/json")
|
public Result<IPage<MwCollectionAmendantRecordVO>> listHistory(MwCollectRecordOpsDTO dto, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
|
|
dto.setAuditStatus(MedicalWasteEnum.MedicalWasteAuditStatusEnum.PASS.getStatus());
|
dto.setDelFlag(CommonConstant.DEL_FLAG_0);
|
//
|
IPage<MwCollectionAmendantRecordVO> pageList = mwCollectionAmendantRecordService.queryPageCollectList(pageNo, pageSize, dto);
|
return Result.ok(pageList);
|
}
|
|
/*=====医废追溯导出--开始=======*/
|
private static Map<String, String> headerMapListHistory = new LinkedHashMap<>();
|
|
static {
|
headerMapListHistory.put("createTime", "收集时间");
|
headerMapListHistory.put("code", "废物编号");
|
headerMapListHistory.put("hospitalName", "医院名称");
|
headerMapListHistory.put("departmentName", "科室名称");
|
/*headerMapListHistory.put("wasteTypeStr", "废物类型");
|
headerMapListHistory.put("weight", "重量(kg)");*/
|
headerMapListHistory.put("departmentUserName", "科室人员");
|
headerMapListHistory.put("creator", "收集人员");
|
headerMapListHistory.put("statusName", "状态");
|
headerMapListHistory.put("typeName", "修改内容");
|
headerMapListHistory.put("contentBefore", "修改前");
|
headerMapListHistory.put("contentAfter", "修改后");
|
}
|
|
@Data
|
private static class MwCollectRecordExportListHistoryVO {
|
|
private String createTime="";
|
|
private String code="";
|
|
private String hospitalName="";
|
|
private String departmentName="";
|
|
/*private String wasteTypeStr="";
|
|
private String weight="";*/
|
|
private String departmentUserName="";
|
|
private String creator="";
|
|
private String statusName="";
|
private String typeName="";
|
private String contentBefore="";
|
private String contentAfter="";
|
|
}
|
|
@GetMapping("/listHistoryExport")
|
@OpenApi
|
@ApiOperation(value = "医废修改导出", notes = "医废修改导出", produces = "application/json")
|
public void listHistoryExport(HttpServletResponse response, MwCollectRecordOpsDTO dto) throws IOException {
|
dto.setAuditStatus(MedicalWasteEnum.MedicalWasteAuditStatusEnum.PASS.getStatus());
|
dto.setDelFlag(CommonConstant.DEL_FLAG_0);
|
List<MwCollectionAmendantRecordVO> list=mwCollectionAmendantRecordService.queryPageCollectList( dto);
|
List<MwCollectionAmendantRecordController.MwCollectRecordExportListHistoryVO> voList = new ArrayList<>();
|
for (MwCollectionAmendantRecordVO collectRecordVO : list) {
|
MwCollectionAmendantRecordController.MwCollectRecordExportListHistoryVO vo=new MwCollectionAmendantRecordController.MwCollectRecordExportListHistoryVO();
|
BeanUtils.copyProperties(collectRecordVO, vo);
|
vo.setCreateTime(DateUtil.formatTime(collectRecordVO.getCreateTime(), "yyyy-MM-dd HH:mm:ss"));
|
//状态1新增 2已入库 3已出库
|
if (collectRecordVO.getStatus().equals(1)) {
|
vo.setStatusName("未入库");
|
} else if (collectRecordVO.getStatus().equals(2)) {
|
vo.setStatusName("已入库");
|
} else if (collectRecordVO.getStatus().equals(3)) {
|
vo.setStatusName("已出库");
|
}
|
if(collectRecordVO.getType().equals(1)){
|
vo.setTypeName("修改废物类型");
|
} else if (collectRecordVO.getType().equals(2)) {
|
vo.setTypeName("修改重量");
|
} else if (collectRecordVO.getType().equals(3)) {
|
vo.setTypeName("删除数据");
|
}
|
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.setColumnWidth(7, 30);
|
writer.setColumnWidth(8, 30);
|
writer.setColumnWidth(9, 30);
|
writer.setHeaderAlias(headerMapListHistory);
|
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();
|
|
}
|
|
}
|