package com.cool.bang.modules.api.controller;

import com.cool.bang.common.base.BaseController;
import com.cool.bang.common.constant.ControllerConstant;
import com.cool.bang.common.web.request.PageDomain;
import com.cool.bang.common.web.response.RestTree;
import com.cool.bang.common.web.response.Result;
import com.cool.bang.common.web.response.module.ResultTable;
import com.cool.bang.modules.business.domain.LpbCommunity;
import com.cool.bang.modules.business.domain.LpbHouse;
import com.cool.bang.modules.business.service.IJobCustomerService;
import com.cool.bang.modules.business.service.ILpbCommunityService;
import com.cool.bang.modules.business.service.ILpbHouseService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 小区门店信息
 *
 * @author Sy
 * @version 1.0.0
 * 2024-10-22 09:08
 */
@RestController
@RequestMapping(ControllerConstant.WX + "community/v1")
public class CommunityController extends BaseController {

    @Autowired
    private ILpbCommunityService lpbCommunityService;

    /**
     * 首页查询所有小区门店
     */
    @GetMapping
    public ResultTable main(PageDomain pageDomain, LpbCommunity param) {
        param.setDelFlag(1);
        PageInfo<LpbCommunity> lpbCommunityPage = lpbCommunityService.page(pageDomain, param);
        return pageTable(lpbCommunityPage.getList(), lpbCommunityPage.getTotal());
    }

    /**
     * 查询所有小区门店
     */
    @GetMapping("select")
    public Result select(LpbCommunity param) {
        param.setDelFlag(1);
        List<LpbCommunity> lpbCommunity = lpbCommunityService.list(param);
        return success(lpbCommunity);
    }

    @GetMapping("{id}")
    public Result get(@PathVariable Long id) {
        return success(lpbCommunityService.queryById(id));
    }

    @PostMapping
    public Result add(@RequestBody LpbCommunity lpbCommunity) {
        lpbCommunity.insertConfigure();
        return decide(lpbCommunityService.save(lpbCommunity));
    }

    @PostMapping("edit")
    public Result edit(@RequestBody LpbCommunity lpbCommunity) {
        return decide(lpbCommunityService.update(lpbCommunity));
    }

}
