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.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.MwDetectionIndex;
|
import cn.besteam.modules.medical.service.IMwDetectionIndexService;
|
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-09-02
|
* @version: V1.0
|
*/
|
@RestController
|
@RequestMapping("/medical/mwDetectionIndex")
|
@Slf4j
|
@Api(description = "检测指标")
|
public class MwDetectionIndexController {
|
|
@Autowired
|
private IMwDetectionIndexService mwDetectionIndexService;
|
|
/**
|
* 分页列表查询
|
* @param mwDetectionIndex
|
* @param pageNo
|
* @param pageSize
|
* @param req
|
* @return
|
*/
|
@GetMapping(value = "/list")
|
@ApiOperation(value = "获取检测指标数据列表", notes = "获取所有检测指标数据列表", produces = "application/json")
|
public Result<IPage<MwDetectionIndex>> queryPageList(MwDetectionIndex mwDetectionIndex, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, HttpServletRequest req) {
|
|
Result<IPage<MwDetectionIndex>> result = new Result<IPage<MwDetectionIndex>>();
|
QueryWrapper<MwDetectionIndex> queryWrapper = new QueryWrapper<MwDetectionIndex>();
|
Page<MwDetectionIndex> page = new Page<MwDetectionIndex>(pageNo, pageSize);
|
//排序逻辑 处理
|
String column = req.getParameter("column");
|
String order = req.getParameter("order");
|
queryWrapper.eq("del_flag",CommonConstant.DEL_FLAG_0);
|
if(oConvertUtils.isNotEmpty(column) && oConvertUtils.isNotEmpty(order)) {
|
if("asc".equals(order)) {
|
queryWrapper.orderByAsc(oConvertUtils.camelToUnderline(column));
|
}else {
|
queryWrapper.orderByDesc(oConvertUtils.camelToUnderline(column));
|
}
|
}
|
if(oConvertUtils.isNotEmpty(mwDetectionIndex.getName()) ){
|
queryWrapper.like("name",mwDetectionIndex.getName());
|
}
|
if(oConvertUtils.isNotEmpty(mwDetectionIndex.getCode()) ){
|
queryWrapper.like("code",mwDetectionIndex.getCode());
|
}
|
if(oConvertUtils.isNotEmpty(mwDetectionIndex.getConcentrationUnit()) ){
|
queryWrapper.like("concentration_unit",mwDetectionIndex.getConcentrationUnit());
|
}
|
IPage<MwDetectionIndex> pageList = mwDetectionIndexService.page(page, queryWrapper);
|
result.setSuccess(true);
|
result.setResult(pageList);
|
return result;
|
}
|
|
/**
|
* 添加
|
* @param mwDetectionIndex
|
* @return
|
*/
|
@PostMapping(value = "/add")
|
@AutoLog(value = "添加检测指标")
|
@ApiOperation(value = "添加检测指标", notes = "添加检测指标", produces = "application/json")
|
public Result<MwDetectionIndex> add(@RequestBody MwDetectionIndex mwDetectionIndex) {
|
|
Result<MwDetectionIndex> result = new Result<MwDetectionIndex>();
|
try {
|
mwDetectionIndexService.save(mwDetectionIndex);
|
result.success("添加成功!");
|
} catch (Exception e) {
|
result.error500("操作失败");
|
}
|
return result;
|
}
|
|
/**
|
* 编辑
|
* @param mwDetectionIndex
|
* @return
|
*/
|
@PostMapping(value = "/edit")
|
@AutoLog(value = "编辑检测指标")
|
@ApiOperation(value = "编辑检测指标", notes = "编辑检测指标", produces = "application/json")
|
public Result<MwDetectionIndex> edit(@RequestBody MwDetectionIndex mwDetectionIndex) {
|
|
Result<MwDetectionIndex> result = new Result<MwDetectionIndex>();
|
MwDetectionIndex mwDetectionIndexEntity = mwDetectionIndexService.getById(mwDetectionIndex.getId());
|
if(mwDetectionIndexEntity==null) {
|
result.error500("未找到对应实体");
|
}else {
|
boolean ok = mwDetectionIndexService.updateById(mwDetectionIndex);
|
//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<MwDetectionIndex> delete(@RequestParam(name="id",required=true) String id) {
|
|
Result<MwDetectionIndex> result = new Result<MwDetectionIndex>();
|
MwDetectionIndex mwDetectionIndex = mwDetectionIndexService.getById(id);
|
if(mwDetectionIndex==null) {
|
result.error500("未找到对应实体");
|
}else {
|
boolean ok = mwDetectionIndexService.removeById(id);
|
if(ok) {
|
result.success("删除成功!");
|
}
|
}
|
|
return result;
|
}
|
|
/**
|
* 批量删除
|
* @param ids
|
* @return
|
*/
|
@PostMapping(value = "/deleteBatch")
|
@AutoLog(value = "批量删除检测指标")
|
@ApiOperation(value = "批量删除检测指标", notes = "批量删除检测指标", produces = "application/json")
|
public Result<MwDetectionIndex> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
|
|
Result<MwDetectionIndex> result = new Result<MwDetectionIndex>();
|
if(ids==null || "".equals(ids.trim())) {
|
result.error500("参数不识别!");
|
}else {
|
this.mwDetectionIndexService.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<MwDetectionIndex> queryById(@RequestParam(name="id",required=true) String id) {
|
|
Result<MwDetectionIndex> result = new Result<MwDetectionIndex>();
|
MwDetectionIndex mwDetectionIndex = mwDetectionIndexService.getById(id);
|
if(mwDetectionIndex==null) {
|
result.error500("未找到对应实体");
|
}else {
|
result.setResult(mwDetectionIndex);
|
result.setSuccess(true);
|
}
|
return result;
|
}
|
|
/*=====检测指标导出--开始=======*/
|
private static Map<String, String> headerMapList = new LinkedHashMap<>();
|
|
static {
|
headerMapList.put("name", "指标名称");
|
headerMapList.put("code", "指标编号");
|
headerMapList.put("concentrationUnit", "浓度单位");
|
headerMapList.put("maxNum", "上限值");
|
headerMapList.put("minNum", "下限值");
|
headerMapList.put("cumulativeUnit", "累计值单位");
|
}
|
|
@Data
|
private static class MwDetectionIndexExportListVO {
|
|
private String name;
|
|
private String code;
|
|
private String concentrationUnit;
|
|
private String maxNum;
|
|
private String minNum;
|
|
private String cumulativeUnit;
|
|
|
}
|
|
@GetMapping("/listExport")
|
@OpenApi
|
@ApiOperation(value = "检测指标导出", notes = "检测指标导出", produces = "application/json")
|
public void listExport(HttpServletResponse response, MwDetectionIndex mwDetectionIndex) throws IOException {
|
|
QueryWrapper<MwDetectionIndex> queryWrapper = new QueryWrapper<MwDetectionIndex>();
|
queryWrapper.eq("del_flag",CommonConstant.DEL_FLAG_0);
|
if(oConvertUtils.isNotEmpty(mwDetectionIndex.getName()) ){
|
queryWrapper.like("name",mwDetectionIndex.getName());
|
}
|
if(oConvertUtils.isNotEmpty(mwDetectionIndex.getCode()) ){
|
queryWrapper.like("code",mwDetectionIndex.getCode());
|
}
|
if(oConvertUtils.isNotEmpty(mwDetectionIndex.getConcentrationUnit()) ){
|
queryWrapper.like("concentrationUnit",mwDetectionIndex.getConcentrationUnit());
|
}
|
List<MwDetectionIndex> list = mwDetectionIndexService.list( queryWrapper);
|
List<MwDetectionIndexController.MwDetectionIndexExportListVO> voList = new ArrayList<>();
|
for (MwDetectionIndex collectRecordVO : list) {
|
MwDetectionIndexController.MwDetectionIndexExportListVO vo=new MwDetectionIndexController.MwDetectionIndexExportListVO();
|
BeanUtils.copyProperties(collectRecordVO, vo);
|
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.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");
|
writer.flush(response.getOutputStream());
|
writer.close();
|
|
}
|
/*=====检测指标导出--结尾=======*/
|
|
}
|