Search in sources :

Example 81 with JSONArray

use of net.sf.json.JSONArray in project pmph by BCSquad.

the class BookServiceImpl method AbuttingJoint.

@Override
public String AbuttingJoint(String[] vns, Integer type) throws CheckedServiceException {
    String result = "SUCCESS";
    Const.AllSYNCHRONIZATION = 1;
    int num = vns.length / 100;
    for (int i = 0; i < vns.length; i++) {
        Book oldBook = bookDao.getBookByBookVn(vns[i]);
        JSONObject ot = new JSONObject();
        if (type == 0) {
            // 商城发送修改的请求
            if (ObjectUtil.isNull(oldBook)) {
                continue;
            }
        }
        try {
            // System.out.println("第"+(i+1)+"条数据,本版号为"+vns[i]+" 共"+vns.length+"条");
            ot = PostBusyAPI(vns[i]);
            if (null != ot && "1".equals(ot.getJSONObject("RESP").getString("CODE"))) {
                JSONArray array = ot.getJSONObject("RESP").getJSONObject("responseData").getJSONArray("results");
                if (array.size() > 0) {
                    Book book = BusyResJSONToModel(array.getJSONObject(0), null);
                    // 获取到图书详情将其存入到图书详情表中
                    String content = book.getContent();
                    if (ObjectUtil.isNull(oldBook)) {
                        book.setScore(9.0);
                        book.setType(1L);
                        bookDao.addBook(book);
                        // Q93
                        book.setIsNew(true);
                        bookDao.updateBook(book);
                        BookDetail bookDetail = new BookDetail(book.getId(), content);
                        bookDetailDao.addBookDetail(bookDetail);
                    } else {
                        Book newBook = new Book(book.getBookname(), book.getIsbn(), book.getSn(), book.getAuthor(), book.getPublisher(), book.getLang(), book.getRevision(), book.getType(), book.getPublishDate(), book.getReader(), book.getPrice(), book.getScore(), book.getBuyUrl(), book.getImageUrl(), book.getPdfUrl(), book.getClicks(), book.getComments(), book.getLikes(), book.getBookmarks(), book.getIsStick(), book.getSort(), book.getDeadlineStick(), book.getIsNew(), book.getSortNew(), book.getDeadlineNew(), book.getIsPromote(), book.getSortPromote(), book.getDeadlinePromote(), book.getIsKey(), book.getSortKey(), book.getSales(), book.getIsOnSale(), book.getGmtCreate(), book.getGmtUpdate());
                        newBook.setId(oldBook.getId());
                        bookDao.updateBook(newBook);
                        BookDetail bookDetail = new BookDetail(oldBook.getId(), content);
                        bookDetailDao.updateBookDetailByBookId(bookDetail);
                    }
                }
                if ((i + 1) >= num * (Const.AllSYNCHRONIZATION + 1)) {
                    Const.AllSYNCHRONIZATION++;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            result = "FAIL";
        }
    }
    return result;
}
Also used : JSONObject(net.sf.json.JSONObject) Book(com.bc.pmpheep.back.po.Book) JSONArray(net.sf.json.JSONArray) BookDetail(com.bc.pmpheep.back.po.BookDetail) TooManyResultsException(org.apache.ibatis.exceptions.TooManyResultsException) OfficeXmlFileException(org.apache.poi.poifs.filesystem.OfficeXmlFileException) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException)

Example 82 with JSONArray

use of net.sf.json.JSONArray in project pmph by BCSquad.

the class TopicServiceImpl method updateByErp.

@Override
public void updateByErp() {
    InfoWorking bookInfoWorking = new InfoWorking();
    JSONArray topicInfo = bookInfoWorking.listTopicInfo();
    Long[] recordIds = new Long[topicInfo.size()];
    Integer total = 0;
    for (int i = 0; i < topicInfo.size(); i++) {
        JSONObject job = topicInfo.getJSONObject(i);
        String auditstates = job.getString("auditstates");
        String topicnumber = job.getString("topicnumber");
        String topicname = job.getString("topicname");
        String vn = job.getString("editionnum");
        recordIds[i] = job.getLong("record_id");
        switch(auditstates) {
            case "11":
                auditstates = "选题通过";
                break;
            case "12":
                auditstates = "转稿";
                break;
            case "13":
                auditstates = "发稿";
                break;
            case "14":
                auditstates = "即将出书";
                break;
            default:
                auditstates = "状态出现错误";
                break;
        }
        Topic topic = new Topic();
        topic.setNote(auditstates);
        topic.setTn(topicnumber);
        topic.setBookname(topicname);
        topic.setVn(vn);
        total += topicDao.updateByVn(topic);
    }
    if (total == topicInfo.size()) {
        bookInfoWorking.updateTopic(recordIds);
    } else {
        throw new CheckedServiceException(CheckedExceptionBusiness.TOPIC, CheckedExceptionResult.NULL_PARAM, "从erp更新教材申报信息失败请查看原因");
    }
}
Also used : JSONObject(net.sf.json.JSONObject) JSONArray(net.sf.json.JSONArray) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) InfoWorking(com.bc.pmpheep.erp.service.InfoWorking)

