yangys
2025-09-20 fcee672452c02cc29e0e17ebc27a8c51698c6d0d
blade-service/blade-mdm/src/main/java/org/springblade/mdm/test/MyTestController.java
@@ -1,18 +1,32 @@
package org.springblade.mdm.test;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.mail.MessagingException;
import jakarta.xml.soap.SOAPException;
import jakarta.xml.ws.WebServiceContext;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils;
import org.apache.neethi.AssertionBuilderFactory;
import org.apache.ws.commons.schema.XmlSchemaSerializer;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.DateUtil;
import org.springblade.core.tool.utils.SpringUtil;
import org.springblade.mdm.basesetting.machine.entity.Machine;
import org.springblade.mdm.commons.service.EmailService;
import org.springblade.mdm.commons.service.InternalEmailService;
import org.springblade.mdm.flow.entity.MesSync;
import org.springblade.mdm.flow.excution.events.CureFinishedEvent;
import org.springblade.mdm.flow.service.MesSyncService;
import org.springblade.mdm.flow.service.WIthdrawService;
import org.springblade.mdm.gkw.programnode.entity.MachineFile;
import org.springblade.mdm.machinefile.entity.MachineFile;
import org.springblade.mdm.machinefile.service.MachineFileScanService;
import org.springblade.mdm.program.entity.NcNode;
import org.springblade.mdm.program.service.NcNodeHisService;
import org.springblade.mdm.program.service.NcNodeService;
import org.springblade.mdm.program.service.ProgramAnnotationService;
import org.springblade.mdm.task.InternalEmailNotifyTask;
import org.springblade.mdm.task.MachineFileScanTask;
import org.springblade.mdm.utils.FileContentUtil;
import org.springblade.system.feign.IDictBizClient;
@@ -22,9 +36,11 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.wsdl.WSDLException;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Date;
import java.util.List;
@Slf4j
@@ -35,18 +51,23 @@
   @Autowired
   private NcNodeService service;
   @Autowired
   private MachineFileScanTask machineFileScanTask;
   private MesSyncService mesSyncService;
   @Autowired
   private ProgramAnnotationService programAnnotationService;
   @Autowired
   private IDictBizClient bizDictClient;
   @Autowired
   private EmailService mailService;
   private InternalEmailService mailService;
   @Autowired
   private MachineFileScanService machineFileScanService;
   @Autowired
   private WIthdrawService withdrawService;
   @Autowired
   private InternalEmailNotifyTask notifyTask;
   @Autowired
   private NcNodeHisService nodeHisService;
   /**
    * 新增
    */
@@ -76,31 +97,16 @@
   }
   @GetMapping("/scan")
   @GetMapping("/scandir")
   @Operation(summary = "test扫描", description = "test扫描")
   public R<Void> scan() throws IOException {
      Machine machine = new Machine();
      machine.setCode("M_01_FN");
      machine.setProgReceiveDir("d:/data/machine1/rec");
      machineFileScanTask.scanDir(machine, MachineFile.DIR_TYPE_REC);
      machineFileScanService.scanDir(machine, MachineFile.DIR_TYPE_REC);
      return R.success();
   }
   @GetMapping("/repalce-anno")
   @Operation(summary = "替换注释", description = "test扫描")
   public R<List<String>> repalceAnno() throws IOException {
      InputStream res;
      try(FileInputStream fis = new FileInputStream("d:/b.txt");) {
         res = programAnnotationService.setSendDirAndStatusAnnotation("D:/mysend", "PL", fis,"FANUC");
      }
      List<String> lines = null;
      if(res!=null) {
         try(res) {
            lines = IOUtils.readLines(res, "utf-8");
         }
      }
      return R.data(lines);
   }
   @GetMapping("/dict-biz")
   @Operation(summary = "biz", description = "test扫描")
@@ -111,8 +117,8 @@
   @GetMapping("/sendmail")
   @Operation(summary = "sendmail", description = "sendmail")
   public R<Void> sendmail(String code) throws IOException, MessagingException {
   public R<Void> sendmail(String from,String to,String subject,String content) throws IOException, MessagingException {
      this.mailService.send(from,to,null,null,subject,content,null);
      return R.success();
   }
@@ -122,6 +128,51 @@
      return R.success();
   }
   @GetMapping("/scanfile")
   public void scanFile(){
      machineFileScanService.scanMachineFile();
   }
   @GetMapping("/notify")
   public void emailNotify(){
      SOAPException s;
      notifyTask.execute();
   }
   @GetMapping("/movehis")
   public void moveHis(Date time){
      //format:?time=2025-09-16%2010:11:10
      nodeHisService.mergeNodeToHisGeTime(time);
   }
   @GetMapping("/mes-sync")
   public void mesSync(){
      mesSyncService.syncToMes();
   }
   @GetMapping("/publish-cure")
   public void publishCure(){
      CureFinishedEvent e = new CureFinishedEvent(this,"0000000173");
      SpringUtil.publishEvent(e);
   }
   @GetMapping("/call-mes")
   public void callMess(){
      JSONObject jsonObject = new JSONObject();
      JSONArray dataList = new JSONArray();
      JSONObject item = new JSONObject();
      item.put("operationId","id1");
      item.put("programNo","00001");
      item.put("curedTime", DateUtil.formatDateTime(new Date()));
      dataList.add(item);
      jsonObject.put("batchData", dataList);
      log.info("mestest data:{}",jsonObject);
      int code = mesSyncService.postData(jsonObject);
      log.info("mestest response:{}",code);
   }
}