com.youanmi.scrm.smp.facade.org.OrgInfoFacade.java Source code

Java tutorial

Introduction

Here is the source code for com.youanmi.scrm.smp.facade.org.OrgInfoFacade.java

Source

/*
 * ??OrgInfoFacade.java
 * ????
 * tanguojun
 * 20161221
 * 
 */
package com.youanmi.scrm.smp.facade.org;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

import javax.annotation.Resource;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.youanmi.commons.base.exception.ViewExternalDisplayException;
import com.youanmi.commons.base.helper.ValidateViewExceptionUtils;
import com.youanmi.commons.base.utils.StringUtil;
import com.youanmi.commons.base.vo.PageBean;
import com.youanmi.scrm.api.account.constants.AccountTableConstants;
import com.youanmi.scrm.api.account.dto.org.OrgDetailInfoDto;
import com.youanmi.scrm.api.account.dto.org.OrgExpireTimeDto;
import com.youanmi.scrm.api.account.dto.org.OrgInfoDto;
import com.youanmi.scrm.api.account.dto.org.OrgPostDto;
import com.youanmi.scrm.api.account.dto.org.OrgStaffDto;
import com.youanmi.scrm.api.account.dto.user.UserInfoDto;
import com.youanmi.scrm.api.account.service.org.IOrgDetailInfoService;
import com.youanmi.scrm.api.account.service.org.IOrgExpireTimeService;
import com.youanmi.scrm.api.account.service.org.IOrgInfoService;
import com.youanmi.scrm.api.account.service.org.IOrgPostService;
import com.youanmi.scrm.api.account.service.org.IOrgStaffService;
import com.youanmi.scrm.api.account.service.user.IUserInfoService;
import com.youanmi.scrm.api.auth.po.permission.PermissionInfoPo;
import com.youanmi.scrm.api.auth.po.permission.PostRolePo;
import com.youanmi.scrm.api.auth.po.permission.RoleInfoPo;
import com.youanmi.scrm.api.auth.po.permission.RolePermissionPo;
import com.youanmi.scrm.api.auth.service.permission.IPermissionInfoService;
import com.youanmi.scrm.api.auth.service.permission.IPostRoleService;
import com.youanmi.scrm.api.auth.service.permission.IRoleInfoService;
import com.youanmi.scrm.api.auth.service.permission.IRolePermissionService;
import com.youanmi.scrm.api.data.dto.industry.IndustryDto;
import com.youanmi.scrm.api.data.service.industry.IIndustryService;
import com.youanmi.scrm.commons.constants.result.ResultCode;
import com.youanmi.scrm.commons.util.object.BeanCopyUtils;
import com.youanmi.scrm.commons.util.string.AssertUtils;
import com.youanmi.scrm.commons.util.string.MatcherUtils;
import com.youanmi.scrm.smp.constants.SmpConstants;
import com.youanmi.scrm.smp.constants.SmpTableConstants;
import com.youanmi.scrm.smp.dto.param.ChangeShopParam;
import com.youanmi.scrm.smp.dto.param.OrgDetailParam;
import com.youanmi.scrm.smp.dto.param.OrgInfoParam;
import com.youanmi.scrm.smp.dto.param.ShopDetailInfoParam;
import com.youanmi.scrm.smp.dto.token.UserTokenDto;
import com.youanmi.scrm.smp.po.address.GeogAreaPo;
import com.youanmi.scrm.smp.po.address.GeogCityPo;
import com.youanmi.scrm.smp.po.address.GeogProvincePo;
import com.youanmi.scrm.smp.service.VarifyCodeService;
import com.youanmi.scrm.smp.service.address.GeogAreaService;
import com.youanmi.scrm.smp.service.address.GeogCityService;
import com.youanmi.scrm.smp.service.address.GeogProvinceService;
import com.youanmi.scrm.smp.service.token.UserTokenThreadLocal;

/**
 * 
 * 
 * @author tanguojun 20161221
 * @version 1.0.0
 */
@Service
public class OrgInfoFacade {
    /**
     * 
     */
    private static final Logger LOG = LoggerFactory.getLogger(OrgInfoFacade.class);

    @Resource(name = "orgInfoService")
    private IOrgInfoService orgInfoService;

    @Resource(name = "orgDetailInfoService")
    private IOrgDetailInfoService orgDetailInfoService;

    @Resource
    private IOrgStaffService orgStaffService;

    @Resource
    private GeogProvinceService geogProvinceService;

    @Resource
    private GeogCityService geogCityService;

    @Resource
    private GeogAreaService geogAreaService;

    @Resource
    private IUserInfoService userInfoService;

    @Resource
    private IOrgPostService orgPostService;

    @Resource
    private IRoleInfoService roleInfoService;

    @Resource
    private IPostRoleService postRoleService;

    @Resource
    private IPermissionInfoService permissionInfoService;

    @Resource
    private IRolePermissionService rolePermissionService;

    @Resource
    private VarifyCodeService varifyCodeService;

    @Resource
    private IOrgExpireTimeService orgExpireTimeService;

    @Resource
    private IIndustryService industryService;

    /**
     * ??
     *
     * @return ?map
     * @author tanguojun on 20161221
     */
    public Map<String, Object> getOrgInfoByUser() {

        UserTokenDto userTokenDto = UserTokenThreadLocal.get();

        Map<String, Object> result = new HashMap<>();

        // id
        Long orgId = userTokenDto.getOrgId();

        // ??
        OrgInfoDto orgInfoDto = orgInfoService.getOrgAndTopOrgInfoById(orgId);

        // ?,,,
        if (orgInfoDto == null) {
            throw new ViewExternalDisplayException(ResultCode.System.SYSTEM_ERROR);
        }

        // 
        OrgDetailInfoDto orgDetailInfo = orgDetailInfoService.getOrgDetailByOrgId(orgId);

        result.put("id", orgInfoDto.getId());
        result.put("orgLevel", orgInfoDto.getOrgLevel());
        result.put("orgType", orgInfoDto.getOrgType());
        result.put("topOrgId", orgInfoDto.getTopOrgId());
        result.put("orgName", orgInfoDto.getOrgName());
        result.put("orgFullName", orgInfoDto.getOrgFullName());

        // ???
        if (!Objects.equals(orgInfoDto.getOrgType(), AccountTableConstants.Org.ORG_TYPE_SINGLE_SHOP)
                && orgInfoDto.getTopOrgInfo() != null) {
            result.put("topOrgName", orgInfoDto.getTopOrgInfo().getOrgName());
            result.put("topOrgFullName", orgInfoDto.getTopOrgInfo().getOrgFullName());
        }

        // ??
        if (orgDetailInfo != null) {
            result.put("address", orgDetailInfo.getAddress());
            result.put("areaId", orgDetailInfo.getAreaId());
            result.put("areaName", orgDetailInfo.getAreaName());
            result.put("businessLicense", orgDetailInfo.getBusinessLicense());
            result.put("cityId", orgDetailInfo.getCityId());
            result.put("cityName", orgDetailInfo.getCityName());
            result.put("provinceId", orgDetailInfo.getProvinceId());
            result.put("provinceName", orgDetailInfo.getProvinceName());
        }

        return result;
    }

