package com.ruoyi.web.controller.house;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.mapper.house.BusinessEntityInfoMapper;
import com.ruoyi.system.mapper.house.HouseResourceBusinessEntityInfoMappingMapper;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/houseResourceBusinessEntityInfoMapping")
public class HouseResourceBusinessEntityInfoMappingController {

    private final HouseResourceBusinessEntityInfoMappingMapper houseResourceBusinessEntityInfoMappingMapper;

    private final BusinessEntityInfoMapper businessEntityInfoMapper;

    public HouseResourceBusinessEntityInfoMappingController(HouseResourceBusinessEntityInfoMappingMapper houseResourceBusinessEntityInfoMappingMapper, BusinessEntityInfoMapper businessEntityInfoMapper) {
        this.houseResourceBusinessEntityInfoMappingMapper = houseResourceBusinessEntityInfoMappingMapper;
        this.businessEntityInfoMapper = businessEntityInfoMapper;
    }

    @PostMapping("/start")
    @Transactional(rollbackFor = Exception.class)
    public AjaxResult start() {
//        List<BusinessEntityInfo> businessEntityInfos = businessEntityInfoMapper.selectAllBusinessEntityInfos();
//        Map<String, List<BusinessEntityInfo>> group = businessEntityInfos.stream().collect(Collectors.groupingBy(BusinessEntityInfo::getHouseResourceId));
//        group.forEach((houseResourceId, businessEntityInfoList) -> {
//            System.out.println("当前处理houseId = " + houseResourceId);
//            if (!CollectionUtils.isEmpty(businessEntityInfoList)) {
//                for (BusinessEntityInfo businessEntityInfo : businessEntityInfoList) {
//                    HouseResourceBusinessEntityInfoMapping houseResourceBusinessEntityInfoMapping = new HouseResourceBusinessEntityInfoMapping();
//                    houseResourceBusinessEntityInfoMapping.setId(UUID.randomUUID().toString().replaceAll("-", ""));
//                    houseResourceBusinessEntityInfoMapping.setHouseResourceId(houseResourceId);
//                    houseResourceBusinessEntityInfoMapping.setBusinessEntityInfoId(businessEntityInfo.getId());
//                    houseResourceBusinessEntityInfoMappingMapper.insert(houseResourceBusinessEntityInfoMapping);
//                }
//            }
//        });
        System.out.println("数据处理完成");
        return AjaxResult.success();
    }
}
