package com.emergency.avenue.storage.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.emergency.avenue.admin.api.entity.SysTreeDict;
import com.emergency.avenue.admin.api.vo.MaterialsFailureDetailVO;
import com.emergency.avenue.admin.service.SysTreeDictService;
import com.emergency.avenue.storage.api.entity.MaterialsFailureDetail;
import com.emergency.avenue.storage.mapper.MaterialsFailureDetailMapper;
import com.emergency.avenue.storage.service.MaterialsFailureDetailService;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
@AllArgsConstructor
public class MaterialsFailureDetailServiceImpl extends ServiceImpl<MaterialsFailureDetailMapper, MaterialsFailureDetail> implements MaterialsFailureDetailService {
    @Autowired
	private MaterialsFailureDetailMapper  materialsFailureDetailMapper;

	@Override
	public MaterialsFailureDetailVO getMaterialsFailureDetailById(Long id) {
		MaterialsFailureDetail materialsFailureDetail = materialsFailureDetailMapper.selectById(id);
		MaterialsFailureDetailVO materialsFailureDetailVO = BeanUtil.toBean(materialsFailureDetail, MaterialsFailureDetailVO.class);
		return materialsFailureDetailVO;
	}

	@Override
	public Boolean saveMaterialsFailureDetail(MaterialsFailureDetailVO materialsFailureDetailVO) {
		MaterialsFailureDetail  materialsFailureDetail=BeanUtil.toBean(materialsFailureDetailVO, MaterialsFailureDetail.class);
		materialsFailureDetail.setSubmitTime(LocalDateTime.now());
		materialsFailureDetailMapper.insert(materialsFailureDetail);
		return true;
	}

	@Override
	public Boolean updateMaterialsFailureDetail(MaterialsFailureDetailVO materialsFailureDetailVO) {
		MaterialsFailureDetail  materialsFailureDetail=BeanUtil.toBean(materialsFailureDetailVO, MaterialsFailureDetail.class);
		materialsFailureDetail.setUpdateTime(LocalDateTime.now());
		materialsFailureDetailMapper.updateById(materialsFailureDetail);
		return true;
	}

}