    /**
     * ?
     * 
     * @return list
     * @author liubing
     */
    public List<OrgInfoDto> getDirectOrg() {
        try {
            return orgInfoService.getDirectOrg(UserTokenThreadLocal.get().getTopOrgId());
        } catch (Exception e) {
            LOG.error(e.getMessage(), e);
        }
        return new ArrayList<>();
    }

    /**
     * 
     * 
     * @param pageBean 
     * @return pageBean
     * @author liubing
     */
    public PageBean<OrgInfoDto> getShopList(PageBean<OrgInfoDto> pageBean) {
        try {
            return orgInfoService.getShopList(pageBean);
        } catch (Exception e) {
            LOG.error(e.getMessage(), e);
            throw new ViewExternalDisplayException(ResultCode.Org.GET_LIST_FAIL);
        }
    }

    /**
     * ?
     * 
     * @param shopDetailInfo ?
     * @author liubing
     */
    public void addOrg(ShopDetailInfoParam shopDetailInfo) {

        checkParam(shopDetailInfo);
        /*
         * ??
         */
        /*
         * if (!varifyCodeService.getCodeValue(shopDetailInfo.getVerifyValue()))
         * { // ?? throw new
         * ViewExternalDisplayException(ResultCode.System.VERIFY_CODE_ERROR); }
         */
        /*
         * ???
         */
        OrgInfoDto orgById = orgInfoService.getOrgById(shopDetailInfo.getParentOrgId());
        if (null == orgById || !UserTokenThreadLocal.get().getTopOrgId().equals(orgById.getTopOrgId())) {
            throw new ViewExternalDisplayException(ResultCode.Org.DEPARTMENT_NOT_EXIST);
        }
        /*
         * ?
         */
        Byte orgChildOrgType = orgInfoService.getOrgChildOrgType(shopDetailInfo.getParentOrgId());
        if (null != orgChildOrgType && orgChildOrgType.equals(AccountTableConstants.Org.ORG_TYPE_CHAIN_DEPART)) {
            throw new ViewExternalDisplayException(ResultCode.Org.DIRECT_ORG_HAS_DEPART);
        }
        /*
         * ??????
         */
        List<Long> shopByTopOrgAndName = orgInfoService
                .getShopByTopOrgAndName(UserTokenThreadLocal.get().getTopOrgId(), shopDetailInfo.getOrgName());
        if (AssertUtils.notNull(shopByTopOrgAndName)) {
            throw new ViewExternalDisplayException(ResultCode.Org.ORG_NAME_REPEAT);
        }
        try {
            OrgInfoDto orgInfo = BeanCopyUtils.map(shopDetailInfo, OrgInfoDto.class);
            // ?
            orgInfo.setOrgType(AccountTableConstants.Org.ORG_TYPE_CHAIN_SHOP);
            // ?
            Long topOrgId = UserTokenThreadLocal.get().getTopOrgId();
            String orgAccount = userInfoService.getCommercialTenantCode(topOrgId);
            orgInfo.setOrgAccount(orgAccount);
            /*
             * ??
             */
            Long orgId = orgInfoService.addShopOrg(orgInfo);
            OrgDetailInfoDto detailInfoDto = BeanCopyUtils.map(shopDetailInfo, OrgDetailInfoDto.class);
            detailInfoDto.setOrgId(orgId);
            orgDetailInfoService.addOrgDetailInfo(detailInfoDto);

            /*
             * ????
             */
            addAdminOrManager(orgId, topOrgId, AccountTableConstants.User.USER_TYPE_SPECIAL,
                    AccountTableConstants.Post.ADMIN, AccountTableConstants.Post.POST_TYPE_ADMIN,
                    shopDetailInfo.getOrgName(), orgAccount);
            /*
             * 
             */
            addAdminOrManager(orgId, topOrgId, AccountTableConstants.User.USER_TYPE_GENERAL,
                    AccountTableConstants.Post.MANAGER, AccountTableConstants.Post.POST_TYPE_SHOP_MANAGER,
                    shopDetailInfo.getManager(), userInfoService.getCommercialTenantCode(topOrgId));

        } catch (Exception e) {
            LOG.error(e.getMessage(), e);
            throw new ViewExternalDisplayException(ResultCode.Org.ADD_ORG_FAIL);
        }
    }

    /**
     * ?
     * 
     * @param shopDetailInfo ??
     */
    private void checkParam(ShopDetailInfoParam shopDetailInfo) {
        if (AssertUtils.isNull(shopDetailInfo.getOrgName())) {
            throw new ViewExternalDisplayException(ResultCode.System.PARAMETER_NOT_NULL, "??");
        }
        // ??10?
        if (shopDetailInfo.getOrgName().length() > AccountTableConstants.Org.MAX_ORG_NAME_LENGTH) {
            throw new ViewExternalDisplayException(ResultCode.System.PARAMETER_LENGTH_BEYOND, "??");
        }
        if (AssertUtils.isNull(shopDetailInfo.getBusinessLicense())) {
            throw new ViewExternalDisplayException(ResultCode.System.PARAMETER_NOT_NULL, "?");
        }
        // ?15?
        if (shopDetailInfo.getBusinessLicense().length() > AccountTableConstants.Org.MAX_LICENSE_LENGTH) {
            throw new ViewExternalDisplayException(ResultCode.System.PARAMETER_LENGTH_BEYOND, "?");
        }
        if (AssertUtils.isNull(shopDetailInfo.getAddress())) {
            throw new ViewExternalDisplayException(ResultCode.System.PARAMETER_NOT_NULL, "?");
        }
        // ??50?
        if (shopDetailInfo.getAddress().length() > AccountTableConstants.Org.MAX_DETAIL_ADDRESS_LENGTH) {
            throw new ViewExternalDisplayException(ResultCode.System.PARAMETER_LENGTH_BEYOND, "?");
        }
        if (AssertUtils.isNull(shopDetailInfo.getProvinceId())) {
            throw new ViewExternalDisplayException(ResultCode.System.PARAMETER_NOT_NULL, "?");
        }
        if (AssertUtils.isNull(shopDetailInfo.getCityName())) {
            throw new ViewExternalDisplayException(ResultCode.System.PARAMETER_NOT_NULL, "");
        }
        if (AssertUtils.isNull(shopDetailInfo.getAreaId())) {
            throw new ViewExternalDisplayException(ResultCode.System.PARAMETER_NOT_NULL, "");
        }
        if (AssertUtils.isNull(shopDetailInfo.getParentOrgId())) {
            throw new ViewExternalDisplayException(ResultCode.System.PARAMETER_NOT_NULL, "");
        }
        /*
         * if (AssertUtils.isNull(shopDetailInfo.getVerifyValue())) { throw new
         * ViewExternalDisplayException(ResultCode.System.PARAMETER_NOT_NULL,
         * "??"); }
         */
    }

