package com.sw.mes.yb.production.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.sw.mes.base.factory.inspect.entity.DocumentPrint;
import com.sw.mes.base.factory.inspect.service.DocumentPrintService;
import com.sw.mes.base.system.service.impl.PrintService;
import com.sw.mes.base.workinprocess.entity.PlanProcessingOrder;
import com.sw.mes.base.workinprocess.service.PlanProcessingOrderService;
import com.sw.mes.core.dto.LongCrystalDto1;
import com.sw.mes.core.dto.PrintInfoDto;
import com.sw.mes.core.enums.EnumValuesFactory;
import com.sw.mes.core.response.ResponsePage;
import com.sw.mes.core.response.Result;
import com.sw.mes.core.response.ResultGenerator;
import com.sw.mes.core.utils.*;
import com.sw.mes.enumvalue.EnumValuesServer;
import com.sw.mes.utils.StringUtils;
import com.sw.mes.yb.plan.entity.ProductionSchedule;
import com.sw.mes.yb.plan.service.ProductionScheduleService;
import com.sw.mes.yb.production.dto.LongCrystalDto;
import com.sw.mes.yb.production.dto.LongCrystalInfoDto;
import com.sw.mes.yb.production.dto.LongCrystalWorkHourDto;
import com.sw.mes.yb.production.dto.ResponseTimePage;
import com.sw.mes.yb.production.entity.AgainTask;
import com.sw.mes.yb.production.entity.InspectionRecord;
import com.sw.mes.yb.production.entity.LongCrystal;
import com.sw.mes.yb.production.service.InspectionRecordService;
import com.sw.mes.yb.production.service.LongCrystalService;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.modelmapper.ModelMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;


/**
 * @Author
 * @Description：
 * @Date: Create in
 * @Modified By:
 */
@RestController
@RequestMapping("/longCrystal")
@Slf4j
@Api(description = "长晶棒信息接口")
public class LongCrystalController {
    @Autowired
    ModelMapper modelMapper;

    @Autowired
    private LongCrystalService longCrystalService;
    @Autowired
    private InspectionRecordService inspectionRecordService;
    @Autowired
    private ProductionScheduleService productionScheduleService;
    @Autowired
    private PlanProcessingOrderService planProcessingOrderService;
    @Autowired
    private DocumentPrintService documentMouldService;

    @Autowired
    private PrintService printService;


