TInteractionController.java 10.7 KB
Newer Older
liqin's avatar
liqin committed
1
package cn.chnmuseum.party.web.controller;
wzp's avatar
wzp committed
2

liqin's avatar
liqin committed
3 4
import cn.chnmuseum.party.auth.SHA256PasswordEncryptionService;
import cn.chnmuseum.party.auth.SecureRandomSaltService;
5 6
import cn.chnmuseum.party.auth.util.AESUtils;
import cn.chnmuseum.party.common.enums.AuditOperationEnum;
liqin's avatar
liqin committed
7 8 9 10
import cn.chnmuseum.party.common.log.MethodLog;
import cn.chnmuseum.party.common.log.OperModule;
import cn.chnmuseum.party.common.log.OperType;
import cn.chnmuseum.party.common.util.DateUtil80;
11
import cn.chnmuseum.party.model.Role;
liqin's avatar
liqin committed
12
import cn.chnmuseum.party.model.TUser;
13
import cn.chnmuseum.party.service.RoleService;
liqin's avatar
liqin committed
14
import cn.chnmuseum.party.service.impl.TUserServiceImpl;
wzp's avatar
wzp committed
15 16 17 18
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
liqin's avatar
liqin committed
19 20 21 22 23 24 25
import cn.chnmuseum.party.web.controller.base.BaseController;
import cn.chnmuseum.party.model.TInteraction;
import cn.chnmuseum.party.service.TInteractionService;
import cn.chnmuseum.party.common.enums.AuditStatusEnum;
import cn.chnmuseum.party.common.validator.groups.Add;
import cn.chnmuseum.party.common.validator.groups.Update;
import cn.chnmuseum.party.common.vo.GenericPageParam;
wzp's avatar
wzp committed
26 27 28 29 30 31 32 33

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
34
import org.apache.shiro.authz.annotation.RequiresAuthentication;
wzp's avatar
wzp committed
35 36 37 38 39 40 41 42 43
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;
44
import java.time.LocalDate;
wzp's avatar
wzp committed
45 46 47 48
import java.time.LocalDateTime;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
49
import java.util.stream.Collectors;
wzp's avatar
wzp committed
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70

/**
 * <pre>
 * 看板互动 前端控制器
 * </pre>
 *
 * @author Danny Lee
 * @since 2021-03-23
 */
@Slf4j
@RestController
@RequestMapping("/interaction")
@Api(tags = {"看板互动操作接口"})
public class TInteractionController extends BaseController {

    @Resource
    private TInteractionService tInteractionService;

    @Resource
    private TUserServiceImpl userService;

71 72 73
    @Resource
    private RoleService roleService;

wzp's avatar
wzp committed
74 75

