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

import cn.hutool.core.exceptions.ExceptionUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.sw.mes.base.factory.utils.excel.ExcelUtil;
import com.sw.mes.core.enums.EnumValues;
import com.sw.mes.core.annotation.TokenNotValidation;
import com.sw.mes.core.context.BaseContextHandler;
import com.sw.mes.core.utils.*;
import com.sw.mes.config.YBMesThreadPoolConfiguration;
import com.sw.mes.yb.accessory.dao.EquipmentAccessoryDao;
import com.sw.mes.yb.accessory.dto.*;
import com.sw.mes.yb.accessory.entity.*;
import com.sw.mes.yb.accessory.service.AccessoryApplyService;
import com.sw.mes.yb.accessory.service.AccessoryMaterialService;
import com.sw.mes.yb.accessory.service.AccessoryReturnService;
import com.sw.mes.yb.accessory.service.EquipmentAccessoryService;
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.yb.accessory.validatedData.ValidateOperate;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.modelmapper.ModelMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.domain.Page;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import springfox.documentation.annotations.ApiIgnore;
import springfox.documentation.spring.web.json.Json;

import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.MathContext;
import java.math.RoundingMode;
import java.util.*;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;


/**
* @Author
* @Description：
* @Date: Create in
* @Modified By:
*/
@RestController
@RequestMapping("/equipmentAccessory")
@Slf4j
@Api(description = "热场监控接口")
public class EquipmentAccessoryController {
	@Autowired
    ModelMapper modelMapper;

	@Autowired
	private EquipmentAccessoryService equipmentAccessoryService;

	@Autowired
    private AccessoryMaterialService accessoryMaterialService;

	@Autowired
    @Qualifier(value = "yBMesThreadPoolTaskExecutor")
    private ThreadPoolTaskExecutor ybMesThreadPoolExecutor;

