Lius
8 天以前 0a19d4923b0a048aee0cda91c37f25bc6e140d54
lxzn-module-eam/src/main/java/org/jeecg/modules/eam/controller/EamEquipmentController.java
@@ -18,6 +18,7 @@
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.util.TranslateDictTextUtils;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.eam.dto.EamEquipmentDto;
import org.jeecg.modules.eam.entity.EamEquipment;
import org.jeecg.modules.eam.entity.EamEquipmentExtend;
import org.jeecg.modules.eam.request.EamEquipmentQuery;
@@ -25,13 +26,16 @@
import org.jeecg.modules.eam.service.IEamEquipmentService;
import org.jeecg.modules.eam.vo.EamEquipmentTree;
import org.jeecg.modules.eam.vo.EquipmentSearchResult;
//import org.jeecg.modules.mdc.entity.MdcEquipment;
//import org.jeecg.modules.mdc.service.IMdcEquipmentService;
import org.jeecg.modules.system.entity.BaseFactory;
import org.jeecg.modules.system.entity.EamBaseRepairDepart;
import org.jeecg.modules.system.service.IBaseFactoryService;
import org.jeecg.modules.system.service.IEamBaseRepairDepartService;
import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
@@ -41,6 +45,7 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
@@ -70,7 +75,10 @@
    private ObjectMapper objectMapper;
    @Autowired
    private TranslateDictTextUtils translateDictTextUtils;
    @Autowired
    private IBaseFactoryService baseFactoryService;
    @Autowired
    private IEamBaseRepairDepartService eamBaseRepairDepartService;
    /**
     * 分页列表查询
     *
@@ -211,18 +219,36 @@
    public ModelAndView exportXls(HttpServletRequest request,EamEquipmentQuery eamEquipment) {
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        List<EamEquipment> equipmentList=eamEquipmentService.exportList(eamEquipment);
        List<EamEquipmentDto> eamEquipmentDtos=new ArrayList<>();
        String selections = request.getParameter("selections");
        if (oConvertUtils.isNotEmpty(selections)) {
            List<String> selectionList = Arrays.asList(selections.split(","));
            equipmentList = equipmentList.stream().filter(item -> selectionList.contains(item.getId())).collect(Collectors.toList());
        }
        equipmentList.forEach(item -> {
            EamEquipmentDto eamEquipmentDto = new EamEquipmentDto();
            BeanUtils.copyProperties(item,eamEquipmentDto);
            if (eamEquipmentDto.getFactoryOrgCode().length()==12){
                eamEquipmentDto.setFactoryOrgCode(
                        baseFactoryService.factoryDataNameByOrgCode(eamEquipmentDto.getZxfactoryOrgCode())
                        +"/"+baseFactoryService.factoryDataNameByOrgCode(eamEquipmentDto.getGqfactoryOrgCode())+"/"+
                                baseFactoryService.factoryDataNameByOrgCode(eamEquipmentDto.getFactoryOrgCode()));
            }else {
                eamEquipmentDto.setFactoryOrgCode(
                        baseFactoryService.factoryDataNameByOrgCode(eamEquipmentDto.getZxfactoryOrgCode())
                                +"/"+ baseFactoryService.factoryDataNameByOrgCode(eamEquipmentDto.getFactoryOrgCode()));
            }
            if (eamEquipmentDto.getEquipmentWeight()!=null){
                eamEquipmentDto.setEquipmentWeightStr(eamEquipmentDto.getEquipmentWeight().toEngineeringString());
            }
            eamEquipmentDtos.add(eamEquipmentDto);
        });
        // Step.3 AutoPoi 导出Excel
        ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
        mv.addObject(NormalExcelConstants.FILE_NAME, "设备台账"); //此处设置的filename无效 ,前端会重更新设置一下
        mv.addObject(NormalExcelConstants.CLASS, EamEquipment.class);
        mv.addObject(NormalExcelConstants.CLASS, EamEquipmentDto.class);
        mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("设备台账" + "报表", "导出人:" + sysUser.getRealname(), "设备台账"));
        mv.addObject(NormalExcelConstants.DATA_LIST, equipmentList);
        mv.addObject(NormalExcelConstants.DATA_LIST, eamEquipmentDtos);
        return mv;
    }
@@ -268,12 +294,29 @@
                        sb.append(String.format("设备编码[%s]已存在,无法重复导入\n\r", eamEquipment.getEquipmentCode()));
                        continue;
                    }
                    BaseFactory baseFactory=baseFactoryService.searchCenterByKeyWord(eamEquipment.getFactoryOrgCode());
                    if(baseFactory==null){
                        sb.append(String.format("EAM中心信息[%s]不存在,无法导入\n\r", eamEquipment.getFactoryOrgCode()));
                        continue;
                    }else {
                        eamEquipment.setFactoryOrgCode(baseFactory.getOrgCode());
                    }
                    EamBaseRepairDepart eamBaseRepairDepart=eamBaseRepairDepartService.searchCenterByKeyWord(eamEquipment.getRepairDepartOrgCode());
                    if(eamBaseRepairDepart==null){
                        sb.append(String.format("维修班组信息[%s]不存在,无法导入\n\r", eamEquipment.getRepairDepartOrgCode()));
                        continue;
                    }else {
                        eamEquipment.setRepairDepartOrgCode(eamBaseRepairDepart.getOrgCode());
                    }
                    EamEquipment equipment = eamEquipmentService.saveEquipment(eamEquipment);
                    if (equipment == null) {
                        //保存失败,跳过本次循环
                        sb.append(String.format("设备编码[%s]保存失败,无法导入\n\r", eamEquipment.getEquipmentCode()));
                        continue;
                    }
                    EamEquipmentExtend eamEquipmentExtend=new EamEquipmentExtend();
                    BeanUtils.copyProperties(eamEquipmentExtend,equipment);
                    eamEquipmentExtendService.save(eamEquipmentExtend);
                }
                log.info("消耗时间" + (System.currentTimeMillis() - start) + "毫秒");
                //update-end-author:taoyan date:20190528 for:批量插入数据