package com.skr.mdm.service.impl.equipment;

import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper;
import com.skr.mdm.annotation.CmdHandler;
import com.skr.mdm.constant.CmdTypeConstants;
import com.skr.mdm.dao.DeviceEquipmentDao;
import com.skr.mdm.entity.DeviceEquipmentDO;
import com.skr.mdm.result.ResponseResult;
import com.skr.mdm.service.CmdHandlerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;


/**
 * @author nfq
 * @date 2020/7/30 15:55
 */
@Slf4j
@CmdHandler(cmdType = CmdTypeConstants.UP_UNINSTALL_CODE)
public class UninstallCodeServiceImpl implements CmdHandlerService {

    @Autowired
    private DeviceEquipmentDao equipmentDao;

    @Override
    public ResponseResult cmdHandler(Integer equipmentId, String data) {
        try {
            LambdaUpdateChainWrapper<DeviceEquipmentDO> updateChainWrapper = new LambdaUpdateChainWrapper<DeviceEquipmentDO>(equipmentDao);
            boolean update = updateChainWrapper.set(DeviceEquipmentDO::getUninstallCode, data).eq(DeviceEquipmentDO::getId, equipmentId).update();
            return update ? ResponseResult.success() : ResponseResult.failure();
        } catch (Exception e) {
           log.error("卸载码上传异常:" + equipmentId + data, e);
           return ResponseResult.failure();
        }
    }

}
