package com.tofly.watermeter.custom.controller.meterBusiness;

import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tofly.common.core.entity.ResultRespone;
import com.tofly.common.core.util.StringUtil;
import com.tofly.common.oauth.exception.ToflyDeniedException;
import com.tofly.watermeter.custom.entity.*;
import com.tofly.watermeter.custom.service.SbManagerService;
import com.tofly.watermeter.em.Constant;
import com.tofly.watermeter.em.ExcelExportFileTypeEnum;
import com.tofly.watermeter.entity.*;
import com.tofly.watermeter.service.*;
import com.tofly.watermeter.strategy.ExcelStrategyContext;
import com.tofly.watermeter.util.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 水表管理接口
 *
 * @author by Wangjieliu
 * @date 2021/3/17
 */
@RestController
@AllArgsConstructor
@RequestMapping("/sbmanager")
@Api(tags = "表务--水表管理接口")
public class SbManagerController {
    private final BwrksbdatailService bwrksbdatailService;
    private final BwckdatailService bwckdatailService;
    private final BwsjdatailService bwsjdatailService;
    private final BwrkdetailService bwrkdetailService;
    private final BwhbdatailService bwhbdatailService;
    private final SbManagerService managerService;
    private final ExcelStrategyContext excelStrategyContext;
    private final QfkhjbxxService qfkhjbxxService;


    /**
     * 分页查询
     *
     * @param page     分页对象
     * @param searchSb 搜索
     * @return
     */
    @GetMapping("/rk")
    @ApiOperation(value = "入库记录分页查询")
    @ApiImplicitParam(name = "templateFlag", value = "导出标识；1：导出", required = false, dataType = "string")
    public ResultRespone getBwrkdetailPage(Page page, SearchSb searchSb, HttpServletResponse response) {
        IPage<MeterInfo> info = bwrkdetailService.getRkRecord(page, searchSb, response);
        if (StringUtil.isNull(info)) {
            return ResultRespone.failed("查询失败");
        }
        return ResultRespone.success(info);
    }


    /**
     * 新增入库记录明细表
     *
     * @param rk 入库记录明细表
     * @return ResultRespone
     */
    // = "新增入库记录明细表")
//    @ApiOperation(value = "新增入库记录明细表")//这里还不完善，需要进一步判断有没有相同水表编号的情况入库
//    @PostMapping("/rk")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "bwLsbh", value = "批次号", required = true, dataType = "String"),
//            @ApiImplicitParam(name = "bwBzh", value = "截止编号", required = true, paramType = "body", dataType = "long"),
//            @ApiImplicitParam(name = "bwBqh", value = "起始编号", required = true, paramType = "body", dataType = "long"),
//            @ApiImplicitParam(name = "beBhqz", value = "编号前缀", required = true, paramType = "body", dataType = "String"),
//            @ApiImplicitParam(name = "bwSbcj", value = "厂家", required = true, paramType = "body", dataType = "long"),
//            @ApiImplicitParam(name = "bwSblx", value = "水表型号", required = true, paramType = "body", dataType = "long"),
//            @ApiImplicitParam(name = "bwPcmc", value = "批号名称", required = true, paramType = "body", dataType = "String"),
//            @ApiImplicitParam(name = "bwSbkj", value = "水表口径", required = true, paramType = "body", dataType = "long")
//    })
//    public ResultRespone save(@RequestBody Bwsbrk rk) {
//        return ResultRespone.success(bwrkdetailService.insert(rk.getList()));
//    }