    // 设备号、炉次号、单晶编号、状态（未送验、已送验）下拉选择
    @ApiOperation(value = "分页查询长晶棒信息列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "rows", value = "行数", dataType = "integer", paramType = "query"),
            @ApiImplicitParam(name = "page", value = "页码", dataType = "integer", paramType = "query"),
            @ApiImplicitParam(name = "search_LIKE_equipmentCode", value = "设备号", dataType = "string"),
            @ApiImplicitParam(name = "search_LIKE_lotNo", value = "炉次号", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "search_LIKE_crystalNo", value = "单晶编号", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "search_EQ_isDone", value = "是否完结(0未完结，1完结复投）", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "search_EQ_crystalStatus", value = "状态 0-未送验；1-已送验；", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "search_GTE_gmtCreate", value = "产出开始时间（yyyy-MM-dd HH:mm:ss）", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "search_LTE_gmtCreate", value = "产出结束时间（yyyy-MM-dd HH:mm:ss）", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "search_GTE_lineStartTime", value = "划线开始时间起（yyyy-MM-dd HH:mm:ss）", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "search_LTE_lineStartTime", value = "划线开始时间止（yyyy-MM-dd HH:mm:ss）", dataType = "String", paramType = "query"),
    })
    //添加完结方式
    @GetMapping("/listByPage")
    public Result<ResponsePage<LongCrystalDto>> listByPage(ServletRequest request, @ApiIgnore RequestPage requestPage) {
        Specification<LongCrystal> specification = DynamicSpecifications.bySearchFilter(request, LongCrystal.class);
        Page<LongCrystal> page = longCrystalService.findByExample(specification, PageUtil.createPageable(requestPage));
        List<LongCrystalDto> dtos = page.getContent().stream()
                .map(entity -> toLazyDto(entity))
                .collect(Collectors.toList());
        // 对完结标识为w的长晶棒，产出时间特殊处理一下,加9个小时
        for (LongCrystalDto dto : dtos) {
//            if (null != dto && null != dto.getClosureIdentification() && !StringUtils.isEmpty(dto.getClosureIdentification()) && dto.getClosureIdentification().equals("W")){
//                Date gmtCreate = dto.getGmtCreate();
//                if (null != gmtCreate){
//                    long gmtCreateTime = gmtCreate.getTime();
//                    Date newDate = new Date();
//                    newDate.setTime(gmtCreateTime + 9*60*60*1000);
//                    dto.setGmtCreate(newDate);
//                }
//            }
            InspectionRecord lastCrystalNoLog = inspectionRecordService.getLastCrystalNoLog(dto.getCrystalNo());
            if(null != lastCrystalNoLog){
                dto.setInspectionTime(lastCrystalNoLog.getInspectionTime());
            }
        }
        ResponseTimePage responsePage = new ResponseTimePage(dtos, page.getTotalElements());
        return ResultGenerator.success(responsePage);
    }

    // 设备号、炉次号、单晶编号、状态（未送验、已送验）下拉选择
    @ApiOperation(value = "晶棒信息表导出(最多可导出1W条)")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "rows", value = "行数", dataType = "integer", paramType = "query"),
            @ApiImplicitParam(name = "page", value = "页码", dataType = "integer", paramType = "query"),
            @ApiImplicitParam(name = "search_LIKE_equipmentCode", value = "设备号", dataType = "string"),
            @ApiImplicitParam(name = "search_LIKE_lotNo", value = "炉次号", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "search_LIKE_crystalNo", value = "单晶编号", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "search_EQ_isDone", value = "是否完结(0未完结，1完结复投）", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "search_EQ_crystalStatus", value = "状态 0-未送验；1-已送验；", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "search_GTE_gmtCreate", value = "产出开始时间（yyyy-MM-dd HH:mm:ss）", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "search_LTE_gmtCreate", value = "产出结束时间（yyyy-MM-dd HH:mm:ss）", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "search_GTE_lineStartTime", value = "划线开始时间起（yyyy-MM-dd HH:mm:ss）", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "search_LTE_lineStartTime", value = "划线开始时间止（yyyy-MM-dd HH:mm:ss）", dataType = "String", paramType = "query"),
    })
    @GetMapping("/export")
    public void export(ServletRequest request, HttpServletResponse response, @ApiIgnore RequestPage requestPage) {
        try {
            requestPage.setRows(20000);
            Specification<LongCrystal> specification = DynamicSpecifications.bySearchFilter(request, LongCrystal.class);
            Page<LongCrystal> page = longCrystalService.findByExample(specification, PageUtil.createPageable(requestPage));
            List<LongCrystalDto> dtos = page.getContent().stream()
                    .map(this::toLazyDto)
                    .collect(Collectors.toList());
            // 对完结标识为w的长晶棒，产出时间特殊处理一下,加9个小时
//            for (LongCrystalDto dto : dtos) {
//                if (null != dto && null != dto.getClosureIdentification() && !StringUtils.isEmpty(dto.getClosureIdentification()) && dto.getClosureIdentification().equals("W")){
//                    Date gmtCreate = dto.getGmtCreate();
//                    if (null != gmtCreate){
//                        long gmtCreateTime = gmtCreate.getTime();
//                        Date newDate = new Date();
//                        newDate.setTime(gmtCreateTime + 9*60*60*1000);
//                        dto.setGmtCreate(newDate);
//                    }
//                }
//            }
            //todo 加很多字段，同时将单晶生产产量报表的数据挪过来，糅合在一起。（此部分代码暂时不上线，方案待重新审核）
//            List<LongCrystalExcelDto> longCrystalExcelDtos = longCrystalService.giveSomeValues(dtos);

            EasyExcelUtils.write(response, LongCrystalDto.class, "长晶棒产出", "长晶棒产出导出", dtos);
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException("长晶棒产出导出，错误信息：" + e.getMessage());
        }
    }

    @ApiOperation(value = "获取所有长晶棒信息")
    @GetMapping("/listAll")
    public Result<List<LongCrystalDto>> listAll(ServletRequest request) {
        Specification<LongCrystal> specification = DynamicSpecifications.bySearchFilter(request, LongCrystal.class);
        List<LongCrystal> longCrystals = longCrystalService.findByExampleSort(specification, null);
        List<LongCrystalDto> longCrystalDtos = longCrystals.stream()
                .map(this::toLazyDto)
                .collect(Collectors.toList());
        return ResultGenerator.success(longCrystalDtos);
    }

    @ApiOperation(value = "长晶棒信息详细信息")
    @GetMapping("/{id}")
    public Result<LongCrystalDto> get(@PathVariable @ApiParam(value = "长晶棒信息id") Long id) {
        LongCrystal longCrystal = longCrystalService.get(id);
        if (null == longCrystal) {
            return ResultGenerator.fail("该长晶棒信息不存在");
        }
        return ResultGenerator.success(toEagerDto(longCrystal));
    }

    @ApiOperation(value = "查询最新的几个炉次号")
    @GetMapping("/findTop3LotNo")
    public Result<List<String>> findTop3LotNo() {
        List<String> top3LotNo = longCrystalService.findTop3LotNo();
        if (null == top3LotNo) {
            return ResultGenerator.fail("该长晶棒信息不存在");
        }
        return ResultGenerator.success(top3LotNo);
    }

    //List<String> findTop3LotNoByEquipmentCode(String equipmentCode)
    @ApiOperation(value = "根据设备号查询最新的几个炉次号")
    @GetMapping("/findTop3LotNoByEquipmentCode")
    public Result<List<String>> findTop3LotNoByEquipmentCode(@RequestParam @ApiParam(value = "设备编号") String equipmentCode) {
//        List<String> top3LotNo = longCrystalService.findTop3LotNoByEquipmentCode(equipmentCode);
        List<String> top3LotNo = productionScheduleService.findTop3LotNoByEquipmentCode(equipmentCode);
        if (null == top3LotNo) {
            return ResultGenerator.fail("该长晶棒信息不存在");
        }
        return ResultGenerator.success(top3LotNo);
    }


    @ApiOperation(value = "创建长晶棒信息")
    @PostMapping("/create")
    public Result create(@RequestBody @Valid @ApiParam(value = "长晶棒信息对象") LongCrystalDto longCrystalDto, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            return ResultGenerator.fail(bindingResult.getFieldError().getDefaultMessage());
        }
        LongCrystal longCrystal = fromDto(longCrystalDto);
        longCrystalService.saveOrUpdate(longCrystal);
        return ResultGenerator.success();
    }

    @ApiOperation(value = "更新长晶棒信息")
    @PostMapping("/update")
    public Result update(@RequestBody @Valid @ApiParam(value = "长晶棒信息") LongCrystalDto dto, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            return ResultGenerator.fail(bindingResult.getFieldError().getDefaultMessage());
        }
        if (dto.getId() == null) {
            return ResultGenerator.fail("id不能为空");
        }
        LongCrystal entity = longCrystalService.get(dto.getId());
        if (entity == null) {
            return ResultGenerator.fail("原信息不存在");
        }
        try {
            LongCrystal entityfromFto = fromDto(dto);
            BeanUtils.copyProperties(entityfromFto, entity, BeanUtil.getIgnoreProperties(entityfromFto, null, null));
            longCrystalService.saveOrUpdate(entity);
            return ResultGenerator.success();
        } catch (Exception e) {
            return ResultGenerator.fail(e.getMessage());
        }
    }

    @ApiOperation(value = "长晶棒重新匹配订单")
    @PostMapping("/updateOrder")
    public Result updateOrder(@RequestBody List<String> sectionNos) {
        if (!CollectionUtils.isEmpty(sectionNos)) {
            for (String sectionNo : sectionNos) {
                LongCrystal longCrystal = longCrystalService.findByCrystalNo(sectionNo);
                if (null != longCrystal) {
                    longCrystalService.completionLongCrystalOrder(longCrystal.getLotNo(), sectionNo, longCrystal.getLineStartTime(), longCrystal.getMaxDiam(), longCrystal.getMinDiam(), false);
                }
            }
        }
        return ResultGenerator.success();
    }

    @ApiOperation(value = "修改长晶棒编号")
    @PostMapping("/updateCrystalNo")
    public Result updateCrystalNo(@RequestBody @Valid @ApiParam(value = "长晶棒信息") LongCrystalInfoDto dto, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            return ResultGenerator.fail(bindingResult.getFieldError().getDefaultMessage());
        }
        if (dto.getId() == null) {
            return ResultGenerator.fail("id不能为空");
        }
        return longCrystalService.updateCrystalNo(dto);
    }

    @ApiOperation(value = "修改长晶棒长度和重量")
    @PostMapping("/updateWeightAndHeight")
    public Result updateWeightAndHeight(@RequestBody @ApiParam(value = "长晶棒信息") LongCrystalInfoDto dto) {

        if (dto.getId() == null) {
            return ResultGenerator.fail("id不能为空");
        }
        return longCrystalService.updateWeightAndHeight(dto);
    }

    /**
     * 此接口对应PDA端“送验绑定页面”的“取消按钮”，将长晶信息中的长晶状态改为4-异常（不流向送验绑定工步）
     *
     * @param dto
     * @param bindingResult
     * @return
     */
    @ApiOperation(value = "更新长晶棒状态")
    @PostMapping("/updateCrystalStatus")
    public Result updateCrystalStatus(@RequestBody @Valid @ApiParam(value = "长晶棒信息") LongCrystalDto dto, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            return ResultGenerator.fail(bindingResult.getFieldError().getDefaultMessage());
        }
        if (dto.getId() == null) {
            return ResultGenerator.fail("id不能为空");
        }
        return longCrystalService.updateCrystalStatus(dto);
    }