    @ApiOperation(value = "分页查询热场状态列表(热场寿命监控处使用)")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "rows", value = "行数", dataType = "integer", paramType = "query"),
            @ApiImplicitParam(name = "page", value = "页码", dataType = "integer", paramType = "query"),
            @ApiImplicitParam(name = "area", value = "设备区域", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "series", value = "设备系列", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "deviceNo", value = "设备编号", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "mcode", value = "热场编码", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "goodsCode", value = "热场条码", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "startOperateDate", value = "更换开始时间", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "endOperateDate", value = "更换结束时间", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "useTime", value = "已使用寿命", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "factory", value = "厂家", dataType = "string", paramType = "query"),
    })
    @GetMapping("/newListByPage")
    public Result<ResponsePage<EquipmentAccessoryListByPageDto>> newListByPage(EquipmentAccessoryParmDto dto, @ApiIgnore RequestPage requestPage) {
        Page<Map<String, Object>> pageMap = equipmentAccessoryService.newListByPage(dto, PageUtil.createPageable(requestPage,new String[]{"a.threshold ASC", "a.id DESC"}));
        List<EquipmentAccessoryListByPageDto> collect
                = pageMap.getContent().stream().map(item ->  JSON.parseObject(JSON.toJSONString(item), new TypeReference<EquipmentAccessoryListByPageDto>() {})).collect(Collectors.toList());
        ResponsePage<EquipmentAccessoryListByPageDto> page = new ResponsePage<>(collect, pageMap.getTotalElements());
        return ResultGenerator.success(page);
    }

	@ApiOperation(value = "分页查询热场状态列表")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "rows", value = "行数", dataType = "integer", paramType = "query"),
		@ApiImplicitParam(name = "page", value = "页码", dataType = "integer", paramType = "query"),
        @ApiImplicitParam(name = "search_LIKE_equipment.area", value = "设备区域", dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "search_LIKE_equipment.series", value = "设备系列", dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "search_LIKE_equipment.code", value = "设备编号", dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "search_LIKE_material.codes", value = "热场编码", dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "search_LIKE_goodsCode", value = "热场条码", dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "search_GTE_operateDate", value = "更换开始时间", dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "search_LT_operateDate", value = "更换结束时间", dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "search_EQ_useTime", value = "已使用寿命", dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "search_EQ_factory", value = "厂家", dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "search_EQ_bind", value = "绑定状态", dataType = "integer", paramType = "query"),
        @ApiImplicitParam(name = "search_EQ_deleted", value = "绑定状态", dataType = "integer", paramType = "query"),
	})
	@GetMapping("/listByPage")
	public Result<ResponsePage<EquipmentAccessoryDto>> listByPage(ServletRequest request, @ApiIgnore RequestPage requestPage) {
		Specification<EquipmentAccessory> specification = DynamicSpecifications.bySearchFilter(request, EquipmentAccessory.class);
		requestPage.setOrderField("warningDate");
		requestPage.setOrderDirection(RequestPage.ORDER_DIRECTION_ASC);
		Page<EquipmentAccessory> page = equipmentAccessoryService.findByExample(specification, PageUtil.createPageable(requestPage));
    	List<EquipmentAccessoryDto> dtos = page.getContent().stream()
                .map(entity -> {
                    EquipmentAccessoryDto dto = toLazyDto(entity);
//                    validateOperate.validateListByPage(dto, entity);
                    return dto;
                    }
                ).collect(Collectors.toList());
		ResponsePage responsePage = new ResponsePage(dtos, page.getTotalElements());
        return ResultGenerator.success(responsePage);
	}

	@ApiOperation(value = "获取所有热场状态")
	@GetMapping("/listAll")
	public Result<List<EquipmentAccessoryDto>> listAll(ServletRequest request) {
		Specification<EquipmentAccessory> specification = DynamicSpecifications.bySearchFilter(request, EquipmentAccessory.class);
		List<EquipmentAccessory> equipmentAccessorys = equipmentAccessoryService.findByExampleSort(specification, null);
		List<EquipmentAccessoryDto> equipmentAccessoryDtos = equipmentAccessorys.stream()
					.map(equipmentAccessory -> toLazyDto(equipmentAccessory))
					.collect(Collectors.toList());
		return ResultGenerator.success(equipmentAccessoryDtos);
	}

	@ApiOperation(value = "热场状态详细信息")
	@GetMapping("/{id}")
	public Result<EquipmentAccessoryDto> get(@PathVariable @ApiParam(value="热场状态id") Long id) {
		EquipmentAccessory equipmentAccessory = equipmentAccessoryService.get(id);
		if (null == equipmentAccessory) {
            return ResultGenerator.fail("该热场状态不存在");
        }
		return ResultGenerator.success(toEagerDto(equipmentAccessory));
	}

	@ApiOperation(value = "对调")
	@PostMapping("/change") //废弃
	public Result change(@RequestBody @Valid @ApiParam(value = "热场状态对象") EquipAccessChangeDto dto, BindingResult bindingResult) {
		if (bindingResult.hasErrors()) {
			return ResultGenerator.fail(bindingResult.getFieldError().getDefaultMessage());
		}
		if (dto.getId() == null || dto.getDeviceNo() == null) {
			return ResultGenerator.fail("对调信息缺失！");
		}
		try {
			equipmentAccessoryService.change(dto);
		} catch (Exception e) {
		    e.printStackTrace();
			return ResultGenerator.fail(e.getMessage());
		}
		return ResultGenerator.success();
	}

	@ApiOperation(value = "批量对调")
	@PostMapping("/batchChange") //废弃
	public Result batchChange(@RequestBody @Valid @ApiParam(value = "热场状态对象") EquipAccessBatchChangeDto dto, BindingResult bindingResult) {
		if (bindingResult.hasErrors()) {
			return ResultGenerator.fail(bindingResult.getFieldError().getDefaultMessage());
		}
		if (dto.getDeviceNo1() == null && dto.getDeviceNo() == null) {
			return ResultGenerator.fail("对调信息缺失！");
		}
		try {
			equipmentAccessoryService.batchChange(dto);
		} catch (Exception e) {
		    e.printStackTrace();
			return ResultGenerator.fail(e.getMessage());
		}
		return ResultGenerator.success();
	}

    @ApiOperation(value = "批量对调 or 单个对调")
    @PostMapping("/newChange")
    public Result newChange(@RequestBody @Valid @ApiParam(value = "热场状态对象") List<EquipAccessNewChangeDto> dtos, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            return ResultGenerator.fail(bindingResult.getFieldError().getDefaultMessage());
        }
        try {
            equipmentAccessoryService.newChange(dtos);
        } catch (Exception e) {
            e.printStackTrace();
            log.error(ExceptionUtil.stacktraceToString(e));
            return ResultGenerator.fail(e.getMessage());
        }
        return ResultGenerator.success();
    }

	@ApiOperation(value = "根据热场条码获得有效运行寿命")
    @GetMapping("/getUseTimeByCode")
    public Result getUseTimeByCode(String code){
        EquipmentAccessory equipmentAccessory = equipmentAccessoryService.getUseTimeByCode(code);
        if (equipmentAccessory == null){
            throw new RuntimeException("当前热场条码未使用过，请手动填写已使用寿命!");
        }
        EquipmentAccessoryDto equipmentAccessoryDto = toEagerDto(equipmentAccessory);
        return ResultGenerator.success(equipmentAccessoryDto);
    }

	@ApiOperation(value = "新增热场监控")
	@PostMapping("/create")
	public Result create(@RequestBody @Valid @ApiParam(value = "新增热场监控对象") EquipAccessCreateDto dto, BindingResult bindingResult) {
		if (bindingResult.hasErrors()) {
			return ResultGenerator.fail(bindingResult.getFieldError().getDefaultMessage());
		}
		if (dto.getDeviceNo() == null || dto.getGoodsCode() == null) {
			return ResultGenerator.fail("请求信息缺失！");
		}
		try {
			equipmentAccessoryService.saveOrUpdate(dto);
		} catch (Exception e) {
            log.error(ExceptionUtil.stacktraceToString(e));
		    e.printStackTrace();
			return ResultGenerator.fail(e.getMessage());
		}
		return ResultGenerator.success();
	}

