EmergencyCommandLiaisonUserController.java 8.0 KB
package com.skua.modules.emergency.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.skua.core.api.vo.Result;
import com.skua.core.aspect.annotation.AutoLog;
import com.skua.modules.emergency.entity.EmergencyCommandLiaison;
import com.skua.modules.emergency.entity.EmergencyCommandLiaisonUser;
import com.skua.modules.emergency.service.IEmergencyCommandLiaisonService;
import com.skua.modules.emergency.service.IEmergencyCommandLiaisonUserService;
import com.skua.modules.emergency.vo.EmergencyCommandLiaisonUserVO;
import com.skua.modules.system.entity.SysUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;

 /**
 * 应急联络图关联人员
  * @author 11389
 */
@Slf4j
@Api(tags="应急联络图关联人员")
@RestController
@RequestMapping("/emergency/emergencyCommandLiaisonUser")
public class EmergencyCommandLiaisonUserController {
	@Autowired
	private IEmergencyCommandLiaisonUserService emergencyCommandLiaisonUserService;
	 @Autowired
	 private IEmergencyCommandLiaisonService emergencyCommandLiaisonService;

	 @AutoLog(value = "应急联络图关联人员-指定查询关联用户")
	 @ApiOperation(value="应急联络图关联人员-指定查询关联用户", notes="应急联络图关联人员-指定查询关联用户")
	 @GetMapping(value = "/queryUserList")
	 public Result<IPage<SysUser>> queryUserList(@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
														@RequestParam(name="pageSize", defaultValue="10") Integer pageSize, HttpServletRequest req) {
		 Result<IPage<SysUser>> result = new Result<>();
		 Page<SysUser> page = new Page<>(pageNo, pageSize);
		 String emergencyId = req.getParameter("emergencyCommandLiaisonId");
		 String username = req.getParameter("username");
		 IPage<SysUser> pageList = emergencyCommandLiaisonUserService.getUserByEmergencyId(page,emergencyId,username);
		 result.setSuccess(true);
		 result.setResult(pageList);
		 return result;
	 }

	 @AutoLog(value = "应急联络图关联人员-指定添加关联用户")
	 @ApiOperation(value="应急联络图关联人员-指定添加关联用户", notes="应急联络图关联人员-指定添加关联用户")
	 @PostMapping(value = "/addUser")
	 public Result<String> addUser(@RequestBody EmergencyCommandLiaisonUserVO emergencyCommandLiaisonUserVO) {
		 Result<String> result = new Result<>();
		 try {
			 String emergencyCommandLiaisonId = emergencyCommandLiaisonUserVO.getEmergencyCommandLiaisonId();
			 for(String sysUserId: emergencyCommandLiaisonUserVO.getUserIdList()) {
				 EmergencyCommandLiaisonUser user = new EmergencyCommandLiaisonUser(emergencyCommandLiaisonId,sysUserId);
				 QueryWrapper<EmergencyCommandLiaisonUser> queryWrapper = new QueryWrapper<>();
				 queryWrapper.eq("emergency_command_liaison_id", emergencyCommandLiaisonId).eq("user_id",sysUserId);
				 EmergencyCommandLiaisonUser one = emergencyCommandLiaisonUserService.getOne(queryWrapper);
				 if(one==null){
					 emergencyCommandLiaisonUserService.save(user);
				 }

			 }
			 result.setMessage("添加成功!");
			 result.setSuccess(true);
			 return result;
		 }catch(Exception e) {
			 log.error(e.getMessage(), e);
			 result.setSuccess(false);
			 result.setMessage("出错了: " + e.getMessage());
			 return result;
		 }
	 }

	 @AutoLog(value = "应急联络图关联人员-指定删除关联用户")
	 @ApiOperation(value="应急联络图关联人员-指定删除关联用户", notes="应急联络图关联人员-指定删除关联用户")
	 @DeleteMapping(value = "/deleteUser")
	 public Result<EmergencyCommandLiaisonUser> deleteUser(@RequestParam(name="emergencyId") String emergencyId,
														  @RequestParam(name="userId",required=true) String userId
	 ) {
		 Result<EmergencyCommandLiaisonUser> result = new Result<>();
		 try {
			 QueryWrapper<EmergencyCommandLiaisonUser> queryWrapper = new QueryWrapper<>();
			 queryWrapper.eq("emergency_command_liaison_id", emergencyId).eq("user_id",userId);
			 emergencyCommandLiaisonUserService.remove(queryWrapper);
			 result.success("删除成功!");
		 }catch(Exception e) {
			 log.error(e.getMessage(), e);
			 result.error500("删除失败!");
		 }
		 return result;
	 }