//    @ApiOperation(value = "删除长晶棒信息")
//    @PostMapping("/delete")
//    public Result remove(@ApiParam(value = "id集合,逗号分隔,如2,4", type = "query") @RequestParam Long[] ids) {
//        for (Long id : ids) {
//            longCrystalService.delete(id);
//        }
//        return ResultGenerator.success();
//    }

    @ApiOperation(value = "删除长晶棒信息-改变标识")
    @PostMapping("/delete")
    public Result remove(@ApiParam(value = "id集合,逗号分隔,如2,4", type = "query") @RequestParam Long[] ids) {
        for (Long id : ids) {
            LongCrystal longCrystal = longCrystalService.get(id);
            if (longCrystal.getCrystalStatus() == 0 || longCrystal.getCrystalStatus() == 9) {
                longCrystalService.delete(id);

                // 检查是否关闭排程
                PlanProcessingOrder processingOrder = planProcessingOrderService.get(longCrystal.getLotId());
                if (processingOrder.getStatus() == EnumValuesFactory.PlanProcessingOrderStatus.加工完成.getKey()){
                    List<LongCrystal> crystalList = longCrystalService.findUnconfirmedByLotNo(longCrystal.getLotNo());
                    if (CollectionUtils.isEmpty(crystalList)){
                        ProductionSchedule schedule = productionScheduleService.get(longCrystal.getScheduleId());
                        schedule.setStatus(EnumValuesServer.ProductionScheduleStatus.已完成.getKey());
                        schedule.setStatusInfo("加工工单已关闭，该炉次无未确认产出晶棒");
                        schedule.setCloseTime(new Date());
                        productionScheduleService.saveOrUpdate(schedule);
                    }
                }
            }
        }
        return ResultGenerator.success();
    }

    @ApiOperation(value = "查询最新的几个炉次号")
    @RequestMapping(value = "/getCrystalData", method = {RequestMethod.GET, RequestMethod.POST})
    public Result<LongCrystalDto1> getCrystalData(String crystalNo) {
        LongCrystal byCrystalNo = longCrystalService.findByCrystalNo(crystalNo);
        if (null != byCrystalNo) {
            LongCrystalDto1 longCrystalDto1 = toLazyDto1(byCrystalNo);
            return ResultGenerator.success(longCrystalDto1);
        }
        return ResultGenerator.success();
    }

    @ApiOperation(value = "查询炉次号")
    @RequestMapping(value = "/getAllCrystalData", method = {RequestMethod.GET, RequestMethod.POST})
    public Result<List<LongCrystalDto1>> getCrystalData(@RequestBody List<String> crystalNo) {
        List<LongCrystal> byCrystalNos = longCrystalService.findAllByCrystalNo(crystalNo);
        if (null != byCrystalNos) {
            List<LongCrystalDto1> byCrystalNoDtos = new ArrayList<>();
            for (LongCrystal byCrystalNo : byCrystalNos) {
                LongCrystalDto1 longCrystalDto1 = toLazyDto1(byCrystalNo);
                byCrystalNoDtos.add(longCrystalDto1);
            }
            return ResultGenerator.success(byCrystalNoDtos);
        }
        return ResultGenerator.success();
    }

    @ApiOperation(value = "查询长晶棒")
    @RequestMapping(value = "/getAllCrystalDataById", method = {RequestMethod.GET, RequestMethod.POST})
    public Result<List<LongCrystalDto1>> getCrystalDataById(@RequestBody List<Integer> ids) {
        List<LongCrystal> byCrystalNos = longCrystalService.findByIds(ids);
        if (null != byCrystalNos) {
            List<LongCrystalDto1> byCrystalNoDtos = new ArrayList<>();
            for (LongCrystal byCrystalNo : byCrystalNos) {
                LongCrystalDto1 longCrystalDto1 = toLazyDto1(byCrystalNo);
                byCrystalNoDtos.add(longCrystalDto1);
            }
            return ResultGenerator.success(byCrystalNoDtos);
        }
        return ResultGenerator.success();
    }

    @ApiOperation(value = "毛棒打印")
    @PostMapping("/printHairStick")
    public Result printHairStick(@RequestParam Long id) {
        LongCrystal longCrystal = longCrystalService.get(id);
        if (null == longCrystal){
            return ResultGenerator.fail("长晶棒记录不存在");
        }
        //查询长棒打印模版配置信息
        DocumentPrint documentPrint = documentMouldService.findByDocumentMould(DocumentPrint.PRINT_HAIR_STICK);
        if (null == documentPrint){
            return ResultGenerator.fail("晶棒产出标签模板不存在！");
        }

        List<Map<String, String>> keyvaluessA = new ArrayList<>();
        Map<String, String> mapData = new HashMap<>();
        mapData.put("crystalNo",longCrystal.getCrystalNo());
        mapData.put("dopant",longCrystal.getDopant());
        mapData.put("specification",longCrystal.getSpecs());
        //添加冷却结束时间
        if(null != longCrystal.getGmtCreate()){
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date coolingEndTime = DateUtil.addHour(longCrystal.getGmtCreate(), 9);
            mapData.put("coolingEndTime", simpleDateFormat.format(coolingEndTime));
        }else {
            mapData.put("coolingEndTime", null);
        }
        mapData.put("lengths",null == longCrystal.getLength() ? "" : longCrystal.getLength().toString());
        mapData.put("weight",null == longCrystal.getWeight() ? "" : longCrystal.getWeight().toString());
        keyvaluessA.add(mapData);
        //打印长棒编码
        PrintInfoDto printInfoDto = new PrintInfoDto();
        printInfoDto.setPrinterName(documentPrint.getPrintName());
        printInfoDto.setTemplateAddress(documentPrint.getDocumentPath());
        printInfoDto.setDocIp(documentPrint.getPrintIp());
        printInfoDto.setData(JSON.toJSONString(keyvaluessA));
        printInfoDto.setPrintNum(1);
        if (StringUtils.isNotBlank(documentPrint.getPrintName())) {
            printService.printAsync(printInfoDto);
        }
        Result result = printService.printShow(printInfoDto);
        log.info("打签日志：{}", JSONObject.toJSONString(result));
        return ResultGenerator.success();
    }

    @ApiOperation(value = "根据设备号查询最新晶棒颗次")
    @GetMapping("/getLastCrystalNum")
    public Result<Integer> getLastCompleteTask(@ApiParam(value = "设备号") String equipmentCode) {
        LongCrystal crystal = longCrystalService.findLastByEquipmentCode(equipmentCode);
        if (ObjectUtils.isEmpty(crystal)) {
           return ResultGenerator.success(1);
        }
        return ResultGenerator.success((crystal.getCrystalNum() + 1));
    }

    @ApiOperation(value = "根据工单拉取拉晶工时数据")
    @PostMapping("/getCrystalWorkHour")
    public Result<List<LongCrystalWorkHourDto>> getCrystalWorkHour(@RequestBody List<String> orderList) {

        List<LongCrystalWorkHourDto> crystalWorkHour = longCrystalService.getCrystalWorkHour(orderList);

//        try {
//            EasyExcelUtils.write(LongCrystalWorkHourDto.class, "拉晶数据工时", "拉晶工时数据", crystalWorkHour);
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
        return ResultGenerator.success(crystalWorkHour);
    }