    /**
     * 
     * 
     * @param param ?
     * @author liubing
     */
    public List<OrgInfoDto> changeShop(ChangeShopParam param) {
        if (null == param.getOrgId()) {
            throw new ViewExternalDisplayException(ResultCode.System.PARAMETER_NOT_NULL, "?");
        }
        return orgInfoService.getOtherOrg(UserTokenThreadLocal.get().getTopOrgId(), param.getOrgId());
    }

    /**
     * 
     * 
     * 
     * @param param ?
     */
    public void orgDetailEdit(OrgDetailParam param) {
        Long currentTimeStamp = System.currentTimeMillis();

        // Long orgId = param.getOrgId();
        Long topOrgId = UserTokenThreadLocal.get().getTopOrgId();
        Long orgId = UserTokenThreadLocal.get().getOrgId();
        String name = param.getName();
        Long provinceId = param.getProvinceId();
        Long cityId = param.getCityId();
        Long areaId = param.getAreaId();
        String address = param.getAddress();
        String businessLicense = param.getBusinessLicense(); // ?
        Long parentOrgId = param.getParentOrgId(); // id
        // 1.
        if (orgId == null) {
            throw new ViewExternalDisplayException(ResultCode.System.PARAMETER_NOT_NULL, "id");
        }
        if (StringUtils.isBlank(name)) {
            throw new ViewExternalDisplayException(ResultCode.System.PARAMETER_NOT_NULL, "??");
        }
        if (StringUtils.isBlank(businessLicense)) {
            throw new ViewExternalDisplayException(ResultCode.System.PARAMETER_NOT_NULL, "??");
        }
        if (provinceId == null) {
            throw new ViewExternalDisplayException(ResultCode.System.PARAMETER_NOT_NULL, "?");
        }
        if (cityId == null) {
            throw new ViewExternalDisplayException(ResultCode.System.PARAMETER_NOT_NULL, "");
        }
        if (areaId == null) {
            throw new ViewExternalDisplayException(ResultCode.System.PARAMETER_NOT_NULL, "");
        }
        if (StringUtils.isBlank(address)) {
            throw new ViewExternalDisplayException(ResultCode.System.PARAMETER_NOT_NULL, "?");
        }

        if (parentOrgId == null) {
            throw new ViewExternalDisplayException(ResultCode.System.PARAMETER_NOT_NULL, "");
        }

        // ???
        if (!MatcherUtils.matcherString(businessLicense, "^[0-9a-zA-Z\\S]+$")) {
            throw new ViewExternalDisplayException(ResultCode.orgDetail.BUSINESS_LICENSE_ILLEGAL);
        }
        // ??50
        if (address.length() > AccountTableConstants.Org.MAX_DETAIL_ADDRESS_LENGTH) {
            throw new ViewExternalDisplayException(ResultCode.System.PARAMETER_LENGTH_BEYOND, "?");
        }

        // ?
        Byte orgChildOrgType = orgInfoService.getOrgChildOrgType(parentOrgId);
        if (null != orgChildOrgType && orgChildOrgType.equals(AccountTableConstants.Org.ORG_TYPE_CHAIN_DEPART)) {
            throw new ViewExternalDisplayException(ResultCode.Org.DIRECT_ORG_HAS_DEPART);
        }

        // ???
        Long parentTopOrgId = null;
        OrgInfoDto parentOrgInfoDto = orgInfoService.getOrgById(parentOrgId);
        if (parentOrgInfoDto != null) {
            parentTopOrgId = parentOrgInfoDto.getTopOrgId();
        }

        if (!topOrgId.equals(parentTopOrgId)) {
            throw new ViewExternalDisplayException(ResultCode.System.ILLEGALITY_REQUEST);
        }

        // ??????
        boolean flag = uniqueneShopOrgName(name, orgId, topOrgId);
        if (!flag) {
            throw new ViewExternalDisplayException(ResultCode.Org.ORG_NAME_REPEAT);
        }
        //checkOrgName(orgId, name);

        // 2.?
        OrgDetailInfoDto dto = new OrgDetailInfoDto();
        dto.setOrgId(orgId);
        dto.setProvinceId(provinceId);
        dto.setCityId(cityId);
        dto.setAreaId(areaId);
        dto.setAddress(address);
        dto.setBusinessLicense(businessLicense);

        String provinceName = null;
        GeogProvincePo provincePo = geogProvinceService.selectByPrimaryKey(provinceId.intValue());
        if (provincePo != null) {
            provinceName = provincePo.getName();
            dto.setProvinceName(provinceName);
        }

        String cityName = null;
        GeogCityPo cityPo = geogCityService.selectByPrimaryKey(cityId.intValue());
        if (cityPo != null) {
            cityName = cityPo.getName();
            dto.setCityName(cityName);
        }

        String areaName = null;
        GeogAreaPo areaPo = geogAreaService.selectByPrimaryKey(areaId.intValue());
        if (areaPo != null) {
            areaName = areaPo.getName();
            dto.setAreaName(areaName);
        }

        // ????
        if (StringUtils.isBlank(provinceName) || StringUtils.isBlank(cityName) || StringUtils.isBlank(areaName)) {
            throw new ViewExternalDisplayException(ResultCode.System.ILLEGALITY_REQUEST);
        }

        dto.setUpdateTime(currentTimeStamp);
        orgDetailInfoService.updateByParam(dto);

        // 3.org
        OrgInfoDto updateOrgInfoDto = new OrgInfoDto();
        updateOrgInfoDto.setId(orgId);
        updateOrgInfoDto.setOrgName(name);
        updateOrgInfoDto.setParentOrgId(parentOrgId);
        updateOrgInfoDto.setUpdateTime(currentTimeStamp);
        orgInfoService.updateByPrimaryKeySelective(updateOrgInfoDto);

    }

