|
@@ -0,0 +1,160 @@
|
|
|
+package com.rongwei.bscommon.sys.service.impl;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.rongwei.bscommon.sys.dao.ZhcxMdfFormDao;
|
|
|
+import com.rongwei.bscommon.sys.service.ZhcxMdfFileService;
|
|
|
+import com.rongwei.bscommon.sys.service.ZhcxMdfFormService;
|
|
|
+import com.rongwei.bscommon.sys.service.ZhcxMdfRowService;
|
|
|
+import com.rongwei.bscommon.sys.service.ZhcxMdfSectionService;
|
|
|
+import com.rongwei.bscommon.sys.utils.MdfApi;
|
|
|
+import com.rongwei.bsentity.domain.ZhcxMdfFileDo;
|
|
|
+import com.rongwei.bsentity.domain.ZhcxMdfFormDo;
|
|
|
+import com.rongwei.bsentity.domain.ZhcxMdfRowDo;
|
|
|
+import com.rongwei.bsentity.domain.ZhcxMdfSectionDo;
|
|
|
+import com.rongwei.bsentity.vo.ZhcxMdfFormVo;
|
|
|
+import com.rongwei.bsentity.vo.ZhcxMdfRowVo;
|
|
|
+import com.rongwei.bsentity.vo.ZhcxMdfSectionVo;
|
|
|
+import com.rongwei.rwcommon.base.R;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * 服务实现类
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author dlc
|
|
|
+ * @since 2024-11-18
|
|
|
+ */
|
|
|
+@Service
|
|
|
+@Slf4j
|
|
|
+public class ZhcxMdfFormServiceImpl extends ServiceImpl<ZhcxMdfFormDao, ZhcxMdfFormDo> implements ZhcxMdfFormService {
|
|
|
+ @Autowired
|
|
|
+ private MdfApi mdfApi;
|
|
|
+ @Autowired
|
|
|
+ private ZhcxMdfFormService zhcxMdfFormService;
|
|
|
+ @Autowired
|
|
|
+ private ZhcxMdfSectionService zhcxMdfSectionService;
|
|
|
+ @Autowired
|
|
|
+ private ZhcxMdfRowService zhcxMdfRowService;
|
|
|
+ @Autowired
|
|
|
+ private ZhcxMdfFileService zhcxMdfFileService;
|
|
|
+ @Autowired
|
|
|
+ private ZhcxMdfFormDao zhcxMdfFormDao;
|
|
|
+
|
|
|
+ //获取修改单信息
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public R getMdfFormInfo(String dtwhoapproveTime) throws Exception {
|
|
|
+ R r = new R();
|
|
|
+ if (dtwhoapproveTime == null || dtwhoapproveTime.length() == 0) {
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
+ calendar.add(Calendar.DATE, -1);
|
|
|
+ Date yesterday = calendar.getTime();
|
|
|
+ dtwhoapproveTime = sdf.format(yesterday);
|
|
|
+ }
|
|
|
+ Map<String, Object> mdfmap = mdfApi.apiCall(dtwhoapproveTime);
|
|
|
+ if (mdfmap.get("code").equals("200")) {
|
|
|
+ List<ZhcxMdfFormVo> mdfFormVoList = JSON.parseArray(JSON.toJSONString(mdfmap.get("data")), ZhcxMdfFormVo.class);
|
|
|
+ if (mdfFormVoList.size() > 0) {
|
|
|
+ //已有修改单数据
|
|
|
+ List<ZhcxMdfFormDo> zhcxMdfFormDos = zhcxMdfFormDao.getZhcxMdfForms(dtwhoapproveTime);
|
|
|
+
|
|
|
+ List<ZhcxMdfFormDo> zhcxMdfFormDoList = new ArrayList<>();
|
|
|
+ List<ZhcxMdfSectionDo> zhcxMdfSectionDoList = new ArrayList<>();
|
|
|
+ List<ZhcxMdfRowDo> zhcxMdfRowDoList = new ArrayList<>();
|
|
|
+ List<ZhcxMdfFileDo> zhcxMdfFileDoList = new ArrayList<>();
|
|
|
+ for (ZhcxMdfFormVo zhcxMdfFormVo : mdfFormVoList) {
|
|
|
+ List<ZhcxMdfFormDo> hasMdfForms = zhcxMdfFormDos.stream().filter(mdf -> mdf.getId().equals(zhcxMdfFormVo.getId())).collect(Collectors.toList());
|
|
|
+ if (hasMdfForms.size() > 0) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ zhcxMdfFormDoList.add(zhcxMdfFormVo);
|
|
|
+ for (ZhcxMdfSectionVo zhcxMdfSectionVo : zhcxMdfFormVo.getSections()) {
|
|
|
+ zhcxMdfSectionVo.setFormid(zhcxMdfFormVo.getId());
|
|
|
+ zhcxMdfSectionDoList.add(zhcxMdfSectionVo);
|
|
|
+ for (ZhcxMdfRowVo zhcxMdfRowVo : zhcxMdfSectionVo.getRows()) {
|
|
|
+ zhcxMdfRowVo.setFormid(zhcxMdfFormVo.getId());
|
|
|
+ zhcxMdfRowVo.setSectionid(zhcxMdfSectionVo.getId());
|
|
|
+ zhcxMdfRowDoList.add(zhcxMdfRowVo);
|
|
|
+ for (ZhcxMdfFileDo zhcxMdfFileDo : zhcxMdfRowVo.getFiles()) {
|
|
|
+ zhcxMdfFileDo.setFormid(zhcxMdfFormVo.getId());
|
|
|
+ zhcxMdfFileDo.setSectionid(zhcxMdfSectionVo.getId());
|
|
|
+ zhcxMdfFileDo.setRowsid(zhcxMdfRowVo.getId());
|
|
|
+ zhcxMdfFileDoList.add(zhcxMdfFileDo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (zhcxMdfFormDoList.size() > 0) {
|
|
|
+ zhcxMdfFormService.saveOrUpdateBatch(zhcxMdfFormDoList);
|
|
|
+ }
|
|
|
+ if (zhcxMdfSectionDoList.size() > 0) {
|
|
|
+ zhcxMdfSectionService.saveOrUpdateBatch(zhcxMdfSectionDoList);
|
|
|
+ }
|
|
|
+ if (zhcxMdfRowDoList.size() > 0) {
|
|
|
+ zhcxMdfRowService.saveOrUpdateBatch(zhcxMdfRowDoList);
|
|
|
+ }
|
|
|
+ if (zhcxMdfFileDoList.size() > 0) {
|
|
|
+ zhcxMdfFileService.saveOrUpdateBatch(zhcxMdfFileDoList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ r.setCode(mdfmap.get("code").toString());
|
|
|
+ r.setMsg(mdfmap.get("msg").toString());
|
|
|
+ return r;
|
|
|
+ }
|
|
|
+
|
|
|
+ //发送原始修改单信息
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public R sendMdfFormInfo(String dtwhoapproveTime) throws Exception {
|
|
|
+ R r = new R();
|
|
|
+ if (dtwhoapproveTime == null || dtwhoapproveTime.length() == 0) {
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
+ calendar.add(Calendar.DATE, -1);
|
|
|
+ Date yesterday = calendar.getTime();
|
|
|
+ dtwhoapproveTime = sdf.format(yesterday);
|
|
|
+ }
|
|
|
+ //主表信息
|
|
|
+ List<ZhcxMdfFormVo> zhcxMdfFormVos = zhcxMdfFormDao.getZhcxMdfFormVos(dtwhoapproveTime);
|
|
|
+ List<Integer> formIds = new ArrayList<>();
|
|
|
+ for (ZhcxMdfFormVo zhcxMdfFormVo : zhcxMdfFormVos) {
|
|
|
+ formIds.add(zhcxMdfFormVo.getId());
|
|
|
+ }
|
|
|
+ //各子表信息
|
|
|
+ List<ZhcxMdfSectionVo> zhcxMdfSectionVos = zhcxMdfFormDao.getZhcxMdfSectionDos(formIds);
|
|
|
+ List<ZhcxMdfRowVo> zhcxMdfRowVos = zhcxMdfFormDao.getZhcxMdfRowDos(formIds);
|
|
|
+ List<ZhcxMdfFileDo> zhcxMdfFileDos = zhcxMdfFormDao.getZhcxMdfFileDos(formIds);
|
|
|
+ //接口发送的数据
|
|
|
+ List<ZhcxMdfFormVo> sendMdfFormVos = new ArrayList<>();
|
|
|
+ for (ZhcxMdfFormVo mdfFormVo : zhcxMdfFormVos) {
|
|
|
+ List<ZhcxMdfSectionVo> mdfSectionVos = zhcxMdfSectionVos.stream().filter(s -> s.getFormid().equals(mdfFormVo.getId())).collect(Collectors.toList());
|
|
|
+ for (ZhcxMdfSectionVo mdfSectionVo : mdfSectionVos) {
|
|
|
+ List<ZhcxMdfRowVo> mdfRowVos = zhcxMdfRowVos.stream().filter(mr -> mr.getFormid().equals(mdfFormVo.getId()) && mr.getSectionid().equals(mdfSectionVo.getId())).collect(Collectors.toList());
|
|
|
+ for (ZhcxMdfRowVo mdfRowVo : mdfRowVos) {
|
|
|
+ List<ZhcxMdfFileDo> mdfFileDos = zhcxMdfFileDos.stream().filter(f -> f.getFormid().equals(mdfFormVo.getId()) && f.getSectionid().equals(mdfSectionVo.getId()) && f.getRowsid().equals(mdfRowVo.getId())).collect(Collectors.toList());
|
|
|
+ mdfRowVo.setFiles(mdfFileDos);
|
|
|
+ }
|
|
|
+ mdfSectionVo.setRows(mdfRowVos);
|
|
|
+ }
|
|
|
+ mdfFormVo.setSections(mdfSectionVos);
|
|
|
+ sendMdfFormVos.add(mdfFormVo);
|
|
|
+ }
|
|
|
+
|
|
|
+ r.setCode("200");
|
|
|
+ r.setMsg("操作成功");
|
|
|
+ r.setData(sendMdfFormVos);
|
|
|
+ log.info("发送的JSON:" + r);
|
|
|
+ return r;
|
|
|
+ }
|
|
|
+}
|