TInteractionController.java 9.46 KB
Newer Older
wzp's avatar
wzp committed
1 2 3 4
package cn.wisenergy.chnmuseum.party.web.controller;

import cn.wisenergy.chnmuseum.party.auth.SHA256PasswordEncryptionService;
import cn.wisenergy.chnmuseum.party.auth.SecureRandomSaltService;
wzp's avatar
wzp committed
5 6 7
import cn.wisenergy.chnmuseum.party.common.log.MethodLog;
import cn.wisenergy.chnmuseum.party.common.log.OperModule;
import cn.wisenergy.chnmuseum.party.common.log.OperType;
wzp's avatar
wzp committed
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
import cn.wisenergy.chnmuseum.party.common.util.DateUtil80;
import cn.wisenergy.chnmuseum.party.model.TUser;
import cn.wisenergy.chnmuseum.party.service.impl.TUserServiceImpl;
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;
import cn.wisenergy.chnmuseum.party.web.controller.base.BaseController;
import cn.wisenergy.chnmuseum.party.model.TInteraction;
import cn.wisenergy.chnmuseum.party.service.TInteractionService;
import cn.wisenergy.chnmuseum.party.common.enums.AuditStatusEnum;
import cn.wisenergy.chnmuseum.party.common.validator.groups.Add;
import cn.wisenergy.chnmuseum.party.common.validator.groups.Update;
import cn.wisenergy.chnmuseum.party.common.vo.GenericPageParam;

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
30
import org.apache.shiro.authz.annotation.RequiresAuthentication;
wzp's avatar
wzp committed
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
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;
import java.time.LocalDateTime;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * <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;


    @PostMapping("/add")
wzp's avatar
wzp committed
67
    @RequiresAuthentication  //@RequiresPermissions("/interaction/add")
wzp's avatar
wzp committed
68
    @ApiOperation(value = "添加看板互动", notes = "添加看板互动")
wzp's avatar
wzp committed
69
    @MethodLog(operModule = OperModule.INTERACTIVE, operType = OperType.ADD)
wzp's avatar
wzp committed
70 71 72
    public Map<String, Object> saveTInteraction(TInteraction tInteraction) {

        // 保存业务节点信息
wzp's avatar
wzp committed
73 74 75
        boolean result = false;
        try {
            Map<String, Object> resultMap = new LinkedHashMap<String, Object>();
wzp's avatar
wzp committed
76
            if (StringUtils.isBlank(tInteraction.getName()) || StringUtils.isBlank(tInteraction.getPassword())) {
wzp's avatar
wzp committed
77 78
                resultMap.put("resultCode", "400");
                resultMap.put("message", "请输入用户名和密码");
wzp's avatar
wzp committed
79 80 81 82
                return resultMap;
            }
            TUser user = userService.selectByUsername(tInteraction.getName());
            if (user == null) {
wzp's avatar
wzp committed
83 84
                resultMap.put("resultCode", "500");
                resultMap.put("message", "用户名错误");
wzp's avatar
wzp committed
85 86
                return resultMap;
            }
wzp's avatar
wzp committed
87
            if (!"2".equals(user.getType())) {
wzp's avatar
wzp committed
88 89
                resultMap.put("resultCode", "500");
                resultMap.put("message", "用户不是单位管理员");
wzp's avatar
wzp committed
90 91
                return resultMap;
            }
wzp's avatar
wzp committed
92
            if (user.getOrgId()!=null&&!user.getOrgId().equals(tInteraction.getOrganId())){
wzp's avatar
wzp committed
93 94 95 96
                resultMap.put("resultCode", "500");
                resultMap.put("message", "管理员账号不是本机构的单位管理员");
                return resultMap;
            }
wzp's avatar
wzp committed
97 98 99
            byte[] salt = user.getPasswordSalt();
            if (!new String(SHA256PasswordEncryptionService.createPasswordHash(tInteraction.getPassword(), salt))
                    .equals(new String(user.getPasswordHash()))) {
wzp's avatar
wzp committed
100 101
                resultMap.put("resultCode", "500");
                resultMap.put("message", "密码错误");
wzp's avatar
wzp committed
102 103
                return resultMap;
            }
wzp's avatar
wzp committed
104
            tInteraction.setUserId(user.getId());
wzp's avatar
wzp committed
105 106 107 108 109 110 111 112 113 114 115
            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
116
        }
wzp's avatar
wzp committed
117
        return getFailResult();
wzp's avatar
wzp committed
118 119 120
    }

    @PutMapping("/update")
