GPressureRegulatingBoxServiceImpl.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. package com.ruoyi.gas.service.impl;
  2. import cn.hutool.core.bean.BeanUtil;
  3. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  4. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  5. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  6. import com.ruoyi.common.core.mybatisplus.core.ServicePlusImpl;
  7. import com.ruoyi.common.core.page.PagePlus;
  8. import com.ruoyi.common.core.page.TableDataInfo;
  9. import com.ruoyi.common.exception.ServiceException;
  10. import com.ruoyi.common.utils.PageUtils;
  11. import com.ruoyi.common.utils.StringUtils;
  12. import com.ruoyi.gas.domain.GPressureRegulatingBox;
  13. import com.ruoyi.gas.domain.GRegulatorBox;
  14. import com.ruoyi.gas.domain.GRegulatorBoxRelation;
  15. import com.ruoyi.gas.domain.bo.GPressureRegulatingBoxBo;
  16. import com.ruoyi.gas.domain.bo.GPressureRegulatingBoxDetailsBo;
  17. import com.ruoyi.gas.domain.bo.GRegulatorBoxBo;
  18. import com.ruoyi.gas.domain.vo.GPressureRegulatingBoxDetailsVo;
  19. import com.ruoyi.gas.domain.vo.GPressureRegulatingBoxExcelVo;
  20. import com.ruoyi.gas.domain.vo.GPressureRegulatingBoxVo;
  21. import com.ruoyi.gas.mapper.GPressureRegulatingBoxMapper;
  22. import com.ruoyi.gas.service.IGPressureRegulatingBoxDetailsService;
  23. import com.ruoyi.gas.service.IGPressureRegulatingBoxService;
  24. import com.ruoyi.gas.service.IGRegulatorBoxRelationService;
  25. import com.ruoyi.system.mapper.SysDictDataMapper;
  26. import org.springframework.beans.factory.annotation.Autowired;
  27. import org.springframework.stereotype.Service;
  28. import org.springframework.transaction.annotation.Transactional;
  29. import org.springframework.util.ObjectUtils;
  30. import javax.annotation.Resource;
  31. import java.util.Collection;
  32. import java.util.HashMap;
  33. import java.util.List;
  34. import java.util.Map;
  35. import java.util.stream.Collectors;
  36. /**
  37. * 调压箱管理Service业务层处理
  38. *
  39. * @author ruoyi
  40. * @date 2024-03-25
  41. */
  42. @Service
  43. public class GPressureRegulatingBoxServiceImpl extends ServicePlusImpl<GPressureRegulatingBoxMapper, GPressureRegulatingBox, GPressureRegulatingBoxVo> implements IGPressureRegulatingBoxService {
  44. @Autowired
  45. private IGPressureRegulatingBoxDetailsService igPressureRegulatingBoxDetailsService;
  46. @Resource
  47. private SysDictDataMapper sysDictDataMapper;
  48. @Override
  49. public Map<String, Object> importVo(List<GPressureRegulatingBoxExcelVo> list, Boolean isUpdateSupport, String operName, int n, int successNum) {
  50. if (ObjectUtils.isEmpty(list) || list.size() == 0) {
  51. throw new ServiceException("导入数据不能为空!");
  52. }
  53. Map<String, Object> ret = new HashMap<>();
  54. StringBuilder successMsg = new StringBuilder();
  55. for (int i = n; i < list.size(); i++) {
  56. GPressureRegulatingBoxExcelVo vo = list.get(i);
  57. try {
  58. n++;
  59. if (StringUtils.isNotEmpty(vo.getNumber())) {
  60. successNum++;
  61. GPressureRegulatingBox gPressureRegulatingBox = baseMapper.getByNumber(vo.getNumber(),vo.getName(),vo.getManagementOffice());
  62. // String type = sysDictDataMapper.queryDictTextByKey("tyx_type", vo.getType());
  63. // if (StringUtils.isBlank(type)) {
  64. // throw new ServiceException( "第" + (n + 1) + "行类型填写错误,导入失败!");
  65. // }
  66. // String getNature = sysDictDataMapper.queryDictTextByKey("tyx_nature", vo.getNature());
  67. // if (StringUtils.isBlank(getNature)) {
  68. // throw new ServiceException("第" + (n + 1) + "行性质填写错误,导入失败!");
  69. // }
  70. // String getNumberOfRoutes = sysDictDataMapper.queryDictTextByKey("tyx_numberOfRoutes", vo.getNumberOfRoutes());
  71. // if (StringUtils.isBlank(getNumberOfRoutes)) {
  72. // throw new ServiceException( "第" + (n + 1) + "行路数填写错误,导入失败!");
  73. // }
  74. String getManagementOffice = sysDictDataMapper.queryDictTextByKey("administrative_office", vo.getManagementOffice());
  75. if (StringUtils.isBlank(getManagementOffice)) {
  76. throw new ServiceException( "第" + (n + 1) + "行管理所填写错误,导入失败!");
  77. }
  78. if (ObjectUtils.isEmpty(gPressureRegulatingBox)) {
  79. GPressureRegulatingBox bean = BeanUtil.toBean(vo, GPressureRegulatingBox.class);
  80. bean.setId(null);
  81. baseMapper.insert(bean);
  82. Long id = bean.getId();
  83. GPressureRegulatingBoxDetailsBo bean1 = BeanUtil.toBean(vo, GPressureRegulatingBoxDetailsBo.class);
  84. bean1.setRegulatingBoxId(id.toString());
  85. bean1.setId(null);
  86. igPressureRegulatingBoxDetailsService.insertByBo(bean1);
  87. } else {
  88. GPressureRegulatingBox bean = BeanUtil.toBean(vo, GPressureRegulatingBox.class);
  89. bean.setId(gPressureRegulatingBox.getId());
  90. baseMapper.updateById(bean);
  91. Long id = gPressureRegulatingBox.getId();
  92. GPressureRegulatingBoxDetailsBo bean1 = BeanUtil.toBean(vo, GPressureRegulatingBoxDetailsBo.class);
  93. bean1.setRegulatingBoxId(id.toString());
  94. bean1.setId(null);
  95. igPressureRegulatingBoxDetailsService.insertByBo(bean1);
  96. }
  97. }else {
  98. throw new ServiceException("第" + (n + 1) + "行编号错误,导入失败!");
  99. }
  100. } catch (Exception e) {
  101. e.printStackTrace();
  102. throw new ServiceException("第" + (n + 1) + "行格式错误,导入失败!");
  103. }
  104. ret.put("bfb", String.format("%.2f", (Double.valueOf((n + 1)) / Double.valueOf(list.size())) * 100));
  105. ret.put("n", n);
  106. ret.put("is_success", true);
  107. ret.put("successMsg", "");
  108. ret.put("successNum", successNum);
  109. return ret;
  110. }
  111. successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条");
  112. ret.put("bfb", String.format("%.2f", (Double.valueOf((n + 1)) / Double.valueOf(list.size())) * 100));
  113. ret.put("n", n);
  114. ret.put("is_success", false);
  115. ret.put("successMsg", successMsg.toString());
  116. return ret;
  117. }
  118. @Override
  119. public GPressureRegulatingBoxVo queryById(Long id) {
  120. GPressureRegulatingBoxVo voById = getVoById(id);
  121. GPressureRegulatingBoxDetailsBo gPressureRegulatingBoxDetailsBo = new GPressureRegulatingBoxDetailsBo();
  122. gPressureRegulatingBoxDetailsBo.setRegulatingBoxId(voById.getId().toString());
  123. TableDataInfo<GPressureRegulatingBoxDetailsVo> queriedPageList = pressureRegulatingBoxDetailsService.queryPageList(gPressureRegulatingBoxDetailsBo);
  124. voById.setPressureRegulatingBoxDetailsVo(queriedPageList.getRows());
  125. return voById;
  126. }
  127. @Override
  128. public List<GPressureRegulatingBoxExcelVo> getExcelList() {
  129. List<GPressureRegulatingBoxExcelVo> excelList = baseMapper.getExcelList();
  130. for (int i = 1; i <= excelList.size(); i++) {
  131. excelList.get(i - 1).setId(String.valueOf(i));
  132. }
  133. return excelList;
  134. }
  135. @Autowired
  136. private IGPressureRegulatingBoxDetailsService pressureRegulatingBoxDetailsService;
  137. @Override
  138. public TableDataInfo<GPressureRegulatingBoxVo> queryPageList(GPressureRegulatingBoxBo bo) {
  139. PagePlus<GPressureRegulatingBox, GPressureRegulatingBoxVo> result = pageVo(PageUtils.buildPagePlus(), buildQueryWrapper(bo));
  140. result.getRecordsVo().forEach(item -> {
  141. GPressureRegulatingBoxDetailsBo gPressureRegulatingBoxDetailsBo = new GPressureRegulatingBoxDetailsBo();
  142. gPressureRegulatingBoxDetailsBo.setRegulatingBoxId(item.getId().toString());
  143. TableDataInfo<GPressureRegulatingBoxDetailsVo> queriedPageList = pressureRegulatingBoxDetailsService.queryPageList(gPressureRegulatingBoxDetailsBo);
  144. item.setPressureRegulatingBoxDetailsVo(queriedPageList.getRows());
  145. });
  146. return PageUtils.buildDataInfo(result);
  147. }
  148. @Override
  149. public List<GPressureRegulatingBoxVo> queryList(GPressureRegulatingBoxBo bo) {
  150. return listVo(buildQueryWrapper(bo));
  151. }
  152. private LambdaQueryWrapper<GPressureRegulatingBox> buildQueryWrapper(GPressureRegulatingBoxBo bo) {
  153. Map<String, Object> params = bo.getParams();
  154. LambdaQueryWrapper<GPressureRegulatingBox> lqw = Wrappers.lambdaQuery();
  155. lqw.eq(StringUtils.isNotBlank(bo.getNature()), GPressureRegulatingBox::getNature, bo.getNature());
  156. lqw.eq(StringUtils.isNotBlank(bo.getType()), GPressureRegulatingBox::getType, bo.getType());
  157. lqw.eq(StringUtils.isNotBlank(bo.getNumberOfRoutes()), GPressureRegulatingBox::getNumberOfRoutes, bo.getNumberOfRoutes());
  158. lqw.eq(StringUtils.isNotBlank(bo.getManagementOffice()), GPressureRegulatingBox::getManagementOffice, bo.getManagementOffice());
  159. lqw.like(StringUtils.isNotBlank(bo.getNumber()), GPressureRegulatingBox::getNumber, bo.getNumber());
  160. lqw.like(StringUtils.isNotBlank(bo.getName()), GPressureRegulatingBox::getName, bo.getName());
  161. lqw.eq(StringUtils.isNotBlank(bo.getLongitude()), GPressureRegulatingBox::getLongitude, bo.getLongitude());
  162. lqw.eq(StringUtils.isNotBlank(bo.getLatitude()), GPressureRegulatingBox::getLatitude, bo.getLatitude());
  163. lqw.like(StringUtils.isNotBlank(bo.getInspector()), GPressureRegulatingBox::getInspector, bo.getInspector());
  164. if (!ObjectUtils.isEmpty(bo.getCreateTimes())){
  165. lqw.ge(GPressureRegulatingBox::getCreateTime, bo.getCreateTimes().get(0));
  166. lqw.le(GPressureRegulatingBox::getCreateTime, bo.getCreateTimes().get(1));
  167. }
  168. return lqw;
  169. }
  170. @Autowired
  171. private IGRegulatorBoxRelationService regulatorBoxRelationService;
  172. @Override
  173. @Transactional(rollbackFor = Exception.class)
  174. public Boolean insertByBo(GPressureRegulatingBoxBo bo) {
  175. GPressureRegulatingBox add = BeanUtil.toBean(bo, GPressureRegulatingBox.class);
  176. validEntityBeforeSave(add);
  177. boolean flag = save(add);
  178. if (flag) {
  179. bo.setId(add.getId());
  180. bo.getPressureRegulatingBoxDetailsBo().setRegulatingBoxId(add.getId().toString());
  181. pressureRegulatingBoxDetailsService.insertByBo(bo.getPressureRegulatingBoxDetailsBo());
  182. }
  183. return flag;
  184. }
  185. @Override
  186. public Boolean updateByBo(GPressureRegulatingBoxBo bo) {
  187. GPressureRegulatingBox update = BeanUtil.toBean(bo, GPressureRegulatingBox.class);
  188. validEntityBeforeSave(update);
  189. pressureRegulatingBoxDetailsService.updateByBo(bo.getPressureRegulatingBoxDetailsBo());
  190. return updateById(update);
  191. }
  192. /**
  193. * 保存前的数据校验
  194. *
  195. * @param entity 实体类数据
  196. */
  197. private void validEntityBeforeSave(GPressureRegulatingBox entity) {
  198. //TODO 做一些数据校验,如唯一约束
  199. }
  200. @Override
  201. public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
  202. if (isValid) {
  203. //TODO 做一些业务上的校验,判断是否需要校验
  204. }
  205. return removeByIds(ids);
  206. }
  207. @Override
  208. public TableDataInfo myList(GPressureRegulatingBoxBo bo) {
  209. LambdaQueryWrapper<GPressureRegulatingBox> lqw = Wrappers.lambdaQuery();
  210. //查询我的
  211. if (StringUtils.isNotBlank(bo.getJobNum())){
  212. QueryWrapper<GRegulatorBoxRelation> queryWrapper = new QueryWrapper<>();
  213. queryWrapper.lambda().eq(GRegulatorBoxRelation::getUserId,bo.getJobNum());
  214. List<Long> collect = regulatorBoxRelationService.list(queryWrapper).stream().map(GRegulatorBoxRelation::getRegulatorBoxId).collect(Collectors.toList());
  215. lqw.in(GPressureRegulatingBox::getId,collect);
  216. }
  217. PagePlus<GPressureRegulatingBox, GPressureRegulatingBoxVo> result = pageVo(PageUtils.buildPagePlus(), lqw);
  218. return PageUtils.buildDataInfo(result);
  219. }
  220. }