package com.dgtly.web.controller.company;

import java.util.Date;
import java.util.List;

import com.dgtly.common.constant.UserConstants;
import com.dgtly.common.core.domain.Ztree;
import com.dgtly.common.utils.security.EncryptPassWordClass;
import com.dgtly.companyext.domain.CompanyExamine;
import com.dgtly.companyext.domain.CompanyReviewed;
import com.dgtly.companyext.service.ICompanyExamineService;
import com.dgtly.companyext.service.ICompanyReviewedService;
import com.dgtly.framework.util.ShiroUtils;
import com.dgtly.system.domain.SysDept;
import com.dgtly.system.domain.SysUser;
import com.dgtly.system.service.ISysDeptService;
import com.dgtly.system.service.ISysUserService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.dgtly.common.annotation.Log;
import com.dgtly.common.enums.BusinessType;
import com.dgtly.system.domain.SysCompany;
import com.dgtly.system.service.ISysCompanyService;
import com.dgtly.common.core.controller.BaseController;
import com.dgtly.common.core.domain.AjaxResult;
import com.dgtly.common.utils.poi.ExcelUtil;
import com.dgtly.common.core.page.TableDataInfo;

/**
 * 公司表Controller
 * 
 * @author dgtly
 * @date 2020-01-08
 */
@Controller
@RequestMapping("/company")
public class CompanyController extends BaseController
{
    private String prefix = "company";

    @Autowired
    private ISysCompanyService sysCompanyService;
    @Autowired
    private ISysDeptService deptService;
    @Autowired
    private ISysUserService userService;


    @Autowired
    private ICompanyReviewedService companyReviewedService;

    @Autowired
    private ICompanyExamineService companyExamineService;

    @RequiresPermissions("company:info:view")
    @GetMapping("/company")
    public String company()
    {
        return prefix + "/company";
    }

    /**
     * 查询公司表列表
     */
    @RequiresPermissions("system:company:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysCompany sysCompany)
    {
        startPage();
        List<SysCompany> list = sysCompanyService.selectSysCompanyListExRoot(sysCompany);
        return getDataTable(list);
    }

    /**
     * 查询公司表列表
     */
    @GetMapping("/tree")
    public Object select(SysCompany sysCompany)
    {
        return prefix + "/tree";
    };
    /**
     * 查询公司表列表
     */
    @GetMapping("/treeData")
    @ResponseBody
    public Object treeData(SysCompany sysCompany)
    {
        List<Ztree> list = sysCompanyService.selectSysCompanyTree(sysCompany);
        return list;
    }


    /**
     * @descption: 商户入驻审核
     * @param:
     * @return:
     * @auther: qxp
     * @date: 2020-2-25
     */
    @RequiresPermissions("company:enterexamine:view")
    @GetMapping("/enterexamine")
    public String enterexamine()
    {
        return prefix + "/enterexamine/reviewed";
    }

    /**
     * 查询商户扩展信息列表
     */
    @RequiresPermissions("company:enterexamine:list")
    @PostMapping("/enterexamine/list")
    @ResponseBody
    public TableDataInfo list(CompanyReviewed companyReviewed)
    {
        startPage();
        companyReviewed.setReason("0");
        List<CompanyReviewed> list = companyReviewedService.selectCompanyReviewedListWiteAudit(companyReviewed);
        return getDataTable(list);
    }

    /**
     * @descption: 商户审核
     * @param:
     * @return:
     * @auther: qxp
     * @date: 2020-2-25
     */
    @RequiresPermissions("company:enterexamine:approve")
    @GetMapping("/enterexamine/approvePage/{id}")
    public String approvePage(@PathVariable("id") Long id, ModelMap mmap)
    {
        CompanyReviewed companyReviewed = companyReviewedService.selectCompanyReviewedById(id);
        mmap.put("companyReviewed", companyReviewed);
        return prefix + "/enterexamine/approve";
    }



    /**
     * 审核商户入驻
     */
    @RequiresPermissions("companyext:enterexamine:approve")
    @Log(title = "审核商户入驻", businessType = BusinessType.UPDATE)
    @PostMapping("/enterexamine/approve")
    @ResponseBody
    public AjaxResult approve(CompanyExamine companyExamine)
    {
        companyExamine.setCreateBy(ShiroUtils.getLoginName());
        int i =0;
        if(companyExamine.getStatus().equals(1)){
            /*审核通过*/
            i=sysCompanyService.allowEnter(companyExamine);

        }else{
            /*审核拒绝*/
            i=companyReviewedService.refuseEnter(companyExamine);
        }
        return toAjax(i);
    }





}
