package com.sqx.modules.material.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sqx.common.utils.Result;
import com.sqx.modules.material.dao.MaterialMassageMapper;
import com.sqx.modules.material.entity.Material;
import com.sqx.modules.material.entity.MaterialMassage;
import com.sqx.modules.material.service.MaterialMassageService;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
* @author Administrator
* @description 针对表【material_massage(物料包与服务表中间表)】的数据库操作Service实现
* @createDate 2024-02-27 15:29:44
*/
@Service
public class MaterialMassageServiceImpl extends ServiceImpl<MaterialMassageMapper, MaterialMassage> implements MaterialMassageService {

    @Override
    public Result insert(MaterialMassage materialMassage) {
        materialMassage.setCreateTime(new Date());
        materialMassage.setUpdateTime(new Date());
        QueryWrapper<MaterialMassage> queryWrapper = new QueryWrapper();
        queryWrapper.eq("material_id", materialMassage.getMaterialId());
        queryWrapper.eq("massage_type_id", materialMassage.getMassageTypeId());
        List<MaterialMassage> materialMassageList = baseMapper.selectList(queryWrapper);
        if(materialMassageList.size()>0){
            return Result.error("该物料包已被添加，请重新选择");
        }
        int result = baseMapper.insert(materialMassage);
        return Result.success(String.valueOf(result));
    }

    @Override
    public Result materialMassageDelete(MaterialMassage materialMassage) {
        int result = baseMapper.deleteById(materialMassage.getId());
        return  Result.success(String.valueOf(result));
    }

    @Override
    public Result materialMassageUpdata(MaterialMassage materialMassage) {
        materialMassage.setUpdateTime(new Date());
        return Result.success(String.valueOf(baseMapper.updateById(materialMassage)));
    }
}