    /**
     *
     * ?
     *
     * @param param ?
     */
    public void orgDetailSingleEdit(OrgDetailParam param) {
        Long currentTimeStamp = System.currentTimeMillis();

        // Long orgId = param.getOrgId();
        Long orgId = UserTokenThreadLocal.get().getOrgId();
        String name = param.getName();
        Long provinceId = param.getProvinceId();
        Long cityId = param.getCityId();
        Long areaId = param.getAreaId();
        String address = param.getAddress();

        // 1.
        if (orgId == null) {
            throw new ViewExternalDisplayException(ResultCode.System.PARAMETER_NOT_NULL, "id");
        }
        if (StringUtils.isBlank(name)) {
            throw new ViewExternalDisplayException(ResultCode.System.PARAMETER_NOT_NULL, "??");
        }
        if (provinceId == null) {
            throw new ViewExternalDisplayException(ResultCode.System.PARAMETER_NOT_NULL, "?");
        }
        if (cityId == null) {
            throw new ViewExternalDisplayException(ResultCode.System.PARAMETER_NOT_NULL, "");
        }
        if (areaId == null) {
            throw new ViewExternalDisplayException(ResultCode.System.PARAMETER_NOT_NULL, "");
        }
        if (StringUtils.isBlank(address)) {
            throw new ViewExternalDisplayException(ResultCode.System.PARAMETER_NOT_NULL, "?");
        }

        // ??50
        if (address.length() > AccountTableConstants.Org.MAX_DETAIL_ADDRESS_LENGTH) {
            throw new ViewExternalDisplayException(ResultCode.System.PARAMETER_LENGTH_BEYOND, "?");
        }

        // ??????
        boolean flag = this.uniqueneOrgName(name, orgId);
        if (!flag) {
            throw new ViewExternalDisplayException(ResultCode.Org.ORG_NAME_REPEAT);
        }

        // 2.?
        OrgDetailInfoDto dto = new OrgDetailInfoDto();
        dto.setOrgId(orgId);
        dto.setProvinceId(provinceId);
        dto.setCityId(cityId);
        dto.setAreaId(areaId);
        dto.setAddress(address);

        String provinceName = null;
        GeogProvincePo provincePo = geogProvinceService.selectByPrimaryKey(provinceId.intValue());
        if (provincePo != null) {
            provinceName = provincePo.getName();
            dto.setProvinceName(provinceName);
        }

        String cityName = null;
        GeogCityPo cityPo = geogCityService.selectByPrimaryKey(cityId.intValue());
        if (cityPo != null) {
            cityName = cityPo.getName();
            dto.setCityName(cityName);
        }

        String areaName = null;
        GeogAreaPo areaPo = geogAreaService.selectByPrimaryKey(areaId.intValue());
        if (areaPo != null) {
            areaName = areaPo.getName();
            dto.setAreaName(areaName);
        }

        // ????
        if (StringUtils.isBlank(provinceName) || StringUtils.isBlank(cityName) || StringUtils.isBlank(areaName)) {
            throw new ViewExternalDisplayException(ResultCode.System.ILLEGALITY_REQUEST);
        }

        dto.setUpdateTime(currentTimeStamp);
        orgDetailInfoService.updateByParam(dto);

        // 3.org
        OrgInfoDto updateOrgInfoDto = new OrgInfoDto();
        updateOrgInfoDto.setId(orgId);
        updateOrgInfoDto.setOrgName(name);
        updateOrgInfoDto.setUpdateTime(currentTimeStamp);
        orgInfoService.updateByPrimaryKeySelective(updateOrgInfoDto);

    }

    /**
     * 
     * ?????
     * 
     * @param orgId
     * @param name
     */
    private void checkOrgName(Long orgId, String name) {
        List<Long> listIds = orgInfoService.getShopByTopOrgAndName(UserTokenThreadLocal.get().getTopOrgId(), name);
        List<Long> resultListIds = new ArrayList<Long>();
        for (Long id : listIds) {
            if (!id.equals(orgId)) {
                resultListIds.add(id);
            }
        }

        // id???????
        if (AssertUtils.notNull(resultListIds)) {
            throw new ViewExternalDisplayException(ResultCode.Org.ORG_NAME_REPEAT);
        }

    }

    /**
     * ??
     * 
     * @param orgId id
     * @param topOrgId id
     */
    private void addAdminOrManager(Long orgId, Long topOrgId, Byte userType, String postName, Byte postType,
            String staffName, String orgAccount) {
        Long currentTime = System.currentTimeMillis();
        /*
         * 2.???
         */
        Long postId = addPost(postName, postType, orgId, topOrgId, currentTime);

        // ,
        if (Objects.equals(postType, AccountTableConstants.Post.POST_TYPE_ADMIN)) {

            //1.?
            Long userId = addUser(userType, currentTime, staffName, orgAccount);
            //3.?
            addStaff(staffName, orgId, postId, userId, topOrgId, currentTime);
            // ??
            addPostRole(postId, roleInfoService.selectAdminId(), currentTime);
            return;
        }
        /*
         * 4.
         */
        Long roleId = addRole(currentTime);

        /*
         * 5.?
         */
        addPostRole(postId, roleId, currentTime);

        /*
         * 6.??
         */
        addRolePermission(roleId, currentTime);
    }

    /**
     * ??
     * 
     * @param userType 
     * @param currentTime ?
     * @return id
     */
    private Long addUser(Byte userType, Long currentTime, String name, String orgAccount) {
        UserInfoDto dto = new UserInfoDto();
        dto.setCreateTime(currentTime);
        dto.setUpdateTime(currentTime);
        dto.setUserType(userType);
        dto.setPassword(userInfoService.encryptionPwd(SmpConstants.User.DEFAULT_PWD));
        dto.setUserName(orgAccount);
        dto.setName(name);
        // ?id
        return userInfoService.insertSelective(dto);
    }

    /**
     * ??
     * 
     * @param postName ???
     * @param postType ?
     * @param orgId id
     * @param topOrgId id
     * @param currentTime ?
     * @return ?id
     */
    private Long addPost(String postName, Byte postType, Long orgId, Long topOrgId, Long currentTime) {
        OrgPostDto postDto = new OrgPostDto();
        postDto.setPostType(postType);
        postDto.setPostName(postName);
        postDto.setOrgId(orgId);
        postDto.setTopOrgId(topOrgId);
        postDto.setCreateTime(currentTime);
        postDto.setUpdateTime(currentTime);
        return orgPostService.insertSelective(postDto);
    }

    /**
     * 
     * 
     * @param staffName ??
     * @param orgId ??
     * @param postId ???
     * @param userId id
     * @param topOrgId id
     * @param currentTime ?
     */
    private void addStaff(String staffName, Long orgId, Long postId, Long userId, Long topOrgId, Long currentTime) {
        OrgStaffDto staffDto = new OrgStaffDto();
        staffDto.setStaffName(staffName);
        staffDto.setOrgId(orgId);
        staffDto.setPostId(postId);
        staffDto.setUserId(userId);
        staffDto.setTopOrgId(topOrgId);
        staffDto.setCreateTime(currentTime);
        staffDto.setUpdateTime(currentTime);
        staffDto.setCreaterId(UserTokenThreadLocal.getUserId());
        orgStaffService.insertSelective(staffDto);
    }

