package com.tuoheng.controller;

import com.tuoheng.model.dto.LoginUser;
import com.tuoheng.model.entity.Area;
import com.tuoheng.model.entity.Marker;
import com.tuoheng.model.query.AreaQuery;
import com.tuoheng.model.query.MarkerQuery;
import com.tuoheng.service.CurrentUser;
import com.tuoheng.service.MarkerService;
import com.tuoheng.until.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * (Marker)表控制层
 *
 * @author xiaoying
 * @since 2023-03-07 14:59:16
 */
@RestController
@RequestMapping("/marker")
public class MarkerController {

    /**
     * 服务对象
     */
    @Autowired
    private MarkerService markerService;


    /**
     * 查询营销人员信息
     *
     * @param query
     * @return
     */
    @GetMapping("/index")
    public JsonResult index(MarkerQuery query) {
        return markerService.index(query);
    }

    /**
     * 根据区域id查询出对应营销人员
     * @param query
     * @return
     */
    @GetMapping("/getMarkerList")
    public JsonResult getMarkerList(MarkerQuery query){
        return markerService.getMarkerList(query);
    }



    /**
     * 新增营销人员信息
     *
     * @param entity
     * @return
     */
    @PostMapping("/add")
    public JsonResult add(@RequestBody @Validated Marker entity, @CurrentUser LoginUser loginUser) {
        return markerService.edit(entity, loginUser);
    }

    /**
     * 新增营销人员信息
     *
     * @param entity
     * @return
     */
    @PutMapping("/edit")
    public JsonResult edit(@RequestBody @Validated Marker entity, @CurrentUser LoginUser loginUser) {
        return markerService.edit(entity, loginUser);
    }

    /**
     * 逻辑删除/批量
     * @param ids
     * @return
     */
    @DeleteMapping("/delete/{ids}")
    public JsonResult delete(@PathVariable("ids") Long[] ids) {
        return markerService.deleteByIds(ids);
    }
}
