package com.hzs.report.member.controller.manage;

import com.hzs.common.core.annotation.Log;
import com.hzs.common.core.enums.EOperationBusiness;
import com.hzs.common.core.enums.EOperationMethod;
import com.hzs.common.core.enums.EOperationModule;
import com.hzs.common.core.utils.StringUtils;
import com.hzs.common.core.utils.poi.ExcelUtil;
import com.hzs.common.core.web.controller.BaseController;
import com.hzs.common.core.web.page.TableDataInfo;
import com.hzs.common.security.utils.SecurityUtils;
import com.hzs.report.member.service.MemberReportService;
import com.hzs.report.member.vo.SmallAreaNewAddAchieveVO;
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;

import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

/**
 * 小区新增业绩统计
 *
 * @Description:
 * @Author: ljc
 * @Time: 2024/3/1 14:52
 * @Classname: SmallAreaNewAddAchieve
 * @Package_name: com.hzs.report.member.controller.manage
 */

@RequestMapping("/manager/small-achieve")
@RestController
public class SmallAreaNewAddAchieveController extends BaseController {


    @Autowired
    MemberReportService memberReportService;


    @Log(module = EOperationModule.STATISTIC_ANALYSIS, business = EOperationBusiness.SMALL_AREA_NEW_ACHIEVE, method = EOperationMethod.SELECT)
    @PostMapping("/achieve-list")
    public TableDataInfo addChieveList(@RequestBody SmallAreaNewAddAchieveVO addAchieveVO) {
        addAchieveVO.setPkCountry(SecurityUtils.getPkCountry());
        List<SmallAreaNewAddAchieveVO> areaNewAddAchieveVOList;
        if (StringUtils.isEmpty(addAchieveVO.getStartDate()) || StringUtils.isEmpty(addAchieveVO.getEndDate()) || null == addAchieveVO.getAchieve()) {
            areaNewAddAchieveVOList = new ArrayList<>();
        } else {
            startPage();
            areaNewAddAchieveVOList = memberReportService.selectSmallAreaNewAdd(addAchieveVO);
        }
        return getDataTable(areaNewAddAchieveVOList);
    }

    @Log(module = EOperationModule.STATISTIC_ANALYSIS, business = EOperationBusiness.SMALL_AREA_NEW_ACHIEVE, method = EOperationMethod.EXPORT)
    @PostMapping("/achieve-export")
    public void addChieveExport(HttpServletResponse response, SmallAreaNewAddAchieveVO addAchieveVO) {
        addAchieveVO.setPkCountry(SecurityUtils.getPkCountry());
        List<SmallAreaNewAddAchieveVO> areaNewAddAchieveVOList;
        if (StringUtils.isEmpty(addAchieveVO.getStartDate()) || StringUtils.isEmpty(addAchieveVO.getEndDate()) || null == addAchieveVO.getAchieve()) {
            areaNewAddAchieveVOList = new ArrayList<>();
        } else {
            areaNewAddAchieveVOList = memberReportService.selectSmallAreaNewAdd(addAchieveVO);
        }
        ExcelUtil<SmallAreaNewAddAchieveVO> util = new ExcelUtil<>(SmallAreaNewAddAchieveVO.class);
        util.exportExcel(response, areaNewAddAchieveVOList, "小区新增业绩");

    }


}
