InfoPublishController.java 2.64 KB
package com.bsth.controller.publish;

import com.bsth.common.ResponseCode;
import com.bsth.entity.publish.ScanStatictic;
import com.bsth.message.entity.AlarmADASVo;
import com.bsth.service.alarm.AlarmAdasService;
import com.bsth.service.publish.InfoPublishService;
import com.bsth.util.ReportUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

//@RestController
//@RequestMapping("api/info_publish")
public class InfoPublishController {

    private final static Logger log = LoggerFactory.getLogger(InfoPublishController.class);

    @Autowired
    private InfoPublishService infoPublishService;

    @RequestMapping(value = "/scan_statistic/list")
    public Map<String, Object> list(@RequestParam Map<String, String> param,
                                    @RequestParam(defaultValue = "0") int page,
                                    @RequestParam(defaultValue = "15") int size,
                                    @RequestParam(defaultValue = "timestamp") String order,
                                    @RequestParam(defaultValue = "0") int direction) {
        Map<String, Object> result = new HashMap<>();
        try {
            Map<String, Object> results = infoPublishService.list(param, page, size, order, direction);

            result.putAll(results);
            result.put("page", page);
            result.put("status", ResponseCode.SUCCESS);
        } catch (Exception e) {
            result.put("status", ResponseCode.ERROR);
            log.error(e.getMessage(), e);
        }

        return result;
    }

    @RequestMapping(value = "/scan_statistic/list_export")
    public Map<String, Object> list(@RequestParam Map<String, String> param) {
        Map<String, Object> result = new HashMap<>();
        try {
            Map<String, Object> results = infoPublishService.export(param);
            ReportUtils util = new ReportUtils();
            String path = this.getClass().getResource("/").getPath() + "static/pages/forms", rq = param.get("rq");
            util.excelReplace((List<Iterator<?>>) results.get("list"), new Object[]{}, String.format("%s/mould/scanStatistic.xls", path), String.format("%s/export/一站一码扫码情况%s.xls", path, rq));

            result.put("status", ResponseCode.SUCCESS);
        } catch (Exception e) {
            result.put("status", ResponseCode.ERROR);
            log.error(e.getMessage(), e);
        }

        return result;
    }
}