package com.dgtis.dorm.manager.wx.web;

import com.dgtis.dorm.manager.db.domain.AdministrativeItems;
import com.dgtis.dorm.manager.db.domain.AdministrativeItemsDoc;
import com.dgtis.dorm.manager.db.param.ItemsQueryParam;
import com.dgtis.dorm.manager.db.service.AdministrativeItemsService;
import com.dgtis.dorm.manager.db.util.ResponseUtil;
import com.dgtis.dorm.manager.wx.param.ItemsParam;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.*;

/**
 * 行政办理事项
 *
 * @author huanghaoqi
 * @version 1.0
 * @date 2018年12月03日 14:52:44
 * @since JDK1.8
 */
@RestController
@RequestMapping("/wx/items")
public class AdministrativeItemsController {
    @Resource
    private AdministrativeItemsService administrativeItemsService;

    /**
     * 方法描述  查询办理事项一级目录
     *
     * @return Object
     * @author huanghaoqi
     * @date 2018年12月03日 15:42:29
     */
    @PostMapping("/firstLevelList")
    public Object firstLevelList() {
        ItemsQueryParam param = new ItemsQueryParam();
        param.setLevel(1);
        param.setSort("name");
        param.setOrder("asc");
        // 查询列表
        List<AdministrativeItems> administrativeItemsList = administrativeItemsService.list(param);

        return ResponseUtil.ok(administrativeItemsList);
    }

    /**
     * 方法描述  查询办理事项二级目录
     *
     * @return Object
     * @author huanghaoqi
     * @date 2018年12月03日 15:42:29
     */
    @PostMapping("/secondLevelList")
    public Object secondLevelList(@RequestBody ItemsParam itemsParam) {
        ItemsQueryParam param = new ItemsQueryParam();
        Integer pid = itemsParam.getPid();
        Integer cid = itemsParam.getCid();
        param.setParentId(pid);
        if (cid != null) {
            param.setId(cid);
        }
        param.setSort("name");
        param.setOrder("asc");

        Map<String, Object> map = new HashMap<>();
        AdministrativeItems parent = administrativeItemsService.findById(pid);
        map.put("name", parent.getName());
        // 查询列表
        List<AdministrativeItems> administrativeItemsList = administrativeItemsService.list(param);

        map.put("list", administrativeItemsList);


        return ResponseUtil.ok(map);
    }


    /**
     * 方法描述  查询办理事项办事指南列表
     *
     * @return Object
     * @author huanghaoqi
     * @date 2018年12月03日 15:42:29
     */
    @PostMapping("/guidanceDocList")
    public Object guidanceDocList(@RequestBody ItemsParam itemsParam) {


        Map<String, Object> map = new HashMap<>();
        AdministrativeItems administrativeItems = administrativeItemsService.findById(itemsParam.getItemsId());
        String name = administrativeItems.getParentName() + administrativeItems.getName();
        map.put("name", name);

        List<AdministrativeItemsDoc> list = administrativeItemsService.selectByItemsId(itemsParam.getItemsId(), itemsParam.getDocType());

        map.put("list", list);

        return ResponseUtil.ok(map);
    }
}
