package com.zcxk.rmcp.web.controller;

import com.zcxk.core.common.pojo.AjaxMessage;
import com.zcxk.rmcp.api.dto.product.ProductVo;
import com.zcxk.rmcp.api.vo.AreaVo;
import com.zcxk.rmcp.api.vo.OrgTreeVo;
import com.zcxk.rmcp.api.vo.ProductCategoryVo;
import com.zcxk.rmcp.core.dao.AreaMapper;
import com.zcxk.rmcp.core.entity.Org;
import com.zcxk.rmcp.web.service.OrgService;
import com.zcxk.rmcp.web.service.ProductService;
import com.zcxk.rmcp.web.util.TreeUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author linqingwei
 * @date 2021-07-22 11:03
 */
@Controller
@ResponseBody
@RequestMapping("common")
@Api(tags = "公共模块")
public class CommonController {

    @Autowired
    private OrgService orgService;
    @Autowired
    private AreaMapper areaMapper;
    @Autowired
    private ProductService productService;


    @GetMapping("/getAllArea")
    @ApiOperation(value = "获取所有的省市区")
    public AjaxMessage<List<AreaVo>> getAllArea(
    ) {
        List<AreaVo> list = areaMapper.getList();
        return AjaxMessage.success(TreeUtil.getAreaTree(list, 100000, 1));
    }

    @GetMapping("getOrgUserTree")
    @ApiOperation(value = "获取机构树")
    public AjaxMessage<List<OrgTreeVo>> getOrgUserTree(
        @ApiParam(value = "机构类型", required = true) @RequestParam String orgType,
        @RequestParam  Integer id
    ) {
        Org org=new Org();
        org.setOrgType(orgType);
        org.setId(id);

        return AjaxMessage.success(orgService.getUserTrees(org));
    }


    @GetMapping("getProductList")
    @ApiOperation(value = "获取产品列表")
    public AjaxMessage<List<ProductVo>> getProductList(
            @ApiParam(value = "分类id", required = false) @RequestParam(required = false) Integer categoryId
    ) {
        List<ProductVo> list = productService.getProductList(categoryId);
        return AjaxMessage.success(list);
    }
    @GetMapping("getCategoryList")
    @ApiOperation(value = "获取产品分类列表")
    public AjaxMessage<List<ProductCategoryVo>> getCategoryList() {
        List<ProductCategoryVo> list = productService.getCategoryList();
        return AjaxMessage.success(list);
    }

}
