package com.xhpc.user.controller;

import com.xhpc.common.core.domain.R;
import com.xhpc.common.core.web.controller.BaseController;
import com.xhpc.common.core.web.domain.AjaxResult;
import com.xhpc.common.core.web.page.TableDataInfo;
import com.xhpc.common.log.annotation.Log;
import com.xhpc.common.log.enums.BusinessType;
import com.xhpc.common.util.UserTypeUtil;
import com.xhpc.user.domain.XhpcCommunity;
import com.xhpc.user.domain.XhpcCommunityPersonnel;
import com.xhpc.user.service.IXhpcCommunityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * @author yuyang
 * @date 2021/12/20 10:12
 */
@RestController
@RequestMapping("/community")
public class XhpcCommunityController extends BaseController {

    @Autowired
    private IXhpcCommunityService xhpcCommunityService;


    /**
     * 社区组树列表
     */
    @GetMapping("/userList")
    public R userList(HttpServletRequest request, String name) {
        return R.ok(xhpcCommunityService.userList(request,name));
    }


    /**
     * 社区组树列表
     */
    @GetMapping("/list")
    public TableDataInfo list(HttpServletRequest request, String name) {
        List<Map<String, Object>> list = xhpcCommunityService.list(request,name);
        return getDataTable(list);
    }

    /**
     * 新增社区组树
     *
     * @return
     */
    @Log(title = "社区", businessType = BusinessType.INSERT)
    @PostMapping(value = "/addCommunity")
    public AjaxResult addCommunity(HttpServletRequest request,@RequestBody XhpcCommunity xhpcCommunity) {
        return xhpcCommunityService.addCommunity(request,xhpcCommunity);
    }

    /**
     * 删除社区组树
     */
    @Log(title = "社区", businessType = BusinessType.DELETE)
    @PostMapping(value = "/deleteCommunity")
    public AjaxResult deleteCommunity(@RequestBody XhpcCommunity xhpcCommunity) {
        return xhpcCommunityService.deleteCommunity(xhpcCommunity);
    }

    /**
     * 查询社区组
     */
    @PostMapping(value = "/getCommunityById")
    public AjaxResult getCommunityById(@RequestBody XhpcCommunity xhpcCommunity) {
        return AjaxResult.success(xhpcCommunityService.getCommunityById(xhpcCommunity));
    }

    /**
     * 编辑社区组树
     *
     * @return
     */
    @Log(title = "社区", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/updateCommunity")
    public AjaxResult updateCommunity(@RequestBody XhpcCommunity xhpcCommunity) {
        return xhpcCommunityService.updateCommunity(xhpcCommunity);
    }




    /**
     * 社区人员列表
     */
    @GetMapping("/communityPersonnelList")
    public TableDataInfo communityPersonnelList(Long communityId,String account,String phone,Integer status) {
        startPage();
        List<Map<String, Object>> list = xhpcCommunityService.communityPersonnelList(communityId, account, phone, status);
        return getDataTable(list);
    }

    /**
     * 社区人员添加
     *
     */
    @Log(title = "社区人员", businessType = BusinessType.INSERT)
    @PostMapping(value = "/addCommunityPersonnel")
    public AjaxResult addCommunityPersonnel(HttpServletRequest request,@RequestBody XhpcCommunityPersonnel xhpcCommunityPersonnel) {
        return xhpcCommunityService.addCommunityPersonnel(request,xhpcCommunityPersonnel);
    }

    /**
     * 查看社区人员
     *
     */
    @PostMapping(value = "/getCommunityPersonnelById")
    public AjaxResult getCommunityPersonnelById(@RequestBody XhpcCommunityPersonnel xhpcCommunityPersonnel) {
        return AjaxResult.success(xhpcCommunityService.getCommunityPersonnelById(xhpcCommunityPersonnel));
    }

    /**
     * 编辑社区人员
     *
     */
    @Log(title = "社区人员", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/updateCommunityPersonnel")
    public AjaxResult updateCommunityPersonnel(@RequestBody XhpcCommunityPersonnel xhpcCommunityPersonnel) {
        return xhpcCommunityService.updateCommunityPersonnel(xhpcCommunityPersonnel);
    }

    /**
     * 删除社区人员
     */
    @Log(title = "社区人员", businessType = BusinessType.DELETE)
    @PostMapping(value = "/deleteCommunityPersonnel")
    public AjaxResult deleteCommunityPersonnel(@RequestBody XhpcCommunityPersonnel xhpcCommunityPersonnel) {
        xhpcCommunityService.deleteCommunityPersonnel(xhpcCommunityPersonnel);
        return AjaxResult.success();
    }

    /**
     * 改变社区人员状态
     */
    @Log(title = "社区人员-状态", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/updateCommunityPersonnelStatus")
    public AjaxResult updateCommunityPersonnelStatus(@RequestBody XhpcCommunityPersonnel xhpcCommunityPersonnel) {
        xhpcCommunityService.updateCommunityPersonnelStatus(xhpcCommunityPersonnel);
        return AjaxResult.success();
    }

    /**
     * 充值
     */
    @Log(title = "社区人员-充值", businessType = BusinessType.INSERT)
    @PostMapping(value = "/addRecharge")
    public AjaxResult addRecharge(@RequestBody XhpcCommunityPersonnel xhpcCommunityPersonnel) {
        xhpcCommunityPersonnel.setRechargeType(UserTypeUtil.RECHARGE_PT);
        return xhpcCommunityService.addRecharge(xhpcCommunityPersonnel);
    }

}
