package cn.com.countrygarden.bi.main.controller.dmn;

import cn.com.countrygarden.bi.main.core.Response;
import cn.com.countrygarden.bi.main.core.Result;
import cn.com.countrygarden.bi.main.dao.dmn.DnmDomainInformationMapper;

import cn.com.countrygarden.bi.main.dto.dmn.DnmDomainInformationAndCost;
import cn.com.countrygarden.bi.main.dto.dmn.DnmDomainInformationPage;
import cn.com.countrygarden.bi.main.model.dmn.DnmDomainInformation;
import cn.com.countrygarden.bi.main.service.dmn.CostInformationService;
import cn.com.countrygarden.bi.main.service.dmn.DnmDomainInformationService;
import cn.com.countrygarden.bi.main.service.dmn.DnmTableService;
import cn.com.countrygarden.bi.main.service.dmn.OrganizationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @program: backEnd
 * @description: 域名管理控制层
 * @author: bug大神
 * @create: 2024-07-24 17:39
 **/

@RestController("DnmDomainInformationController")
@RequestMapping("/api/dmn/DnmDomainInformationController")
public class DnmDomainInformationController {

    @Autowired
    private DnmDomainInformationService dmnDomainInformationService;


    @Autowired
    private DnmTableService dmnTableService;

    //查询
    @RequestMapping("/getDnmDomainInformation")
    public Result getDnmDomainInformation() {
        return dmnDomainInformationService.getDomainInformation();
    }

    //    分页查询，带高级搜索
    @RequestMapping("/selectDnmDomainInformationByPage")
    public Result searchDomainsByPage(
            @RequestParam(required = false) String domainName,
            @RequestParam(required = false) String domainCouponNumber,
            @RequestParam(required = false) String owner,
            @RequestParam(required = false) String auditStatus,
            @RequestParam(required = false) String startDate,
            @RequestParam(required = false) String endDate,
            @RequestParam(required = false) Integer pageSize,
            @RequestParam(required = false) Integer page
    ) {
        return dmnDomainInformationService.searchDomainsByPage(domainName, domainCouponNumber, owner, auditStatus, startDate, endDate, pageSize, page);

    }

    //    分页查询，带高级搜索
    @RequestMapping("/selectDnmDomainInformationByPageByLeader")
    public Result searchDomainsByPageByLeader(
            @RequestParam(required = false) String domainName,
            @RequestParam(required = false) String domainCouponNumber,
            @RequestParam(required = false) String owner,
            @RequestParam(required = false) String auditStatus,
            @RequestParam(required = false) String startDate,
            @RequestParam(required = false) String endDate,
            @RequestParam(required = false) Integer pageSize,
            @RequestParam(required = false) Integer page
    ) {
        return dmnDomainInformationService.searchDomainsByPageByLeader(domainName, domainCouponNumber, owner, auditStatus, startDate, endDate, pageSize, page);

    }


    //    插入域名信息
    @PostMapping("/insertDnmDomainInformation")
    public Result insertDnmDomainInformation(@RequestBody DnmDomainInformation domainInformation) {
        return dmnDomainInformationService.insertDomainInformation(domainInformation);
    }

    //    插入域名信息and消费字表
    @PostMapping("/insertDnmDomainInformationAndCost")
    public Result insertDnmDomainInformationAndCost(@RequestBody DnmDomainInformationAndCost dnmDomainInformationAndCost) {
        return dmnDomainInformationService.insertDnmDomainInformationAndCost(dnmDomainInformationAndCost);
    }

    //    获取域名信息and消费字表
    @GetMapping("/getDnmDomainInformationAndCost")
    public Result getDnmDomainInformationAndCost(@RequestParam(required = false) Integer id) {
        return dmnDomainInformationService.getDnmDomainInformationAndCost(id);
    }
    //    修改域名信息and消费字表
    @PostMapping("/updateDnmDomainInformationAndCost")
    public Result updateDnmDomainInformationAndCost(@RequestBody DnmDomainInformationAndCost dnmDomainInformationAndCost) {
        return dmnDomainInformationService.updateDnmDomainInformationAndCost(dnmDomainInformationAndCost);
    }

    //根据id修改域名信息
    @PostMapping("/updateDnmDomainInformationById")
    public Result updateDnmDomainInformation(@RequestBody DnmDomainInformation domainInformation) {
        return dmnDomainInformationService.updateDnmDomainInformation(domainInformation);
    }

    //根据id删除域名信息 将defalg置1
    @GetMapping("/deleteDnmDomainInformationById")
    public Result deleteDnmDomainInformation(@RequestParam(required = false) Integer id) {
        return dmnDomainInformationService.deleteDnmDomainInformation(id);
    }

    //根据id修改域名信息 为审核通过状态
    @GetMapping("/updateDnmDomainInformationById")
    public Result updateDnmDomainInformationById(@RequestParam(required = false) Integer id, Integer flag) {
        return dmnDomainInformationService.updateDnmDomainInformationById(id, flag);
    }

    // 检查域名是否重复
    @GetMapping("/checkDomainName")
    public Result checkDomainName(@RequestParam(required = false) String domainName) {
        return dmnDomainInformationService.checkDomainName(domainName);
    }
//    生成一个唯一个域名券号
    @GetMapping("/generateDomainCouponNumber")
    public Result generateDomainCouponNumber() {
        return dmnDomainInformationService.generateDomainCouponNumber();
    }
    //导出excel
    @GetMapping("/exportExcel")
    public Result exportExcel(HttpServletResponse response) {
        //实例化导出工具类
        dmnDomainInformationService.getDomainInformation();
        return null;
    }
}
