| | |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.apache.shiro.SecurityUtils; |
| | | import org.jeecg.common.api.vo.Result; |
| | | import org.jeecg.common.constant.CommonConstant; |
| | | import org.jeecg.common.system.base.controller.JeecgController; |
| | | 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; |
| | |
| | | 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; |
| | |
| | | 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; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * @Description: 设备台账 |
| | |
| | | private ObjectMapper objectMapper; |
| | | @Autowired |
| | | private TranslateDictTextUtils translateDictTextUtils; |
| | | |
| | | @Autowired |
| | | private IBaseFactoryService baseFactoryService; |
| | | @Autowired |
| | | private IEamBaseRepairDepartService eamBaseRepairDepartService; |
| | | /** |
| | | * 分页列表查询 |
| | | * |
| | |
| | | return Result.OK("添加失败!"); |
| | | } |
| | | //调用mdcEquipment插入MDC设备 |
| | | if (CommonConstant.DEFAULT_1.equals(eamEquipment.getMdcFlag())) { |
| | | // if (CommonConstant.DEFAULT_1.equals(eamEquipment.getMdcFlag())) { |
| | | //插入MDC设备 |
| | | // MdcEquipment mdcEquipment = new MdcEquipment(); |
| | | // mdcEquipment.setEquipmentId(entity.getEquipmentCode()); |
| | | // mdcEquipment.setEquipmentType(entity.getDeviceType()); |
| | | // mdcEquipment.setEquipmentName(entity.getEquipmentName()); |
| | | // mdcEquipmentService.addNewEquipmentFromEam(mdcEquipment, eamEquipment.getOrgId()); |
| | | } |
| | | // } |
| | | return Result.OK("添加成功!"); |
| | | } |
| | | |
| | |
| | | @ApiOperation(value = "设备台账-编辑", notes = "设备台账-编辑") |
| | | @RequestMapping(value = "/edit", method = {RequestMethod.PUT, RequestMethod.POST}) |
| | | public Result<?> edit(@RequestBody EamEquipment eamEquipment) { |
| | | eamEquipmentService.updateById(eamEquipment); |
| | | eamEquipmentService.updateEquipment(eamEquipment); |
| | | return Result.OK("编辑成功!"); |
| | | } |
| | | |
| | |
| | | JSONObject item = JSONObject.parseObject(json, Feature.OrderedField); |
| | | translateDictTextUtils.translateField("createBy", eamEquipment.getCreateBy(), item, "sys_user,realname,username"); |
| | | translateDictTextUtils.translateField("updateBy", eamEquipment.getUpdateBy(), item, "sys_user,realname,username"); |
| | | translateDictTextUtils.translateField("technologyStatus", eamEquipment.getTechnologyStatus(), item, "technology_status"); |
| | | translateDictTextUtils.translateField("orgId", eamEquipment.getOrgId(), item, "mdc_production,production_name,id"); |
| | | translateDictTextUtils.translateField("equipmentManager", eamEquipment.getEquipmentManager(), item, "sys_user,realname,username"); |
| | | // translateDictTextUtils.translateField("technologyStatus", eamEquipment.getTechnologyStatus(), item, "technology_status"); |
| | | // translateDictTextUtils.translateField("orgId", eamEquipment.getOrgId(), item, "mdc_production,production_name,id"); |
| | | // translateDictTextUtils.translateField("equipmentManager", eamEquipment.getEquipmentManager(), item, "sys_user,realname,username"); |
| | | translateDictTextUtils.translateField("equipmentCategory", eamEquipment.getEquipmentCategory(), item, "equipment_category"); |
| | | translateDictTextUtils.translateField("assetStatus", eamEquipment.getAssetStatus(), item, "asset_status"); |
| | | translateDictTextUtils.translateField("repairStatus", eamEquipment.getRepairStatus(), item, "equipment_repair_status"); |
| | |
| | | |
| | | /** |
| | | * 导出excel |
| | | * |
| | | * @param request |
| | | * @param eamEquipment |
| | | */ |
| | | @RequestMapping(value = "/exportXls") |
| | | public ModelAndView exportXls(HttpServletRequest request, EamEquipment eamEquipment) { |
| | | return super.exportXls(request, eamEquipment, EamEquipment.class, "设备台账"); |
| | | 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, EamEquipmentDto.class); |
| | | mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("设备台账" + "报表", "导出人:" + sysUser.getRealname(), "设备台账")); |
| | | mv.addObject(NormalExcelConstants.DATA_LIST, eamEquipmentDtos); |
| | | return mv; |
| | | |
| | | } |
| | | |
| | | /** |
| | |
| | | // 获取上传文件对象 |
| | | MultipartFile file = entity.getValue(); |
| | | ImportParams params = new ImportParams(); |
| | | params.setTitleRows(0); |
| | | params.setTitleRows(2); |
| | | params.setHeadRows(1); |
| | | params.setNeedSave(true); |
| | | params.setStartSheetIndex(0); |
| | |
| | | sb.append(String.format("设备编码[%s]设备分类为空,无法导入\n\n", eamEquipment.getEquipmentCode())); |
| | | continue; |
| | | } |
| | | if (StringUtils.isBlank(eamEquipment.getOrgId()) || StringUtils.isBlank(eamEquipment.getEquipmentManager())) { |
| | | sb.append(String.format("设备编码[%s]使用车间或设备管理员为空,无法导入\n\n", eamEquipment.getEquipmentCode())); |
| | | continue; |
| | | } |
| | | // if (eamEquipment.getAcceptanceCheckDate() == null) { |
| | | // sb.append(String.format("设备编码[%s]验收为空,无法导入\n\r", eamEquipment.getEquipmentCode())); |
| | | // continue; |
| | | // } |
| | | // if (StringUtils.isBlank(eamEquipment.getTechnologyStatus())) { |
| | | // sb.append(String.format("设备编码[%s]技术状态为空,无法导入\n\r", eamEquipment.getEquipmentCode())); |
| | | // continue; |
| | | // } |
| | | EamEquipment one = eamEquipmentService.getOne(new LambdaQueryWrapper<EamEquipment>().eq(EamEquipment::getEquipmentCode, eamEquipment.getEquipmentCode()).eq(EamEquipment::getDelFlag, CommonConstant.DEL_FLAG_0)); |
| | | if (one != null) { |
| | | sb.append(String.format("设备编码[%s]已存在,无法重复导入\n\r", eamEquipment.getEquipmentCode())); |
| | | continue; |
| | | } |
| | | if (!CommonConstant.DEFAULT_1.equals(eamEquipment.getMdcFlag())) { |
| | | eamEquipment.setMdcFlag(CommonConstant.DEFAULT_0); |
| | | 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; |
| | | } |
| | | //调用mdcEquipment插入MDC设备 |
| | | if (CommonConstant.DEFAULT_1.equals(eamEquipment.getMdcFlag())) { |
| | | //插入MDC设备 |
| | | // MdcEquipment mdcEquipment = new MdcEquipment(); |
| | | // mdcEquipment.setEquipmentId(eamEquipment.getEquipmentCode()); |
| | | // mdcEquipment.setEquipmentType(eamEquipment.getDeviceType()); |
| | | // mdcEquipment.setEquipmentName(eamEquipment.getEquipmentName()); |
| | | // mdcEquipmentService.addNewEquipmentFromEam(mdcEquipment, eamEquipment.getOrgId()); |
| | | } |
| | | EamEquipmentExtend eamEquipmentExtend=new EamEquipmentExtend(); |
| | | BeanUtils.copyProperties(eamEquipmentExtend,equipment); |
| | | eamEquipmentExtendService.save(eamEquipmentExtend); |
| | | } |
| | | //400条 saveBatch消耗时间1592毫秒 循环插入消耗时间1947毫秒 |
| | | //1200条 saveBatch消耗时间3687毫秒 循环插入消耗时间5212毫秒 |
| | | log.info("消耗时间" + (System.currentTimeMillis() - start) + "毫秒"); |
| | | //update-end-author:taoyan date:20190528 for:批量插入数据 |
| | | if (sb.length() > 0) { |
| | |
| | | return result; |
| | | } |
| | | |
| | | @ApiOperation(value = "设备表-通过EAM中心ids获取设备树", notes = "设备表-通过EAM中心ids获取设备树") |
| | | @GetMapping(value = "/loadTreeListByEamCenterIds") |
| | | public Result<List<EamEquipmentTree>> loadTreeListByEamCenterIds(@RequestParam(name = "ids", required = true) String ids) { |
| | | Result<List<EamEquipmentTree>> result = new Result<>(); |
| | | try { |
| | | List<EamEquipmentTree> mdcEquipmentTreeList = eamEquipmentService.loadTreeListByEamCenterIds(ids); |
| | | result.setSuccess(true); |
| | | result.setResult(mdcEquipmentTreeList); |
| | | } catch (Exception e) { |
| | | log.error(e.getMessage(), e); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * 检索设备 |
| | | * @param keyword 查询关键词 设备编号,设备名称模糊匹配 |
| | |
| | | @GetMapping(value = "/asyncLoadEquipment") |
| | | public Result<?> asyncLoadEquipment(@RequestParam(name="keyword",required = false) String keyword, |
| | | @RequestParam(value = "pageSize", required = false, defaultValue = "20") Integer pageSize, |
| | | @RequestParam(name="id",required = false) String id) { |
| | | List<EquipmentSearchResult> resultList = eamEquipmentService.asyncLoadEquipment(keyword, pageSize, id); |
| | | return Result.ok(resultList); |
| | | @RequestParam(name="id",required = false) String id, |
| | | @RequestParam(name="factoryOrgCode",required = false) String factoryOrgCode) { |
| | | List<EquipmentSearchResult> resultList = eamEquipmentService.asyncLoadEquipment(keyword, pageSize, id, factoryOrgCode); |
| | | List<JSONObject> items = new ArrayList<>(); |
| | | try { |
| | | for(EquipmentSearchResult vo : resultList) { |
| | | String json = objectMapper.writeValueAsString(vo); |
| | | JSONObject item = JSONObject.parseObject(json, Feature.OrderedField); |
| | | translateDictTextUtils.translateField("factoryOrgCode", vo.getFactoryOrgCode(), item, "eam_base_factory,factory_name,org_code"); |
| | | items.add(item); |
| | | } |
| | | return Result.OK(items); |
| | | }catch (Exception e) { |
| | | return Result.error("数据转译失败!"); |
| | | } |
| | | } |
| | | |
| | | } |