//	@ApiOperation(value = "创建热场状态")
//	@PostMapping("/insert")
//	public Result insert(@RequestBody @Valid @ApiParam(value = "热场状态对象") EquipmentAccessoryDto equipmentAccessoryDto, BindingResult bindingResult) {
//		if (bindingResult.hasErrors()) {
//			return ResultGenerator.fail(bindingResult.getFieldError().getDefaultMessage());
//		}
//		if (equipmentAccessoryDto.getUseLife() == null || equipmentAccessoryDto.getUseLife() < 0) {
//			return ResultGenerator.fail("使用周期不合法！");
//		}
//		if (equipmentAccessoryDto.getWarnTime() != null && equipmentAccessoryDto.getUseLife() < equipmentAccessoryDto.getWarnTime()) {
//			return ResultGenerator.fail("使用周期不能小于预警时间！");
//		}
//		try {
//			equipmentAccessoryService.saveOrUpdate(equipmentAccessoryDto);
//		} catch (Exception e) {
//			return ResultGenerator.fail(e.getMessage());
//		}
//		return ResultGenerator.success();
//	}

    @ApiOperation(value = "更换热场监控")
    @PostMapping("/update")
    public Result update(@RequestBody @Valid @ApiParam(value = "热场状态") EquipAccessUpdateDto dto, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            return ResultGenerator.fail(bindingResult.getFieldError().getDefaultMessage());
        }
        if (dto.getId() == null) {
            return ResultGenerator.fail("id不能为空");
        }
            EquipmentAccessory entity = equipmentAccessoryService.get(dto.getId());
        if (entity == null) {
            return ResultGenerator.fail("原信息不存在");
        }
        try {
			equipmentAccessoryService.update(dto);
            return ResultGenerator.success();
        } catch (Exception e) {
            e.printStackTrace();
            log.error(ExceptionUtil.stacktraceToString(e));
            return ResultGenerator.fail(e.getMessage());
        }
    }

    @ApiOperation(value = "编辑热场监控")
    @PostMapping("/editor")
    public Result editor(@RequestBody @Valid @ApiParam(value = "热场状态") EquipAccessEditorDto dto, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            return ResultGenerator.fail(bindingResult.getFieldError().getDefaultMessage());
        }
        if (dto.getId() == null) {
            return ResultGenerator.fail("id不能为空");
        }
        EquipmentAccessory entity = equipmentAccessoryService.get(dto.getId());
        if (entity == null) {
            return ResultGenerator.fail("原信息不存在");
        }
        try {
            BeanUtils.copyProperties(dto, entity, BeanUtil.getIgnoreProperties(dto, null, null));
            equipmentAccessoryService.saveOrUpdate(entity);
            return ResultGenerator.success();
        } catch (Exception e) {
            e.printStackTrace();
            log.error(ExceptionUtil.stacktraceToString(e));
            return ResultGenerator.fail(e.getMessage());
        }
    }

	@ApiOperation(value = "删除热场状态")
	@PostMapping("/delete")
	public Result remove(@ApiParam(value = "id集合,逗号分隔,如2,4", type = "query") @RequestParam Long[] ids) {
		for (Long id : ids) {
            EquipmentAccessory entity = equipmentAccessoryService.get(id);
            if (entity != null){
//                if(entity.getButtonStatus() == 0){
//                    throw new RuntimeException("正在退库要料中，无法变动");
//                }
//                validateOperate.validateInOrOut(entity);
                equipmentAccessoryService.delete(id);
            }

		}
		return ResultGenerator.success();
	}

    @ApiOperation(value = "热场导入")
    @PostMapping("/import")
    public Result importAccessory(MultipartFile file){
        Object objList = EasyExcelUtils.readExcel(file, new ImportAccessory(), 1, 1);
        if (objList != null){
            List<ImportAccessory> importAccessories= (List<ImportAccessory>) objList;

            List<String> repeatList = new ArrayList<>();//用于存放重复的元素的list
            Map<String, Integer> map = new HashMap<>();
            for (ImportAccessory importAccessory : importAccessories) {
                if(map.containsKey(importAccessory.getGoodsCode())){
                    repeatList.add(importAccessory.getGoodsCode());//获取重复的热场条码
                    Integer num = map.get(importAccessory.getGoodsCode());
                    map.put(importAccessory.getGoodsCode(), num+1);
                }else{
                    map.put(importAccessory.getGoodsCode(), 1);
                }
            }
            if (repeatList.size() > 0){
                StringBuilder builder = new StringBuilder();
                for (String repeat : repeatList){
                    builder.append("唯一码：").append(repeat).append("重复,出现了:").append(map.get(repeat)).append("次！");
                }
                throw new RuntimeException(builder.toString());
            }

            StringBuffer failMessage = new StringBuffer();
            AtomicInteger successCount = new AtomicInteger(0);
            AtomicInteger failCount = new AtomicInteger(0);
            List<EquipmentAccessory> synchronizedList = Collections.synchronizedList(new ArrayList<>());
            Integer userId = BaseContextHandler.getUserID();
            String username = BaseContextHandler.getUsername();
            CountDownLatch latch = new CountDownLatch(importAccessories.size());
            for (ImportAccessory importAccessory : importAccessories) {
                ybMesThreadPoolExecutor.execute(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            BaseContextHandler.setUserID(userId);
                            BaseContextHandler.setUsername(username);
                            AccessoryMaterial material = accessoryMaterialService.findByCodes(importAccessory.getMaterialCode().trim());
                            if (material != null){
                                EquipAccessCreateDto dto = new EquipAccessCreateDto();
                                dto.setDeviceNo(importAccessory.getDeviceNo());
                                dto.setMaterialId(material.getId().intValue());
                                dto.setGoodsCode(importAccessory.getGoodsCode());
                                dto.setNum(importAccessory.getNum());
                                dto.setUseTime(importAccessory.getUseTime());
                                dto.setBatchNo(importAccessory.getBatchNo());
                                dto.setAccessoryType(importAccessory.getAccessoryType());
                                dto.setCarbonFelt(importAccessory.getCarbonFelt());
                                dto.setEngraving(importAccessory.getEngraving());
                                dto.setUpdateDate(importAccessory.getUpdateDate());

                                equipmentAccessoryService.collectForExportAndSaveWithAsync(dto,synchronizedList);
                                successCount.getAndAdd(1);
                            }else {
                                failMessage.append("导入失败,辅料编码【 ").append(importAccessory.getMaterialCode()).append(" 】在系统中不存在;");
                                failCount.getAndAdd(1);
                            }
                        } catch (Exception e) {
                            failCount.getAndAdd(1);
                            failMessage.append("设备编号【").append(importAccessory.getDeviceNo()).append("】")
                                    .append("唯一码【").append(importAccessory.getGoodsCode()).append("】")
                                    .append("辅料模型编码【").append(importAccessory.getMaterialCode()).append("】")
                                    .append("导入失败,原因:").append(e.getMessage()).append(";");
                        } finally {
                            latch.countDown();
                            BaseContextHandler.remove();
                        }
                    }
                });
            }
            try {
                latch.await();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            equipmentAccessoryService.saveAll(synchronizedList);
            if (successCount.intValue() > 0) {
                return ResultGenerator.success("共【" + importAccessories.size() + "】条，成功【" + successCount + "】条；"
                        + "失败【" + failCount + "】：" + failMessage);
            } else {
                return ResultGenerator.fail("共【" + importAccessories.size() + "】条，全部失败：" + failMessage);
            }
        }else {
            return ResultGenerator.fail("导入数据为空");
        }
    }

    @ApiOperation(value = "分页查询热场状态列表(热场寿命监控处使用)")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "rows", value = "行数", dataType = "integer", paramType = "query"),
            @ApiImplicitParam(name = "page", value = "页码", dataType = "integer", paramType = "query"),
            @ApiImplicitParam(name = "area", value = "设备区域", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "series", value = "设备系列", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "deviceNo", value = "设备编号", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "mcode", value = "热场编码", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "goodsCode", value = "热场条码", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "startOperateDate", value = "更换开始时间", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "endOperateDate", value = "更换结束时间", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "useTime", value = "已使用寿命", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "factory", value = "厂家", dataType = "string", paramType = "query"),
    })
    @GetMapping("/export")
    public void export(EquipmentAccessoryParmDto dto, @ApiIgnore RequestPage requestPage, HttpServletResponse response){
        try {
            int count = equipmentAccessoryService.countNewListByPage(dto);
            int batch = 4000; //每个批次查多少条
            int number = count / batch + 1; //需要多少批次
            List<RequestPage> requestPages = new ArrayList<>();
            for (int i = 1; i <= number; i++){
                if (i < number){
                    RequestPage page = new RequestPage();
                    page.setPage(i);
                    page.setRows(batch);
                    requestPages.add(page);
                }else {
                    if (count%batch!=0) {
                        RequestPage page = new RequestPage();
                        page.setPage(i);
                        page.setRows(batch);
                        requestPages.add(page);
                    }
                }
            }
            CountDownLatch countDownLatch = new CountDownLatch(requestPages.size());
            List<EquipmentAccessoryExportDto> allLists = Collections.synchronizedList(new ArrayList<>());

            for (RequestPage page : requestPages) {
                ybMesThreadPoolExecutor.execute(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            Page<Map<String, Object>> pageMap = equipmentAccessoryService.newListByPage(dto, PageUtil.createPageable(page,new String[]{"a.threshold ASC", "a.id DESC"}));
                            List<EquipmentAccessoryExportDto> collect
                                    = pageMap.getContent().stream().map(item -> JSON.parseObject(JSON.toJSONString(item), new TypeReference<EquipmentAccessoryExportDto>() {
                            })).collect(Collectors.toList());
                            if (page.getRows() > 0 && page.getRows() < batch) {
                                collect = collect.subList(0, page.getRows());
                            }

                            allLists.addAll(collect);
                        }catch (Exception e){
                            e.printStackTrace();
                        }finally {
                            countDownLatch.countDown();
                        }
                    }
                });
            }
            countDownLatch.await();
            EasyExcelUtils.write(response, EquipmentAccessoryExportDto.class, "热场监控", "热场监控", allLists);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @ApiOperation(value = "热场导入模版下载")
    @PostMapping("/downloadTemplate")
    @TokenNotValidation
    public Result exportUserTemplate(HttpServletResponse response){
        String path = "template/热场监控导入.xlsx";
        ExcelUtil.download1(path, response);
        return ResultGenerator.success();
    }

	public EquipmentAccessoryDto toLazyDto(EquipmentAccessory entity) {
        EquipmentAccessoryDto equipmentAccessoryDto = modelMapper.map(entity, EquipmentAccessoryDto.class);
        if (equipmentAccessoryDto.getMaterialId() != null) {
			AccessoryMaterial accessoryMaterial = accessoryMaterialService.get(equipmentAccessoryDto.getMaterialId());
			if (accessoryMaterial != null) {
				AccessoryMaterialDto materialDto = modelMapper.map(accessoryMaterial, AccessoryMaterialDto.class);
				equipmentAccessoryDto.setMaterialDto(materialDto);
			}
		}
		return equipmentAccessoryDto;
	}

	public EquipmentAccessoryDto toEagerDto(EquipmentAccessory entity) {
		EquipmentAccessoryDto dto = modelMapper.map(entity, EquipmentAccessoryDto.class);
        if (dto.getMaterialId() != null) {
			AccessoryMaterial accessoryMaterial = accessoryMaterialService.get(dto.getMaterialId());
			if (accessoryMaterial != null) {
				AccessoryMaterialDto materialDto = modelMapper.map(accessoryMaterial, AccessoryMaterialDto.class);
				dto.setMaterialDto(materialDto);
			}
		}
		return dto;
	}

	public EquipmentAccessory fromDto(EquipmentAccessoryDto dto) {
		return modelMapper.map(dto, EquipmentAccessory.class);
	}


}
