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

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.DistributionUserIncomeDTO;
import com.tmerclub.cloud.distribution.service.DistributionUserIncomeService;
import com.tmerclub.cloud.distribution.vo.DistributionUserIncomeVO;
import com.tmerclub.cloud.distribution.vo.DistributionUserVO;
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;

import java.util.Objects;

/**
 * @Author lth
 * @Date 2021/8/10 16:30
 */
@RestController("adminDistributionUserIncomeController")
@RequestMapping("/mp/distributionUserIncome")
@Tag(name = "admin-分销收入记录信息")
public class DistributionUserIncomeController {

    @Autowired
    private DistributionUserIncomeService distributionUserIncomeService;

    @GetMapping("/salesRecordPage")
    @Operation(summary = "获取销售记录", description = "获取销售记录")
    public ServerResponseEntity<PageVO<DistributionUserIncomeVO>> salesRecordPage(@Valid PageDTO pageDTO, DistributionUserIncomeDTO distributionUserIncomeDTO) {
        PageVO<DistributionUserIncomeVO> distributionUserIncomePageVO = distributionUserIncomeService.pageSalesRecord(pageDTO, distributionUserIncomeDTO);
        for (DistributionUserIncomeVO record : distributionUserIncomePageVO.getList()) {
            DistributionUserVO distributionUser = record.getDistributionUser();
            if (Objects.nonNull(distributionUser)) {
                if (StrUtil.isNotBlank(distributionUser.getNickName()) && PrincipalUtil.isMobile(distributionUser.getNickName())) {
                    distributionUser.setNickName(PhoneUtil.hideBetween(distributionUser.getNickName()).toString());
                }
                if (StrUtil.isNotBlank(distributionUser.getUserMobile()) && PrincipalUtil.isMobile(distributionUser.getUserMobile())) {
                    distributionUser.setUserMobile(PhoneUtil.hideBetween(distributionUser.getUserMobile()).toString());
                }
            }
        }
        return ServerResponseEntity.success(distributionUserIncomePageVO);
    }
}
