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

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.newfiber.api.core.annotation.SysLog;
import com.newfiber.api.core.commons.*;
import com.newfiber.api.pc.dto.AreaInsertDTO;
import com.newfiber.api.pc.dto.SiteDTO;
import com.newfiber.api.pc.model.entity.ProSiteInfoEntity;
import com.newfiber.api.pc.model.meet.MeetAreaSite;
import com.newfiber.api.pc.model.vo.MeetAreaSiteVo;
import com.newfiber.api.pc.service.MeetAreaSiteService;
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 java.util.ArrayList;
import java.util.List;

/**
 * @description: 区域站点管理
 * @author: 张鸿志
 * @date: 2020/12/16 14:54
 * @version: v1.0
 */
@RestController
@RequestMapping("/areaSite")
@Api(value = "MeetAreaSiteController",tags = "区域站点管理")
public class MeetAreaSiteController {

    @Autowired
    private MeetAreaSiteService meetAreaSiteService;

    @PostMapping("/queryPage")
    @ApiOperation("分页查询已分配的站点数据")
    @SysLog(actionType = "4",value = "分页查询已分配的站点数据")
    public ResultObj<PageResultObject<ProSiteInfoEntity>> queryPage(@RequestBody PageRequestObject<SiteDTO> pageRequestObject){
        return new ResultObj<PageResultObject<ProSiteInfoEntity>>(ResultCode.OK,meetAreaSiteService.queryPage(pageRequestObject));
    }


    @PostMapping("/delete")
    @ApiOperation("删除某个区域下的站点数据")
    @SysLog(actionType = "2",value = "删除某个区域下的站点数据")
    public ResultObj deleteAreaSite(@RequestBody  AreaInsertDTO areaInsertDTO){
        if(StringUtils.isEmpty(areaInsertDTO.getAreaId())){
            throw new CustomException(ResultCode.PARAM_NULL);
        }
        EntityWrapper<MeetAreaSite> wrapper = new EntityWrapper<>();
        wrapper.eq("area_id",areaInsertDTO.getAreaId());
        wrapper.in("site_id",areaInsertDTO.getSiteNo());
        boolean delete = meetAreaSiteService.delete(wrapper);
        if(delete){
            return ResultObj.ok();
        }
        return ResultObj.error();
    }

    @PostMapping("/add")
    @ApiOperation("新增区域下的站点信息")
    @SysLog(actionType = "1",value = "新增区域下的站点信息")
    public ResultObj addAreaSite(@RequestBody  AreaInsertDTO areaInsertDTO){
        if(StringUtils.isEmpty(areaInsertDTO.getAreaId())){
            throw new CustomException(ResultCode.PARAM_NULL);
        }
        List<MeetAreaSite> list = new ArrayList<>();
        for(Integer siteNo : areaInsertDTO.getSiteNo()){
            MeetAreaSite meetAreaSite = new MeetAreaSite();
            meetAreaSite.setSiteId(siteNo);
            meetAreaSite.setAreaId(Integer.parseInt(areaInsertDTO.getAreaId()));
            list.add(meetAreaSite);
        }
        boolean batch = meetAreaSiteService.insertBatch(list);
        if(batch){
            return ResultObj.ok();
        }
        return ResultObj.error();
    }

    @PostMapping("/queryAreaSite")
    public ResultObj<List<MeetAreaSiteVo>> queryAreaSite(@RequestParam("areaId")String areaId){
        return new ResultObj<>(ResultCode.OK,meetAreaSiteService.queryAreaSite(areaId));
    }
}