Search in sources :

Example 11 with CustomException

use of com.hfut.exception.CustomException in project Workload by amoxu.

the class RemoteTeachServiceImpl method insertLoad.

@Override
public boolean insertLoad(RemoteTeachWorkload workload) throws Exception {
    try {
        int people = workload.getPeople();
        // 46个人为一个班,每增加一个班增加0.1系数
        workload.setClassCoefficient((float) (Math.round(people / 46F) * 0.1 + 0.9));
        // 计算工作量 课时
        workload.setWorkload(workload.getPeriod() * workload.getClassCoefficient());
        // 计算酬金
        workload.setMoney(PropertyUtil.getAllowance() * workload.getWorkload());
    } catch (NullPointerException | DataIntegrityViolationException nop) {
        throw new CustomException("请输入班级人数,学时,教学班");
    }
    if (workloadMapper.insertSelective(workload) == 0) {
        return false;
    }
    return true;
}
Also used : CustomException(com.hfut.exception.CustomException) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException)

Example 12 with CustomException

use of com.hfut.exception.CustomException in project Workload by amoxu.

the class ToolKit method getFileFromBytes.

/**
 * 根据字节数组获取File
 *
 * @param b          字节数组
 * @param outputFile 输出的路径(保存路径)
 * @return
 */
public static File getFileFromBytes(byte[] b, String outputFile) throws CustomException {
    BufferedOutputStream stream = null;
    File file;
    try {
        file = new File(outputFile);
        FileOutputStream fstream = new FileOutputStream(file);
        stream = new BufferedOutputStream(fstream);
        stream.write(b);
    } catch (Exception e) {
        throw new CustomException("文件保存出错" + e);
    } finally {
        if (stream != null) {
            try {
                stream.close();
            } catch (IOException e1) {
                throw new CustomException("文件流关闭出错");
            }
        }
    }
    return file;
}
Also used : FileOutputStream(java.io.FileOutputStream) CustomException(com.hfut.exception.CustomException) IOException(java.io.IOException) BufferedOutputStream(java.io.BufferedOutputStream) File(java.io.File) IOException(java.io.IOException) CustomException(com.hfut.exception.CustomException)

Aggregations

CustomException (com.hfut.exception.CustomException)12 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)6 User (com.hfut.entity.User)5 AjaxResult (com.hfut.entity.AjaxResult)4 Subject (org.apache.shiro.subject.Subject)4 File (java.io.File)3 IOException (java.io.IOException)3 BufferedOutputStream (java.io.BufferedOutputStream)2 FileInputStream (java.io.FileInputStream)2 UserExample (com.hfut.entity.UserExample)1 Transient (java.beans.Transient)1 BufferedInputStream (java.io.BufferedInputStream)1 FileOutputStream (java.io.FileOutputStream)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 List (java.util.List)1 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)1 XSSFWorkbook (org.apache.poi.xssf.usermodel.XSSFWorkbook)1