当前位置:   article > 正文

ssm仓库管理系统源码_java ssm源码

java ssm源码

【216】ssm仓库管理系统

# warehouse
基于SSM框架的仓库管理系统
开发环境:idea或eclipse  mysql5  mysql8均可  jdk1.8
开发技术:ssm maven jsp

角色:管理员 账号1001  密码123456
    普通用户  可自己注册


  1. package com.ken.wms.common.controller;
  2. import com.ken.wms.common.service.Interface.RepositoryService;
  3. import com.ken.wms.common.util.Response;
  4. import com.ken.wms.common.util.ResponseFactory;
  5. import com.ken.wms.domain.Repository;
  6. import com.ken.wms.exception.RepositoryManageServiceException;
  7. import org.apache.commons.lang3.StringUtils;
  8. import org.springframework.beans.factory.annotation.Autowired;
  9. import org.springframework.stereotype.Controller;
  10. import org.springframework.web.bind.annotation.*;
  11. import org.springframework.web.multipart.MultipartFile;
  12. import javax.servlet.http.HttpServletResponse;
  13. import java.io.File;
  14. import java.io.FileInputStream;
  15. import java.io.IOException;
  16. import java.io.OutputStream;
  17. import java.util.ArrayList;
  18. import java.util.HashMap;
  19. import java.util.List;
  20. import java.util.Map;
  21. /**
  22. * 仓库信息管理请求 Handler
  23. *
  24. * @author Ken
  25. */
  26. @Controller
  27. @RequestMapping(value = "/**/repositoryManage")
  28. public class RepositoryManageHandler {
  29. @Autowired
  30. private RepositoryService repositoryService;
  31. private static final String SEARCH_BY_ID = "searchByID";
  32. private static final String SEARCH_BY_ADDRESS = "searchByAddress";
  33. private static final String SEARCH_ALL = "searchAll";
  34. /**
  35. * 通用的记录查询
  36. *
  37. * @param searchType 查询方式
  38. * @param keyword 查询关键字
  39. * @param offset 分页偏移值
  40. * @param limit 分页大小
  41. * @return 返回所有符合条件的查询结果
  42. */
  43. private Map<String, Object> query(String searchType, String keyword, int offset, int limit) throws RepositoryManageServiceException {
  44. Map<String, Object> queryResult = null;
  45. switch (searchType) {
  46. case SEARCH_BY_ID:
  47. if (StringUtils.isNumeric(keyword)) {
  48. queryResult = repositoryService.selectById(Integer.valueOf(keyword));
  49. }
  50. break;
  51. case SEARCH_BY_ADDRESS:
  52. queryResult = repositoryService.selectByAddress(offset, limit, keyword);
  53. break;
  54. case SEARCH_ALL:
  55. queryResult = repositoryService.selectAll(offset, limit);
  56. break;
  57. default:
  58. // do other thing
  59. break;
  60. }
  61. return queryResult;
  62. }
  63. /**
  64. * 查询仓库信息
  65. *
  66. * @param searchType 查询类型
  67. * @param offset 分页偏移值
  68. * @param limit 分页大小
  69. * @param keyWord 查询关键字
  70. * @return 返回一个Map,其中key=rows,表示查询出来的记录;key=total,表示记录的总条数
  71. */
  72. @SuppressWarnings("unchecked")
  73. @RequestMapping(value = "getRepositoryList", method = RequestMethod.GET)
  74. public
  75. @ResponseBody
  76. Map<String, Object> getRepositoryList(@RequestParam("searchType") String searchType,
  77. @RequestParam("offset") int offset, @RequestParam("limit") int limit,
  78. @RequestParam("keyWord") String keyWord) throws RepositoryManageServiceException {
  79. // 初始化 Response
  80. Response responseContent = ResponseFactory.newInstance();
  81. List<Repository> rows = null;
  82. long total = 0;
  83. // 查询
  84. Map<String, Object> queryResult = query(searchType, keyWord, offset, limit);
  85. if (queryResult != null) {
  86. rows = (List<Repository>) queryResult.get("data");
  87. total = (long) queryResult.get("total");
  88. }
  89. // 设置 Response
  90. responseContent.setCustomerInfo("rows", rows);
  91. responseContent.setResponseTotal(total);
  92. return responseContent.generateResponse();
  93. }
  94. /**
  95. * 查询所有未指派管理员的仓库
  96. *
  97. * @return 返回一个 map,其中key=data表示查询的记录,key=total表示记录的条数
  98. */
  99. @SuppressWarnings("unchecked")
  100. @RequestMapping(value = "getUnassignRepository", method = RequestMethod.GET)
  101. public
  102. @ResponseBody
  103. Map<String, Object> getUnassignRepository() throws RepositoryManageServiceException {
  104. // 初始化结果集
  105. Map<String, Object> resultSet = new HashMap<>();
  106. List<Repository> data;
  107. long total = 0;
  108. // 查询
  109. Map<String, Object> queryResult = repositoryService.selectUnassign();
  110. if (queryResult != null) {
  111. data = (List<Repository>) queryResult.get("data");
  112. total = (long) queryResult.get("total");
  113. } else
  114. data = new ArrayList<>();
  115. resultSet.put("data", data);
  116. resultSet.put("total", total);
  117. return resultSet;
  118. }
  119. /**
  120. * 添加一条仓库信息
  121. *
  122. * @param repository 仓库信息
  123. * @return 返回一个map,其中:key 为 result表示操作的结果,包括:success 与 error
  124. */
  125. @RequestMapping(value = "addRepository", method = RequestMethod.POST)
  126. public
  127. @ResponseBody
  128. Map<String, Object> addRepository(@RequestBody Repository repository) throws RepositoryManageServiceException {
  129. // 初始化 Response
  130. Response responseContent = ResponseFactory.newInstance();
  131. // 添加记录
  132. String result = repositoryService.addRepository(repository) ? Response.RESPONSE_RESULT_SUCCESS : Response.RESPONSE_RESULT_ERROR;
  133. // 设置 Response
  134. responseContent.setResponseResult(result);
  135. return responseContent.generateResponse();
  136. }
  137. /**
  138. * 查询指定 ID 的仓库信息
  139. *
  140. * @param repositoryID 仓库ID
  141. * @return 返回一个map,其中:key 为 result 的值为操作的结果,包括:success 与 error;key 为 data
  142. * 的值为仓库信息
  143. */
  144. @RequestMapping(value = "getRepositoryInfo", method = RequestMethod.GET)
  145. public
  146. @ResponseBody
  147. Map<String, Object> getRepositoryInfo(@RequestParam("repositoryID") Integer repositoryID) throws RepositoryManageServiceException {
  148. // 初始化 Response
  149. Response responseContent = ResponseFactory.newInstance();
  150. String result = Response.RESPONSE_RESULT_ERROR;
  151. // 查询
  152. Repository repository = null;
  153. Map<String, Object> queryResult = repositoryService.selectById(repositoryID);
  154. if (queryResult != null) {
  155. repository = (Repository) queryResult.get("data");
  156. if (repository != null)
  157. result = Response.RESPONSE_RESULT_SUCCESS;
  158. }
  159. // 设置 Response
  160. responseContent.setResponseResult(result);
  161. responseContent.setResponseData(repository);
  162. return responseContent.generateResponse();
  163. }
  164. /**
  165. * 更新仓库信息
  166. *
  167. * @param repository 仓库信息
  168. * @return 返回一个map,其中:key 为 result 的值为操作的结果,包括:success 与 error;key 为 data
  169. * 的值为仓库信息
  170. */
  171. @RequestMapping(value = "updateRepository", method = RequestMethod.POST)
  172. public
  173. @ResponseBody
  174. Map<String, Object> updateRepository(@RequestBody Repository repository) throws RepositoryManageServiceException {
  175. // 初始化 Response
  176. Response responseContent = ResponseFactory.newInstance();
  177. // 更新
  178. String result = repositoryService.updateRepository(repository) ? Response.RESPONSE_RESULT_SUCCESS : Response.RESPONSE_RESULT_ERROR;
  179. // 设置 Response
  180. responseContent.setResponseResult(result);
  181. return responseContent.generateResponse();
  182. }
  183. /**
  184. * 删除指定 ID 的仓库信息
  185. *
  186. * @param repositoryID 仓库ID
  187. * @return 返回一个map,其中:key 为 result 的值为操作的结果,包括:success 与 error;key 为 data
  188. * 的值为仓库信息
  189. */
  190. @RequestMapping(value = "deleteRepository", method = RequestMethod.GET)
  191. public
  192. @ResponseBody
  193. Map<String, Object> deleteRepository(@RequestParam("repositoryID") Integer repositoryID) throws RepositoryManageServiceException {
  194. // 初始化 Response
  195. Response responseContent = ResponseFactory.newInstance();
  196. // 删除记录
  197. String result = repositoryService.deleteRepository(repositoryID) ? Response.RESPONSE_RESULT_SUCCESS : Response.RESPONSE_RESULT_ERROR;
  198. // 设置 Response
  199. responseContent.setResponseResult(result);
  200. return responseContent.generateResponse();
  201. }
  202. /**
  203. * 从文件中导入仓库信息
  204. *
  205. * @param file 保存有仓库信息的文件
  206. * @return 返回一个map,其中:key 为 result表示操作的结果,包括:success 与
  207. * error;key为total表示导入的总条数;key为available表示有效的条数
  208. */
  209. @RequestMapping(value = "importRepository", method = RequestMethod.POST)
  210. public
  211. @ResponseBody
  212. Map<String, Object> importRepository(MultipartFile file) throws RepositoryManageServiceException {
  213. // 初始化 Response
  214. Response responseContent = ResponseFactory.newInstance();
  215. String result = Response.RESPONSE_RESULT_ERROR;
  216. // 读取文件
  217. int total = 0;
  218. int available = 0;
  219. if (file != null) {
  220. Map<String, Object> importInfo = repositoryService.importRepository(file);
  221. if (importInfo != null) {
  222. total = (int) importInfo.get("total");
  223. available = (int) importInfo.get("available");
  224. result = Response.RESPONSE_RESULT_SUCCESS;
  225. }
  226. }
  227. // 设置 Response
  228. responseContent.setResponseResult(result);
  229. responseContent.setResponseTotal(total);
  230. responseContent.setCustomerInfo("available", available);
  231. return responseContent.generateResponse();
  232. }
  233. /**
  234. * 导出仓库信息到文件中
  235. *
  236. * @param searchType 查询类型
  237. * @param keyWord 查询关键字
  238. * @param response HttpServletResponse
  239. */
  240. @SuppressWarnings("unchecked")
  241. @RequestMapping(value = "exportRepository", method = RequestMethod.GET)
  242. public void exportRepository(@RequestParam("searchType") String searchType, @RequestParam("keyWord") String keyWord,
  243. HttpServletResponse response) throws RepositoryManageServiceException, IOException {
  244. // 导出文件名
  245. String fileName = "repositoryInfo.xlsx";
  246. // 查询
  247. List<Repository> repositories;
  248. Map<String, Object> queryResult = query(searchType, keyWord, -1, -1);
  249. if (queryResult != null)
  250. repositories = (List<Repository>) queryResult.get("data");
  251. else
  252. repositories = new ArrayList<>();
  253. // 生成文件
  254. File file = repositoryService.exportRepository(repositories);
  255. // 输出文件
  256. if (file != null) {
  257. // 设置响应头
  258. response.addHeader("Content-Disposition", "attachment;filename=" + fileName);
  259. FileInputStream inputStream = new FileInputStream(file);
  260. OutputStream outputStream = response.getOutputStream();
  261. byte[] buffer = new byte[8192];
  262. int len;
  263. while ((len = inputStream.read(buffer, 0, buffer.length)) > 0) {
  264. outputStream.write(buffer, 0, len);
  265. outputStream.flush();
  266. }
  267. inputStream.close();
  268. outputStream.close();
  269. }
  270. }
  271. }

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小小林熬夜学编程/article/detail/170123
推荐阅读
相关标签
  

闽ICP备14008679号