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

import com.alibaba.excel.EasyExcel;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
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.listener.BlackRiverListener;
import com.newfiber.api.pc.model.River.*;
import com.newfiber.api.pc.service.BlackRiverImageService;
import com.newfiber.api.pc.service.BlackRiverService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * @ClassName BlackRiverController
 * @Description TODO
 * @Author 张鸿志
 * @Date 2021年3月28日14:20:33 14:20
 * Version 1.0
 **/
@RestController
@RequestMapping("/blackRiver")
@Api(value = "BlackRiverController",tags = "黑臭水体基本信息维护控制层")
public class BlackRiverController {

    @Autowired
    private BlackRiverService blackRiverService;

    @Autowired
    private BlackRiverImageService blackRiverImageService;


    @PostMapping("/queryPage")
    @SysLog(value="查询黑臭水体",actionType="4")
    public RespBodyObj queryPage(@RequestBody ReqBodyObj<Map<String, Object>> params){
        Integer pageSize = params.getSize();
        Integer pageNo = (params.getCurrent() - 1) * pageSize;
        Object riverName = params.getData().get("blackRiverName");
        Object blackType = params.getData().get("blackType");
        List<BlackRiver> selectPage = blackRiverService.queryPage(riverName,blackType,pageNo,pageSize);
        int count = blackRiverService.queryCount(riverName,blackType);
        Page<BlackRiver> page = new Page<>(params.getSize(),params.getCurrent());
        page.setRecords(selectPage);
        page.setTotal(count);
        return RespBodyObj.ok(page);
    }

    @PostMapping("/update")
    @ApiOperation("修改黑臭水体数据")
    @SysLog(value="修改黑臭水体数据",actionType="3")
    public RespBodyObj updateBlackRiver(@RequestBody BlackRiver blackRiver){
        blackRiverService.updateBlackRiver(blackRiver);
        return RespBodyObj.ok();
    }

    @PostMapping("/selectAll")
    @ApiOperation("查询所有的黑臭水体数据")
    @SysLog(value="查询所有的黑臭水体数据",actionType="4")
    public RespBodyObj selecAll(){
        List<BlackRiver> blackRivers = blackRiverService.selectAll();
        return RespBodyObj.ok(blackRivers);
    }

    @PostMapping("/selecById")
    @ApiOperation("查询单条黑臭水体数据")
    @SysLog(value="查询单条黑臭水体数据",actionType="4")
    public RespBodyObj selecById(@RequestBody ReqBodyObj<Map<String, Object>> params){
        String blackId = params.getData().get("blackId").toString();
        BlackRiver blackRivers = blackRiverService.selecById(blackId);
        return RespBodyObj.ok(blackRivers);
    }

    @PostMapping("/delete")
    @ApiOperation("删除黑臭水体")
    @SysLog(value="删除黑臭水体",actionType="2")
    public RespBodyObj deleteBlackRiver(@RequestParam("blackId")String blackId){
        if(StringUtils.isEmpty(blackId)){
            return RespBodyObj.error("参数不能为空!");
        }
        BlackRiver blackRiver = blackRiverService.selectById(blackId);
        if(StringUtils.isEmpty(blackId)){
            return RespBodyObj.error("没有该黑臭水体相关的信息");
        }
        blackRiverService.deleteById(blackId);
        EntityWrapper<BlackRiverImageUrl> wrapper = new EntityWrapper<>();
        wrapper.eq("black_inner_id",blackId);
        blackRiverImageService.delete(wrapper);
        return RespBodyObj.ok();
    }

    @PostMapping("/add")
    @ApiOperation("新增黑臭水体")
    @SysLog(value="新增黑臭水体",actionType="1")
    public RespBodyObj addBlackRiver(@RequestBody BlackRiver blackRiver){
        blackRiverService.addBlackRiver(blackRiver);
        return RespBodyObj.ok();
    }

    @PostMapping("/upload")
    @ApiOperation("批量上传黑臭水体数据")
    @SysLog(value="批量上传黑臭水体数据",actionType="1")
    public void batchBlackRiver(@RequestParam("file") MultipartFile file){

        try {
            EasyExcel.read(file.getInputStream(), BlackRiver.class,new BlackRiverListener(blackRiverService)).sheet(0).doRead();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @PostMapping("/selectList")
    @ApiOperation("查询黑臭水体")
    @SysLog(value="查询黑臭水体",actionType="4")
    public RespBodyObj selectList(){
        //List<RiverInfoData> result = blackRiverService.selectListData();
        List<RiverInfoData> result = blackRiverService.selectNewListData();
        return RespBodyObj.ok(result);
    }


    @PostMapping("/oneMapSelectAll")
    @ApiOperation("新版一张图中查询黑臭水体统计信息 以及所有黑臭水体的数据")
    public RespBodyObj<OneMapBlackRiver> oneMapSelectAll(){
        OneMapBlackRiver oneMapBlackRiver = blackRiverService.oneMapSelectAll();
        return RespBodyObj.ok(oneMapBlackRiver);
    }


    @PostMapping("/oneMapBlackRiverInfo")
    @ApiOperation("一张图黑臭水体基础信息")
    public RespBodyObj<OneMapGisResult> oneMapBlackRiverInfo(@RequestParam("type")String type){
        if(StringUtils.isEmpty(type)){
            return RespBodyObj.error("参数不能为空");
        }
        return RespBodyObj.ok(blackRiverService.oneMapBlackRiverInfo(type));
    }
}