DepotItemController.java 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084
  1. package com.jsh.erp.controller;
  2. import com.alibaba.fastjson.JSONArray;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.jsh.erp.constants.BusinessConstants;
  5. import com.jsh.erp.constants.ExceptionConstants;
  6. import com.jsh.erp.datasource.entities.*;
  7. import com.jsh.erp.datasource.vo.DepotItemStockWarningCount;
  8. import com.jsh.erp.datasource.vo.DepotItemVoBatchNumberList;
  9. import com.jsh.erp.datasource.vo.InOutPriceVo;
  10. import com.jsh.erp.exception.BusinessRunTimeException;
  11. import com.jsh.erp.service.*;
  12. import com.jsh.erp.utils.*;
  13. import io.swagger.annotations.Api;
  14. import io.swagger.annotations.ApiOperation;
  15. import jxl.Sheet;
  16. import jxl.Workbook;
  17. import org.slf4j.Logger;
  18. import org.slf4j.LoggerFactory;
  19. import org.springframework.beans.factory.annotation.Value;
  20. import org.springframework.web.bind.annotation.*;
  21. import org.springframework.web.multipart.MultipartFile;
  22. import javax.annotation.Resource;
  23. import javax.servlet.http.HttpServletRequest;
  24. import javax.servlet.http.HttpServletResponse;
  25. import java.math.BigDecimal;
  26. import java.util.ArrayList;
  27. import java.util.HashMap;
  28. import java.util.List;
  29. import java.util.Map;
  30. import static com.jsh.erp.utils.ResponseJsonUtil.returnJson;
  31. /**
  32. * @author ji-sheng-hua 富贵ERP
  33. */
  34. @RestController
  35. @RequestMapping(value = "/depotItem")
  36. @Api(tags = {"单据明细"})
  37. public class DepotItemController {
  38. private Logger logger = LoggerFactory.getLogger(DepotItemController.class);
  39. @Resource
  40. private DepotHeadService depotHeadService;
  41. @Resource
  42. private DepotItemService depotItemService;
  43. @Resource
  44. private MaterialService materialService;
  45. @Resource
  46. private UnitService unitService;
  47. @Resource
  48. private DepotService depotService;
  49. @Resource
  50. private RoleService roleService;
  51. @Resource
  52. private UserService userService;
  53. @Resource
  54. private SystemConfigService systemConfigService;
  55. @Value(value="${file.uploadType}")
  56. private Long fileUploadType;
  57. /**
  58. * 根据仓库和商品查询单据列表
  59. * @param mId
  60. * @param request
  61. * @return
  62. */
  63. @GetMapping(value = "/findDetailByDepotIdsAndMaterialId")
  64. @ApiOperation(value = "根据仓库和商品查询单据列表")
  65. public String findDetailByDepotIdsAndMaterialId(
  66. @RequestParam(value = Constants.PAGE_SIZE, required = false) Integer pageSize,
  67. @RequestParam(value = Constants.CURRENT_PAGE, required = false) Integer currentPage,
  68. @RequestParam(value = "depotIds",required = false) String depotIds,
  69. @RequestParam(value = "sku",required = false) String sku,
  70. @RequestParam(value = "batchNumber",required = false) String batchNumber,
  71. @RequestParam(value = "number",required = false) String number,
  72. @RequestParam(value = "beginTime",required = false) String beginTime,
  73. @RequestParam(value = "endTime",required = false) String endTime,
  74. @RequestParam("materialId") Long mId,
  75. HttpServletRequest request)throws Exception {
  76. Map<String, Object> objectMap = new HashMap<>();
  77. if(StringUtil.isNotEmpty(beginTime)) {
  78. beginTime = beginTime + BusinessConstants.DAY_FIRST_TIME;
  79. }
  80. if(StringUtil.isNotEmpty(endTime)) {
  81. endTime = endTime + BusinessConstants.DAY_LAST_TIME;
  82. }
  83. Boolean forceFlag = systemConfigService.getForceApprovalFlag();
  84. Boolean inOutManageFlag = systemConfigService.getInOutManageFlag();
  85. List<DepotItemVo4DetailByTypeAndMId> list = depotItemService.findDetailByDepotIdsAndMaterialIdList(depotIds, forceFlag, inOutManageFlag, sku,
  86. batchNumber, StringUtil.toNull(number), beginTime, endTime, mId, (currentPage-1)*pageSize, pageSize);
  87. JSONArray dataArray = new JSONArray();
  88. if (list != null) {
  89. for (DepotItemVo4DetailByTypeAndMId d: list) {
  90. JSONObject item = new JSONObject();
  91. item.put("number", d.getNumber()); //编号
  92. item.put("barCode", d.getBarCode()); //条码
  93. item.put("materialName", d.getMaterialName()); //名称
  94. String type = d.getType();
  95. String subType = d.getSubType();
  96. if(("其它").equals(type)) {
  97. item.put("type", subType); //进出类型
  98. } else {
  99. item.put("type", subType + type); //进出类型
  100. }
  101. item.put("depotName", d.getDepotName()); //仓库名称
  102. item.put("basicNumber", d.getBnum()); //数量
  103. item.put("unitPrice", d.getUnitPrice()); //单价
  104. item.put("allPrice", d.getAllPrice()); //金额
  105. item.put("operTime", Tools.getCenternTime(d.getOtime())); //时间
  106. dataArray.add(item);
  107. }
  108. }
  109. if (list == null) {
  110. objectMap.put("rows", new ArrayList<Object>());
  111. objectMap.put("total", BusinessConstants.DEFAULT_LIST_NULL_NUMBER);
  112. return returnJson(objectMap, "查找不到数据", ErpInfo.OK.code);
  113. }
  114. objectMap.put("rows", dataArray);
  115. objectMap.put("total", depotItemService.findDetailByDepotIdsAndMaterialIdCount(depotIds, forceFlag, inOutManageFlag, sku,
  116. batchNumber, StringUtil.toNull(number), beginTime, endTime, mId));
  117. return returnJson(objectMap, ErpInfo.OK.name, ErpInfo.OK.code);
  118. }
  119. /**
  120. * 根据商品条码和仓库id查询库存数量
  121. * @param depotId
  122. * @param barCode
  123. * @param request
  124. * @return
  125. * @throws Exception
  126. */
  127. @GetMapping(value = "/findStockByDepotAndBarCode")
  128. @ApiOperation(value = "根据商品条码和仓库id查询库存数量")
  129. public BaseResponseInfo findStockByDepotAndBarCode(
  130. @RequestParam(value = "depotId",required = false) Long depotId,
  131. @RequestParam("barCode") String barCode,
  132. HttpServletRequest request) throws Exception{
  133. BaseResponseInfo res = new BaseResponseInfo();
  134. Map<String, Object> map = new HashMap<String, Object>();
  135. try {
  136. BigDecimal stock = BigDecimal.ZERO;
  137. List<MaterialVo4Unit> list = materialService.getMaterialByBatchNumber(barCode);
  138. if(list!=null && list.size()>0) {
  139. MaterialVo4Unit materialVo4Unit = list.get(0);
  140. if(StringUtil.isNotEmpty(materialVo4Unit.getSku())){
  141. stock = depotItemService.getSkuStockByParam(depotId,materialVo4Unit.getMeId(),null,null);
  142. } else {
  143. stock = depotItemService.getCurrentStockByParam(depotId, materialVo4Unit.getId());
  144. if(materialVo4Unit.getUnitId()!=null) {
  145. Unit unit = unitService.getUnit(materialVo4Unit.getUnitId());
  146. String commodityUnit = materialVo4Unit.getCommodityUnit();
  147. stock = unitService.parseStockByUnit(stock, unit, commodityUnit);
  148. }
  149. }
  150. }
  151. map.put("stock", stock);
  152. res.code = 200;
  153. res.data = map;
  154. } catch (Exception e) {
  155. logger.error(e.getMessage(), e);
  156. res.code = 500;
  157. res.data = "获取数据失败";
  158. }
  159. return res;
  160. }
  161. /**
  162. * 单据明细列表
  163. * @param headerId
  164. * @param mpList
  165. * @param request
  166. * @return
  167. * @throws Exception
  168. */
  169. @GetMapping(value = "/getDetailList")
  170. @ApiOperation(value = "单据明细列表")
  171. public BaseResponseInfo getDetailList(@RequestParam("headerId") Long headerId,
  172. @RequestParam("mpList") String mpList,
  173. @RequestParam(value = "linkType", required = false) String linkType,
  174. @RequestParam(value = "isReadOnly", required = false) String isReadOnly,
  175. HttpServletRequest request)throws Exception {
  176. BaseResponseInfo res = new BaseResponseInfo();
  177. try {
  178. Long userId = userService.getUserId(request);
  179. String priceLimit = userService.getRoleTypeByUserId(userId).getPriceLimit();
  180. List<DepotItemVo4WithInfoEx> dataList = new ArrayList<>();
  181. String billCategory = depotHeadService.getBillCategory(depotHeadService.getDepotHead(headerId).getSubType());
  182. if(headerId != 0) {
  183. dataList = depotItemService.getDetailList(headerId);
  184. }
  185. String[] mpArr = mpList.split(",");
  186. JSONObject outer = new JSONObject();
  187. outer.put("total", dataList.size());
  188. //存放数据json数组
  189. JSONArray dataArray = new JSONArray();
  190. if (null != dataList) {
  191. BigDecimal totalOperNumber = BigDecimal.ZERO;
  192. BigDecimal totalAllPrice = BigDecimal.ZERO;
  193. BigDecimal totalTaxMoney = BigDecimal.ZERO;
  194. BigDecimal totalTaxLastMoney = BigDecimal.ZERO;
  195. BigDecimal totalWeight = BigDecimal.ZERO;
  196. for (DepotItemVo4WithInfoEx diEx : dataList) {
  197. JSONObject item = new JSONObject();
  198. item.put("id", diEx.getId());
  199. item.put("materialExtendId", diEx.getMaterialExtendId() == null ? "" : diEx.getMaterialExtendId());
  200. item.put("barCode", diEx.getBarCode());
  201. item.put("name", diEx.getMName());
  202. item.put("standard", diEx.getMStandard());
  203. item.put("model", diEx.getMModel());
  204. item.put("color", diEx.getMColor());
  205. item.put("brand", diEx.getBrand());
  206. item.put("mfrs", diEx.getMMfrs());
  207. item.put("materialOther", depotItemService.getOtherInfo(mpArr, diEx));
  208. BigDecimal stock;
  209. Unit unitInfo = materialService.findUnit(diEx.getMaterialId()); //查询多单位信息
  210. String materialUnit = diEx.getMaterialUnit();
  211. if(StringUtil.isNotEmpty(diEx.getSku())){
  212. stock = depotItemService.getSkuStockByParam(diEx.getDepotId(),diEx.getMaterialExtendId(),null,null);
  213. } else {
  214. stock = depotItemService.getCurrentStockByParam(diEx.getDepotId(),diEx.getMaterialId());
  215. if (StringUtil.isNotEmpty(unitInfo.getName())) {
  216. stock = unitService.parseStockByUnit(stock, unitInfo, materialUnit);
  217. }
  218. }
  219. item.put("stock", stock);
  220. item.put("unit", diEx.getMaterialUnit());
  221. item.put("snList", diEx.getSnList());
  222. item.put("batchNumber", diEx.getBatchNumber());
  223. item.put("expirationDate", Tools.parseDateToStr(diEx.getExpirationDate()));
  224. item.put("sku", diEx.getSku());
  225. item.put("enableSerialNumber", diEx.getEnableSerialNumber());
  226. item.put("enableBatchNumber", diEx.getEnableBatchNumber());
  227. item.put("operNumber", diEx.getOperNumber());
  228. item.put("basicNumber", diEx.getBasicNumber());
  229. item.put("preNumber", diEx.getOperNumber()); //原数量
  230. item.put("finishNumber", depotItemService.getFinishNumber(diEx.getMaterialExtendId(), diEx.getId(), diEx.getHeaderId(), unitInfo, materialUnit, linkType)); //已入库|已出库
  231. item.put("purchaseDecimal", roleService.parseBillPriceByLimit(diEx.getPurchaseDecimal(), billCategory, priceLimit, request)); //采购价
  232. if("basic".equals(linkType) || "1".equals(isReadOnly)) {
  233. //正常情况显示金额,而以销定购的情况不能显示金额
  234. item.put("unitPrice", roleService.parseBillPriceByLimit(diEx.getUnitPrice(), billCategory, priceLimit, request));
  235. item.put("taxUnitPrice", roleService.parseBillPriceByLimit(diEx.getTaxUnitPrice(), billCategory, priceLimit, request));
  236. item.put("allPrice", roleService.parseBillPriceByLimit(diEx.getAllPrice(), billCategory, priceLimit, request));
  237. item.put("taxRate", roleService.parseBillPriceByLimit(diEx.getTaxRate(), billCategory, priceLimit, request));
  238. item.put("taxMoney", roleService.parseBillPriceByLimit(diEx.getTaxMoney(), billCategory, priceLimit, request));
  239. item.put("taxLastMoney", roleService.parseBillPriceByLimit(diEx.getTaxLastMoney(), billCategory, priceLimit, request));
  240. }
  241. BigDecimal allWeight = diEx.getBasicNumber()==null||diEx.getWeight()==null?BigDecimal.ZERO:diEx.getBasicNumber().multiply(diEx.getWeight());
  242. item.put("weight", allWeight);
  243. item.put("position", diEx.getPosition());
  244. item.put("remark", diEx.getRemark());
  245. item.put("imgName", diEx.getImgName());
  246. if(fileUploadType == 2) {
  247. item.put("imgSmall", "small");
  248. item.put("imgLarge", "large");
  249. } else {
  250. item.put("imgSmall", "");
  251. item.put("imgLarge", "");
  252. }
  253. item.put("linkId", diEx.getLinkId());
  254. item.put("depotId", diEx.getDepotId() == null ? "" : diEx.getDepotId());
  255. item.put("depotName", diEx.getDepotId() == null ? "" : diEx.getDepotName());
  256. item.put("anotherDepotId", diEx.getAnotherDepotId() == null ? "" : diEx.getAnotherDepotId());
  257. item.put("anotherDepotName", diEx.getAnotherDepotId() == null ? "" : diEx.getAnotherDepotName());
  258. item.put("mType", diEx.getMaterialType());
  259. item.put("op", 1);
  260. item.put("productionDate",diEx.getProductionDate());
  261. item.put("expiryNum",diEx.getExpiryNum());
  262. item.put("supplierId",diEx.getSupplierId());
  263. item.put("batchNumber",diEx.getBatchNumber());
  264. item.put("inventory",diEx.getInventory());
  265. item.put("supplierName",diEx.getSupplierName());
  266. item.put("unitId",diEx.getUnitId());
  267. item.put("unitList",diEx.getUnitId() == null ? null : unitService.getUnitListByID(diEx.getUnitId()));
  268. item.put("actualQuantityInStorage",diEx.getActualQuantityInStorage());
  269. item.put("warehousingVariance",diEx.getWarehousingVariance());
  270. item.put("reasonOfDifference",diEx.getReasonOfDifference());
  271. item.put("warehousingUser",diEx.getWarehousingUser());
  272. item.put("warehousingTime",diEx.getWarehousingTime());
  273. dataArray.add(item);
  274. //合计数据汇总
  275. totalOperNumber = totalOperNumber.add(diEx.getOperNumber()==null?BigDecimal.ZERO:diEx.getOperNumber());
  276. totalAllPrice = totalAllPrice.add(diEx.getAllPrice()==null?BigDecimal.ZERO:diEx.getAllPrice());
  277. totalTaxMoney = totalTaxMoney.add(diEx.getTaxMoney()==null?BigDecimal.ZERO:diEx.getTaxMoney());
  278. totalTaxLastMoney = totalTaxLastMoney.add(diEx.getTaxLastMoney()==null?BigDecimal.ZERO:diEx.getTaxLastMoney());
  279. totalWeight = totalWeight.add(allWeight);
  280. }
  281. if(StringUtil.isNotEmpty(isReadOnly) && "1".equals(isReadOnly)) {
  282. JSONObject footItem = new JSONObject();
  283. footItem.put("operNumber", totalOperNumber);
  284. footItem.put("allPrice", roleService.parseBillPriceByLimit(totalAllPrice, billCategory, priceLimit, request));
  285. footItem.put("taxMoney", roleService.parseBillPriceByLimit(totalTaxMoney, billCategory, priceLimit, request));
  286. footItem.put("taxLastMoney", roleService.parseBillPriceByLimit(totalTaxLastMoney, billCategory, priceLimit, request));
  287. footItem.put("weight", totalWeight);
  288. dataArray.add(footItem);
  289. }
  290. }
  291. outer.put("rows", dataArray);
  292. res.code = 200;
  293. res.data = outer;
  294. } catch (Exception e) {
  295. logger.error(e.getMessage(), e);
  296. res.code = 500;
  297. res.data = "获取数据失败";
  298. }
  299. return res;
  300. }
  301. /**
  302. * 进销存统计查询
  303. * @param currentPage
  304. * @param pageSize
  305. * @param depotIds
  306. * @param beginTime
  307. * @param endTime
  308. * @param materialParam
  309. * @param mpList
  310. * @param request
  311. * @return
  312. * @throws Exception
  313. */
  314. @GetMapping(value = "/getInOutStock")
  315. @ApiOperation(value = "进销存统计查询")
  316. public BaseResponseInfo getInOutStock(@RequestParam("currentPage") Integer currentPage,
  317. @RequestParam("pageSize") Integer pageSize,
  318. @RequestParam(value = "depotIds",required = false) String depotIds,
  319. @RequestParam(value = "categoryId", required = false) Long categoryId,
  320. @RequestParam("beginTime") String beginTime,
  321. @RequestParam("endTime") String endTime,
  322. @RequestParam("materialParam") String materialParam,
  323. @RequestParam("mpList") String mpList,
  324. HttpServletRequest request)throws Exception {
  325. BaseResponseInfo res = new BaseResponseInfo();
  326. Map<String, Object> map = new HashMap<>();
  327. try {
  328. Boolean moveAvgPriceFlag = systemConfigService.getMoveAvgPriceFlag();
  329. List<Long> categoryIdList = new ArrayList<>();
  330. if(categoryId != null){
  331. categoryIdList = materialService.getListByParentId(categoryId);
  332. }
  333. beginTime = Tools.parseDayToTime(beginTime, BusinessConstants.DAY_FIRST_TIME);
  334. endTime = Tools.parseDayToTime(endTime,BusinessConstants.DAY_LAST_TIME);
  335. List<Long> depotList = parseListByDepotIds(depotIds);
  336. List<DepotItemVo4WithInfoEx> dataList = depotItemService.getInOutStock(StringUtil.toNull(materialParam),
  337. categoryIdList, endTime,(currentPage-1)*pageSize, pageSize);
  338. String[] mpArr = mpList.split(",");
  339. int total = depotItemService.getInOutStockCount(StringUtil.toNull(materialParam), categoryIdList, endTime);
  340. map.put("total", total);
  341. //存放数据json数组
  342. JSONArray dataArray = new JSONArray();
  343. if (null != dataList) {
  344. for (DepotItemVo4WithInfoEx diEx : dataList) {
  345. JSONObject item = new JSONObject();
  346. Long mId = diEx.getMId();
  347. item.put("barCode", diEx.getBarCode());
  348. item.put("materialName", diEx.getMName());
  349. item.put("materialModel", diEx.getMModel());
  350. item.put("materialStandard", diEx.getMStandard());
  351. item.put("materialColor", diEx.getMColor());
  352. item.put("materialMfrs", diEx.getMMfrs());
  353. item.put("materialBrand", diEx.getBrand());
  354. //扩展信息
  355. String materialOther = depotItemService.getOtherInfo(mpArr, diEx);
  356. item.put("materialOther", materialOther);
  357. item.put("unitId", diEx.getUnitId());
  358. item.put("unitName", null!=diEx.getUnitId() ? diEx.getMaterialUnit()+"[多单位]" : diEx.getMaterialUnit());
  359. BigDecimal prevSum = depotItemService.getStockByParamWithDepotList(depotList,mId,null,beginTime);
  360. Map<String,BigDecimal> intervalMap = depotItemService.getIntervalMapByParamWithDepotList(depotList,mId,beginTime,endTime);
  361. BigDecimal inSum = intervalMap.get("inSum");
  362. BigDecimal outSum = intervalMap.get("outSum");
  363. BigDecimal thisSum = prevSum.add(inSum).subtract(outSum);
  364. item.put("prevSum", prevSum);
  365. item.put("inSum", inSum);
  366. item.put("outSum", outSum);
  367. item.put("thisSum", thisSum);
  368. //将小单位的库存换算为大单位的库存
  369. item.put("bigUnitStock", materialService.getBigUnitStock(thisSum, diEx.getUnitId()));
  370. if(moveAvgPriceFlag) {
  371. item.put("unitPrice", diEx.getCurrentUnitPrice());
  372. } else {
  373. item.put("unitPrice", diEx.getPurchaseDecimal());
  374. }
  375. if(moveAvgPriceFlag) {
  376. item.put("thisAllPrice", thisSum.multiply(diEx.getCurrentUnitPrice()));
  377. } else {
  378. item.put("thisAllPrice", thisSum.multiply(diEx.getPurchaseDecimal()));
  379. }
  380. dataArray.add(item);
  381. }
  382. }
  383. map.put("rows", dataArray);
  384. res.code = 200;
  385. res.data = map;
  386. } catch (BusinessRunTimeException e) {
  387. res.code = e.getCode();
  388. res.data = e.getData().get("message");
  389. } catch(Exception e){
  390. logger.error(e.getMessage(), e);
  391. res.code = 500;
  392. res.data = "获取数据失败";
  393. }
  394. return res;
  395. }
  396. /**
  397. * 进销存统计总计金额
  398. * @param depotIds
  399. * @param endTime
  400. * @param materialParam
  401. * @param request
  402. * @return
  403. */
  404. @GetMapping(value = "/getInOutStockCountMoney")
  405. @ApiOperation(value = "进销存统计总计金额")
  406. public BaseResponseInfo getInOutStockCountMoney(@RequestParam(value = "depotIds",required = false) String depotIds,
  407. @RequestParam(value = "categoryId", required = false) Long categoryId,
  408. @RequestParam("endTime") String endTime,
  409. @RequestParam("materialParam") String materialParam,
  410. HttpServletRequest request) throws Exception{
  411. BaseResponseInfo res = new BaseResponseInfo();
  412. Map<String, Object> map = new HashMap<>();
  413. try {
  414. Boolean moveAvgPriceFlag = systemConfigService.getMoveAvgPriceFlag();
  415. List<Long> categoryIdList = new ArrayList<>();
  416. if(categoryId != null){
  417. categoryIdList = materialService.getListByParentId(categoryId);
  418. }
  419. endTime = Tools.parseDayToTime(endTime,BusinessConstants.DAY_LAST_TIME);
  420. List<Long> depotList = parseListByDepotIds(depotIds);
  421. List<DepotItemVo4WithInfoEx> dataList = depotItemService.getInOutStock(StringUtil.toNull(materialParam),
  422. categoryIdList, endTime, null, null);
  423. BigDecimal thisAllStock = BigDecimal.ZERO;
  424. BigDecimal thisAllPrice = BigDecimal.ZERO;
  425. if (null != dataList) {
  426. for (DepotItemVo4WithInfoEx diEx : dataList) {
  427. Long mId = diEx.getMId();
  428. BigDecimal thisSum = depotItemService.getStockByParamWithDepotList(depotList,mId,null,endTime);
  429. thisAllStock = thisAllStock.add(thisSum);
  430. BigDecimal unitPrice = null;
  431. if(moveAvgPriceFlag) {
  432. unitPrice = diEx.getCurrentUnitPrice();
  433. } else {
  434. unitPrice = diEx.getPurchaseDecimal();
  435. }
  436. if(unitPrice == null) {
  437. unitPrice = BigDecimal.ZERO;
  438. }
  439. thisAllPrice = thisAllPrice.add(thisSum.multiply(unitPrice));
  440. }
  441. }
  442. map.put("totalStock", thisAllStock);
  443. map.put("totalCount", thisAllPrice);
  444. res.code = 200;
  445. res.data = map;
  446. } catch (BusinessRunTimeException e) {
  447. res.code = e.getCode();
  448. res.data = e.getData().get("message");
  449. } catch(Exception e){
  450. logger.error(e.getMessage(), e);
  451. res.code = 500;
  452. res.data = "获取数据失败";
  453. }
  454. return res;
  455. }
  456. private List<Long> parseListByDepotIds(@RequestParam("depotIds") String depotIds) throws Exception {
  457. List<Long> depotList = new ArrayList<>();
  458. if(StringUtil.isNotEmpty(depotIds)) {
  459. depotList = StringUtil.strToLongList(depotIds);
  460. } else {
  461. //未选择仓库时默认为当前用户有权限的仓库
  462. JSONArray depotArr = depotService.findDepotByCurrentUser();
  463. for(Object obj: depotArr) {
  464. JSONObject object = JSONObject.parseObject(obj.toString());
  465. depotList.add(object.getLong("id"));
  466. }
  467. //如果有权限的仓库数量太多则提示要选择仓库
  468. if(depotList.size()>20) {
  469. throw new BusinessRunTimeException(ExceptionConstants.REPORT_TWO_MANY_DEPOT_FAILED_CODE,
  470. ExceptionConstants.REPORT_TWO_MANY_DEPOT_FAILED_MSG);
  471. }
  472. }
  473. return depotList;
  474. }
  475. /**
  476. * 采购统计
  477. * @param currentPage
  478. * @param pageSize
  479. * @param beginTime
  480. * @param endTime
  481. * @param materialParam
  482. * @param mpList
  483. * @param request
  484. * @return
  485. */
  486. @GetMapping(value = "/buyIn")
  487. @ApiOperation(value = "采购统计")
  488. public BaseResponseInfo buyIn(@RequestParam("currentPage") Integer currentPage,
  489. @RequestParam("pageSize") Integer pageSize,
  490. @RequestParam("beginTime") String beginTime,
  491. @RequestParam("endTime") String endTime,
  492. @RequestParam(value = "organId", required = false) Long organId,
  493. @RequestParam(value = "depotId", required = false) Long depotId,
  494. @RequestParam(value = "categoryId", required = false) Long categoryId,
  495. @RequestParam(value = "organizationId", required = false) Long organizationId,
  496. @RequestParam("materialParam") String materialParam,
  497. @RequestParam("mpList") String mpList,
  498. HttpServletRequest request)throws Exception {
  499. BaseResponseInfo res = new BaseResponseInfo();
  500. Map<String, Object> map = new HashMap<String, Object>();
  501. beginTime = Tools.parseDayToTime(beginTime, BusinessConstants.DAY_FIRST_TIME);
  502. endTime = Tools.parseDayToTime(endTime,BusinessConstants.DAY_LAST_TIME);
  503. try {
  504. String [] creatorArray = depotHeadService.getCreatorArray();
  505. if(creatorArray == null && organizationId != null) {
  506. creatorArray = depotHeadService.getCreatorArrayByOrg(organizationId);
  507. }
  508. String [] organArray = null;
  509. List<Long> categoryList = new ArrayList<>();
  510. if(categoryId != null){
  511. categoryList = materialService.getListByParentId(categoryId);
  512. }
  513. List<Long> depotList = depotService.parseDepotList(depotId);
  514. Boolean forceFlag = systemConfigService.getForceApprovalFlag();
  515. List<DepotItemVo4WithInfoEx> dataList = depotItemService.getListWithBuyOrSale(StringUtil.toNull(materialParam),
  516. "buy", beginTime, endTime, creatorArray, organId, organArray, categoryList, depotList, forceFlag, (currentPage-1)*pageSize, pageSize);
  517. String[] mpArr = mpList.split(",");
  518. int total = depotItemService.getListWithBuyOrSaleCount(StringUtil.toNull(materialParam),
  519. "buy", beginTime, endTime, creatorArray, organId, organArray, categoryList, depotList, forceFlag);
  520. map.put("total", total);
  521. //存放数据json数组
  522. JSONArray dataArray = new JSONArray();
  523. if (null != dataList) {
  524. for (DepotItemVo4WithInfoEx diEx : dataList) {
  525. JSONObject item = new JSONObject();
  526. BigDecimal InSum = depotItemService.buyOrSale("入库", "采购", diEx.getMId(), beginTime, endTime, creatorArray, organId, organArray, depotList, forceFlag, "number");
  527. BigDecimal OutSum = depotItemService.buyOrSale("出库", "采购退货", diEx.getMId(), beginTime, endTime, creatorArray, organId, organArray, depotList, forceFlag, "number");
  528. BigDecimal InSumPrice = depotItemService.buyOrSale("入库", "采购", diEx.getMId(), beginTime, endTime, creatorArray, organId, organArray, depotList, forceFlag, "price");
  529. BigDecimal OutSumPrice = depotItemService.buyOrSale("出库", "采购退货", diEx.getMId(), beginTime, endTime, creatorArray, organId, organArray, depotList, forceFlag, "price");
  530. BigDecimal InOutSumPrice = InSumPrice.subtract(OutSumPrice);
  531. item.put("barCode", diEx.getBarCode());
  532. item.put("materialName", diEx.getMName());
  533. item.put("materialModel", diEx.getMModel());
  534. item.put("materialStandard", diEx.getMStandard());
  535. //扩展信息
  536. String materialOther = depotItemService.getOtherInfo(mpArr, diEx);
  537. item.put("materialOther", materialOther);
  538. item.put("materialColor", diEx.getMColor());
  539. item.put("materialBrand", diEx.getBrand());
  540. item.put("materialMfrs", diEx.getMMfrs());
  541. item.put("materialUnit", diEx.getMaterialUnit());
  542. item.put("unitName", diEx.getUnitName());
  543. item.put("inSum", InSum);
  544. item.put("outSum", OutSum);
  545. item.put("inSumPrice", InSumPrice);
  546. item.put("outSumPrice", OutSumPrice);
  547. item.put("inOutSumPrice",InOutSumPrice);//实际采购金额
  548. dataArray.add(item);
  549. }
  550. }
  551. BigDecimal inSumPriceTotal = depotItemService.buyOrSalePriceTotal("入库", "采购", StringUtil.toNull(materialParam),
  552. beginTime, endTime, creatorArray, organId, organArray, categoryList, depotList, forceFlag);
  553. BigDecimal outSumPriceTotal = depotItemService.buyOrSalePriceTotal("出库", "采购退货", StringUtil.toNull(materialParam),
  554. beginTime, endTime, creatorArray, organId, organArray, categoryList, depotList, forceFlag);
  555. BigDecimal realityPriceTotal = inSumPriceTotal.subtract(outSumPriceTotal);
  556. map.put("rows", dataArray);
  557. map.put("realityPriceTotal", realityPriceTotal);
  558. res.code = 200;
  559. res.data = map;
  560. } catch(Exception e){
  561. logger.error(e.getMessage(), e);
  562. res.code = 500;
  563. res.data = "获取数据失败";
  564. }
  565. return res;
  566. }
  567. /**
  568. * 零售统计
  569. * @param currentPage
  570. * @param pageSize
  571. * @param beginTime
  572. * @param endTime
  573. * @param materialParam
  574. * @param mpList
  575. * @param request
  576. * @return
  577. */
  578. @GetMapping(value = "/retailOut")
  579. @ApiOperation(value = "零售统计")
  580. public BaseResponseInfo retailOut(@RequestParam("currentPage") Integer currentPage,
  581. @RequestParam("pageSize") Integer pageSize,
  582. @RequestParam("beginTime") String beginTime,
  583. @RequestParam("endTime") String endTime,
  584. @RequestParam(value = "organId", required = false) Long organId,
  585. @RequestParam(value = "depotId", required = false) Long depotId,
  586. @RequestParam(value = "categoryId", required = false) Long categoryId,
  587. @RequestParam(value = "organizationId", required = false) Long organizationId,
  588. @RequestParam("materialParam") String materialParam,
  589. @RequestParam("mpList") String mpList,
  590. HttpServletRequest request)throws Exception {
  591. BaseResponseInfo res = new BaseResponseInfo();
  592. Map<String, Object> map = new HashMap<String, Object>();
  593. beginTime = Tools.parseDayToTime(beginTime, BusinessConstants.DAY_FIRST_TIME);
  594. endTime = Tools.parseDayToTime(endTime,BusinessConstants.DAY_LAST_TIME);
  595. try {
  596. String [] creatorArray = depotHeadService.getCreatorArray();
  597. if(creatorArray == null && organizationId != null) {
  598. creatorArray = depotHeadService.getCreatorArrayByOrg(organizationId);
  599. }
  600. String [] organArray = null;
  601. List<Long> categoryList = new ArrayList<>();
  602. if(categoryId != null){
  603. categoryList = materialService.getListByParentId(categoryId);
  604. }
  605. List<Long> depotList = depotService.parseDepotList(depotId);
  606. Boolean forceFlag = systemConfigService.getForceApprovalFlag();
  607. List<DepotItemVo4WithInfoEx> dataList = depotItemService.getListWithBuyOrSale(StringUtil.toNull(materialParam),
  608. "retail", beginTime, endTime, creatorArray, organId, organArray, categoryList, depotList, forceFlag, (currentPage-1)*pageSize, pageSize);
  609. String[] mpArr = mpList.split(",");
  610. int total = depotItemService.getListWithBuyOrSaleCount(StringUtil.toNull(materialParam),
  611. "retail", beginTime, endTime, creatorArray, organId, organArray, categoryList, depotList, forceFlag);
  612. map.put("total", total);
  613. //存放数据json数组
  614. JSONArray dataArray = new JSONArray();
  615. if (null != dataList) {
  616. for (DepotItemVo4WithInfoEx diEx : dataList) {
  617. JSONObject item = new JSONObject();
  618. BigDecimal OutSumRetail = depotItemService.buyOrSale("出库", "零售", diEx.getMId(), beginTime, endTime, creatorArray, organId, organArray, depotList, forceFlag, "number");
  619. BigDecimal InSumRetail = depotItemService.buyOrSale("入库", "零售退货", diEx.getMId(), beginTime, endTime, creatorArray, organId, organArray, depotList, forceFlag, "number");
  620. BigDecimal OutSumRetailPrice = depotItemService.buyOrSale("出库", "零售", diEx.getMId(), beginTime, endTime, creatorArray, organId, organArray, depotList, forceFlag, "price");
  621. BigDecimal InSumRetailPrice = depotItemService.buyOrSale("入库", "零售退货", diEx.getMId(), beginTime, endTime, creatorArray, organId, organArray, depotList, forceFlag, "price");
  622. BigDecimal OutInSumPrice = OutSumRetailPrice.subtract(InSumRetailPrice);
  623. item.put("barCode", diEx.getBarCode());
  624. item.put("materialName", diEx.getMName());
  625. item.put("materialModel", diEx.getMModel());
  626. item.put("materialStandard", diEx.getMStandard());
  627. //扩展信息
  628. String materialOther = depotItemService.getOtherInfo(mpArr, diEx);
  629. item.put("materialOther", materialOther);
  630. item.put("materialColor", diEx.getMColor());
  631. item.put("materialBrand", diEx.getBrand());
  632. item.put("materialMfrs", diEx.getMMfrs());
  633. item.put("materialUnit", diEx.getMaterialUnit());
  634. item.put("unitName", diEx.getUnitName());
  635. item.put("outSum", OutSumRetail);
  636. item.put("inSum", InSumRetail);
  637. item.put("outSumPrice", OutSumRetailPrice);
  638. item.put("inSumPrice", InSumRetailPrice);
  639. item.put("outInSumPrice",OutInSumPrice);//实际销售金额
  640. dataArray.add(item);
  641. }
  642. }
  643. BigDecimal outSumPriceTotal = depotItemService.buyOrSalePriceTotal("出库", "零售", StringUtil.toNull(materialParam),
  644. beginTime, endTime, creatorArray, organId, organArray, categoryList, depotList, forceFlag);
  645. BigDecimal inSumPriceTotal = depotItemService.buyOrSalePriceTotal("入库", "零售退货", StringUtil.toNull(materialParam),
  646. beginTime, endTime, creatorArray, organId, organArray, categoryList, depotList, forceFlag);
  647. BigDecimal realityPriceTotal = outSumPriceTotal.subtract(inSumPriceTotal);
  648. map.put("rows", dataArray);
  649. map.put("realityPriceTotal", realityPriceTotal);
  650. res.code = 200;
  651. res.data = map;
  652. } catch(Exception e){
  653. logger.error(e.getMessage(), e);
  654. res.code = 500;
  655. res.data = "获取数据失败";
  656. }
  657. return res;
  658. }
  659. /**
  660. * 销售统计
  661. * @param currentPage
  662. * @param pageSize
  663. * @param beginTime
  664. * @param endTime
  665. * @param materialParam
  666. * @param mpList
  667. * @param request
  668. * @return
  669. */
  670. @GetMapping(value = "/saleOut")
  671. @ApiOperation(value = "销售统计")
  672. public BaseResponseInfo saleOut(@RequestParam("currentPage") Integer currentPage,
  673. @RequestParam("pageSize") Integer pageSize,
  674. @RequestParam("beginTime") String beginTime,
  675. @RequestParam("endTime") String endTime,
  676. @RequestParam(value = "organId", required = false) Long organId,
  677. @RequestParam(value = "depotId", required = false) Long depotId,
  678. @RequestParam(value = "categoryId", required = false) Long categoryId,
  679. @RequestParam(value = "organizationId", required = false) Long organizationId,
  680. @RequestParam("materialParam") String materialParam,
  681. @RequestParam("mpList") String mpList,
  682. HttpServletRequest request)throws Exception {
  683. BaseResponseInfo res = new BaseResponseInfo();
  684. Map<String, Object> map = new HashMap<String, Object>();
  685. beginTime = Tools.parseDayToTime(beginTime, BusinessConstants.DAY_FIRST_TIME);
  686. endTime = Tools.parseDayToTime(endTime,BusinessConstants.DAY_LAST_TIME);
  687. try {
  688. String [] creatorArray = depotHeadService.getCreatorArray();
  689. if(creatorArray == null && organizationId != null) {
  690. creatorArray = depotHeadService.getCreatorArrayByOrg(organizationId);
  691. }
  692. String [] organArray = depotHeadService.getOrganArray("销售", "");
  693. List<Long> categoryList = new ArrayList<>();
  694. if(categoryId != null){
  695. categoryList = materialService.getListByParentId(categoryId);
  696. }
  697. List<Long> depotList = depotService.parseDepotList(depotId);
  698. Boolean forceFlag = systemConfigService.getForceApprovalFlag();
  699. List<DepotItemVo4WithInfoEx> dataList = depotItemService.getListWithBuyOrSale(StringUtil.toNull(materialParam),
  700. "sale", beginTime, endTime, creatorArray, organId, organArray, categoryList, depotList, forceFlag, (currentPage-1)*pageSize, pageSize);
  701. String[] mpArr = mpList.split(",");
  702. int total = depotItemService.getListWithBuyOrSaleCount(StringUtil.toNull(materialParam),
  703. "sale", beginTime, endTime, creatorArray, organId, organArray, categoryList, depotList, forceFlag);
  704. map.put("total", total);
  705. //存放数据json数组
  706. JSONArray dataArray = new JSONArray();
  707. if (null != dataList) {
  708. for (DepotItemVo4WithInfoEx diEx : dataList) {
  709. JSONObject item = new JSONObject();
  710. BigDecimal OutSum = depotItemService.buyOrSale("出库", "销售", diEx.getMId(), beginTime, endTime, creatorArray, organId, organArray, depotList, forceFlag, "number");
  711. BigDecimal InSum = depotItemService.buyOrSale("入库", "销售退货", diEx.getMId(), beginTime, endTime, creatorArray, organId, organArray, depotList, forceFlag, "number");
  712. BigDecimal OutSumPrice = depotItemService.buyOrSale("出库", "销售", diEx.getMId(), beginTime, endTime, creatorArray, organId, organArray, depotList, forceFlag, "price");
  713. BigDecimal InSumPrice = depotItemService.buyOrSale("入库", "销售退货", diEx.getMId(), beginTime, endTime, creatorArray, organId, organArray, depotList, forceFlag, "price");
  714. BigDecimal OutInSumPrice = OutSumPrice.subtract(InSumPrice);
  715. item.put("barCode", diEx.getBarCode());
  716. item.put("materialName", diEx.getMName());
  717. item.put("materialModel", diEx.getMModel());
  718. item.put("materialStandard", diEx.getMStandard());
  719. //扩展信息
  720. String materialOther = depotItemService.getOtherInfo(mpArr, diEx);
  721. item.put("materialOther", materialOther);
  722. item.put("materialColor", diEx.getMColor());
  723. item.put("materialBrand", diEx.getBrand());
  724. item.put("materialMfrs", diEx.getMMfrs());
  725. item.put("materialUnit", diEx.getMaterialUnit());
  726. item.put("unitName", diEx.getUnitName());
  727. item.put("outSum", OutSum);
  728. item.put("inSum", InSum);
  729. item.put("outSumPrice", OutSumPrice);
  730. item.put("inSumPrice", InSumPrice);
  731. item.put("outInSumPrice",OutInSumPrice);//实际销售金额
  732. dataArray.add(item);
  733. }
  734. }
  735. BigDecimal outSumPriceTotal = depotItemService.buyOrSalePriceTotal("出库", "销售", StringUtil.toNull(materialParam),
  736. beginTime, endTime, creatorArray, organId, organArray, categoryList, depotList, forceFlag);
  737. BigDecimal inSumPriceTotal = depotItemService.buyOrSalePriceTotal("入库", "销售退货", StringUtil.toNull(materialParam),
  738. beginTime, endTime, creatorArray, organId, organArray, categoryList, depotList, forceFlag);
  739. BigDecimal realityPriceTotal = outSumPriceTotal.subtract(inSumPriceTotal);
  740. map.put("rows", dataArray);
  741. map.put("realityPriceTotal", realityPriceTotal);
  742. res.code = 200;
  743. res.data = map;
  744. } catch(Exception e){
  745. logger.error(e.getMessage(), e);
  746. res.code = 500;
  747. res.data = "获取数据失败";
  748. }
  749. return res;
  750. }
  751. /**
  752. * 获取单位
  753. * @param materialUnit
  754. * @param uName
  755. * @return
  756. */
  757. public String getUName(String materialUnit, String uName) {
  758. String unitName = null;
  759. if(StringUtil.isNotEmpty(materialUnit)) {
  760. unitName = materialUnit;
  761. } else if(StringUtil.isNotEmpty(uName)) {
  762. unitName = uName;
  763. }
  764. return unitName;
  765. }
  766. /**
  767. * 库存预警报表
  768. * @param currentPage
  769. * @param pageSize
  770. * @return
  771. */
  772. @GetMapping(value = "/findStockWarningCount")
  773. @ApiOperation(value = "库存预警报表")
  774. public BaseResponseInfo findStockWarningCount(@RequestParam("currentPage") Integer currentPage,
  775. @RequestParam("pageSize") Integer pageSize,
  776. @RequestParam("materialParam") String materialParam,
  777. @RequestParam(value = "depotId", required = false) Long depotId,
  778. @RequestParam(value = "categoryId", required = false) Long categoryId,
  779. @RequestParam("mpList") String mpList)throws Exception {
  780. BaseResponseInfo res = new BaseResponseInfo();
  781. Map<String, Object> map = new HashMap<String, Object>();
  782. try {
  783. List<Long> depotList = new ArrayList<>();
  784. if(depotId != null) {
  785. depotList.add(depotId);
  786. } else {
  787. //未选择仓库时默认为当前用户有权限的仓库
  788. JSONArray depotArr = depotService.findDepotByCurrentUser();
  789. for(Object obj: depotArr) {
  790. JSONObject object = JSONObject.parseObject(obj.toString());
  791. depotList.add(object.getLong("id"));
  792. }
  793. }
  794. List<Long> categoryList = new ArrayList<>();
  795. if(categoryId != null){
  796. categoryList = materialService.getListByParentId(categoryId);
  797. }
  798. String[] mpArr = mpList.split(",");
  799. List<DepotItemStockWarningCount> list = depotItemService.findStockWarningCount((currentPage-1)*pageSize, pageSize, materialParam, depotList, categoryList);
  800. //存放数据json数组
  801. if (null != list) {
  802. for (DepotItemStockWarningCount disw : list) {
  803. DepotItemVo4WithInfoEx diEx = new DepotItemVo4WithInfoEx();
  804. diEx.setMOtherField1(disw.getMOtherField1());
  805. diEx.setMOtherField2(disw.getMOtherField2());
  806. diEx.setMOtherField3(disw.getMOtherField3());
  807. disw.setMaterialOther(depotItemService.getOtherInfo(mpArr, diEx));
  808. disw.setMaterialUnit(getUName(disw.getMaterialUnit(), disw.getUnitName()));
  809. if(null!=disw.getLowSafeStock() && disw.getCurrentNumber().compareTo(disw.getLowSafeStock())<0) {
  810. disw.setLowCritical(disw.getLowSafeStock().subtract(disw.getCurrentNumber()));
  811. }
  812. if(null!=disw.getHighSafeStock() && disw.getCurrentNumber().compareTo(disw.getHighSafeStock())>0) {
  813. disw.setHighCritical(disw.getCurrentNumber().subtract(disw.getHighSafeStock()));
  814. }
  815. }
  816. }
  817. int total = depotItemService.findStockWarningCountTotal(materialParam, depotList, categoryList);
  818. map.put("total", total);
  819. map.put("rows", list);
  820. res.code = 200;
  821. res.data = map;
  822. } catch(Exception e){
  823. logger.error(e.getMessage(), e);
  824. res.code = 500;
  825. res.data = "获取数据失败";
  826. }
  827. return res;
  828. }
  829. /**
  830. * 统计采购、销售、零售的总金额
  831. * @param request
  832. * @param response
  833. * @return
  834. * @throws Exception
  835. */
  836. @GetMapping(value = "/buyOrSalePrice")
  837. @ApiOperation(value = "统计采购、销售、零售的总金额")
  838. public BaseResponseInfo buyOrSalePrice(HttpServletRequest request,
  839. HttpServletResponse response)throws Exception {
  840. BaseResponseInfo res = new BaseResponseInfo();
  841. try {
  842. Map<String, Object> map = new HashMap<>();
  843. String loginName = userService.getCurrentUser().getLoginName();
  844. if(!"admin".equals(loginName)) {
  845. Long userId = userService.getUserId(request);
  846. List<String> monthList = Tools.getLastMonths(6);
  847. String beginTime = Tools.firstDayOfMonth(monthList.get(0)) + BusinessConstants.DAY_FIRST_TIME;
  848. String endTime = Tools.getNow() + BusinessConstants.DAY_LAST_TIME;
  849. List<InOutPriceVo> inOrOutPriceList = depotItemService.inOrOutPriceList(beginTime, endTime);
  850. String priceLimit = userService.getRoleTypeByUserId(userId).getPriceLimit();
  851. JSONArray buyPriceList = new JSONArray();
  852. for (String month : monthList) {
  853. JSONObject obj = new JSONObject();
  854. BigDecimal outPrice = BigDecimal.ZERO;
  855. BigDecimal inPrice = BigDecimal.ZERO;
  856. for (InOutPriceVo item : inOrOutPriceList) {
  857. String billOperMonth = Tools.dateToStr(item.getOperTime(), "yyyy-MM");
  858. if (month.equals(billOperMonth)) {
  859. if ("入库".equals(item.getType()) && "采购".equals(item.getSubType())) {
  860. outPrice = outPrice.add(item.getDiscountLastMoney());
  861. }
  862. if ("出库".equals(item.getType()) && "采购退货".equals(item.getSubType())) {
  863. inPrice = inPrice.add(item.getDiscountLastMoney());
  864. }
  865. }
  866. }
  867. obj.put("x", month);
  868. obj.put("y", roleService.parseHomePriceByLimit(outPrice.subtract(inPrice), "buy", priceLimit, "***", request));
  869. buyPriceList.add(obj);
  870. }
  871. map.put("buyPriceList", buyPriceList);
  872. JSONArray salePriceList = new JSONArray();
  873. for (String month : monthList) {
  874. JSONObject obj = new JSONObject();
  875. BigDecimal outPrice = BigDecimal.ZERO;
  876. BigDecimal inPrice = BigDecimal.ZERO;
  877. for (InOutPriceVo item : inOrOutPriceList) {
  878. String billOperMonth = Tools.dateToStr(item.getOperTime(), "yyyy-MM");
  879. if (month.equals(billOperMonth)) {
  880. if ("出库".equals(item.getType()) && "销售".equals(item.getSubType())) {
  881. outPrice = outPrice.add(item.getDiscountLastMoney());
  882. }
  883. if ("入库".equals(item.getType()) && "销售退货".equals(item.getSubType())) {
  884. inPrice = inPrice.add(item.getDiscountLastMoney());
  885. }
  886. }
  887. }
  888. obj.put("x", month);
  889. obj.put("y", roleService.parseHomePriceByLimit(outPrice.subtract(inPrice), "sale", priceLimit, "***", request));
  890. salePriceList.add(obj);
  891. }
  892. map.put("salePriceList", salePriceList);
  893. JSONArray retailPriceList = new JSONArray();
  894. for (String month : monthList) {
  895. JSONObject obj = new JSONObject();
  896. BigDecimal outPrice = BigDecimal.ZERO;
  897. BigDecimal inPrice = BigDecimal.ZERO;
  898. for (InOutPriceVo item : inOrOutPriceList) {
  899. String billOperMonth = Tools.dateToStr(item.getOperTime(), "yyyy-MM");
  900. if (month.equals(billOperMonth)) {
  901. if ("出库".equals(item.getType()) && "零售".equals(item.getSubType())) {
  902. outPrice = outPrice.add(item.getTotalPrice().abs());
  903. }
  904. if ("入库".equals(item.getType()) && "零售退货".equals(item.getSubType())) {
  905. inPrice = inPrice.add(item.getTotalPrice().abs());
  906. }
  907. }
  908. }
  909. obj.put("x", month);
  910. obj.put("y", roleService.parseHomePriceByLimit(outPrice.subtract(inPrice), "retail", priceLimit, "***", request));
  911. retailPriceList.add(obj);
  912. }
  913. map.put("retailPriceList", retailPriceList);
  914. }
  915. res.code = 200;
  916. res.data = map;
  917. } catch (Exception e) {
  918. logger.error(e.getMessage(), e);
  919. res.code = 500;
  920. res.data = "统计失败";
  921. }
  922. return res;
  923. }
  924. /**
  925. * 获取批次商品列表信息
  926. * @param request
  927. * @return
  928. */
  929. @GetMapping(value = "/getBatchNumberList")
  930. @ApiOperation(value = "获取批次商品列表信息")
  931. public BaseResponseInfo getBatchNumberList(@RequestParam("name") String name,
  932. @RequestParam("depotItemId") Long depotItemId,
  933. @RequestParam("barCode") String barCode,
  934. @RequestParam(value = "batchNumber", required = false) String batchNumber,
  935. HttpServletRequest request) throws Exception{
  936. BaseResponseInfo res = new BaseResponseInfo();
  937. Map<String, Object> map = new HashMap<>();
  938. try {
  939. String number = "";
  940. if(depotItemId != null) {
  941. DepotItem depotItem = depotItemService.getDepotItem(depotItemId);
  942. number = depotHeadService.getDepotHead(depotItem.getHeaderId()).getNumber();
  943. }
  944. Boolean forceFlag = systemConfigService.getForceApprovalFlag();
  945. Boolean inOutManageFlag = systemConfigService.getInOutManageFlag();
  946. List<DepotItemVoBatchNumberList> list = depotItemService.getBatchNumberList(number, name, null, barCode,
  947. batchNumber, forceFlag, inOutManageFlag);
  948. map.put("rows", list);
  949. map.put("total", list.size());
  950. res.code = 200;
  951. res.data = map;
  952. } catch (Exception e) {
  953. logger.error(e.getMessage(), e);
  954. res.code = 500;
  955. res.data = "获取数据失败";
  956. }
  957. return res;
  958. }
  959. /**
  960. * Excel导入明细
  961. * @param file
  962. * @param request
  963. * @param response
  964. * @return
  965. */
  966. @PostMapping(value = "/importItemExcel")
  967. public BaseResponseInfo importItemExcel(MultipartFile file,
  968. @RequestParam(required = false, value = "prefixNo") String prefixNo,
  969. HttpServletRequest request, HttpServletResponse response) throws Exception{
  970. BaseResponseInfo res = new BaseResponseInfo();
  971. Map<String, Object> data = new HashMap<>();
  972. String message = "";
  973. try {
  974. String barCodes = "";
  975. //文件合法性校验
  976. Sheet src = null;
  977. try {
  978. Workbook workbook = Workbook.getWorkbook(file.getInputStream());
  979. src = workbook.getSheet(0);
  980. } catch (Exception e) {
  981. message = "导入文件不合法,请检查";
  982. data.put("message", message);
  983. res.code = 400;
  984. res.data = data;
  985. }
  986. if(src.getRows()>1000) {
  987. message = "导入失败,明细不能超出1000条";
  988. res.code = 500;
  989. data.put("message", message);
  990. res.data = data;
  991. } else {
  992. List<Map<String, String>> detailList = new ArrayList<>();
  993. for (int i = 2; i < src.getRows(); i++) {
  994. String depotName = "", barCode = "", num = "", unitPrice = "", taxRate = "", remark = "";
  995. if("QGD".equals(prefixNo)) {
  996. barCode = ExcelUtils.getContent(src, i, 0);
  997. num = ExcelUtils.getContent(src, i, 2);
  998. remark = ExcelUtils.getContent(src, i, 3);
  999. }
  1000. if("CGDD".equals(prefixNo) || "XSDD".equals(prefixNo)) {
  1001. barCode = ExcelUtils.getContent(src, i, 0);
  1002. num = ExcelUtils.getContent(src, i, 2);
  1003. unitPrice = ExcelUtils.getContent(src, i, 3);
  1004. taxRate = ExcelUtils.getContent(src, i, 4);
  1005. remark = ExcelUtils.getContent(src, i, 5);
  1006. }
  1007. if("CGRK".equals(prefixNo) || "XSCK".equals(prefixNo)) {
  1008. depotName = ExcelUtils.getContent(src, i, 0);
  1009. barCode = ExcelUtils.getContent(src, i, 1);
  1010. num = ExcelUtils.getContent(src, i, 3);
  1011. unitPrice = ExcelUtils.getContent(src, i, 4);
  1012. taxRate = ExcelUtils.getContent(src, i, 5);
  1013. remark = ExcelUtils.getContent(src, i, 6);
  1014. }
  1015. if("QTRK".equals(prefixNo) || "QTCK".equals(prefixNo)) {
  1016. depotName = ExcelUtils.getContent(src, i, 0);
  1017. barCode = ExcelUtils.getContent(src, i, 1);
  1018. num = ExcelUtils.getContent(src, i, 3);
  1019. unitPrice = ExcelUtils.getContent(src, i, 4);
  1020. remark = ExcelUtils.getContent(src, i, 5);
  1021. }
  1022. Map<String, String> materialMap = new HashMap<>();
  1023. materialMap.put("depotName", depotName);
  1024. materialMap.put("barCode", barCode);
  1025. materialMap.put("num", num);
  1026. materialMap.put("unitPrice", unitPrice);
  1027. materialMap.put("taxRate", taxRate);
  1028. materialMap.put("remark", remark);
  1029. detailList.add(materialMap);
  1030. barCodes += "'" + barCode + "',";
  1031. }
  1032. if (StringUtil.isNotEmpty(barCodes)) {
  1033. barCodes = barCodes.substring(0, barCodes.length() - 1);
  1034. }
  1035. JSONObject map = depotItemService.parseMapByExcelData(barCodes, detailList, prefixNo);
  1036. if (map != null) {
  1037. res.code = 200;
  1038. } else {
  1039. res.code = 500;
  1040. }
  1041. res.data = map;
  1042. }
  1043. } catch (BusinessRunTimeException e) {
  1044. res.code = 500;
  1045. data.put("message", e.getData().get("message"));
  1046. res.data = data;
  1047. } catch (Exception e) {
  1048. logger.error(e.getMessage(), e);
  1049. message = "导入失败,请检查表格内容";
  1050. res.code = 500;
  1051. data.put("message", message);
  1052. res.data = data;
  1053. }
  1054. return res;
  1055. }
  1056. }