    /**
     * 新增水表入库第二种
     * 水表入库会存在几千上万支数量入库；出库则几百几百支的出库
     *
     * @param sbrk
     * @return
     */
    @ApiOperation(value = "新增入库记录明细表(第二种)")
    @PostMapping("/saveTwo")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "bwLsbh", value = "批次号", required = true, dataType = "String"),
            @ApiImplicitParam(name = "sbbhList", value = "水表编号；多个以逗号隔开", required = true, paramType = "body", dataType = "String"),
            @ApiImplicitParam(name = "bwSbcj", value = "厂家", required = true, paramType = "body", dataType = "long"),
            @ApiImplicitParam(name = "bwSblx", value = "水表型号", required = true, paramType = "body", dataType = "long"),
            @ApiImplicitParam(name = "bwSbkj", value = "水表口径", required = true, paramType = "body", dataType = "long")
    })
    public ResultRespone saveTwo(@RequestBody BwSbRkCkTwo sbrk) {
        return ResultRespone.success(bwrkdetailService.saveTwo(sbrk));
    }


    /**
     * 通过id查询入库记录明细表
     *
     * @return ResultRespone
     */
    @GetMapping("/getbylsbh")
    @ApiOperation(value = "通过流水编号，查看水表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "lsbh", value = "流水编号", required = true, dataType = "Long")
//            @ApiImplicitParam(name = "inputContent", value = "输入框搜索内容", required = true, dataType = "String")
    })
    public ResultRespone getSbByLsbh(@RequestParam("lsbh") String lsbh, Page page) {
//        , @RequestParam("inputContent") String inputContent
        IPage info = bwrkdetailService.getSbByLsbh(lsbh, page);
        if (StringUtil.isNull(info)) {
            return ResultRespone.failed("查询失败");
        }
        return ResultRespone.success(info);
    }


    /**
     * 分页查询
     *
     * @param page     分页对象
     * @param searchSb 水表首检表记录
     * @return
     */
    @GetMapping("/sbsj")
    @ApiOperation(value = "水表首检数据分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "size", value = "单页个数", dataType = "int"),
            @ApiImplicitParam(name = "current", value = "第几页", dataType = "int")
    })
    public ResultRespone getSjData(Page page, SearchSb searchSb) {
        Long bwSbkj = searchSb.getBwSbkj();
        Long bwSbcj = searchSb.getBwSbcj();
        Long bwSblx = searchSb.getBwSblx();
        String state = searchSb.getIsState();
        IPage info = bwsjdatailService.page(page, Wrappers.<Bwsjdatail>lambdaQuery()
                .eq(StringUtil.isNotNull(bwSbkj), Bwsjdatail::getBwSbkj, bwSbkj)
                .eq(StringUtil.isNotNull(bwSbcj), Bwsjdatail::getBwSbcj, bwSbcj)
                .eq(StringUtil.isNotNull(bwSblx), Bwsjdatail::getBwSblx, bwSblx)
                .eq(StringUtil.isNotEmpty(state), Bwsjdatail::getIsCheck, state)
                .orderByAsc(Bwsjdatail::getIsCheck, Bwsjdatail::getOperateDate));
//        IPage info = bwsjdatailService.getSjData(page, bwsjdatail);
        if (StringUtil.isNull(info)) {
            return ResultRespone.failed("查询失败");
        }
        return ResultRespone.success(info);
    }

    /**
     * 填写水表首检数据
     *
     * @param bwsjdatail 水表首检表记录
     * @return ResultRespone
     */
    // = "填写水表首检数据")
    @ApiOperation(value = "填写水表首检数据")
    @PostMapping("/sbsj")

    public ResultRespone updateById(@RequestBody Bwsjdatail bwsjdatail) {
        return ResultRespone.success(bwsjdatailService.updateSjData(bwsjdatail));
    }

    /**
     * 新增水表出库批次记录表
     *
     * @param ckInfo 出库信息字符串
     * @return ResultRespone
     */
