| | |
| | | package com.ruoyi.web.controller.api; |
| | | |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.ruoyi.common.annotation.Log; |
| | | import com.ruoyi.common.basic.PageInfo; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.enums.BusinessType; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.framework.web.service.TokenService; |
| | | import com.ruoyi.system.dto.*; |
| | | import com.ruoyi.system.mapper.SysUserMapper; |
| | | import com.ruoyi.system.model.*; |
| | | import com.ruoyi.system.query.TSamplingRecordQuery; |
| | | import com.ruoyi.system.service.*; |
| | | import com.ruoyi.system.vo.TSamplingRecordVO; |
| | | import io.swagger.annotations.Api; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.time.LocalDateTime; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | @RequestMapping("/t-sampling-record") |
| | | public class TSamplingRecordController { |
| | | |
| | | private final TSamplingRecordService samplingRecordService; |
| | | private final TokenService tokenService; |
| | | private final ISysUserService sysUserService; |
| | | private final SysUserMapper sysUserMapper; |
| | | private final TSamplingRecordOperationService samplingRecordOperationService; |
| | | @Autowired |
| | | public TSamplingRecordController(TSamplingRecordService samplingRecordService, TokenService tokenService, ISysUserService sysUserService, SysUserMapper sysUserMapper, TSamplingRecordOperationService samplingRecordOperationService) { |
| | | this.samplingRecordService = samplingRecordService; |
| | | this.tokenService = tokenService; |
| | | this.sysUserService = sysUserService; |
| | | this.sysUserMapper = sysUserMapper; |
| | | this.samplingRecordOperationService = samplingRecordOperationService; |
| | | } |
| | | |
| | | /** |
| | | * 获取取样记录管理列表 |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('system:samplingRecord:list')") |
| | | @ApiOperation(value = "获取取样记录分页列表") |
| | | @PostMapping(value = "/api/t-sampling-record/pageList") |
| | | public R<PageInfo<TSamplingRecordVO>> pageList(@RequestBody String param) { |
| | | TSamplingRecordQuery query = JSON.parseObject(param, TSamplingRecordQuery.class); |
| | | return R.ok(samplingRecordService.pageList(query)); |
| | | } |
| | | |
| | | /** |
| | | * 添加取样记录管理 |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('system:samplingRecord:add')") |
| | | @Log(title = "取样记录信息-新增取样记录", businessType = BusinessType.INSERT) |
| | | @ApiOperation(value = "添加取样记录",response = TSamplingRecordDTO.class) |
| | | @PostMapping(value = "/api/t-sampling-record/add") |
| | | public R<Boolean> add(@RequestBody String param) { |
| | | TSamplingRecordDTO dto = JSON.parseObject(param,TSamplingRecordDTO.class); |
| | | // TODO 生成取样单编号 |
| | | samplingRecordService.save(dto); |
| | | List<TSamplingRecordOperation> samplingRecordOperations = dto.getSamplingRecordOperations(); |
| | | samplingRecordOperations.forEach(samplingRecordOperation -> { |
| | | samplingRecordOperation.setSamplingId(dto.getId()); |
| | | }); |
| | | samplingRecordOperationService.saveBatch(samplingRecordOperations); |
| | | return R.ok(); |
| | | } |
| | | |
| | | /** |
| | | * 修改取样记录 |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('system:samplingRecord:edit')") |
| | | @Log(title = "取样记录信息-修改取样记录", businessType = BusinessType.UPDATE) |
| | | @ApiOperation(value = "修改取样记录") |
| | | @PostMapping(value = "/api/t-sampling-record/update") |
| | | public R<Boolean> update(@RequestBody String param) { |
| | | TSamplingRecordDTO dto = JSON.parseObject(param,TSamplingRecordDTO.class); |
| | | samplingRecordService.updateById(dto); |
| | | samplingRecordOperationService.remove(Wrappers.lambdaQuery(TSamplingRecordOperation.class).eq(TSamplingRecordOperation::getSamplingId,dto.getId())); |
| | | List<TSamplingRecordOperation> samplingRecordOperations = dto.getSamplingRecordOperations(); |
| | | samplingRecordOperations.forEach(samplingRecordOperation -> { |
| | | samplingRecordOperation.setSamplingId(dto.getId()); |
| | | }); |
| | | samplingRecordOperationService.saveBatch(samplingRecordOperations); |
| | | return R.ok(); |
| | | } |
| | | |
| | | /** |
| | | * 修改取样操作记录 |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('system:samplingRecordOperation:edit')") |
| | | @Log(title = "取样记录信息-修改取样操作记录", businessType = BusinessType.UPDATE) |
| | | @ApiOperation(value = "修改取样操作记录") |
| | | @PostMapping(value = "/api/t-sampling-record/updateRecordOperation") |
| | | public R<Boolean> updateRecordOperation(@RequestBody String param) { |
| | | TSamplingRecordOperation operation = JSON.parseObject(param,TSamplingRecordOperation.class); |
| | | Long userId = tokenService.getLoginUser().getUserId(); |
| | | operation.setHandlePersonId(userId); |
| | | samplingRecordOperationService.updateById(operation); |
| | | return R.ok(); |
| | | } |
| | | |
| | | /** |
| | | * 修改取样操作记录 |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('system:samplingRecordOperation:edit')") |
| | | @Log(title = "取样记录信息-实验员提交取样记录", businessType = BusinessType.UPDATE) |
| | | @ApiOperation(value = "实验员提交取样记录") |
| | | @PostMapping(value = "/api/t-sampling-record/commitRecord") |
| | | public R<Boolean> commitRecord(@RequestBody String param) { |
| | | TSamplingRecord samplingRecord = JSON.parseObject(param,TSamplingRecord.class); |
| | | if(StringUtils.isBlank(samplingRecord.getCommitSign())){ |
| | | return R.fail("请提交实验员签字"); |
| | | } |
| | | Long userId = tokenService.getLoginUser().getUserId(); |
| | | samplingRecord.setCommitPersonId(userId); |
| | | samplingRecord.setStatus(2); |
| | | samplingRecord.setCommitTime(LocalDateTime.now()); |
| | | samplingRecordService.updateById(samplingRecord); |
| | | return R.ok(); |
| | | } |
| | | |
| | | /** |
| | | * 查看取样记录详情 |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('system:samplingRecord:detail')") |
| | | @ApiOperation(value = "查看取样记录详情") |
| | | @GetMapping(value = "/open/t-sampling-record/getDetailById") |
| | | public R<TSamplingRecordVO> getDetailById(@RequestParam String id) { |
| | | TSamplingRecord samplingRecord = samplingRecordService.getById(id); |
| | | TSamplingRecordVO samplingRecordVO = new TSamplingRecordVO(); |
| | | BeanUtils.copyProperties(samplingRecord, samplingRecordVO); |
| | | |
| | | // 查询取样操作记录 |
| | | samplingRecordVO.setSamplingRecordOperations(samplingRecordOperationService.list(Wrappers.lambdaQuery(TSamplingRecordOperation.class).eq(TSamplingRecordOperation::getSamplingId, id))); |
| | | |
| | | return R.ok(samplingRecordVO); |
| | | } |
| | | |
| | | /** |
| | | * 删除取样记录 |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('system:samplingRecord:delete')") |
| | | @Log(title = "取样记录信息-删除取样记录", businessType = BusinessType.DELETE) |
| | | @ApiOperation(value = "删除取样记录") |
| | | @DeleteMapping(value = "/open/t-sampling-record/deleteById") |
| | | public R<Boolean> deleteById(@RequestParam String id) { |
| | | // 删除取样操作记录 |
| | | samplingRecordOperationService.remove(Wrappers.lambdaQuery(TSamplingRecordOperation.class).eq(TSamplingRecordOperation::getSamplingId, id)); |
| | | return R.ok(samplingRecordService.removeById(id)); |
| | | } |
| | | |
| | | /** |
| | | * 批量删除取样记录 |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('system:samplingRecord:delete')") |
| | | @Log(title = "取样记录信息-删除取样记录", businessType = BusinessType.DELETE) |
| | | @ApiOperation(value = "批量删除取样记录") |
| | | @DeleteMapping(value = "/open/t-sampling-record/deleteByIds") |
| | | public R<Boolean> deleteByIds(@RequestBody List<String> ids) { |
| | | // 删除取样操作记录 |
| | | samplingRecordOperationService.remove(Wrappers.lambdaQuery(TSamplingRecordOperation.class).in(TSamplingRecordOperation::getSamplingId, ids)); |
| | | return R.ok(samplingRecordService.removeByIds(ids)); |
| | | } |
| | | |
| | | /** |
| | | * 批量送样 |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('system:samplingRecord:sendSamples')") |
| | | @Log(title = "取样记录信息-批量送样", businessType = BusinessType.UPDATE) |
| | | @ApiOperation(value = "批量送样") |
| | | @PostMapping(value = "/open/t-sampling-record/batchSendSamples") |
| | | public R<Boolean> batchSendSamples(@RequestBody String param) { |
| | | BatchSendSamplesDTO batchSendSamplesDTO = JSON.parseObject(param, BatchSendSamplesDTO.class); |
| | | Long userId = tokenService.getLoginUser().getUserId(); |
| | | // 批量送样 |
| | | samplingRecordOperationService.update(Wrappers.lambdaUpdate(TSamplingRecordOperation.class) |
| | | .eq(TSamplingRecordOperation::getId, batchSendSamplesDTO.getRecordOperationId()) |
| | | .set(TSamplingRecordOperation::getStatus, 2) |
| | | .set(TSamplingRecordOperation::getSendSign, batchSendSamplesDTO.getSendSign()) |
| | | .set(TSamplingRecordOperation::getSendTime, LocalDateTime.now()) |
| | | .set(TSamplingRecordOperation::getSendPersonId, userId)); |
| | | return R.ok(); |
| | | } |
| | | |
| | | /** |
| | | * 批量删除取样记录 |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('system:samplingRecord:collectSamples')") |
| | | @Log(title = "取样记录信息-批量收样", businessType = BusinessType.UPDATE) |
| | | @ApiOperation(value = "批量收样") |
| | | @PostMapping(value = "/open/t-sampling-record/batchCollectSamples") |
| | | public R<Boolean> batchCollectSamples(@RequestBody String param) { |
| | | BatchCollectSamplesDTO batchCollectSamplesDTO = JSON.parseObject(param, BatchCollectSamplesDTO.class); |
| | | Long userId = tokenService.getLoginUser().getUserId(); |
| | | // 批量送样 |
| | | samplingRecordOperationService.update(Wrappers.lambdaUpdate(TSamplingRecordOperation.class) |
| | | .eq(TSamplingRecordOperation::getId, batchCollectSamplesDTO.getRecordOperationId()) |
| | | .set(TSamplingRecordOperation::getStatus, 3) |
| | | .set(TSamplingRecordOperation::getReceiptsSign, batchCollectSamplesDTO.getReceiptsSign()) |
| | | .set(TSamplingRecordOperation::getReceiptsTime, LocalDateTime.now()) |
| | | .set(TSamplingRecordOperation::getReceiptsPersonId, userId)); |
| | | return R.ok(); |
| | | } |
| | | |
| | | } |
| | | |