liyong
16 小时以前 6b39b27a2807f4fb60e3b8ac12a1bb5deaad7775
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
package com.ruoyi.production.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.basic.dto.ProductModelDto;
import com.ruoyi.basic.mapper.ProductMapper;
import com.ruoyi.basic.mapper.ProductModelMapper;
import com.ruoyi.basic.pojo.Product;
import com.ruoyi.basic.pojo.ProductModel;
import com.ruoyi.production.dto.ProductStructureDto;
import com.ruoyi.production.mapper.ProductStructureMapper;
import com.ruoyi.production.pojo.ProductStructure;
import com.ruoyi.production.service.ProductStructureService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.HashMap;
import java.util.List;
 
@Service
@RequiredArgsConstructor
@Slf4j
public class ProductStructureServiceImpl extends ServiceImpl<ProductStructureMapper, ProductStructure> implements ProductStructureService {
 
    @Autowired
    private  ProductStructureMapper productStructureMapper;
    @Autowired
    private ProductModelMapper productModelMapper;
    @Autowired
    private ProductMapper productMapper;
 
    @Override
    public ProductModelDto listByproductModelId(Long productModelId) {
        ProductModel productModel = productModelMapper.selectById(productModelId);
        Product product = productMapper.selectById(productModel.getProductId());
        ProductModelDto productModelDto = new ProductModelDto();
        BeanUtils.copyProperties(productModel,productModelDto);
        productModelDto.setProductName(product.getProductName());
        List<ProductStructureDto> productStructureDtos = productStructureMapper.listByproductModelId(productModelId);
        productModelDto.setProductStructureList(productStructureDtos);
        return productModelDto;
    }
 
    @Override
    public Boolean addProductStructureDto(ProductStructureDto productStructureDto) {
        this.remove(new QueryWrapper<ProductStructure>().lambda().eq(ProductStructure::getParentId, productStructureDto.getParentId()));
        productStructureDto.getProductStructureList().forEach(productStructure -> {
            productStructure.setParentId(productStructureDto.getParentId());
        });
        return this.saveBatch(productStructureDto.getProductStructureList());
    }
}