SampleManagementServiceImpl.java 4.82 KB
Newer Older
高滢's avatar
高滢 committed
1 2
package com.ruoyi.service.impl;

3
import java.util.ArrayList;
高滢's avatar
高滢 committed
4 5 6 7 8 9
import java.util.List;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
高滢's avatar
高滢 committed
10
import com.ruoyi.domain.Sample;
11
import com.ruoyi.domain.vo.SampleTaskVo;
高滢's avatar
高滢 committed
12
import com.ruoyi.mapper.SampleManagementMapper;
13
import com.ruoyi.mapper.TaskSampleRelationMapper;
高滢's avatar
高滢 committed
14 15 16 17 18 19 20 21 22 23 24 25 26 27
import com.ruoyi.service.SampleManagementService;
import com.ruoyi.web.request.SampleManagementRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 样品管理Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-01-29
 */
@Service
@Transactional
高滢's avatar
高滢 committed
28
public class SampleManagementServiceImpl extends ServiceImpl<SampleManagementMapper, Sample> implements SampleManagementService
高滢's avatar
高滢 committed
29 30 31 32
{
    @Autowired
    private SampleManagementMapper sampleManagementMapper;

33 34 35
    @Autowired
    private TaskSampleRelationMapper taskSampleRelationMapper;

高滢's avatar
高滢 committed
36 37 38 39 40 41 42
    /**
     * 查询样品管理
     * 
     * @param id 样品管理主键
     * @return 样品管理
     */
    @Override
高滢's avatar
高滢 committed
43
    public Sample selectSampleManagementById(Long id)
高滢's avatar
高滢 committed
44 45 46 47 48 49 50 51 52 53 54
    {
        return sampleManagementMapper.selectSampleManagementById(id);
    }

    /**
     * 查询样品管理列表
     * 
     * @param sampleManagementRequest 样品管理
     * @return 样品管理
     */
    @Override
高滢's avatar
高滢 committed
55
    public List<Sample> selectSampleManagementList(SampleManagementRequest sampleManagementRequest)
高滢's avatar
高滢 committed
56
    {
57 58 59 60 61
        List<Sample> list = sampleManagementMapper.selectSampleManagementList(sampleManagementRequest);
        if(list.size()>0){
            setSampleTask(list);
        }
        return list;
高滢's avatar
高滢 committed
62 63 64 65 66 67 68 69 70
    }

    /**
     * 新增样品管理
     * 
     * @param sampleManagement 样品管理
     * @return 结果
     */
    @Override
高滢's avatar
高滢 committed
71
    public int insertSampleManagement(Sample sampleManagement)
高滢's avatar
高滢 committed
72 73
    {
        // 判断车辆识别码是否重复
高滢's avatar
高滢 committed
74
        if(Sample.SAMPLE_FLAG_CAR.equals(sampleManagement.getFlag())){
75 76 77 78
            int dentificationCode = sampleManagementMapper.selectIdentificationCodeCount(sampleManagement);
            if(dentificationCode>0){
                throw new ServiceException("车辆识别码已存在");
            }
高滢's avatar
高滢 committed
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
        }
        // 判断样品编号是否存在
        int sampleNumber = sampleManagementMapper.selectSampleNumberCount(sampleManagement);
        if(sampleNumber>0){
            throw new ServiceException("样品编号已存在");
        }
        sampleManagement.setCreateBy(String.valueOf(SecurityUtils.getUserId()));
        sampleManagement.setCreateTime(DateUtils.getNowDate());
        return sampleManagementMapper.insertSampleManagement(sampleManagement);
    }

    /**
     * 修改样品管理
     * 
     * @param sampleManagement 样品管理
     * @return 结果
     */
    @Override
高滢's avatar
高滢 committed
97
    public int updateSampleManagement(Sample sampleManagement)
高滢's avatar
高滢 committed
98 99
    {
        // 判断车辆识别码是否重复
高滢's avatar
高滢 committed
100
        if(Sample.SAMPLE_FLAG_CAR.equals(sampleManagement.getFlag())){
101 102 103 104
            int dentificationCode = sampleManagementMapper.selectIdentificationCodeCount(sampleManagement);
            if(dentificationCode>0){
                throw new ServiceException("车辆识别码已存在");
            }
高滢's avatar
高滢 committed
105 106 107 108 109 110 111 112 113 114
        }
        // 判断样品编号是否存在
        int sampleNumber = sampleManagementMapper.selectSampleNumberCount(sampleManagement);
        if(sampleNumber>0){
            throw new ServiceException("样品编号已存在");
        }
        sampleManagement.setUpdateBy(String.valueOf(SecurityUtils.getUserId()));
        sampleManagement.setUpdateTime(DateUtils.getNowDate());
        return sampleManagementMapper.updateSampleManagement(sampleManagement);
    }
高滢's avatar
高滢 committed
115 116 117 118 119 120 121 122

    /**
     * 根据车辆识别码和样品编号查询样品信息
     * */
    @Override
    public List<Sample> selectSampleList(SampleManagementRequest sampleManagementRequest){
        return sampleManagementMapper.selectSampleList(sampleManagementRequest);
    }
123

124 125 126

    /**
     * 给样品的数据赋值任务集合*/
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
    public void setSampleTask(List<Sample> sampleList){
        List<Long> listId = new ArrayList<>();
        for(Sample sample : sampleList){
            listId.add(sample.getId());
        }
        List<SampleTaskVo> sampleTaskVoList = taskSampleRelationMapper.selectTaskBysampleId(listId);
        for(Sample sample : sampleList){
            List<SampleTaskVo> sampleTaskVos = new ArrayList<>();
            for (SampleTaskVo sampleTaskVo : sampleTaskVoList){
                if(sampleTaskVo.getSampleId().equals(sample.getId())){
                    sampleTaskVos.add(sampleTaskVo);
                }
            }
            sample.setTaskSampleRelation(sampleTaskVos);
        }
    }
高滢's avatar
高滢 committed
143
}