ContractTableServiceImpl.java 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. package com.ruoyi.system.service.impl;
  2. import java.util.List;
  3. import com.ruoyi.common.exception.ServiceException;
  4. import com.ruoyi.common.utils.StringUtils;
  5. import com.ruoyi.common.utils.bean.BeanValidators;
  6. import org.springframework.beans.factory.annotation.Autowired;
  7. import org.springframework.stereotype.Service;
  8. import com.ruoyi.system.mapper.ContractTableMapper;
  9. import com.ruoyi.system.domain.ContractTable;
  10. import com.ruoyi.system.service.IContractTableService;
  11. import javax.validation.Validator;
  12. /**
  13. * B类Service业务层处理
  14. *
  15. * @author ruoyi
  16. * @date 2022-11-25
  17. */
  18. @Service
  19. public class ContractTableServiceImpl implements IContractTableService
  20. {
  21. @Autowired
  22. private ContractTableMapper contractTableMapper;
  23. @Autowired
  24. protected Validator validator;
  25. /**
  26. * 查询B类
  27. *
  28. * @param id B类主键
  29. * @return B类
  30. */
  31. @Override
  32. public ContractTable selectContractTableById(Long id)
  33. {
  34. return contractTableMapper.selectContractTableById(id);
  35. }
  36. /**
  37. * 查询B类列表
  38. *
  39. * @param contractTable B类
  40. * @return B类
  41. */
  42. @Override
  43. public List<ContractTable> selectContractTableList(ContractTable contractTable)
  44. {
  45. return contractTableMapper.selectContractTableList(contractTable);
  46. }
  47. /**
  48. * 新增B类
  49. *
  50. * @param contractTable B类
  51. * @return 结果
  52. */
  53. @Override
  54. public int insertContractTable(ContractTable contractTable)
  55. {
  56. return contractTableMapper.insertContractTable(contractTable);
  57. }
  58. /**
  59. * 修改B类
  60. *
  61. * @param contractTable B类
  62. * @return 结果
  63. */
  64. @Override
  65. public int updateContractTable(ContractTable contractTable)
  66. {
  67. return contractTableMapper.updateContractTable(contractTable);
  68. }
  69. /**
  70. * 批量删除B类
  71. *
  72. * @param ids 需要删除的B类主键
  73. * @return 结果
  74. */
  75. @Override
  76. public int deleteContractTableByIds(Long[] ids)
  77. {
  78. return contractTableMapper.deleteContractTableByIds(ids);
  79. }
  80. /**
  81. * 删除B类信息
  82. *
  83. * @param id B类主键
  84. * @return 结果
  85. */
  86. @Override
  87. public int deleteContractTableById(Long id)
  88. {
  89. return contractTableMapper.deleteContractTableById(id);
  90. }
  91. @Override
  92. public String importCon(List<ContractTable> stuList, Boolean isUpdateSupport, String operName) {
  93. if (StringUtils.isNull(stuList) || stuList.size() == 0)
  94. {
  95. throw new ServiceException("导入B类证书基本信息数据不能为空!");
  96. }
  97. int successNum = 0;
  98. int failureNum = 0;
  99. StringBuilder successMsg = new StringBuilder();
  100. StringBuilder failureMsg = new StringBuilder();
  101. for (ContractTable con : stuList)
  102. {
  103. try
  104. {
  105. // 验证是否存在这个用户
  106. ContractTable u = contractTableMapper.selectContractTableByCode(con.getCertId());
  107. if (StringUtils.isNull(u))
  108. {
  109. BeanValidators.validateWithException(validator, con);
  110. con.setCreateBy(operName);
  111. this.insertContractTable(con);
  112. successNum++;
  113. successMsg.append("<br/>" + successNum + "、证书编码 " + con.getCertId() + " 导入成功");
  114. }
  115. else if (isUpdateSupport)
  116. {
  117. BeanValidators.validateWithException(validator, con);
  118. con.setUpdateBy(operName);
  119. this.updateContractTable(con);
  120. successNum++;
  121. successMsg.append("<br/>" + successNum + "、证书编码 " + con.getCertId() + " 更新成功");
  122. }
  123. else
  124. {
  125. failureNum++;
  126. failureMsg.append("<br/>" + failureNum + "、证书编码 " + con.getCertId() + " 已存在");
  127. }
  128. }
  129. catch (Exception e)
  130. {
  131. failureNum++;
  132. String msg = "<br/>" + failureNum + "、证书编码 " + con.getCertId() + " 导入失败:";
  133. failureMsg.append(msg + e.getMessage());
  134. }
  135. }
  136. if (failureNum > 0)
  137. {
  138. failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:");
  139. throw new ServiceException(failureMsg.toString());
  140. }
  141. else
  142. {
  143. successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条,数据如下:");
  144. }
  145. return successMsg.toString();
  146. }
  147. }