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.dto.IdDTO;
|
import cn.besteam.common.util.DateUtil;
|
import cn.besteam.modules.medical.dto.MwCollectRecordOpsDTO;
|
import cn.besteam.modules.medical.dto.MwCollectionPointDTO;
|
import cn.besteam.modules.medical.vo.MwCollectRecordVO;
|
import cn.besteam.modules.medical.vo.MwCollectionPointVO;
|
import cn.besteam.modules.system.entity.SysDepartment;
|
import cn.besteam.modules.system.service.ISysDepartmentService;
|
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.MwCollectionPoint;
|
import cn.besteam.modules.medical.service.IMwCollectionPointService;
|
import lombok.Data;
|
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.validation.annotation.Validated;
|
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-09
|
* @version: V1.0
|
*/
|
@RestController
|
@RequestMapping("/medical/mwCollectionPoint")
|
@Slf4j
|
@Api(description = "收集点位")
|
public class MwCollectionPointController {
|
|
@Autowired
|
private IMwCollectionPointService mwCollectionPointService;
|
|
@Autowired
|
private ISysDepartmentService sysDepartmentService;
|
|
/**
|
* 分页列表查询
|
* @param mwCollectionPoint
|
* @param pageNo
|
* @param pageSize
|
* @param req
|
* @return
|
*/
|
@GetMapping(value = "/list")
|
@ApiOperation(value = "获取收集点位数据列表", notes = "获取所有收集点位数据列表", produces = "application/json")
|
public Result<IPage<MwCollectionPoint>> queryPageList(MwCollectionPoint mwCollectionPoint, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, HttpServletRequest req) {
|
|
Result<IPage<MwCollectionPoint>> result = new Result<IPage<MwCollectionPoint>>();
|
QueryWrapper<MwCollectionPoint> queryWrapper = new QueryWrapper<MwCollectionPoint>(mwCollectionPoint);
|
Page<MwCollectionPoint> page = new Page<MwCollectionPoint>(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));
|
}
|
}
|
IPage<MwCollectionPoint> pageList = mwCollectionPointService.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 mwCollectionPoint
|
* @return
|
*/
|
@PostMapping(value = "/add")
|
@AutoLog(value = "添加收集点位")
|
@ApiOperation(value = "添加收集点位", notes = "添加收集点位", produces = "application/json")
|
public Result<MwCollectionPoint> add(@RequestBody MwCollectionPoint mwCollectionPoint) {
|
|
Result<MwCollectionPoint> result = new Result<MwCollectionPoint>();
|
try {
|
|
String[] ids = mwCollectionPoint.getOfficeId().split(",");
|
String officeName="";
|
for(String id:ids){
|
SysDepartment sysDepartment = sysDepartmentService.getById(id);
|
officeName+=sysDepartment.getDepartName()+",";
|
}
|
mwCollectionPoint.setOfficeName(officeName.substring(0,officeName.length()-1));
|
SysDepartment sysDepartment = sysDepartmentService.getById(ids[0]);
|
|
SysDepartment sysDepartment1 = sysDepartmentService.getById(sysDepartment.getParentId());
|
if(sysDepartment1.getOrgType().equals(2)){
|
mwCollectionPoint.setHospitalId(sysDepartment1.getId());
|
mwCollectionPoint.setHospitalName(sysDepartment1.getDepartName());
|
}else{
|
sysDepartment1 = sysDepartmentService.getById(sysDepartment1.getParentId());
|
mwCollectionPoint.setHospitalId(sysDepartment1.getId());
|
mwCollectionPoint.setHospitalName(sysDepartment1.getDepartName());
|
}
|
MwCollectionPoint mwCollectionPoint1 = mwCollectionPointService.getOne(new QueryWrapper<MwCollectionPoint>().eq("name",mwCollectionPoint.getName()).eq("hospital_id",mwCollectionPoint.getHospitalId()));
|
if(mwCollectionPoint1==null){
|
mwCollectionPointService.save(mwCollectionPoint);
|
result.success("添加成功!");
|
}else{
|
result.error500("操作失败,名称重复!");
|
}
|
|
} catch (Exception e) {
|
log.error("", e);
|
result.error500("操作失败");
|
}
|
return result;
|
}
|
|
/**
|
* 编辑
|
* @param mwCollectionPoint
|
* @return
|
*/
|
@PostMapping(value = "/edit")
|
@AutoLog(value = "编辑收集点位")
|
@ApiOperation(value = "编辑收集点位", notes = "编辑收集点位", produces = "application/json")
|
public Result<MwCollectionPoint> edit(@RequestBody MwCollectionPoint mwCollectionPoint) {
|
|
Result<MwCollectionPoint> result = new Result<MwCollectionPoint>();
|
MwCollectionPoint mwCollectionPointEntity = mwCollectionPointService.getById(mwCollectionPoint.getId());
|
if(mwCollectionPointEntity==null) {
|
result.error500("未找到对应实体");
|
}else {
|
String[] ids = mwCollectionPoint.getOfficeId().split(",");
|
String officeName="";
|
for(String id:ids){
|
SysDepartment sysDepartment = sysDepartmentService.getById(id);
|
officeName+=sysDepartment.getDepartName()+",";
|
}
|
mwCollectionPoint.setOfficeName(officeName.substring(0,officeName.length()-1));
|
SysDepartment sysDepartment = sysDepartmentService.getById(ids[0]);
|
|
SysDepartment sysDepartment1 = sysDepartmentService.getById(sysDepartment.getParentId());
|
if(sysDepartment1.getOrgType().equals(2)){
|
mwCollectionPoint.setHospitalId(sysDepartment1.getId());
|
mwCollectionPoint.setHospitalName(sysDepartment1.getDepartName());
|
}else{
|
sysDepartment1 = sysDepartmentService.getById(sysDepartment1.getParentId());
|
mwCollectionPoint.setHospitalId(sysDepartment1.getId());
|
mwCollectionPoint.setHospitalName(sysDepartment1.getDepartName());
|
}
|
MwCollectionPoint mwCollectionPoint1 = mwCollectionPointService.getOne(new QueryWrapper<MwCollectionPoint>().ne("id",mwCollectionPoint.getId()).eq("name",mwCollectionPoint.getName()).eq("hospital_id",mwCollectionPoint.getHospitalId()));
|
if(mwCollectionPoint1==null){
|
boolean ok = mwCollectionPointService.updateById(mwCollectionPoint);
|
//TODO 返回false说明什么?
|
if(ok) {
|
result.success("修改成功!");
|
}
|
}else{
|
result.error500("操作失败,名称重复!");
|
}
|
|
}
|
|
return result;
|
}
|
|
/**
|
* 通过id删除
|
* @return
|
*/
|
@PostMapping(value = "/delete")
|
@AutoLog(value = "删除收集点位")
|
@ApiOperation(value = "删除收集点位", notes = "删除收集点位", produces = "application/json")
|
public Result<MwCollectionPoint> delete(@Validated @RequestBody IdDTO dto) {
|
|
Result<MwCollectionPoint> result = new Result<MwCollectionPoint>();
|
MwCollectionPoint mwCollectionPoint = mwCollectionPointService.getById(dto.getId());
|
if(mwCollectionPoint==null) {
|
result.error500("未找到对应实体");
|
}else {
|
boolean ok = mwCollectionPointService.removeById(dto.getId());
|
if(ok) {
|
result.success("删除成功!");
|
}
|
}
|
|
return result;
|
}
|
|
/**
|
* 批量删除
|
* @param ids
|
* @return
|
*/
|
@PostMapping(value = "/deleteBatch")
|
@AutoLog(value = "批量删除收集点位")
|
@ApiOperation(value = "批量删除收集点位", notes = "批量删除收集点位", produces = "application/json")
|
public Result<MwCollectionPoint> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
|
|
Result<MwCollectionPoint> result = new Result<MwCollectionPoint>();
|
if(ids==null || "".equals(ids.trim())) {
|
result.error500("参数不识别!");
|
}else {
|
this.mwCollectionPointService.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<MwCollectionPoint> queryById(@RequestParam(name="id",required=true) String id) {
|
|
Result<MwCollectionPoint> result = new Result<MwCollectionPoint>();
|
MwCollectionPoint mwCollectionPoint = mwCollectionPointService.getById(id);
|
if(mwCollectionPoint==null) {
|
result.error500("未找到对应实体");
|
}else {
|
result.setResult(mwCollectionPoint);
|
result.setSuccess(true);
|
}
|
return result;
|
}
|
@GetMapping(value = "/listPoint")
|
@ApiOperation(value = "收集点位列表", notes = "收集点位列表", produces = "application/json")
|
public Result<IPage<MwCollectionPointVO>> listPoint(MwCollectionPointDTO dto, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
|
|
//
|
IPage<MwCollectionPointVO> pageList = mwCollectionPointService.queryPageCollectList(pageNo, pageSize, dto);
|
return Result.ok(pageList);
|
}
|
|
/*=====医废追溯导出--开始=======*/
|
private static Map<String, String> headerMapListPoint = new LinkedHashMap<>();
|
|
static {
|
headerMapListPoint.put("hospitalName", "机构名称");
|
headerMapListPoint.put("name", "点位名称");
|
headerMapListPoint.put("nature", "点位性质");
|
headerMapListPoint.put("officeNames", "关联科室");
|
}
|
|
@Data
|
private static class MwCollectionPointExportListVO {
|
|
|
private String hospitalName="";
|
|
private String name="";
|
|
private String nature="";
|
|
private String officeNames="";
|
|
}
|
|
@GetMapping("/listExport")
|
@OpenApi
|
@ApiOperation(value = "收集点位导出", notes = "收集点位导出", produces = "application/json")
|
public void listExport(HttpServletResponse response, MwCollectionPointDTO dto) throws IOException {
|
List<MwCollectionPointVO> list=mwCollectionPointService.queryPageCollectList( dto);
|
List<MwCollectionPointController.MwCollectionPointExportListVO> voList = new ArrayList<>();
|
for (MwCollectionPointVO collectRecordVO : list) {
|
MwCollectionPointController.MwCollectionPointExportListVO vo=new MwCollectionPointController.MwCollectionPointExportListVO();
|
BeanUtils.copyProperties(collectRecordVO, vo);
|
//性质(1=院内站点,2=院外站点)
|
if (collectRecordVO.getNature().equals(1)) {
|
vo.setNature("院内站点");
|
} else if (collectRecordVO.getNature().equals(2)) {
|
vo.setNature("院外站点");
|
}
|
vo.setOfficeNames(collectRecordVO.getOfficeName().toString());
|
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.setHeaderAlias(headerMapListPoint);
|
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();
|
|
}
|
}
|