package vip.xiaonuo.sale.service.impl;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import vip.xiaonuo.sale.entity.SaleSalesman;
import vip.xiaonuo.sale.mapper.SaleSalesmanMapper;
import vip.xiaonuo.sale.param.SaleSalesmanParam;
import vip.xiaonuo.sale.service.ISaleSalesmanService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 销售业务员发货 服务实现类
 * </p>
 *
 * @author author
 * @since 2024-12-13
 */
@Service
public class SaleSalesmanServiceImpl extends ServiceImpl<SaleSalesmanMapper, SaleSalesman> implements ISaleSalesmanService {

    @Autowired
    private SaleSalesmanMapper salesmanMapper;

    @Override
    public List<SaleSalesman> getList(SaleSalesmanParam salesmanParam) {
        String orgId = salesmanParam.getOrgId();
        QueryWrapper<SaleSalesman> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(StringUtils.isNotBlank(orgId), "org_id", orgId);
        queryWrapper.ge("create_time", DateUtil.beginOfYear(new Date()));
        queryWrapper.select(" salesman_name salesmanName,IFNULL(sum(salesman_money),'0') salesmanMoney");
        queryWrapper.groupBy("salesman_name,DATE_FORMAT(create_time,'%Y-%m')");
        return salesmanMapper.selectList(queryWrapper);
    }

}