    /**
     * 
     * 
     * @param currentTime ?
     * @return id
     */
    private Long addRole(Long currentTime) {
        RoleInfoPo roleInfoPo = new RoleInfoPo();
        roleInfoPo.setRoleName(SmpTableConstants.RoleInfo.MANAGER_NAME);
        roleInfoPo.setRoleType(SmpTableConstants.RoleInfo.ROLE_TYPE_GENERA);
        roleInfoPo.setCreateTime(currentTime);
        roleInfoPo.setUpdateTime(currentTime);
        return roleInfoService.insertSelective(roleInfoPo);
    }

    /**
     * ?
     * 
     * @param postId ?id
     * @param roleId id
     * @param currentTime ?
     */
    private void addPostRole(Long postId, Long roleId, Long currentTime) {
        PostRolePo postRolePo = new PostRolePo();
        postRolePo.setPostId(postId);
        postRolePo.setRoleId(roleId);
        postRolePo.setCreateTime(currentTime);
        postRolePo.setUpdateTime(currentTime);
        postRoleService.insertSelective(postRolePo);
    }

    /**
     * ??
     * 
     * @param roleId id
     * @param currentTime ?
     */
    private void addRolePermission(Long roleId, Long currentTime) {
        /*
         * 1.???????
         */
        PermissionInfoPo permissionInfoPo = new PermissionInfoPo();
        permissionInfoPo.setBusinessType(SmpTableConstants.PermissionInfo.BUSINESS_TYPE_CHAIN_SHOP);
        permissionInfoPo.setIsAuthorize(SmpTableConstants.PermissionInfo.NEED_AUTHORIZE);
        permissionInfoPo.setPermissionType(SmpTableConstants.PermissionInfo.PERMISSION_TYPE_MENU);
        List<PermissionInfoPo> permissionList = permissionInfoService.selectPermissionInfoByVo(permissionInfoPo);

        // ????
        List<RolePermissionPo> rolePermissionPoList = new ArrayList<>();
        Boolean isParent;
        /*
         * ??
         */
        for (PermissionInfoPo po : permissionList) {
            isParent = Boolean.FALSE;
            for (PermissionInfoPo infoPo : permissionList) {
                if (po.getId().equals(infoPo.getParentId())) {
                    isParent = Boolean.TRUE;
                    break;
                }
            }
            /*
             * ????
             */
            if (Boolean.FALSE.equals(isParent)) {
                RolePermissionPo rolePermissionPo = new RolePermissionPo();
                rolePermissionPo.setRoleId(roleId);
                rolePermissionPo.setPermissionId(po.getId());
                rolePermissionPo.setCreateTime(currentTime);
                rolePermissionPo.setUpdateTime(currentTime);
                rolePermissionPoList.add(rolePermissionPo);
            }
        }

        /*
         * 2.???
         */
        rolePermissionService.batchInsert(roleId, rolePermissionPoList);
    }

    /**
     * ??
     * 
     * @return 
     */
    public List<OrgInfoDto> getAllChainShop() {

        return orgInfoService.getAllChainShopByTopOrg(UserTokenThreadLocal.get().getTopOrgId());
    }

    /**
     * ?????
     * 
     * @param param ???
     */
    public void checkOrgName(ShopDetailInfoParam param) {
        if (null == param || AssertUtils.isNull(param.getOrgName())) {
            throw new ViewExternalDisplayException(ResultCode.System.PARAMETER_NOT_NULL, "??");
        }
        List<Long> shopByTopOrgAndName = orgInfoService
                .getShopByTopOrgAndName(UserTokenThreadLocal.get().getTopOrgId(), param.getOrgName());
        if (AssertUtils.notNull(shopByTopOrgAndName)) {
            throw new ViewExternalDisplayException(ResultCode.Org.ORG_NAME_REPEAT);
        }
    }

    /**
     * 
     * @Description: 1??2???
     * @author li.jinwen
     * @email lijinwen@youanmi.com
     * @date 2017210 ?9:53:10
     * @return
     */
    public Map<String, Object> getTopOrgInfoByUser() {
        UserTokenDto userTokenDto = UserTokenThreadLocal.get();
        Map<String, Object> result = new HashMap<>();
        // id
        Long topOrgId = userTokenDto.getTopOrgId();
        // ?
        OrgInfoDto orgInfoDto = orgInfoService.getOrgById(topOrgId);
        // ?,,,
        if (orgInfoDto == null) {
            throw new ViewExternalDisplayException(ResultCode.System.SYSTEM_ERROR);
        }
        // 
        OrgDetailInfoDto orgDetailInfo = orgDetailInfoService.getOrgDetailByOrgId(topOrgId);
        // ?
        if (orgDetailInfo == null) {
            throw new ViewExternalDisplayException(ResultCode.System.SYSTEM_ERROR);
        }
        result.put("id", orgInfoDto.getId() == null ? "" : orgInfoDto.getId());// ID
        result.put("orgName", orgInfoDto.getOrgName() == null ? "" : orgInfoDto.getOrgName());// ??
        result.put("orgFullName", orgInfoDto.getOrgFullName() == null ? "" : orgInfoDto.getOrgFullName());// ??
        result.put("orgAccount", orgInfoDto.getOrgAccount() == null ? "" : orgInfoDto.getOrgAccount());// ?
        result.put("thumLogo", orgInfoDto.getThumLogo() == null ? "" : orgInfoDto.getThumLogo());//
        // ?
        result.put("businessLicense",
                orgDetailInfo.getBusinessLicense() == null ? "" : orgDetailInfo.getBusinessLicense());
        // ?
        result.put("provinceName", orgDetailInfo.getProvinceName() == null ? "" : orgDetailInfo.getProvinceName());// ?
        result.put("cityName", orgDetailInfo.getCityName() == null ? "" : orgDetailInfo.getCityName());// 
        result.put("areaName", orgDetailInfo.getAreaName() == null ? "" : orgDetailInfo.getAreaName());// 
        result.put("provinceId", orgDetailInfo.getProvinceId() == null ? "" : orgDetailInfo.getProvinceId());// ?ID
        result.put("cityId", orgDetailInfo.getCityId() == null ? "" : orgDetailInfo.getCityId());// ID
        result.put("areaId", orgDetailInfo.getAreaId() == null ? "" : orgDetailInfo.getAreaId());// ID
        result.put("address", orgDetailInfo.getAddress() == null ? "" : orgDetailInfo.getAddress());// ?
        result.put("fullAddress", orgDetailInfo.getProvinceName() + " " + orgDetailInfo.getCityName() + " "
                + orgDetailInfo.getAreaName() + " " + orgDetailInfo.getAddress());// ?
        // --dubbo?
        List<Long> ids = Arrays.asList(orgInfoDto.getFirstIndustryId(), orgInfoDto.getSecondIndustryId());
        Map<String, Object> params = new HashMap<>();
        params.put("ids", ids);
        List<IndustryDto> industrys = industryService.getIndustrysByIds(params);
        List<Map<String, Object>> industryMaps = new ArrayList<>();
        for (IndustryDto industryDto : industrys) {
            Map<String, Object> tempMap = new HashMap<>();
            tempMap.put("id", industryDto.getId());
            tempMap.put("name", industryDto.getName());
            industryMaps.add(tempMap);
        }
        result.put("industrys", industryMaps);// [{"",""},{"",""}]
        result.put("createTime", orgInfoDto.getCreateTime() == null ? "" : orgInfoDto.getCreateTime());// 
        // -
        OrgExpireTimeDto orgExpireTimeDto = orgExpireTimeService.getOrgExpireTimePoByOrgId(topOrgId);
        if (!StringUtil.isNotNull(orgExpireTimeDto)) {// 
            LOG.info("OrgInfoFacade-getTopOrgInfoByUser-ID" + topOrgId + "?");
            throw new ViewExternalDisplayException(ResultCode.System.SYSTEM_ERROR);
        }
        result.put("expireTime", orgExpireTimeDto.getExpireTime() == null ? "" : orgExpireTimeDto.getExpireTime());// 
        return result;
    }

