package cn.com.countrygarden.bi.main.controller.manager.follow;
import cn.com.countrygarden.bi.main.controller.BaseController;
import cn.com.countrygarden.bi.main.core.Result;
import cn.com.countrygarden.bi.main.dto.HouseKeeperParamVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import cn.com.countrygarden.bi.main.model.manager.map.ManagerHousekeeperFollow;
import cn.com.countrygarden.bi.main.dao.manager.map.ManagerHousekeeperFollowMapper;
import cn.com.countrygarden.bi.main.service.manager.map.ManagerHousekeeperFollowService;

/**
 * 管家用户关注-业务逻辑层实现
 *
 * @author ÀîÉ­ÁÖ
 * @email www.justintoforest@gamail.com
 * @url www.yuhi.com.cn
 * @date 2018-06-29
 */
@RestController("ManagerHousekeeperFollowController")
@RequestMapping("/api/manager/houseKeeper/follow")
public class ManagerHousekeeperFollowController extends BaseController{
    @Autowired
    private ManagerHousekeeperFollowService managerHousekeeperFollowService;


    @GetMapping(value = "/list", produces = "application/json;charset=utf-8")
    public Result list(HouseKeeperParamVo houseKeeperParamVo,
                       @RequestParam(value = "size", required = false, defaultValue = "10") int size,
                       @RequestParam(value = "page", required = false, defaultValue = "1") int page,
                       HttpServletRequest request){
        return  managerHousekeeperFollowService.queryPageList(houseKeeperParamVo,page,size,getAccessToken());
    }

    @GetMapping(value = "/one", produces = "application/json;charset=utf-8")
    public Result queryById(@RequestParam(value = "id", required = true)Integer id,
                            HttpServletRequest request){
        return  managerHousekeeperFollowService.queryById(id);
    }


    /**
     * 添加关注
     * @param size
     * @param request
     * @return
     */
    @PostMapping(value = "/addFollow")
    public Result addFollow(@RequestParam(value = "bid", required = true) Integer bid,
				    		@RequestParam(value = "hjid", required = true) String hjid,
                      @RequestParam(value = "organName", required = true) String organName,
                      @RequestParam(value = "post",required = true)String post,
                      HttpServletRequest request){
        return  managerHousekeeperFollowService.addFollow(bid,hjid,organName,post,getAccessToken());
    }


    /**
     * 取消关注
     * @param size
     * @param request
     * @return
     */
    @PostMapping(value = "/deleteFollow")
    public Result deleteFollow(@RequestParam(value = "bid", required = false) Integer bid,
    						@RequestParam(value = "hjid", required = false) Integer hjid,
                            HttpServletRequest request){
        return  managerHousekeeperFollowService.deleteFollow(bid,hjid, getAccessToken());
    }
    @PostMapping(value = "/add")
    public Result add(ManagerHousekeeperFollow managerHousekeeperFollow,
                      HttpServletRequest request){
        return  managerHousekeeperFollowService.add(managerHousekeeperFollow,getAccessToken(request));
    }

    @PutMapping(value = "/edit")
    public Result edit(ManagerHousekeeperFollow managerHousekeeperFollow, HttpServletRequest request){
        return  managerHousekeeperFollowService.edit(managerHousekeeperFollow,getAccessToken(request));
    }

    @DeleteMapping(value="/del")
    public Result del(@RequestParam(value = "id", required = true)Integer id){
        return  managerHousekeeperFollowService.del(id);
    }

    @GetMapping(value="/name/tree",produces="application/json;charset=utf-8")
	public Result nameTree(){
		return managerHousekeeperFollowService.getHouseKeeperFollowNameTree(getAccessToken());
	}
	
	@GetMapping(value="/garden/tree",produces="application/json;charset=utf-8")
	public Result gardenDistrictTree(){
		return managerHousekeeperFollowService.getGardenDistrictTree(getAccessToken());
	}
	



}