package com.whyc.service;
|
|
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
import com.whyc.dto.Response;
|
import com.whyc.mapper.LockAddressMapper;
|
import com.whyc.pojo.plus_inf.LockAddress;
|
import com.whyc.util.ActionUtil;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import javax.swing.*;
|
import java.util.List;
|
|
@Service
|
public class LockAddressService {
|
@Autowired(required = false)
|
private LockAddressMapper mapper;
|
//编辑锁的位置
|
@Transactional
|
public Response updateAddress(List<LockAddress> list) {
|
//集合中没有就添加有就编辑
|
for (LockAddress lockAddress : list) {
|
//先查询是否存在
|
QueryWrapper wrapper=new QueryWrapper();
|
wrapper.eq("station_id",lockAddress.getStationId());
|
wrapper.eq("lock_id",lockAddress.getLockId());
|
wrapper.last("limit 1");
|
LockAddress judgeAddress=mapper.selectOne(wrapper);
|
if(judgeAddress==null){
|
mapper.insert(lockAddress);
|
}else {
|
UpdateWrapper wrapper1=new UpdateWrapper();
|
wrapper1.set("screen_flag",lockAddress.getScreenFlag());
|
wrapper1.set("address_flag",lockAddress.getAddressFlag());
|
wrapper1.eq("station_id",lockAddress.getStationId());
|
wrapper1.eq("lock_id",lockAddress.getLockId());
|
mapper.update(null,wrapper1);
|
}
|
}
|
return new Response().set(1,true,"编辑锁的位置");
|
}
|
//删除锁的位置
|
public Response delAddress(Integer lockId) {
|
UpdateWrapper wrapper=new UpdateWrapper();
|
wrapper.eq("lock_id",lockId);
|
int flag=mapper.delete(wrapper);
|
return new Response().set(1,flag>0,"删除锁的位置");
|
}
|
//添加锁的位置
|
public Response addAddress(LockAddress address) {
|
int flag=mapper.insert(address);
|
return new Response().set(1,flag>0,"添加锁的位置");
|
}
|
}
|