    /**
     * 
     * ?logo
     * 
     * @param param
     */
    public void uploadOrgLogo(OrgDetailParam param) {
        Long orgId = UserTokenThreadLocal.get().getOrgId();

        String logo = param.getLogo();
        if (AssertUtils.isNull(logo)) {
            throw new ViewExternalDisplayException(ResultCode.System.PARAMETER_NOT_NULL, "logo");
        }

        OrgInfoDto dto = new OrgInfoDto();
        dto.setId(orgId);
        dto.setLogo(logo);

        orgInfoService.updateByPrimaryKeySelective(dto);
    }

    /**
     * 
     * @Description: logo
     * @author li.jinwen
     * @email lijinwen@youanmi.com
     * @date 2017213 ?10:28:09
     * @param param
     */
    public void uploadTopOrgLogo(OrgInfoParam param) {
        Long topOrgId = UserTokenThreadLocal.get().getTopOrgId();
        if (AssertUtils.isNull(topOrgId)) {
            LOG.info("OrgInfoFacade-uploadTopOrgLogo-token?topOrgId");
            throw new ViewExternalDisplayException(ResultCode.System.SYSTEM_ERROR, "topOrgId");
        }
        String logo = param.getLogo();
        if (AssertUtils.isNull(logo)) {
            throw new ViewExternalDisplayException(ResultCode.System.PARAMETER_NOT_NULL, "logo");
        }
        String thumLogo = param.getThumLogo();
        if (AssertUtils.isNull(thumLogo)) {
            throw new ViewExternalDisplayException(ResultCode.System.PARAMETER_NOT_NULL, "thumLogo");
        }

        OrgInfoDto dto = new OrgInfoDto();
        dto.setId(topOrgId);
        dto.setLogo(logo);
        dto.setThumLogo(thumLogo);
        orgInfoService.updateByPrimaryKeySelective(dto);
    }

    /**
     * 
     * @Description: ?
     * @author li.jinwen
     * @email lijinwen@youanmi.com
     * @date 2017213 ?10:42:01
     * @param param
     */
    public void updateTopOrgInfo(OrgInfoParam param) {
        Long topOrgId = UserTokenThreadLocal.get().getTopOrgId();
        if (AssertUtils.isNull(topOrgId)) {
            LOG.info("OrgInfoFacade-updateTopOrgInfo-token?topOrgId");
            throw new ViewExternalDisplayException(ResultCode.System.SYSTEM_ERROR, "topOrgId");
        }
        // ?null
        if (checkTopOrgInfoParam(param, topOrgId)) {
            OrgInfoDto orgDto = new OrgInfoDto();
            orgDto.setId(topOrgId);
            orgDto.setOrgName(param.getOrgName());
            orgDto.setAddress(param.getAddress());
            // ?orgId?orgDetail
            OrgDetailInfoDto orgDetail = orgDetailInfoService.getOrgDetailByOrgId(topOrgId);
            if (!StringUtil.isNotNull(orgDetail)) {// 
                LOG.info("OrgInfoFacade-updateTopOrgInfo-?orgId=" + topOrgId + "??orgDetail?");
                throw new ViewExternalDisplayException(ResultCode.System.SYSTEM_ERROR, "topOrgId");
            }
            orgDetail.setProvinceId(param.getProvinceId());
            orgDetail.setCityId(param.getCityId());
            orgDetail.setAreaId(param.getAreaId());
            orgDetail.setProvinceName(param.getProvinceName());
            orgDetail.setCityName(param.getCityName());
            orgDetail.setAreaName(param.getAreaName());
            orgInfoService.editOrgInfo(orgDto, orgDetail);
        }
    }

    /**
     * 
     * @Description: ??
     * @author li.jinwen
     * @email lijinwen@youanmi.com
     * @date 2017213 ?1:54:48
     * @param param
     * @return
     */
    private boolean checkTopOrgInfoParam(OrgInfoParam param, Long orgId) {
        boolean b = true;
        // 
        try {
            String orgName = param.getOrgName();// 
            Long p = param.getProvinceId();// ?Id
            Long c = param.getCityId();// Id
            Long a = param.getAreaId();// Id
            String pname = param.getProvinceName();
            String cname = param.getCityName();
            String aname = param.getAreaName();
            String address = param.getAddress();// ?
            if (StringUtil.isEmpty(orgName)) {
                LOG.info("OrgInfoFacade-checkTopOrgInfoParam-orgName?");
                throw new ViewExternalDisplayException(ResultCode.System.PARAMETER_NOT_NULL, "orgName");
            }
            if (AssertUtils.isNull(p) || AssertUtils.isNull(c) || AssertUtils.isNull(a)) {
                LOG.info("OrgInfoFacade-checkTopOrgInfoParam-???Id?");
                throw new ViewExternalDisplayException(ResultCode.System.PARAMETER_NOT_NULL,
                        "provinceId,cityId,areaId");
            }
            if (StringUtil.isEmpty(pname) || StringUtil.isEmpty(cname) || StringUtil.isEmpty(aname)) {
                LOG.info("OrgInfoFacade-checkTopOrgInfoParam-??????");
                throw new ViewExternalDisplayException(ResultCode.System.PARAMETER_NOT_NULL,
                        "provinceName,cityName,areaName");
            }
            if (StringUtil.isEmpty(address)) {
                LOG.info("OrgInfoFacade-checkTopOrgInfoParam-??");
                throw new ViewExternalDisplayException(ResultCode.System.PARAMETER_NOT_NULL, "address");
            }
        } catch (NullPointerException e) {// ??
            LOG.info("OrgInfoFacade-checkTopOrgInfoParam-?paramnull");
            // false;
            throw new ViewExternalDisplayException(ResultCode.System.PARAMETER_NOT_NULL, "paramnull");
        }

        // ?????
        if (!this.uniqueneOrgName(param.getOrgName(), orgId)) {
            LOG.info("OrgInfoFacade-checkTopOrgInfoParam-?????");
            // false;
            throw new ViewExternalDisplayException(ResultCode.System.NAME_EXIST, "??");
        }

        return b;
    }

