TBoxOperationController.java 9.96 KB
Newer Older
wzp's avatar
wzp committed
1 2
package cn.wisenergy.chnmuseum.party.web.controller;

wzp's avatar
wzp committed
3 4 5
import cn.wisenergy.chnmuseum.party.common.log.MethodLog;
import cn.wisenergy.chnmuseum.party.common.log.OperModule;
import cn.wisenergy.chnmuseum.party.common.log.OperType;
liqin's avatar
liqin committed
6
import cn.wisenergy.chnmuseum.party.common.util.RSAUtils;
liqin's avatar
liqin committed
7
import cn.wisenergy.chnmuseum.party.model.TBoxOperation;
wzp's avatar
wzp committed
8
import cn.wisenergy.chnmuseum.party.model.TUser;
liqin's avatar
liqin committed
9
import cn.wisenergy.chnmuseum.party.service.TBoxOperationService;
wzp's avatar
wzp committed
10
import cn.wisenergy.chnmuseum.party.service.impl.TUserServiceImpl;
liqin's avatar
liqin committed
11
import cn.wisenergy.chnmuseum.party.web.controller.base.BaseController;
wzp's avatar
wzp committed
12 13 14 15 16 17 18 19 20 21 22 23
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
liqin's avatar
liqin committed
24
import java.util.ArrayList;
wzp's avatar
wzp committed
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
import java.util.List;
import java.util.Map;

/**
 * <pre>
 * 机顶盒运维信息 前端控制器
 * </pre>
 *
 * @author Danny Lee
 * @since 2021-03-25
 */
@Slf4j
@RestController
@RequestMapping("/boxOperation")
@Api(tags = {"机顶盒运维信息操作接口"})
public class TBoxOperationController extends BaseController {

    @Resource
    private TBoxOperationService tBoxOperationService;

    @Resource
    private TUserServiceImpl userService;

wzp's avatar
wzp committed
48 49 50 51 52 53 54 55 56 57
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "_index", value = "分页起始偏移量", paramType = "query", dataType = "Integer"),
            @ApiImplicitParam(name = "_size", value = "返回条数", paramType = "query", dataType = "Integer"),
            @ApiImplicitParam(name = "organId", value = "所属单位", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "status", value = "状态 1.未激活 2.已激活 3.故障", paramType = "query", dataType = "Integer"),
            @ApiImplicitParam(name = "areaId", value = "区域", paramType = "query", dataType = "String")
    })
    @PostMapping("/selectPageList")
    @RequiresPermissions("/boxOperation/selectPageList")
    @ApiOperation(value = "获取机顶盒基础信息分页列表", notes = "获取机顶盒基础信息分页列表")
wzp's avatar
wzp committed
58
    @MethodLog(operModule = OperModule.STBBASE,operType = OperType.SELECT)
