123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 |
- package com.nokia.controller;
- import com.alibaba.fastjson.JSONObject;
- import com.nokia.common.R;
- import com.nokia.pojo.Role;
- import com.nokia.service.FlowService;
- import com.nokia.vo.flow.FlowRoleCityVo;
- import com.nokia.vo.flow.FlowRoleVo;
- import com.nokia.vo.flow.FlowUserVo;
- import com.nokia.vo.flow.UserTreeReq;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.web.bind.annotation.*;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Map;
- /**
- * 提供给工作流的api
- */
- @Slf4j
- @RestController
- @RequestMapping("rest")
- public class FlowApiController {
- private final FlowService flowService;
- @Autowired
- public FlowApiController(FlowService flowService) {
- this.flowService = flowService;
- }
- /*
- * 页面上的用户树结构
- */
- @PostMapping("flow/api/userTree")
- public R getUserTree(@RequestBody UserTreeReq userTreeReq) {
- List<Map<String, Object>> userTree = flowService.getUserTree(userTreeReq);
- return R.ok().data(userTree);
- }
- /*
- * 根据输入的角色和city信息返回用户手机号列表
- */
- @PostMapping("flow/api/getPhoneListByRole")
- public R getPhoneListByRole(@RequestBody JSONObject req) {
- try {
- int roleId = req.getIntValue("roleId");
- int cityId = req.getIntValue("cityId");
- List<String> phoneList = flowService.getPhoneListByRole(roleId, cityId);
- return R.ok().data(phoneList);
- } catch (NumberFormatException e) {
- e.printStackTrace();
- return R.error().message("roleId和cityId必需为有意义的整数");
- }
- }
- @PostMapping("flow/api")
- @ResponseBody
- public R flowApi(@RequestBody JSONObject jsonObject) {
- String callType = jsonObject.getString("callType");
- if (callType == null) {
- return R.error().message("输入必须包含callType");
- }
- switch (callType) {
- case "findRoleList":
- return findRoleList(jsonObject);
- case "findToPage":
- return findToPage();
- case "getByLoginId":
- return getByLoginId(jsonObject);
- case "get":
- return get(jsonObject);
- case "findRoleIdByUserId":
- return findRoleIdByUserId(jsonObject);
- case "findUserIdByRoleId":
- return findUserIdByRoleId(jsonObject);
- case "findAuthorizedUser":
- return findAuthorizedUser(jsonObject);
- case "getRoleCityByUserId":
- return getRoleCityByUserId(jsonObject);
- default:
- return R.error().message("callType类型错误");
- }
- }
- /**
- *
- * @param jsonObject
- * @return
- */
- private R getRoleCityByUserId(JSONObject jsonObject) {
- Integer userId = jsonObject.getInteger("userId");
- if (null == userId) {
- return R.error().message("输入必须包含userId");
- }
- List<FlowRoleCityVo> flowRoleCityVos = new ArrayList<>();
- for (Role role : flowService.getRoleCityByUserId(userId)) {
- log.debug("查询结果:{}", role);
- if ("flow".equals(role.getSystem())) {
- flowRoleCityVos.add(new FlowRoleCityVo(role));
- }
- }
- return R.ok().data(flowRoleCityVos);
- }
- public R findRoleList(JSONObject jsonObject) {
- String username = jsonObject.getString("userName");
- if (username == null || username.equals("")) {
- return R.ok().data(flowService.findRoleList());
- }
- List<FlowRoleVo> roleList = flowService.findRoleList(username);
- return R.ok().data(roleList);
- }
- public R findToPage() {
- List<FlowUserVo> flowUserVos = flowService.findToPage();
- return R.ok().data(flowUserVos);
- }
- public R getByLoginId(JSONObject jsonObject) {
- String loginId = jsonObject.getString("loginId");
- if (loginId == null || loginId.equals("")) {
- return R.error().message("输入必须包含loginId");
- }
- FlowUserVo flowUserVo = flowService.getByLoginId(loginId);
- return R.ok().data(flowUserVo);
- }
- public R get(JSONObject jsonObject) {
- Integer userId = null;
- try {
- userId = jsonObject.getInteger("userId");
- } catch (NumberFormatException e) {
- return R.error().message("输入的userId必须为整数格式");
- }
- if (userId == null) {
- return R.error().message("输入必须包含userId");
- }
- FlowUserVo flowUserVo = flowService.getByUserId(userId);
- return R.ok().data(flowUserVo);
- }
- public R findRoleIdByUserId(JSONObject jsonObject) {
- Integer userId = null;
- try {
- userId = jsonObject.getInteger("userId");
- } catch (NumberFormatException e) {
- return R.error().message("输入的userId必须为整数格式");
- }
- if (userId == null) {
- return R.error().message("输入必须包含userId");
- }
- List<Integer> roleIdList = flowService.findRoleIdByUserId(userId);
- return R.ok().data(roleIdList);
- }
- public R findUserIdByRoleId(JSONObject jsonObject) {
- Integer roleId = null;
- try {
- roleId = jsonObject.getInteger("roleId");
- } catch (NumberFormatException e) {
- return R.error().message("输入的roleId必须为整数格式");
- }
- if (roleId == null) {
- return R.error().message("输入必须包含roleId");
- }
- List<Integer> userIdList = flowService.findUserIdByRoleId(roleId);
- return R.ok().data(userIdList);
- }
- public R findAuthorizedUser(JSONObject jsonObject) {
- String loginId = jsonObject.getString("loginId");
- loginId = loginId == null || loginId.equals("") ? null : loginId.trim();
- Integer roleId = null;
- try {
- roleId = jsonObject.getInteger("roleId");
- } catch (NumberFormatException ignored) {
- }
- String userName = jsonObject.getString("userName");
- userName = userName == null || userName.equals("") ? null : userName.trim();
- List<FlowUserVo> flowUserVos = flowService.findAuthorizedUser(loginId, roleId, userName);
- return R.ok().data(flowUserVos);
- }
- }
|