package com.hys.app.service.erp.impl;

import cn.hutool.core.util.StrUtil;
import com.hys.app.converter.erp.OrderConverter;
import com.hys.app.converter.erp.OrderItemConverter;
import com.hys.app.converter.erp.OrderPaymentConverter;
import com.hys.app.converter.erp.SaleChannelConverter;
import com.hys.app.framework.context.user.AdminUserContext;
import com.hys.app.framework.database.WebPage;
import com.hys.app.framework.database.mybatisplus.base.BaseServiceImpl;
import com.hys.app.framework.exception.ServiceException;
import com.hys.app.framework.util.CurrencyUtil;
import com.hys.app.framework.util.DateUtil;
import com.hys.app.mapper.erp.OrderMapper;
import com.hys.app.mapper.erp.SaleChannelMapper;
import com.hys.app.model.erp.dos.*;
import com.hys.app.model.erp.dto.*;
import com.hys.app.model.erp.enums.*;
import com.hys.app.model.erp.vo.OrderAllowable;
import com.hys.app.model.erp.vo.OrderVO;
import com.hys.app.model.erp.vo.SaleChannelV0;
import com.hys.app.model.goods.dos.CategoryDO;
import com.hys.app.model.system.dos.DeptDO;
import com.hys.app.service.erp.*;
import com.hys.app.service.goods.BrandManager;
import com.hys.app.service.goods.CategoryManager;
import com.hys.app.service.system.DeptManager;
import com.hys.app.util.ValidateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.function.Function;

import static com.hys.app.framework.util.CollectionUtils.convertList;
import static com.hys.app.framework.util.CollectionUtils.convertMap;

/**
 * 订单业务层实现
 *
 * @author 张崧
 * 2024-01-24 15:58:31
 */
@Service
public class SaleChannelImpl extends BaseServiceImpl<SaleChannelMapper, SaleChannelDO> implements SaleChannelManager {

    @Autowired
    private SaleChannelConverter converter;



    @Override
    public WebPage<SaleChannelV0> list(SaleChannelQueryParams queryParams) {
        WebPage<SaleChannelDO> page = baseMapper.selectPage(queryParams);
        return converter.convert(page);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void add(SaleChannelDO saleChannelDO) {
        baseMapper.insert(saleChannelDO);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void edit(SaleChannelDO saleChannelDO,Long id) {
        SaleChannelDO old = ValidateUtil.getOne(baseMapper, SaleChannelDO::getId, id, "渠道");
        AdminUserContext.compareCompany(old.getCompanyId());
        updateById(saleChannelDO);
    }

    @Override
    public SaleChannelV0 getDetail(Long id) {
        SaleChannelDO orderDO = getById(id);
        return converter.convert(orderDO);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void delete(Long id) {
        SaleChannelDO old = ValidateUtil.getOne(baseMapper, SaleChannelDO::getId, id, "渠道");
        AdminUserContext.compareCompany(old.getCompanyId());
        removeById(id);
    }

}

