AdaKing88
2023-08-23 ae35159387a55199e8ab150ebb97d89d68a235bd
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
package org.jeecg.modules.arj.service.impl;
 
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.modules.arj.entity.Bianxk;
import org.jeecg.modules.arj.mapper.BianxkMapper;
import org.jeecg.modules.arj.service.BianxkService;
import org.jeecg.modules.arj.service.HeadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper;
import org.jeecg.modules.arj.entity.Head;
import org.jeecg.modules.arj.mapper.HeadMapper;
 
import java.util.List;
 
/**
 * ;(head)表服务实现类
 * @author : http://www.chiner.pro
 * @date : 2022-11-22
 */
@Service
public class HeadServiceImpl extends ServiceImpl<HeadMapper, Head> implements HeadService {
    @Autowired
    private HeadMapper headMapper;
 
    @Override
    public Head queryLast(String leixing) {
 
        QueryWrapper Q = new QueryWrapper();
//        LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
//
//
//        if (loginUser != null) {
//            if (loginUser.getUserIdentity() <= 1)
//                Q.eq("createdby", loginUser.getRealname());
//            else {
//                // 0开头的工号是盖线
//                if (loginUser.getWorkNo().indexOf("0") == 0) {
//                    Q.like("shengcx", "盖");
//                }
//                if (loginUser.getWorkNo().indexOf("2") == 0) {
//                    Q.like("shengcx", "二");
//                }
//                if (loginUser.getWorkNo().indexOf("5") == 0) {
//                    Q.like("shengcx", "五");
//                }
//            }
//        }
        Q.orderByDesc("reportTime");
        Q.eq("leixing",leixing);
        Q.last("limit 1");
        List<Head> h = headMapper.selectList(Q);
        if( h != null && h.size() > 0 ) return  h.get(0) ;
 
        return null ;
    }
 
    @Override
    public Head queryLeixingChanxian(String leixing,String shengcx) {
        QueryWrapper Q = new QueryWrapper();
        Q.orderByDesc("reportTime");
        Q.eq("leixing",leixing);
        if( shengcx != null )
        Q.like("shengcx",shengcx);
 
        Q.last("limit 1");
        List<Head> h = headMapper.selectList(Q);
        if( h != null && h.size() > 0 ) return  h.get(0) ;
 
        return null ;
    }
    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    public Head queryById(String id){
        return headMapper.selectById(id);
    }
 
    /**
     * 分页查询
     *
     * @param head 筛选条件
     * @param current 当前页码
     * @param size  每页大小
     * @return
     */
    public Page<Head> paginQuery(Head head, long current, long size){
        //1. 构建动态查询条件
        LambdaQueryWrapper<Head> queryWrapper = new LambdaQueryWrapper<>();
        if(StrUtil.isNotBlank(head.getShengcx())){
            queryWrapper.eq(Head::getShengcx, head.getShengcx());
        }
        if(StrUtil.isNotBlank(head.getChanpin())){
            queryWrapper.eq(Head::getChanpin, head.getChanpin());
        }
        if(StrUtil.isNotBlank(head.getBanci())){
            queryWrapper.eq(Head::getBanci, head.getBanci());
        }
        if(StrUtil.isNotBlank(head.getJiluyuan())){
            queryWrapper.eq(Head::getJiluyuan, head.getJiluyuan());
        }
        //2. 执行分页查询
        Page<Head> pagin = new Page<>(current , size , true);
        IPage<Head> selectResult = headMapper.selectPage(pagin , queryWrapper);
        pagin.setPages(selectResult.getPages());
        pagin.setTotal(selectResult.getTotal());
        pagin.setRecords(selectResult.getRecords());
        //3. 返回结果
        return pagin;
    }
 
    /**
     * 新增数据
     *
     * @param head 实例对象
     * @return 实例对象
     */
    public Head insert(Head head){
        headMapper.insert(head);
        return head;
    }
 
    /**
     * 更新数据
     *
     * @param head 实例对象
     * @return 实例对象
     */
    public Head update(Head head){
        //1. 根据条件动态更新
        LambdaUpdateChainWrapper<Head> chainWrapper = new LambdaUpdateChainWrapper<Head>(headMapper);
        if(StrUtil.isNotBlank(head.getShengcx())){
            chainWrapper.eq(Head::getShengcx, head.getShengcx());
        }
        if(StrUtil.isNotBlank(head.getChanpin())){
            chainWrapper.eq(Head::getChanpin, head.getChanpin());
        }
        if(StrUtil.isNotBlank(head.getBanci())){
            chainWrapper.eq(Head::getBanci, head.getBanci());
        }
        if(StrUtil.isNotBlank(head.getJiluyuan())){
            chainWrapper.eq(Head::getJiluyuan, head.getJiluyuan());
        }
        //2. 设置主键,并更新
        chainWrapper.set(Head::getId, head.getId());
        boolean ret = chainWrapper.update();
        //3. 更新成功了,查询最最对象返回
        if(ret){
            return queryById(head.getId());
        }else{
            return head;
        }
    }
 
    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    public boolean deleteById(String id){
        int total = headMapper.deleteById(id);
        return total > 0;
    }
}