    /**
     * 
     * @Description: ?orgName??
     * @author li.jinwen
     * @email lijinwen@youanmi.com
     * @date 2017213 ?2:14:04
     * @param orgName
     * @return
     */
    public boolean uniqueneOrgName(String orgName, Long orgId) {
        // 1?????????
        Map<String, Object> params = new HashMap<>();
        params.put("orgId", orgId);
        params.put("orgName", orgName);
        params.put("orgLevel", 1);
        boolean b = orgInfoService.uniqueneOrgParams(params);
        // 2????????
        params.clear();
        params.put("orgId", orgId);
        params.put("orgName", orgName);
        params.put("topOrgId", orgId);// topOrgId=orgId
        params.put("notOrgType", 2);
        boolean c = orgInfoService.uniqueneOrgParams(params);
        return b && c;
    }

    /**
     * 
     * @Description: ?OrgIdOrgInfo
     * @author li.jinwen
     * @email lijinwen@youanmi.com
     * @date 2017214 ?2:32:08
     * @param param ?OrgIdOrgInfo
     * @return OrgInfo
     */
    public Map<String, Object> getOrgInfo(OrgInfoParam param) {
        if (StringUtil.isNotNull(param) && !AssertUtils.isNull(param.getId())) {
            OrgInfoDto dto = orgInfoService.getOrgById(param.getId());
            if (!StringUtil.isNotNull(dto)) {
                LOG.info("OrgInfoFacade-getOrgInfo-Org?");
                throw new ViewExternalDisplayException(ResultCode.System.SYSTEM_ERROR);
            }
            // ??org?
            if (dto.getOrgType() != 2) {
                LOG.info("OrgInfoFacade-getOrgInfo-OrgType2?");
                throw new ViewExternalDisplayException(ResultCode.System.SYSTEM_ERROR);
            }
            // ??
            Map<String, Object> result = new HashMap<>();
            result.put("orgName", dto.getOrgName() == null ? "" : dto.getOrgName());// ??
            result.put("orgAccount", dto.getOrgAccount() == null ? "" : dto.getOrgAccount());// ?
            OrgDetailInfoDto orgDetailDto = orgDetailInfoService.getOrgDetailByOrgId(dto.getId());
            result.put("businessLicense",
                    orgDetailDto.getBusinessLicense() == null ? "" : orgDetailDto.getBusinessLicense());// ??
            result.put("provinceName",
                    orgDetailDto.getProvinceName() == null ? "" : orgDetailDto.getProvinceName());// ???
            result.put("provinceId", orgDetailDto.getProvinceId() == null ? "" : orgDetailDto.getProvinceId());//
            result.put("cityName", orgDetailDto.getCityName() == null ? "" : orgDetailDto.getCityName());
            result.put("cityId", orgDetailDto.getCityId() == null ? "" : orgDetailDto.getCityId());
            result.put("areaName", orgDetailDto.getAreaName() == null ? "" : orgDetailDto.getAreaName());
            result.put("areaId", orgDetailDto.getAreaId() == null ? "" : orgDetailDto.getAreaId());
            result.put("address", orgDetailDto.getAddress() == null ? "" : orgDetailDto.getAddress());// ?
            // ---
            if (AssertUtils.isNull(dto.getParentOrgId())) {
                LOG.info("OrgInfoFacade-getOrgInfo-OrgInfoparentOrgId?");
                throw new ViewExternalDisplayException(ResultCode.System.PARAMETER_NOT_NULL, "parentOrgId");
            }
            OrgInfoDto parentDto = orgInfoService.getOrgById(dto.getParentOrgId());
            if (!StringUtil.isNotNull(parentDto)) {
                LOG.info("OrgInfoFacade-getOrgInfo-Org?");
                throw new ViewExternalDisplayException(ResultCode.System.SYSTEM_ERROR);
            }
            result.put("belongToId", parentDto.getId());
            result.put("belongTo", parentDto.getOrgName() == null ? "" : parentDto.getOrgName());// --
            // ??
            UserInfoDto userDto = userInfoService.getShopManagerUserInfoByOrgId(param.getId());
            if (!StringUtil.isNotNull(userDto)) {
                LOG.info("OrgInfoFacade-getOrgInfo-userDto?ID" + param.getId()
                        + ".");
                result.put("shopManagerName", "");
            } else {
                result.put("shopManagerName", userDto.getName() == null ? "" : userDto.getName());// ??
            }
            // logo
            result.put("logo", dto.getLogo() == null ? "" : dto.getLogo());
            result.put("thumLogo", dto.getThumLogo() == null ? "" : dto.getThumLogo());
            return result;
        } else {
            LOG.info("OrgInfoFacade-getOrgInfo-?");
            throw new ViewExternalDisplayException(ResultCode.System.PARAMETER_NOT_NULL, "ID");
        }
    }

    /**
     * 
     * @Description: ?
     * @author li.jinwen
     * @email lijinwen@youanmi.com
     * @date 2017215 ?7:32:41
     * @param param
     * @return
     */
    public void updateShopOrgInfo(OrgInfoParam param) {
        Long orgId = UserTokenThreadLocal.get().getOrgId();
        if (AssertUtils.isNull(orgId)) {
            LOG.info("OrgInfoFacade-updateShopOrgInfo-token?orgId");
            throw new ViewExternalDisplayException(ResultCode.System.SYSTEM_ERROR, "orgId");
        }
        Long topOrgId = UserTokenThreadLocal.get().getTopOrgId();
        if (AssertUtils.isNull(topOrgId)) {
            LOG.info("OrgInfoFacade-updateShopOrgInfo-token?topOrgId");
            throw new ViewExternalDisplayException(ResultCode.System.SYSTEM_ERROR, "topOrgId");
        }
        // org?type2??????
        OrgInfoDto dto = orgInfoService.getOrgById(orgId);
        if (!StringUtil.isNotNull(dto) || 2 != dto.getOrgType()) {// dtotype?2
            LOG.info("OrgInfoFacade-updateShopOrgInfo-orgId=" + orgId + "?");
            throw new ViewExternalDisplayException(ResultCode.System.SYSTEM_ERROR);
        }
        // ?null
        if (checkShopOrgInfoParam(param, orgId, topOrgId)) {
            OrgInfoDto orgDto = new OrgInfoDto();
            orgDto.setId(orgId);
            orgDto.setOrgName(param.getOrgName());
            orgDto.setAddress(param.getAddress());
            // ?orgId?orgDetail
            OrgDetailInfoDto orgDetail = orgDetailInfoService.getOrgDetailByOrgId(orgId);
            if (!StringUtil.isNotNull(orgDetail)) {// 
                LOG.info("OrgInfoFacade-updateShopOrgInfo-?orgId=" + orgId + "??orgDetail?");
                throw new ViewExternalDisplayException(ResultCode.System.SYSTEM_ERROR);
            }
            orgDetail.setProvinceId(param.getProvinceId());
            orgDetail.setCityId(param.getCityId());
            orgDetail.setAreaId(param.getAreaId());
            orgDetail.setProvinceName(param.getProvinceName());
            orgDetail.setCityName(param.getCityName());
            orgDetail.setAreaName(param.getAreaName());
            orgDetail.setBusinessLicense(param.getBusinessLicense());
            orgInfoService.editOrgInfo(orgDto, orgDetail);
        }

    }