//    @ApiOperation(value = "新增水表出库批次记录表")
//    @PostMapping("/ck")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "bwRkid", value = "入库记录明细表主键ID", required = true, dataType = "Long"),
//            @ApiImplicitParam(name = "bwLsbh", value = "出库流水编号", required = true, dataType = "String"),
//            @ApiImplicitParam(name = "bwSbcj", value = "水表厂家", required = true, dataType = "String"),
//            @ApiImplicitParam(name = "bwSblx", value = "水表类型", required = true, dataType = "String"),
//            @ApiImplicitParam(name = "bwSbkj", value = "水表口径", required = true, dataType = "String"),
//            @ApiImplicitParam(name = "lqSl", value = "领取数量", required = true, dataType = "Long"),
//            @ApiImplicitParam(name = "bwLqbm", value = "领取部门", required = true, dataType = "Long"),
//            @ApiImplicitParam(name = "bwLqry", value = "领取人员", required = true, dataType = "Long")
//    })
//    //出库这里逻辑变化，后期更改
//    public ResultRespone insertCk(@RequestBody String ckInfo) {
//        //JSON字符串转实体bean
//        List<Bwckdatail> ckList = JSONObject.parseArray(ckInfo, Bwckdatail.class);
//        return ResultRespone.success(bwckdatailService.insertCk(ckList));
//    }

    /**
     * 出库
     * 水表入库会存在几千上万支数量入库；出库则几百几百支的出库
     *
     * @param sbck
     * @return
     */
    @ApiOperation(value = "水表出库(第二种)")
    @PostMapping("/ckTwo")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "deptId", value = "领取部门ID", required = true, dataType = "String"),
            @ApiImplicitParam(name = "sbbhList", value = "水表编号；多个以逗号隔开", required = true, paramType = "body", dataType = "String"),
            @ApiImplicitParam(name = "bwSbcj", value = "厂家", required = true, paramType = "body", dataType = "long"),
            @ApiImplicitParam(name = "bwSblx", value = "水表型号", required = true, paramType = "body", dataType = "long"),
            @ApiImplicitParam(name = "bwSbkj", value = "水表口径", required = true, paramType = "body", dataType = "long"),
            @ApiImplicitParam(name = "userId", value = "领取人员ID", required = true, paramType = "body", dataType = "long"),
            @ApiImplicitParam(name = "gdbh", value = "出库工单编号", required = true, paramType = "body", dataType = "String")
    })
    public ResultRespone insertCkTwo(@RequestBody BwSbRkCkTwo sbck) {
        return ResultRespone.success(bwckdatailService.insertCkTwo(sbck));
    }


    @ApiOperation(value = "出库查询前缀")
    @PostMapping("/ckPrefix")
    public ResultRespone ckPrefix(@RequestBody SearchSb sb) {
        Long cjId = sb.getBwSbcj();
        return ResultRespone.success(bwckdatailService.ckPrefix(cjId));
    }


    // = "APP端依次录入水表出库状态")
    @ApiOperation(value = "APP端依次录入水表出库状态")
    @PostMapping("/enter")
    public ResultRespone ck(String sbbh) {
        return ResultRespone.success(bwckdatailService.appCk(sbbh));
    }

    @GetMapping("/sbkc")
    @ApiOperation(value = "库存查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "size", value = "单页个数", dataType = "int"),
            @ApiImplicitParam(name = "current", value = "第几页", dataType = "int")
    })
    public ResultRespone getKcRecord(Page page, String sbcj , String sbkj , String sblx) {
        IPage<Map> info = bwrksbdatailService.getsbkc(page, sbcj , sbkj , sblx);
        if (StringUtil.isNull(info)) {
            return ResultRespone.failed("查询失败");
        }
        return ResultRespone.success(info);
    }


    /**
     * 分页查询
     *
     * @param page       分页对象
     * @param bwckdatail 水表出库批次记录表
     * @return
     */
    @GetMapping("/ckpage")
    @ApiOperation(value = "出库记录分页查询")
    public ResultRespone getBwckdatailPage(Page page, @ModelAttribute Bwckdatail bwckdatail) {
        IPage info = bwckdatailService.page(page, Wrappers.query(bwckdatail));
        if (StringUtil.isNull(info)) {
            return ResultRespone.failed("查询失败");
        }
        return ResultRespone.success(info);
    }

    /**
     * 通过id查询水表出库批次记录表
     *
     * @param bwLsbh 出库流水编号
     * @return ResultRespone
     */
    @GetMapping("/ckbylsbh")
    @ApiOperation(value = "根据出库流水编号查看详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "bwLsbh", value = "出库记录流失编号", required = true, dataType = "String")
    })
    public ResultRespone getByCkLsbh(String bwLsbh) {
        List info = bwckdatailService.list(Wrappers.<Bwckdatail>lambdaQuery().eq(Bwckdatail::getBwLsbh, bwLsbh));
        if (StringUtil.isNull(info)) {
            return ResultRespone.failed("查询失败");
        }
        return ResultRespone.success(info);
    }


    /**
     * 修改水表出库批次记录表
     *
     * @param updateCkInfo 水表出库信息
     * @return ResultRespone
     */
