DepotController.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. package com.jsh.erp.controller;
  2. import com.alibaba.fastjson.JSONArray;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.jsh.erp.base.BaseController;
  5. import com.jsh.erp.base.TableDataInfo;
  6. import com.jsh.erp.datasource.entities.Depot;
  7. import com.jsh.erp.datasource.entities.DepotEx;
  8. import com.jsh.erp.datasource.entities.MaterialInitialStock;
  9. import com.jsh.erp.service.DepotService;
  10. import com.jsh.erp.service.MaterialExtendService;
  11. import com.jsh.erp.service.MaterialService;
  12. import com.jsh.erp.service.UserBusinessService;
  13. import com.jsh.erp.utils.BaseResponseInfo;
  14. import com.jsh.erp.utils.Constants;
  15. import com.jsh.erp.utils.ErpInfo;
  16. import com.jsh.erp.utils.StringUtil;
  17. import io.swagger.annotations.Api;
  18. import io.swagger.annotations.ApiOperation;
  19. import org.slf4j.Logger;
  20. import org.slf4j.LoggerFactory;
  21. import org.springframework.web.bind.annotation.*;
  22. import javax.annotation.Resource;
  23. import javax.servlet.http.HttpServletRequest;
  24. import java.math.BigDecimal;
  25. import java.util.ArrayList;
  26. import java.util.HashMap;
  27. import java.util.List;
  28. import java.util.Map;
  29. import static com.jsh.erp.utils.ResponseJsonUtil.returnJson;
  30. import static com.jsh.erp.utils.ResponseJsonUtil.returnStr;
  31. /**
  32. * @author ji sheng hua 752*718*920
  33. */
  34. @RestController
  35. @RequestMapping(value = "/depot")
  36. @Api(tags = {"仓库管理"})
  37. public class DepotController extends BaseController {
  38. private Logger logger = LoggerFactory.getLogger(DepotController.class);
  39. @Resource
  40. private DepotService depotService;
  41. @Resource
  42. private UserBusinessService userBusinessService;
  43. @Resource
  44. private MaterialService materialService;
  45. @Resource
  46. private MaterialExtendService materialExtendService;
  47. @GetMapping(value = "/info")
  48. @ApiOperation(value = "根据id获取信息")
  49. public String getList(@RequestParam("id") Long id,
  50. HttpServletRequest request) throws Exception {
  51. Depot depot = depotService.getDepot(id);
  52. Map<String, Object> objectMap = new HashMap<>();
  53. if(depot != null) {
  54. objectMap.put("info", depot);
  55. return returnJson(objectMap, ErpInfo.OK.name, ErpInfo.OK.code);
  56. } else {
  57. return returnJson(objectMap, ErpInfo.ERROR.name, ErpInfo.ERROR.code);
  58. }
  59. }
  60. @GetMapping(value = "/list")
  61. @ApiOperation(value = "获取信息列表")
  62. public TableDataInfo getList(@RequestParam(value = Constants.SEARCH, required = false) String search,
  63. HttpServletRequest request)throws Exception {
  64. String name = StringUtil.getInfo(search, "name");
  65. Integer type = StringUtil.parseInteger(StringUtil.getInfo(search, "type"));
  66. String remark = StringUtil.getInfo(search, "remark");
  67. List<DepotEx> list = depotService.select(name, type, remark);
  68. return getDataTable(list);
  69. }
  70. @PostMapping(value = "/add")
  71. @ApiOperation(value = "新增")
  72. public String addResource(@RequestBody JSONObject obj, HttpServletRequest request)throws Exception {
  73. Map<String, Object> objectMap = new HashMap<>();
  74. int insert = depotService.insertDepot(obj, request);
  75. return returnStr(objectMap, insert);
  76. }
  77. @PutMapping(value = "/update")
  78. @ApiOperation(value = "修改")
  79. public String updateResource(@RequestBody JSONObject obj, HttpServletRequest request)throws Exception {
  80. Map<String, Object> objectMap = new HashMap<>();
  81. int update = depotService.updateDepot(obj, request);
  82. return returnStr(objectMap, update);
  83. }
  84. @DeleteMapping(value = "/delete")
  85. @ApiOperation(value = "删除")
  86. public String deleteResource(@RequestParam("id") Long id, HttpServletRequest request)throws Exception {
  87. Map<String, Object> objectMap = new HashMap<>();
  88. int delete = depotService.deleteDepot(id, request);
  89. return returnStr(objectMap, delete);
  90. }
  91. @DeleteMapping(value = "/deleteBatch")
  92. @ApiOperation(value = "批量删除")
  93. public String batchDeleteResource(@RequestParam("ids") String ids, HttpServletRequest request)throws Exception {
  94. Map<String, Object> objectMap = new HashMap<>();
  95. int delete = depotService.batchDeleteDepot(ids, request);
  96. return returnStr(objectMap, delete);
  97. }
  98. @GetMapping(value = "/checkIsNameExist")
  99. @ApiOperation(value = "检查名称是否存在")
  100. public String checkIsNameExist(@RequestParam Long id, @RequestParam(value ="name", required = false) String name,
  101. HttpServletRequest request)throws Exception {
  102. Map<String, Object> objectMap = new HashMap<>();
  103. int exist = depotService.checkIsNameExist(id, name);
  104. if(exist > 0) {
  105. objectMap.put("status", true);
  106. } else {
  107. objectMap.put("status", false);
  108. }
  109. return returnJson(objectMap, ErpInfo.OK.name, ErpInfo.OK.code);
  110. }
  111. /**
  112. * 仓库列表
  113. * @param request
  114. * @return
  115. * @throws Exception
  116. */
  117. @GetMapping(value = "/getAllList")
  118. @ApiOperation(value = "仓库列表")
  119. public BaseResponseInfo getAllList(HttpServletRequest request) throws Exception{
  120. BaseResponseInfo res = new BaseResponseInfo();
  121. try {
  122. List<Depot> depotList = depotService.getAllList();
  123. res.code = 200;
  124. res.data = depotList;
  125. } catch(Exception e){
  126. logger.error(e.getMessage(), e);
  127. res.code = 500;
  128. res.data = "获取数据失败";
  129. }
  130. return res;
  131. }
  132. /**
  133. * 用户对应仓库显示
  134. * @param type
  135. * @param keyId
  136. * @param request
  137. * @return
  138. */
  139. @GetMapping(value = "/findUserDepot")
  140. @ApiOperation(value = "用户对应仓库显示")
  141. public JSONArray findUserDepot(@RequestParam("UBType") String type, @RequestParam("UBKeyId") String keyId,
  142. HttpServletRequest request) throws Exception{
  143. JSONArray arr = new JSONArray();
  144. try {
  145. //获取权限信息
  146. String ubValue = userBusinessService.getUBValueByTypeAndKeyId(type, keyId);
  147. List<Depot> dataList = depotService.findUserDepot();
  148. //开始拼接json数据
  149. JSONObject outer = new JSONObject();
  150. outer.put("id", 0);
  151. outer.put("key", 0);
  152. outer.put("value", 0);
  153. outer.put("title", "仓库列表");
  154. outer.put("attributes", "仓库列表");
  155. //存放数据json数组
  156. JSONArray dataArray = new JSONArray();
  157. if (null != dataList) {
  158. for (Depot depot : dataList) {
  159. JSONObject item = new JSONObject();
  160. item.put("id", depot.getId());
  161. item.put("key", depot.getId());
  162. item.put("value", depot.getId());
  163. item.put("title", depot.getName());
  164. item.put("attributes", depot.getName());
  165. Boolean flag = ubValue.contains("[" + depot.getId().toString() + "]");
  166. if (flag) {
  167. item.put("checked", true);
  168. }
  169. dataArray.add(item);
  170. }
  171. }
  172. outer.put("children", dataArray);
  173. arr.add(outer);
  174. } catch (Exception e) {
  175. logger.error(e.getMessage(), e);
  176. }
  177. return arr;
  178. }
  179. /**
  180. * 获取当前用户拥有权限的仓库列表
  181. * @param request
  182. * @return
  183. * @throws Exception
  184. */
  185. @GetMapping(value = "/findDepotByCurrentUser")
  186. @ApiOperation(value = "获取当前用户拥有权限的仓库列表")
  187. public BaseResponseInfo findDepotByCurrentUser(HttpServletRequest request) throws Exception{
  188. BaseResponseInfo res = new BaseResponseInfo();
  189. try {
  190. JSONArray arr = depotService.findDepotByCurrentUser();
  191. res.code = 200;
  192. res.data = arr;
  193. } catch (Exception e) {
  194. logger.error(e.getMessage(), e);
  195. res.code = 500;
  196. res.data = "获取数据失败";
  197. }
  198. return res;
  199. }
  200. /**
  201. * 更新默认仓库
  202. * @param object
  203. * @param request
  204. * @return
  205. * @throws Exception
  206. */
  207. @PostMapping(value = "/updateIsDefault")
  208. @ApiOperation(value = "更新默认仓库")
  209. public String updateIsDefault(@RequestBody JSONObject object,
  210. HttpServletRequest request) throws Exception{
  211. Long depotId = object.getLong("id");
  212. Map<String, Object> objectMap = new HashMap<>();
  213. int res = depotService.updateIsDefault(depotId);
  214. if(res > 0) {
  215. return returnJson(objectMap, ErpInfo.OK.name, ErpInfo.OK.code);
  216. } else {
  217. return returnJson(objectMap, ErpInfo.ERROR.name, ErpInfo.ERROR.code);
  218. }
  219. }
  220. /**
  221. * 仓库列表-带库存
  222. * @param mId
  223. * @param request
  224. * @return
  225. */
  226. @GetMapping(value = "/getAllListWithStock")
  227. @ApiOperation(value = "仓库列表-带库存")
  228. public BaseResponseInfo getAllList(@RequestParam("mId") Long mId,
  229. HttpServletRequest request) {
  230. BaseResponseInfo res = new BaseResponseInfo();
  231. try {
  232. List<Depot> list = depotService.getAllList();
  233. List<DepotEx> depotList = new ArrayList<DepotEx>();
  234. for(Depot depot: list) {
  235. DepotEx de = new DepotEx();
  236. if(mId!=0) {
  237. BigDecimal initStock = materialService.getInitStock(mId, depot.getId());
  238. BigDecimal currentStock = materialService.getCurrentStockByMaterialIdAndDepotId(mId, depot.getId());
  239. de.setInitStock(initStock);
  240. de.setCurrentStock(currentStock == null ? BigDecimal.ZERO : currentStock);
  241. MaterialInitialStock materialInitialStock = materialService.getSafeStock(mId, depot.getId());
  242. de.setLowSafeStock(materialInitialStock.getLowSafeStock());
  243. de.setHighSafeStock(materialInitialStock.getHighSafeStock());
  244. de.setPosition(materialInitialStock.getPosition());
  245. } else {
  246. de.setInitStock(BigDecimal.ZERO);
  247. de.setCurrentStock(BigDecimal.ZERO);
  248. }
  249. de.setId(depot.getId());
  250. de.setName(depot.getName());
  251. depotList.add(de);
  252. }
  253. res.code = 200;
  254. res.data = depotList;
  255. } catch(Exception e){
  256. logger.error(e.getMessage(), e);
  257. res.code = 500;
  258. res.data = "获取数据失败";
  259. }
  260. return res;
  261. }
  262. /**
  263. * 批量设置状态-启用或者禁用
  264. * @param jsonObject
  265. * @param request
  266. * @return
  267. */
  268. @PostMapping(value = "/batchSetStatus")
  269. @ApiOperation(value = "批量设置状态")
  270. public String batchSetStatus(@RequestBody JSONObject jsonObject,
  271. HttpServletRequest request)throws Exception {
  272. Boolean status = jsonObject.getBoolean("status");
  273. String ids = jsonObject.getString("ids");
  274. Map<String, Object> objectMap = new HashMap<>();
  275. int res = depotService.batchSetStatus(status, ids);
  276. if(res > 0) {
  277. return returnJson(objectMap, ErpInfo.OK.name, ErpInfo.OK.code);
  278. } else {
  279. return returnJson(objectMap, ErpInfo.ERROR.name, ErpInfo.ERROR.code);
  280. }
  281. }
  282. }