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

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

    @PutMapping("/update")
wzp's avatar
wzp committed
112
    @RequiresAuthentication  //@RequiresPermissions("/boxOperation/update")
wzp's avatar
wzp committed
113
    @ApiOperation(value = "修改机顶盒运维信息", notes = "修改机顶盒运维信息")
wzp's avatar
wzp committed
114
    @MethodLog(operModule = OperModule.STBOPERATION,operType = OperType.ACTIVATION)
wzp's avatar
wzp committed
115
    public Map<String, Object> updateTBoxOperation(TBoxOperation tBoxOperation) {
wzp's avatar
wzp committed
116
        Map<String, Object> resultMap = new LinkedHashMap<String, Object>();
liqin's avatar
liqin committed
117 118 119 120
        try {
            if (tBoxOperation != null && StringUtils.isNotBlank(tBoxOperation.getMac())) {
                tBoxOperation.setMac(tBoxOperation.getMac().toUpperCase());
            }
wzp's avatar
wzp committed
121
            if (2==tBoxOperation.getStatus()) {
wzp's avatar
wzp committed
122
                TBoxOperation byId = tBoxOperationService.getById(tBoxOperation.getId());
wzp's avatar
wzp committed
123
                if (byId.getMac()!=null&&!"".equals(byId.getMac())&&!byId.getMac().equals(tBoxOperation.getMac())){
wzp's avatar
wzp committed
124 125 126 127
                    resultMap.put("resultCode", "500");
                    resultMap.put("message", "此账号已绑定机顶盒!");
                    return resultMap;
                }
wzp's avatar
wzp committed
128 129 130
                UpdateWrapper<TBoxOperation> wrapper = new UpdateWrapper<>();
                wrapper.eq("mac",tBoxOperation.getMac());
                TBoxOperation one = tBoxOperationService.getOne(wrapper);
wzp's avatar
wzp committed
131
                if (one!=null&&!one.getOrganId().equals(tBoxOperation.getOrganId())){
wzp's avatar
wzp committed
132 133 134 135 136
                    TUser u = userService.getOne(new UpdateWrapper<TUser>().eq("org_id", one.getOrganId()).eq("type", 3).eq("is_deleted", false));
                    resultMap.put("resultCode", "500");
                    resultMap.put("message", "此mac地址已绑定"+u.getUserName()+"账号!");
                    return resultMap;
                }
wzp's avatar
wzp committed
137 138 139 140
                final ArrayList<String> rsaKeys = RSAUtils.createRSAKeys();
                tBoxOperation.setPublicKey(rsaKeys.get(0));
                tBoxOperation.setPrivateKey(rsaKeys.get(1));
            }
wzp's avatar
wzp committed
141 142 143
            if (3==tBoxOperation.getStatus()) {
                tBoxOperation.setMac("");
            }
liqin's avatar
liqin committed
144 145 146 147 148 149 150 151 152 153 154 155 156
            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
157 158 159
    }

    @DeleteMapping("/delete")
wzp's avatar
wzp committed
160
    @RequiresAuthentication  //@RequiresPermissions("/boxOperation/delete")
wzp's avatar
wzp committed
161 162
    @ApiOperation(value = "根据ID删除机顶盒运维信息", notes = "根据ID删除机顶盒运维信息")
    @ApiImplicitParams(value = {
wzp's avatar
wzp committed
163
            @ApiImplicitParam(name = "id", value = "标识ID", paramType = "query", dataType = "String")
wzp's avatar
wzp committed
164
    })
wzp's avatar
wzp committed
165
    @MethodLog(operModule = OperModule.STBOPERATION,operType = OperType.DELETE)
wzp's avatar
wzp committed
166
    public Map<String, Object> deleteTBoxOperation(String id) {
liqin's avatar
liqin committed
167
        boolean result;
wzp's avatar
wzp committed
168 169 170 171 172
        try {
            result = tBoxOperationService.removeById(id);
            if (!result) {
                return getFailResult();
            }
wzp's avatar
wzp committed
173
            return getSuccessResult();
wzp's avatar
wzp committed
174 175
        } catch (Exception e) {
            e.printStackTrace();
wzp's avatar
wzp committed
176 177 178 179 180
        }
        return getFailResult();
    }

    @GetMapping("/getList")
wzp's avatar
wzp committed
181
    @RequiresAuthentication  //@RequiresPermissions("/boxOperation/getList")
wzp's avatar
wzp committed
182
    @ApiOperation(value = "获取机顶盒运维信息全部列表(无分页)", notes = "获取机顶盒运维信息全部列表(无分页)")
wzp's avatar
wzp committed
183
    @MethodLog(operModule = OperModule.STBOPERATION,operType = OperType.SELECT)
wzp's avatar
wzp committed
184
    public Map<String, Object> getTBoxOperationList(String status) {
wzp's avatar
wzp committed
185
        List<TBoxOperation> tBoxOperationList = null;
wzp's avatar
wzp committed
186 187 188
        TUser user = getcurUser();
        //设置数据权限
        String areaId = user.getAreaId();
wzp's avatar
wzp committed
189
        try {
liqin's avatar
liqin committed
190
            tBoxOperationList = tBoxOperationService.getList(status, getAreaId(areaId));
wzp's avatar
wzp committed
191 192 193 194
            return getResult(tBoxOperationList);
        } catch (Exception e) {
            e.printStackTrace();
        }
liqin's avatar
liqin committed
195
        return getFailResult();
wzp's avatar
wzp committed
196 197 198 199 200 201 202 203 204 205
    }

    @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
206
    @RequiresAuthentication  //@RequiresPermissions("/boxOperation/getPageList")
wzp's avatar
wzp committed
207
    @ApiOperation(value = "获取机顶盒运维信息分页列表", notes = "获取机顶盒运维信息分页列表")
wzp's avatar
wzp committed
208
    @MethodLog(operModule = OperModule.STBOPERATION,operType = OperType.SELECT)
wzp's avatar
wzp committed
209
    public Map<String, Object> getTBoxOperationPageList(String organId, Integer status, String areaId) {
wzp's avatar
wzp committed
210
        TUser user = getcurUser();
wzp's avatar
wzp committed
211
        TBoxOperation tBoxOperation = new TBoxOperation();
wzp's avatar
wzp committed
212
        if (StringUtils.isNotBlank(organId)) {
wzp's avatar
wzp committed
213
            tBoxOperation.setOrganId(organId);
wzp's avatar
wzp committed
214 215
        }
        if (status != null) {
wzp's avatar
wzp committed
216
            tBoxOperation.setStatus(status);
wzp's avatar
wzp committed
217 218
        }
        if (StringUtils.isNotBlank(areaId)) {
wzp's avatar
wzp committed
219
           tBoxOperation.setAreaId(areaId);
wzp's avatar
wzp committed
220
        }
wzp's avatar
wzp committed
221 222
        if (StringUtils.isNotBlank(user.getAreaId())) {
            //设置数据权限
wzp's avatar
wzp committed
223
            tBoxOperation.setAreaName(getAreaId(user.getAreaId()));
wzp's avatar
wzp committed
224
        }
wzp's avatar
wzp committed
225 226
        Page<TBoxOperation> page = null;
        try {
wzp's avatar
wzp committed
227
            page = this.tBoxOperationService.selectPage(getPage(), tBoxOperation);
wzp's avatar
wzp committed
228 229 230 231 232
            return getResult(page);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return getFailResult();
wzp's avatar
wzp committed
233 234 235 236
    }

    @ApiOperation(value = "获取机顶盒运维信息详情", notes = "获取机顶盒运维信息详情")
    @GetMapping("/getById")
wzp's avatar
wzp committed
237
    @RequiresAuthentication  //@RequiresPermissions("/boxOperation/getById")
wzp's avatar
wzp committed
238
    @MethodLog(operModule = OperModule.STBOPERATION,operType = OperType.SELECT)
wzp's avatar
wzp committed
239
    public Map<String, Object> getById(String id) {
wzp's avatar
wzp committed
240 241 242 243 244 245 246 247
        TBoxOperation tBoxOperation = null;
        try {
            tBoxOperation = tBoxOperationService.getById(id);
            return getResult(tBoxOperation);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return getFailResult();
wzp's avatar
wzp committed
248 249
    }

wzp's avatar
wzp committed
250

wzp's avatar
wzp committed
251
    public static String getAreaId(String areaId) {
wzp's avatar
wzp committed
252 253
        if ("0000".equals(areaId.substring(2))) {
            areaId = areaId.substring(0, 2);
liqin's avatar
liqin committed
254
        } else if ("00".equals(areaId.substring(4))) {
wzp's avatar
wzp committed
255
            areaId = areaId.substring(0, 4);
wzp's avatar
wzp committed
256 257 258 259
        }
        return areaId;
    }

wzp's avatar
wzp committed
260 261
}