//    // = "修改水表出库记录")
//    @ApiOperation(value = "修改水表出库记录")
//    @PutMapping("/updateck")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "ckId", value = "出库记录的ID", required = true, dataType = "Long"),
//            @ApiImplicitParam(name = "num", value = "修改后出库数量", required = true, dataType = "Long")
//    })
//    public ResultRespone updateCk(String updateCkInfo) {
//        List<BwSbCk> sbCkList = JSONObject.parseArray(updateCkInfo, BwSbCk.class);
//        return ResultRespone.success(bwckdatailService.updateCk(sbCkList));
//    }

    /**
     * 分页查询
     *
     * @param page         分页对象
     * @param bwrksbdatail 入库水表明细表
     * @return
     */
    @GetMapping("/sbpage")
    @ApiOperation(value = "水表分页查询")
    public ResultRespone getBwrksbdatailPage(Page page, @ModelAttribute Bwrksbdatail bwrksbdatail) {
        IPage info = bwrksbdatailService.page(page, Wrappers.query(bwrksbdatail));
        if (StringUtil.isNull(info)) {
            return ResultRespone.failed("查询失败");
        }
        return ResultRespone.success(info);
    }

    /**
     * 通过id查询入库水表明细表
     *
     * @param sbbh 水表编号
     * @return ResultRespone
     */
    @GetMapping
    @ApiOperation(value = "通过水表编号/客户编号查看水表详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "sbbh", value = "水表编号", required = true, dataType = "String"),
            @ApiImplicitParam(name = "yhbh", value = "用户编号", required = true, dataType = "String")
    })
    public ResultRespone getById(String sbbh, String yhbh) {
        if (StringUtil.isNotEmpty(sbbh)) {
            Bwrksbdatail info = bwrksbdatailService.getBySbbh(sbbh);
            if (StringUtil.isNull(info)) {
                return ResultRespone.failed("没该表记录");
            }
            return ResultRespone.success(info);
        } else if (StringUtil.isNotEmpty(yhbh)) {
            //App根据用户编号查询水表信息
            Bwrksbdatail info = bwrksbdatailService.getByYhbh(yhbh);
            return ResultRespone.success(info);
        } else {
            throw new ToflyDeniedException("请输入编号");
        }
    }


    @GetMapping("/hbGetOldInfo")
    @ApiOperation(value = "换表--查询旧表信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "sbbh", value = "水表编号", required = true, dataType = "String"),
            @ApiImplicitParam(name = "yhbh", value = "用户编号", required = true, dataType = "String")
    })
    public ResultRespone hbGetOldInfo(String sbbh, String yhbh) {
//        if (StringUtil.isEmpty(yhbh)&&StringUtil.isEmpty(sbbh)){
//            throw new ToflyDeniedException("请填写编号");
//        }
        Page page = new Page();
        //存在多次换表的情况
        IPage<Qfkhjbxx> qfkhjbxxPage = qfkhjbxxService.page(page , Wrappers.<Qfkhjbxx>lambdaQuery()
                .eq(StringUtil.isNotEmpty(sbbh) , Qfkhjbxx::getSbbh , sbbh)
                .eq(StringUtil.isNotEmpty(yhbh) , Qfkhjbxx::getYhbh , yhbh)
                .select(Qfkhjbxx::getYhbh , Qfkhjbxx::getYhxm , Qfkhjbxx::getYhdz , Qfkhjbxx::getLxdh ,
                        Qfkhjbxx::getSbbh , Qfkhjbxx::getSbcj , Qfkhjbxx::getSblx , Qfkhjbxx::getSbkj)
                .orderByDesc(Qfkhjbxx::getAzrq));
        if (StringUtil.isNull(qfkhjbxxPage)){
            ResultRespone.failed("暂未查询到旧表信息");
        }
        List<Qfkhjbxx> qfkhjbxx = qfkhjbxxPage.getRecords();
        return ResultRespone.success(qfkhjbxx);
    }


    @GetMapping("/azsb")
    @ApiOperation(value = "已安装水表分页查询")
    public ResultRespone getAzSb(Page page, SearchSb searchSb, HttpServletResponse response) {
        Long bwSbkj = searchSb.getBwSbkj();
        Long bwSbcj = searchSb.getBwSbcj();
        Long bwSblx = searchSb.getBwSblx();
        String inputContent = searchSb.getInputContent();
        String templateFlag = searchSb.getTemplateFlag();
        IPage info = bwrksbdatailService.page(page, Wrappers.<Bwrksbdatail>lambdaQuery().eq(Bwrksbdatail::getBwSbzt, "57")
                .eq(StringUtil.isNotNull(bwSbkj), Bwrksbdatail::getBwSbkj, bwSbkj)
                .eq(StringUtil.isNotNull(bwSbcj), Bwrksbdatail::getBwSbcj, bwSbcj)
                .eq(StringUtil.isNotNull(bwSblx), Bwrksbdatail::getBwSblx, bwSblx)
                .orderByDesc(Bwrksbdatail::getBwAzrq)
                .and(StringUtil.isNotEmpty(inputContent),k->k.like(Bwrksbdatail::getBwKhbh, inputContent).or()
                        .like(Bwrksbdatail::getBwKhxm, inputContent).or()
                        .like(Bwrksbdatail::getBwKhdz, inputContent).or()
                        .like(Bwrksbdatail::getBwKhdh, inputContent)));
        //如果传的是 1，则代表导出Excel数据
        if ("1".equals(templateFlag)) {
            // 根据templateServiceType,templateFlag获取对应模板数据
            ExcelExportFileTypeEnum excelExportFileTypeEnum = ExcelExportFileTypeEnum.getExcelExportFileTypeEnum("meterInstallServiceImpl", templateFlag);
            if (null == excelExportFileTypeEnum) {
                return null;
            }
            //将查询的结果转json字符串的格式，因为导出的时候只能传一个字符串
            String resultListToString = JSONArray.toJSONStringWithDateFormat(info.getRecords(), "yyyy-MM-dd");
            // 从模型类型枚举根据templateServiceType获取策略对应模板数据
            List<Map<String, Object>> dataList = excelStrategyContext.getExportData("meterInstallServiceImpl", templateFlag, resultListToString);
            ExcelUtil.export(dataList.get(0), excelExportFileTypeEnum, Constant.FILE_PATH_TEST_EXPORT_EXCEL, response);
            return null;
        }
        if (StringUtil.isNull(info)) {
            return ResultRespone.failed("查询失败");
        }
        return ResultRespone.success(info);
    }


    /**
     * 水表零星安装
     *
     * @param bwrksbdatail
     * @return
     */
    // = "水表单个安装/修改")
    @ApiOperation(value = "水表单个安装/修改")
    @PostMapping("/azsb")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "bwSbbh", value = "水表编号", required = true, dataType = "Long"),
            @ApiImplicitParam(name = "bwAzrq", value = "安装日期", required = true, dataType = "Date"),
            @ApiImplicitParam(name = "bwAzry", value = "安装人员", required = true, dataType = "Long"),
            @ApiImplicitParam(name = "bwGspq", value = "片区", required = true, dataType = "Long"),
            @ApiImplicitParam(name = "bwKhdh", value = "客户电话", required = true, dataType = "String"),
            @ApiImplicitParam(name = "bwKhdz", value = "客户地址", required = true, dataType = "String"),
            @ApiImplicitParam(name = "bwKhxm", value = "客户姓名", required = true, dataType = "String"),
            @ApiImplicitParam(name = "bwSbqd", value = "水表起度", required = true, dataType = "Double"),
            @ApiImplicitParam(name = "flag", value = "水表安装/修改标识；1：安装；2：修改", required = true, dataType = "byte"),
    })
    public ResultRespone install(@RequestBody Bwrksbdatail bwrksbdatail) {

        return ResultRespone.success(bwrksbdatailService.install(bwrksbdatail));
    }


    // = "安装水表删除")
    @ApiOperation(value = "安装水表删除")
    @DeleteMapping("/deleteAz/{id}")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "水表ID", required = true, dataType = "Long")
    })
    public ResultRespone delteInsatll(@PathVariable("id") Long id) {
        return ResultRespone.success(bwrksbdatailService.delteInsatll(id));
    }