wzp's avatar
wzp committed
121
    @RequiresAuthentication  //@RequiresPermissions("/interaction/update")
wzp's avatar
wzp committed
122
    @ApiOperation(value = "修改看板互动信息", notes = "修改看板互动信息")
wzp's avatar
wzp committed
123
    @MethodLog(operModule = OperModule.INTERACTIVE, operType = OperType.UPDATE)
wzp's avatar
wzp committed
124
    public Map<String, Object> updateTInteraction(TInteraction tInteraction) {
wzp's avatar
wzp committed
125 126 127 128 129 130
        boolean flag = false;
        try {
            flag = tInteractionService.updateById(tInteraction);
            if (!flag) {
                return getFailResult();
            }
wzp's avatar
wzp committed
131
            return getSuccessResult();
wzp's avatar
wzp committed
132 133
        } catch (Exception e) {
            e.printStackTrace();
wzp's avatar
wzp committed
134
        }
wzp's avatar
wzp committed
135

wzp's avatar
wzp committed
136 137 138 139 140
        return getFailResult();
    }


    @DeleteMapping("/delete")
wzp's avatar
wzp committed
141
    @RequiresAuthentication  //@RequiresPermissions("/interaction/delete")
wzp's avatar
wzp committed
142 143
    @ApiOperation(value = "根据ID删除看板互动", notes = "根据ID删除看板互动")
    @ApiImplicitParams(value = {
wzp's avatar
wzp committed
144
            @ApiImplicitParam(name = "id", value = "标识ID", paramType = "query", dataType = "String")
wzp's avatar
wzp committed
145
    })
wzp's avatar
wzp committed
146
    @MethodLog(operModule = OperModule.INTERACTIVE, operType = OperType.DELETE)
wzp's avatar
wzp committed
147
    public Map<String, Object> deleteTInteraction(String id) {
wzp's avatar
wzp committed
148 149 150 151 152 153 154 155 156
        boolean result = tInteractionService.removeById(id);
        if (result) {
            return getSuccessResult();
        }
        return getFailResult();
    }


    @PostMapping("/getList")
wzp's avatar
wzp committed
157
    @RequiresAuthentication  //@RequiresPermissions("/interaction/getList")
wzp's avatar
wzp committed
158 159 160 161 162
    @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
163
    @ApiOperation(value = "获取看板互动列表", notes = "获取看板互动列表")
wzp's avatar
wzp committed
164
    @MethodLog(operModule = OperModule.INTERACTIVE, operType = OperType.SELECT)
wzp's avatar
wzp committed
165
    public Map<String, Object> getTInteractionPageList(String orgId) {
wzp's avatar
wzp committed
166 167
        Page<TInteraction> list = null;
        try {
wzp's avatar
wzp committed
168
            list = tInteractionService.selectPageList(getPage(), orgId);
wzp's avatar
wzp committed
169 170 171 172
            return getResult(list);
        } catch (Exception e) {
            e.printStackTrace();
        }
wzp's avatar
wzp committed
173
        return getFailResult();
wzp's avatar
wzp committed
174 175 176 177 178
    }


    @ApiOperation(value = "获取看板互动详情", notes = "获取看板互动详情")
    @GetMapping("/getById")
wzp's avatar
wzp committed
179
    @RequiresAuthentication  //@RequiresPermissions("/interaction/getById")
wzp's avatar
wzp committed
180
    @MethodLog(operModule = OperModule.INTERACTIVE, operType = OperType.SELECT)
wzp's avatar
wzp committed
181
    public Map<String, Object> getById(String id) {
wzp's avatar
wzp committed
182 183 184 185 186 187 188
        TInteraction tInteraction = null;
        try {
            tInteraction = tInteractionService.getById(id);
            return getResult(tInteraction);
        } catch (Exception e) {
            e.printStackTrace();
        }
wzp's avatar
wzp committed
189
        return getFailResult();
wzp's avatar
wzp committed
190 191 192 193 194 195 196 197 198 199 200
    }


//	@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
201
//		@RequiresAuthentication  //@RequiresPermissions("/interaction/getPageList")
wzp's avatar
wzp committed
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225
//		@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);
//    }


}