Java tutorial
package com.clt.sub.controller; import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import net.sf.json.JSONArray; import org.apache.commons.lang.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.authentication.encoding.Md5PasswordEncoder; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.ModelAttribute; 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 com.clt.sub.model.TDriver; import com.clt.sub.model.TDriverSalary; import com.clt.sub.model.TDriverSalaryCoefficient; import com.clt.sub.model.TDriverSubsideLinks; import com.clt.sub.model.TDriverSubsides; import com.clt.sub.model.TSharecircle; import com.clt.sub.service.IDriverSalaryService; import com.clt.sub.service.IDriverService; import com.clt.sub.service.ISharecircleService; import com.clt.sub.service.ISubsuppliersService; import com.clt.sub.service.ITruckDriverService; import com.clt.systemmanger.model.TRole; import com.clt.systemmanger.model.TUser; import com.clt.systemmanger.model.TUserRole; import com.clt.systemmanger.service.IPictureService; import com.clt.systemmanger.service.IRoleService; import com.clt.systemmanger.service.IStaticService; import com.clt.systemmanger.service.IUserRoleService; import com.clt.systemmanger.service.IUserService; import com.clt.util.AjaxUtil; import com.clt.util.HqlHelper; import com.clt.util.Page; import com.clt.util.ServiceUtil; import com.clt.util.SystemConstants; import com.mangofactory.swagger.annotations.ApiIgnore; import com.wordnik.swagger.annotations.Api; import com.wordnik.swagger.annotations.ApiOperation; import com.wordnik.swagger.annotations.ApiParam; @Controller @RequestMapping("/driverAction") @Api(value = "driver-api", description = "??", position = 5) public class DriverAction { @Autowired private IDriverService driverService; @Autowired private ISubsuppliersService subService; @Autowired private IStaticService staticService; @Autowired ITruckDriverService truckDriverService; @Autowired private IDriverSalaryService salaryService; @Autowired private IPictureService pictureService; @Autowired IUserService iUserService; @Autowired IRoleService roleService; @Autowired IUserRoleService iUserRoleService; @Autowired private ISharecircleService shareService; /** * @Description: ?? * @return String ? * @throws */ @RequestMapping("/intoDriverSalaryCoefficient") @ApiIgnore public String intoDriverSalaryCoefficient(HttpServletRequest request) { return "sub/subBasicData/driverSalaryCoefflist"; } /** * * @Description: TODO(?) * @param request * @return String ?? * @author liuwu * @create_date 2015-5-27 ?5:12:15 */ @RequestMapping("/intoDriverSubsidies") @ApiIgnore public String intoDriverSubsidies(HttpServletRequest request) { return "sub/subBasicData/driverSalarySubsidList"; } /** * * @Description: TODO(??) * @param request * @return String ?? * @author liuwu * @create_date 2015-5-28 ?2:00:19 */ @RequestMapping("/intoDriverSubsidiesLinks") @ApiIgnore public String intoDriverSubsidiesLinks(HttpServletRequest request) { return "sub/subBasicData/driverSubsidiesLinks"; } /** * * @Description: TODO(??) * @return Map<String,Object> ?? * @author liuwu * @create_date 2015-5-29 ?10:25:57 */ @RequestMapping(value = "/getDriverSubsidiesLinks", method = RequestMethod.POST) @ResponseBody @ApiIgnore public Map<String, Object> getDriverSubsidiesLinks(HttpServletRequest request) { HttpSession session = request.getSession(); TUser user = (TUser) session.getAttribute("user"); String subno = subService.get(user.getiArchive()).getVcSubno(); Page page = ServiceUtil.getcurrPage(request); HqlHelper hql = new HqlHelper(TDriver.class); hql.setQueryPage(page); hql.addEqual("vcSubno", subno); hql.addEqual("NEnable", SystemConstants.SYS_ENABLE); String driverName = request.getParameter("driverName"); if (StringUtils.isNotBlank(driverName)) { hql.addLike("vcDriverName", driverName); } hql.addOrderBy("id", "desc"); Map<String, Object> resuMap = driverService.findDriverSalaryCoffe(hql); return resuMap; } /** * * @Description: TODO(??) * @param request * @return String ?? * @author liuwu * @create_date 2015-6-1 ?3:25:08 */ @RequestMapping(value = "/saveBeforeSubsidiesLinks") @ApiIgnore public String saveBeforeDriverlink(HttpServletRequest request, String id) { System.out.println("id = " + id); request.setAttribute("driverIds", id); return "sub/subBasicData/driverSubsidiesLinksSave"; } /** * * @Description: TODO(???) * @param request * @param response * void ?? * @author liuwu * @create_date 2015-6-1 ?5:08:13 */ @RequestMapping(value = "/saveSalarySubsideLinks", method = RequestMethod.POST) @ApiIgnore public void saveSalarySubsideLinks(HttpServletRequest request, HttpServletResponse response, String strIds, String driverIds) { String[] subsidesIds = strIds.split(",");// ID String[] driverId = driverIds.split(",");// ?id try { for (String drId : driverId) { List<TDriverSubsideLinks> tLinks = driverService .findTDriverSubsideLinksByDriverId(Integer.parseInt(drId)); driverService.deleteDriverLinks(tLinks); for (String subId : subsidesIds) { TDriverSubsideLinks tSubsideLinks = new TDriverSubsideLinks(); tSubsideLinks.setiDriverId(Integer.parseInt(drId)); tSubsideLinks.setnEnable(SystemConstants.SYS_ENABLE); tSubsideLinks.setiSubsidesId(Integer.parseInt(subId)); driverService.saveUpdateDriverSubsideLink(tSubsideLinks); } } AjaxUtil.rendJson(response, true, "??"); } catch (Exception e) { AjaxUtil.rendJson(response, false, "?" + e.getMessage()); } } /** * * @Description: TODO(??) * @param request * void ?? * @author liuwu * @create_date 2015-6-3 ?9:45:42 */ @RequestMapping(value = "/deleteSubsidiesLinks") @ApiIgnore public void deleteSalarySubsideLinks(HttpServletRequest request, HttpServletResponse response, String driverIds) { String[] driverId = driverIds.split(",");// ?id try { for (String drId : driverId) { List<TDriverSubsideLinks> tLinks = driverService .findTDriverSubsideLinksByDriverId(Integer.parseInt(drId)); driverService.deleteDriverLinks(tLinks); } AjaxUtil.rendJson(response, true, "??"); } catch (Exception e) { AjaxUtil.rendJson(response, false, "?" + e.getMessage()); } } /** * * @Description: TODO(?) * @param request * @return Map<String,Object> ?? * @author liuwu * @create_date 2015-5-29 ?11:27:39 */ @RequestMapping(value = "/getDriverSubside", method = RequestMethod.POST) @ResponseBody @ApiIgnore public Map<String, Object> getDriverSubside(HttpServletRequest request, String driverId) { int drId = Integer.parseInt(driverId); String sql = "SELECT td.* FROM T_DRIVER_SUBSIDES td , T_DRIVER_SUBSIDES_LINK t where td.id = t.i_subsidesid " + " and t.i_driverid = " + drId; Map<String, Object> subsideMap; String visit = request.getParameter(SystemConstants.APP_VISIT_PARME); HttpSession session = request.getSession(); TUser user = (TUser) session.getAttribute("user"); System.out.println("sql = " + sql); try { // String subbo = subService.get( user.getiArchive() ).getVcSubno(); Page page = ServiceUtil.getcurrPage(request); subsideMap = driverService.getSpringSql(sql, page); return AjaxUtil.getMapByResult(visit, subsideMap); } catch (Exception e) { return AjaxUtil.getMapByException(e); } } /** * * @Description: TODO(??) * @param request * @return Map<String,Object> ?? * @author liuwu * @create_date 2015-5-27 ?5:36:21 */ @RequestMapping(value = "/getDriverSalarySubsideList", method = RequestMethod.POST) @ResponseBody @ApiIgnore public Map<String, Object> getDriverSalarySubsideList(HttpServletRequest request) { HttpSession session = request.getSession(); TUser user = (TUser) session.getAttribute("user"); String subno = subService.get(user.getiArchive()).getVcSubno(); Page page = ServiceUtil.getcurrPage(request); HqlHelper hql = new HqlHelper(TDriverSubsides.class); hql.setQueryPage(page); hql.addEqual("vcSubno", subno); hql.addEqual("nEnable", SystemConstants.SYS_ENABLE); String vcName = request.getParameter("vcName"); if (StringUtils.isNotBlank(vcName)) { hql.addEqual("vcName", vcName); } hql.addOrderBy("id", "desc"); Map<String, Object> resuMap = driverService.findDriverSalarySubside(hql); return resuMap; } /** * * @Description: TODO(??) * @param request * @return String ?? * @author liuwu * @create_date 2015-5-27 ?5:43:40 */ @RequestMapping(value = "/saveBeforeSalarySubside") @ApiIgnore public String saveBeforeSalarySubside(HttpServletRequest request, String salaryID) { HttpSession session = request.getSession(); String paramType = "add"; if (StringUtils.isNotBlank(salaryID)) { TDriverSubsides tDriverSubsides = driverService.findDriverSalarySubsideById(Integer.parseInt(salaryID)); request.setAttribute("tDriverSubsides", tDriverSubsides); paramType = "update"; } request.setAttribute("paramType", paramType); return "sub/subBasicData/saveDriverSalarySubside"; } /** * * @Description: TODO(??) * @param request * @param response * @param tDriverSubsides * @param paramType * void ?? * @author liuwu * @create_date 2015-5-28 ?9:28:02 */ @ApiIgnore @RequestMapping(value = "/saveDriverSalarySubside", method = RequestMethod.POST) public void saveDriverSalarySubside(HttpServletRequest request, HttpServletResponse response, TDriverSubsides tDriverSubsides, String paramType) { try { TUser user = (TUser) request.getSession().getAttribute("user"); String subno = subService.get(user.getiArchive()).getVcSubno(); tDriverSubsides.setVcSubno(subno); if (paramType.equalsIgnoreCase("add")) { driverService.saveDriverSubsides(tDriverSubsides); } else if (paramType.equalsIgnoreCase("update")) { tDriverSubsides.setnEnable(SystemConstants.SYS_ENABLE); driverService.updateDriverSubsides(tDriverSubsides); } AjaxUtil.rendJson(response, true, "??"); } catch (Exception e) { AjaxUtil.rendJson(response, false, "??" + e.getMessage()); } } /** * * @Description: TODO(??) * @param request * @return Map<String,Object> ?? * @author liuwu * @create_date 2015-5-25 ?11:04:32 */ @RequestMapping(value = "/getDriverSalaryCoefflist", method = RequestMethod.POST) @ResponseBody @ApiIgnore public Map<String, Object> getDriverSalaryCoefflist(HttpServletRequest request) { HttpSession session = request.getSession(); TUser user = (TUser) session.getAttribute("user"); String subno = subService.get(user.getiArchive()).getVcSubno(); Page page = ServiceUtil.getcurrPage(request); HqlHelper hql = new HqlHelper(TDriverSalaryCoefficient.class); hql.setQueryPage(page); hql.addEqual("vcSubno", subno); hql.addEqual("nEnable", SystemConstants.SYS_ENABLE); String driverName = request.getParameter("vcDriver"); if (StringUtils.isNotBlank(driverName)) { hql.addLike("vcDriver", driverName); } hql.addOrderBy("id", "desc"); Map<String, Object> resuMap = driverService.findDriverSalaryCoffe(hql); return resuMap; } /** * * @Description: TODO(?) * @param request * @return String ?? * @author liuwu * @create_date 2015-5-25 ?11:47:35 */ @RequestMapping(value = "/saveBeforeSalaryCoff") @ApiIgnore public String saveBeforeSalaryCoff(HttpServletRequest request, String salaryID) { HttpSession session = request.getSession(); String paramType = "add"; TUser user = (TUser) session.getAttribute("user"); String subno = subService.get(user.getiArchive()).getVcSubno(); String[] propertyNames = { "vcSubno", "NEnable" }; Object[] values = { subno, SystemConstants.SYS_ENABLE }; List<TDriver> tDrivers = driverService.findByPropertys(propertyNames, values); if (StringUtils.isNotBlank(salaryID)) { TDriverSalaryCoefficient tSalaryCoefficient = driverService .findDriverSalaryCoffById(Integer.parseInt(salaryID)); request.setAttribute("tSalaryCoefficient", tSalaryCoefficient); paramType = "update"; } request.setAttribute("tDrivers", tDrivers); request.setAttribute("paramType", paramType); return "sub/subBasicData/saveDriverSalaryCoff"; } /** * * @Description: TODO(?) * @param request * @param response * void ?? * @author liuwu * @create_date 2015-5-26 ?3:01:05 */ @ApiIgnore @RequestMapping(value = "/delSalaryCoff", method = RequestMethod.POST) public void delSalaryCoff(HttpServletRequest request, HttpServletResponse response, String scID) { int id = Integer.parseInt(scID); try { TDriverSalaryCoefficient driverSalaryCoefficient = driverService.findDriverSalaryCoffById(id); driverSalaryCoefficient.setnEnable(SystemConstants.SYS_DISABLE); driverService.saveOrUpdateSalaryCoefficient(driverSalaryCoefficient); AjaxUtil.rendJson(response, true, "???"); } catch (Exception e) { AjaxUtil.rendJson(response, false, "?!" + e.getMessage()); } } /** * * @Description: TODO(????) * @param request * @param response * void ?? * @author liuwu * @create_date 2015-5-25 ?3:31:18 */ @ApiIgnore @RequestMapping(value = "/saveDriverSalaryCofflis", method = RequestMethod.POST) public void saveSalaryCoff(HttpServletRequest request, HttpServletResponse response, String paramType, TDriverSalaryCoefficient tSalaryCoefficient) { try { HttpSession session = request.getSession(); TUser user = (TUser) session.getAttribute("user"); String subno = subService.get(user.getiArchive()).getVcSubno(); TDriver tDriver = driverService.get(tSalaryCoefficient.getiDriverId()); if (paramType.equalsIgnoreCase("add")) { // ?? String message = driverService.checkSalaryCoefficient(tSalaryCoefficient, subno, tDriver); if (message.equalsIgnoreCase("success")) { tSalaryCoefficient.setVcSubno(subno); tSalaryCoefficient.setnEnable(SystemConstants.SYS_ENABLE); tSalaryCoefficient.setVcDriver(tDriver.getVcDriverName()); driverService.saveOrUpdateSalaryCoefficient(tSalaryCoefficient); AjaxUtil.rendJson(response, true, "???"); } else { AjaxUtil.rendJson(response, false, "??" + message); } } else if (paramType.equalsIgnoreCase("update")) { TDriverSalaryCoefficient tCoefficient = driverService .findDriverSalaryCoffById(tSalaryCoefficient.getId()); // ?????? if (tCoefficient.getiDriverId().equals(tSalaryCoefficient.getiDriverId())) { tSalaryCoefficient.setVcSubno(subno); tSalaryCoefficient.setnEnable(SystemConstants.SYS_ENABLE); tSalaryCoefficient.setVcDriver(tDriver.getVcDriverName()); driverService.updateTSalaryCOfficient(tSalaryCoefficient); AjaxUtil.rendJson(response, true, "???"); } else { String message = driverService.checkSalaryCoefficient(tSalaryCoefficient, subno, tDriver); if (message.equalsIgnoreCase("success")) { tSalaryCoefficient.setVcSubno(subno); tSalaryCoefficient.setnEnable(SystemConstants.SYS_ENABLE); tSalaryCoefficient.setVcDriver(tDriver.getVcDriverName()); driverService.updateTSalaryCOfficient(tSalaryCoefficient); AjaxUtil.rendJson(response, true, "???"); } else { AjaxUtil.rendJson(response, false, "??" + message); } } } } catch (Exception e) { AjaxUtil.rendJson(response, false, "??" + e.getMessage()); } } /** * @Description ?? * @param request * @param * @author chengwzh * @date 2015/5/12 17:12 */ @RequestMapping(value = "/getAllDrivers", method = RequestMethod.POST) @ResponseBody @ApiOperation(value = "??", notes = "??", position = 5) public Map<String, Object> getAllDrivers(HttpServletRequest request) { HttpSession session = request.getSession(); TUser user = (TUser) session.getAttribute("user"); int subId = user.getiArchive(); String subno = subService.get(subId).getVcSubno();// ?? HqlHelper hql = new HqlHelper(TDriver.class); Page page = ServiceUtil.getcurrPage(request);// ?? hql.setQueryPage(page); hql.addEqual("vcSubno", subno); hql.addEqual("NEnable", SystemConstants.SYS_ENABLE); hql.addOrderBy("id", "desc"); try { String visit = request.getParameter(SystemConstants.APP_VISIT_PARME); Map<String, Object> result = driverService.findByHelper(hql); result = driverService.parseUrl(result);// ? return AjaxUtil.getMapByResult(visit, result); } catch (Exception e) { e.printStackTrace(); return AjaxUtil.getMapByException(e); } } /** * @Description /? * @param driver */ @RequestMapping(value = "/addDriver", method = RequestMethod.POST) @ApiOperation(value = "/?", notes = "/??", position = 5, response = TDriver.class) public void addDriver(@ApiParam(value = "??") @ModelAttribute TDriver driver, @ApiParam(value = "??") @RequestParam(value = "files", required = false) CommonsMultipartFile[] files, @ApiParam(value = "?") @RequestParam(value = "cardImgFile", required = false) CommonsMultipartFile[] cardImgFile, @ApiParam(value = "?") @RequestParam(value = "driveImgFile", required = false) CommonsMultipartFile[] driveImgFile, @ApiParam(value = "") @RequestParam(value = "truckImgFile", required = false) CommonsMultipartFile[] truckImgFile, HttpServletResponse response, HttpServletRequest request) { HttpSession session = request.getSession(); TUser user = (TUser) session.getAttribute("user"); try { int subId = user.getiArchive(); int type = user.getIArchiveType(); String subno = ""; if (type == SystemConstants.SYS_TARCHIVE_SUB) { subno = subService.get(subId).getVcSubno();// ?? } // ????? boolean flag = true; if (driver.getId() == null) // ? { String[] propertyNames = { "NEnable", "vcDriverTel" }; Object[] values = { SystemConstants.SYS_ENABLE, driver.getVcDriverTel() }; List<TDriver> tDrivers = driverService.findByPropertys(propertyNames, values); if (tDrivers != null && tDrivers.size() > 0) { flag = false; AjaxUtil.rendJson(response, false, "???" + driver.getVcDriverTel() + "?"); } } else // ? { TDriver newDriver = driverService.get(driver.getId()); // ?????? if (!newDriver.getVcDriverTel().equals(driver.getVcDriverTel())) { String[] propertyNames = { "NEnable", "vcDriverTel" }; Object[] values = { SystemConstants.SYS_ENABLE, driver.getVcDriverTel() }; List<TDriver> tDrivers = driverService.findByPropertys(propertyNames, values); if (tDrivers != null && tDrivers.size() > 0) { flag = false; AjaxUtil.rendJson(response, false, "???" + driver.getVcDriverTel() + "?"); } } } if (flag) { driver.setVcSubno(subno); driver.setiUserId(user.getId()); if (driver.getId() == null) // { if (files != null) { uploadImg(request, files, driver);// ? } if (cardImgFile != null) { uploadCardImg(request, cardImgFile, driver);// ? } if (driveImgFile != null) { uploadDriveImg(request, driveImgFile, driver);// ? } if (truckImgFile != null) { uploadTruckImg(request, truckImgFile, driver);// } String headImgPath = driver.getVcImgPath(); driverService.save(driver); /** * ? */ TUser tuser = new TUser(); if (StringUtils.isNotBlank(headImgPath)) { tuser.setVcImgpath(headImgPath);// ? } tuser.setNEnable(0); tuser.setDtAddtime(new Date()); tuser.setIArchiveType(SystemConstants.SYS_TARCHIVE_DRIVER); tuser.setiArchive(driver.getId()); tuser.setVcUsername(driver.getVcDriverName()); // ???? ?123456 MD5 tuser.setVcAccount(driver.getVcDriverTel()); org.springframework.security.authentication.encoding.Md5PasswordEncoder t = new Md5PasswordEncoder(); String tt = t.encodePassword("123456", tuser.getVcAccount()); tuser.setVcPassword(tt); iUserService.saveUpdateUser(tuser); // ? List<TRole> tRoles = roleService.findDriverRole(); if (tRoles.size() > 0) { TUserRole tUserRole = new TUserRole(); tUserRole.setIEnable(SystemConstants.SYS_ENABLE); tUserRole.setIRole(tRoles.get(0).getId()); tUserRole.setIUser(tuser.getId()); iUserRoleService.save(tUserRole); AjaxUtil.rendJson(response, true, "???"); } else { AjaxUtil.rendJson(response, false, "?!"); } } else { if (files != null) { uploadImg(request, files, driver);// ? } if (cardImgFile != null) { uploadCardImg(request, cardImgFile, driver);// ? } if (driveImgFile != null) { uploadDriveImg(request, driveImgFile, driver);// ? } if (truckImgFile != null) { uploadTruckImg(request, truckImgFile, driver);// } String headImgPath = driver.getVcImgPath();// ??? TDriver oldDriver = driverService.get(driver.getId()); driver.setVcSubno(oldDriver.getVcSubno());// ?? driverService.updateCleanBefore(driver);// ?? String[] properties = { "IArchiveType", "iArchive" }; Object[] mainValues = { SystemConstants.SYS_TARCHIVE_DRIVER, driver.getId() }; TUser tUser = iUserService.findByProperties(properties, mainValues).get(0); if (StringUtils.isNotBlank(headImgPath)) { if (headImgPath.startsWith("http")) { headImgPath = headImgPath.substring(headImgPath.lastIndexOf("/") + 1); } tUser.setVcImgpath(headImgPath);// ? // ??? String[] propertyNames = { "IUserid" }; Object[] values = { user.getId() }; List<TSharecircle> shares = shareService.findByPropertys(propertyNames, values); for (TSharecircle share : shares) { share.setVcHeadImg(headImgPath); shareService.updateCleanBefore(share); } } tUser.setDtAddtime(new Date()); tUser.setVcAccount(driver.getVcDriverTel()); tUser.setVcUsername(driver.getVcDriverName()); // org.springframework.security.authentication.encoding.Md5PasswordEncoder // t = new Md5PasswordEncoder(); // String tt = t.encodePassword( "123456" , // tUser.getVcAccount() ); // tUser.setVcPassword( tt ); iUserService.updateUser(tUser); AjaxUtil.rendJson(response, true, "???"); } } } catch (Exception e) { e.printStackTrace(); AjaxUtil.rendJson(response, false, "?" + e.getMessage()); } } /** * @Description Id?? * @param driverId * @author chengwzh * @date 2015/5/13 10:30 */ @RequestMapping(value = "/findDriverById", method = RequestMethod.POST) @ResponseBody @ApiOperation(value = "Id?", notes = "Id?", position = 5) public Map<String, Object> findDriverById(HttpServletRequest request, @ApiParam("?id") @RequestParam("driverId") int driverId) { try { Map<String, Object> driver = driverService.findById(driverId); Map<String, Object> truck = driverService.findCarNoById(driverId); if (driver == null) { return AjaxUtil.getMap(false, ""); } if (truck == null) { driver.put("vcCarNo", ""); } else { driver.put("truckId", truck.get("ID")); driver.put("vcCarNo", truck.get("VC_CAR_NO")); } // ? String url = staticService.getStringByParame("driverUrl"); if (StringUtils.isBlank(url)) { return AjaxUtil.getMap(false, "?"); } if (!url.endsWith("/")) { url += "/"; } Object imgPathObj = driver.get("VC_IMGPATH"); if (imgPathObj == null) { // return AjaxUtil.getMap( false , "?" ); } else { String imgPath = imgPathObj.toString(); String path = url + imgPath; driver.put("VC_IMGPATH", path); } JSONArray array = JSONArray.fromObject(driver); System.out.println("driver json:" + array); String visit = request.getParameter(SystemConstants.APP_VISIT_PARME); if (StringUtils.isNotBlank(visit) && SystemConstants.APP_VISIT.equals(visit)) { return AjaxUtil.getMapByNotException(true, driver); } else { return driver; } } catch (Exception e) { e.printStackTrace(); return AjaxUtil.getMapByException(e); } } /** * @Description ?? * @param driverId * @author chengwzh * @date 2015/5/13 10:40 */ @RequestMapping(value = "/deleteDriver", method = RequestMethod.POST) @ApiOperation(value = "?", notes = "?", position = 5, response = TDriver.class) @ResponseBody public Map<String, Object> deleteDriver( @ApiParam(value = "?id") @RequestParam("driverId") Integer driverId, HttpServletResponse response) { try { driverService.deleteLinkById(driverId);// link TDriver driver = driverService.get(driverId); driver.setNEnable(SystemConstants.SYS_DISABLE); /** * */ String[] properties = { "IArchiveType", "iArchive", "NEnable" }; Object[] mainvalues = { SystemConstants.SYS_TARCHIVE_DRIVER, driverId, SystemConstants.SYS_ENABLE }; List<TUser> tUsers = iUserService.findByProperties(properties, mainvalues); if (tUsers != null && tUsers.size() > 0) { for (TUser tUser : tUsers) { tUser.setNEnable(SystemConstants.SYS_DISABLE); iUserService.updateUser(tUser); } } driverService.update(driver); return AjaxUtil.getMap(true, "???"); } catch (Exception e) { e.printStackTrace(); return AjaxUtil.getMapByException(e); } } /** * @Description ?? */ @RequestMapping(value = "/getAllTypes", method = RequestMethod.POST) @ResponseBody @ApiOperation(value = "??", notes = "??", position = 5) public Map<String, Object> getAllTypes(HttpServletRequest request) { try { Map<String, Object> result = driverService.findDriverClass(); String visit = request.getParameter(SystemConstants.APP_VISIT_PARME); return AjaxUtil.getMapByResult(visit, result); } catch (Exception e) { e.printStackTrace(); return AjaxUtil.getMapByException(e); } } /** * @Description ?? * @author chengwzh * @date 2015/5/22 10:50 */ @RequestMapping("/intoDriverSalaryList") @ApiIgnore public String intoDriverSalaryList() { return "sub/subBasicData/driverSalaryInfoList"; } /** * @Description ?? * @author chengwzh * @date 2015/5/22 11:40 */ @RequestMapping("/getDriverSalaryList") @ResponseBody @ApiIgnore public Map<String, Object> getDriverSalaryList(HttpServletRequest request, @RequestParam(value = "driverName", required = false) String driverName, @RequestParam(value = "nMonth", required = false) Integer nMonth) { HttpSession session = request.getSession(); TUser user = (TUser) session.getAttribute("user"); int subId = user.getiArchive(); String subno = subService.get(subId).getVcSubno(); HqlHelper hql = new HqlHelper(TDriverSalary.class); Page page = ServiceUtil.getcurrPage(request); hql.setQueryPage(page); hql.addEqual("nEnable", SystemConstants.SYS_ENABLE); hql.addEqual("vcSubno", subno); // ???? if (StringUtils.isNotBlank(driverName)) { hql.addEqual("vcDriverName", driverName); } // ? if (nMonth != null) { hql.addEqual("nMonth", nMonth); } Map<String, Object> result = salaryService.findByHelper(hql); JSONArray array = JSONArray.fromObject(result); System.out.println("driver salary json:" + array); return result; } /** * @Description ???? * @author chengwzh * @date 2015/5/22 15:43 */ @RequestMapping(value = "/intoSave") @ApiIgnore public String intoSave(@RequestParam(value = "id", required = false) Integer id, HttpServletRequest request) { if (id != null) { TDriverSalary driverSalary = salaryService.get(id); request.setAttribute("driverSalary", driverSalary); } // ?? TUser user = (TUser) request.getSession().getAttribute("user"); String subno = subService.get(user.getiArchive()).getVcSubno(); String[] propertyNames = { "vcSubno", "NEnable" }; Object[] values = { subno, SystemConstants.SYS_ENABLE }; List<TDriver> drivers = driverService.findByPropertys(propertyNames, values); request.setAttribute("drivers", drivers); return "sub/subBasicData/driverSalarySave"; } /** * @Description ?? */ @RequestMapping("/saveDriverSalary") @ApiIgnore public void saveDriverSalary(HttpServletRequest request, TDriverSalary entity, HttpServletResponse response) { try { int driverId = entity.getiDriverId(); TDriver driver = driverService.get(driverId); String driverName = driver.getVcDriverName(); entity.setVcDriverName(driverName); // id? if (entity.getId() == null) { HttpSession session = request.getSession(); TUser user = (TUser) session.getAttribute("user"); String addUser = user.getVcUsername();// ??? int subId = user.getiArchive(); String subno = subService.get(subId).getVcSubno();// ?? entity.setVcAddUser(addUser); entity.setVcSubno(subno); String[] nMonths = request.getParameterValues("nMonths"); // ??id? // List< Integer > months = salaryService.getMonthsExist( // driverId ); List<TDriverSalary> entities = new ArrayList<TDriverSalary>(); if (nMonths.length > 0) { for (String nMonth : nMonths) { // if ( months != null // && months.contains( Integer.parseInt( nMonth ) ) ) // { // AjaxUtil.rendJson( response , false , "" + nMonth // + "" ); // return; // } TDriverSalary salary = new TDriverSalary(); salary.setDtStart(entity.getDtStart()); salary.setDtEnd(entity.getDtEnd()); salary.setiDriverId(entity.getiDriverId()); salary.setnSalary(entity.getnSalary()); salary.setVcDriverName(entity.getVcDriverName()); salary.setnMonth(Integer.parseInt(nMonth)); salary.setVcAddUser(entity.getVcAddUser()); salary.setVcSubno(entity.getVcSubno()); entities.add(salary); } } salaryService.saveOrUpdateAll(entities); } else { salaryService.saveOrUpdate(entity); } AjaxUtil.rendJson(response, true, "???"); } catch (Exception e) { e.printStackTrace(); AjaxUtil.rendJson(response, false, "?" + e.getMessage()); } } /** * @Description ? * @author chengwzh * @date 2015/5/25 17:46 */ @RequestMapping("/delDriverSalary") @ApiIgnore public void deleteDriverSalary(@RequestParam(value = "id") int id, HttpServletResponse response) { try { salaryService.delete(id); AjaxUtil.rendJson(response, true, "?"); } catch (Exception e) { e.printStackTrace(); AjaxUtil.rendJson(response, false, "" + e.getMessage()); } } /** * */ @RequestMapping(value = "/getMonthsExist", method = RequestMethod.POST) @ResponseBody @ApiOperation(value = "?", notes = "?", position = 5) public Map<String, Object> getMonthsExist(@ApiParam("driverId") @RequestParam int driverId) { try { List<Integer> months = salaryService.getMonthsExist(driverId); if (months == null) { return AjaxUtil.getMap(false, "?"); } else { return AjaxUtil.getMapByNotException(true, months); } } catch (Exception e) { e.printStackTrace(); return AjaxUtil.getMapByException(e); } } /** * ?? * * @param request * @param files * @throws FileNotFoundException * @throws IOException */ private void uploadImg(HttpServletRequest request, CommonsMultipartFile[] files, TDriver driver) throws FileNotFoundException, IOException { if (files == null) { return; } for (int i = 0; i < files.length; i++) { System.out.println("fileName---------->" + files[i].getOriginalFilename()); if (!files[i].isEmpty()) { int pre = (int) System.currentTimeMillis(); // String source = request.getSession().getServletContext() // .getRealPath( "/" ); String source = pictureService.getPathById(22);// ? if (!source.endsWith("/")) { source += "/"; } if (StringUtils.isBlank(source)) { System.out.println("source??"); return; } String path = source; File pathFile = new File(path); if (!pathFile.exists()) { pathFile.mkdirs(); } String jpgPath = new Date().getTime() + files[i].getOriginalFilename(); // path += new Date().getTime() + // files[i].getOriginalFilename(); path += jpgPath; // ????? FileOutputStream os = new FileOutputStream(path); // ? ByteArrayInputStream in = (ByteArrayInputStream) files[i].getInputStream(); // ? int b = 0; while ((b = in.read()) != -1) { os.write(b); } os.flush(); os.close(); in.close(); int finaltime = (int) System.currentTimeMillis(); System.out.println(finaltime - pre); String imgPath = driver.getVcImgPath(); if (StringUtils.isBlank(imgPath)) { driver.setVcImgPath(jpgPath); } else { // share.setVcImgpath( imgPath + "," + path ); imgPath = imgPath.substring(imgPath.lastIndexOf("/") + 1);// ? String existImgPath = source + imgPath; File imgFile = new File(existImgPath); if (imgFile.exists()) { boolean isDel = imgFile.delete(); if (isDel) { System.out.println("'" + imgPath + "'"); } } driver.setVcImgPath(jpgPath); } } } } /** * ?? * * @param request * @param files * @throws FileNotFoundException * @throws IOException */ private void uploadCardImg(HttpServletRequest request, CommonsMultipartFile[] files, TDriver driver) throws FileNotFoundException, IOException { if (files == null) { return; } for (int i = 0; i < files.length; i++) { System.out.println("fileName---------->" + files[i].getOriginalFilename()); if (!files[i].isEmpty()) { int pre = (int) System.currentTimeMillis(); // String source = request.getSession().getServletContext() // .getRealPath( "/" ); String source = pictureService.getPathById(22);// ? if (!source.endsWith("/")) { source += "/"; } if (StringUtils.isBlank(source)) { System.out.println("source??"); return; } String path = source; File pathFile = new File(path); if (!pathFile.exists()) { pathFile.mkdirs(); } String jpgPath = new Date().getTime() + files[i].getOriginalFilename(); // path += new Date().getTime() + // files[i].getOriginalFilename(); path += jpgPath; // ????? FileOutputStream os = new FileOutputStream(path); // ? ByteArrayInputStream in = (ByteArrayInputStream) files[i].getInputStream(); // ? int b = 0; while ((b = in.read()) != -1) { os.write(b); } os.flush(); os.close(); in.close(); int finaltime = (int) System.currentTimeMillis(); System.out.println(finaltime - pre); String imgPath = driver.getVcCardImgPath();// ?? if (StringUtils.isBlank(imgPath)) { driver.setVcCardImgPath(jpgPath); } else { // share.setVcImgpath( imgPath + "," + path ); imgPath = imgPath.substring(imgPath.lastIndexOf("/") + 1);// ? String existImgPath = source + imgPath; File imgFile = new File(existImgPath); if (imgFile.exists()) { boolean isDel = imgFile.delete(); if (isDel) { System.out.println("'" + imgPath + "'"); } } driver.setVcCardImgPath(jpgPath); } } } } /** * ?? * * @param request * @param files * @throws FileNotFoundException * @throws IOException */ private void uploadDriveImg(HttpServletRequest request, CommonsMultipartFile[] files, TDriver driver) throws FileNotFoundException, IOException { if (files == null) { return; } for (int i = 0; i < files.length; i++) { System.out.println("fileName---------->" + files[i].getOriginalFilename()); if (!files[i].isEmpty()) { int pre = (int) System.currentTimeMillis(); // String source = request.getSession().getServletContext() // .getRealPath( "/" ); String source = pictureService.getPathById(22);// ? if (!source.endsWith("/")) { source += "/"; } if (StringUtils.isBlank(source)) { System.out.println("source??"); return; } String path = source; File pathFile = new File(path); if (!pathFile.exists()) { pathFile.mkdirs(); } String jpgPath = new Date().getTime() + files[i].getOriginalFilename(); // path += new Date().getTime() + // files[i].getOriginalFilename(); path += jpgPath; // ????? FileOutputStream os = new FileOutputStream(path); // ? ByteArrayInputStream in = (ByteArrayInputStream) files[i].getInputStream(); // ? int b = 0; while ((b = in.read()) != -1) { os.write(b); } os.flush(); os.close(); in.close(); int finaltime = (int) System.currentTimeMillis(); System.out.println(finaltime - pre); String imgPath = driver.getVcDriveImgPath();// ?? if (StringUtils.isBlank(imgPath)) { driver.setVcDriveImgPath(jpgPath); } else { // share.setVcImgpath( imgPath + "," + path ); imgPath = imgPath.substring(imgPath.lastIndexOf("/") + 1);// ? String existImgPath = source + imgPath; File imgFile = new File(existImgPath); if (imgFile.exists()) { boolean isDel = imgFile.delete(); if (isDel) { System.out.println("'" + imgPath + "'"); } } driver.setVcDriveImgPath(jpgPath); } } } } /** * ? * * @param request * @param files * @throws FileNotFoundException * @throws IOException */ private void uploadTruckImg(HttpServletRequest request, CommonsMultipartFile[] files, TDriver driver) throws FileNotFoundException, IOException { if (files == null) { return; } for (int i = 0; i < files.length; i++) { System.out.println("fileName---------->" + files[i].getOriginalFilename()); if (!files[i].isEmpty()) { int pre = (int) System.currentTimeMillis(); // String source = request.getSession().getServletContext() // .getRealPath( "/" ); String source = pictureService.getPathById(22);// ? if (!source.endsWith("/")) { source += "/"; } if (StringUtils.isBlank(source)) { System.out.println("source??"); return; } String path = source; File pathFile = new File(path); if (!pathFile.exists()) { pathFile.mkdirs(); } String jpgPath = new Date().getTime() + files[i].getOriginalFilename(); // path += new Date().getTime() + // files[i].getOriginalFilename(); path += jpgPath; // ????? FileOutputStream os = new FileOutputStream(path); // ? ByteArrayInputStream in = (ByteArrayInputStream) files[i].getInputStream(); // ? int b = 0; while ((b = in.read()) != -1) { os.write(b); } os.flush(); os.close(); in.close(); int finaltime = (int) System.currentTimeMillis(); System.out.println(finaltime - pre); String imgPath = driver.getVcTruckImgPath(); if (StringUtils.isBlank(imgPath)) { driver.setVcTruckImgPath(jpgPath); } else { // share.setVcImgpath( imgPath + "," + path ); imgPath = imgPath.substring(imgPath.lastIndexOf("/") + 1);// ? String existImgPath = source + imgPath; File imgFile = new File(existImgPath); if (imgFile.exists()) { boolean isDel = imgFile.delete(); if (isDel) { System.out.println("'" + imgPath + "'"); } } driver.setVcTruckImgPath(jpgPath); } } } } /** * @Description ?????? */ @RequestMapping(value = "/getDriverMessage", method = RequestMethod.POST) @ResponseBody @ApiOperation(value = "??????", notes = ":driverId ?id<br/>" + "vcDriverName ???<br/>" + "vcImgPath <br/>", position = 5) public Map<String, Object> getDriverMessage(HttpSession session) { TUser user = (TUser) session.getAttribute("user"); int driverId = user.getiArchive(); int typeId = user.getIArchiveType();// ?? if (typeId != SystemConstants.SYS_TARCHIVE_DRIVER) { return AjaxUtil.getMap(false, "??,???"); } try { TDriver driver = driverService.get(driverId); Map<String, Object> result = new HashMap<String, Object>(); result.put("driverId", driverId); result.put("vcDriverName", driver.getVcDriverName()); // result.put( "vcImgPath" , driver.getVcImgPath() ); String path = staticService.getStringByParame("driverUrl"); if (StringUtils.isBlank(path)) { return AjaxUtil.getMap(false, "?"); } if (!path.endsWith("/")) { path += "/"; } path += driver.getVcImgPath(); result.put("vcImgPath", path);// return AjaxUtil.getMapByNotException(true, result); } catch (Exception e) { e.printStackTrace(); return AjaxUtil.getMapByException(e); } } /** * * @Description: ? * @param request * @param response * @return String ?? * @author hjx * @create_date 2015-7-27 ?4:22:08 */ @RequestMapping(value = "/getSpecification") @ApiIgnore public String getSpecification(HttpServletRequest request, HttpServletResponse response) { return "sub/subuser/registerLicense"; } }