Example 83 with JSONArray

use of net.sf.json.JSONArray in project pmph by BCSquad.

the class MigrationBook method clearBook.

protected void clearBook() {
    StringBuilder sns = new StringBuilder();
    InputStream is;
    Workbook workbook;
    String path = this.getClass().getClassLoader().getResource("book.xlsx").getPath();
    try {
        is = new FileInputStream(path);
    } catch (IOException e) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.FILE_CREATION_FAILED, "未找到模板文件");
    }
    try {
        workbook = new XSSFWorkbook(is);
    } catch (IOException e) {
        throw new CheckedServiceException(CheckedExceptionBusiness.EXCEL, CheckedExceptionResult.ILLEGAL_PARAM, "读取文件失败");
    }
    Map<String, MaterialType> snsAndMaterNames = new HashMap<String, MaterialType>(16);
    for (int numSheet = 0; numSheet < workbook.getNumberOfSheets(); numSheet++) {
        Sheet sheet = workbook.getSheetAt(numSheet);
        if (ObjectUtil.isNull(sheet)) {
            continue;
        }
        for (int rowNum = 1; rowNum <= sheet.getLastRowNum(); rowNum++) {
            Row row = sheet.getRow(rowNum);
            Cell sn = row.getCell(1);
            if (ObjectUtil.notNull(sn) && !"".equals(sn.toString())) {
                MaterialType materialType = new MaterialType();
                sns.append(",'" + sn.toString().replace(".0", "") + "'");
                materialType.setTypeName(String.valueOf(row.getCell(2)));
                materialType.setId(Long.valueOf(row.getCell(3).toString().replace(".0", "")));
                snsAndMaterNames.put(sn.toString().replace(".0", ""), materialType);
            }
        }
    }
    bookDao.deleted();
    bookDetailDao.deleteBookDetailByBookIds();
    bookDao.deletedBookSupport();
    bookCorrectionDao.deleteBookCoorrectionTrackByBookIds();
    bookEditorDao.deleteBookEditorByBookIds();
    bookUserCommentDao.deleteBookUserCommentBookIds();
    bookUserLikeDao.deleteBookUserLikeByBookIds();
    bookUserMarkDao.deleteBookUserMarkByBookIds();
    bookVideoDao.deleteBookVideoByBookIds();
    // 同步更新或者插入书籍
    String sn = sns.toString().substring(1);
    JSONArray bookInfo = new InfoWorking().listBook(sn);
    // 版本号
    String[] vns = new String[bookInfo.size()];
    for (int i = 0; i < bookInfo.size(); i++) {
        JSONObject job = bookInfo.getJSONObject(i);
        vns[i] = job.getString("editionnum");
    }
    bookService.AbuttingJoint(vns, 1);
    // 初始化教材社区数据
    Map<String, Long> materNamesAndIds = new HashMap<String, Long>(16);
    for (int i = 0; i < bookInfo.size(); i++) {
        JSONObject job = bookInfo.getJSONObject(i);
        // 本版号
        String bookVn = job.getString("editionnum");
        // 书号
        String bookSn = job.getString("booknumber");
        String materName = snsAndMaterNames.get(bookSn).getTypeName();
        Long type = snsAndMaterNames.get(bookSn).getId();
        if (null == materName || "".equals(materName.trim())) {
            continue;
        }
        Long materId = materNamesAndIds.get(materName);
        if (null == materId) {
            materId = Long.MAX_VALUE - i;
            Content content = new Content(materName);
            content = contentService.add(content);
            CmsContent cmsContent = new CmsContent();
            cmsContent.setParentId(0L);
            cmsContent.setPath("0");
            cmsContent.setMid(content.getId());
            cmsContent.setCategoryId(3L);
            cmsContent.setTitle(materName);
            cmsContent.setAuthorType(new Short("0"));
            cmsContent.setAuthorId(342L);
            cmsContent.setIsPublished(true);
            cmsContent.setAuthStatus(new Short("2"));
            cmsContent.setAuthDate(DateUtil.date2Str(new Date()));
            cmsContent.setAuthUserId(342L);
            cmsContent.setGmtCreate(DateUtil.getCurrentTime());
            cmsContent.setGmtUpdate(DateUtil.getCurrentTime());
            cmsContent.setIsMaterialEntry(true);
            cmsContent.setMaterialId(materId);
            cmsContentService.addCmsContent(cmsContent);
            materNamesAndIds.put(materName, materId);
        }
        // 更新书籍
        Book book = bookDao.getBookByVn2(bookVn);
        if (null != book) {
            book.setType(type);
            book.setMaterialId(materId);
            book.setSn(bookSn);
            bookDao.updateBook(book);
        }
    }
}
Also used : HashMap(java.util.HashMap) InfoWorking(com.bc.pmpheep.erp.service.InfoWorking) MaterialType(com.bc.pmpheep.back.po.MaterialType) Book(com.bc.pmpheep.back.po.Book) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Cell(org.apache.poi.ss.usermodel.Cell) CmsContent(com.bc.pmpheep.back.po.CmsContent) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) JSONArray(net.sf.json.JSONArray) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) IOException(java.io.IOException) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Workbook(org.apache.poi.ss.usermodel.Workbook) FileInputStream(java.io.FileInputStream) Date(java.util.Date) JSONObject(net.sf.json.JSONObject) CmsContent(com.bc.pmpheep.back.po.CmsContent) Content(com.bc.pmpheep.general.po.Content) Row(org.apache.poi.ss.usermodel.Row) Sheet(org.apache.poi.ss.usermodel.Sheet)

