Java tutorial
/* * Copyright (c) 2013 ????www.hrbesd.com. All rights reserved. * * HRBESD PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ package com.esd.ps; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.text.DecimalFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.multipart.commons.CommonsMultipartFile; import org.springframework.web.servlet.ModelAndView; import com.esd.db.model.inspectorrecord; import com.esd.db.model.manager; import com.esd.db.model.markTimeMethod; import com.esd.db.model.task; import com.esd.db.model.worker; import com.esd.db.model.workerRecord; import com.esd.ps.model.WorkerRecordTrans; import com.esd.ps.model.taskTrans; import com.esd.ps.util.TaskMarkTime; import com.esd.ps.util.TaskMarkTime1; import com.esd.db.model.taskWithBLOBs; import com.esd.db.service.InspectorRecordService; import com.esd.db.service.ManagerService; import com.esd.db.service.MarkTimeMethodService; import com.esd.db.service.PackService; import com.esd.db.service.SalaryService; import com.esd.db.service.TaskService; import com.esd.db.service.WorkerRecordService; import com.esd.db.service.WorkerService; /** * * * @author chen * */ @Controller @RequestMapping("/security") public class WorkerController { private static final Logger logger = LoggerFactory.getLogger(WorkerController.class); @Autowired private TaskService taskService; @Autowired private ManagerService managerService; @Autowired private WorkerService workerService; @Autowired private WorkerRecordService workerRecordService; @Autowired private PackService packService; @Autowired private SalaryService salaryService; @Autowired private MarkTimeMethodService markTimeMethodService; @Autowired private InspectorRecordService inspectorRecordService; /** * ? */ @Value("${MSG_TASK_NOT_ENOUGH}") private String MSG_TASK_NOT_ENOUGH; /** * */ @Value("${MSG_UNAUDIT}") private String MSG_UNAUDIT; /** * ?? */ @Value("${MSG_UNQUALIFY}") private String MSG_UNQUALIFY; /** * ? */ @Value("${MSG_QUALIFY}") private String MSG_QUALIFY; /** * */ @Value("${MSG_GIVEUP}") private String MSG_GIVEUP; int workerMark = 0; /** * ? * * @return */ @RequestMapping(value = "/worker", method = RequestMethod.GET) public ModelAndView worker(HttpSession session) { int workerId = workerService .getWorkerIdByUserId(Integer.parseInt(session.getAttribute(Constants.USER_ID).toString())); manager manager = managerService.selectByPrimaryKey(1); SimpleDateFormat sdf = new SimpleDateFormat(Constants.DATETIME_FORMAT); String nowMonth = sdf.format(new Date()); Double aduited = salaryService.getSumMarkTime2(workerId, nowMonth); if (aduited == null) { aduited = 0.00; } DecimalFormat df = new DecimalFormat("#"); session.setAttribute("salary", df.format(aduited * manager.getSalary() / 3600)); session.setAttribute("aduiting", workerRecordService.getTaskMarkTimeMonthByWorkerIdAndMonth(workerId, "", "", "", 0, 1, 0)); session.setAttribute("aduited", aduited); worker worker = workerService.selectByPrimaryKey(workerId); session.setAttribute("downing", worker.getDowning()); int userLvl = Integer.parseInt(session.getAttribute(Constants.USER_LVL).toString()); int typeCount = 1; if (userLvl > 1) { typeCount = 2; } session.setAttribute("typeCount", typeCount); return new ModelAndView(Constants.WORKER + Constants.SLASH + Constants.WORKER); } // NullPointerException /** * list * * @param loginrName * @return */ @RequestMapping(value = "/worker", method = RequestMethod.POST) @ResponseBody public Map<String, Object> workerPost(HttpSession session, HttpServletRequest request, int taskEffective, int packType) { Map<String, Object> map = new HashMap<String, Object>(); int workerId = workerService .getWorkerIdByUserId(Integer.parseInt(session.getAttribute(Constants.USER_ID).toString())); List<workerRecord> listAll = workerRecordService.getByWorkerIdAndEffective(workerId, 3, 0); // if (listAll == null || listAll.isEmpty()) { int userLvl = Integer.parseInt(session.getAttribute(Constants.USER_LVL).toString()); workerMark = 0; int downMaxCount = 0; int downOneCount = 0; // ?? // int countPackDoing = taskService.getFreePackCount(); // ? int countTaskDoing = taskService.getCountTaskDoing(1); int auditingCount = workerRecordService.getCountByWorkerId(workerId, 1, 4); int countTaskDoing2 = 0; if (userLvl > 1) { countTaskDoing2 = taskService.getCountTaskDoing(2); } worker worker = workerService.selectByPrimaryKey(workerId); if (worker.getDownCount() != null) { String downc = worker.getDownCount(); String str[] = downc.split("/"); downMaxCount = Integer.parseInt(str[0]); downOneCount = Integer.parseInt(str[1]); } else { manager manager = managerService.selectByPrimaryKey(1); downMaxCount = manager.getDownMaxCount(); downOneCount = manager.getDownCount(); } // worker? int downCount = 0; if ((downMaxCount - auditingCount) > downOneCount) { downCount = downOneCount; } else { downCount = (downMaxCount - auditingCount); } if (downCount > countTaskDoing) { downCount = countTaskDoing; } // int downCount2 = 0; if ((downMaxCount - auditingCount) > downOneCount) { downCount2 = downOneCount; } else { downCount2 = (downMaxCount - auditingCount); } if (downCount2 > countTaskDoing2) { downCount2 = countTaskDoing2; } // String noteId = packService.getNoteIdByPackId(0); // map.put(Constants.COUNTPACKDOING, countPackDoing); map.put(Constants.COUNTTASKDOING, countTaskDoing); map.put("downCount", downCount); map.put("countTaskDoing2", countTaskDoing2); map.put("downCount2", downCount2); map.put("noteId", noteId); map.put(Constants.WORKERMARK, 0); return map; } List<workerRecord> listWorkerRecord = workerRecordService.getByWorkerIdAndEffective(workerId, taskEffective, 0); logger.debug("listWorkerRecord:{},", listWorkerRecord); workerMark = 1; SimpleDateFormat sdf = new SimpleDateFormat(Constants.DATETIME_FORMAT); Date downloadTime = new Date(); int packLockTime = 0; List<taskTrans> list = new ArrayList<taskTrans>(); for (Iterator<workerRecord> iterator = listWorkerRecord.iterator(); iterator.hasNext();) { workerRecord workerRecord = (workerRecord) iterator.next(); downloadTime = workerRecord.getTaskDownTime(); packLockTime = workerRecord.getTaskLockTime(); taskTrans taskTrans = new taskTrans(); if (workerRecord.getTaskDownTime() == null) { taskTrans.setTaskDownloadTime(Constants.EMPTY); } else { taskTrans.setTaskDownloadTime(sdf.format(workerRecord.getTaskDownTime())); } taskTrans.setTaskId(workerRecord.getTaskId()); taskTrans.setNoteId(packService.getNoteIdByPackId(workerRecord.getPackId())); taskTrans.setTaskName(workerRecord.getTaskName()); taskTrans.setInspectorrecordId(workerRecord.getInspectorrecordId()); logger.debug("TaskName:{}", workerRecord.getTaskName()); list.add(taskTrans); } Date begin; try { begin = sdf.parse(sdf.format(downloadTime)); Date end = sdf.parse(sdf.format(new Date())); long between = (end.getTime() - begin.getTime());// long mm = packLockTime - between; logger.debug("packLockTime:{},between:{},mm:{}", packLockTime, between, mm); map.clear(); map.put(Constants.WORKERMARK, 1); map.put("list", list); map.put("mm", mm); } catch (ParseException e) { e.printStackTrace(); } session.setAttribute(Constants.WORKER_ID, workerId); return map; } /** * ?? * * @param inspectorrecordId * @return */ @RequestMapping(value = "/getInspectrecord", method = RequestMethod.POST) @ResponseBody public Map<String, Object> getInspectrecordPost(int inspectorrecordId) { Map<String, Object> map = new HashMap<String, Object>(); if (inspectorrecordId > 0) { inspectorrecord inspectorrecord = inspectorRecordService.selectByPrimaryKey(inspectorrecordId); map.put("note", inspectorrecord.getNote()); } return map; } /** * * * @param session * @param taskId * @return */ @RequestMapping(value = "/GiveUpTask", method = RequestMethod.POST) @ResponseBody public Map<String, Object> GiveUpTaskPost(HttpSession session, int taskId) { Map<String, Object> map = new HashMap<String, Object>(); int workerId = workerService .getWorkerIdByUserId(Integer.parseInt(session.getAttribute(Constants.USER_ID).toString())); StackTraceElement[] items = Thread.currentThread().getStackTrace(); if (workerRecordService.updateByGiveUp(workerId, taskId, 0, items[1].toString()) > 0) { task task = new task(); task.setWorkerId(0); task.setVersion(1); task.setTaskMarkTime(0.00); task.setTaskUpload(false); task.setUpdateId(Integer.parseInt(session.getAttribute(Constants.USER_ID).toString())); task.setTaskId(taskId); taskService.updateByTaskId(task); } else { map.put(Constants.REPLAY, 0); return map; } // int packId = workerRecordService.getPackIdByTaskId(taskId); // if (taskService.getUndoTaskCountByPackId(packId) > 0) { // packWithBLOBs pack = new packWithBLOBs(); // pack.setPackId(packId); // pack.setPackStatus(0); // packService.updateByPrimaryKeySelective(pack); // } map.put(Constants.REPLAY, 1); return map; } /** * ? * @return */ @RequestMapping(value = "/workerSalary", method = RequestMethod.GET) public ModelAndView workerSalaryGET() { return new ModelAndView(Constants.WORKER + Constants.SLASH + "workerSalary"); } /** * * @param session * @param page * @param downPackName * @return */ @RequestMapping(value = "/workerMonthSalary", method = RequestMethod.POST) @ResponseBody public Map<String, Object> workerMonthSalaryPOST(HttpSession session) { Map<String, Object> map = new HashMap<String, Object>(); int userId = Integer.parseInt(session.getAttribute(Constants.USER_ID).toString()); int workerId = workerService.getWorkerIdByUserId(userId); manager m = managerService.selectByPrimaryKey(1); List<Map<String, Object>> workerSalaryList = salaryService.getWorkerSalaryByWorkerId(workerId); map.put("list", workerSalaryList); if (m.getSalary() > 0) { map.put("salary", m.getSalary()); } else { map.put("salary", 0); } return map; } /** * workerdown pack?? * * @return */ @RequestMapping(value = "/workerHistoryPack", method = RequestMethod.GET) public ModelAndView workerHistoryPackGET() { return new ModelAndView(Constants.WORKER + Constants.SLASH + Constants.WORKEHISTORYPACK); } /** * workerdown pack?? * * @param session * @param page * @param downPackName * @return */ @RequestMapping(value = "/workerHistoryPack", method = RequestMethod.POST) @ResponseBody public Map<String, Object> workerHistoryPackPOST(HttpSession session, int page, String downPackName) { Map<String, Object> map = new HashMap<String, Object>(); int workerId = workerService .getWorkerIdByUserId(Integer.parseInt(session.getAttribute(Constants.USER_ID).toString())); //SimpleDateFormat sdf = new SimpleDateFormat(Constants.DATETIME_FORMAT); int totle = workerRecordService.getDownPackNameCountByworkerIdGroupByDownPackName(workerId, downPackName); //List<WorkerDownPackHistoryTrans> list = new ArrayList<>(); int totlePage = 0; if (totle == 0) { map.clear(); map.put(Constants.TOTLE, totle); map.put(Constants.TOTLE_PAGE, totlePage); map.put(Constants.LIST, null); return map; } List<Map<String, Object>> list = workerRecordService.getWorkerHis(workerId, page, Constants.ROW); // List<workerRecord> workerRecordList = workerRecordService.getWorkerRecordLikeDownPackName(workerId, page, downPackName, Constants.ROW); // logger.debug("workerRecordList:{}", workerRecordList); // for (Iterator<workerRecord> iterator = workerRecordList.iterator(); iterator.hasNext();) { // workerRecord workerRecord = (workerRecord) iterator.next(); // WorkerDownPackHistoryTrans workerDownPackHistoryTrans = new WorkerDownPackHistoryTrans(); // workerDownPackHistoryTrans.setTaskCount(workerRecordService.getTaskCountByDownPackName(workerRecord.getDownPackName())); // workerDownPackHistoryTrans.setDownPackName(workerRecord.getDownPackName()); // logger.debug("status:{}", workerRecordService.getPackStatuByDownPackName(workerRecord.getDownPackName())); // if (workerRecordService.getPackStatuByDownPackName(workerRecord.getDownPackName()) > 0) { // workerDownPackHistoryTrans.setPackStatu(Constants.ZERO); // } else { // workerDownPackHistoryTrans.setPackStatu(Constants.ONE); // } // // if (workerRecord.getTaskDownTime() == null) { // workerDownPackHistoryTrans.setDownTime(Constants.EMPTY); // } else { // workerDownPackHistoryTrans.setDownTime(sdf.format(workerRecord.getTaskDownTime())); // } // list.add(workerDownPackHistoryTrans); // } map.clear(); totlePage = (int) Math.ceil((double) totle / (double) Constants.ROW); map.put(Constants.TOTLE, totle); map.put(Constants.TOTLE_PAGE, totlePage); map.put(Constants.LIST, list); return map; } /** * worker? * * @param downPackName * @return */ @RequestMapping(value = "/workerHistoryTask", method = RequestMethod.POST) @ResponseBody public Map<String, Object> workerHistoryTaskPOST(String downPackName) { Map<String, Object> map = new HashMap<String, Object>(); logger.debug("downPackName:{}", downPackName); SimpleDateFormat sdf = new SimpleDateFormat(Constants.DATETIME_FORMAT); List<WorkerRecordTrans> list = new ArrayList<WorkerRecordTrans>(); List<workerRecord> workerRecordList = workerRecordService.getAllByDownPackName(downPackName); if (workerRecordList == null) { return null; } for (Iterator<workerRecord> iterator = workerRecordList.iterator(); iterator.hasNext();) { workerRecord workerRecord = (workerRecord) iterator.next(); WorkerRecordTrans workerRecordTrans = new WorkerRecordTrans(); workerRecordTrans.setDownPackName(downPackName); workerRecordTrans.setTaskDownTime(sdf.format(workerRecord.getTaskDownTime())); if (workerRecord.getTaskEffective() == 0) { workerRecordTrans.setTaskEffective(MSG_UNAUDIT); } else if (workerRecord.getTaskEffective() == 2) { workerRecordTrans.setTaskEffective(MSG_UNQUALIFY); } else if (workerRecord.getTaskEffective() == 1) { workerRecordTrans.setTaskEffective(MSG_QUALIFY); } else if (workerRecord.getTaskEffective() == 3) { workerRecordTrans.setTaskEffective(MSG_GIVEUP); } workerRecordTrans.setEffective(workerRecord.getTaskEffective()); workerRecordTrans.setTaskLockTime(workerRecord.getTaskLockTime() / 3600000); if (workerRecord.getTaskMarkTime() == null) { workerRecordTrans.setTaskMarkTime(0.00); } else { workerRecordTrans.setTaskMarkTime(workerRecord.getTaskMarkTime()); } workerRecordTrans.setTaskId(workerRecord.getTaskId()); workerRecordTrans.setTaskName(workerRecord.getTaskName()); workerRecordTrans.setTaskStatus(workerRecord.getTaskStatu()); if (workerRecord.getTaskUploadTime() == null) { workerRecordTrans.setTaskUploadTime(Constants.EMPTY); } else { workerRecordTrans.setTaskUploadTime(sdf.format(workerRecord.getTaskUploadTime())); } list.add(workerRecordTrans); } map.put(Constants.LIST, list); return map; } /** * ? * * @param downPackName * @return */ @RequestMapping(value = "/downOncePack", method = RequestMethod.GET) @ResponseBody public Map<String, Object> downOncePack(String downPackName, HttpServletRequest request, HttpSession session) { Map<String, Object> map = new HashMap<String, Object>(); String url = WorkerController.url(request); File f = new File(url); File zipFile = null; // ??? // String serverAndProjectPath = request.getLocalAddr() + // Constants.COLON + request.getLocalPort() + request.getContextPath(); // ? // String wrongPath = Constants.HTTP + serverAndProjectPath + // Constants.SLASH + Constants.WORKERTEMP + Constants.SLASH + // downPackName; String wrongPath = Constants.SLASH + Constants.WORKERTEMP + Constants.SLASH + downPackName; if (f.exists()) { zipFile = new File(url + Constants.SLASH + downPackName); if (zipFile.exists()) { //System.out.println(url + Constants.SLASH + downPackName); map.put(Constants.WRONGPATH, wrongPath); return map; } } else { f.mkdir(); } try { zipFile.createNewFile(); int workerId = Integer.parseInt(session.getAttribute(Constants.WORKER_ID).toString()); List<taskWithBLOBs> list = taskService.getDoingTaskByWorkerId(workerId); logger.debug("workerId:{},list1:{}", workerId, list); this.wrongPath(zipFile, list); workerRecord workerRecord = new workerRecord(); workerRecord.setUpdateTime(new Date()); workerRecord.setDownUrl(wrongPath); workerRecord.setDownPackName(downPackName); int a = workerRecordService.updateBydownPackName(workerRecord); logger.debug("a:{}", a); } catch (IOException e) { e.printStackTrace(); } map.put(Constants.WRONGPATH, wrongPath); logger.debug("wrongPath:{}", wrongPath); return map; } /** * ? * * @param response * @param taskName */ @RequestMapping(value = "/downOneTask", method = RequestMethod.GET) @ResponseBody public Map<String, Object> downOneTask(HttpServletRequest request, String taskName, int taskId) { Map<String, Object> map = new HashMap<String, Object>(); String url = WorkerController.url(request); File f = new File(url); String zipName = taskName.substring(0, taskName.indexOf(Constants.POINT)) + Constants.POINT + Constants.ZIP; File zipFile = new File(url + Constants.SLASH + zipName); // ??? // String serverAndProjectPath = request.getLocalAddr() + // Constants.COLON + request.getLocalPort() + request.getContextPath(); // ? // String wrongPath = Constants.HTTP + serverAndProjectPath + // Constants.SLASH + Constants.WORKERTEMP + Constants.SLASH + zipName; String wrongPath = Constants.SLASH + Constants.WORKERTEMP + Constants.SLASH + zipName; if (!f.exists()) { f.mkdir(); } try { zipFile.createNewFile(); taskWithBLOBs task = taskService.selectByPrimaryKey(taskId); List<taskWithBLOBs> list = new ArrayList<taskWithBLOBs>(); list.add(task); this.wrongPath(zipFile, list); } catch (IOException e) { e.printStackTrace(); } map.put(Constants.WRONGPATH, wrongPath); return map; } /** * (wav?) * @param response * @param downTaskCount * @param session * @param request * @param packType * @return */ @RequestMapping(value = "/downTask", method = RequestMethod.GET) @ResponseBody public Map<String, Object> downTask(final HttpServletResponse response, int downTaskCount, HttpSession session, HttpServletRequest request, int packType) { Map<String, Object> map = new HashMap<String, Object>(); //session?user_id int userId = Integer.parseInt(session.getAttribute(Constants.USER_ID).toString()); //int workerId = workerService.getWorkerIdByUserId(Integer.parseInt(session.getAttribute(Constants.USER_ID).toString())); //workeruser_idworker worker w = workerService.getWorkerByUserId(userId); if (w == null) { map.put("replay", 1); return map; } //worker_id int workerId = w.getWorkerId(); //workerdowningworker? //downing = 1 if (w.getDowning() == 1) { map.put("replay", 1); return map; } else { //worker_recordworker_idworker?? int doingtaskcount = workerRecordService.getDoingTaskCountByWorkerId(workerId); if (doingtaskcount > 0) { map.put("replay", 1); return map; } } //sessiondowning?1 session.setAttribute("downing", 1); logger.debug("downTaskCount:{}", downTaskCount); //taskpack_type?? int countTaskDoing = taskService.getCountTaskDoing(packType); // ???? if (countTaskDoing < downTaskCount) { // String nowCountTaskDoing=countTaskDoing + ""; map.put(Constants.MESSAGE, MSG_TASK_NOT_ENOUGH); session.setAttribute("downing", 0); return map; } //String realName = workerService.getWorkerRealNameByWorkerId(workerId); //?worker?? String realName = w.getWorkerRealName(); // int packId = packService.getPackIdOrderByPackLvl(); // ? worker worker = new worker(); worker.setWorkerId(workerId); worker.setDowning(1); //workerdowning workerService.updateByPrimaryKeySelective(worker); //? String url = WorkerController.url(request); logger.debug("url:{}", url); // SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd-HHmmss"); //??? String downPackName = sdf.format(new Date()) + Constants.UNDERLINE + downTaskCount + Constants.UNDERLINE + userId + Constants.POINT + Constants.ZIP; String wrongPath = Constants.SLASH + Constants.WORKERTEMP + Constants.SLASH + downPackName; //?list String downPackName,String wrongPath,String realName,String userName List<taskWithBLOBs> list = taskService.updateWorkerIdDowningTask(downTaskCount, 0, userId, workerId, packType, downPackName, wrongPath, realName, session.getAttribute(Constants.USER_NAME).toString()); if (list == null) { session.setAttribute("downing", 0); return null; } File f = new File(url); if (f.exists() == false) { f.mkdir(); } //? File zipFile = new File(url + Constants.SLASH + downPackName); if (zipFile.exists()) { zipFile.delete(); } // ??? // String serverAndProjectPath = request.getLocalAddr() + // Constants.COLON + request.getLocalPort() + request.getContextPath(); // ? // String wrongPath = Constants.HTTP + serverAndProjectPath + // Constants.SLASH + Constants.WORKERTEMP + Constants.SLASH + // downPackName; //?? logger.debug("wrongPath:{}", wrongPath); try { zipFile.createNewFile(); FileOutputStream fos = new FileOutputStream(zipFile); ZipOutputStream zos = new ZipOutputStream(new BufferedOutputStream(fos)); byte[] bufs = new byte[1024 * 10]; for (Iterator<taskWithBLOBs> iterator = list.iterator(); iterator.hasNext();) { taskWithBLOBs taskWithBLOBs = (taskWithBLOBs) iterator.next(); //?? String fileName = taskWithBLOBs.getTaskName() == null ? "Task.wav" : taskWithBLOBs.getTaskName(); // ZIP, ZipEntry zipEntry = new ZipEntry(fileName); zos.putNextEntry(zipEntry); //task?? byte[] data = taskWithBLOBs.getTaskWav(); //?? InputStream is = new ByteArrayInputStream(data); // ? BufferedInputStream bis = new BufferedInputStream(is, 1024); int read; while ((read = bis.read(bufs)) > 0) {// , 0, 2048 zos.write(bufs, 0, read);// } // zos.closeEntry(); bis.close(); is.close(); // task // worker_record // workerRecord workerRecord = new workerRecord(); // workerRecord.setCreateTime(new Date()); // workerRecord.setTaskOverTime(new Date()); // workerRecord.setDownPackName(downPackName); // workerRecord.setDownUrl(wrongPath); // workerRecord.setPackId(taskWithBLOBs.getPackId()); // workerRecord.setPackName(packService.getPackNameByPackId(taskWithBLOBs.getPackId())); // workerRecord.setTaskDownTime(new Date()); // workerRecord.setTaskId(taskWithBLOBs.getTaskId()); // int packLockTime = packService.getPackLockTime(taskWithBLOBs.getPackId()); // if (packLockTime > 0) { // workerRecord.setTaskLockTime(packLockTime); // } // workerRecord.setTaskName(taskWithBLOBs.getTaskName()); // //?? // workerRecord.setRealName(realName); // workerRecord.setTaskStatu(0); // workerRecord.setWorkerId(workerId); // workerRecord.setUserName(session.getAttribute(Constants.USER_NAME).toString()); // StackTraceElement[] items1 = Thread.currentThread().getStackTrace(); // workerRecord.setCreateMethod(items1[1].toString()); // workerRecordService.insertSelective(workerRecord); } session.setAttribute(Constants.WORKERMARK, 1); zos.close();// ,??0kb fos.flush(); fos.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } /** * ,packStatus */ // if (taskService.getUndoTaskCountByPackId(packId) == 0) { // packWithBLOBs pack = new packWithBLOBs(); // pack.setPackId(packId); // pack.setPackStatus(2); // packService.updateByPrimaryKeySelective(pack); // } logger.debug("wrongPath:{}", wrongPath); map.put(Constants.WRONGPATH, wrongPath); map.put("replay", 0); session.setAttribute("downing", 0); // ? worker.setDowning(0); workerService.updateByPrimaryKeySelective(worker); return map; } /** * workerTAGTextGrid * * @param files * @param session * @param taskWithBLOBs */ @RequestMapping(value = "/upTagAndTextGrid", method = RequestMethod.POST) @ResponseBody public Map<String, Object> upTagAndTextGrid(@RequestParam("file") CommonsMultipartFile[] files, HttpSession session, taskWithBLOBs taskWithBLOBs, HttpServletRequest request) { Map<String, Object> map = new HashMap<String, Object>(); int workerId = workerService .getWorkerIdByUserId(Integer.parseInt(session.getAttribute(Constants.USER_ID).toString())); boolean flag = false; logger.debug("workerId:{}", workerId); List<task> listTask = taskService.getAllDoingTaskByWorkerId(workerId); if (files.length == 0) { return null; } List<String> listMath = new ArrayList<String>(); List<String> listAll = new ArrayList<String>(); // int task_id = Constants.ZERO; for (int i = 0; i < files.length; i++) { listAll.add(files[i].getOriginalFilename()); logger.debug(files[i].getOriginalFilename()); } for (Iterator<task> iterator = listTask.iterator(); iterator.hasNext();) { task task = (task) iterator.next(); String taskName = task.getTaskName(); for (int i = 0; i < files.length; i++) { try { files[i].getInputStream(); } catch (IOException e2) { e2.printStackTrace(); } String nameWav = files[i].getOriginalFilename().substring(0, files[i].getOriginalFilename().indexOf(Constants.POINT)) + Constants.POINT + Constants.WAV; // nameWav??,taskName??? if (taskName.equals(nameWav)) { int taskId = task.getTaskId(); String markTimeName = packService.getTaskMarkTimeName(task.getPackId()); int uploadFileCount = Integer.parseInt(markTimeName.split("_")[1]); // textgridtag if (uploadFileCount == 2) { for (int j = 0; j < files.length; j++) { if (files[i].getOriginalFilename().split("\\.")[0] .equalsIgnoreCase(files[j].getOriginalFilename().split("\\.")[0]) && !files[i].getOriginalFilename() .equalsIgnoreCase(files[j].getOriginalFilename())) { if (files[i].getOriginalFilename().split("\\.")[1] .equalsIgnoreCase(Constants.TEXTGRID) || files[i].getOriginalFilename().split("\\.")[1] .equalsIgnoreCase(Constants.TAG)) { flag = true; break; } } } } else if (uploadFileCount == 1) { if (files[i].getOriginalFilename().split("\\.")[1].equalsIgnoreCase(Constants.TEXTGRID)) { flag = true; } } if (flag) { String uploadTaskNameI = files[i].getOriginalFilename(); byte[] bytes = files[i].getBytes(); // String nameLast = // files[i].getOriginalFilename().substring((files[i].getOriginalFilename().indexOf(Constants.POINT) // + 1), files[i].getOriginalFilename().length()); String nameLast = files[i].getOriginalFilename().split("\\.")[1]; if (nameLast.equalsIgnoreCase(Constants.TEXTGRID)) { int packId = task.getPackId(); markTimeMethod markTimeMethod = markTimeMethodService .getByPrimaryKey(packService.getTaskMarkTimeId(packId)); String keyWords = "\"" + markTimeMethod.getKeywords() + "\""; double taskMarkTime = 0; try { InputStream is = files[i].getInputStream(); TaskMarkTime tmt = new TaskMarkTime1(); taskMarkTime = tmt.textGrid1(is, keyWords); if (taskMarkTime == 10000) { map.clear(); map.put(Constants.REPLAY, 0); map.put(Constants.MESSAGE, "??,??!"); return map; } } catch (IOException e) { e.printStackTrace(); } // workerRecord workerRecord workerRecord = new workerRecord(); workerRecord.setTaskUploadTime(new Date()); workerRecord.setTaskOverTime(new Date()); workerRecord.setTaskStatu(1); workerRecord.setTaskEffective(0); workerRecord.setTaskMarkTime( Double.parseDouble(String.format(Constants.SPILT_TWELVE, taskMarkTime))); workerRecord.setRecordId(workerRecordService.getPkIDByTaskId(taskId)); StackTraceElement[] items1 = Thread.currentThread().getStackTrace(); workerRecord.setUpdateMethod(items1[1].toString()); workerRecordService.updateByPrimaryKeySelective(workerRecord); // task taskWithBLOBs.setTaskMarkTime( Double.parseDouble(String.format(Constants.SPILT_TWELVE, taskMarkTime))); taskWithBLOBs.setTaskTextgrid(bytes); taskWithBLOBs.setTaskId(taskId); taskWithBLOBs.setTaskUpload(true); taskWithBLOBs.setTaskUploadTime(new Date()); StackTraceElement[] items = Thread.currentThread().getStackTrace(); taskWithBLOBs.setUpdateMethod(items[1].toString()); taskWithBLOBs.setTaskEffective(null); taskService.updateByPrimaryKeySelective(taskWithBLOBs); listMath.add(uploadTaskNameI); // task_id = taskId; } else if (nameLast.equalsIgnoreCase(Constants.TAG)) { taskWithBLOBs.setTaskTag(bytes); taskWithBLOBs.setTaskId(taskId); taskWithBLOBs.setTaskUploadTime(new Date()); StackTraceElement[] items = Thread.currentThread().getStackTrace(); taskWithBLOBs.setUpdateMethod(items[1].toString()); taskService.updateByPrimaryKeySelective(taskWithBLOBs); listMath.add(uploadTaskNameI); } } } } } int doingTaskCount = workerRecordService.getDoingTaskCountByWorkerId(workerId); if (doingTaskCount == 0) { workerRecord workerRecord = workerRecordService.getWorkerRecordByWorkerId(workerId); String url = WorkerController.url(request); File file = new File(url + Constants.SLASH + workerRecord.getDownPackName()); if (file.exists()) { file.delete(); } } map.put(Constants.REPLAY, 1); map.put(Constants.LISTMATH, listMath); map.put(Constants.LISTALL, listAll); return map; } /** * ? * * @param request * @return */ public static String url(HttpServletRequest request) { String url = request.getSession().getServletContext().getRealPath(Constants.SLASH); url = url + Constants.WORKERTEMP; File f = new File(url); if (f.exists()) { return url; } f.mkdir(); return url; } /** * * * @param zipFile * @param list * @return */ public String wrongPath(File zipFile, List<taskWithBLOBs> list) { logger.debug("list2:{}", list); try { FileOutputStream fos = new FileOutputStream(zipFile); ZipOutputStream zos = new ZipOutputStream(new BufferedOutputStream(fos)); byte[] bufs = new byte[1024 * 10]; for (Iterator<taskWithBLOBs> iterator = list.iterator(); iterator.hasNext();) { taskWithBLOBs taskWithBLOBs = (taskWithBLOBs) iterator.next(); String fileName = taskWithBLOBs.getTaskName() == null ? "Task.wav" : taskWithBLOBs.getTaskName(); // ZIP, ZipEntry zipEntry = new ZipEntry(fileName); zos.putNextEntry(zipEntry); byte[] data = taskWithBLOBs.getTaskWav(); InputStream is = new ByteArrayInputStream(data); // ? BufferedInputStream bis = new BufferedInputStream(is, 1024); int read; while ((read = bis.read(bufs)) > 0) { zos.write(bufs, 0, read);// } // zos.closeEntry(); bis.close(); is.close(); // task } zos.close();// ,??0kb fos.flush(); fos.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return ""; } // public void test (){ // System.out.println(salaryService.getWorkerSalaryByWorkerId(25)); // } }