TTInfoDetailController.java 2.61 KB
package com.bsth.controller.schedule;

import com.bsth.common.ResponseCode;
import com.bsth.controller.BaseController;
import com.bsth.entity.CarPark;
import com.bsth.entity.schedule.TTInfoDetail;
import com.bsth.service.CarParkService;
import com.bsth.service.schedule.TTInfoDetailServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

/**
 * Created by xu on 16/7/2.
 */
@RestController
@RequestMapping("tidc")
public class TTInfoDetailController extends BaseController<TTInfoDetail, Long> {
    @Autowired
    private TTInfoDetailServiceImpl ttInfoDetailService;
    @Autowired
    private CarParkService carParkService;

    @RequestMapping(value = "/dataImportExtend", method = RequestMethod.POST)
    public Map<String, Object> uploadDataAndImport(
            MultipartFile file, String xlmc, String ttinfoname, String tcccode) throws Exception {
        Map<String, Object> resultMap = new HashMap<>();

        try {
            // 查看停车场是否存在,不存在报错
            Map<String, Object> param = new HashMap<>();
            param.put("parkCode_eq", tcccode);
            Iterator<CarPark> carParkIterator = carParkService.list(param).iterator();
            if (!carParkIterator.hasNext()) {
                // 没有停车场,报错
                resultMap.put("status", ResponseCode.ERROR);
                resultMap.put("msg", "没有停车场数据,停车场代码=" + tcccode);
            } else {
                CarPark carPark = carParkIterator.next();
                ttInfoDetailService.fileDataImport(file, xlmc, ttinfoname, carPark.getParkName());
                resultMap.put("status", ResponseCode.SUCCESS);
                resultMap.put("msg", "导入成功");
            }
        } catch (Exception exp) {
            exp.printStackTrace();
            throw exp;
        }

        return resultMap;
    }

    @RequestMapping(value = "/edit/{xlid}/{ttid}", method = RequestMethod.GET)
    public Object getEditInfo(
            @PathVariable("xlid") Integer xlid,
            @PathVariable("ttid") Long ttid) throws Exception {
        // TODO:返回类型需要修正
        return ttInfoDetailService.getEditInfo(xlid, ttid);
    }
}