Example 84 with JSONArray

use of net.sf.json.JSONArray in project pmph by BCSquad.

the class SqlHelper method executeQuery.

/**
 * 提供查询方法
 *
 * @param sql
 *            sql语句
 * @param parameters
 *            给问号赋值的参数组
 * @return {@link ArrayList}
 */
public static JSONArray executeQuery(String sql, String[] parameters) {
    JSONArray al = new JSONArray();
    try {
        con = DBUtil.getConnection();
        ps = con.prepareStatement(sql);
        // 给sql语句中的问号赋值
        if (parameters != null) {
            for (int i = 0; i < parameters.length; i++) {
                ps.setObject(i + 1, parameters[i]);
            }
        }
        rs = ps.executeQuery();
        // 得到结果集(rs)的结构
        ResultSetMetaData rsmd = rs.getMetaData();
        // 通过rsmd可以得到该结果集有多少列
        int columnNum = rsmd.getColumnCount();
        // 从rs中取出数据,并且封装到ArrayList中
        while (rs.next()) {
            JSONObject object = new JSONObject();
            for (int i = 0; i < columnNum; i++) {
                object.put(rsmd.getColumnName(i + 1), rs.getObject((i + 1)) == null ? "" : rs.getObject((i + 1)));
            }
            al.add(object);
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        DBUtil.close(rs, ps, con);
    }
    return al;
}
Also used : ResultSetMetaData(java.sql.ResultSetMetaData) JSONObject(net.sf.json.JSONObject) JSONArray(net.sf.json.JSONArray)

Example 85 with JSONArray

use of net.sf.json.JSONArray in project pmph by BCSquad.

the class InfoWorking method listBookInfo.

/**
 * 功能描述:从erp中获取所有书籍本版号
 *
 * @return
 */
public String[] listBookInfo() {
    JSONArray bookInfo = listBookVn("i_bookinfo");
    String[] vns = new String[bookInfo.size()];
    for (int i = 0; i < bookInfo.size(); i++) {
        JSONObject job = bookInfo.getJSONObject(i);
        vns[i] = job.getString("editionnum");
    }
    return vns;
}
Also used : JSONObject(net.sf.json.JSONObject) JSONArray(net.sf.json.JSONArray)

Aggregations

JSONArray (net.sf.json.JSONArray)144 JSONObject (net.sf.json.JSONObject)109 ArrayList (java.util.ArrayList)31 IOException (java.io.IOException)22 HashMap (java.util.HashMap)20 File (java.io.File)16 Test (org.junit.Test)15 JSON (net.sf.json.JSON)14 Map (java.util.Map)12 JsonConfig (net.sf.json.JsonConfig)10 URISyntaxException (java.net.URISyntaxException)9 URL (java.net.URL)9 URI (java.net.URI)8 SimpleChartData (com.sohu.cache.web.chart.model.SimpleChartData)6 Date (java.util.Date)6 CheckedServiceException (com.bc.pmpheep.service.exception.CheckedServiceException)5 OutputStream (java.io.OutputStream)5 List (java.util.List)5 CAFunctorFactory (edu.uiuc.ncsa.myproxy.oa4mp.oauth2.claims.CAFunctorFactory)4 OA2Client (edu.uiuc.ncsa.security.oauth_2_0.OA2Client)4