package org.jeecg.modules.stm.audit.service.impl;

import org.jeecg.modules.stm.audit.entity.AuditComplianeItem;
import org.jeecg.modules.stm.audit.mapper.AuditComplianeItemMapper;
import org.jeecg.modules.stm.audit.service.IAuditComplianeItemService;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description: audit_compliane_item
 * @Author: jeecg-boot
 * @Date:   2024-08-23
 * @Version: V1.0
 */
@Service
public class AuditComplianeItemServiceImpl extends ServiceImpl<AuditComplianeItemMapper, AuditComplianeItem> implements IAuditComplianeItemService {

    @Override
    public  Map<Integer,Map<String,String>> queryAllActForItems(List<Integer> idList){
        List<Map<String,Object>> dataList = this.baseMapper.queryAllActForItems(idList);
        Map<Integer,Map<String,String>> retMap = new HashMap<>();
        for (Integer tId : idList) {
            List<String> listCaName = new ArrayList<>();
            List<String> listActId = new ArrayList<>();
            List<String> listCheckId = new ArrayList<>();
            for (Map<String, Object> map : dataList) {
                Integer tId1 = Integer.valueOf(map.get("citemid").toString());

                if(tId.intValue()==tId1.intValue()) {
                    String checkId = map.get("checkid").toString();
                    String actId = map.get("actId").toString();
                    String caName = map.get("caName").toString();
                    if(!listActId.contains(actId)) {
                        listActId.add(actId);
                        listCaName.add(caName);
                    }
                    if(!listCheckId.contains(checkId)) {
                        listCheckId.add(checkId);
                    }
                }
            }

            if(listCheckId.size()>0) {
                Map<String,String> strTmpMap = new HashMap<>();
                String checkIds = String.join(",", listCheckId);
                strTmpMap.put("checkIds",checkIds);

                if(listActId.size()>0) {
                    strTmpMap.put("caNames",String.join(",", listCaName));
                    strTmpMap.put("actIds",String.join(",", listActId));
                }
                retMap.put(tId,strTmpMap);
            }

        }

        return retMap;

    }
}