//    /**
//     * 根据Excel表导入到临时表并返回数据
//     *
//     * @param page
//     * @param file
//     * @return
//     */
//    @PostMapping(value = "/excelAz", headers = "content-type=multipart/form-data")
//    @ApiOperation(value = "Excel表批量导入安装数据")
//    // = "Excel表批量导入安装数据")
//    public ResultRespone excelAz(Page page, @RequestParam("file") MultipartFile file) {
//        return ResultRespone.success(bwrksbdatailService.excelAz(page, file));
//    }

//    /**
//     * 根据Excel表导入到临时表并返回数据
//     *
//     * @return
//     */
//    @DeleteMapping(value = "/deleteTemp")
//    @ApiOperation(value = "删除临时表中安装数据")
//    // = "删除临时表中安装数据")
//    public ResultRespone deleteTemp(String[] sbbh) {
//        return ResultRespone.success(bwrksbdatailService.deleteTemp(Arrays.asList(sbbh)));
//    }

    /**
     * 批量导入临时表中的安装数据
     *
     * @param infos
     * @return
     */
    @PostMapping(value = "/batchImport")
    @ApiOperation(value = "批量导入水表安装数据")
    // = "批量导入水表安装数据")
    public ResultRespone batchImport(@RequestBody SbInfo infos) {
        return ResultRespone.success(bwrksbdatailService.batchImport(infos));
    }

    /**
     * 修改换表客户信息，目前不能删除客户信息，因为报废表统计需要展示客户信息
     *
     * @param bwhbdatail
     * @return
     */
    @PostMapping(value = "/exchange")
    @ApiOperation(value = "换表")
    // = "换表")
    public ResultRespone exchange(@RequestBody CustomHbdetail bwhbdatail) {
        return ResultRespone.success(bwrksbdatailService.exchange(bwhbdatail));
    }

    @PostMapping(value = "/exchangeApp")
    @ApiOperation(value = "换表App")
    public ResultRespone exchangeApp(@RequestBody CustomHbdetail bwhbdatail) {
        return ResultRespone.success(bwrksbdatailService.exchangeApp(bwhbdatail));
    }

    @GetMapping(value = "/exchange")
    @ApiOperation(value = "换表分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "inputContent", value = "搜索客户信息输入框", required = true, dataType = "String"),
            @ApiImplicitParam(name = "sbbh", value = "水表编号输入框", required = true, dataType = "String"),
            @ApiImplicitParam(name = "templateFlag", value = "导出标识；1：导出", required = true, dataType = "String")
    })
    public ResultRespone getExchange(Page page, SearchSb searchSb, HttpServletResponse response) {
        String inputcontent = searchSb.getInputContent();
        String templateFlag = searchSb.getTemplateFlag();
        String sbbh = searchSb.getSbbh();
        Date startTime = searchSb.getTime();
        Date endTime = searchSb.getEndTime();

        IPage info = bwhbdatailService.getExchange(page, inputcontent, sbbh, startTime, endTime);
        //如果传的是 1，则代表导出Excel数据
        if ("1".equals(templateFlag)) {
            // 根据templateServiceType,templateFlag获取对应模板数据
            ExcelExportFileTypeEnum excelExportFileTypeEnum = ExcelExportFileTypeEnum.getExcelExportFileTypeEnum("meterExchangeService", templateFlag);
            if (null == excelExportFileTypeEnum) {
                return null;
            }
            //将查询的结果转json字符串的格式，因为导出的时候只能传一个字符串
            String resultListToString = JSONArray.toJSONStringWithDateFormat(info.getRecords(), "yyyy-MM-dd HH:mm:ss");
            // 从模型类型枚举根据templateServiceType获取策略对应模板数据
            List<Map<String, Object>> dataList = excelStrategyContext.getExportData("meterExchangeService", templateFlag, resultListToString);
            ExcelUtil.export(dataList.get(0), excelExportFileTypeEnum, Constant.FILE_PATH_TEST_EXPORT_EXCEL, response);
            return null;
        }


        if (StringUtil.isNull(info)) {
            return ResultRespone.failed("查询失败");
        }
        return ResultRespone.success(info);
    }

    @PutMapping(value = "/exchange")
    @ApiOperation(value = "修改换表信息")
    // = "修改换表信息")
    public ResultRespone updateExchange(@RequestBody Bwhbdatail bwhbdatail) {
        return ResultRespone.success(managerService.updateExchange(bwhbdatail));
    }

    @DeleteMapping(value = "/exchange/{id}")
    @ApiOperation(value = "删除换表信息")
    // = "删除换表信息")
    public ResultRespone deleteExchange(@PathVariable("id") Long id) {
        return ResultRespone.success(managerService.deleteExchange(id));
    }


    /**
     * 移交
     *
     * @return
     */
    // = "新增水表移交")
