//package com.crunii.micro.service.sysmgr.service.impl;
//
//import com.crunii.micro.common.dto.OrderProp;
//import com.crunii.micro.common.exception.BusinessException;
//import com.crunii.micro.domain.entity.main.YcqDynamicFormConfig;
//import com.crunii.micro.domain.entity.main.YcqDynamicFormContent;
//import com.crunii.micro.domain.repo.main.YcqDynamicFormContentRepo;
//import com.crunii.micro.service.sysmgr.api.domain.dto.form.YcqDynamicFormContentDTO;
//import com.crunii.micro.service.sysmgr.api.domain.dto.form.YcqDynamicFormContentVO;
//import com.crunii.micro.service.sysmgr.api.domain.vo.YcqDynamicFormContentDetailVO;
//import com.crunii.micro.service.sysmgr.jdbc.YcqDynamicFormConfigDao;
//import com.crunii.micro.service.sysmgr.jdbc.YcqDynamicFormContentDao;
//import com.crunii.micro.service.sysmgr.service.YcqDynamicFormContentService;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.BeanUtils;
//import org.springframework.stereotype.Service;
//import org.springframework.util.CollectionUtils;
//
//import javax.annotation.Resource;
//import javax.transaction.Transactional;
//import java.util.*;
//import java.util.function.Function;
//import java.util.stream.Collectors;
//
///**
// * @author 15294
// */
//@Service
//@Slf4j
//public class YcqDynamicFormContentServiceImpl implements YcqDynamicFormContentService {
//
//
//    @Resource
//    private YcqDynamicFormContentRepo repo;
//
//    @Resource
//    private YcqDynamicFormConfigDao configJdbc;
//
//    @Resource
//    private YcqDynamicFormContentDao contentDao;
//
//    @Override
//    @Transactional
//    public YcqDynamicFormContentVO insert(YcqDynamicFormContentDTO dto, Integer loginId){
//        YcqDynamicFormContent ycqDynamicFormContent = new YcqDynamicFormContent();
//        BeanUtils.copyProperties(dto, ycqDynamicFormContent);
//        ycqDynamicFormContent.setCreateId(loginId);
//        ycqDynamicFormContent.setCreateTime(new Date());
//        YcqDynamicFormContent ycqDynamicFormContent1 = repo.saveAndFlush(ycqDynamicFormContent);
//        YcqDynamicFormContentVO result = new YcqDynamicFormContentVO();
//        BeanUtils.copyProperties(ycqDynamicFormContent1, result);
//        return result;
//    }
//
//
//    @Override
//    public List<YcqDynamicFormContentDetailVO> getByConfigId(Long configId){
//        List<YcqDynamicFormContent> byProp = repo.findByProp("configId", configId, new OrderProp("createTime", false));
//        if (CollectionUtils.isEmpty(byProp)){
//            return Collections.emptyList();
//        }
//
//        // 根据configId查询配置表的表单json
//        Set<Long> collect = byProp.stream().map(YcqDynamicFormContent::getConfigId).collect(Collectors.toSet());
//        List<YcqDynamicFormConfig> ycqDynamicFormConfigs = configJdbc.listByIdList(new ArrayList<>(collect));
//        Map<Long, YcqDynamicFormConfig> configMap = ycqDynamicFormConfigs.stream().collect(Collectors.toMap(YcqDynamicFormConfig::getId, Function.identity()));
//        List<YcqDynamicFormContentDetailVO> result = new ArrayList<>(byProp.size());
//        for (YcqDynamicFormContent item : byProp) {
//            YcqDynamicFormContentDetailVO ycqDynamicFormContentDetailVO = new YcqDynamicFormContentDetailVO();
//            BeanUtils.copyProperties(item, ycqDynamicFormContentDetailVO);
//            YcqDynamicFormConfig ycqDynamicFormConfig = configMap.get(item.getConfigId());
//            if (null != ycqDynamicFormConfig){
//                ycqDynamicFormContentDetailVO.setHtml(ycqDynamicFormConfig.getHtml());
//            }
//            result.add(ycqDynamicFormContentDetailVO);
//        }
//        return result;
//    }
//
//    @Override
//    public List<YcqDynamicFormContentDetailVO> getByBusinessIds(List<Long> ids){
//        if (CollectionUtils.isEmpty(ids)){
//            throw new BusinessException("入参不能为空");
//        }
//        List<YcqDynamicFormContent> byProp = contentDao.listByBusinessIdList(ids);
//        if (CollectionUtils.isEmpty(byProp)){
//            return Collections.emptyList();
//        }
//        // 根据configId查询配置表的表单json
//        Set<Long> collect = byProp.stream().map(YcqDynamicFormContent::getConfigId).collect(Collectors.toSet());
//        List<YcqDynamicFormConfig> ycqDynamicFormConfigs = configJdbc.listByIdList(new ArrayList<>(collect));
//        Map<Long, YcqDynamicFormConfig> configMap = ycqDynamicFormConfigs.stream().collect(Collectors.toMap(YcqDynamicFormConfig::getId, Function.identity()));
//        List<YcqDynamicFormContentDetailVO> result = new ArrayList<>(byProp.size());
//        for (YcqDynamicFormContent item : byProp) {
//            YcqDynamicFormContentDetailVO ycqDynamicFormContentDetailVO = new YcqDynamicFormContentDetailVO();
//            BeanUtils.copyProperties(item, ycqDynamicFormContentDetailVO);
//            YcqDynamicFormConfig ycqDynamicFormConfig = configMap.get(item.getConfigId());
//            if (null != ycqDynamicFormConfig){
//                ycqDynamicFormContentDetailVO.setHtml(ycqDynamicFormConfig.getHtml());
//            }
//            result.add(ycqDynamicFormContentDetailVO);
//        }
//        return result;
//    }
//
//    @Override
//    public YcqDynamicFormContentDetailVO getById(Long id) {
//        YcqDynamicFormContent byId = repo.getById(id);
//        YcqDynamicFormContentDetailVO ycqDynamicFormContentDetailVO = new YcqDynamicFormContentDetailVO();
//        BeanUtils.copyProperties(byId, ycqDynamicFormContentDetailVO);
//        List<YcqDynamicFormConfig> ycqDynamicFormConfigs = configJdbc.listByIdList(Collections.singletonList(byId.getConfigId()));
//        Map<Long, YcqDynamicFormConfig> configMap = ycqDynamicFormConfigs.stream().collect(Collectors.toMap(YcqDynamicFormConfig::getId, Function.identity()));
//        YcqDynamicFormConfig ycqDynamicFormConfig = configMap.get(byId.getConfigId());
//        if (null != ycqDynamicFormConfig){
//            ycqDynamicFormContentDetailVO.setHtml(ycqDynamicFormConfig.getHtml());
//        }
//        return ycqDynamicFormContentDetailVO;
//    }
//
//    @Override
//    public List<YcqDynamicFormContentDetailVO> getByIds(List<Long> ids) {
//        List<YcqDynamicFormContent> byProp = contentDao.listByIdList(ids);
//        if (CollectionUtils.isEmpty(byProp)){
//            return Collections.emptyList();
//        }
//        // 根据configId查询配置表的表单json
//        Set<Long> collect = byProp.stream().map(YcqDynamicFormContent::getConfigId).collect(Collectors.toSet());
//        List<YcqDynamicFormConfig> ycqDynamicFormConfigs = configJdbc.listByIdList(new ArrayList<>(collect));
//        Map<Long, YcqDynamicFormConfig> configMap = ycqDynamicFormConfigs.stream().collect(Collectors.toMap(YcqDynamicFormConfig::getId, Function.identity()));
//        List<YcqDynamicFormContentDetailVO> result = new ArrayList<>(byProp.size());
//        for (YcqDynamicFormContent item : byProp) {
//            YcqDynamicFormContentDetailVO ycqDynamicFormContentDetailVO = new YcqDynamicFormContentDetailVO();
//            BeanUtils.copyProperties(item, ycqDynamicFormContentDetailVO);
//            YcqDynamicFormConfig ycqDynamicFormConfig = configMap.get(item.getConfigId());
//            if (null != ycqDynamicFormConfig){
//                ycqDynamicFormContentDetailVO.setHtml(ycqDynamicFormConfig.getHtml());
//            }
//            result.add(ycqDynamicFormContentDetailVO);
//        }
//        return result;
//    }
//}
