¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.jeecg.modules.eam.controller; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.alibaba.fastjson.parser.Feature; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.fasterxml.jackson.core.JsonProcessingException; |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import io.swagger.annotations.Api; |
| | | 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.entity.EamEquipment; |
| | | import org.jeecg.modules.eam.entity.EamEquipmentExtend; |
| | | import org.jeecg.modules.eam.request.EamEquipmentQuery; |
| | | import org.jeecg.modules.eam.service.IEamEquipmentExtendService; |
| | | 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.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.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | import org.springframework.web.multipart.MultipartHttpServletRequest; |
| | | import org.springframework.web.servlet.ModelAndView; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * @Description: 设å¤å°è´¦ |
| | | * @Author: jeecg-boot |
| | | * @Date: 2025-03-19 |
| | | * @Version: V1.0 |
| | | */ |
| | | @Slf4j |
| | | @Api(tags = "设å¤å°è´¦") |
| | | @RestController |
| | | @RequestMapping("/eam/equipment") |
| | | public class EamEquipmentController extends JeecgController<EamEquipment, IEamEquipmentService> { |
| | | @Autowired |
| | | private IEamEquipmentService eamEquipmentService; |
| | | |
| | | @Autowired |
| | | private IEamEquipmentExtendService eamEquipmentExtendService; |
| | | |
| | | // @Autowired |
| | | // private IMdcEquipmentService mdcEquipmentService; |
| | | |
| | | @Autowired |
| | | private ObjectMapper objectMapper; |
| | | @Autowired |
| | | private TranslateDictTextUtils translateDictTextUtils; |
| | | |
| | | /** |
| | | * å页å表æ¥è¯¢ |
| | | * |
| | | * @param eamEquipment |
| | | * @param pageNo |
| | | * @param pageSize |
| | | * @return |
| | | */ |
| | | // @AutoLog(value = "设å¤å°è´¦-å页å表æ¥è¯¢") |
| | | @ApiOperation(value = "设å¤å°è´¦-å页å表æ¥è¯¢", notes = "设å¤å°è´¦-å页å表æ¥è¯¢") |
| | | @GetMapping(value = "/list") |
| | | public Result<?> queryPageList(EamEquipmentQuery eamEquipment, |
| | | @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, |
| | | @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) { |
| | | // QueryWrapper<EamEquipment> queryWrapper = QueryGenerator.initQueryWrapper(eamEquipment, req.getParameterMap()); |
| | | IPage<EamEquipment> page = new Page<>(pageNo, pageSize); |
| | | IPage<EamEquipment> pageList = eamEquipmentService.queryPageList(page, eamEquipment); |
| | | return Result.OK(pageList); |
| | | } |
| | | |
| | | /** |
| | | * æ·»å |
| | | * |
| | | * @param eamEquipment |
| | | * @return |
| | | */ |
| | | // @AutoLog(value = "设å¤å°è´¦-æ·»å ") |
| | | @ApiOperation(value = "设å¤å°è´¦-æ·»å ", notes = "设å¤å°è´¦-æ·»å ") |
| | | @PostMapping(value = "/add") |
| | | public Result<?> add(@RequestBody EamEquipment eamEquipment) { |
| | | EamEquipment entity = eamEquipmentService.saveEquipment(eamEquipment); |
| | | if (entity == null) { |
| | | return Result.OK("æ·»å 失败ï¼"); |
| | | } |
| | | //è°ç¨mdcEquipmentæå
¥MDCè®¾å¤ |
| | | // 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("æ·»å æåï¼"); |
| | | } |
| | | |
| | | /** |
| | | * ç¼è¾ |
| | | * |
| | | * @param eamEquipment |
| | | * @return |
| | | */ |
| | | @ApiOperation(value = "设å¤å°è´¦-ç¼è¾", notes = "设å¤å°è´¦-ç¼è¾") |
| | | @RequestMapping(value = "/edit", method = {RequestMethod.PUT, RequestMethod.POST}) |
| | | public Result<?> edit(@RequestBody EamEquipment eamEquipment) { |
| | | eamEquipmentService.updateEquipment(eamEquipment); |
| | | return Result.OK("ç¼è¾æå!"); |
| | | } |
| | | |
| | | /** |
| | | * éè¿idå é¤ |
| | | * |
| | | * @param id |
| | | * @return |
| | | */ |
| | | @ApiOperation(value = "设å¤å°è´¦-éè¿idå é¤", notes = "设å¤å°è´¦-éè¿idå é¤") |
| | | @DeleteMapping(value = "/delete") |
| | | public Result<?> delete(@RequestParam(name = "id", required = true) String id) { |
| | | EamEquipment entity = eamEquipmentService.getById(id); |
| | | if (entity != null) { |
| | | entity.setDelFlag(CommonConstant.DEL_FLAG_1); |
| | | eamEquipmentService.updateById(entity); |
| | | } |
| | | return Result.OK("å 餿å!"); |
| | | } |
| | | |
| | | /** |
| | | * æ¹éå é¤ |
| | | * |
| | | * @param ids |
| | | * @return |
| | | */ |
| | | @ApiOperation(value = "设å¤å°è´¦-æ¹éå é¤", notes = "设å¤å°è´¦-æ¹éå é¤") |
| | | @DeleteMapping(value = "/deleteBatch") |
| | | public Result<?> deleteBatch(@RequestParam(name = "ids", required = true) String ids) { |
| | | List<String> list = Arrays.asList(ids.split(",")); |
| | | list.forEach(id -> { |
| | | EamEquipment entity = eamEquipmentService.getById(id); |
| | | if (entity != null) { |
| | | entity.setDelFlag(CommonConstant.DEL_FLAG_1); |
| | | eamEquipmentService.updateById(entity); |
| | | } |
| | | }); |
| | | return Result.OK("æ¹éå 餿åï¼"); |
| | | } |
| | | |
| | | /** |
| | | * éè¿idæ¥è¯¢ |
| | | * |
| | | * @param id |
| | | * @return |
| | | */ |
| | | @ApiOperation(value = "设å¤å°è´¦-éè¿idæ¥è¯¢", notes = "设å¤å°è´¦-éè¿idæ¥è¯¢") |
| | | @GetMapping(value = "/queryById") |
| | | public Result<?> queryById(@RequestParam(name = "id", required = true) String id) { |
| | | EamEquipment eamEquipment = eamEquipmentService.getById(id); |
| | | if (eamEquipment == null) { |
| | | return Result.error("æªæ¾å°å¯¹åºæ°æ®"); |
| | | } |
| | | EamEquipmentExtend extend = eamEquipmentExtendService.getById(id); |
| | | if(extend != null){ |
| | | eamEquipment.setRepairStatus(extend.getRepairStatus()); |
| | | eamEquipment.setMaintenanceStatus(extend.getMaintenanceStatus()); |
| | | } |
| | | try { |
| | | String json = objectMapper.writeValueAsString(eamEquipment); |
| | | 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("equipmentCategory", eamEquipment.getEquipmentCategory(), item, "equipment_category"); |
| | | translateDictTextUtils.translateField("assetStatus", eamEquipment.getAssetStatus(), item, "asset_status"); |
| | | translateDictTextUtils.translateField("repairStatus", eamEquipment.getRepairStatus(), item, "equipment_repair_status"); |
| | | translateDictTextUtils.translateField("maintenanceStatus", eamEquipment.getMaintenanceStatus(), item, "equipment_maintenance_status"); |
| | | return Result.OK(item); |
| | | } catch (JsonProcessingException e) { |
| | | return Result.error("æ°æ®è½¬è¯å¤±è´¥ï¼"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 导åºexcel |
| | | * @param eamEquipment |
| | | */ |
| | | @RequestMapping(value = "/exportXls") |
| | | public ModelAndView exportXls(HttpServletRequest request,EamEquipmentQuery eamEquipment) { |
| | | LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); |
| | | List<EamEquipment> equipmentList=eamEquipmentService.exportList(eamEquipment); |
| | | 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()); |
| | | } |
| | | |
| | | // 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.PARAMS, new ExportParams("设å¤å°è´¦" + "æ¥è¡¨", "导åºäºº:" + sysUser.getRealname(), "设å¤å°è´¦")); |
| | | mv.addObject(NormalExcelConstants.DATA_LIST, equipmentList); |
| | | return mv; |
| | | |
| | | } |
| | | |
| | | /** |
| | | * éè¿excel导å
¥æ°æ® |
| | | * |
| | | * @param request |
| | | * @param response |
| | | * @return |
| | | */ |
| | | @RequestMapping(value = "/importExcel", method = RequestMethod.POST) |
| | | public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) { |
| | | MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; |
| | | Map<String, MultipartFile> fileMap = multipartRequest.getFileMap(); |
| | | for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) { |
| | | // è·åä¸ä¼ æä»¶å¯¹è±¡ |
| | | MultipartFile file = entity.getValue(); |
| | | ImportParams params = new ImportParams(); |
| | | params.setTitleRows(2); |
| | | params.setHeadRows(1); |
| | | params.setNeedSave(true); |
| | | params.setStartSheetIndex(0); |
| | | params.setSheetNum(1); |
| | | try { |
| | | List<EamEquipment> list = ExcelImportUtil.importExcel(file.getInputStream(), EamEquipment.class, params); |
| | | //update-begin-author:taoyan date:20190528 for:æ¹éæå
¥æ°æ® |
| | | long start = System.currentTimeMillis(); |
| | | // service.saveBatch(list); |
| | | StringBuilder sb = new StringBuilder(); |
| | | for (EamEquipment eamEquipment : list) { |
| | | //å¿
å¡«åæ®µæ ¡éª |
| | | if (StringUtils.isBlank(eamEquipment.getEquipmentCode()) || StringUtils.isBlank(eamEquipment.getEquipmentName())) { |
| | | sb.append(String.format("设å¤ç¼ç [%s]æè®¾å¤åç§°[%s]ä¸ºç©ºï¼æ æ³å¯¼å
¥\n\n", eamEquipment.getEquipmentCode(), eamEquipment.getEquipmentName())); |
| | | continue; |
| | | } |
| | | if (StringUtils.isBlank(eamEquipment.getEquipmentCategory())) { |
| | | sb.append(String.format("设å¤ç¼ç [%s]设å¤åç±»ä¸ºç©ºï¼æ æ³å¯¼å
¥\n\n", 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; |
| | | } |
| | | EamEquipment equipment = eamEquipmentService.saveEquipment(eamEquipment); |
| | | if (equipment == null) { |
| | | //ä¿å失败ï¼è·³è¿æ¬æ¬¡å¾ªç¯ |
| | | sb.append(String.format("设å¤ç¼ç [%s]ä¿åå¤±è´¥ï¼æ æ³å¯¼å
¥\n\r", eamEquipment.getEquipmentCode())); |
| | | continue; |
| | | } |
| | | } |
| | | log.info("æ¶èæ¶é´" + (System.currentTimeMillis() - start) + "毫ç§"); |
| | | //update-end-author:taoyan date:20190528 for:æ¹éæå
¥æ°æ® |
| | | if (sb.length() > 0) { |
| | | return Result.ok(sb.toString()); |
| | | } |
| | | return Result.ok("æä»¶å¯¼å
¥æåï¼æ°æ®è¡æ°ï¼" + list.size()); |
| | | } catch (Exception e) { |
| | | //update-begin-author:taoyan date:20211124 for: 导å
¥æ°æ®éå¤å¢å æç¤º |
| | | String msg = e.getMessage(); |
| | | log.error(msg, e); |
| | | if (msg != null && msg.indexOf("Duplicate entry") >= 0) { |
| | | return Result.error("æä»¶å¯¼å
¥å¤±è´¥:æé夿°æ®ï¼"); |
| | | } else { |
| | | return Result.error("æä»¶å¯¼å
¥å¤±è´¥:" + e.getMessage()); |
| | | } |
| | | //update-end-author:taoyan date:20211124 for: 导å
¥æ°æ®éå¤å¢å æç¤º |
| | | } finally { |
| | | try { |
| | | file.getInputStream().close(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | return Result.error("æä»¶å¯¼å
¥å¤±è´¥ï¼"); |
| | | } |
| | | |
| | | @ApiOperation(value = "设å¤è¡¨-éè¿è½¦é´idsè·åè®¾å¤æ ", notes = "设å¤è¡¨-éè¿è½¦é´idsè·åè®¾å¤æ ") |
| | | @GetMapping(value = "/loadTreeListByProductionIds") |
| | | public Result<List<EamEquipmentTree>> loadTreeListByProductionIds(@RequestParam(name = "ids", required = true) String ids) { |
| | | Result<List<EamEquipmentTree>> result = new Result<>(); |
| | | try { |
| | | List<EamEquipmentTree> mdcEquipmentTreeList = eamEquipmentService.loadTreeListByProductionIds(ids); |
| | | result.setSuccess(true); |
| | | result.setResult(mdcEquipmentTreeList); |
| | | } catch (Exception e) { |
| | | log.error(e.getMessage(), e); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * æ£ç´¢è®¾å¤ |
| | | * @param keyword æ¥è¯¢å
³é®è¯ 设å¤ç¼å·ï¼è®¾å¤å称模ç³å¹é
|
| | | * @param pageSize 䏿¬¡è¿åå¤å°è®°å½ |
| | | * @param id 设å¤ä¸»é® |
| | | * @return |
| | | */ |
| | | @ApiOperation(value = "设å¤è¡¨-弿¥å 载设å¤å表", notes = "设å¤è¡¨-弿¥å 载设å¤å表") |
| | | @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); |
| | | } |
| | | |
| | | } |