/*
 * Author: wangjian
 * 生成ServiceImpl
 */
package com.tofly.watermeter.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tofly.watermeter.custom.service.meterBusiness.export.ExportCommonCodeService;
import com.tofly.watermeter.entity.Qfcbcqgl;
import com.tofly.watermeter.mapper.QfcbcqglMapper;
import com.tofly.watermeter.service.QfcbcqglService;
import com.tofly.watermeter.util.service.FileUpLoadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * 存储崔欠工作管理信息
 *
 * @author admin
 * @date Mon Aug 29 00:00:00 CST 2022
 */
@Service("qfcbcqglService")
public class QfcbcqglServiceImpl extends ServiceImpl<QfcbcqglMapper, Qfcbcqgl> implements QfcbcqglService {
    @Autowired
    private FileUpLoadService fileUpLoadService;
    @Autowired
    private ExportCommonCodeService exportCommonCodeService;

    @Value("${meter.upload.collectionFile}")
    private String collectionFile;

    private final static String TABLE_NAME = "TF_YWPN_QFCBCQGL_W";

    @Override
    public boolean insertInfo(Qfcbcqgl cqgl, List<MultipartFile> fileList) {
        StringBuilder sb = fileUpLoadService.saveFileList(fileList, collectionFile, TABLE_NAME);
        if (sb.length() > 0) {
            cqgl.setFiles(sb.toString());
        }
        return save(cqgl);
    }

    @Override
    public Page<Map> countInfo(HttpServletResponse response,Page page, Long templateExpert, String input, String start, String end) {
        if (templateExpert != null && templateExpert == 1){
            exportCommonCodeService.exportCode(response,"rushToOweService",baseMapper.countInfo(input, start, end));
        }
        return baseMapper.countInfo(page,input, start, end);
    }

    @Override
    public Map<String, Object> queryInfoByCode(String code,String start, String end,String node) {
        Map<String, Object> map = baseMapper.queryInfoByCode(code);
        if (map != null && !map.isEmpty()){
            map.put("info",baseMapper.rushToOweInfo(code, start, end, node));
        }
        return map;
    }
}
