whycxzp
2021-03-05 e7a7b634352f684085bb6eea34b331fc069ff44d
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
package com.whyc.service;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.whyc.dto.Response;
import com.whyc.mapper.CommonMapper;
import com.whyc.mapper.OilCommHistoryMapper;
import com.whyc.mapper.OilCommMapper;
import com.whyc.pojo.CentralMonitorSysST;
import com.whyc.pojo.OilComm;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.util.List;
 
/**
 * Oil通讯
 */
@Service
public class OilCommService {
 
    @Resource
    private OilCommMapper mapper;
 
    @Resource
    private OilCommHistoryMapper historyMapper;
 
    @Resource
    private CommonMapper commonMapper;
 
    public Response<List<OilComm>> getAll() {
        try {
            List<OilComm> Oils = mapper.selectList(null);
            return new Response<List<OilComm>>().set(1,Oils);
        } catch (Exception e) {
            e.printStackTrace();
            return new Response().setCode(0);
        }
    }
 
    public Response<OilComm> getInfoByDevId(int devId) {
        try{
            QueryWrapper<OilComm> queryWrapper = Wrappers.query();
            queryWrapper.eq("dev_id",devId);
            OilComm oilComm = mapper.selectOne(queryWrapper);
            return new Response<OilComm>().set(1,oilComm);
        }catch (Exception e){
            e.printStackTrace();
            return new Response<OilComm>().setCode(0);
 
        }
    }
 
    public Response<PageInfo<OilComm>> getHistory(int pageNum, int pageSize, int devId) {
        List<String> tableNames = commonMapper.getTableName("db_3.5mw_motor_history", "tb_oil_comm_" + devId);
        PageHelper.startPage(pageNum,pageSize);
        List<OilComm> oilComms = historyMapper.getHistory(tableNames);
        PageInfo<OilComm> oilCommPageInfo = new PageInfo<>(oilComms);
        return new Response<PageInfo<OilComm>>().set(1,oilCommPageInfo);
    }
}