| | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | |
| | |
| | | battInfMapper.insert(battinf); |
| | | battInfMapper.insertUserBattgroupBaojigroupBattgroup(battinf.getStationId(),battinf.getBattGroupId()); |
| | | battInfMapper.insertUserBattgroupBaojigroupBattgroupSelect(battinf.getStationId(),battinf.getBattGroupId(),userId); |
| | | run_cmd(); |
| | | return new Response().set(1,battinf,"添加成功"); |
| | | } |
| | | |
| | | |
| | | //启动创建数据库的jar文件 |
| | | public static void run_cmd() { |
| | | //String path=System.getProperty("user.dir"); //myeclipse中获取的目录(获取到的是tomcat/bin)和分离项目获取到的路径(tomcat)不一样 |
| | | String fullRealPath = ActionUtil.getSession().getServletContext().getRealPath("/"); |
| | | String path = fullRealPath.split(File.separator+"webapps")[0]; |
| | | System.out.println("tomcat的路径为"+path); |
| | | //识别服务器的系统类型 |
| | | String OS = System.getProperty("os.name").toLowerCase(); |
| | | // System.out.println(OS); |
| | | String strcmd=""; |
| | | if(OS.contains("window")) { |
| | | String realapth=path.substring(0,path.lastIndexOf("\\")); |
| | | strcmd="cmd /c start "+realapth+"/webapps/cmd_BTSE_DB_Builder.cmd"; |
| | | String batPath = realapth+"/webapps/cmd_BTSE_DB_Builder.cmd"; |
| | | File f = new File(path); |
| | | //System.out.println("File :"+f.getParentFile().getAbsolutePath()+File.separator+"Batt_MS_FBSDEV_X64/Batt_MS_FBSDEV/"+"cmd_BTSE_DB_Builder.cmd"); |
| | | //batPath = f.getParentFile().getAbsolutePath()+File.separator+"Batt_MS_FBSDEV_X64/Batt_MS_FBSDEV/"+"cmd_BTSE_DB_Builder.cmd"; |
| | | String jarPath = ""; |
| | | if(path.endsWith("bin")){ |
| | | f = f.getParentFile(); |
| | | } |
| | | |
| | | jarPath = f.getParentFile().getAbsolutePath()+File.separator+"Batt_MS_FBSDEV_X64/Batt_MS_FBSDEV/"+"BTSE_DB_Builder.exe"; //主程序中jar的目录 |
| | | System.out.println("jar执行文件全路径为:"+jarPath); |
| | | //strcmd = "cmd /c start "+batPath; |
| | | strcmd = ("cmd /c start ")+jarPath.replaceAll(" ", "\" \""); |
| | | }else { |
| | | strcmd="java -jar /app/BTSE_DB_Builder.jar"; |
| | | } |
| | | //System.out.println(path); |
| | | //修复绝对路径中存在空格时执行不成功bug |
| | | Process child = null; |
| | | InputStream in = null; |
| | | try { |
| | | //System.out.println(strcmd); |
| | | child = Runtime.getRuntime().exec(strcmd); |
| | | in = child.getInputStream(); |
| | | int c; |
| | | while ((c = in.read()) != -1) { |
| | | //System.out.print((char)c); |
| | | } |
| | | in.close(); |
| | | try { |
| | | child.waitFor(); |
| | | } catch (InterruptedException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | //System.out.println("Run Bat OK...."); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | public Response searchInfo(int pageNum,int pageSize,Integer userId,String stationName1,String stationName2,String stationName5,String stationName3){ |
| | |
| | | |
| | | public Response update(Battinf battinf){ |
| | | if (battInfMapper.updateById(battinf)>0){ |
| | | run_cmd(); |
| | | return new Response().set(1,"更新成功"); |
| | | }else { |
| | | return new Response().set(0,"更新失败"); |