//    @ApiOperation(value = "新增水表移交(第一种)")
//    @PostMapping(value = "/turnover")
//    public ResultRespone turnover(@RequestBody CustomSbYjgl bwsbyjgl) {
//        return ResultRespone.success(managerService.turnover(bwsbyjgl));
//    }

    @ApiOperation(value = "新增水表移交(第二种)")
    @PostMapping(value = "/turnoverTwo")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "bwJsbm", value = "接收部门ID", required = true, dataType = "long"),
            @ApiImplicitParam(name = "sbbhList", value = "水表编号；多个以逗号隔开", required = true, paramType = "body", dataType = "String"),
            @ApiImplicitParam(name = "bwSbcj", value = "厂家", required = true, paramType = "body", dataType = "long"),
            @ApiImplicitParam(name = "bwSblx", value = "水表型号", required = true, paramType = "body", dataType = "long"),
            @ApiImplicitParam(name = "bwSbkj", value = "水表口径", required = true, paramType = "body", dataType = "long"),
            @ApiImplicitParam(name = "bwJsry", value = "接收人员ID", required = true, paramType = "body", dataType = "long"),
            @ApiImplicitParam(name = "bwYjrq", value = "移交时间", required = true, paramType = "body", dataType = "Date")
    })
    public ResultRespone turnoverTwo(@RequestBody CustomSbYjgl bwsbyjgl) {
        return ResultRespone.success(managerService.turnoverTwo(bwsbyjgl));
    }

    @ApiOperation(value = "新增水表移交(第三种)")
    @PostMapping(value = "/turnoverThree")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "bwJsbm", value = "接收部门ID", required = true, dataType = "long"),
