package com.mvc.controller;

import com.mvc.model.CorrectMap;
import com.mvc.model.ErrorMap;
import com.mvc.othermodel.GroupAndStationTree;
import com.mvc.service.TUnitStructureService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Api(tags = "单位结构接口类")
@RequestMapping("/TUnitStructureAction")
@Controller
public class TUnitStructureAction {
    @Resource
    private TUnitStructureService unitStructureService;

    @ApiOperation("导入站点结构数据")
    @PostMapping(value = "/importUnitStructureData")
    @ResponseBody
    public Map<String, Object> importDeviceAccData(@RequestParam("file") MultipartFile file, @RequestParam String unitCode,
                                                   @RequestParam String createMan) {
        try {
            String resMsg = unitStructureService.importUnitStructureData(file, unitCode, createMan);
            Map<String, Object> resMap = new CorrectMap();
            resMap.put("res", resMsg);
            return resMap;
        } catch (Exception e) {
            Map<String, Object> resMap = new ErrorMap();
            resMap.put("error", e.getMessage());
            return resMap;
        }
    }

    @ApiOperation("获取单位结构树")
    @RequestMapping(value = "/findGroupAndStationTreeByUnitCode/{unitCode}", method = RequestMethod.GET)
    @ResponseBody
    public Map<String, Object> sendEMail(@PathVariable("unitCode") String unitCode) {
        try {
            List<GroupAndStationTree> treeList = unitStructureService.findGroupAndStationTreeByUnitCode(unitCode);
            Map<String, Object> resMap = new CorrectMap();
            resMap.put("res", treeList);
            return resMap;
        } catch (Exception e) {
            e.printStackTrace();
            Map<String, Object> resMap = new ErrorMap();
            resMap.put("error", e.getMessage());
            return resMap;
        }
    }
}
