package org.jeecg.modules.lims.controller;
|
|
import java.lang.reflect.InvocationTargetException;
|
import java.text.ParseException;
|
import java.util.*;
|
import java.util.stream.Collectors;
|
import java.io.IOException;
|
import java.io.UnsupportedEncodingException;
|
import java.net.URLDecoder;
|
import java.util.stream.Stream;
|
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletResponse;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.fasterxml.classmate.Annotations;
|
import org.apache.commons.beanutils.BeanUtils;
|
import org.apache.commons.lang3.StringUtils;
|
import org.jeecg.common.api.vo.Result;
|
import org.jeecg.common.system.query.QueryGenerator;
|
import org.jeecg.common.util.DateUtils;
|
import org.jeecg.common.util.oConvertUtils;
|
import org.jeecg.modules.lims.entity.LimsAppointment;
|
import org.jeecg.modules.lims.entity.LimsAppointmentOption;
|
import org.jeecg.modules.lims.entity.LimsInstrument;
|
import org.jeecg.modules.lims.entity.LimsInstrumentType;
|
import org.jeecg.modules.lims.service.*;
|
|
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;
|
|
import org.jeecg.modules.lims.vo.LimsInstrumentVo;
|
import org.jeecgframework.poi.excel.ExcelImportUtil;
|
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
|
import org.jeecgframework.poi.excel.entity.ExportParams;
|
import org.jeecgframework.poi.excel.entity.ImportParams;
|
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
|
import org.jeecg.common.system.base.controller.JeecgController;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartHttpServletRequest;
|
import org.springframework.web.servlet.ModelAndView;
|
import com.alibaba.fastjson.JSON;
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiOperation;
|
import org.jeecg.common.aspect.annotation.AutoLog;
|
|
/**
|
* @Description: 仪器
|
* @Author: jeecg-boot
|
* @Date: 2022-11-07
|
* @Version: V1.0
|
*/
|
@Api(tags="仪器")
|
@RestController
|
@RequestMapping("/limsInstrument")
|
@Slf4j
|
public class LimsInstrumentController extends JeecgController<LimsInstrument, ILimsInstrumentService> {
|
@Autowired
|
private ILimsInstrumentService limsInstrumentService;
|
@Autowired
|
private ILimsInstrumentTypeService limsInstrumentTypeService;
|
@Autowired
|
private ILimsAppointmentService limsAppointmentService;
|
|
@Autowired
|
private ILimsAppointmentOptionService limsAppointmentOptionService;
|
|
/**
|
* 分页列表查询
|
*
|
* @param limsInstrument
|
* @param pageNo
|
* @param pageSize
|
* @param req
|
* @return
|
*/
|
@AutoLog(value = "仪器-分页列表查询")
|
@ApiOperation(value="仪器-分页列表查询", notes="仪器-分页列表查询")
|
@GetMapping(value = "/list")
|
public Result<?> queryPageList(LimsInstrument limsInstrument,
|
@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
|
@RequestParam(name="pageSize", defaultValue="100") Integer pageSize,
|
HttpServletRequest req) throws InvocationTargetException, IllegalAccessException, ParseException {
|
QueryWrapper<LimsInstrument> queryWrapper = QueryGenerator.initQueryWrapper(limsInstrument, req.getParameterMap());
|
Page<LimsInstrument> page = new Page<LimsInstrument>(pageNo, pageSize);
|
IPage<LimsInstrument> pageList = limsInstrumentService.page(page, queryWrapper);
|
//查询所有预约
|
List<LimsAppointmentOption> options = limsAppointmentOptionService.list(new LambdaQueryWrapper<LimsAppointmentOption>().orderByAsc(LimsAppointmentOption::getSort));
|
|
|
// 填充类型名称
|
Set<String> collect = pageList.getRecords().stream().map(item -> item.getType()).collect(Collectors.toSet());
|
Set<String> eqpIds = pageList.getRecords().stream().map(item -> item.getId()).collect(Collectors.toSet());
|
Map<String, String> map = new HashMap<>();
|
Map<String, List<LimsAppointment>> listMap = new HashMap<>();
|
if (collect != null && collect.size() > 0) {
|
// 获取类型
|
LambdaQueryWrapper<LimsInstrumentType> in = new LambdaQueryWrapper<LimsInstrumentType>().in(LimsInstrumentType::getId, collect);
|
List<LimsInstrumentType> list = limsInstrumentTypeService.list(in);
|
map = list.stream().collect(Collectors.toMap(LimsInstrumentType::getId, LimsInstrumentType::getName));
|
|
// 获取第二天预约信息
|
LambdaQueryWrapper<LimsAppointment> qw = new LambdaQueryWrapper<>();
|
Date nextDay =DateUtils.getTomorrow();
|
qw.ge(LimsAppointment::getStime, DateUtils.getDayStartTime(nextDay));
|
qw.le(LimsAppointment::getEtime, DateUtils.getDayEndTime(nextDay));
|
qw.in(LimsAppointment::getInstrument,eqpIds);
|
qw.in(LimsAppointment::getStatus, 0,5);
|
List<LimsAppointment> appointments = limsAppointmentService.list(qw);
|
listMap = appointments.stream().collect(Collectors.groupingBy(LimsAppointment::getInstrument, Collectors.toList()));
|
}
|
|
|
Page<LimsInstrumentVo> page1 = new Page<>();
|
BeanUtils.copyProperties(page1,pageList);
|
List<LimsInstrumentVo> resList = new ArrayList();
|
|
|
for ( LimsInstrument instrument: pageList.getRecords()
|
) {
|
LimsInstrumentVo vo = new LimsInstrumentVo();
|
try {
|
BeanUtils.copyProperties(vo, instrument);
|
} catch (IllegalAccessException e) {
|
throw new RuntimeException(e);
|
} catch (InvocationTargetException e) {
|
throw new RuntimeException(e);
|
}
|
|
Map<String, List<LimsAppointment>> finalListMap = listMap;
|
// 获取当前仪器预约详情
|
List<LimsAppointment> limsAppointments = finalListMap.get(instrument.getId());
|
Map<String, LimsAppointment> optionMap = new HashMap<>();
|
if (limsAppointments != null && limsAppointments.size()> 0) {
|
// optionMap = limsAppointments.stream().collect(Collectors.toMap(item -> item.getOptionid(), item -> item));
|
limsAppointments.stream().forEach(item -> {
|
String[] ids = item.getOptionid().split(",");
|
for (String str: ids) {
|
if (StringUtils.isNotBlank(str)){
|
optionMap.put(str,item);
|
}
|
}
|
});
|
}
|
Map<String, LimsAppointment> finalOptionMap = optionMap;
|
List<Integer> tagStrs = options.stream().map(item -> {
|
|
if (finalOptionMap.get(item.getId()) != null) {
|
return 1;
|
} else {
|
return 0;
|
}
|
}).collect(Collectors.toList());
|
vo.setAppointmentTagStr(tagStrs);
|
|
vo.setTypeName(map.get(vo.getType()));
|
resList.add(vo);
|
|
}
|
page1.setRecords(resList);
|
page1.setTotal(pageList.getTotal());
|
return Result.OK(page1);
|
}
|
|
|
@AutoLog(value = "仪器-分页列表今天预约查询")
|
@ApiOperation(value="仪器-分页列表今天预约查询", notes="仪器-分页列表今天预约查询")
|
@GetMapping(value = "/listtoday")
|
public Result<?> queryTodayAppo(LimsInstrument limsInstrument,
|
@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
|
@RequestParam(name="pageSize", defaultValue="100") Integer pageSize,
|
HttpServletRequest req) throws InvocationTargetException, IllegalAccessException, ParseException {
|
QueryWrapper<LimsInstrument> queryWrapper = QueryGenerator.initQueryWrapper(limsInstrument, req.getParameterMap());
|
Page<LimsInstrument> page = new Page<LimsInstrument>(pageNo, pageSize);
|
IPage<LimsInstrument> pageList = limsInstrumentService.page(page, queryWrapper);
|
//查询所有预约
|
List<LimsAppointmentOption> options = limsAppointmentOptionService.list(new LambdaQueryWrapper<LimsAppointmentOption>().orderByAsc(LimsAppointmentOption::getSort));
|
|
|
// 填充类型名称
|
Set<String> collect = pageList.getRecords().stream().map(item -> item.getType()).collect(Collectors.toSet());
|
Set<String> eqpIds = pageList.getRecords().stream().map(item -> item.getId()).collect(Collectors.toSet());
|
Map<String, String> map = new HashMap<>();
|
Map<String, List<LimsAppointment>> listMap = new HashMap<>();
|
if (collect != null && collect.size() > 0) {
|
// 获取类型
|
LambdaQueryWrapper<LimsInstrumentType> in = new LambdaQueryWrapper<LimsInstrumentType>().in(LimsInstrumentType::getId, collect);
|
List<LimsInstrumentType> list = limsInstrumentTypeService.list(in);
|
map = list.stream().collect(Collectors.toMap(LimsInstrumentType::getId, LimsInstrumentType::getName));
|
|
// 获取第今天预约信息
|
LambdaQueryWrapper<LimsAppointment> qw = new LambdaQueryWrapper<>();
|
Date nextDay = new Date();
|
qw.ge(LimsAppointment::getStime, DateUtils.getDayStartTime(nextDay));
|
qw.le(LimsAppointment::getEtime, DateUtils.getDayEndTime(nextDay));
|
qw.in(LimsAppointment::getInstrument,eqpIds);
|
qw.in(LimsAppointment::getStatus, 0,5);
|
List<LimsAppointment> appointments = limsAppointmentService.list(qw);
|
listMap = appointments.stream().collect(Collectors.groupingBy(LimsAppointment::getInstrument, Collectors.toList()));
|
}
|
|
|
Page<LimsInstrumentVo> page1 = new Page<>();
|
BeanUtils.copyProperties(page1,pageList);
|
List<LimsInstrumentVo> resList = new ArrayList();
|
|
|
for ( LimsInstrument instrument: pageList.getRecords()
|
) {
|
LimsInstrumentVo vo = new LimsInstrumentVo();
|
try {
|
BeanUtils.copyProperties(vo, instrument);
|
} catch (IllegalAccessException e) {
|
throw new RuntimeException(e);
|
} catch (InvocationTargetException e) {
|
throw new RuntimeException(e);
|
}
|
|
Map<String, List<LimsAppointment>> finalListMap = listMap;
|
// 获取当前仪器预约详情
|
List<LimsAppointment> limsAppointments = finalListMap.get(instrument.getId());
|
Map<String, LimsAppointment> optionMap = new HashMap<>();
|
if (limsAppointments != null && limsAppointments.size()> 0) {
|
// optionMap = limsAppointments.stream().collect(Collectors.toMap(item -> item.getOptionid(), item -> item));
|
limsAppointments.stream().forEach(item -> {
|
String[] ids = item.getOptionid().split(",");
|
for (String str: ids) {
|
if (StringUtils.isNotBlank(str)){
|
optionMap.put(str,item);
|
}
|
}
|
});
|
}
|
Map<String, LimsAppointment> finalOptionMap = optionMap;
|
List<Integer> tagStrs = options.stream().map(item -> {
|
|
if (finalOptionMap.get(item.getId()) != null) {
|
return 1;
|
} else {
|
return 0;
|
}
|
}).collect(Collectors.toList());
|
vo.setAppointmentTagStr(tagStrs);
|
|
vo.setTypeName(map.get(vo.getType()));
|
resList.add(vo);
|
|
}
|
page1.setRecords(resList);
|
page1.setTotal(pageList.getTotal());
|
return Result.OK(page1);
|
}
|
|
/**
|
* 添加
|
*
|
* @param limsInstrument
|
* @return
|
*/
|
@AutoLog(value = "仪器-添加")
|
@ApiOperation(value="仪器-添加", notes="仪器-添加")
|
@PostMapping(value = "/add")
|
public Result<?> add(@RequestBody LimsInstrument limsInstrument) {
|
List<LimsInstrument> list = limsInstrumentService.list(
|
new LambdaQueryWrapper<LimsInstrument>()
|
.eq(LimsInstrument::getCode, limsInstrument.getCode())
|
.or()
|
.eq(LimsInstrument::getAssetNo, limsInstrument.getAssetNo()));
|
if (list != null && list.size() > 0) {
|
LimsInstrument li = list.get(0);
|
if (li.getCode().equals(limsInstrument.getCode())) {
|
Result.error("设备编号重复");
|
} else {
|
Result.error("固定资产编号重复");
|
}
|
}
|
limsInstrumentService.save(limsInstrument);
|
return Result.OK("添加成功!");
|
}
|
|
/**
|
* 编辑
|
*
|
* @param limsInstrument
|
* @return
|
*/
|
@AutoLog(value = "仪器-编辑")
|
@ApiOperation(value="仪器-编辑", notes="仪器-编辑")
|
@PutMapping(value = "/edit")
|
public Result<?> edit(@RequestBody LimsInstrument limsInstrument) {
|
limsInstrumentService.updateById(limsInstrument);
|
return Result.OK("编辑成功!");
|
}
|
|
/**
|
* 通过id删除
|
*
|
* @param id
|
* @return
|
*/
|
@AutoLog(value = "仪器-通过id删除")
|
@ApiOperation(value="仪器-通过id删除", notes="仪器-通过id删除")
|
@DeleteMapping(value = "/delete")
|
public Result<?> delete(@RequestParam(name="id",required=true) String id) {
|
limsInstrumentService.removeById(id);
|
return Result.OK("删除成功!");
|
}
|
|
/**
|
* 批量删除
|
*
|
* @param ids
|
* @return
|
*/
|
@AutoLog(value = "仪器-批量删除")
|
@ApiOperation(value="仪器-批量删除", notes="仪器-批量删除")
|
@DeleteMapping(value = "/deleteBatch")
|
public Result<?> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
|
this.limsInstrumentService.removeByIds(Arrays.asList(ids.split(",")));
|
return Result.OK("批量删除成功!");
|
}
|
|
/**
|
* 通过id查询
|
*
|
* @param id
|
* @return
|
*/
|
@AutoLog(value = "仪器-通过id查询")
|
@ApiOperation(value="仪器-通过id查询", notes="仪器-通过id查询")
|
@GetMapping(value = "/queryById")
|
public Result<?> queryById(@RequestParam(name="id",required=true) String id) {
|
LimsInstrument limsInstrument = limsInstrumentService.getById(id);
|
if(limsInstrument==null) {
|
return Result.error("未找到对应数据");
|
}
|
return Result.OK(limsInstrument);
|
}
|
|
/**
|
* 导出excel
|
*
|
* @param request
|
* @param limsInstrument
|
*/
|
@RequestMapping(value = "/exportXls")
|
public ModelAndView exportXls(HttpServletRequest request, LimsInstrument limsInstrument) {
|
return super.exportXls(request, limsInstrument, LimsInstrument.class, "仪器");
|
}
|
|
/**
|
* 通过excel导入数据
|
*
|
* @param request
|
* @param response
|
* @return
|
*/
|
@RequestMapping(value = "/importExcel", method = RequestMethod.POST)
|
public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
|
return super.importExcel(request, response, LimsInstrument.class);
|
}
|
|
|
}
|