package cn.cslg.report.service.business;

import cn.cslg.report.entity.AssoComapareFiel;
import cn.cslg.report.entity.Report;
import cn.cslg.report.entity.asso.AssoTaskPatentSplit;
import cn.cslg.report.entity.asso.AssoTaskPersonel;
import cn.cslg.report.mapper.AssoComapareFielMapper;
import cn.cslg.report.mapper.AssoTaskPatentSplitMapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@SuppressWarnings({"all"})
@Service
@Slf4j
@RequiredArgsConstructor(onConstructor_ = {@Lazy})
public class AssoTaskPatentSplitService extends ServiceImpl<AssoTaskPatentSplitMapper, AssoTaskPatentSplit> {
 private final AssoTaskPersonelService assoTaskPersonelService;
 private final FeatureService featureService;
 private final ReportService reportService;

    /**
     *
     * @param reportId
     * @param patentNo
     * @return
     * @autor lrj
     * @description 查找任务专利的拆分详情
     */
    @Transactional(rollbackFor = Exception.class)
    public Map<String,Object> getSplitMessage(Integer taskId, String patentNo,Integer reportId) {
        if (taskId != null) {
            Map<String, Object> map = new HashMap<>();
            AssoTaskPatentSplit assoTaskPatentSplit = assoTaskPersonelService.getBaseMapper().getSplitMessage(patentNo, taskId);
            if (assoTaskPatentSplit != null) {
                map.put("splitBy", assoTaskPatentSplit.getSplitBy());
                map.put("splitType", assoTaskPatentSplit.getSplitType());
            } else {
                map.put("splitBy", null);
                map.put("splitType", null);
            }
            return map;
        }else {
            Map<String, Object> map = new HashMap<>();
            LambdaQueryWrapper<Report> queryWrapper=new LambdaQueryWrapper<>();
            queryWrapper.eq(Report::getId,reportId);
            Report report = reportService.list(queryWrapper).get(0);
            if (report != null) {
                map.put("splitBy", report.getSplitBy());
                map.put("splitType", report.getSplitType());
            }
            else {
                map.put("splitBy", null);
                map.put("splitType", null);
            }

            return map;
        }
    }

}