    @PostMapping("/add")
wzp's avatar
wzp committed
76
    @RequiresAuthentication  //@RequiresPermissions("/interaction/add")
wzp's avatar
wzp committed
77
    @ApiOperation(value = "添加看板互动", notes = "添加看板互动")
wzp's avatar
wzp committed
78
    @MethodLog(operModule = OperModule.INTERACTIVE, operType = OperType.ADD)
wzp's avatar
wzp committed
79
    public Map<String, Object> saveTInteraction(TInteraction tInteraction) {
wzp's avatar
wzp committed
80
        TUser user = getcurUser();
wzp's avatar
wzp committed
81
        // 保存业务节点信息
wzp's avatar
wzp committed
82 83 84
        boolean result = false;
        try {
            Map<String, Object> resultMap = new LinkedHashMap<String, Object>();
85 86 87 88 89 90
            // 验证互动审核员账号
            if (StringUtils.isBlank(tInteraction.getName()) || StringUtils.isBlank(tInteraction.getPassword())) {
                resultMap.put("resultCode", "400");
                resultMap.put("message", "互动管理员账号或密码不能为空");
                return resultMap;
            }
91 92 93 94 95 96
            // 只能填写当前操作的互动审核员账号
            if (!tInteraction.getName().equals(user.getUserName())) {
                resultMap.put("resultCode", "400");
                resultMap.put("message", "请填写当前登录用户的账号和密码");
                return resultMap;
            }
97 98 99 100 101 102
            TUser tUser = userService.selectByUsername(tInteraction.getName());
            if (tUser == null) {
                resultMap.put("resultCode", "400");
                resultMap.put("message", "用户名不正确!");
                return resultMap;
            }
103
            if (AuditOperationEnum.DISABLE.name().equals(tUser.getStatus())) {
104 105 106 107
                resultMap.put("resultCode", "400");
                resultMap.put("message", "此帐号已禁用,请联系管理员!");
                return resultMap;
            }
108
            if (tUser.getPermanent() != null && !tUser.getPermanent()) {
109 110 111 112 113 114 115 116
                if (user.getEffectiveDate() != null && user.getEffectiveDate().isAfter(LocalDate.now()) || user.getExiredDate() != null && user.getExiredDate().isBefore(LocalDate.now())) {
                    resultMap.put("resultCode", "400");
                    resultMap.put("message", "此帐号已失效,请联系管理员!");
                    return resultMap;
                }
            }
            //密码解密
            String s = AESUtils.aesDecrypt(tInteraction.getPassword());
117
            byte[] salt = tUser.getPasswordSalt();
118
            String s1 = new String(SHA256PasswordEncryptionService.createPasswordHash(s, salt));
119
            if (!s1.equals(new String(tUser.getPasswordHash()))) {
120 121 122 123
                resultMap.put("resultCode", "400");
                resultMap.put("message", "密码不正确!");
                return resultMap;
            }
124
            List<Role> roles = roleService.selectRoleByUserId(tUser.getId());
125 126 127 128 129 130
            List<String> roleIds = roles.stream().map(Role::getId).collect(Collectors.toList());
            if (!roleIds.contains("17")) {
                resultMap.put("resultCode", "400");
                resultMap.put("message", "所填写账号非互动审核员!");
                return resultMap;
            }
wzp's avatar
wzp committed
131
            tInteraction.setUserId(user.getId());
wzp's avatar
wzp committed
132 133 134 135 136 137 138 139 140 141 142
            tInteraction.setCreateTime(LocalDateTime.now());
            result = tInteractionService.save(tInteraction);
            // 返回操作结果
            if (result) {
                return getSuccessResult();
            } else {
                // 保存失败
                return getFailResult();
            }
        } catch (Exception e) {
            e.printStackTrace();
wzp's avatar
wzp committed
143
        }
wzp's avatar
wzp committed
144
        return getFailResult();
wzp's avatar
wzp committed
145 146 147
    }

    @PutMapping("/update")
wzp's avatar
wzp committed
148
    @RequiresAuthentication  //@RequiresPermissions("/interaction/update")
wzp's avatar
wzp committed
149
    @ApiOperation(value = "修改看板互动信息", notes = "修改看板互动信息")
wzp's avatar
wzp committed
150
    @MethodLog(operModule = OperModule.INTERACTIVE, operType = OperType.UPDATE)
wzp's avatar
wzp committed
151
    public Map<String, Object> updateTInteraction(TInteraction tInteraction) {
wzp's avatar
wzp committed
152 153 154 155 156 157
        boolean flag = false;
        try {
            flag = tInteractionService.updateById(tInteraction);
            if (!flag) {
                return getFailResult();
            }
wzp's avatar
wzp committed
158
            return getSuccessResult();
wzp's avatar
wzp committed
159 160
        } catch (Exception e) {
            e.printStackTrace();
wzp's avatar
wzp committed
161
        }
wzp's avatar
wzp committed
162

wzp's avatar
wzp committed
163 164 165 166 167
        return getFailResult();
    }


    @DeleteMapping("/delete")
wzp's avatar
wzp committed
168
    @RequiresAuthentication  //@RequiresPermissions("/interaction/delete")
wzp's avatar
wzp committed
169 170
    @ApiOperation(value = "根据ID删除看板互动", notes = "根据ID删除看板互动")
    @ApiImplicitParams(value = {
wzp's avatar
wzp committed
171
            @ApiImplicitParam(name = "id", value = "标识ID", paramType = "query", dataType = "String")
wzp's avatar
wzp committed
172
    })
wzp's avatar
wzp committed
173
    @MethodLog(operModule = OperModule.INTERACTIVE, operType = OperType.DELETE)
wzp's avatar
wzp committed
174
    public Map<String, Object> deleteTInteraction(String id) {
wzp's avatar
wzp committed
175 176 177 178 179 180 181 182 183
        boolean result = tInteractionService.removeById(id);
        if (result) {
            return getSuccessResult();
        }
        return getFailResult();
    }


