
package com.tmerclub.cloud.distribution.controller.platform;

import cn.hutool.core.util.BooleanUtil;
import cn.hutool.core.util.PhoneUtil;
import cn.hutool.core.util.StrUtil;
import com.tmerclub.cloud.common.database.dto.PageDTO;
import com.tmerclub.cloud.common.database.vo.PageVO;
import com.tmerclub.cloud.common.response.ServerResponseEntity;
import com.tmerclub.cloud.common.util.PrincipalUtil;
import com.tmerclub.cloud.distribution.dto.DistributionUserBindDTO;
import com.tmerclub.cloud.distribution.service.DistributionUserBindService;
import com.tmerclub.cloud.distribution.vo.DistributionUserBindVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 分销员绑定关系
 *
 * @author cl
 * @date 2021-08-09 14:14:09
 */
@RestController("platformDistributionUserBindController")
@RequestMapping("/p/distributionUserBind")
@Tag(name = "platform-分销员绑定关系")
public class DistributionUserBindController {

    @Autowired
    private DistributionUserBindService distributionUserBindService;

    @GetMapping("/page")
    @Operation(summary = "获取分销员绑定关系列表", description = "分页获取分销员绑定关系列表")
    public ServerResponseEntity<PageVO<DistributionUserBindVO>> page(@Valid PageDTO pageDTO, DistributionUserBindDTO distributionUserBindDTO) {
        PageVO<DistributionUserBindVO> page = distributionUserBindService.page(pageDTO, distributionUserBindDTO);
        for (DistributionUserBindVO distributionUserBindVO : page.getList()) {
            if (StrUtil.isNotBlank(distributionUserBindVO.getNickName()) && PrincipalUtil.isMobile(distributionUserBindVO.getNickName())) {
                distributionUserBindVO.setNickName(PhoneUtil.hideBetween(distributionUserBindVO.getNickName()).toString());
            }
            if (StrUtil.isNotBlank(distributionUserBindVO.getUserNickName()) && PrincipalUtil.isMobile(distributionUserBindVO.getUserNickName())) {
                distributionUserBindVO.setUserNickName(PhoneUtil.hideBetween(distributionUserBindVO.getUserNickName()).toString());
            }
        }
        return ServerResponseEntity.success(page);
    }
}
