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

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.emergency.avenue.admin.config.WebSocketServer;
import com.emergency.avenue.common.core.util.R;
import com.emergency.avenue.storage.api.entity.Storage;
import com.emergency.avenue.storage.mapper.SysStorageMapper;
import com.emergency.avenue.storage.service.SysStorageService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @Author: Insight
 * @Description: TODO
 * @Date: 2024/4/2 17:04
 * @Version: 1.0
 */
@Service
@AllArgsConstructor
public class SysStorageServiceImpl extends ServiceImpl<SysStorageMapper, Storage> implements SysStorageService {

	private final SysStorageMapper sysStorageMapper;

    @Override
    public R save(List<String> rfids) {
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		UpdateWrapper<Storage> storageUpdateWrapper = new UpdateWrapper<>();
		storageUpdateWrapper.lambda().set(Storage::getCksj,format.format(new Date()));
		storageUpdateWrapper.lambda().set(Storage::getZt,"1");
		storageUpdateWrapper.lambda().in(Storage::getRfid,rfids);
		sysStorageMapper.update(null,storageUpdateWrapper);
		List<Storage> storages = sysStorageMapper.selectList(new QueryWrapper<Storage>().lambda().eq(Storage::getZt, "1"));
		WebSocketServer.sendInfo(JSON.toJSONString(storages),null);
		return R.ok();
    }

}
