package com.dxhy.customs.controller;

import java.util.Map;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.dxhy.common.aspect.SysLog;
import com.dxhy.common.constant.CommonConstants;
import com.dxhy.common.controller.AbstractController;
import com.dxhy.common.util.StringHelper;
import com.dxhy.common.utils.R;
import com.dxhy.customs.service.CustomsCollectService;

/**
 * 统计查询-获取图片流信息
 *
 * @author dxhy
 */
@SuppressWarnings("AlibabaUndefineMagicConstant")
@RestController
@RequestMapping("/collect")
public class CustomsCollectController extends AbstractController {

    /**
     * 下载文件的本地默认存储根路径
     */
    @Value("${ftp.connection.localpathprefix}")
    public String localPathDefault;

    @Resource
    private CustomsCollectService customsCollectService;

    /**
     * 获取图片附件流
     * 
     * @author 陈刚扬
     * @date 2020/8/10
     * @param pramsMap
     *            入参
     * @return java.lang.Object
     */
    @RequestMapping("/getImg")
    @ResponseBody
    @SysLog("获取图片流信息")
    public Object getImg(@RequestBody Map<String, String> pramsMap) {
        if (StringHelper.isBlank(pramsMap.get("customsScanId"))) {
            return ResponseEntity.ok(R.error("请检查参数！"));
        }
        if (StringHelper.isBlank(pramsMap.get("imgOrFile"))) {
            return ResponseEntity.ok(R.error("请检查参数！"));
        }
        try {
            String localPath = localPathDefault + "file/" + getUserName() + "/";
            return customsCollectService.getImgByCustomsScanId(pramsMap.get("customsScanId"), pramsMap.get("imgOrFile"),
                getUserInfo(), localPath);
        } catch (Exception e) {
            e.printStackTrace();
            return ResponseEntity.ok(R.error(CommonConstants.MSG_ERR_DEFAULT));
        }
    }

}
