TBCarDriverController.java 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  1. package cn.com.lzt.car.driver.controller;
  2. import cn.com.lzt.car.cardoc.entity.CarEntity;
  3. import cn.com.lzt.car.driver.entity.TBCarDriver;
  4. import cn.com.lzt.car.driver.service.impl.TBCarDriverServiceImpl;
  5. import cn.hutool.core.date.DateUtil;
  6. import com.daju.mix.dao.mapper.TBCarMapper;
  7. import org.apache.commons.lang.xwork.StringUtils;
  8. import org.apache.poi.hssf.usermodel.HSSFRow;
  9. import org.apache.poi.hssf.usermodel.HSSFSheet;
  10. import org.apache.poi.hssf.usermodel.HSSFWorkbook;
  11. import org.apache.poi.ss.usermodel.*;
  12. import org.jeecgframework.core.common.controller.BaseController;
  13. import org.jeecgframework.core.common.exception.BusinessException;
  14. import org.jeecgframework.core.common.hibernate.qbc.CriteriaQuery;
  15. import org.jeecgframework.core.common.model.json.AjaxJson;
  16. import org.jeecgframework.core.common.model.json.DataGrid;
  17. import org.jeecgframework.core.util.StringUtil;
  18. import org.jeecgframework.tag.core.easyui.TagUtil;
  19. import org.jeecgframework.web.system.pojo.base.TSType;
  20. import org.jeecgframework.web.system.pojo.base.TSTypegroup;
  21. import org.jeecgframework.web.system.pojo.base.TSUser;
  22. import org.jeecgframework.web.system.service.SystemService;
  23. import org.jeecgframework.web.system.service.UserService;
  24. import org.springframework.beans.factory.annotation.Autowired;
  25. import org.springframework.stereotype.Controller;
  26. import org.springframework.ui.ModelMap;
  27. import org.springframework.web.bind.annotation.RequestMapping;
  28. import org.springframework.web.bind.annotation.ResponseBody;
  29. import org.springframework.web.multipart.MultipartFile;
  30. import org.springframework.web.servlet.ModelAndView;
  31. import javax.annotation.Resource;
  32. import javax.servlet.ServletOutputStream;
  33. import javax.servlet.http.HttpServletRequest;
  34. import javax.servlet.http.HttpServletResponse;
  35. import java.io.IOException;
  36. import java.io.OutputStream;
  37. import java.net.URLEncoder;
  38. import java.util.*;
  39. @Controller
  40. @RequestMapping("/tBCarDriverController")
  41. public class TBCarDriverController extends BaseController {
  42. @Resource
  43. private TBCarDriverServiceImpl tbCarDriverService;
  44. @Autowired
  45. private UserService userService;
  46. @Resource
  47. TBCarMapper tbCarMapper;
  48. @Autowired
  49. SystemService systemService;
  50. @RequestMapping(params = "driverList")
  51. public ModelAndView nlist(HttpServletRequest request) {
  52. return new ModelAndView("cn/com/lzt/car/driver/driverList");
  53. }
  54. @RequestMapping(params = "datagrid")
  55. public void datagrid(TBCarDriver driver, HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
  56. CriteriaQuery cq = new CriteriaQuery(TBCarDriver.class, dataGrid);
  57. //自定义追加查询条件
  58. String name = request.getParameter("userName");
  59. // 查询条件组装器
  60. if (StringUtils.isNotBlank(name)) {
  61. // 模糊查询
  62. cq.like("userName", "%" + name + "%");
  63. driver.setUserName(null);
  64. }
  65. String licenseType = request.getParameter("licenseType");
  66. // 查询条件组装器
  67. if (StringUtils.isNotBlank(licenseType)) {
  68. cq.eq("licenseType", licenseType);
  69. driver.setLicenseType(null);
  70. }
  71. String licenseArea = request.getParameter("licenseArea");
  72. // 查询条件组装器
  73. if (StringUtils.isNotBlank(licenseArea)) {
  74. // 模糊查询
  75. cq.eq("licenseArea", licenseArea);
  76. driver.setLicenseArea(null);
  77. }
  78. String havingDate = request.getParameter("havingDate");
  79. // 查询条件组装器
  80. if (StringUtils.isNotBlank(havingDate)) {
  81. // 模糊查询
  82. cq.eq("havingDate", havingDate );
  83. driver.setHavingDate(null);
  84. }
  85. String effectiveDate = request.getParameter("effectiveDate");
  86. // 查询条件组装器
  87. if (StringUtils.isNotBlank(effectiveDate)) {
  88. // 模糊查询
  89. cq.like("effectiveDate", effectiveDate);
  90. driver.setEffectiveDate(null);
  91. }
  92. //查询条件组装器
  93. org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, driver, request.getParameterMap());
  94. cq.add();
  95. this.tbCarDriverService.getDataGridReturn(cq, true);
  96. List<TBCarDriver> resultes = dataGrid.getResults();
  97. for (TBCarDriver tbCarDriver : resultes){
  98. if(StringUtil.isNotEmpty(tbCarDriver.getUserId())){
  99. TSUser tsUser = userService.get(TSUser.class, tbCarDriver.getUserId());
  100. if(tsUser != null){
  101. tbCarDriver.setMobilePhone(tsUser.getMobilePhone());
  102. tbCarDriver.setIdcard(tsUser.getIdcard());
  103. tbCarDriver.setAddress(tsUser.getAddress());
  104. }
  105. }
  106. }
  107. TagUtil.datagrid(response, dataGrid);
  108. }
  109. @RequestMapping(params = "doAdd")
  110. @ResponseBody
  111. public AjaxJson doAdd(TBCarDriver driver, HttpServletRequest request) {
  112. String message = null;
  113. AjaxJson j = new AjaxJson();
  114. message = "驾驶员档案添加成功";
  115. try {
  116. //driver.setCreateTime(DateUtil.parse(DateUtil.now(), "YYYY-MM-dd HH:mm:ss"));
  117. tbCarDriverService.save(driver);
  118. //carService.save(car);
  119. } catch (Exception e) {
  120. e.printStackTrace();
  121. message = "驾驶员档案添加失败";
  122. throw new BusinessException(e.getMessage());
  123. }
  124. j.setMsg(message);
  125. return j;
  126. }
  127. @RequestMapping(params = "goAdd")
  128. public ModelAndView goAdd(TBCarDriver driver, HttpServletRequest req) {
  129. if (StringUtil.isNotEmpty(driver.getId())) {
  130. driver = tbCarDriverService.getEntity(CarEntity.class, driver.getId());
  131. req.setAttribute("driverPage", driver);
  132. }
  133. return new ModelAndView("cn/com/lzt/car/driver/driver-add");
  134. }
  135. @RequestMapping(params = "doUpdate")
  136. @ResponseBody
  137. public AjaxJson doUpdate(TBCarDriver driver, HttpServletRequest request) {
  138. String message = null;
  139. AjaxJson j = new AjaxJson();
  140. message = "驾驶员档案更新成功";
  141. TBCarDriver t = tbCarDriverService.get(TBCarDriver.class, driver.getId());
  142. try {
  143. t.setUpdateTime(DateUtil.parse(DateUtil.now(), "YYYY-MM-dd HH:mm:ss"));
  144. t.setLicenseNum(driver.getLicenseNum());
  145. t.setUserName(driver.getUserName());
  146. t.setUserId(driver.getUserId());
  147. t.setLicenseArea(driver.getLicenseArea());
  148. t.setLicenseType(driver.getLicenseType());
  149. t.setDrivingLicense(driver.getDrivingLicense());
  150. t.setEffectiveDate(driver.getEffectiveDate());
  151. t.setRemarks(driver.getRemarks());
  152. tbCarDriverService.saveOrUpdate(t);
  153. } catch (Exception e) {
  154. e.printStackTrace();
  155. message = "驾驶员档案更新失败";
  156. throw new BusinessException(e.getMessage());
  157. }
  158. j.setMsg(message);
  159. return j;
  160. }
  161. @RequestMapping(params = "goUpdate")
  162. public ModelAndView goUpdate(TBCarDriver driver, HttpServletRequest req) {
  163. if (StringUtil.isNotEmpty(driver.getId())) {
  164. driver = tbCarDriverService.getEntity(TBCarDriver.class, driver.getId());
  165. if(StringUtil.isNotEmpty(driver.getUserId())){
  166. TSUser tsUser = userService.get(TSUser.class, driver.getUserId());
  167. if(tsUser != null){
  168. driver.setMobilePhone(tsUser.getMobilePhone());
  169. driver.setIdcard(tsUser.getIdcard());
  170. driver.setAddress(tsUser.getAddress());
  171. }
  172. }
  173. req.setAttribute("driverPage", driver);
  174. }
  175. return new ModelAndView("cn/com/lzt/car/driver/driver-update");
  176. }
  177. @RequestMapping(params = "doDel")
  178. @ResponseBody
  179. public AjaxJson doDel(TBCarDriver driver, HttpServletRequest request) {
  180. String message = null;
  181. AjaxJson j = new AjaxJson();
  182. driver = tbCarDriverService.getEntity(TBCarDriver.class, driver.getId());
  183. message = "驾驶员档案删除成功";
  184. try {
  185. tbCarDriverService.delete(driver);
  186. } catch (Exception e) {
  187. e.printStackTrace();
  188. message = "驾驶员档案删除失败";
  189. throw new BusinessException(e.getMessage());
  190. }
  191. j.setMsg(message);
  192. return j;
  193. }
  194. /**
  195. * 批量删除
  196. *
  197. * @return
  198. */
  199. @RequestMapping(params = "doBatchDel")
  200. @ResponseBody
  201. public AjaxJson doBatchDel(String ids, HttpServletRequest request) {
  202. String message = null;
  203. AjaxJson j = new AjaxJson();
  204. message = "驾驶员档案删除成功";
  205. try {
  206. for (String id : ids.split(",")) {
  207. TBCarDriver driver = tbCarDriverService.getEntity(TBCarDriver.class,
  208. Long.parseLong(id)
  209. );
  210. tbCarDriverService.delete(driver);
  211. }
  212. } catch (Exception e) {
  213. e.printStackTrace();
  214. message = "驾驶员档案删除失败";
  215. throw new BusinessException(e.getMessage());
  216. }
  217. j.setMsg(message);
  218. return j;
  219. }
  220. @RequestMapping(params = "upload")
  221. public ModelAndView upload(HttpServletRequest req) {
  222. req.setAttribute("controller_name", "tBCarDriverController");
  223. return new ModelAndView("common/upload/common_excel_upload");
  224. }
  225. /**
  226. * 导出excel
  227. *
  228. * @param request
  229. * @param response
  230. */
  231. @RequestMapping(params = "exportXls")
  232. public void exportXls(TBCarDriver car, HttpServletRequest request, HttpServletResponse response
  233. , DataGrid dataGrid, ModelMap modelMap) throws IOException {
  234. CriteriaQuery cq = new CriteriaQuery(TBCarDriver.class, dataGrid);
  235. org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, car, request.getParameterMap());
  236. List<TBCarDriver> cars = this.tbCarDriverService.getListByCriteriaQuery(cq, false);
  237. HSSFWorkbook wb = new HSSFWorkbook();
  238. HSSFSheet sheet = wb.createSheet("驾驶员档案管理");
  239. HSSFRow title = sheet.createRow(0);
  240. title.createCell(0).setCellValue("驾照档案号");
  241. title.createCell(1).setCellValue("员工姓名");
  242. title.createCell(2).setCellValue("员工电话");
  243. title.createCell(3).setCellValue("员工身份证号");
  244. title.createCell(4).setCellValue("员工居住地");
  245. title.createCell(5).setCellValue("准驾车型");
  246. title.createCell(6).setCellValue("驾照号码");
  247. title.createCell(7).setCellValue("驾照颁发地");
  248. title.createCell(8).setCellValue("领证日期");
  249. title.createCell(9).setCellValue("有效期");
  250. title.createCell(10).setCellValue("备注");
  251. // 根据数据字典关键字得到数据字典集合
  252. TSTypegroup tsTypegroup = this.systemService.getTypeGroupByCode("licenseType");
  253. Map<String,String> licenseTypesMap = new HashMap<>();
  254. if(tsTypegroup != null && tsTypegroup.getTSTypes().size() > 0){
  255. List<TSType> tsTypeList = tsTypegroup.getTSTypes();
  256. for (TSType tsType:tsTypeList){
  257. licenseTypesMap.put(tsType.getTypecode(),tsType.getTypename());
  258. }
  259. }
  260. for (int i = 1; i < cars.size()+1; i++) {
  261. TBCarDriver tbCarDriver = cars.get(i - 1);
  262. TSUser tsUser = userService.get(TSUser.class, tbCarDriver.getUserId());
  263. HSSFRow row = sheet.createRow(i);
  264. row.createCell(0).setCellValue(tbCarDriver.getLicenseNum());
  265. row.createCell(1).setCellValue(tbCarDriver.getUserName());
  266. row.createCell(2).setCellValue(tsUser.getMobilePhone());
  267. row.createCell(3).setCellValue(tsUser.getIdcard());
  268. row.createCell(4).setCellValue(tsUser.getAddress());
  269. row.createCell(5).setCellValue(licenseTypesMap.getOrDefault(tbCarDriver.getLicenseType(), "未知车型"));
  270. row.createCell(6).setCellValue(tbCarDriver.getDrivingLicense());
  271. row.createCell(7).setCellValue(tbCarDriver.getLicenseArea());
  272. row.createCell(8).setCellValue(tbCarDriver.getHavingDate());
  273. row.createCell(9).setCellValue(tbCarDriver.getEffectiveDate());
  274. row.createCell(10).setCellValue(tbCarDriver.getRemarks());
  275. }
  276. ServletOutputStream servletOutputStream = response.getOutputStream();
  277. response.reset();
  278. response.setHeader("Content-disposition", "attachment; filename=" + URLEncoder.encode("驾驶员档案管理") + ".xls");
  279. response.setContentType("application/vnd.ms-excel");
  280. wb.write((OutputStream) servletOutputStream);
  281. servletOutputStream.close();
  282. }
  283. @RequestMapping(params = "exportXlsByT")
  284. public void exportXlsByT(TBCarDriver car, HttpServletRequest request, HttpServletResponse response
  285. , DataGrid dataGrid, ModelMap modelMap) throws IOException {
  286. HSSFWorkbook wb = new HSSFWorkbook();
  287. HSSFSheet sheet = wb.createSheet("驾驶员档案管理");
  288. HSSFRow title = sheet.createRow(0);
  289. title.createCell(0).setCellValue("驾照档案号");
  290. title.createCell(1).setCellValue("员工姓名");
  291. title.createCell(2).setCellValue("准驾车型");
  292. title.createCell(3).setCellValue("驾照号码");
  293. title.createCell(4).setCellValue("驾照颁发地");
  294. title.createCell(5).setCellValue("领证日期");
  295. title.createCell(6).setCellValue("有效期");
  296. title.createCell(7).setCellValue("备注");
  297. ServletOutputStream servletOutputStream = response.getOutputStream();
  298. response.reset();
  299. response.setHeader("Content-disposition", "attachment; filename=" + URLEncoder.encode("驾驶员档案管理模板") + ".xls");
  300. response.setContentType("application/vnd.ms-excel");
  301. wb.write((OutputStream) servletOutputStream);
  302. servletOutputStream.close();
  303. }
  304. @RequestMapping(params = "importExcel")
  305. @ResponseBody
  306. public AjaxJson importExcel(MultipartFile files) throws IOException {
  307. Workbook wb = WorkbookFactory.create(files.getInputStream());
  308. for (int i = 0; i < wb.getNumberOfSheets(); i++) {
  309. Sheet sheet = wb.getSheetAt(i);
  310. //第一行标题
  311. Row firstRow = sheet.getRow(sheet.getFirstRowNum());
  312. for (int j = sheet.getFirstRowNum() + 1; j <= sheet.getLastRowNum(); j++) {
  313. Row row = sheet.getRow(j);
  314. if (row.getCell(0) == null ) {
  315. continue;
  316. }
  317. TBCarDriver tbCarDriver = new TBCarDriver();
  318. tbCarDriver.setLicenseNum(getStringCellValue(row.getCell(0)));
  319. tbCarDriver.setUserName(getStringCellValue(row.getCell(1)));
  320. tbCarDriver.setLicenseType(getStringCellValue(row.getCell(2)));
  321. tbCarDriver.setDrivingLicense(getStringCellValue(row.getCell(3)));
  322. tbCarDriver.setLicenseArea(getStringCellValue(row.getCell(4)));
  323. tbCarDriver.setHavingDate(getStringCellValue(row.getCell(5)));
  324. tbCarDriver.setEffectiveDate(getStringCellValue(row.getCell(6)));
  325. tbCarDriver.setRemarks(getStringCellValue(row.getCell(7)));
  326. tbCarDriverService.save(tbCarDriver);
  327. }
  328. }
  329. AjaxJson ajaxJson = new AjaxJson();
  330. ajaxJson.setMsg("导入成功");
  331. ajaxJson.setSuccess(true);
  332. return ajaxJson;
  333. }
  334. private String getStringCellValue(Cell cell) {
  335. try {
  336. return Optional.ofNullable(cell).map(Cell::getStringCellValue).orElse(null);
  337. } catch (IllegalStateException ex) {
  338. try {
  339. return Integer.toString(Double.valueOf(cell.getNumericCellValue()).intValue());
  340. }catch (IllegalStateException ex1){
  341. int cellNum = cell.getColumnIndex();
  342. log.error((cellNum + 1) + "格,错误", ex1);
  343. return null;
  344. }
  345. }
  346. }
  347. /**
  348. * 驾驶员驾照到期提醒
  349. */
  350. @RequestMapping(params = "driverRemind")
  351. @ResponseBody
  352. public AjaxJson driverRemind(){
  353. List<String> list = tbCarMapper.getDriverRemind();
  354. AjaxJson j = new AjaxJson();
  355. j.setMsg("请求成功");
  356. j.setObj(list);
  357. j.setSuccess(true);
  358. return j;
  359. }
  360. }