MaterialExtendController.java 8.9 KB

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