Newer
Older
huludao / src / main / java / com / newfiber / api / pc / controller / TaskUserAuthController.java
package com.newfiber.api.pc.controller;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.github.pagehelper.PageInfo;
import com.newfiber.api.core.bean.ReqBodyObj;
import com.newfiber.api.core.bean.RespBodyObj;
import com.newfiber.api.core.commons.Constant;
import com.newfiber.api.core.support.HttpCode;
import com.newfiber.api.pc.model.entity.TaskUserAuth;
import com.newfiber.api.pc.service.TaskUserAuthService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;


/**
 *  taskUserAuth控制层
 *
 * @author luzhan
 * @since 2021-11-12
 */
@RestController
@RequestMapping("/taskUserAuth")
@Api(value = "API - TaskUserAuthController", description = "")
public class TaskUserAuthController {

    private static final Logger log = LoggerFactory.getLogger(TaskUserAuthController.class);

    @Autowired
    public TaskUserAuthService taskUserAuthService;

    @PostMapping("getUserAuth")
    @ApiOperation(value = "获取派发任务的用户权限",notes="")
    public RespBodyObj<TaskUserAuth> getUserAuth(HttpServletRequest request) {
        String userNo = request.getHeader("userNo");
        EntityWrapper<TaskUserAuth> wrapper = new EntityWrapper<>();
        wrapper.eq("user_no",userNo);
        TaskUserAuth taskUserAuth =taskUserAuthService.selectOne(wrapper);
        if(taskUserAuth==null){
            taskUserAuth = new TaskUserAuth();
            taskUserAuth.setUserNo("admin");
            taskUserAuth.setUserType(2);
        }
        return RespBodyObj.ok(taskUserAuth);
    }

    /**
     * 获取taskUserAuth信息(分页)
     * @param params
     * @return
     */
    @PostMapping("list")
    @ApiOperation(value = "获取task_user_auth列表",notes="")
    public RespBodyObj<PageInfo<TaskUserAuth>> list(@RequestBody ReqBodyObj<Map<String, Object>> params) {
        Integer pageNo = params.getCurrent();
        Integer pageSize = params.getSize();
        String searchStr = String.valueOf(params.getData().get("searchStr" ));
        PageInfo<TaskUserAuth> taskUserAuth =taskUserAuthService.listForPage(searchStr, pageNo, pageSize);
        return RespBodyObj.ok(taskUserAuth);
    }

    /**
     * taskUserAuth添加或编辑
     * @param param
     * @return
     */
    @PostMapping("saveOrupdate")
    @ApiOperation(value = "新增或编辑task_user_auth",notes="根据实体修改task_user_auth")
    public RespBodyObj saveOrupdate(@RequestBody ReqBodyObj<TaskUserAuth> param) {
        try {
            boolean b = taskUserAuthService.insertOrUpdate(param.getData());
            return b ? RespBodyObj.ok(Constant.SUCCESS) : RespBodyObj.error(Constant.FAILED);
        } catch (Exception e) {
            log.error("/taskUserAuth/saveOrupdate", e);
            return RespBodyObj.error(Constant.ERROR);
        }
    }

    /**
     * taskUserAuth批量移除
     *
     * @param params
     * @return
     */
    @PostMapping("removeBatch")
    @ApiOperation(value = "批量删除辑task_user_auth",notes="根据id批量删除task_user_auth")
    public RespBodyObj removeBatch(@RequestBody ReqBodyObj<Map<String, Object>> params) {
        try {
            List<String> list = (List<String>) params.getData().get("taskUserAuthList");
            boolean b = taskUserAuthService.deleteBatchIds(list);
            return b ? RespBodyObj.ok(Constant.SUCCESS) : RespBodyObj.error(Constant.FAILED);
        } catch (Exception e) {
            log.error("/taskUserAuth/removeBatch", e);
            return RespBodyObj.error(Constant.ERROR);
        }
    }

   /**
   * taskUserAuth查询单个
   *
   * @param params
   * @return
   */
    @PostMapping("selectOne")
    @ApiOperation(value = "查询task_user_auth",notes="根据主键查询task_user_auth")
    public RespBodyObj<TaskUserAuth> selectOne(@RequestBody ReqBodyObj<Map<String, Object>> params) {
        if (params.getData() == null) {
            return RespBodyObj.error(HttpCode.BAD_REQUEST);
        }
        if (StringUtils.isEmpty(params.getData().get("id" ).toString())) {
            return RespBodyObj.error(HttpCode.BAD_REQUEST);
        }
        String id = params.getData().get("id" ).toString();
        TaskUserAuth taskUserAuth = taskUserAuthService.selectById(id);
        return RespBodyObj.ok(taskUserAuth);
    }

}