package com.huijy.web.controller.management;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.huijy.management.domain.Content;
import com.huijy.management.service.IContentService;
import com.huijy.management.service.IMarkerContentService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.huijy.common.annotation.Log;
import com.huijy.common.core.controller.BaseController;
import com.huijy.common.core.domain.AjaxResult;
import com.huijy.common.enums.BusinessType;
import com.huijy.management.domain.Marker;
import com.huijy.management.service.IMarkerService;
import com.huijy.common.utils.poi.ExcelUtil;
import com.huijy.common.core.page.TableDataInfo;

/**
 * 标记物管理Controller
 *
 * @author luobo
 * @date 2021-09-08
 */
@RestController
@RequestMapping("/management/marker")
public class MarkerController extends BaseController
{
    @Autowired
    private IMarkerService markerService;
    @Autowired
    private IContentService contentService;
    @Autowired
    private IMarkerContentService markerContentService;
    /**
     * 查询标记物管理列表
     */
    @PreAuthorize("@ss.hasPermi('management:marker:list')")
    @GetMapping("/list")
    public TableDataInfo list(Marker marker)
    {
        startPage();
        List<Marker> list = markerService.selectMarkerList(marker);
        return getDataTable(list);
    }

    /**
     * 导出标记物管理列表
     */
    @PreAuthorize("@ss.hasPermi('management:marker:export')")
    @Log(title = "标记物管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Marker marker)
    {
        List<Marker> list = markerService.selectMarkerList(marker);
        ExcelUtil<Marker> util = new ExcelUtil<Marker>(Marker.class);
        return util.exportExcel(list, "标记物管理数据");
    }

    /**
     * 获取标记物管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('management:marker:query')")
    @GetMapping(value = "/{markerId}")
    public AjaxResult getInfo(@PathVariable("markerId") Long markerId)
    {
        Marker info=  markerService.selectMarkerByMarkerId(markerId);
        Content content = new Content();
        //1、党政 2、景区
        content.setServiceInfo("2");
        List<Content> contentList = contentService.selectContentList(content);
        //获取中间表数据
        List<Long> contentIdsList =markerContentService.getContentIdListByMarkerId(markerId);
        Map<String, Object> resultObj = new HashMap<String, Object>();
        resultObj.put("info", info);
        resultObj.put("contentList", contentList);
        resultObj.put("contentIdsList", contentIdsList);

        return AjaxResult.success(resultObj);
    }

    /**
     * 新增标记物管理
     */
    @PreAuthorize("@ss.hasPermi('management:marker:add')")
    @Log(title = "标记物管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Marker marker)
    {
        return toAjax(markerService.insertMarker(marker));
    }

    /**
     * 修改标记物管理
     */
    @PreAuthorize("@ss.hasPermi('management:marker:edit')")
    @Log(title = "标记物管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Marker marker)
    {
        return toAjax(markerService.updateMarker(marker));
    }

    /**
     * 删除标记物管理
     */
    @PreAuthorize("@ss.hasPermi('management:marker:remove')")
    @Log(title = "标记物管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{markerIds}")
    public AjaxResult remove(@PathVariable Long[] markerIds)
    {
        return toAjax(markerService.deleteMarkerByMarkerIds(markerIds));
    }
}
