TBoxOperationController.java 10.2 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
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;
wzp's avatar
wzp committed
20
import org.apache.shiro.authz.annotation.RequiresAuthentication;
wzp's avatar
wzp committed
21 22 23 24
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
liqin's avatar
liqin committed
25
import java.util.ArrayList;
wzp's avatar
wzp committed
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
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
49 50 51 52 53 54 55 56
    @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")
wzp's avatar
wzp committed
57
    @RequiresAuthentication  //@RequiresPermissions("/boxOperation/selectPageList")
wzp's avatar
wzp committed
58
    @ApiOperation(value = "获取机顶盒基础信息分页列表", notes = "获取机顶盒基础信息分页列表")
wzp's avatar
wzp committed
59
    @MethodLog(operModule = OperModule.STBBASE,operType = OperType.SELECT)
liqin's avatar
liqin committed
60
    public Map<String, Object> selectPageList(String organId, String areaId) {
wzp's avatar
wzp committed
61
        TUser user1 = getcurUser();
wzp's avatar
wzp committed
62 63 64 65 66
        TUser user = new TUser();
        if (StringUtils.isNotBlank(organId)) {
            user.setOrgId(organId);
        }
        if (StringUtils.isNotBlank(areaId)) {
wzp's avatar
wzp committed
67
            user.setAreaId(areaId);
wzp's avatar
wzp committed
68
        }
wzp's avatar
wzp committed
69
        //设置数据权限
wzp's avatar
wzp committed
70 71 72 73
//        if (StringUtils.isNotBlank(user1.getAreaId())) {
//            String areaId1 = getAreaId(user1.getAreaId());
//            user.setAreaName(areaId1);
//        }
wzp's avatar
wzp committed
74
        user.setOrgCode(user1.getOrgCode());
wzp's avatar
wzp committed
75
        try {
liqin's avatar
liqin committed
76
            Page<TBoxOperation> page = tBoxOperationService.selectBoxPage(getPage(), user);
wzp's avatar
wzp committed
77 78 79 80 81
            return getResult(page);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return getFailResult();
wzp's avatar
wzp committed
82 83
    }

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

    @PutMapping("/update")
wzp's avatar
wzp committed
111
    @RequiresAuthentication  //@RequiresPermissions("/boxOperation/update")
wzp's avatar
wzp committed
112
    @ApiOperation(value = "修改机顶盒运维信息", notes = "修改机顶盒运维信息")
wzp's avatar
wzp committed
113
    @MethodLog(operModule = OperModule.STBOPERATION,operType = OperType.ACTIVATION)
wzp's avatar
wzp committed
114
    public Map<String, Object> updateTBoxOperation(TBoxOperation tBoxOperation) {
liqin's avatar
liqin committed
115 116 117 118
        try {
            if (tBoxOperation != null && StringUtils.isNotBlank(tBoxOperation.getMac())) {
                tBoxOperation.setMac(tBoxOperation.getMac().toUpperCase());
            }
wzp's avatar
wzp committed
119 120 121 122 123
            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
124 125 126 127 128 129 130 131 132 133 134 135 136
            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
137 138 139
    }

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

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

    @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")
wzp's avatar
wzp committed
186
    @RequiresAuthentication  //@RequiresPermissions("/boxOperation/getPageList")
wzp's avatar
wzp committed
187
    @ApiOperation(value = "获取机顶盒运维信息分页列表", notes = "获取机顶盒运维信息分页列表")
wzp's avatar
wzp committed
188
    @MethodLog(operModule = OperModule.STBOPERATION,operType = OperType.SELECT)
wzp's avatar
wzp committed
189
    public Map<String, Object> getTBoxOperationPageList(String organId, Integer status, String areaId) {
wzp's avatar
wzp committed
190
        TUser user = getcurUser();
wzp's avatar
wzp committed
191
        TBoxOperation tBoxOperation = new TBoxOperation();
wzp's avatar
wzp committed
192
        if (StringUtils.isNotBlank(organId)) {
wzp's avatar
wzp committed
193
            tBoxOperation.setOrganId(organId);
wzp's avatar
wzp committed
194 195
        }
        if (status != null) {
wzp's avatar
wzp committed
196
            tBoxOperation.setStatus(status);
wzp's avatar
wzp committed
197 198
        }
        if (StringUtils.isNotBlank(areaId)) {
wzp's avatar
wzp committed
199
           tBoxOperation.setAreaId(areaId);
wzp's avatar
wzp committed
200
        }
wzp's avatar
wzp committed
201 202
        if (StringUtils.isNotBlank(user.getAreaId())) {
            //设置数据权限
wzp's avatar
wzp committed
203
            tBoxOperation.setAreaName(getAreaId(user.getAreaId()));
wzp's avatar
wzp committed
204
        }
wzp's avatar
wzp committed
205 206
        Page<TBoxOperation> page = null;
        try {
wzp's avatar
wzp committed
207
            page = this.tBoxOperationService.selectPage(getPage(), tBoxOperation);
wzp's avatar
wzp committed
208 209 210 211 212
            return getResult(page);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return getFailResult();
wzp's avatar
wzp committed
213 214 215 216
    }

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

wzp's avatar
wzp committed
230

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

wzp's avatar
wzp committed
240 241
}