zhuguifei
2025-04-28 442928123f63ee497d766f9a7a14f0a6ee067e25
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
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);
    }
 
 
}