package cn.superdesk.uniorder.service.organisation.impl;

import cn.superdesk.uniorder.common.numerical.AnBeanUtils;
import cn.superdesk.uniorder.common.rest.response.R;
import cn.superdesk.uniorder.dao.entity.organisation.UnifiedSupplierCostConfig;
import cn.superdesk.uniorder.dao.mapper.unified.UnifiedSupplierCostConfigMapper;
import cn.superdesk.uniorder.dao.mapper.unified.UnifiedSupplierCostConfigMapperEx;
import cn.superdesk.uniorder.dto.param.organisation.UnifiedSupplierQueryCriteria;
import cn.superdesk.uniorder.dto.vo.unified.OrderCostUpdateParam;
import cn.superdesk.uniorder.service.organisation.UnifiedSupplierCostConfigService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @Description: 成本核算-重构
 * @Author: linjinyu
 * @CreateDate: 2021/6/2 上午11:37
 * @UpdateUser: linjinyu
 * @UpdateDate: 2021/6/2 上午11:37
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
@Service
public class UnifiedSupplierCostConfigServiceImpl implements UnifiedSupplierCostConfigService {


    @Autowired
    private UnifiedSupplierCostConfigMapper   unifiedSupplierCostConfigMapper;
    @Autowired
    private UnifiedSupplierCostConfigMapperEx unifiedSupplierCostConfigMapperEx;


    @Override
    public int insertSelective(UnifiedSupplierCostConfig unifiedSupplierCostConfig) {
        return unifiedSupplierCostConfigMapper.insertSelective(unifiedSupplierCostConfig);
    }

    @Override
    public int updateByPrimaryKeySelective(UnifiedSupplierCostConfig unifiedSupplierCostConfig) {
        return unifiedSupplierCostConfigMapper.updateByPrimaryKeySelective(unifiedSupplierCostConfig);
    }

    @Override
    public void deleteObj(Long id) {
        unifiedSupplierCostConfigMapper.deleteByPrimaryKey(id);
    }

    @Override
    public UnifiedSupplierCostConfig findById(Long id) {
        return unifiedSupplierCostConfigMapper.selectByPrimaryKey(id);
    }


    @Override
    public List<UnifiedSupplierCostConfig> findAll(Map<String, Object> queryMap) {

        UnifiedSupplierQueryCriteria criteria = AnBeanUtils.mapToBean(queryMap, UnifiedSupplierQueryCriteria.class);

        return unifiedSupplierCostConfigMapperEx.findAll(criteria);
    }

    @Override
    public PageInfo<UnifiedSupplierCostConfig> findByPaging(Map<String, Object> params, Integer pageNo, Integer pageSize) {
        return null;
    }

    @Override
    public R<List<UnifiedSupplierCostConfig>> getDataByPage(UnifiedSupplierQueryCriteria criteria, int pageNo, int pageSize) {

        PageHelper.startPage(pageNo, pageSize);
        List<UnifiedSupplierCostConfig>     resultList = unifiedSupplierCostConfigMapperEx.findAll(criteria);
        PageInfo<UnifiedSupplierCostConfig> page       = new PageInfo<>(resultList);
        PageHelper.clearPage();
        return new R<List<UnifiedSupplierCostConfig>>(page.getPageNum(), page.getPageSize(), (int) page.getTotal(), resultList);
    }

    @Override
    public UnifiedSupplierCostConfig findBySaleId(Long saleId) {
        return unifiedSupplierCostConfigMapperEx.findBySaleId(saleId);
    }

    @Override
    public void updateOrderCost(OrderCostUpdateParam updateMap) {
        // 更新订单成本
        unifiedSupplierCostConfigMapperEx.updateOrderCost(updateMap);

    }

    @Override
    public void updateOrderGoodsCost(OrderCostUpdateParam updateMap) {
        // 更新订单货品成本
        unifiedSupplierCostConfigMapperEx.updateOrderGoodsCost(updateMap);
    }
}
