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
package com.by4cloud.platformx.business.service.impl;
 
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.by4cloud.platformx.admin.api.entity.SysDept;
import com.by4cloud.platformx.admin.api.vo.DeptExcelVO;
import com.by4cloud.platformx.business.dto.ContractSubjectMatterAddDTO;
import com.by4cloud.platformx.business.entity.ContractSubjectMatter;
import com.by4cloud.platformx.business.entity.Product;
import com.by4cloud.platformx.business.mapper.ContractSubjectMatterMapper;
import com.by4cloud.platformx.business.mapper.ProductMapper;
import com.by4cloud.platformx.business.service.ContractSubjectMatterService;
import com.by4cloud.platformx.business.vo.ContractSubjectMatterVo;
import com.by4cloud.platformx.business.vo.SubjectMatterExcelVO;
import com.by4cloud.platformx.common.core.util.R;
import com.by4cloud.platformx.common.data.datascope.DataScope;
import com.by4cloud.platformx.common.data.mybatis.BaseModel;
import com.by4cloud.platformx.common.excel.vo.ErrorMessage;
import com.by4cloud.platformx.common.security.util.SecurityUtils;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.validation.BindingResult;
 
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
 
/**
 * 合同标的物明细表
 *
 * @author platformx
 * @date 2026-04-29 16:39:29
 */
@Service
@RequiredArgsConstructor
public class ContractSubjectMatterServiceImpl extends ServiceImpl<ContractSubjectMatterMapper, ContractSubjectMatter> implements ContractSubjectMatterService {
 
    private final ProductMapper productMapper;
 
    @Override
    public R selectSubjectMatterProcess(Long id) {
        MPJLambdaWrapper<ContractSubjectMatter> wrapper = new MPJLambdaWrapper<ContractSubjectMatter>()
                .selectAll(ContractSubjectMatter.class)
                .eq(ContractSubjectMatter::getContractId,id)
                .orderByAsc(ContractSubjectMatter::getCreateTime);
        List<ContractSubjectMatterVo> matterVoList = baseMapper.selectJoinList(ContractSubjectMatterVo.class,wrapper);
        return R.ok(matterVoList);
    }
 
    @Override
    public R selectSubjectMatter(Long contractId) {
        return R.ok(baseMapper.selectListByScope(Wrappers.<ContractSubjectMatter>lambdaQuery().eq(ContractSubjectMatter::getContractId,contractId)
                .orderByAsc(ContractSubjectMatter::getCreateTime), DataScope.of("comp_id")));
    }
 
    @Override
    public R importSubjectMatter(List<SubjectMatterExcelVO> excelVOList, BindingResult bindingResult) {
        List<ErrorMessage> errorMessageList = (List<ErrorMessage>) bindingResult.getTarget();
        List<ContractSubjectMatterAddDTO> addDTOList = new ArrayList<>();
        for (SubjectMatterExcelVO item : excelVOList) {
            Set<String> errorMsg = new HashSet<>();
 
            Product one = productMapper.selectOne(Wrappers.<Product>lambdaQuery()
                    .eq(Product::getErpCode, item.getMaterialCode())
                    .eq(Product::getCompId, SecurityUtils.getUser().getCompId()));
 
            if (one == null) {
                errorMsg.add(item.getMaterialCode()+"erp编码不存在");
            }
            if (CollUtil.isEmpty(errorMsg)) {
                ContractSubjectMatterAddDTO addDTO = new ContractSubjectMatterAddDTO();
                addDTO.setMaterialCode(item.getMaterialCode());
                addDTO.setMaterialInternalName(one.getProductName());
                addDTO.setMaterialName(item.getMaterialName());
                addDTO.setUnitPrice(item.getUnitPrice());
                addDTO.setQuantity(item.getQuantity());
                addDTO.setSpecification(one.getProductType());
                addDTOList.add(addDTO);
            }
            else {
                // 数据不合法情况
                errorMessageList.add(new ErrorMessage(item.getLineNum(), errorMsg));
            }
        }
        if (CollUtil.isNotEmpty(errorMessageList)) {
            return R.failed(errorMessageList,"部门导入失败");
        }
        return R.ok(addDTOList, "部门导入成功");
    }
 
 
}