package com.chushang.inspection.terminal.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chushang.common.core.web.AjaxResult;
import com.chushang.common.mybatis.utils.PageResult;
import com.chushang.datascope.annotation.DataScope;
import com.chushang.inspection.terminal.po.ConsumablesTotal;
import com.chushang.inspection.terminal.query.ConsumablesDetailsQuery;
import com.chushang.inspection.terminal.service.ConsumableDetailsService;
import com.chushang.security.entity.po.SysUser;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chushang.inspection.terminal.mapper.ConsumableDetailsMapper;
import com.chushang.inspection.terminal.po.ConsumableDetails;

import java.time.LocalDateTime;
import java.util.List;

/**
  * @auther: zhao
  * @date: 2024/6/21 11:47
  */
@Slf4j
@Service
public class ConsumableDetailsServiceImpl extends ServiceImpl<ConsumableDetailsMapper, ConsumableDetails> implements ConsumableDetailsService {

    @Override
    @DataScope(deptAlias = "cd")
    public PageResult findPage(ConsumablesDetailsQuery query) {
        Page<SysUser> page = new Page<>(query.getPage(),query.getLimit());
        List<ConsumableDetails> listAfDataVOList = baseMapper.findPage(query,
                page);
        return new PageResult(
                listAfDataVOList,
                page.getTotal(),
                page.getPages(),
                page.getCurrent());
    }

    @Override
    public void saveDetails(ConsumablesTotal consumablesTotal, Integer total, int type) {
        ConsumableDetails details = ConsumableDetails
                .builder()
                .totalId(consumablesTotal.getTotalId())
                .inboundAndOutboundType(type)
                .deptId(consumablesTotal.getDeptId())
                .quantity(total)
                .build();
        save(details);
    }
}
