package com.dgtly.companyext.service.impl;

import java.util.List;

import com.dgtly.common.constant.UserConstants;
import com.dgtly.common.utils.DateUtils;
import com.dgtly.common.utils.ShiroSaltUtil;
import com.dgtly.companyext.domain.CompanyExamine;
import com.dgtly.companyext.mapper.CompanyExamineMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.dgtly.companyext.mapper.CompanyReviewedMapper;
import com.dgtly.companyext.domain.CompanyReviewed;
import com.dgtly.companyext.service.ICompanyReviewedService;
import com.dgtly.common.core.text.Convert;
import org.springframework.transaction.annotation.Transactional;

/**
 * 商户扩展信息Service业务层处理
 * 
 * @author dgtly
 * @date 2020-02-13
 */
@Service
public class CompanyReviewedServiceImpl implements ICompanyReviewedService 
{
    @Autowired
    private CompanyReviewedMapper companyReviewedMapper;

    @Autowired
    private CompanyExamineMapper companyExamineMapper;

    /**
     * 查询商户扩展信息
     * 
     * @param id 商户扩展信息ID
     * @return 商户扩展信息
     */
    @Override
    public CompanyReviewed selectCompanyReviewedById(Long id)
    {
        return companyReviewedMapper.selectCompanyReviewedById(id);
    }

    /**
     * 查询商户扩展信息列表
     * 
     * @param companyReviewed 商户扩展信息
     * @return 商户扩展信息
     */
    @Override
    public List<CompanyReviewed> selectCompanyReviewedList(CompanyReviewed companyReviewed)
    {
        return companyReviewedMapper.selectCompanyReviewedList(companyReviewed);
    }

    /**
     * 新增商户扩展信息
     * 
     * @param companyReviewed 商户扩展信息
     * @return 结果
     */
    @Override
    public int insertCompanyReviewed(CompanyReviewed companyReviewed)
    {
        companyReviewed.setCreateTime(DateUtils.getNowDate());
        return companyReviewedMapper.insertCompanyReviewed(companyReviewed);
    }

    /**
     * 修改商户扩展信息
     * 
     * @param companyReviewed 商户扩展信息
     * @return 结果
     */
    @Override
    public int updateCompanyReviewed(CompanyReviewed companyReviewed)
    {
        companyReviewed.setUpdateTime(DateUtils.getNowDate());
        return companyReviewedMapper.updateCompanyReviewed(companyReviewed);
    }

    /**
     * 删除商户扩展信息对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteCompanyReviewedByIds(String ids)
    {
        return companyReviewedMapper.deleteCompanyReviewedByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除商户扩展信息信息
     * 
     * @param id 商户扩展信息ID
     * @return 结果
     */
    @Override
    public int deleteCompanyReviewedById(Long id)
    {
        return companyReviewedMapper.deleteCompanyReviewedById(id);
    }

    /**
     * 查询商户扩展信息
     *
     * @param companyId 商户ID
     * @return 商户扩展信息
     */
    @Override
    public CompanyReviewed selectCompanyReviewedByCompanyId(Long companyId) {
        return companyReviewedMapper.selectCompanyReviewedByCompanyId(companyId);
    }

    /**
     * @descption: 商家入驻时检测商户管理员是否在企业待审核列表中存在
     * @param:
     * @return:
     * @auther: qxp
     * @date: 2020-2-25
     */
    @Override
    public String checkLoginNameUnique(String loginName) {
        int count = companyReviewedMapper.checkLoginNameUnique(loginName);
        if (count > 0)
        {
            return UserConstants.USER_NAME_NOT_UNIQUE;
        }
        return UserConstants.USER_NAME_UNIQUE;
    }


    /**
     * @descption: 查询待审核列表，未审核排在前面
     * @param:
     * @return:
     * @auther: qxp
     * @date: 2020-2-25
     */
    @Override
    public List<CompanyReviewed> selectCompanyReviewedListWiteAudit(CompanyReviewed companyReviewed) {
        return companyReviewedMapper.selectCompanyReviewedListWiteAudit(companyReviewed);
    }

    /**
     * @descption: 拒绝申请
     * @param:
     * @return:
     * @auther: qxp
     * @date: 2020-2-25
     */
    @Override
    @Transactional
    public int refuse(CompanyExamine companyExamine) {
        CompanyReviewed cr = new CompanyReviewed();
        cr.setId(companyExamine.getCompanyReviewedId());
        cr.setStatus("2");
        cr.setUpdateBy(companyExamine.getCreateBy());
        companyReviewedMapper.updateCompanyReviewed(cr);

        return companyExamineMapper.insertCompanyExamine(companyExamine);
    }

    /**
     * @descption: 查询入驻申请公示列表
     * @param:
     * @return:
     * @auther: qxp
     * @date: 2020/3/3 13:25
     */
    @Override
    public List<CompanyReviewed> selectEnterPublicityList() {
        return companyReviewedMapper.selectEnterPublicityList();
    }

    /**
     * @descption: 查询商户信息变更记录
     * @param:
     * @return:
     * @auther: qxp
     * @date: 2020/3/3 13:25
     */
    @Override
    public List<CompanyReviewed> selectCompanyReviewedListById(CompanyReviewed cr) {
        return companyReviewedMapper.selectCompanyReviewedListById(cr);
    }
}
