package org.jeecg.modules.lims.controller;
|
|
import java.sql.Timestamp;
|
import java.util.*;
|
import java.util.stream.Collectors;
|
import java.io.IOException;
|
import java.io.UnsupportedEncodingException;
|
import java.net.URLDecoder;
|
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletResponse;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
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.api.JeecgSystemClient;
|
import org.jeecg.modules.lims.entity.*;
|
import org.jeecg.modules.lims.service.ILimsInspectionDetailService;
|
import org.jeecg.modules.lims.service.ILimsInspectionItemService;
|
import org.jeecg.modules.lims.service.ILimsInspectionService;
|
|
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.service.ILimsInstrumentService;
|
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.transaction.annotation.Transactional;
|
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("/limsInspection")
|
@Slf4j
|
public class LimsInspectionController extends JeecgController<LimsInspection, ILimsInspectionService> {
|
@Autowired
|
private ILimsInspectionService limsInspectionService;
|
|
@Autowired
|
private ILimsInstrumentService limsInstrumentService;
|
|
@Autowired
|
private ILimsInspectionDetailService detailService;
|
|
@Autowired
|
private ILimsInspectionItemService itemService;
|
|
@Autowired
|
private JeecgSystemClient jeecgSystemClient;
|
|
/**
|
* 分页列表查询
|
*
|
* @param limsInspection
|
* @param pageNo
|
* @param pageSize
|
* @param req
|
* @return
|
*/
|
@AutoLog(value = "点检记录-分页列表查询")
|
@ApiOperation(value="点检记录-分页列表查询", notes="点检记录-分页列表查询")
|
@GetMapping(value = "/list")
|
public Result<?> queryPageList(LimsInspection limsInspection,
|
@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
|
@RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
|
HttpServletRequest req) {
|
// if (limsInspection.getInspectionTime() != null) {
|
//
|
// req.getParameterMap().put("inspectionTime_begin", new String[] {DateUtils.formatDate(new Date(DateUtils.getDayStartTime(limsInspection.getInspectionTime()).getTime()),"yyyy-MM-dd HH:mm:ss")});
|
// req.getParameterMap().put("inspectionTime_end", new String[] {DateUtils.formatDate(new Date(DateUtils.getDayEndTime(limsInspection.getInspectionTime()).getTime()),"yyyy-MM-dd HH:mm:ss")});
|
// }
|
QueryWrapper<LimsInspection> queryWrapper = QueryGenerator.initQueryWrapper(limsInspection, req.getParameterMap());
|
// if (limsInspection.getInspectionTime() != null) {
|
// queryWrapper.ge("inspection_time", DateUtils.getDayStartTime(limsInspection.getInspectionTime()));
|
// queryWrapper.le("inspection_time",DateUtils.getDayEndTime(limsInspection.getInspectionTime()));
|
// }
|
Page<LimsInspection> page = new Page<LimsInspection>(pageNo, pageSize);
|
IPage<LimsInspection> pageList = limsInspectionService.page(page, queryWrapper);
|
Set<String> ids = pageList.getRecords().stream().map(LimsInspection::getId).collect(Collectors.toSet());
|
Set<String> insIds = pageList.getRecords().stream().map(LimsInspection::getInstrumentId).collect(Collectors.toSet());
|
if (ids != null && ids.size()>0) {
|
List<LimsInspectionDetail> list = detailService.list(new LambdaQueryWrapper<LimsInspectionDetail>().in(LimsInspectionDetail::getPid, ids));
|
List<LimsInstrument> instrumentList = limsInstrumentService.list(new LambdaQueryWrapper<LimsInstrument>().in(LimsInstrument::getId, insIds));
|
Map<String, List<LimsInspectionDetail>> listMap = list.stream().collect(Collectors.groupingBy(LimsInspectionDetail::getPid, Collectors.toList()));
|
Map<String, String> instrumentMap = instrumentList.stream().collect(Collectors.toMap(LimsInstrument::getId, LimsInstrument::getName));
|
pageList.setRecords(pageList.getRecords().stream().map(item -> {
|
List<LimsInspectionDetail> items = listMap.get(item.getId());
|
item.setItems(items);
|
if(items!=null){
|
int result = 1;
|
for (int i = 0; i < items.size(); i++) {
|
LimsInspectionDetail detail = items.get(i);
|
if(detail.getResult()==null || detail.getResult()!=1){
|
result = 0;
|
}
|
}
|
item.setResult(result);
|
}
|
|
if(instrumentMap!=null)
|
item.setInstrument(instrumentMap.get(item.getInstrumentId()));
|
SysUser user = jeecgSystemClient.queryByUserName(item.getCreateBy()).getResult();
|
if(user!=null)
|
item.setRealname(user.getRealname());
|
return item;
|
}).collect(Collectors.toList()));
|
}
|
return Result.OK(pageList);
|
}
|
|
/**
|
* 添加
|
*
|
* @param limsInspection
|
* @return
|
*/
|
@AutoLog(value = "点检记录-添加")
|
@ApiOperation(value="点检记录-添加", notes="点检记录-添加")
|
@PostMapping(value = "/add")
|
@Transactional
|
public Result<?> add(@RequestBody LimsInspection limsInspection) {
|
limsInspection.setInspectionTime(new Date());
|
limsInspectionService.save(limsInspection);
|
List<LimsInspectionDetail> collect = limsInspection.getItems().stream().map(item -> {
|
item.setPid(limsInspection.getId());
|
return item;
|
}).collect(Collectors.toList());
|
detailService.saveBatch(collect);
|
LambdaUpdateWrapper<LimsInstrument> updateWrapper = new LambdaUpdateWrapper<>();
|
updateWrapper.set(LimsInstrument::getInspection, "1").eq(LimsInstrument::getId, limsInspection.getInstrumentId());
|
limsInstrumentService.update(updateWrapper);
|
return Result.OK("添加成功!");
|
}
|
|
/**
|
* 编辑
|
*
|
* @param limsInspection
|
* @return
|
*/
|
@AutoLog(value = "点检记录-编辑")
|
@ApiOperation(value="点检记录-编辑", notes="点检记录-编辑")
|
@PutMapping(value = "/edit")
|
public Result<?> edit(@RequestBody LimsInspection limsInspection) {
|
limsInspectionService.updateById(limsInspection);
|
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) {
|
limsInspectionService.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.limsInspectionService.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) {
|
LimsInspection limsInspection = limsInspectionService.getById(id);
|
if(limsInspection==null) {
|
return Result.error("未找到对应数据");
|
}
|
return Result.OK(limsInspection);
|
}
|
|
/**
|
* 导出excel
|
*
|
* @param request
|
* @param limsInspection
|
*/
|
@RequestMapping(value = "/exportXls")
|
public ModelAndView exportXls(HttpServletRequest request, LimsInspection limsInspection) {
|
return super.exportXls(request, limsInspection, LimsInspection.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, LimsInspection.class);
|
}
|
|
|
/**
|
* 通过设备id获取设备点检详情
|
*/
|
|
@GetMapping("/inspDetail")
|
public Result<?> queryInspectionDetail(@RequestParam(name="id",required=true) String id) {
|
|
// // 1、查询设备
|
// LimsInstrument instrument = limsInstrumentService.getById(id);
|
// // 2、查询设备所属类型的点检项
|
// itemService.list(new LambdaQueryWrapper<LimsInspectionItem>().eq(LimsInspectionItem::getInstrumentType,instrument.get))
|
//
|
// // 3、查询该设备已做点检记录
|
//
|
// // 4、组装到一块
|
|
return Result.OK();
|
}
|
}
|