whyclxw
2025-04-21 a206891cc36384c3bf4b36d9605ba4c01e525374
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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,"添加锁的位置");
    }
}