whycxzp
2022-09-16 ba4df2d373ffd0a1a3536af9a5c44c7af6ef7e48
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
58
59
60
61
62
63
64
65
66
package com.whyc.service;
 
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.AttachLockMapper;
import com.whyc.pojo.AttachLock;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.List;
 
@Service
public class AttachLockService {
    @Autowired(required = false)
    private AttachLockMapper mapper;
 
    @Transactional
    public Response attachLock(List<AttachLock> list) {
        if(list!=null&&list.size()>0){}
            list.stream().forEach(attachLock -> {
                //1.查询是否存在该记录
                QueryWrapper qwrapper=new QueryWrapper();
                qwrapper.eq("material_id",attachLock.getMaterialId());
                qwrapper.eq("attach_name",attachLock.getAttachName());
                qwrapper.last("limit 1");
                AttachLock attach=mapper.selectOne(qwrapper);
                if(attach!=null){
                    UpdateWrapper uwrapper=new UpdateWrapper();
                    uwrapper.set("lock_flag",attachLock.getLockFlag());
                    uwrapper.set("local_reason",attachLock.getLocalReason());
                    uwrapper.eq("attach_name",attachLock.getAttachName());
                    uwrapper.eq("material_id",attachLock.getMaterialId());
                    mapper.update(null,uwrapper);
                }else{
                    mapper.insert(attachLock);
                }
            });
        return new Response().set(1,true,"");
    }
 
    @Transactional
    public Response updateProductLock(List<AttachLock> list) {
        if(list!=null&&list.size()>0){}
        list.stream().forEach(attachLock -> {
            //1.查询是否存在该记录
            QueryWrapper qwrapper=new QueryWrapper();
            qwrapper.eq("product_id",attachLock.getProductId());
            qwrapper.eq("attach_name",attachLock.getAttachName());
            qwrapper.last("limit 1");
            AttachLock attach=mapper.selectOne(qwrapper);
            if(attach!=null){
                UpdateWrapper uwrapper=new UpdateWrapper();
                uwrapper.set("lock_flag",attachLock.getLockFlag());
                uwrapper.set("local_reason",attachLock.getLocalReason());
                uwrapper.eq("attach_name",attachLock.getAttachName());
                uwrapper.eq("product_id",attachLock.getProductId());
                mapper.update(null,uwrapper);
            }else{
                mapper.insert(attachLock);
            }
        });
        return new Response().set(1,true,"");
    }
}