liqin's avatar
liqin committed
59
    public Map<String, Object> selectPageList(String organId, String areaId) {
wzp's avatar
wzp committed
60
        TUser user1 = getcurUser();
wzp's avatar
wzp committed
61 62 63 64 65
        TUser user = new TUser();
        if (StringUtils.isNotBlank(organId)) {
            user.setOrgId(organId);
        }
        if (StringUtils.isNotBlank(areaId)) {
wzp's avatar
wzp committed
66
            user.setAreaId(areaId);
wzp's avatar
wzp committed
67
        }
wzp's avatar
wzp committed
68
        //设置数据权限
wzp's avatar
wzp committed
69 70 71 72
//        if (StringUtils.isNotBlank(user1.getAreaId())) {
//            String areaId1 = getAreaId(user1.getAreaId());
//            user.setAreaName(areaId1);
//        }
wzp's avatar
wzp committed
73
        user.setOrgCode(user1.getOrgCode());
wzp's avatar
wzp committed
74
        try {
liqin's avatar
liqin committed
75
            Page<TBoxOperation> page = tBoxOperationService.selectBoxPage(getPage(), user);
wzp's avatar
wzp committed
76 77 78 79 80
            return getResult(page);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return getFailResult();
wzp's avatar
wzp committed
81 82
    }

wzp's avatar
wzp committed
83 84 85
    @PostMapping("/add")
    @RequiresPermissions("/boxOperation/add")
    @ApiOperation(value = "添加机顶盒运维信息", notes = "添加机顶盒运维信息")
wzp's avatar
wzp committed
86
    @MethodLog(operModule = OperModule.STBOPERATION,operType = OperType.ADD)
wzp's avatar
wzp committed
87 88
    public Map<String, Object> saveTBoxOperation(TBoxOperation tBoxOperation) {
        // 保存业务节点信息
liqin's avatar
liqin committed
89
        boolean result;
wzp's avatar
wzp committed
90
        try {
liqin's avatar
liqin committed
91 92 93
            if (tBoxOperation != null && StringUtils.isNotBlank(tBoxOperation.getMac())) {
                tBoxOperation.setMac(tBoxOperation.getMac().toUpperCase());
            }
liqin's avatar
liqin committed
94 95 96
            final ArrayList<String> rsaKeys = RSAUtils.createRSAKeys();
            tBoxOperation.setPublicKey(rsaKeys.get(0));
            tBoxOperation.setPrivateKey(rsaKeys.get(1));
wzp's avatar
wzp committed
97 98 99 100
            result = tBoxOperationService.save(tBoxOperation);
            if (!result) {
                return getFailResult();
            }
wzp's avatar
wzp committed
101
            return getSuccessResult();
wzp's avatar
wzp committed
102 103 104
        } catch (Exception e) {
            e.printStackTrace();
        }
liqin's avatar
liqin committed
105 106
        // 保存失败
        return getFailResult();
wzp's avatar
wzp committed
107 108 109 110
    }

    @PutMapping("/update")
    @RequiresPermissions("/boxOperation/update")
wzp's avatar
wzp committed
111
    @ApiOperation(value = "修改机顶盒运维信息", notes = "修改机顶盒运维信息")
wzp's avatar
wzp committed
112
    @MethodLog(operModule = OperModule.STBOPERATION,operType = OperType.ACTIVATION)
wzp's avatar
wzp committed
113
    public Map<String, Object> updateTBoxOperation(TBoxOperation tBoxOperation) {
liqin's avatar
liqin committed
114 115 116 117
        try {
            if (tBoxOperation != null && StringUtils.isNotBlank(tBoxOperation.getMac())) {
                tBoxOperation.setMac(tBoxOperation.getMac().toUpperCase());
            }
wzp's avatar
wzp committed
118 119 120 121 122
            if (2==tBoxOperation.getStatus()) {
                final ArrayList<String> rsaKeys = RSAUtils.createRSAKeys();
                tBoxOperation.setPublicKey(rsaKeys.get(0));
                tBoxOperation.setPrivateKey(rsaKeys.get(1));
            }
liqin's avatar
liqin committed
123 124 125 126 127 128 129 130 131 132 133 134 135
            boolean flag = tBoxOperationService.updateById(tBoxOperation);
            UpdateWrapper<TUser> wrapper = new UpdateWrapper<>();
            wrapper.eq("org_id", tBoxOperation.getOrganId());
            wrapper.eq("type", "3");
            TUser user = userService.getOne(wrapper);
            String password = user.getPassword();
            if (flag) {
                return getResult(password);
            }
            return getFailResult();
        } catch (Exception e) {
            return getFailResult();
        }
wzp's avatar
wzp committed
136 137 138 139 140 141
    }

    @DeleteMapping("/delete")
    @RequiresPermissions("/boxOperation/delete")
    @ApiOperation(value = "根据ID删除机顶盒运维信息", notes = "根据ID删除机顶盒运维信息")
    @ApiImplicitParams(value = {
wzp's avatar
wzp committed
142
            @ApiImplicitParam(name = "id", value = "标识ID", paramType = "query", dataType = "String")
wzp's avatar
wzp committed
143
    })
wzp's avatar
wzp committed
144
    @MethodLog(operModule = OperModule.STBOPERATION,operType = OperType.DELETE)
wzp's avatar
wzp committed
145
    public Map<String, Object> deleteTBoxOperation(String id) {
liqin's avatar
liqin committed
146
        boolean result;
wzp's avatar
wzp committed
147 148 149 150 151
        try {
            result = tBoxOperationService.removeById(id);
            if (!result) {
                return getFailResult();
            }
wzp's avatar
wzp committed
152
            return getSuccessResult();
wzp's avatar
wzp committed
153 154
        } catch (Exception e) {
            e.printStackTrace();
wzp's avatar
wzp committed
155 156 157 158 159 160 161
        }
        return getFailResult();
    }

    @GetMapping("/getList")
    @RequiresPermissions("/boxOperation/getList")
    @ApiOperation(value = "获取机顶盒运维信息全部列表(无分页)", notes = "获取机顶盒运维信息全部列表(无分页)")
wzp's avatar
wzp committed
162
    @MethodLog(operModule = OperModule.STBOPERATION,operType = OperType.SELECT)
wzp's avatar
wzp committed
163
    public Map<String, Object> getTBoxOperationList(String status) {
wzp's avatar
wzp committed
164
        List<TBoxOperation> tBoxOperationList = null;
wzp's avatar
wzp committed
165 166 167
        TUser user = getcurUser();
        //设置数据权限
        String areaId = user.getAreaId();
wzp's avatar
wzp committed
168
        try {
liqin's avatar
liqin committed
169
            tBoxOperationList = tBoxOperationService.getList(status, getAreaId(areaId));
wzp's avatar
wzp committed
170 171 172 173
            return getResult(tBoxOperationList);
        } catch (Exception e) {
            e.printStackTrace();
        }
liqin's avatar
liqin committed
174
        return getFailResult();
wzp's avatar
wzp committed
175 176 177 178 179 180 181 182 183 184 185 186
    }

    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "_index", value = "分页起始偏移量", paramType = "query", dataType = "Integer"),
            @ApiImplicitParam(name = "_size", value = "返回条数", paramType = "query", dataType = "Integer"),
            @ApiImplicitParam(name = "organId", value = "所属单位", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "status", value = "状态 1.未激活 2.已激活 3.故障", paramType = "query", dataType = "Integer"),
            @ApiImplicitParam(name = "areaId", value = "区域", paramType = "query", dataType = "String")
    })
    @PostMapping("/getPageList")
    @RequiresPermissions("/boxOperation/getPageList")
    @ApiOperation(value = "获取机顶盒运维信息分页列表", notes = "获取机顶盒运维信息分页列表")
