MesDeviceOeeService.java 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. package com.jeesite.modules.mes.service;
  2. import com.jeesite.common.config.Global;
  3. import com.jeesite.common.entity.Page;
  4. import com.jeesite.common.service.CrudService;
  5. import com.jeesite.common.service.ServiceException;
  6. import com.jeesite.common.utils.excel.ExcelImport;
  7. import com.jeesite.common.validator.ValidatorUtils;
  8. import com.jeesite.modules.mes.dao.MesDeviceOeeDao;
  9. import com.jeesite.modules.mes.entity.MesDeviceOee;
  10. import org.springframework.beans.factory.annotation.Autowired;
  11. import org.springframework.stereotype.Service;
  12. import org.springframework.transaction.annotation.Transactional;
  13. import org.springframework.web.multipart.MultipartFile;
  14. import javax.validation.ConstraintViolation;
  15. import javax.validation.ConstraintViolationException;
  16. import java.util.List;
  17. /**
  18. * OEEService
  19. * @author mes
  20. * @version 2024-08-02
  21. */
  22. @Service
  23. public class MesDeviceOeeService extends CrudService<MesDeviceOeeDao, MesDeviceOee> {
  24. @Autowired
  25. private MesDeviceOeeDao mesDeviceOeeDao;
  26. /**
  27. * 获取单条数据
  28. * @param mesDeviceOee
  29. * @return
  30. */
  31. @Override
  32. public MesDeviceOee get(MesDeviceOee mesDeviceOee) {
  33. return super.get(mesDeviceOee);
  34. }
  35. /**
  36. * 查询分页数据
  37. * @param mesDeviceOee 查询条件
  38. * @param mesDeviceOee.page 分页对象
  39. * @return
  40. */
  41. @Override
  42. public Page<MesDeviceOee> findPage(MesDeviceOee mesDeviceOee) {
  43. return super.findPage(mesDeviceOee);
  44. }
  45. /**
  46. * 查询列表数据
  47. * @param mesDeviceOee
  48. * @return
  49. */
  50. @Override
  51. public List<MesDeviceOee> findList(MesDeviceOee mesDeviceOee) {
  52. return super.findList(mesDeviceOee);
  53. }
  54. /**
  55. * 保存数据(插入或更新)
  56. * @param mesDeviceOee
  57. */
  58. @Override
  59. @Transactional
  60. public void save(MesDeviceOee mesDeviceOee) {
  61. super.save(mesDeviceOee);
  62. }
  63. /**
  64. * 导入数据
  65. * @param file 导入的数据文件
  66. */
  67. @Transactional
  68. public String importData(MultipartFile file) {
  69. if (file == null){
  70. throw new ServiceException(text("请选择导入的数据文件!"));
  71. }
  72. int successNum = 0; int failureNum = 0;
  73. StringBuilder successMsg = new StringBuilder();
  74. StringBuilder failureMsg = new StringBuilder();
  75. try(ExcelImport ei = new ExcelImport(file, 2, 0)){
  76. List<MesDeviceOee> list = ei.getDataList(MesDeviceOee.class);
  77. for (MesDeviceOee mesDeviceOee : list) {
  78. try{
  79. ValidatorUtils.validateWithException(mesDeviceOee);
  80. this.save(mesDeviceOee);
  81. successNum++;
  82. successMsg.append("<br/>" + successNum + "、编号 " + mesDeviceOee.getId() + " 导入成功");
  83. } catch (Exception e) {
  84. failureNum++;
  85. String msg = "<br/>" + failureNum + "、编号 " + mesDeviceOee.getId() + " 导入失败:";
  86. if (e instanceof ConstraintViolationException){
  87. ConstraintViolationException cve = (ConstraintViolationException)e;
  88. for (ConstraintViolation<?> violation : cve.getConstraintViolations()) {
  89. msg += Global.getText(violation.getMessage()) + " ("+violation.getPropertyPath()+")";
  90. }
  91. }else{
  92. msg += e.getMessage();
  93. }
  94. failureMsg.append(msg);
  95. logger.error(msg, e);
  96. }
  97. }
  98. } catch (Exception e) {
  99. logger.error(e.getMessage(), e);
  100. failureMsg.append(e.getMessage());
  101. return failureMsg.toString();
  102. }
  103. if (failureNum > 0) {
  104. failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:");
  105. throw new ServiceException(failureMsg.toString());
  106. }else{
  107. successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条,数据如下:");
  108. }
  109. return successMsg.toString();
  110. }
  111. /**
  112. * 更新状态
  113. * @param mesDeviceOee
  114. */
  115. @Override
  116. @Transactional
  117. public void updateStatus(MesDeviceOee mesDeviceOee) {
  118. super.updateStatus(mesDeviceOee);
  119. }
  120. /**
  121. * 删除数据
  122. * @param mesDeviceOee
  123. */
  124. @Override
  125. @Transactional
  126. public void delete(MesDeviceOee mesDeviceOee) {
  127. super.delete(mesDeviceOee);
  128. }
  129. /**
  130. * 根据故障工序名称和日期查询
  131. * @param mesDeviceOee
  132. */
  133. @Transactional
  134. public MesDeviceOee findByDateAndtitle(MesDeviceOee mesDeviceOee) {
  135. return mesDeviceOeeDao.findByDateAndtitle(mesDeviceOee);
  136. }
  137. }