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


import com.github.pagehelper.PageInfo;
import com.newfiber.api.core.annotation.SysLog;
import com.newfiber.api.core.bean.ReqBodyObj;
import com.newfiber.api.core.bean.RespBodyObj;
import com.newfiber.api.core.support.HttpCode;
import com.newfiber.api.core.utils.Constant;
import com.newfiber.api.pc.model.River.PatrolManageUserRelation;
import com.newfiber.api.pc.service.PatrolManageUserRelationService;
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;


/**
 *  patrolManageUserRelation控制层
 *
 * @author luzhan
 * @since 2021-07-15
 */
@RestController
@RequestMapping("/patrolManageUserRelation")
@Api(value = "API - PatrolManageUserRelationController", description = "河道管网巡查人员关联列表")
public class PatrolManageUserRelationController {

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

    @Autowired
    public PatrolManageUserRelationService patrolManageUserRelationService;

    /**
     * 获取patrolManageUserRelation信息(分页)
     * @param params
     * @return
     */
    @PostMapping("list")
    @ApiOperation(value = "获取patrol_manage_user_relation列表",notes="")
    @SysLog(value="查询河道管网巡查人员关联列表",actionType="4")
    public RespBodyObj<PageInfo<PatrolManageUserRelation>> list(@RequestBody ReqBodyObj<Map<String, Object>> params) {
        Integer pageNo = params.getCurrent();
        Integer pageSize = params.getSize();
        String searchStr = String.valueOf(params.getData().get("searchStr" ));
        PageInfo<PatrolManageUserRelation> patrolManageUserRelation =patrolManageUserRelationService.listForPage(searchStr, pageNo, pageSize);
        return RespBodyObj.ok(patrolManageUserRelation);
    }

    /**
     * patrolManageUserRelation添加或编辑
     * @param param
     * @return
     */
    @PostMapping("saveOrupdate")
    @ApiOperation(value = "新增或编辑patrol_manage_user_relation",notes="根据实体修改patrol_manage_user_relation")
    @SysLog(value="添加或编辑河道管网巡查人员关联列表",actionType="1")
    public RespBodyObj saveOrupdate(@RequestBody ReqBodyObj<PatrolManageUserRelation> param, HttpServletRequest request) {
        try {
            PatrolManageUserRelation data = param.getData();
            data.setUpdateUserNo(request.getHeader("userNo"));
            data.setBindNo(data.getId());
            data.setPatrolType(data.getPatrolType());
            boolean b = patrolManageUserRelationService.insertOrUpdate(param.getData());
            return b ? RespBodyObj.ok(Constant.SUCCESS) : RespBodyObj.error(Constant.FAILED);
        } catch (Exception e) {
            log.error("/patrolManageUserRelation/saveOrupdate", e);
            return RespBodyObj.error(Constant.ERROR);
        }
    }

    /**
     * patrolManageUserRelation批量移除
     *
     * @param params
     * @return
     */
    @PostMapping("removeBatch")
    @ApiOperation(value = "批量删除辑patrol_manage_user_relation",notes="根据id批量删除patrol_manage_user_relation")
    @SysLog(value="删除河道管网巡查人员关联列表",actionType="2")
    public RespBodyObj removeBatch(@RequestBody ReqBodyObj<Map<String, Object>> params) {
        try {
            List<String> list = (List<String>) params.getData().get("patrolManageUserRelationList");
            boolean b = patrolManageUserRelationService.deleteBatchIds(list);
            return b ? RespBodyObj.ok(Constant.SUCCESS) : RespBodyObj.error(Constant.FAILED);
        } catch (Exception e) {
            log.error("/patrolManageUserRelation/removeBatch", e);
            return RespBodyObj.error(Constant.ERROR);
        }
    }

   /**
   * patrolManageUserRelation查询单个
   *
   * @param params
   * @return
   */
    @PostMapping("selectOne")
    @ApiOperation(value = "查询patrol_manage_user_relation",notes="根据主键查询patrol_manage_user_relation")
    @SysLog(value="查询河道管网巡查人员关联",actionType="4")
    public RespBodyObj<PatrolManageUserRelation> selectOne(@RequestBody ReqBodyObj<Map<String, Object>> params) {
        if (params.getData() == null) {
            return RespBodyObj.error(HttpCode.BAD_REQUEST);
        }
        if (StringUtils.isEmpty(params.getData().get("bindNo" ).toString())) {
            return RespBodyObj.error(HttpCode.BAD_REQUEST);
        }
        Long bindNo = Long.valueOf(params.getData().get("bindNo" ).toString());
        Integer patrolType = Integer.valueOf(params.getData().get("patrolType" ).toString());
        PatrolManageUserRelation patrolManageUserRelation = patrolManageUserRelationService.selectByBindNo(bindNo,patrolType);
        return RespBodyObj.ok(patrolManageUserRelation);
    }

}