wzp's avatar
wzp committed
187
    @MethodLog(operModule = OperModule.STBOPERATION,operType = OperType.SELECT)
wzp's avatar
wzp committed
188
    public Map<String, Object> getTBoxOperationPageList(String organId, Integer status, String areaId) {
wzp's avatar
wzp committed
189
        TUser user = getcurUser();
wzp's avatar
wzp committed
190
        TBoxOperation tBoxOperation = new TBoxOperation();
wzp's avatar
wzp committed
191
        if (StringUtils.isNotBlank(organId)) {
wzp's avatar
wzp committed
192
            tBoxOperation.setOrganId(organId);
wzp's avatar
wzp committed
193 194
        }
        if (status != null) {
wzp's avatar
wzp committed
195
            tBoxOperation.setStatus(status);
wzp's avatar
wzp committed
196 197
        }
        if (StringUtils.isNotBlank(areaId)) {
wzp's avatar
wzp committed
198
           tBoxOperation.setAreaId(areaId);
wzp's avatar
wzp committed
199
        }
wzp's avatar
wzp committed
200 201
        if (StringUtils.isNotBlank(user.getAreaId())) {
            //设置数据权限
wzp's avatar
wzp committed
202
            tBoxOperation.setAreaName(getAreaId(user.getAreaId()));
wzp's avatar
wzp committed
203
        }
wzp's avatar
wzp committed
204 205
        Page<TBoxOperation> page = null;
        try {
wzp's avatar
wzp committed
206
            page = this.tBoxOperationService.selectPage(getPage(), tBoxOperation);
wzp's avatar
wzp committed
207 208 209 210 211
            return getResult(page);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return getFailResult();
wzp's avatar
wzp committed
212 213 214 215 216
    }

    @ApiOperation(value = "获取机顶盒运维信息详情", notes = "获取机顶盒运维信息详情")
    @GetMapping("/getById")
    @RequiresPermissions("/boxOperation/getById")
wzp's avatar
wzp committed
217
    @MethodLog(operModule = OperModule.STBOPERATION,operType = OperType.SELECT)
wzp's avatar
wzp committed
218
    public Map<String, Object> getById(@PathVariable("id") String id) {
wzp's avatar
wzp committed
219 220 221 222 223 224 225 226
        TBoxOperation tBoxOperation = null;
        try {
            tBoxOperation = tBoxOperationService.getById(id);
            return getResult(tBoxOperation);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return getFailResult();
wzp's avatar
wzp committed
227 228
    }

wzp's avatar
wzp committed
229

wzp's avatar
wzp committed
230
    public static String getAreaId(String areaId) {
wzp's avatar
wzp committed
231 232
        if ("0000".equals(areaId.substring(2))) {
            areaId = areaId.substring(0, 2);
liqin's avatar
liqin committed
233
        } else if ("00".equals(areaId.substring(4))) {
wzp's avatar
wzp committed
234
            areaId = areaId.substring(0, 4);
wzp's avatar
wzp committed
235 236 237 238
        }
        return areaId;
    }

wzp's avatar
wzp committed
239 240
}