    @PostMapping("/getList")
wzp's avatar
wzp committed
184
    @RequiresAuthentication  //@RequiresPermissions("/interaction/getList")
wzp's avatar
wzp committed
185 186 187 188 189
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "_index", value = "分页起始偏移量", paramType = "query", dataType = "Integer"),
            @ApiImplicitParam(name = "_size", value = "返回条数", paramType = "query", dataType = "Integer"),
            @ApiImplicitParam(name = "orgId", value = "机构id", paramType = "query", dataType = "String")
    })
wzp's avatar
wzp committed
190
    @ApiOperation(value = "获取看板互动列表", notes = "获取看板互动列表")
wzp's avatar
wzp committed
191
    @MethodLog(operModule = OperModule.INTERACTIVE, operType = OperType.SELECT)
wzp's avatar
wzp committed
192
    public Map<String, Object> getTInteractionPageList(String orgId) {
wzp's avatar
wzp committed
193 194
        Page<TInteraction> list = null;
        try {
wzp's avatar
wzp committed
195
            list = tInteractionService.selectPageList(getPage(), orgId);
wzp's avatar
wzp committed
196 197 198 199
            return getResult(list);
        } catch (Exception e) {
            e.printStackTrace();
        }
wzp's avatar
wzp committed
200
        return getFailResult();
wzp's avatar
wzp committed
201 202 203 204 205
    }


    @ApiOperation(value = "获取看板互动详情", notes = "获取看板互动详情")
    @GetMapping("/getById")
wzp's avatar
wzp committed
206
    @RequiresAuthentication  //@RequiresPermissions("/interaction/getById")
wzp's avatar
wzp committed
207
    @MethodLog(operModule = OperModule.INTERACTIVE, operType = OperType.SELECT)
wzp's avatar
wzp committed
208
    public Map<String, Object> getById(String id) {
wzp's avatar
wzp committed
209 210 211 212 213 214 215
        TInteraction tInteraction = null;
        try {
            tInteraction = tInteractionService.getById(id);
            return getResult(tInteraction);
        } catch (Exception e) {
            e.printStackTrace();
        }
wzp's avatar
wzp committed
216
        return getFailResult();
wzp's avatar
wzp committed
217 218 219 220 221 222 223 224 225 226 227
    }


//	@ApiImplicitParams(value = {
//			@ApiImplicitParam(name = "_index", value = "分页起始偏移量", paramType = "query", dataType = "Integer"),
//			@ApiImplicitParam(name = "_size", value = "返回条数", paramType = "query", dataType = "Integer"),
//			@ApiImplicitParam(name = "nameOrCode", value = "名称或编码", paramType = "query", dataType = "String"),
//			@ApiImplicitParam(name = "startDate", value = "创建时间-开始", paramType = "query", dataType = "String"),
//			@ApiImplicitParam(name = "endDate", value = "创建时间-结束", paramType = "query", dataType = "String")
//	})
//    @PostMapping("/getPageList")
wzp's avatar
wzp committed
228
//		@RequiresAuthentication  //@RequiresPermissions("/interaction/getPageList")
wzp's avatar
wzp committed
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252
//		@ApiOperation(value = "获取看板互动分页列表", notes = "获取看板互动分页列表")
//    public Map<String, Object> getTInteractionPageList(GenericPageParam genericPageParam) {
//		LambdaQueryWrapper<TInteraction> queryWrapper = new LambdaQueryWrapper<>();
//		// 对名称或编码模糊查询
//		if (StringUtils.isNotBlank(genericPageParam.getNameOrCode())) {
//			queryWrapper.like(TInteraction::getUsername, genericPageParam.getNameOrCode());
//		}
//		// 根据创建时间区间检索
//		if (genericPageParam.getStartDate() != null && genericPageParam.getEndDate() != null) {
//			queryWrapper.ge(TInteraction::getCreateTime, genericPageParam.getStartDate().atTime(0, 0, 0))
//				.le(TInteraction::getCreateTime, genericPageParam.getEndDate().atTime(23, 59, 59));
//		}
//		// 设置排序规则
//		queryWrapper.orderByDesc(TInteraction::getCreateTime);
//		Page<TInteraction> page = this.tInteractionService.page(getPage(), queryWrapper);
//		for (TInteraction tInteraction : page.getRecords()) {
//
//		}
//		return getResult(page);
//    }


}