
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.DistributionUserBanDTO;
import com.tmerclub.cloud.distribution.service.DistributionUserBanService;
import com.tmerclub.cloud.distribution.vo.DistributionUserBanVO;
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:08
 */
@RestController("platformDistributionUserBanController")
@RequestMapping("/p/distributionuserBan")
@Tag(name = "platform-分销封禁记录")
public class DistributionUserBanController {

    @Autowired
    private DistributionUserBanService distributionUserBanService;

    @GetMapping("/page")
    @Operation(summary = "获取分销封禁记录列表", description = "分页获取分销封禁记录列表")
    public ServerResponseEntity<PageVO<DistributionUserBanVO>> page(@Valid PageDTO pageDTO, DistributionUserBanDTO distributionUserBanDTO) {
        PageVO<DistributionUserBanVO> page = distributionUserBanService.page(pageDTO, distributionUserBanDTO);
        for (DistributionUserBanVO distributionUserBanVO : page.getList()) {
            if (StrUtil.isNotBlank(distributionUserBanVO.getNickName()) && PrincipalUtil.isMobile(distributionUserBanVO.getNickName())) {
                distributionUserBanVO.setNickName(PhoneUtil.hideBetween(distributionUserBanVO.getNickName()).toString());
            }
            if (StrUtil.isNotBlank(distributionUserBanVO.getUserMobile())) {
                distributionUserBanVO.setUserMobile(PhoneUtil.hideBetween(distributionUserBanVO.getUserMobile()).toString());
            }
        }
        return ServerResponseEntity.success(page);
    }
}