	 @AutoLog(value = "应急联络图关联人员-指定批量删除关联用户")
	 @ApiOperation(value="应急联络图关联人员-指定批量删除关联用户", notes="应急联络图关联人员-指定批量删除关联用户")
	 @DeleteMapping(value = "/batchDeleteUser")
	 public Result<EmergencyCommandLiaisonUser> batchDeleteUser(@RequestParam(name="emergencyId") String emergencyId,
															   @RequestParam(name="userIds",required=true) String userIds) {
		 Result<EmergencyCommandLiaisonUser> result = new Result<>();
		 try {
			 QueryWrapper<EmergencyCommandLiaisonUser> queryWrapper = new QueryWrapper<>();
			 queryWrapper.eq("emergency_command_liaison_id", emergencyId).in("user_id",Arrays.asList(userIds.split(",")));
			 emergencyCommandLiaisonUserService.remove(queryWrapper);
			 result.success("删除成功!");
		 }catch(Exception e) {
			 log.error(e.getMessage(), e);
			 result.error500("删除失败!");
		 }
		 return result;
	 }



	 @AutoLog(value = "应急联络图关联人员-指定添加关联用户")
	 @ApiOperation(value="应急联络图关联人员-指定添加关联用户", notes="应急联络图关联人员-指定添加关联用户")
	 @PostMapping(value = "/addUserNew")
	 public Result<String> addUserNew(@RequestBody EmergencyCommandLiaisonUserVO emergencyCommandLiaisonUserVO) {
		 Result<String> result = new Result<>();
		 try {
			 EmergencyCommandLiaison emergencyCommandLiaison = emergencyCommandLiaisonUserVO.getEmergencyCommandLiaison();
			 String parentId = emergencyCommandLiaison.getParentId();
			 if (StringUtils.isBlank(parentId)){
				 emergencyCommandLiaison.setParentId("");
			 }
			 emergencyCommandLiaisonService.save(emergencyCommandLiaison);
			// String emergencyCommandLiaisonId = emergencyCommandLiaisonUserVO.getEmergencyCommandLiaisonId();
			 String emergencyCommandLiaisonId = emergencyCommandLiaison.getId();
			 for(String sysUserId: emergencyCommandLiaisonUserVO.getUserIdList()) {
				 EmergencyCommandLiaisonUser user = new EmergencyCommandLiaisonUser(emergencyCommandLiaisonId,sysUserId);
				 QueryWrapper<EmergencyCommandLiaisonUser> queryWrapper = new QueryWrapper<>();
				 queryWrapper.eq("emergency_command_liaison_id", emergencyCommandLiaisonId).eq("user_id",sysUserId);
				 EmergencyCommandLiaisonUser one = emergencyCommandLiaisonUserService.getOne(queryWrapper);
				 if(one==null){
					 emergencyCommandLiaisonUserService.save(user);
				 }

			 }
			 result.setMessage("添加成功!");
			 result.setSuccess(true);
			 return result;
		 }catch(Exception e) {
			 log.error(e.getMessage(), e);
			 result.setSuccess(false);
			 result.setMessage("出错了: " + e.getMessage());
			 return result;
		 }
	 }

	 @AutoLog(value = "应急联络图关联人员-指定查询关联用户")
	 @ApiOperation(value="应急联络图关联人员-指定查询关联用户", notes="应急联络图关联人员-指定查询关联用户")
	 @GetMapping(value = "/queryUserListNew")
	 public Result<IPage<SysUser >> queryUserListNew(@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
												 @RequestParam(name="pageSize", defaultValue="10") Integer pageSize, HttpServletRequest req) {
		 Result<IPage<SysUser >> result = new Result<>();
		 Page<SysUser > page = new Page<>(pageNo, pageSize);
		 //String emergencyId = req.getParameter("parentId");
		 String username = req.getParameter("username");
		 IPage<SysUser > pageList = emergencyCommandLiaisonUserService.userList(page,username);
		 result.setSuccess(true);
		 result.setResult(pageList);
		 return result;
	 }
}