package com.rongwei.bscommon.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.rongwei.bscommon.sys.dao.EquFrockListDao;
import com.rongwei.bscommon.sys.service.EquFrockListService;
import com.rongwei.bsentity.domain.EquFrockListDo;
import com.rongwei.bsentity.dto.EquipmentDisposeDTO;
import com.rongwei.bsentity.enums.PlantEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @author shangmi
 * @title EquFrockListServiceImpl
 * @date 2024/1/16 15:46
 * @description 工装清单服务实现层
 */
@Service
public class EquFrockListServiceImpl extends ServiceImpl<EquFrockListDao,EquFrockListDo> implements EquFrockListService {

    @Autowired
    private EquFrockListDao equFrockListDao;

    /**
     * 根据ID修改地址信息
     *
     * @param equipmentDisposeDTO
     * @return
     * @date 2024/1/16 16:28
     * @author shangmi
     *
     */

    @Override
    public void updateSiteById(EquipmentDisposeDTO equipmentDisposeDTO) {
        LambdaUpdateWrapper<EquFrockListDo> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.eq(EquFrockListDo::getId,equipmentDisposeDTO.getEquipmentId())
                .set(EquFrockListDo::getTenantid,equipmentDisposeDTO.getRollInPlantId())
                .set(EquFrockListDo::getUsedeptid,equipmentDisposeDTO.getRollInDeptId())
                .set(EquFrockListDo::getOwnedfactory, PlantEnum.nameOf(equipmentDisposeDTO.getRollInPlantId()))
                .set(EquFrockListDo::getUsedeptname,equipmentDisposeDTO.getRollInDept());
        equFrockListDao.update(null,updateWrapper);

    }

    /**
     * 更新报废状态
     *
     * @param equipmentId id
     * @param newDate
     */
    @Override
    public void updateStateById(String equipmentId, Date newDate) {

        LambdaUpdateWrapper<EquFrockListDo> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.eq(EquFrockListDo::getId,equipmentId)
                .set(EquFrockListDo::getUsestate,"报废")
                .set(EquFrockListDo::getFactobsoledate,newDate);
        equFrockListDao.update(null,updateWrapper);
    }
}