//            @ApiImplicitParam(name = "sbbhList", value = "水表编号；多个以逗号隔开", required = true, paramType = "body", dataType = "String"),
//            @ApiImplicitParam(name = "bwSbcj", value = "厂家", required = true, paramType = "body", dataType = "long"),
//            @ApiImplicitParam(name = "bwSblx", value = "水表型号", required = true, paramType = "body", dataType = "long"),
//            @ApiImplicitParam(name = "bwSbkj", value = "水表口径", required = true, paramType = "body", dataType = "long"),
//            @ApiImplicitParam(name = "bwJsry", value = "接收人员ID", required = true, paramType = "body", dataType = "long"),
//            @ApiImplicitParam(name = "bwYjrq", value = "移交时间", required = true, paramType = "body", dataType = "Date")
//    })
    public ResultRespone turnoverThree(@RequestPart @Valid CustomSbYjgl bwsbyjgl , @RequestPart(value = "file", required = false) MultipartFile file) {
        return ResultRespone.success(managerService.turnoverFive(bwsbyjgl , file));
    }

    @ApiOperation(value = "新增水表移交(第四种);用于退库")
    @PostMapping(value = "/turnoverFour")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "bwJsbm", value = "接收部门ID", required = true, dataType = "long"),
//            @ApiImplicitParam(name = "sbbhList", value = "水表编号；多个以逗号隔开", required = true, paramType = "body", dataType = "String"),
//            @ApiImplicitParam(name = "bwSbcj", value = "厂家", required = true, paramType = "body", dataType = "long"),
//            @ApiImplicitParam(name = "bwSblx", value = "水表型号", required = true, paramType = "body", dataType = "long"),
//            @ApiImplicitParam(name = "bwSbkj", value = "水表口径", required = true, paramType = "body", dataType = "long"),
//            @ApiImplicitParam(name = "bwJsry", value = "接收人员ID", required = true, paramType = "body", dataType = "long"),
//            @ApiImplicitParam(name = "bwYjrq", value = "移交时间", required = true, paramType = "body", dataType = "Date")
//    })
    public ResultRespone turnoverFour(@RequestPart @Valid CustomSbYjgl bwsbyjgl , @RequestPart(value = "file", required = false) MultipartFile file) {
        return ResultRespone.success(managerService.turnoverFour(bwsbyjgl , file));
    }


    @ApiOperation(value = "移交水表分页查询")
    @GetMapping(value = "/turnover")
    public ResultRespone getTurnover(Page page, Bwsbyjgl bwsbyjgl) {
        return ResultRespone.success(managerService.getTurnover(page, bwsbyjgl));
    }

    @ApiOperation(value = "移交水表详情查看")
    @GetMapping(value = "/turnoverById")
    public ResultRespone getTurnoverById(Long id) {
        return ResultRespone.success(managerService.getTurnoverById(id));
    }

    @ApiOperation(value = "根据ID删除移交")
    @PostMapping(value = "/deleteTurnoverById")
    public ResultRespone deleteTurnoverById(Long id) {
        return ResultRespone.success(managerService.deleteTurnoverById(id));
    }


    /**
     * 获取周检或故障移交未处理的水表
     *
     * @param sb
     * @return
     */
    @ApiOperation(value = "获取周检或故障移交未处理的水表")
    @GetMapping(value = "/getZjOrGz")
    public ResultRespone getZjOrGz(Page page, SearchSb sb) {
        return ResultRespone.success(managerService.getZjOrGz(page, sb));
    }

}
