| | |
| | | package com.ruoyi.process.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.deepoove.poi.XWPFTemplate; |
| | | import com.deepoove.poi.config.Configure; |
| | | import com.deepoove.poi.data.FilePictureRenderData; |
| | | import com.ruoyi.common.utils.QueryWrappers; |
| | | import com.ruoyi.inspect.util.HackLoopTableRenderPolicy; |
| | | import com.ruoyi.process.mapper.ProcessSampleMapper; |
| | | import com.ruoyi.process.mapper.ProcessTotalSampleMapper; |
| | | import com.ruoyi.process.pojo.ProcessSample; |
| | | import com.ruoyi.process.pojo.ProcessTotalSample; |
| | | import com.ruoyi.process.service.ProcessSampleService; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.time.LocalDate; |
| | | import java.time.format.DateTimeFormatter; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.InputStream; |
| | | import java.io.OutputStream; |
| | | import java.net.URLEncoder; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * <p> |
| | | * 样品接收 服务实现类 |
| | | * </p> |
| | | * |
| | | * @author 芯导软件(江苏)有限公司 |
| | | * @author |
| | | * @since 2024-12-12 05:02:49 |
| | | */ |
| | | @Service |
| | |
| | | @Resource |
| | | private ProcessSampleMapper processSampleMapper; |
| | | |
| | | @Resource |
| | | private ProcessTotalSampleMapper processTotalSampleMapper; |
| | | |
| | | |
| | | |
| | | @Override |
| | | public IPage<ProcessSample> pageProcessSample(Page page, ProcessSample processSample) { |
| | | //todo:仅看我 |
| | | if (ObjectUtils.isEmpty(processSample.getTotalSampleId())) { |
| | | //获取当前月份 |
| | | LocalDate currentDate = LocalDate.now(); |
| | | // 定义日期格式 |
| | | DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM"); |
| | | // 格式化当前日期 |
| | | String currentMonth = currentDate.format(formatter); |
| | | //查询历史 |
| | | ProcessTotalSample processTotalSample = processTotalSampleMapper.selectOne(Wrappers.<ProcessTotalSample>lambdaQuery().eq(ProcessTotalSample::getMonth, currentMonth)); |
| | | processSample.setTotalSampleId(processTotalSample.getId()); |
| | | } |
| | | return processSampleMapper.pageProcessSample(page, QueryWrappers.queryWrappers(processSample)); |
| | | } |
| | | |
| | | @Override |
| | | public int addProcessSample(ProcessSample processSample) { |
| | | ProcessTotalSample processTotalSample; |
| | | if (ObjectUtils.isEmpty(processSample.getTotalSampleId())){ |
| | | LocalDate dealTime = LocalDate.now(); |
| | | // 定义日期格式 |
| | | DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM"); |
| | | // 格式化当前日期 |
| | | String currentMonth = dealTime.format(formatter); |
| | | processTotalSample= processTotalSampleMapper.selectOne(Wrappers.<ProcessTotalSample>lambdaQuery().eq(ProcessTotalSample::getMonth,currentMonth)); |
| | | processSample.setTotalSampleId(processTotalSample.getId()); |
| | | }else { |
| | | processTotalSample= processTotalSampleMapper.selectById(processSample.getTotalSampleId()); |
| | | public void exportProcessSample(ProcessSample processSample, HttpServletResponse response) { |
| | | List<ProcessSample> processSampleList = pageProcessSample(new Page(-1, -1), processSample).getRecords(); |
| | | InputStream inputStream = this.getClass().getResourceAsStream("/static/sample-receive.docx"); |
| | | Configure configure = Configure.builder() |
| | | .bind("sampleList", new HackLoopTableRenderPolicy()) |
| | | .build(); |
| | | XWPFTemplate template = XWPFTemplate.compile(inputStream, configure).render( |
| | | new HashMap<String, Object>() {{ |
| | | put("sampleList", processSampleList); |
| | | }}); |
| | | try { |
| | | response.setContentType("application/msword"); |
| | | String fileName = URLEncoder.encode( |
| | | "检验样品登记表", "UTF-8"); |
| | | response.setHeader("Content-disposition", |
| | | "attachment;filename=" + fileName + ".docx"); |
| | | OutputStream os = response.getOutputStream(); |
| | | template.write(os); |
| | | os.flush(); |
| | | os.close(); |
| | | inputStream.close(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | throw new RuntimeException("导出失败"); |
| | | } |
| | | processSampleMapper.insert(processSample); |
| | | processTotalSample.setTotalNum(processSample.getNum()+processTotalSample.getTotalNum()); |
| | | return processTotalSampleMapper.updateById(processTotalSample); |
| | | } |
| | | |
| | | @Override |
| | | public int delProcessSample(Integer id) { |
| | | ProcessSample processSample = processSampleMapper.selectById(id); |
| | | processSampleMapper.deleteById(id); |
| | | ProcessTotalSample processTotalSample = processTotalSampleMapper.selectById(processSample.getTotalSampleId()); |
| | | processTotalSample.setTotalNum(processTotalSample.getTotalNum()-processSample.getNum()); |
| | | return processTotalSampleMapper.updateById(processTotalSample); |
| | | } |
| | | |
| | | @Override |
| | | public int doProcessSample(ProcessSample processSample) { |
| | | if (ObjectUtils.isNotEmpty(processSample.getNum())) { |
| | | ProcessSample oldProcessSample = processSampleMapper.selectById(processSample.getId()); |
| | | ProcessTotalSample processTotalSample = processTotalSampleMapper.selectById(processSample.getTotalSampleId()); |
| | | processTotalSample.setTotalNum(processTotalSample.getTotalNum() - oldProcessSample.getNum() + processSample.getNum()); |
| | | processTotalSampleMapper.updateById(processTotalSample); |
| | | } |
| | | return processSampleMapper.updateById(processSample); |
| | | } |
| | | } |