package com.persagy.dmp.rwd.digital.service.calstrategy;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.persagy.dmp.basic.dto.RelationCalRuleDTO;
import com.persagy.dmp.digital.entity.ObjectRelation;
import com.persagy.dmp.rwd.digital.dao.ObjectRelationMapper;
import com.persagy.dmp.rwd.digital.domain.CalculatingDTO;
import com.persagy.dmp.rwd.digital.service.CalculateService;
import com.persagy.dmp.rwd.digital.service.IObjectRelationService;
import com.persagy.dmp.rwd.digital.utils.ObjectDigitalCriteriaHelper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Set;

/***
 * Description: 楼层贯通关系计算
 * @author : lijie
 * @date :2021/10/9 16:26
 * Update By lijie 2021/10/9 16:26
 */
@Service
@Slf4j
@RequiredArgsConstructor
public class FlThroughFlRelCalculateServiceImpl implements CalculateService {

    private final IObjectRelationService objectRelationService;
    private final ObjectRelationMapper objectRelationMapper;


    /***
     * Description: 楼层贯通关系计算
     * @param calRule : 计算规则
     * @param calculatingDTO : 请求参数
     * @return : void
     * @author : lijie
     * @date :2021/10/9 16:26
     * Update By lijie 2021/10/9 16:26
     */
    @Override
    public void calculateRelation(RelationCalRuleDTO calRule, CalculatingDTO calculatingDTO) {
        // 1.根据图类型编码,边类型编码,relValue,项目id,集团编码删除关系
        deleteRelDataByCondition(calculatingDTO);
        // 2.调用接口批量生成关系
        objectRelationMapper.insertObjectRelationForFlThroughFl(calculatingDTO);
    }

    /***
     * Description: 根据请求参数和id集合删除关系
     * @param calculatingDTO : 请求参数
     * @return : void
     * @author : lijie
     * @date :2021/9/11 16:13
     * Update By lijie 2021/9/11 16:13
     */
    private void deleteRelDataByCondition(CalculatingDTO calculatingDTO) {
        QueryWrapper<ObjectRelation> queryWrapper = ObjectDigitalCriteriaHelper.createCommonQueryWrapper(null,calculatingDTO);
        queryWrapper.eq(StrUtil.toUnderlineCase(ObjectRelation.GRAPH_CODE_HUM),calculatingDTO.getGraphCode());
        queryWrapper.eq(StrUtil.toUnderlineCase(ObjectRelation.REL_CODE_HUM),calculatingDTO.getRelCode());
        objectRelationService.remove(queryWrapper);
    }
}
