Newer
Older
huludao / src / main / java / com / newfiber / api / pc / controller / River / PatrolManageDicController.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.PatrolManageDic;
import com.newfiber.api.pc.service.PatrolManageDicService;
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 java.util.List;
import java.util.Map;


/**
 *  patrolManageDic控制层
 *
 * @author luzhan
 * @since 2021-07-16
 */
@RestController
@RequestMapping("/patrolManageDic")
@Api(value = "API - PatrolManageDicController", description = "河道管网巡查问题字典")
public class PatrolManageDicController {

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

    @Autowired
    public PatrolManageDicService patrolManageDicService;

    /**
     * 获取patrolManageDic信息(分页)
     * @param params
     * @return
     */
    @PostMapping("list")
    @ApiOperation(value = "获取patrol_manage_dic列表",notes="")
    @SysLog(value="获取patrolManageDic信息(分页)",actionType="4")
    public RespBodyObj<PageInfo<PatrolManageDic>> list(@RequestBody ReqBodyObj<Map<String, Object>> params) {
        Integer pageNo = params.getCurrent();
        Integer pageSize = params.getSize();
        String searchStr = String.valueOf(params.getData().get("name"));
        String patrolType = StringUtils.isEmpty(params.getData().get("patrolType").toString())?null:String.valueOf(params.getData().get("patrolType"));
        //String source = StringUtils.isEmpty(params.getData().get("source").toString())?null:String.valueOf(params.getData().get("source"));
        String source = "problem";
        PageInfo<PatrolManageDic> patrolManageDic =patrolManageDicService.listForPage(searchStr,patrolType,source, pageNo, pageSize);
        return RespBodyObj.ok(patrolManageDic);
    }

    @PostMapping("getDic")
    @ApiOperation(value = "获取patrol_manage_dic列表",notes="")
    @SysLog(value="获取patrolManageDic信息(分页)",actionType="4")
    public RespBodyObj<PageInfo<PatrolManageDic>> getDic(@RequestBody ReqBodyObj<Map<String, Object>> params) {
        Integer pageNo = params.getCurrent();
        Integer pageSize = params.getSize();
        String searchStr = null;
        String patrolType = StringUtils.isEmpty(params.getData().get("patrolType").toString())?null:String.valueOf(params.getData().get("patrolType"));
        String source = StringUtils.isEmpty(params.getData().get("source").toString())?null:String.valueOf(params.getData().get("source"));
        //String source = "problem";
        PageInfo<PatrolManageDic> patrolManageDic =patrolManageDicService.listForPage(searchStr,patrolType,source, pageNo, pageSize);
        return RespBodyObj.ok(patrolManageDic);
    }

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

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

   /**
   * patrolManageDic查询单个
   *
   * @param params
   * @return
   */
    @PostMapping("selectOne")
    @ApiOperation(value = "查询patrol_manage_dic",notes="根据主键查询patrol_manage_dic")
    @SysLog(value="查询patrol_manage_dic",actionType="4")
    public RespBodyObj<PatrolManageDic> 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();
        PatrolManageDic patrolManageDic = patrolManageDicService.selectById(id);
        return RespBodyObj.ok(patrolManageDic);
    }

}