whycxzp
2023-02-25 ade751704a36681e5eb0e55c3db8458896a0135c
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
package com.whyc.service;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.pagehelper.PageInfo;
import com.whyc.dto.Response;
import com.whyc.factory.TableInitFactory;
import com.whyc.mapper.PageParam2Mapper;
import com.whyc.mapper.PageParamMapper;
import com.whyc.pojo.PageParam;
import com.whyc.pojo.PageParam2;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
 
@Service
public class PageParamService {
 
    @Resource
    private PageParamMapper mapper;
    @Resource
    private PageParam2Mapper param2Mapper;
 
    public Map<Integer, List<PageParam>> getAllList(int categoryId) {
        QueryWrapper<PageParam> wrapper = Wrappers.query();
        wrapper.eq("categoryId",categoryId);
        List<PageParam> pageParamList = mapper.selectList(wrapper);
        return pageParamList.stream().collect(Collectors.groupingBy(PageParam::getStatus));
    }
 
    public List<PageParam> getList(int categoryId) {
        QueryWrapper<PageParam> wrapper = Wrappers.query();
        wrapper.eq("categoryId",categoryId).eq("status",1);
        return mapper.selectList(wrapper);
    }
 
    public void updateList(List<PageParam> pageParamList, int operationFlag) {
        //添加
        mapper.updateList(pageParamList,operationFlag);
    }
 
    public void addList(List<PageParam> pageParamList) {
        mapper.insertBatchSomeColumn(pageParamList);
    }
 
    //在线监测-查询拓扑图状态的显示/查询控制信息
    public Response findByCategoryId(int categoryId) {
        boolean res=mapper.exist();
        List<PageParam> listparam= TableInitFactory.getPageParamInit();
        if(!res) { //表不存在,新建表,同时初始化参数
            mapper.createTable();
            mapper.init(listparam);
        }else {
            int count=mapper.getCount();
            if(count==0){
                boolean inited = mapper.init(listparam);
            }
        }
 
        List list=mapper.findByCategoryId(categoryId);
        PageInfo pageInfo=new PageInfo(list);
        return new Response().set(1,pageInfo);
    }
 
    public Response update(int id,int status){
        //如果id为40(账号登录失败限制次数),status的取值范围必须为1~10
        if(id == 40 && (status < 1 || status >10)){
            return new Response().set(1,false,"账号登录失败限制次数不在1~10范围内,修改失败");
        }
        int flag = mapper.update(id,status);
        return new Response().set(1,flag>0?true:false);
    }
 
 
    public Response updateParamById(PageParam param){
        if (mapper.updateById(param)>0){
            return new Response().set(1,true,"更新成功");
        }else {
            return new Response().set(1, false,"更新失败");
        }
    }
 
    public Response getListByCategoryId(int categoryId){
        QueryWrapper<PageParam2> queryWrapper = new QueryWrapper();
        queryWrapper.eq("categoryId",categoryId);
        List<PageParam2> param2List = param2Mapper.selectList(queryWrapper);
        if (param2List.size()==1){
            return new Response().set(1,param2List.get(0));
        }else {
            return new Response().set(1,param2List);
        }
    }
 
    public Response updateAudiCap(PageParam2 pageParam2){
        int flag = param2Mapper.updateById(pageParam2);
        return new Response().set(1,flag>0?true:false,"更新成功");
    }
 
}