package com.yuchen.saas.park.service.controller.property;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yuchen.saas.park.api.dto.property.CreateBillDto;
import com.yuchen.saas.park.api.dto.property.PropertyCycleCreateBillDto;
import com.yuchen.saas.park.api.entity.property.PropertyHouseBindFee;
import com.yuchen.saas.park.api.enums.property.CreateBillTypeEnum;
import com.yuchen.saas.park.service.service.property.IPropertyHouseBindFeeService;
import com.yuchen.saas.park.service.service.property.bill.PropertyBillFactoryService;
import org.nest.springwrap.core.mp.support.Query;
import org.nest.springwrap.core.tool.api.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/billTest")
public class BillTestController {
    @Autowired
    private IPropertyHouseBindFeeService propertyHouseBindFeeService;
    @Autowired
    private PropertyBillFactoryService propertyBillFactoryService;


    @PostMapping("/test")
    public R test(@RequestBody JSONObject json) {
        Query query = new Query();
        int size = 500;
        query.setCurrent(1);
        query.setSize(size);
        Page<PropertyHouseBindFee> page = propertyHouseBindFeeService.searchHouseBindCycleFeePage(query);
//        long total = page.getTotal();
//        long pageNo = (total / size) + (total % size == 0 ? 0 : 1);
//        for (int i = 0; i <pageNo; i ++) {
//        }

        page.getRecords().forEach(item -> {
            PropertyCycleCreateBillDto cycleCreateBillDto = new PropertyCycleCreateBillDto();
            cycleCreateBillDto.setHouseId(item.getHouseId());
            cycleCreateBillDto.setFeeId(item.getFeeStandardId());
            cycleCreateBillDto.setTestDate(json.getString("testDate"));
            CreateBillDto createBillDto = new CreateBillDto();
            createBillDto.setCreateBillTypeEnum(CreateBillTypeEnum.CYCLE);
            createBillDto.setCycleCreateBillDto(cycleCreateBillDto);
            propertyBillFactoryService.createBill(createBillDto);
        });

        return R.success();

    }
//
//    @GetMapping("/test2")
//    public R test2() {
//        billTaskService.updateArrearsStatus();
//        return R.success();
//    }




}