    /**
     * 
     * @Description: ?
     * @author li.jinwen
     * @email lijinwen@youanmi.com
     * @date 2017215 ?7:48:43
     * @param param
     * @param orgId
     * @return
     */
    private boolean checkShopOrgInfoParam(OrgInfoParam param, Long orgId, Long topOrgId) {
        boolean b = true;

        // 
        try {
            String orgName = param.getOrgName();// 
            Long p = param.getProvinceId();// ?Id
            Long c = param.getCityId();// Id
            Long a = param.getAreaId();// Id
            String pname = param.getProvinceName();
            String cname = param.getCityName();
            String aname = param.getAreaName();
            String address = param.getAddress();// ?
            String businessLicense = param.getBusinessLicense();
            if (StringUtil.isEmpty(orgName)) {
                LOG.info("OrgInfoFacade-checkTopOrgInfoParam-orgName?");
                throw new ViewExternalDisplayException(ResultCode.System.PARAMETER_NOT_NULL, "orgName");
            }
            if (AssertUtils.isNull(p) || AssertUtils.isNull(c) || AssertUtils.isNull(a)) {
                LOG.info("OrgInfoFacade-checkTopOrgInfoParam-???Id?");
                throw new ViewExternalDisplayException(ResultCode.System.PARAMETER_NOT_NULL,
                        "provinceId,cityId,areaId");
            }
            if (StringUtil.isEmpty(pname) || StringUtil.isEmpty(cname) || StringUtil.isEmpty(aname)) {
                LOG.info("OrgInfoFacade-checkTopOrgInfoParam-??????");
                throw new ViewExternalDisplayException(ResultCode.System.PARAMETER_NOT_NULL,
                        "provinceName,cityName,areaName");
            }
            if (StringUtil.isEmpty(address)) {
                LOG.info("OrgInfoFacade-checkTopOrgInfoParam-??");
                throw new ViewExternalDisplayException(ResultCode.System.PARAMETER_NOT_NULL, "address");
            }
            if (StringUtil.isEmpty(businessLicense)) {
                LOG.info("OrgInfoFacade-checkTopOrgInfoParam-??");
                throw new ViewExternalDisplayException(ResultCode.System.PARAMETER_NOT_NULL, "businessLicense");
            }
        } catch (NullPointerException e) {// ??
            LOG.info("OrgInfoFacade-checkTopOrgInfoParam-?paramnull");
            // false;
            throw new ViewExternalDisplayException(ResultCode.System.PARAMETER_NOT_NULL, "paramnull");
        }

        // ?????---
        if (!this.uniqueneShopOrgName(param.getOrgName(), orgId, topOrgId)) {
            LOG.info("OrgInfoFacade-checkTopOrgInfoParam-?????");
            // false;
            throw new ViewExternalDisplayException(ResultCode.System.NAME_EXIST, "??");
        }

        // ????---?
        if (!this.uniqueneOrgBusinessLicense(param.getBusinessLicense(), orgId)) {
            LOG.info("OrgInfoFacade-checkTopOrgInfoParam-????");
            // false;
            throw new ViewExternalDisplayException(ResultCode.System.NAME_EXIST, "??");
        }
        return b;
    }

    private boolean uniqueneOrgBusinessLicense(String businessLicense, Long orgId) {
        // 
        Map<String, Object> params = new HashMap<>();
        params.put("orgId", orgId);
        params.put("businessLicense", businessLicense);
        boolean b = orgInfoService.uniqueneOrgParams(params);
        return b;
    }

    /**
     * 
     * @Description: ??????
     * @author li.jinwen
     * @email lijinwen@youanmi.com
     * @date 2017216 ?7:57:00
     * @param orgName ??
     * @param orgId ID
     * @param topOrgId ID
     * @return
     */
    public boolean uniqueneShopOrgName(String orgName, Long orgId, Long topOrgId) {
        Map<String, Object> params = new HashMap<>();
        params.put("topOrgId", topOrgId);
        params.put("orgId", orgId);
        params.put("orgName", orgName);
        params.put("orgType", 2);// ??????
        boolean b = orgInfoService.uniqueneOrgParams(params);
        return b;
    }

    /**
     * ???
     *
     * @param orgId
     * @author tanguojun on 2017220
     */
    public void resetShopManagerPwd(Long orgId) {

        // orgId?
        ValidateViewExceptionUtils.validateObjectIsNotNull(ResultCode.System.PARAMETER_NOT_NULL, orgId, "");

        UserTokenDto userToken = UserTokenThreadLocal.get();

        // ??
        orgInfoService.resetShopManagerPwd(orgId, userToken.getTopOrgId());
    }

    /**
     * 
     * @param orgId id
     */
    public void deleteOrg(Long orgId) {
        //?id
        Long topOrgId = UserTokenThreadLocal.get().getTopOrgId();
        //??
        OrgInfoDto orgInfo = orgInfoService.getOrgById(orgId);
        /**
         * ??
         */
        if (null == orgInfo || !orgInfo.getTopOrgId().equals(topOrgId)) {
            throw new ViewExternalDisplayException(ResultCode.System.ILLEGALITY_REQUEST);
        }
        orgInfoService.deleteShop(orgId);
    }

    /**
     * logo
     * @param orgInfoDto ?
     */
    public void updateShopLogo(OrgInfoDto orgInfoDto) {
        if (null == orgInfoDto) {
            throw new ViewExternalDisplayException(ResultCode.System.ILLEGALITY_REQUEST);
        }
        orgInfoDto.setId(UserTokenThreadLocal.getOrgId());
        orgInfoDto.setUpdateTime(System.currentTimeMillis());
        orgInfoService.updateByPrimaryKeySelective(orgInfoDto);
    }
}