MaterialController.java 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907
  1. package com.jsh.erp.controller;
  2. import com.alibaba.fastjson.JSONArray;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.jsh.erp.base.AjaxResult;
  5. import com.jsh.erp.base.BaseController;
  6. import com.jsh.erp.base.TableDataInfo;
  7. import com.jsh.erp.datasource.dto.MaterialDto;
  8. import com.jsh.erp.datasource.entities.*;
  9. import com.jsh.erp.datasource.vo.TaskStocktakingItemVO;
  10. import com.jsh.erp.service.*;
  11. import com.jsh.erp.utils.*;
  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.beans.factory.annotation.Value;
  17. import org.springframework.web.bind.annotation.*;
  18. import org.springframework.web.multipart.MultipartFile;
  19. import javax.annotation.Resource;
  20. import javax.servlet.http.HttpServletRequest;
  21. import javax.servlet.http.HttpServletResponse;
  22. import java.math.BigDecimal;
  23. import java.util.*;
  24. import static com.jsh.erp.utils.ResponseJsonUtil.returnJson;
  25. import static com.jsh.erp.utils.ResponseJsonUtil.returnStr;
  26. /**
  27. * @author ji|sheng|hua jshERP
  28. */
  29. @RestController
  30. @RequestMapping(value = "/material")
  31. @Api(tags = {"商品管理"})
  32. public class MaterialController extends BaseController {
  33. private Logger logger = LoggerFactory.getLogger(MaterialController.class);
  34. @Resource
  35. private MaterialService materialService;
  36. @Resource
  37. private DepotItemService depotItemService;
  38. @Resource
  39. private SystemConfigService systemConfigService;
  40. @Resource
  41. private UnitService unitService;
  42. @Resource
  43. private DepotService depotService;
  44. @Resource
  45. private RoleService roleService;
  46. @Resource
  47. private UserService userService;
  48. @Resource
  49. private MaterialBatchService materialBatchService;
  50. @Value(value="${file.uploadType}")
  51. private Long fileUploadType;
  52. @GetMapping(value = "/info")
  53. @ApiOperation(value = "根据id获取信息")
  54. public String getList(@RequestParam("id") Long id,
  55. HttpServletRequest request) throws Exception {
  56. Material material = materialService.getMaterial(id);
  57. Map<String, Object> objectMap = new HashMap<>();
  58. if(material != null) {
  59. objectMap.put("info", material);
  60. return returnJson(objectMap, ErpInfo.OK.name, ErpInfo.OK.code);
  61. } else {
  62. return returnJson(objectMap, ErpInfo.ERROR.name, ErpInfo.ERROR.code);
  63. }
  64. }
  65. @GetMapping(value = "/list")
  66. @ApiOperation(value = "获取信息列表")
  67. public TableDataInfo getList(@RequestParam(value = Constants.SEARCH, required = false) String search,
  68. HttpServletRequest request)throws Exception {
  69. String categoryId = StringUtil.getInfo(search, "categoryId");
  70. String materialParam = StringUtil.getInfo(search, "materialParam");
  71. String standard = StringUtil.getInfo(search, "standard");
  72. String model = StringUtil.getInfo(search, "model");
  73. String color = StringUtil.getInfo(search, "color");
  74. String brand = StringUtil.getInfo(search, "brand");
  75. String mfrs = StringUtil.getInfo(search, "mfrs");
  76. String materialOther = StringUtil.getInfo(search, "materialOther");
  77. String weight = StringUtil.getInfo(search, "weight");
  78. String expiryNum = StringUtil.getInfo(search, "expiryNum");
  79. String enableSerialNumber = StringUtil.getInfo(search, "enableSerialNumber");
  80. String enableBatchNumber = StringUtil.getInfo(search, "enableBatchNumber");
  81. String position = StringUtil.getInfo(search, "position");
  82. String enabled = StringUtil.getInfo(search, "enabled");
  83. String remark = StringUtil.getInfo(search, "remark");
  84. String mpList = StringUtil.getInfo(search, "mpList");
  85. List<MaterialVo4Unit> list = materialService.select(materialParam, standard, model, color, brand, mfrs, materialOther, weight, expiryNum,
  86. enableSerialNumber, enableBatchNumber, position, enabled, remark, categoryId, mpList);
  87. return getDataTable(list);
  88. }
  89. @PostMapping(value = "/add")
  90. @ApiOperation(value = "新增")
  91. public String addResource(@RequestBody MaterialDto obj, HttpServletRequest request)throws Exception {
  92. Map<String, Object> objectMap = new HashMap<>();
  93. int insert = materialService.insertMaterial(obj, request);
  94. return returnStr(objectMap, insert);
  95. }
  96. @PutMapping(value = "/update")
  97. @ApiOperation(value = "修改")
  98. public String updateResource(@RequestBody MaterialDto obj, HttpServletRequest request)throws Exception {
  99. Map<String, Object> objectMap = new HashMap<>();
  100. int update = materialService.updateMaterial(obj, request);
  101. return returnStr(objectMap, update);
  102. }
  103. @DeleteMapping(value = "/delete")
  104. @ApiOperation(value = "删除")
  105. public String deleteResource(@RequestParam("id") Long id, HttpServletRequest request)throws Exception {
  106. Map<String, Object> objectMap = new HashMap<>();
  107. int delete = materialService.deleteMaterial(id, request);
  108. return returnStr(objectMap, delete);
  109. }
  110. @DeleteMapping(value = "/deleteBatch")
  111. @ApiOperation(value = "批量删除")
  112. public String batchDeleteResource(@RequestParam("ids") String ids, HttpServletRequest request)throws Exception {
  113. Map<String, Object> objectMap = new HashMap<>();
  114. int delete = materialService.batchDeleteMaterial(ids, request);
  115. return returnStr(objectMap, delete);
  116. }
  117. @GetMapping(value = "/checkIsNameExist")
  118. @ApiOperation(value = "检查名称是否存在")
  119. public String checkIsNameExist(@RequestParam Long id, @RequestParam(value ="name", required = false) String name,
  120. HttpServletRequest request)throws Exception {
  121. Map<String, Object> objectMap = new HashMap<>();
  122. int exist = materialService.checkIsNameExist(id, name);
  123. if(exist > 0) {
  124. objectMap.put("status", true);
  125. } else {
  126. objectMap.put("status", false);
  127. }
  128. return returnJson(objectMap, ErpInfo.OK.name, ErpInfo.OK.code);
  129. }
  130. /**
  131. * 检查商品是否存在
  132. * @param id
  133. * @param name
  134. * @param model
  135. * @param color
  136. * @param standard
  137. * @param mfrs
  138. * @param otherField1
  139. * @param otherField2
  140. * @param otherField3
  141. * @param unit
  142. * @param unitId
  143. * @param request
  144. * @return
  145. * @throws Exception
  146. */
  147. @GetMapping(value = "/checkIsExist")
  148. @ApiOperation(value = "检查商品是否存在")
  149. public String checkIsExist(@RequestParam("id") Long id, @RequestParam("name") String name,
  150. @RequestParam("model") String model, @RequestParam("color") String color,
  151. @RequestParam("standard") String standard, @RequestParam("mfrs") String mfrs,
  152. @RequestParam("otherField1") String otherField1, @RequestParam("otherField2") String otherField2,
  153. @RequestParam("otherField3") String otherField3, @RequestParam("unit") String unit,@RequestParam("unitId") Long unitId,
  154. HttpServletRequest request)throws Exception {
  155. Map<String, Object> objectMap = new HashMap<String, Object>();
  156. int exist = materialService.checkIsExist(id, name, StringUtil.toNull(model), StringUtil.toNull(color),
  157. StringUtil.toNull(standard), StringUtil.toNull(mfrs), StringUtil.toNull(otherField1),
  158. StringUtil.toNull(otherField2), StringUtil.toNull(otherField3), StringUtil.toNull(unit), unitId);
  159. if(exist > 0) {
  160. objectMap.put("status", true);
  161. } else {
  162. objectMap.put("status", false);
  163. }
  164. return returnJson(objectMap, ErpInfo.OK.name, ErpInfo.OK.code);
  165. }
  166. /**
  167. * 批量设置状态-启用或者禁用
  168. * @param jsonObject
  169. * @param request
  170. * @return
  171. * @throws Exception
  172. */
  173. @PostMapping(value = "/batchSetStatus")
  174. @ApiOperation(value = "批量设置状态-启用或者禁用")
  175. public String batchSetStatus(@RequestBody JSONObject jsonObject,
  176. HttpServletRequest request)throws Exception {
  177. Boolean status = jsonObject.getBoolean("status");
  178. String ids = jsonObject.getString("ids");
  179. Map<String, Object> objectMap = new HashMap<>();
  180. int res = materialService.batchSetStatus(status, ids);
  181. if(res > 0) {
  182. return returnJson(objectMap, ErpInfo.OK.name, ErpInfo.OK.code);
  183. } else {
  184. return returnJson(objectMap, ErpInfo.ERROR.name, ErpInfo.ERROR.code);
  185. }
  186. }
  187. /**
  188. * 根据id来查询商品名称
  189. * @param id
  190. * @param request
  191. * @return
  192. */
  193. @GetMapping(value = "/findById")
  194. @ApiOperation(value = "根据id来查询商品名称")
  195. public BaseResponseInfo findById(@RequestParam("id") Long id, HttpServletRequest request) throws Exception{
  196. BaseResponseInfo res = new BaseResponseInfo();
  197. try {
  198. List<MaterialVo4Unit> list = materialService.findById(id);
  199. res.code = 200;
  200. res.data = list;
  201. } catch(Exception e){
  202. logger.error(e.getMessage(), e);
  203. res.code = 500;
  204. res.data = "获取数据失败";
  205. }
  206. return res;
  207. }
  208. /**
  209. * 根据meId来查询商品名称
  210. * @param meId
  211. * @param request
  212. * @return
  213. */
  214. @GetMapping(value = "/findByIdWithBarCode")
  215. @ApiOperation(value = "根据meId来查询商品名称")
  216. public BaseResponseInfo findByIdWithBarCode(@RequestParam("meId") Long meId,
  217. @RequestParam("mpList") String mpList,
  218. HttpServletRequest request) throws Exception{
  219. BaseResponseInfo res = new BaseResponseInfo();
  220. try {
  221. String[] mpArr = mpList.split(",");
  222. MaterialVo4Unit mu = new MaterialVo4Unit();
  223. List<MaterialVo4Unit> list = materialService.findByIdWithBarCode(meId);
  224. if(list!=null && list.size()>0) {
  225. mu = list.get(0);
  226. mu.setMaterialOther(materialService.getMaterialOtherByParam(mpArr, mu));
  227. }
  228. res.code = 200;
  229. res.data = mu;
  230. } catch(Exception e){
  231. logger.error(e.getMessage(), e);
  232. res.code = 500;
  233. res.data = "获取数据失败";
  234. }
  235. return res;
  236. }
  237. /**
  238. * 根据关键词查找商品信息-条码、名称、规格、型号
  239. * @param q
  240. * @param request
  241. * @return
  242. */
  243. @GetMapping(value = "/getMaterialByParam")
  244. @ApiOperation(value = "根据关键词查找商品信息")
  245. public BaseResponseInfo getMaterialByParam(@RequestParam("q") String q,
  246. HttpServletRequest request) throws Exception{
  247. BaseResponseInfo res = new BaseResponseInfo();
  248. try {
  249. JSONArray arr = materialService.getMaterialByParam(q);
  250. res.code = 200;
  251. res.data = arr;
  252. } catch (Exception e) {
  253. logger.error(e.getMessage(), e);
  254. res.code = 500;
  255. res.data = "获取数据失败";
  256. }
  257. return res;
  258. }
  259. /**
  260. * 查找商品信息-下拉框
  261. * @param mpList
  262. * @param request
  263. * @return
  264. */
  265. @GetMapping(value = "/findBySelect")
  266. @ApiOperation(value = "查找商品信息")
  267. public JSONObject findBySelect(@RequestParam(value = "categoryId", required = false) Long categoryId,
  268. @RequestParam(value = "q", required = false) String q,
  269. @RequestParam(value = "standardOrModel", required = false) String standardOrModel,
  270. @RequestParam(value = "mpList", required = false) String mpList,
  271. @RequestParam(value = "depotId", required = false) Long depotId,
  272. @RequestParam(value = "color", required = false) String color,
  273. @RequestParam(value = "brand", required = false) String brand,
  274. @RequestParam(value = "mfrs", required = false) String mfrs,
  275. @RequestParam(value = "enableSerialNumber", required = false) String enableSerialNumber,
  276. @RequestParam(value = "enableBatchNumber", required = false) String enableBatchNumber,
  277. @RequestParam("page") Integer currentPage,
  278. @RequestParam("rows") Integer pageSize,
  279. HttpServletRequest request) throws Exception{
  280. JSONObject object = new JSONObject();
  281. try {
  282. String[] mpArr = new String[]{};
  283. if(StringUtil.isNotEmpty(mpList)){
  284. mpArr= mpList.split(",");
  285. }
  286. List<MaterialVo4Unit> dataList = materialService.findBySelectWithBarCode(categoryId, q, StringUtil.toNull(standardOrModel),
  287. StringUtil.toNull(color), StringUtil.toNull(brand), StringUtil.toNull(mfrs), enableSerialNumber, enableBatchNumber,
  288. (currentPage-1)*pageSize, pageSize,depotId);
  289. int total = materialService.findBySelectWithBarCodeCount(categoryId, q, StringUtil.toNull(standardOrModel),
  290. StringUtil.toNull(color), StringUtil.toNull(brand), StringUtil.toNull(mfrs), enableSerialNumber, enableBatchNumber,depotId);
  291. object.put("total", total);
  292. JSONArray dataArray = new JSONArray();
  293. //存放数据json数组
  294. if (null != dataList) {
  295. for (MaterialVo4Unit material : dataList) {
  296. JSONObject item = new JSONObject();
  297. item.put("id", material.getMeId()); //商品扩展表的id
  298. item.put("mid", material.getId()); //商品扩展表的id
  299. String ratioStr = ""; //比例
  300. Unit unit = new Unit();
  301. BigDecimal ratio = new BigDecimal("1");
  302. if (material.getUnitId() == null) {
  303. ratioStr = "";
  304. } else {
  305. unit = unitService.getUnit(material.getUnitId());
  306. //拼接副单位的比例
  307. String commodityUnit = material.getCommodityUnit();
  308. if(commodityUnit.equals(unit.getBasicUnit())) {
  309. ratioStr = "[基本]";
  310. ratio = new BigDecimal("1");
  311. }
  312. if(commodityUnit.equals(unit.getOtherUnit()) && unit.getRatio()!=null) {
  313. ratioStr = "[" + unit.getRatio().stripTrailingZeros().toPlainString() + unit.getBasicUnit() + "]";
  314. ratio = unit.getRatio();
  315. }
  316. if(commodityUnit.equals(unit.getOtherUnitTwo()) && unit.getRatioTwo()!=null) {
  317. ratioStr = "[" + unit.getRatioTwo().stripTrailingZeros().toPlainString() + unit.getBasicUnit() + "]";
  318. ratio = unit.getRatioTwo();
  319. }
  320. if(commodityUnit.equals(unit.getOtherUnitThree()) && unit.getRatioThree()!=null) {
  321. ratioStr = "[" + unit.getRatioThree().stripTrailingZeros().toPlainString() + unit.getBasicUnit() + "]";
  322. ratio = unit.getRatioThree();
  323. }
  324. }
  325. item.put("barCode", material.getBarCode());
  326. item.put("name", material.getName());
  327. item.put("mnemonic", material.getMnemonic());
  328. item.put("categoryName", material.getCategoryName());
  329. item.put("standard", material.getStandard());
  330. item.put("model", material.getModel());
  331. item.put("color", material.getColor());
  332. item.put("brand", material.getBrand());
  333. //item.put("mfrs", material.getMfrs());
  334. item.put("unit", material.getCommodityUnit() + ratioStr);
  335. item.put("sku", material.getSku());
  336. item.put("enableSerialNumber", material.getEnableSerialNumber());
  337. item.put("enableBatchNumber", material.getEnableBatchNumber());
  338. item.put("productionDate",material.getProductionDate());
  339. item.put("expiryNum",material.getExpiryNum());
  340. item.put("batchNumber",material.getBatchNumber());
  341. item.put("position",material.getPosition());
  342. item.put("supplierId",material.getSupplierId());
  343. item.put("supplierName",material.getSupplierName());
  344. item.put("depotId",material.getDepotId());
  345. item.put("depotName",material.getDepotName());
  346. item.put("unitId",material.getUnitId());
  347. item.put("inventory",materialService.getMaterialStockByMid(material.getId()).divide(ratio,2,BigDecimal.ROUND_HALF_UP));
  348. BigDecimal stock;
  349. if(StringUtil.isNotEmpty(material.getSku())){
  350. stock = depotItemService.getSkuStockByParam(depotId,material.getMeId(),null,null);
  351. } else {
  352. stock = depotItemService.getCurrentStockByParam(depotId, material.getId());
  353. if (material.getUnitId()!=null){
  354. String commodityUnit = material.getCommodityUnit();
  355. stock = unitService.parseStockByUnit(stock, unit, commodityUnit);
  356. }
  357. }
  358. item.put("stock", stock);
  359. item.put("expand", materialService.getMaterialOtherByParam(mpArr, material));
  360. item.put("imgName", material.getImgName());
  361. if(fileUploadType == 2) {
  362. item.put("imgSmall", "small");
  363. item.put("imgLarge", "large");
  364. } else {
  365. item.put("imgSmall", "");
  366. item.put("imgLarge", "");
  367. }
  368. dataArray.add(item);
  369. }
  370. }
  371. object.put("rows", dataArray);
  372. } catch (Exception e) {
  373. logger.error(e.getMessage(), e);
  374. }
  375. return object;
  376. }
  377. /**
  378. * 根据商品id查找商品信息
  379. * @param meId
  380. * @param request
  381. * @return
  382. * @throws Exception
  383. */
  384. @GetMapping(value = "/getMaterialByMeId")
  385. @ApiOperation(value = "根据商品id查找商品信息")
  386. public JSONObject getMaterialByMeId(@RequestParam(value = "meId", required = false) Long meId,
  387. @RequestParam("mpList") String mpList,
  388. HttpServletRequest request) throws Exception{
  389. JSONObject item = new JSONObject();
  390. try {
  391. String[] mpArr = mpList.split(",");
  392. List<MaterialVo4Unit> materialList = materialService.getMaterialByMeId(meId);
  393. if(materialList!=null && materialList.size()!=1) {
  394. return item;
  395. } else if(materialList.size() == 1) {
  396. MaterialVo4Unit material = materialList.get(0);
  397. item.put("Id", material.getMeId()); //商品扩展表的id
  398. String ratio; //比例
  399. if (material.getUnitId() == null || material.getUnitId().equals("")) {
  400. ratio = "";
  401. } else {
  402. ratio = material.getUnitName();
  403. ratio = ratio.substring(ratio.indexOf("("));
  404. }
  405. //名称/型号/扩展信息/包装
  406. String MaterialName = "";
  407. MaterialName = MaterialName + material.getmBarCode() + "_" + material.getName()
  408. + ((material.getStandard() == null || material.getStandard().equals("")) ? "" : "(" + material.getStandard() + ")");
  409. String expand = materialService.getMaterialOtherByParam(mpArr, material); //扩展信息
  410. MaterialName = MaterialName + expand + ((material.getUnit() == null || material.getUnit().equals("")) ? "" : "(" + material.getUnit() + ")") + ratio;
  411. item.put("MaterialName", MaterialName);
  412. item.put("name", material.getName());
  413. item.put("expand", expand);
  414. item.put("model", material.getModel());
  415. item.put("standard", material.getStandard());
  416. item.put("unit", material.getUnit() + ratio);
  417. }
  418. } catch (Exception e) {
  419. logger.error(e.getMessage(), e);
  420. }
  421. return item;
  422. }
  423. /**
  424. * 生成excel表格
  425. * @param categoryId
  426. * @param materialParam
  427. * @param color
  428. * @param weight
  429. * @param expiryNum
  430. * @param enabled
  431. * @param enableSerialNumber
  432. * @param enableBatchNumber
  433. * @param remark
  434. * @param mpList
  435. * @param request
  436. * @param response
  437. */
  438. @GetMapping(value = "/exportExcel")
  439. @ApiOperation(value = "生成excel表格")
  440. public void exportExcel(@RequestParam(value = "categoryId", required = false) String categoryId,
  441. @RequestParam(value = "materialParam", required = false) String materialParam,
  442. @RequestParam(value = "color", required = false) String color,
  443. @RequestParam(value = "materialOther", required = false) String materialOther,
  444. @RequestParam(value = "weight", required = false) String weight,
  445. @RequestParam(value = "expiryNum", required = false) String expiryNum,
  446. @RequestParam(value = "enabled", required = false) String enabled,
  447. @RequestParam(value = "enableSerialNumber", required = false) String enableSerialNumber,
  448. @RequestParam(value = "enableBatchNumber", required = false) String enableBatchNumber,
  449. @RequestParam(value = "remark", required = false) String remark,
  450. @RequestParam(value = "mpList", required = false) String mpList,
  451. HttpServletRequest request, HttpServletResponse response) {
  452. try {
  453. materialService.exportExcel(StringUtil.toNull(categoryId), StringUtil.toNull(materialParam), StringUtil.toNull(color),
  454. StringUtil.toNull(materialOther), StringUtil.toNull(weight),
  455. StringUtil.toNull(expiryNum), StringUtil.toNull(enabled), StringUtil.toNull(enableSerialNumber),
  456. StringUtil.toNull(enableBatchNumber), StringUtil.toNull(remark), response);
  457. } catch (Exception e) {
  458. logger.error(e.getMessage(), e);
  459. }
  460. }
  461. /**
  462. * excel表格导入产品(含初始库存)
  463. * @param file
  464. * @param request
  465. * @param response
  466. * @return
  467. */
  468. @PostMapping(value = "/importExcel")
  469. @ApiOperation(value = "excel表格导入产品")
  470. public BaseResponseInfo importExcel(MultipartFile file,
  471. HttpServletRequest request, HttpServletResponse response) throws Exception{
  472. BaseResponseInfo res = new BaseResponseInfo();
  473. try {
  474. res = materialService.importExcelTwo(file, request);
  475. } catch (Exception e) {
  476. logger.error(e.getMessage(), e);
  477. }
  478. return res;
  479. }
  480. /**
  481. * 获取商品序列号
  482. * @param q
  483. * @param currentPage
  484. * @param pageSize
  485. * @param request
  486. * @param response
  487. * @return
  488. * @throws Exception
  489. */
  490. @GetMapping(value = "/getMaterialEnableSerialNumberList")
  491. @ApiOperation(value = "获取商品序列号")
  492. public JSONObject getMaterialEnableSerialNumberList(
  493. @RequestParam(value = "q", required = false) String q,
  494. @RequestParam("page") Integer currentPage,
  495. @RequestParam("rows") Integer pageSize,
  496. HttpServletRequest request,
  497. HttpServletResponse response)throws Exception {
  498. JSONObject object= new JSONObject();
  499. try {
  500. List<MaterialVo4Unit> list = materialService.getMaterialEnableSerialNumberList(q, (currentPage-1)*pageSize, pageSize);
  501. Long count = materialService.getMaterialEnableSerialNumberCount(q);
  502. object.put("rows", list);
  503. object.put("total", count);
  504. } catch (Exception e) {
  505. logger.error(e.getMessage(), e);
  506. }
  507. return object;
  508. }
  509. /**
  510. * 获取最大条码
  511. * @return
  512. * @throws Exception
  513. */
  514. @GetMapping(value = "/getMaxBarCode")
  515. @ApiOperation(value = "获取最大条码")
  516. public BaseResponseInfo getMaxBarCode() throws Exception {
  517. BaseResponseInfo res = new BaseResponseInfo();
  518. Map<String, Object> map = new HashMap<String, Object>();
  519. String barCode = materialService.getMaxBarCode();
  520. map.put("barCode", barCode);
  521. res.code = 200;
  522. res.data = map;
  523. return res;
  524. }
  525. /**
  526. * 商品名称模糊匹配
  527. * @return
  528. * @throws Exception
  529. */
  530. @GetMapping(value = "/getMaterialNameList")
  531. @ApiOperation(value = "商品名称模糊匹配")
  532. public JSONArray getMaterialNameList() throws Exception {
  533. JSONArray arr = new JSONArray();
  534. try {
  535. List<String> list = materialService.getMaterialNameList();
  536. for (String s : list) {
  537. JSONObject item = new JSONObject();
  538. item.put("value", s);
  539. item.put("text", s);
  540. arr.add(item);
  541. }
  542. } catch (Exception e) {
  543. logger.error(e.getMessage(), e);
  544. }
  545. return arr;
  546. }
  547. /**
  548. * 根据条码查询商品信息
  549. * @return
  550. * @throws Exception
  551. */
  552. @GetMapping(value = "/getMaterialByBarCode")
  553. @ApiOperation(value = "根据条码查询商品信息")
  554. public BaseResponseInfo getMaterialByBarCode(@RequestParam("barCode") String barCode,
  555. @RequestParam(value = "organId", required = false) Long organId,
  556. @RequestParam(value = "depotId", required = false) Long depotId,
  557. @RequestParam("mpList") String mpList,
  558. @RequestParam(required = false, value = "prefixNo") String prefixNo,
  559. HttpServletRequest request) throws Exception {
  560. BaseResponseInfo res = new BaseResponseInfo();
  561. try {
  562. Long userId = userService.getUserId(request);
  563. String priceLimit = userService.getRoleTypeByUserId(userId).getPriceLimit();
  564. String[] mpArr = mpList.split(",");
  565. //支持序列号查询,先根据序列号查询条码,如果查不到就直接查条码
  566. // MaterialExtend materialExtend = materialService.getMaterialExtendBySerialNumber(barCode);
  567. // if(materialExtend!=null && StringUtil.isNotEmpty(materialExtend.getBarCode())) {
  568. // barCode = materialExtend.getBarCode();
  569. // }
  570. List<MaterialVo4Unit> list = materialService.getMaterialByBarCode(barCode);
  571. if(list!=null && list.size()>0) {
  572. for(MaterialVo4Unit mvo: list) {
  573. mvo.setMaterialOther(materialService.getMaterialOtherByParam(mpArr, mvo));
  574. if ("LSCK".equals(prefixNo) || "LSTH".equals(prefixNo)) {
  575. //零售价
  576. mvo.setBillPrice(mvo.getCommodityDecimal());
  577. } else if ("CGDD".equals(prefixNo) || "CGRK".equals(prefixNo) || "CGTH".equals(prefixNo)) {
  578. //采购价
  579. mvo.setBillPrice(mvo.getPurchaseDecimal());
  580. } else if("QTRK".equals(prefixNo) || "DBCK".equals(prefixNo) || "ZZD".equals(prefixNo) || "CXD".equals(prefixNo)
  581. || "PDLR".equals(prefixNo) || "PDFP".equals(prefixNo)) {
  582. //采购价-给录入界面按权限屏蔽
  583. mvo.setBillPrice(roleService.parseBillPriceByLimit(mvo.getPurchaseDecimal(), "buy", priceLimit, request));
  584. } if ("XSDD".equals(prefixNo) || "XSCK".equals(prefixNo) || "XSTH".equals(prefixNo) || "QTCK".equals(prefixNo)) {
  585. //销售价
  586. if(organId == null) {
  587. mvo.setBillPrice(mvo.getWholesaleDecimal());
  588. } else {
  589. //查询最后一单的销售价,实现不同的客户不同的销售价
  590. BigDecimal lastUnitPrice = depotItemService.getLastUnitPriceByParam(organId, mvo.getMeId(), prefixNo);
  591. mvo.setBillPrice(lastUnitPrice!=null? lastUnitPrice : mvo.getWholesaleDecimal());
  592. }
  593. //销售价-给录入界面按权限屏蔽价格
  594. if("QTCK".equals(prefixNo)) {
  595. mvo.setBillPrice(roleService.parseBillPriceByLimit(mvo.getWholesaleDecimal(), "sale", priceLimit, request));
  596. }
  597. }
  598. //仓库id
  599. if (depotId == null) {
  600. JSONArray depotArr = depotService.findDepotByCurrentUser();
  601. for (Object obj : depotArr) {
  602. JSONObject depotObj = JSONObject.parseObject(obj.toString());
  603. if (depotObj.get("isDefault") != null) {
  604. Boolean isDefault = depotObj.getBoolean("isDefault");
  605. if (isDefault) {
  606. Long id = depotObj.getLong("id");
  607. if (!"CGDD".equals(prefixNo) && !"XSDD".equals(prefixNo)) {
  608. //除订单之外的单据才有仓库
  609. mvo.setDepotId(id);
  610. }
  611. getStockByMaterialInfo(mvo);
  612. }
  613. }
  614. }
  615. } else {
  616. mvo.setDepotId(depotId);
  617. getStockByMaterialInfo(mvo);
  618. }
  619. mvo.setInventory(mvo.getStock());
  620. }
  621. }
  622. res.code = 200;
  623. res.data = list;
  624. } catch(Exception e){
  625. logger.error(e.getMessage(), e);
  626. res.code = 500;
  627. res.data = "获取数据失败";
  628. }
  629. return res;
  630. }
  631. /**
  632. * 根据商品信息获取库存,进行赋值
  633. * @param mvo
  634. * @throws Exception
  635. */
  636. private void getStockByMaterialInfo(MaterialVo4Unit mvo) throws Exception {
  637. BigDecimal stock;
  638. if (StringUtil.isNotEmpty(mvo.getSku())) {
  639. stock = depotItemService.getSkuStockByParam(mvo.getDepotId(), mvo.getMeId(), null, null);
  640. } else {
  641. stock = depotItemService.getCurrentStockByParam(mvo.getDepotId(), mvo.getId());
  642. if (mvo.getUnitId() != null) {
  643. Unit unit = unitService.getUnit(mvo.getUnitId());
  644. String commodityUnit = mvo.getCommodityUnit();
  645. stock = unitService.parseStockByUnit(stock, unit, commodityUnit);
  646. }
  647. }
  648. mvo.setStock(stock);
  649. }
  650. /**
  651. * 商品库存查询
  652. * @param currentPage
  653. * @param pageSize
  654. * @param depotIds
  655. * @param categoryId
  656. * @param materialParam
  657. * @param zeroStock
  658. * @param column
  659. * @param order
  660. * @param request
  661. * @return
  662. * @throws Exception
  663. */
  664. @GetMapping(value = "/getListWithStock")
  665. @ApiOperation(value = "商品库存查询")
  666. public BaseResponseInfo getListWithStock(@RequestParam("currentPage") Integer currentPage,
  667. @RequestParam("pageSize") Integer pageSize,
  668. @RequestParam(value = "depotIds", required = false) String depotIds,
  669. @RequestParam(value = "categoryId", required = false) Long categoryId,
  670. @RequestParam(value = "position", required = false) String position,
  671. @RequestParam("materialParam") String materialParam,
  672. @RequestParam("zeroStock") Integer zeroStock,
  673. @RequestParam(value = "column", required = false, defaultValue = "createTime") String column,
  674. @RequestParam(value = "order", required = false, defaultValue = "desc") String order,
  675. HttpServletRequest request)throws Exception {
  676. BaseResponseInfo res = new BaseResponseInfo();
  677. Map<String, Object> map = new HashMap<>();
  678. try {
  679. List<Long> idList = new ArrayList<>();
  680. List<Long> depotList = new ArrayList<>();
  681. if(categoryId != null){
  682. idList = materialService.getListByParentId(categoryId);
  683. }
  684. if(StringUtil.isNotEmpty(depotIds)) {
  685. depotList = StringUtil.strToLongList(depotIds);
  686. } else {
  687. //未选择仓库时默认为当前用户有权限的仓库
  688. JSONArray depotArr = depotService.findDepotByCurrentUser();
  689. for(Object obj: depotArr) {
  690. JSONObject object = JSONObject.parseObject(obj.toString());
  691. depotList.add(object.getLong("id"));
  692. }
  693. }
  694. Boolean moveAvgPriceFlag = systemConfigService.getMoveAvgPriceFlag();
  695. List<MaterialVo4Unit> dataList = materialService.getListWithStock(depotList, idList, StringUtil.toNull(position), StringUtil.toNull(materialParam),
  696. moveAvgPriceFlag, zeroStock, StringUtil.safeSqlParse(column), StringUtil.safeSqlParse(order), (currentPage-1)*pageSize, pageSize);
  697. int total = materialService.getListWithStockCount(depotList, idList, StringUtil.toNull(position), StringUtil.toNull(materialParam), zeroStock);
  698. MaterialVo4Unit materialVo4Unit= materialService.getTotalStockAndPrice(depotList, idList, StringUtil.toNull(position), StringUtil.toNull(materialParam));
  699. map.put("total", total);
  700. map.put("currentStock", materialVo4Unit.getCurrentStock()!=null?materialVo4Unit.getCurrentStock():BigDecimal.ZERO);
  701. if(moveAvgPriceFlag) {
  702. map.put("currentStockPrice", materialVo4Unit.getCurrentStockMovePrice()!=null?materialVo4Unit.getCurrentStockMovePrice():BigDecimal.ZERO);
  703. } else {
  704. map.put("currentStockPrice", materialVo4Unit.getCurrentStockPrice()!=null?materialVo4Unit.getCurrentStockPrice():BigDecimal.ZERO);
  705. }
  706. map.put("currentWeight", materialVo4Unit.getCurrentWeight()!=null?materialVo4Unit.getCurrentWeight():BigDecimal.ZERO);
  707. map.put("rows", dataList);
  708. res.code = 200;
  709. res.data = map;
  710. } catch(Exception e){
  711. logger.error(e.getMessage(), e);
  712. res.code = 500;
  713. res.data = "获取数据失败";
  714. }
  715. return res;
  716. }
  717. /**
  718. * 批量设置商品当前的实时库存(按每个仓库)
  719. * @param jsonObject
  720. * @param request
  721. * @return
  722. * @throws Exception
  723. */
  724. @PostMapping(value = "/batchSetMaterialCurrentStock")
  725. @ApiOperation(value = "批量设置商品当前的实时库存(按每个仓库)")
  726. public String batchSetMaterialCurrentStock(@RequestBody JSONObject jsonObject,
  727. HttpServletRequest request)throws Exception {
  728. String ids = jsonObject.getString("ids");
  729. Map<String, Object> objectMap = new HashMap<>();
  730. int res = materialService.batchSetMaterialCurrentStock(ids);
  731. if(res > 0) {
  732. return returnJson(objectMap, ErpInfo.OK.name, ErpInfo.OK.code);
  733. } else {
  734. return returnJson(objectMap, ErpInfo.ERROR.name, ErpInfo.ERROR.code);
  735. }
  736. }
  737. /**
  738. * 批量设置商品当前的成本价
  739. * @param jsonObject
  740. * @param request
  741. * @return
  742. * @throws Exception
  743. */
  744. @PostMapping(value = "/batchSetMaterialCurrentUnitPrice")
  745. @ApiOperation(value = "批量设置商品当前的成本价")
  746. public String batchSetMaterialCurrentUnitPrice(@RequestBody JSONObject jsonObject,
  747. HttpServletRequest request)throws Exception {
  748. String ids = jsonObject.getString("ids");
  749. Map<String, Object> objectMap = new HashMap<>();
  750. int res = materialService.batchSetMaterialCurrentUnitPrice(ids);
  751. if(res > 0) {
  752. return returnJson(objectMap, ErpInfo.OK.name, ErpInfo.OK.code);
  753. } else {
  754. return returnJson(objectMap, ErpInfo.ERROR.name, ErpInfo.ERROR.code);
  755. }
  756. }
  757. /**
  758. * 批量更新商品信息
  759. * @param jsonObject
  760. * @param request
  761. * @return
  762. * @throws Exception
  763. */
  764. @PostMapping(value = "/batchUpdate")
  765. @ApiOperation(value = "批量更新商品信息")
  766. public String batchUpdate(@RequestBody JSONObject jsonObject,
  767. HttpServletRequest request)throws Exception {
  768. Map<String, Object> objectMap = new HashMap<>();
  769. int res = materialService.batchUpdate(jsonObject);
  770. if(res > 0) {
  771. return returnJson(objectMap, ErpInfo.OK.name, ErpInfo.OK.code);
  772. } else {
  773. return returnJson(objectMap, ErpInfo.ERROR.name, ErpInfo.ERROR.code);
  774. }
  775. }
  776. /**
  777. * 转换名称为拼音
  778. * @param jsonObject
  779. */
  780. @PostMapping(value = "/changeNameToPinYin")
  781. @ApiOperation(value = "转换名称为拼音")
  782. public BaseResponseInfo changeNameToPinYin(@RequestBody JSONObject jsonObject)throws Exception {
  783. BaseResponseInfo res = new BaseResponseInfo();
  784. try {
  785. String name = jsonObject.getString("name");
  786. res.code = 200;
  787. res.data = PinYinUtil.getFirstLettersLo(name);
  788. } catch(Exception e){
  789. logger.error(e.getMessage(), e);
  790. res.code = 500;
  791. res.data = "获取数据失败";
  792. }
  793. return res;
  794. }
  795. @GetMapping(value = "/getMaterialByBatchNumber")
  796. @ApiOperation(value = "根据批次号查询商品信息")
  797. public TableDataInfo getMaterialByBatchNumber(@RequestParam("batchNumber") String batchNumber){
  798. String[] batchNumbers = batchNumber.split(",");
  799. startPage();
  800. List<TaskStocktakingItemVO> list = materialBatchService.getMaterialByBatchNumber(batchNumbers);
  801. return getDataTable(list);
  802. }
  803. @GetMapping(value = "/getMaterialById")
  804. @ApiOperation(value = "根据商品id查询商品及子表信息")
  805. public BaseResponseInfo getMaterialById(@RequestParam("mid") Long materialId,
  806. HttpServletRequest request)throws Exception {
  807. BaseResponseInfo res = new BaseResponseInfo();
  808. res.code = 200;
  809. res.data = materialService.getMaterialById(materialId);
  810. return res;
  811. }
  812. @GetMapping(value = "/getMaterialWarn")
  813. @ApiOperation(value = "获取商品提醒")
  814. public BaseResponseInfo getMaterialWarn()throws Exception {
  815. BaseResponseInfo res = new BaseResponseInfo();
  816. res.code = 200;
  817. res.data = materialService.getMaterialWarn();
  818. return res;
  819. }
  820. @GetMapping(value = "/findBatchNumbersBySelect")
  821. @ApiOperation(value = "商品选择全选获取商品批次号")
  822. public BaseResponseInfo findBatchNumberSBySelect(@RequestParam(value = "categoryId", required = false) Long categoryId,
  823. @RequestParam(value = "q", required = false) String q,
  824. @RequestParam(value = "standardOrModel", required = false) String standardOrModel,
  825. @RequestParam(value = "mpList", required = false) String mpList,
  826. @RequestParam(value = "depotId", required = false) Long depotId,
  827. @RequestParam(value = "color", required = false) String color,
  828. @RequestParam(value = "brand", required = false) String brand,
  829. @RequestParam(value = "mfrs", required = false) String mfrs,
  830. @RequestParam(value = "enableSerialNumber", required = false) String enableSerialNumber,
  831. @RequestParam(value = "enableBatchNumber", required = false) String enableBatchNumber,
  832. HttpServletRequest request){
  833. BaseResponseInfo res = new BaseResponseInfo();
  834. try {
  835. List<MaterialVo4Unit> dataList = materialBatchService.findBySelectWithBarCode(categoryId, q, StringUtil.toNull(standardOrModel),
  836. StringUtil.toNull(color), StringUtil.toNull(brand), StringUtil.toNull(mfrs), enableSerialNumber, enableBatchNumber,
  837. null, null,depotId);
  838. StringBuffer str = new StringBuffer();
  839. //存放数据json数组
  840. if (null != dataList) {
  841. for (MaterialVo4Unit material : dataList) {
  842. str.append("," + material.getBatchNumber());
  843. }
  844. }
  845. res.code = 200;
  846. res.data = str.deleteCharAt(0);
  847. } catch (Exception e) {
  848. logger.error(e.getMessage(), e);
  849. res.code = 500;
  850. }
  851. return res;
  852. }
  853. @GetMapping(value = "/getPositionByDidAndMid")
  854. @ApiOperation(value = "获取商品仓库库位")
  855. public AjaxResult getPositionByDidAndMid(@RequestParam(value = "did") Long did,
  856. @RequestParam(value = "mid") Long mid){
  857. return AjaxResult.success(materialService.getPositionByDidAndMid(did,mid));
  858. }
  859. }