whycxzp
2021-07-26 8c189b243bfbbacb2ab1ce79f4e1ff22708f125a
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
package com.whyc.service;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.whyc.dto.Response;
import com.whyc.mapper.AFERectifierHistoryMapper;
import com.whyc.mapper.AFERectifierMapper;
import com.whyc.mapper.CommonMapper;
import com.whyc.pojo.AFEInverterState;
import com.whyc.pojo.AFERectifierState;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestParam;
 
import javax.annotation.Resource;
import java.sql.Wrapper;
import java.util.List;
 
@Service
public class AFERectifierService {
 
    @Resource
    private AFERectifierMapper mapper;
 
    @Resource
    private AFERectifierHistoryMapper historyMapper;
 
    @Resource
    private CommonMapper commonMapper;
 
    /**分页*/
    public Response<IPage<AFERectifierState>> getAll(int pageNum,int pageSize) {
        IPage<AFERectifierState> afeRectifierStateIPage = mapper.selectPage(new Page<>(pageNum, pageSize), null);
        return new Response<IPage<AFERectifierState>>().set(1,afeRectifierStateIPage);
    }
 
    public Response<AFERectifierState> getInfoByDevId(int devId) {
        QueryWrapper<AFERectifierState> query = Wrappers.query();
        query.eq("dev_id",devId);
        AFERectifierState afeRectifierState = mapper.selectOne(query);
        return new Response<AFERectifierState>().set(1,afeRectifierState);
    }
 
    public Response<PageInfo<AFERectifierState>> getHistory(int pageNum, int pageSize, int devId) {
        List<String> tableNames = commonMapper.getTableName("db_3.5mw_motor_history", "tb_afe_rectifier_state_" + devId);
        PageHelper.startPage(pageNum,pageSize);
        List<AFERectifierState> afeInverterStates = historyMapper.getHistory(tableNames);
        PageInfo<AFERectifierState> afeInverterStatePageInfo = new PageInfo<>(afeInverterStates);
        return new Response<PageInfo<AFERectifierState>>().set(1,afeInverterStatePageInfo);
    }
 
 
    public Response updateState1(int devId, int rectifierRun) {
        UpdateWrapper<AFERectifierState> wrapper = Wrappers.update();
        wrapper.set("rectifier_run",rectifierRun).eq("dev_id",devId);
        mapper.update(null,wrapper);
        return new Response().setMsg(1,"更新成功");
    }
 
    public Response updateState2(int devId, int inverterRun) {
        UpdateWrapper<AFERectifierState> wrapper = Wrappers.update();
        wrapper.set("inverter_run",inverterRun).eq("dev_id",devId);
        mapper.update(null,wrapper);
        return new Response().setMsg(1,"更新成功");
    }
}