|
@@ -6,12 +6,14 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.ruoyi.common.core.mybatisplus.core.ServicePlusImpl;
|
|
|
import com.ruoyi.common.core.page.PagePlus;
|
|
|
import com.ruoyi.common.core.page.TableDataInfo;
|
|
|
+import com.ruoyi.common.exception.ServiceException;
|
|
|
import com.ruoyi.common.utils.PageUtils;
|
|
|
import com.ruoyi.common.utils.StringUtils;
|
|
|
import com.ruoyi.gas.domain.GPressureRegulatingBox;
|
|
|
import com.ruoyi.gas.domain.bo.GPressureRegulatingBoxBo;
|
|
|
import com.ruoyi.gas.domain.bo.GPressureRegulatingBoxDetailsBo;
|
|
|
import com.ruoyi.gas.domain.vo.GPressureRegulatingBoxDetailsVo;
|
|
|
+import com.ruoyi.gas.domain.vo.GPressureRegulatingBoxExcelVo;
|
|
|
import com.ruoyi.gas.domain.vo.GPressureRegulatingBoxVo;
|
|
|
import com.ruoyi.gas.mapper.GPressureRegulatingBoxMapper;
|
|
|
import com.ruoyi.gas.service.IGPressureRegulatingBoxDetailsService;
|
|
@@ -19,8 +21,10 @@ import com.ruoyi.gas.service.IGPressureRegulatingBoxService;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.util.ObjectUtils;
|
|
|
|
|
|
import java.util.Collection;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
@@ -32,25 +36,86 @@ import java.util.Map;
|
|
|
*/
|
|
|
@Service
|
|
|
public class GPressureRegulatingBoxServiceImpl extends ServicePlusImpl<GPressureRegulatingBoxMapper, GPressureRegulatingBox, GPressureRegulatingBoxVo> implements IGPressureRegulatingBoxService {
|
|
|
+ @Autowired
|
|
|
+ private IGPressureRegulatingBoxDetailsService igPressureRegulatingBoxDetailsService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> importVo(List<GPressureRegulatingBoxExcelVo> list, Boolean isUpdateSupport, String operName, int n, int successNum) {
|
|
|
+ if (ObjectUtils.isEmpty(list) || list.size() == 0) {
|
|
|
+ throw new ServiceException("导入数据不能为空!");
|
|
|
+ }
|
|
|
+ Map<String, Object> ret = new HashMap<>();
|
|
|
+ StringBuilder successMsg = new StringBuilder();
|
|
|
+ for (int i = n; i < list.size(); i++) {
|
|
|
+ GPressureRegulatingBoxExcelVo vo = list.get(i);
|
|
|
+ try {
|
|
|
+ n++;
|
|
|
+ if (StringUtils.isNotEmpty(vo.getNumber())) {
|
|
|
+ GPressureRegulatingBox gPressureRegulatingBox = baseMapper.getByNumber(vo.getNumber());
|
|
|
+ if (ObjectUtils.isEmpty(gPressureRegulatingBox)) {
|
|
|
+ GPressureRegulatingBox bean = BeanUtil.toBean(vo, GPressureRegulatingBox.class);
|
|
|
+ bean.setId(null);
|
|
|
+ baseMapper.insert(bean);
|
|
|
+ Long id = bean.getId();
|
|
|
+ GPressureRegulatingBoxDetailsBo bean1 = BeanUtil.toBean(vo, GPressureRegulatingBoxDetailsBo.class);
|
|
|
+ bean1.setRegulatingBoxId(id.toString());
|
|
|
+ igPressureRegulatingBoxDetailsService.insertByBo(bean1);
|
|
|
+ } else {
|
|
|
+ Long id = gPressureRegulatingBox.getId();
|
|
|
+ GPressureRegulatingBoxDetailsBo bean1 = BeanUtil.toBean(vo, GPressureRegulatingBoxDetailsBo.class);
|
|
|
+ bean1.setRegulatingBoxId(id.toString());
|
|
|
+ bean1.setId(null);
|
|
|
+ igPressureRegulatingBoxDetailsService.insertByBo(bean1);
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ throw new ServiceException("第" + (n + 1) + "行格式错误,导入失败!");
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new ServiceException("第" + (n + 1) + "行格式错误,导入失败!");
|
|
|
+ }
|
|
|
+ ret.put("bfb", String.format("%.2f", (Double.valueOf((n + 1)) / Double.valueOf(list.size())) * 100));
|
|
|
+ ret.put("n", n);
|
|
|
+ ret.put("is_success", true);
|
|
|
+ ret.put("successMsg", "");
|
|
|
+ ret.put("successNum", successNum);
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+ successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + list.size() + " 条");
|
|
|
+ ret.put("bfb", String.format("%.2f", (Double.valueOf((n + 1)) / Double.valueOf(list.size())) * 100));
|
|
|
+ ret.put("n", n);
|
|
|
+ ret.put("is_success", false);
|
|
|
+ ret.put("successMsg", successMsg.toString());
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
|
|
|
@Override
|
|
|
- public GPressureRegulatingBoxVo queryById(Long id){
|
|
|
+ public GPressureRegulatingBoxVo queryById(Long id) {
|
|
|
GPressureRegulatingBoxVo voById = getVoById(id);
|
|
|
GPressureRegulatingBoxDetailsBo gPressureRegulatingBoxDetailsBo = new GPressureRegulatingBoxDetailsBo();
|
|
|
- gPressureRegulatingBoxDetailsBo.setRegulatingBoxId(voById.getId());
|
|
|
+ gPressureRegulatingBoxDetailsBo.setRegulatingBoxId(voById.getId().toString());
|
|
|
TableDataInfo<GPressureRegulatingBoxDetailsVo> queriedPageList = pressureRegulatingBoxDetailsService.queryPageList(gPressureRegulatingBoxDetailsBo);
|
|
|
voById.setPressureRegulatingBoxDetailsVo(queriedPageList.getRows());
|
|
|
return voById;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public List<GPressureRegulatingBoxExcelVo> getExcelList() {
|
|
|
+ List<GPressureRegulatingBoxExcelVo> excelList = baseMapper.getExcelList();
|
|
|
+ for (int i = 1; i <= excelList.size(); i++) {
|
|
|
+ excelList.get(i - 1).setId(String.valueOf(i));
|
|
|
+ }
|
|
|
+ return excelList;
|
|
|
+ }
|
|
|
+
|
|
|
@Autowired
|
|
|
private IGPressureRegulatingBoxDetailsService pressureRegulatingBoxDetailsService;
|
|
|
+
|
|
|
@Override
|
|
|
public TableDataInfo<GPressureRegulatingBoxVo> queryPageList(GPressureRegulatingBoxBo bo) {
|
|
|
PagePlus<GPressureRegulatingBox, GPressureRegulatingBoxVo> result = pageVo(PageUtils.buildPagePlus(), buildQueryWrapper(bo));
|
|
|
result.getRecordsVo().forEach(item -> {
|
|
|
GPressureRegulatingBoxDetailsBo gPressureRegulatingBoxDetailsBo = new GPressureRegulatingBoxDetailsBo();
|
|
|
- gPressureRegulatingBoxDetailsBo.setRegulatingBoxId(item.getId());
|
|
|
+ gPressureRegulatingBoxDetailsBo.setRegulatingBoxId(item.getId().toString());
|
|
|
TableDataInfo<GPressureRegulatingBoxDetailsVo> queriedPageList = pressureRegulatingBoxDetailsService.queryPageList(gPressureRegulatingBoxDetailsBo);
|
|
|
item.setPressureRegulatingBoxDetailsVo(queriedPageList.getRows());
|
|
|
});
|
|
@@ -84,7 +149,7 @@ public class GPressureRegulatingBoxServiceImpl extends ServicePlusImpl<GPressure
|
|
|
boolean flag = save(add);
|
|
|
if (flag) {
|
|
|
bo.setId(add.getId());
|
|
|
- bo.getPressureRegulatingBoxDetailsBo().setRegulatingBoxId(add.getId());
|
|
|
+ bo.getPressureRegulatingBoxDetailsBo().setRegulatingBoxId(add.getId().toString());
|
|
|
pressureRegulatingBoxDetailsService.insertByBo(bo.getPressureRegulatingBoxDetailsBo());
|
|
|
}
|
|
|
return flag;
|
|
@@ -103,13 +168,13 @@ public class GPressureRegulatingBoxServiceImpl extends ServicePlusImpl<GPressure
|
|
|
*
|
|
|
* @param entity 实体类数据
|
|
|
*/
|
|
|
- private void validEntityBeforeSave(GPressureRegulatingBox entity){
|
|
|
+ private void validEntityBeforeSave(GPressureRegulatingBox entity) {
|
|
|
//TODO 做一些数据校验,如唯一约束
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
|
|
- if(isValid){
|
|
|
+ if (isValid) {
|
|
|
//TODO 做一些业务上的校验,判断是否需要校验
|
|
|
}
|
|
|
return removeByIds(ids);
|