|
@@ -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;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|