package com.jwipc.sys.logic.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jwipc.page.PageUtil;
import com.jwipc.page.PageView;
import com.jwipc.sys.convert.PurchaseCategoryConvert;
import com.jwipc.sys.dto.PurchaseCategoryDTO;
import com.jwipc.sys.entity.PurchaseCategory;
import com.jwipc.sys.logic.PurchaseCategoryLogic;
import com.jwipc.sys.model.po.PurchaseCategoryPO;
import com.jwipc.sys.model.query.PurchaseCategoryQuery;
import com.jwipc.sys.service.IPurchaseCategoryService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author shenyang.ou
 * @date 2024/2/4 14:54
 * @desc
 */
@Service
@RequiredArgsConstructor
public class PurchaseCategoryLogicImpl implements PurchaseCategoryLogic {
    private final PurchaseCategoryConvert purchaseCategoryConvert;
    private final IPurchaseCategoryService purchaseCategoryService;
    @Override
    public PageView findByPage(PurchaseCategoryQuery query) {
        final Page<PurchaseCategory> dbPage = PageUtil.toPage(query);
        List<PurchaseCategoryPO> purchaseCategoryPOS = purchaseCategoryService.findPageByQuery(dbPage, query);
        List<PurchaseCategoryDTO> purchaseCategoryDTOS = purchaseCategoryConvert.po2DTOList(purchaseCategoryPOS);
        return PageUtil.getPV(purchaseCategoryDTOS, dbPage.getTotal());
    }

    @Override
    public List<PurchaseCategoryDTO> listAll(PurchaseCategoryQuery query) {
        List<PurchaseCategoryPO> purchaseCategoryPOS = purchaseCategoryService.findPageByQuery(null, query);
        return purchaseCategoryConvert.po2DTOList(purchaseCategoryPOS);
    }

    @Override
    public void disable(Long id, Integer status) {
        PurchaseCategory purchaseCategory = new PurchaseCategory();
        purchaseCategory.setId(id);
        purchaseCategory.setStatus(status);
        purchaseCategoryService.updateById(purchaseCategory);
    }
}