//    public void getExcel(List<LongCrystalWorkHourDto> crystalWorkHour){
//        XSSFWorkbook wb = new XSSFWorkbook();
//        XSSFSheet sheet = wb.createSheet("方棒出库到WMS");
//        XSSFRow row;
//        row = sheet.createRow(0);
//        row.createCell(0).setCellValue("序号");
//        row.createCell(1).setCellValue("托号");
//
//
//        for (int i = 0; i < crystalWorkHour.size(); i++) {
//            row = sheet.createRow(i + 1);
//            LongCrystalWorkHourDto byTrayNo = crystalWorkHour.get(i);
//
//            if (byTrayNo.getCrystalNo() != null) {
//                row.createCell(0).setCellValue(byTrayNo.getCrystalNo());
//            }
//            if (byTrayNo.getWeight() != null) {
//                row.createCell(1).setCellValue(byTrayNo.getWeight().toString());
//            }
//        }
//        sheet.setDefaultRowHeight((short) (20 * 20));
//        //列宽自适应
//        int num = 30;
//        for (int i = 0; i <= num; i++) {
//            sheet.autoSizeColumn(i);
//        }
//        String fileName = "方棒组托信息导出.xls";
//        //乱码解决
//        String userAgent = request.getHeader("user-agent").toLowerCase();
//        if (userAgent.contains("msie") || userAgent.contains("like gecko")) {
//            // win10 ie edge 浏览器 和其他系统的ie
//            try {
//                fileName = URLEncoder.encode(fileName, "UTF-8");
//            } catch (UnsupportedEncodingException e) {
//                e.printStackTrace();
//            }
//        } else {
//            // fe
//            fileName = new String(fileName.getBytes(StandardCharsets.UTF_8), StandardCharsets.ISO_8859_1);
//        }
//        //输出Excel文件
//        OutputStream output = resp.getOutputStream();
//        resp.reset();
//        resp.setHeader("Content-disposition", "attachment; filename=" + fileName);
//        resp.setContentType("application/msexcel");
//        wb.write(output);
//        output.flush();
//        output.close();
//    }

    public LongCrystalDto toLazyDto(LongCrystal entity) {
        return modelMapper.map(entity, LongCrystalDto.class);
    }

    public LongCrystalDto1 toLazyDto1(LongCrystal entity) {
        return modelMapper.map(entity, LongCrystalDto1.class);
    }

    public LongCrystalDto toEagerDto(LongCrystal entity) {
        LongCrystalDto dto = modelMapper.map(entity, LongCrystalDto.class);
        return dto;
    }

    public LongCrystal fromDto(LongCrystalDto dto) {
        return modelMapper.map(dto, LongCrystal.class);
    }


}
