package com.gunshi.project.xyt.service; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.gunshi.project.xyt.entity.vo.GateStautsVo; import com.gunshi.project.xyt.mapper.GateValveRMapper; import com.gunshi.project.xyt.mapper.GateValveRealMapper; import com.gunshi.project.xyt.model.GateValveKey; import com.gunshi.project.xyt.model.GateValveKeyAutoDao; import com.gunshi.project.xyt.model.GateValveReal; import com.gunshi.project.xyt.util.DateUtil; import jakarta.annotation.Resource; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.math.BigDecimal; import java.util.Date; import java.util.List; /** * 描述: 闸阀开关表 * author: xusan * date: 2024-07-08 17:30:37 */ @Service @Slf4j @Transactional(rollbackFor = Exception.class) public class GateValveRealService extends ServiceImpl { @Resource private GateValveKeyAutoDao gateValveKeyAutoDao; @Resource private GateValveRMapper gateValveRMapper; public List gateStatusList() { List list = baseMapper.gateStatusList(); for(GateStautsVo vo : list){ if(vo.getTm() != null && DateUtil.hoursBetweenDate(vo.getTm(), new Date()) > 2){ vo.setFlag(1); } } return list; } public BigDecimal realQ(String valveCode) { return baseMapper.realQ(valveCode); } public String control(GateValveKey gateValveKey) { //先判断密码是否正确 String valveCode = gateValveKey.getValveCode(); String key = gateValveKey.getKey(); GateValveKey valveKey = gateValveKeyAutoDao.getById(valveCode); if(valveKey == null || !key.equals(valveKey.getKey())){ throw new IllegalArgumentException("密码不正确"); } //todo 给闸阀下发调节指令 // GateValveR gateValveR = new GateValveR(); // BeanUtils.copyProperties(gateValveKey,gateValveR); // gateValveR.setTm(new Date()); // gateValveRMapper.insert(gateValveR); // // GateValveReal real = new GateValveReal(); // BeanUtils.copyProperties(gateValveKey,real); // real.setTm(new Date()); // this.remove(new QueryWrapper().eq("valve_code",valveCode)); // this.save(real); return "调节闸阀指令已下发"; } }