songshuai 5 years ago
parent
commit
00f861928b

+ 5 - 0
pom.xml

@@ -135,6 +135,11 @@
 			<version>3.13</version>
 		</dependency>
 		<dependency>
+			<groupId>net.sourceforge.jexcelapi</groupId>
+			<artifactId>jxl</artifactId>
+			<version>2.6.10</version>
+		</dependency>
+		<dependency>
 			<groupId>ws.schild</groupId>
 			<artifactId>jave-core</artifactId>
 			<version>2.4.4</version>

+ 0 - 15
src/main/java/cn/efunbox/audio/entity/res/ResWare.java

@@ -55,21 +55,6 @@ public class ResWare {
     @Transient
     private String contentPicUrl;
 
-    @Column(name = "price")
-    private String price;
-
-    @Column(name = "play_count")
-    private String playCount;
-
-    @Column(name = "sort")
-    private String sort;
-
-    @Column(name = "type_id")
-    private String typeId;
-
-    @Column(name = "publish_time")
-    private String publishTime;
-
     @Column(name = "is_del")
     private String isDel;
 

+ 2 - 2
src/main/java/cn/efunbox/audio/impl/res/ResWareServiceImpl.java

@@ -63,9 +63,9 @@ public class ResWareServiceImpl implements ResWareService {
               SortHelper.sortMap2Sort(
                     new LinkedHashMap<String, BaseOrderEnum>() {{
                         if(StringUtils.isBlank(order) || "asc".equals(order)){
-                            put("sort", BaseOrderEnum.ASC);
+                            put("chapterRanking", BaseOrderEnum.ASC);
                         }else{
-                            put("sort",BaseOrderEnum.DESC);
+                            put("chapterRanking",BaseOrderEnum.DESC);
                         }
                     }}
               )

+ 62 - 0
src/main/java/cn/efunbox/audio/utils/DBhepler.java

@@ -0,0 +1,62 @@
+package cn.efunbox.audio.utils;
+
+import java.sql.*;
+
+public class DBhepler {
+	/*String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
+	String url = "jdbc:sqlserver://127.0.0.1;DatabaseName=Mobile";*/
+	
+	String driver = "com.mysql.jdbc.Driver";
+	String url = "jdbc:mysql://192.168.1.96:3306/efunbox_audio?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&allowMultiQueries=true";
+//	String url = "jdbc:mysql://192.168.1.96:3306/audio_bak?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&allowMultiQueries=true";
+
+	
+	Connection con = null;
+	ResultSet res = null;
+
+	public void DataBase() {
+			try {
+				Class.forName(driver);
+				con = DriverManager.getConnection(url, "root", "Efunbox^^2015$");
+			} catch (ClassNotFoundException e) {
+				e.printStackTrace();
+			} catch (SQLException e) {
+				e.printStackTrace();
+			}
+	}
+
+	public ResultSet  Search(String sql, String str[]) {
+		DataBase();
+		try {
+			PreparedStatement pst =con.prepareStatement(sql);
+			if (str != null) {
+				for (int i = 0; i < str.length; i++) {
+					pst.setString(i + 1, str[i]);
+				}
+			}
+			res = pst.executeQuery();
+
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+		return res;
+	}
+
+	public int AddU(String sql, String str[]) {
+		int a = 0;
+		DataBase();
+		try {
+			PreparedStatement pst = con.prepareStatement(sql);
+			if (str != null) {
+				for (int i = 0; i < str.length; i++) {
+					pst.setString(i + 1, str[i]);
+				}
+			}
+			a = pst.executeUpdate();
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+		return a;
+	}
+
+}

+ 226 - 0
src/main/java/cn/efunbox/audio/utils/DateUtil.java

@@ -0,0 +1,226 @@
+package cn.efunbox.audio.utils;
+
+
+import org.apache.commons.lang3.time.DateFormatUtils;
+import org.apache.commons.lang3.time.DateUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.Locale;
+
+/**
+ * 日期工具类
+ */
+public class DateUtil {
+    private static Logger log = LoggerFactory.getLogger(DateUtil.class);
+
+    private static final String DEFAULT_PATTERN = "yyyy-MM-dd";
+    /**
+     * 一天的毫秒数
+     */
+    public static long TIME_OF_ONE_DAY = 24 * 60 * 60 * 1000;
+    /**
+     * 将日期转换为字符串
+     *
+     * @return
+     */
+    public static String dateFormat() {
+        return dateFormat(new Date(), "yyyy-MM-dd HH:mm:ss");
+    }
+
+    public static String dateFormat(String pattern) {
+        return dateFormat(new Date(), pattern);
+    }
+
+    public static String dateFormat(Date date, String pattern) {
+        SimpleDateFormat sdf = new SimpleDateFormat(pattern);
+        return sdf.format(date);
+    }
+
+    /**
+     * 字符串转换为日期
+     *
+     * @param source
+     * @return
+     * @throws ParseException
+     */
+    public static Date StrToDate(String source) throws ParseException {
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        return sdf.parse(source);
+    }
+
+    public static Date StrToDate(String source, String pattern) throws ParseException {
+        SimpleDateFormat sdf = new SimpleDateFormat(pattern);
+        return sdf.parse(source);
+    }
+
+    /**
+     * 增加年
+     *
+     * @param date
+     * @param i
+     * @return
+     */
+    public static Date addYears(Date date, int i) {
+        return DateUtils.addYears(date, i);
+    }
+
+    /**
+     * 增加月
+     *
+     * @param date
+     * @param i
+     * @return
+     */
+    public static Date addMonths(Date date, int i) {
+        return DateUtils.addMonths(date, i);
+    }
+
+    /**
+     * 增加小时
+     *
+     * @param date
+     * @param amount
+     * @return
+     */
+    public static Date addHours(Date date, int amount) {
+        return DateUtils.addHours(date, amount);
+    }
+
+    /**
+     * 增加天数
+     *
+     * @param date
+     * @param amount
+     * @return
+     */
+    public static Date addDays(Date date, int amount) {
+        return DateUtils.addDays(date, amount);
+    }
+
+    /**
+     * 日期格式换行为GMT格式
+     *
+     * @param date
+     * @return
+     */
+    public static String toGMTString(Date date) {
+        SimpleDateFormat df = new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss z", Locale.UK);
+        df.setTimeZone(new java.util.SimpleTimeZone(0, "GMT"));
+        return df.format(date);
+    }
+
+    /**
+     * 获取传入日期和当前当前日期相隔分钟数
+     *
+     * @param date
+     * @return
+     * @throws ParseException
+     */
+    public static int getDateDiffMinutes(String date){
+        long intervalMilli = 0;
+        try {
+            long now = System.currentTimeMillis();
+            long ago = StrToDate(date, "yyyy-MM-dd HH:mm:ss").getTime();
+
+            intervalMilli = now - ago;
+            if (intervalMilli < 0) {
+                return 0;
+            }
+        }catch (Exception e){
+            e.printStackTrace();
+            return 0;
+        }
+        return (int)(intervalMilli / (60 * 1000));
+    }
+
+    /**
+     * 获取传入日期和当前当前日期相隔天数
+     *
+     * @param date
+     * @return
+     * @throws ParseException
+     */
+    public static int getDateDiffDays(String date) throws ParseException {
+        long now = new Date().getTime();
+        long ago = StrToDate(date, "yyyy-MM-dd").getTime();
+
+        long intervalMilli = now - ago;
+        if (intervalMilli < 0) {
+            return 0;
+        }
+        return (int) (intervalMilli / (24 * 3600 * 1000));
+    }
+
+    /**
+     * 获取传入日期和当前当前日期相隔年数
+     *
+     * @param date
+     * @return
+     * @throws ParseException
+     */
+    public static int getDateDiffYears(Date date) {
+        Calendar cal1 = Calendar.getInstance();
+        cal1.setTime(date);
+
+        Calendar cal2 = Calendar.getInstance();
+        cal2.setTime(new Date());
+
+        return cal2.get(Calendar.YEAR) - cal1.get(Calendar.YEAR);
+    }
+
+    /**
+     * 将DATE类型转成String类型,pattern默认为yyyy-MM-dd
+     *
+     * @return
+     */
+    public static String getDateStr() {
+        Date  date = new Date();
+        SimpleDateFormat formater = new SimpleDateFormat(DEFAULT_PATTERN);
+        return formater.format(date);
+    }
+
+    public static String getPreDateStr() {
+        Date  date = new Date(System.currentTimeMillis() - TIME_OF_ONE_DAY);
+        SimpleDateFormat formater = new SimpleDateFormat(DEFAULT_PATTERN);
+        return formater.format(date);
+    }
+
+    public static String formatPreDayEndTime() {
+        Date  date = new Date(System.currentTimeMillis() - TIME_OF_ONE_DAY);
+        return  DateFormatUtils.format(date, "yyyy-MM-dd 23:59:59");
+    }
+
+
+
+    public static String formatPreDayStartTime() {
+        Date  date = new Date(System.currentTimeMillis() - TIME_OF_ONE_DAY);
+        return  DateFormatUtils.format(date, "yyyy-MM-dd 00:00:00");
+    }
+
+    public static Date getPreDayStartTime() {
+
+        String format = DateFormatUtils.format(new Date(System.currentTimeMillis() - TIME_OF_ONE_DAY), "yyyy-MM-dd 00:00:00");
+        java.text.DateFormat dfNew = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        try {
+            return dfNew.parse(format);
+        } catch (ParseException e) {
+            e.printStackTrace();
+        }
+        return new Date();
+    }
+
+
+    public static void main(String[] args) {
+        Date preDayStartTime = getPreDayStartTime();
+        //System.out.println(preDayStartTime);
+
+        //System.out.println(formatPreDayEndTime());
+        System.out.println(dateFormat());
+    }
+
+}

+ 211 - 0
src/main/java/cn/efunbox/audio/utils/ExcelUtil.java

@@ -0,0 +1,211 @@
+package cn.efunbox.audio.utils;
+
+import cn.efunbox.audio.impl.AudioServiceImpl;
+import jxl.Sheet;
+import jxl.Workbook;
+import org.apache.commons.lang3.StringUtils;
+
+import java.io.File;
+import java.util.Objects;
+
+public class ExcelUtil {
+
+
+    /**
+     * 杭研导数据
+     * @param name
+     */
+    public static void hyImportExcel(String name){
+
+        try {
+            Workbook rwb = Workbook.getWorkbook(new File(name));
+            Sheet rs1 = rwb.getSheet("分类列表");
+
+            if (Objects.nonNull(rs1)) {
+
+                int clos1 = rs1.getColumns();
+                int rows1 = rs1.getRows();
+
+                System.out.println("分类=》 cols:" + clos1 + " rows:" + rows1);
+
+                for (int i = 3; i < rows1; i++) {
+
+                    long id = SnowflakeIdUtil.getSnowflakeIdUtil().nextId();
+
+                    String typeId = rs1.getCell(0, i).getContents();
+                    String typeName = rs1.getCell(1, i).getContents();
+                    String parentId = rs1.getCell(2, i).getContents();
+                    String sort = rs1.getCell(3, i).getContents();
+
+                    if (StringUtils.isNotBlank(typeName)) {
+
+                        /***************************分类****************************/
+                        DBhepler db = new DBhepler();
+                        System.out.println("分类入库"+ typeName);
+                        String sql = "insert into res_category (type_id,type_name,parent_id,sort,type_updatetime,is_del,renewal) value (?,?,?,?,?,?,?)";
+                        String[] str = new String[]{id +"", typeName, parentId,sort, DateUtil.dateFormat(),"0","0"};
+                        db.AddU(sql, str);
+
+                        /***************************专辑****************************/
+                        hyImportExcel_Album(rwb,id,typeId);
+                    }
+
+                }
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * 导入专辑数据
+     * @Param parentId Id
+     * @Pararm parentTypeId  分类Id
+     */
+    public static void hyImportExcel_Album( Workbook rwb,long parentId,String parentTypeId){
+        Sheet rs1 = rwb.getSheet("专辑列表");
+
+        if (Objects.nonNull(rs1)) {
+
+            int clos1 = rs1.getColumns();
+            int rows1 = rs1.getRows();
+
+            System.out.println("专辑=》 cols:" + clos1 + " rows:" + rows1);
+
+            for (int i = 3; i < rows1; i++) {
+
+                String typeId = rs1.getCell(16, i).getContents();
+                if(typeId.equals(parentTypeId)){
+                    long id = SnowflakeIdUtil.getSnowflakeIdUtil().nextId();
+
+                    String content_id = rs1.getCell(0, i).getContents();
+                    String content_name = rs1.getCell(1, i).getContents();
+                    String shortrecommend = rs1.getCell(2, i).getContents();
+                    String longrecommend = rs1.getCell(3, i).getContents();
+                    //String author = rs1.getCell(4, i).getContents();
+                    //String reader_name = rs1.getCell(5, i).getContents();
+                    String content_pic_url = "https://ai-admin-image.ai160.com"+rs1.getCell(6, i).getContents();
+                    String chapter_count = rs1.getCell(7, i).getContents();
+                    String cooperation_pay_mode = rs1.getCell(8, i).getContents();
+                    String pay_mode = rs1.getCell(9, i).getContents();
+                    String price = rs1.getCell(11, i).getContents();
+                    String playcount = rs1.getCell(12, i).getContents();
+                    String media_type = rs1.getCell(13, i).getContents();
+                    String publish_time = rs1.getCell(14, i).getContents();
+                    String sort = rs1.getCell(15, i).getContents();
+
+                    if (StringUtils.isNotBlank(content_name)) {
+
+                        /***************************专辑****************************/
+                        DBhepler db = new DBhepler();
+                        System.out.println("专辑入库"+ content_name);
+                        String sql = "insert into res_album (content_id,content_name,shortrecommend,longrecommend" +
+                                                            ",content_pic_url,chapter_count,cooperation_pay_mode,pay_mode" +
+                                                            ",price,playcount,media_type,sort,type_id,publish_time,is_del,renewal" +
+                                       ") value (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
+                        String[] str = new String[]{id +"", content_name, shortrecommend,longrecommend,content_pic_url,chapter_count,cooperation_pay_mode,pay_mode,price,playcount,media_type,sort,parentId+"",publish_time,"0","0"};
+                        db.AddU(sql, str);
+
+
+                        /***************************节目****************************/
+                        hyImportExcel_Ware(rwb,id,content_id);
+                    }
+
+                }
+            }
+        }
+    }
+
+    /**
+     * 导入节目数据
+     * @param rwb
+     * @param parentId
+     * @param parentContentId
+     */
+    public static void hyImportExcel_Ware( Workbook rwb,long parentId,String parentContentId){
+        Sheet rs1 = rwb.getSheet("专辑节目");
+
+        if (Objects.nonNull(rs1)) {
+
+            int clos1 = rs1.getColumns();
+            int rows1 = rs1.getRows();
+
+            System.out.println("节目=》 cols:" + clos1 + " rows:" + rows1);
+
+            for (int i = 3; i < rows1; i++) {
+
+                String contentId = rs1.getCell(8, i).getContents();
+                if (contentId.equals(parentContentId)) {
+                    long id = SnowflakeIdUtil.getSnowflakeIdUtil().nextId();
+
+                    String chapter_name = rs1.getCell(1, i).getContents();
+                    String sort = rs1.getCell(2, i).getContents();
+                    String down_load_flag = rs1.getCell(3, i).getContents();
+                    String chapter_pic_url = "https://ai-admin-image.ai160.com"+rs1.getCell(4, i).getContents();
+                    //String chapter_recommend = rs1.getCell(5, i).getContents();
+                    String pay_mode = rs1.getCell(6, i).getContents();
+                    String media_type = rs1.getCell(7, i).getContents();
+                    String content_id = rs1.getCell(8, i).getContents();
+                    String chapter_url = rs1.getCell(9, i).getContents();
+                    String chapter_duration = secToTime(AudioServiceImpl.getMicrosecondLength(chapter_url));
+
+                    if (StringUtils.isNotBlank(chapter_name)) {
+
+                        /***************************节目****************************/
+                        DBhepler db = new DBhepler();
+                        System.out.println("节目入库" + chapter_name);
+                        String sql = "insert into res_ware (chapter_id,chapter_name,chapter_ranking,chapter_duration,down_load_flag,chapter_pic_url" +
+                                                   ",chapter_url,pay_mode,media_type,content_id," +
+                                                    "is_del,renewal" +
+                                      ") value (?,?,?,?,?,?,?,?,?,?,?,?)";
+                        String[] str = new String[]{id + "", chapter_name, sort, chapter_duration, down_load_flag, chapter_pic_url, chapter_url, pay_mode, media_type, parentId+"", "0", "0"};
+                        db.AddU(sql, str);
+                    }
+
+                }
+            }
+        }
+    }
+
+
+    public static void main(String[] args) {
+        String pathName = "C:\\Users\\Administrator\\Desktop\\移动1.xls";
+        //hyImportExcel(pathName);
+        System.out.println(AudioServiceImpl.getMicrosecondLength("https://ai-admin-audio.ai160.com/audio/050/05007001/05007001004.mp3"));
+        System.out.println(secToTime(225));
+    }
+
+    public static String secToTime(long time) {
+        String timeStr = null;
+        long hour = 0;
+        long minute = 0;
+        long second = 0;
+        if (time <= 0)
+            return "00:00:00";
+        else {
+            minute = time / 60;
+            if (minute < 60) {
+                second = time % 60;
+                timeStr = "00:"+unitFormat(minute) + ":" + unitFormat(second);
+            } else {
+                hour = minute / 60;
+                if (hour > 99)
+                    return "99:59:59";
+                minute = minute % 60;
+                second = time - hour * 3600 - minute * 60;
+                timeStr = unitFormat(hour) + ":" + unitFormat(minute) + ":" + unitFormat(second);
+            }
+        }
+        return timeStr;
+    }
+
+    public static String unitFormat(long i) {
+        String retStr = null;
+        if (i >= 0 && i < 10)
+            retStr = "0" + Long.toString(i);
+        else
+            retStr = "" + i;
+        return retStr;
+    }
+
+}