MaterialExtendController.java 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. package com.jsh.erp.controller;
  2. import com.alibaba.fastjson.JSONArray;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.jsh.erp.datasource.entities.MaterialExtend;
  5. import com.jsh.erp.datasource.vo.MaterialExtendVo4List;
  6. import com.jsh.erp.service.MaterialExtendService;
  7. import com.jsh.erp.utils.BaseResponseInfo;
  8. import com.jsh.erp.utils.DateUtils;
  9. import com.jsh.erp.utils.ErpInfo;
  10. import com.jsh.erp.utils.StringUtil;
  11. import io.swagger.annotations.Api;
  12. import io.swagger.annotations.ApiOperation;
  13. import org.slf4j.Logger;
  14. import org.slf4j.LoggerFactory;
  15. import org.springframework.web.bind.annotation.*;
  16. import javax.annotation.Resource;
  17. import javax.servlet.http.HttpServletRequest;
  18. import java.util.ArrayList;
  19. import java.util.HashMap;
  20. import java.util.List;
  21. import java.util.Map;
  22. import static com.jsh.erp.utils.ResponseJsonUtil.returnJson;
  23. import static com.jsh.erp.utils.ResponseJsonUtil.returnStr;
  24. /**
  25. * @author jijiaqing
  26. */
  27. @RestController
  28. @RequestMapping(value = "/materialsExtend")
  29. @Api(tags = {"商品价格扩展"})
  30. public class MaterialExtendController {
  31. private Logger logger = LoggerFactory.getLogger(MaterialExtendController.class);
  32. @Resource
  33. private MaterialExtendService materialExtendService;
  34. @GetMapping(value = "/info")
  35. @ApiOperation(value = "根据id获取信息")
  36. public String getList(@RequestParam("id") Long id,
  37. HttpServletRequest request) throws Exception {
  38. MaterialExtend materialExtend = materialExtendService.getMaterialExtend(id);
  39. Map<String, Object> objectMap = new HashMap<>();
  40. if(materialExtend != null) {
  41. objectMap.put("info", materialExtend);
  42. return returnJson(objectMap, ErpInfo.OK.name, ErpInfo.OK.code);
  43. } else {
  44. return returnJson(objectMap, ErpInfo.ERROR.name, ErpInfo.ERROR.code);
  45. }
  46. }
  47. @PostMapping(value = "/add")
  48. @ApiOperation(value = "新增")
  49. public String addResource(@RequestBody JSONObject obj, HttpServletRequest request)throws Exception {
  50. Map<String, Object> objectMap = new HashMap<>();
  51. int insert = materialExtendService.insertMaterialExtend(obj, request);
  52. return returnStr(objectMap, insert);
  53. }
  54. @PutMapping(value = "/update")
  55. @ApiOperation(value = "修改")
  56. public String updateResource(@RequestBody JSONObject obj, HttpServletRequest request)throws Exception {
  57. Map<String, Object> objectMap = new HashMap<>();
  58. int update = materialExtendService.updateMaterialExtend(obj, request);
  59. return returnStr(objectMap, update);
  60. }
  61. @DeleteMapping(value = "/delete")
  62. @ApiOperation(value = "删除")
  63. public String deleteResource(@RequestParam("id") Long id, HttpServletRequest request)throws Exception {
  64. Map<String, Object> objectMap = new HashMap<>();
  65. int delete = materialExtendService.deleteMaterialExtend(id, request);
  66. return returnStr(objectMap, delete);
  67. }
  68. @DeleteMapping(value = "/deleteBatch")
  69. @ApiOperation(value = "批量删除")
  70. public String batchDeleteResource(@RequestParam("ids") String ids, HttpServletRequest request)throws Exception {
  71. Map<String, Object> objectMap = new HashMap<>();
  72. int delete = materialExtendService.batchDeleteMaterialExtendByIds(ids, request);
  73. return returnStr(objectMap, delete);
  74. }
  75. @GetMapping(value = "/getDetailList")
  76. @ApiOperation(value = "价格信息列表")
  77. public BaseResponseInfo getDetailList(@RequestParam("materialId") Long materialId,
  78. HttpServletRequest request)throws Exception {
  79. BaseResponseInfo res = new BaseResponseInfo();
  80. try {
  81. List<MaterialExtendVo4List> dataList = new ArrayList<MaterialExtendVo4List>();
  82. if(materialId!=0) {
  83. dataList = materialExtendService.getDetailList(materialId);
  84. }
  85. JSONObject outer = new JSONObject();
  86. outer.put("total", dataList.size());
  87. //存放数据json数组
  88. JSONArray dataArray = new JSONArray();
  89. if (null != dataList) {
  90. for (MaterialExtendVo4List md : dataList) {
  91. JSONObject item = new JSONObject();
  92. item.put("id", md.getId());
  93. item.put("barCode", md.getBarCode());
  94. item.put("commodityUnit", md.getCommodityUnit());
  95. if(StringUtil.isNotEmpty(md.getSku())){
  96. item.put("sku", md.getSku());
  97. }
  98. item.put("purchaseDecimal", md.getPurchaseDecimal());
  99. item.put("commodityDecimal", md.getCommodityDecimal());
  100. item.put("wholesaleDecimal", md.getWholesaleDecimal());
  101. item.put("lowDecimal", md.getLowDecimal());
  102. item.put("productionDate", DateUtils.dateTime(md.getProductionDate()));
  103. item.put("expiryNum",md.getExpiryNum());
  104. item.put("supplierId",md.getSupplierId());
  105. item.put("barCode",md.getBarCode());
  106. item.put("batchNumber",md.getBatchNumber());
  107. item.put("inventory",md.getInventory());
  108. item.put("depotId",md.getDepotId());
  109. item.put("position",md.getPosition());
  110. dataArray.add(item);
  111. }
  112. }
  113. outer.put("rows", dataArray);
  114. res.code = 200;
  115. res.data = outer;
  116. } catch (Exception e) {
  117. logger.error(e.getMessage(), e);
  118. res.code = 500;
  119. res.data = "获取数据失败";
  120. }
  121. return res;
  122. }
  123. /**
  124. * 根据条码查询商品信息
  125. * @param barCode
  126. * @param request
  127. * @return
  128. * @throws Exception
  129. */
  130. @GetMapping(value = "/getInfoByBarCode")
  131. @ApiOperation(value = "根据条码查询商品信息")
  132. public BaseResponseInfo getInfoByBarCode(@RequestParam("barCode") String barCode,
  133. HttpServletRequest request)throws Exception {
  134. BaseResponseInfo res = new BaseResponseInfo();
  135. Map<String, Object> map = new HashMap<String, Object>();
  136. try {
  137. MaterialExtend materialExtend = materialExtendService.getInfoByBarCode(barCode);
  138. res.code = 200;
  139. res.data = materialExtend;
  140. } catch (Exception e) {
  141. logger.error(e.getMessage(), e);
  142. res.code = 500;
  143. res.data = "获取数据失败";
  144. }
  145. return res;
  146. }
  147. /**
  148. * 校验条码是否存在
  149. * @param id
  150. * @param barCode
  151. * @param request
  152. * @return
  153. * @throws Exception
  154. */
  155. @GetMapping(value = "/checkIsBarCodeExist")
  156. @ApiOperation(value = "校验条码是否存在")
  157. public BaseResponseInfo checkIsBarCodeExist(@RequestParam("id") Long id,
  158. @RequestParam("barCode") String barCode,
  159. HttpServletRequest request)throws Exception {
  160. BaseResponseInfo res = new BaseResponseInfo();
  161. Map<String, Object> map = new HashMap<>();
  162. try {
  163. int exist = materialExtendService.checkIsBarCodeExist(id, barCode);
  164. if(exist > 0) {
  165. map.put("status", true);
  166. } else {
  167. map.put("status", false);
  168. }
  169. res.code = 200;
  170. res.data = map;
  171. } catch (Exception e) {
  172. logger.error(e.getMessage(), e);
  173. res.code = 500;
  174. res.data = "获取数据失败";
  175. }
  176. return res;
  177. }
  178. }