DepotItemController.java 58 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089
  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("unitName", diEx.getUnitName());
  269. item.put("actualQuantityInStorage",diEx.getActualQuantityInStorage());
  270. item.put("warehousingVariance",diEx.getWarehousingVariance());
  271. item.put("reasonOfDifference",diEx.getReasonOfDifference());
  272. item.put("warehousingUser",diEx.getWarehousingUser());
  273. item.put("warehousingTime",diEx.getWarehousingTime());
  274. dataArray.add(item);
  275. //合计数据汇总
  276. totalOperNumber = totalOperNumber.add(diEx.getOperNumber()==null?BigDecimal.ZERO:diEx.getOperNumber());
  277. totalAllPrice = totalAllPrice.add(diEx.getAllPrice()==null?BigDecimal.ZERO:diEx.getAllPrice());
  278. totalTaxMoney = totalTaxMoney.add(diEx.getTaxMoney()==null?BigDecimal.ZERO:diEx.getTaxMoney());
  279. totalTaxLastMoney = totalTaxLastMoney.add(diEx.getTaxLastMoney()==null?BigDecimal.ZERO:diEx.getTaxLastMoney());
  280. totalWeight = totalWeight.add(allWeight);
  281. }
  282. if(StringUtil.isNotEmpty(isReadOnly) && "1".equals(isReadOnly)) {
  283. JSONObject footItem = new JSONObject();
  284. footItem.put("operNumber", totalOperNumber);
  285. footItem.put("allPrice", roleService.parseBillPriceByLimit(totalAllPrice, billCategory, priceLimit, request));
  286. footItem.put("taxMoney", roleService.parseBillPriceByLimit(totalTaxMoney, billCategory, priceLimit, request));
  287. footItem.put("taxLastMoney", roleService.parseBillPriceByLimit(totalTaxLastMoney, billCategory, priceLimit, request));
  288. footItem.put("weight", totalWeight);
  289. dataArray.add(footItem);
  290. }
  291. }
  292. outer.put("rows", dataArray);
  293. res.code = 200;
  294. res.data = outer;
  295. } catch (Exception e) {
  296. logger.error(e.getMessage(), e);
  297. res.code = 500;
  298. res.data = "获取数据失败";
  299. }
  300. return res;
  301. }
  302. /**
  303. * 进销存统计查询
  304. * @param currentPage
  305. * @param pageSize
  306. * @param depotIds
  307. * @param beginTime
  308. * @param endTime
  309. * @param materialParam
  310. * @param mpList
  311. * @param request
  312. * @return
  313. * @throws Exception
  314. */
  315. @GetMapping(value = "/getInOutStock")
  316. @ApiOperation(value = "进销存统计查询")
  317. public BaseResponseInfo getInOutStock(@RequestParam("currentPage") Integer currentPage,
  318. @RequestParam("pageSize") Integer pageSize,
  319. @RequestParam(value = "depotIds",required = false) String depotIds,
  320. @RequestParam(value = "categoryId", required = false) Long categoryId,
  321. @RequestParam("beginTime") String beginTime,
  322. @RequestParam("endTime") String endTime,
  323. @RequestParam("materialParam") String materialParam,
  324. @RequestParam("mpList") String mpList,
  325. HttpServletRequest request)throws Exception {
  326. BaseResponseInfo res = new BaseResponseInfo();
  327. Map<String, Object> map = new HashMap<>();
  328. try {
  329. Boolean moveAvgPriceFlag = systemConfigService.getMoveAvgPriceFlag();
  330. List<Long> categoryIdList = new ArrayList<>();
  331. if(categoryId != null){
  332. categoryIdList = materialService.getListByParentId(categoryId);
  333. }
  334. beginTime = Tools.parseDayToTime(beginTime, BusinessConstants.DAY_FIRST_TIME);
  335. endTime = Tools.parseDayToTime(endTime,BusinessConstants.DAY_LAST_TIME);
  336. List<Long> depotList = parseListByDepotIds(depotIds);
  337. List<DepotItemVo4WithInfoEx> dataList = depotItemService.getInOutStock(StringUtil.toNull(materialParam),
  338. categoryIdList, endTime,(currentPage-1)*pageSize, pageSize);
  339. String[] mpArr = mpList.split(",");
  340. int total = depotItemService.getInOutStockCount(StringUtil.toNull(materialParam), categoryIdList, endTime);
  341. map.put("total", total);
  342. //存放数据json数组
  343. JSONArray dataArray = new JSONArray();
  344. if (null != dataList) {
  345. for (DepotItemVo4WithInfoEx diEx : dataList) {
  346. JSONObject item = new JSONObject();
  347. Long mId = diEx.getMId();
  348. item.put("barCode", diEx.getBarCode());
  349. item.put("materialName", diEx.getMName());
  350. item.put("materialModel", diEx.getMModel());
  351. item.put("materialStandard", diEx.getMStandard());
  352. item.put("materialColor", diEx.getMColor());
  353. item.put("materialMfrs", diEx.getMMfrs());
  354. item.put("materialBrand", diEx.getBrand());
  355. //扩展信息
  356. String materialOther = depotItemService.getOtherInfo(mpArr, diEx);
  357. item.put("materialOther", materialOther);
  358. item.put("unitId", diEx.getUnitId());
  359. item.put("unitName", null!=diEx.getUnitId() ? diEx.getMaterialUnit()+"[多单位]" : diEx.getMaterialUnit());
  360. BigDecimal prevSum = depotItemService.getStockByParamWithDepotList(depotList,mId,null,beginTime);
  361. Map<String,BigDecimal> intervalMap = depotItemService.getIntervalMapByParamWithDepotList(depotList,mId,beginTime,endTime);
  362. BigDecimal inSum = intervalMap.get("inSum");
  363. BigDecimal outSum = intervalMap.get("outSum");
  364. BigDecimal thisSum = prevSum.add(inSum).subtract(outSum);
  365. item.put("prevSum", prevSum);
  366. item.put("inSum", inSum);
  367. item.put("outSum", outSum);
  368. item.put("thisSum", thisSum);
  369. //将小单位的库存换算为大单位的库存
  370. item.put("bigUnitStock", materialService.getBigUnitStock(thisSum, diEx.getUnitId()));
  371. if(moveAvgPriceFlag) {
  372. item.put("unitPrice", diEx.getCurrentUnitPrice());
  373. } else {
  374. item.put("unitPrice", diEx.getPurchaseDecimal());
  375. }
  376. if(moveAvgPriceFlag) {
  377. item.put("thisAllPrice", thisSum.multiply(diEx.getCurrentUnitPrice()));
  378. } else {
  379. item.put("thisAllPrice", thisSum.multiply(diEx.getPurchaseDecimal()));
  380. }
  381. dataArray.add(item);
  382. }
  383. }
  384. map.put("rows", dataArray);
  385. res.code = 200;
  386. res.data = map;
  387. } catch (BusinessRunTimeException e) {
  388. res.code = e.getCode();
  389. res.data = e.getData().get("message");
  390. } catch(Exception e){
  391. logger.error(e.getMessage(), e);
  392. res.code = 500;
  393. res.data = "获取数据失败";
  394. }
  395. return res;
  396. }
  397. /**
  398. * 进销存统计总计金额
  399. * @param depotIds
  400. * @param endTime
  401. * @param materialParam
  402. * @param request
  403. * @return
  404. */
  405. @GetMapping(value = "/getInOutStockCountMoney")
  406. @ApiOperation(value = "进销存统计总计金额")
  407. public BaseResponseInfo getInOutStockCountMoney(@RequestParam(value = "depotIds",required = false) String depotIds,
  408. @RequestParam(value = "categoryId", required = false) Long categoryId,
  409. @RequestParam("endTime") String endTime,
  410. @RequestParam("materialParam") String materialParam,
  411. HttpServletRequest request) throws Exception{
  412. BaseResponseInfo res = new BaseResponseInfo();
  413. Map<String, Object> map = new HashMap<>();
  414. try {
  415. Boolean moveAvgPriceFlag = systemConfigService.getMoveAvgPriceFlag();
  416. List<Long> categoryIdList = new ArrayList<>();
  417. if(categoryId != null){
  418. categoryIdList = materialService.getListByParentId(categoryId);
  419. }
  420. endTime = Tools.parseDayToTime(endTime,BusinessConstants.DAY_LAST_TIME);
  421. List<Long> depotList = parseListByDepotIds(depotIds);
  422. List<DepotItemVo4WithInfoEx> dataList = depotItemService.getInOutStock(StringUtil.toNull(materialParam),
  423. categoryIdList, endTime, null, null);
  424. BigDecimal thisAllStock = BigDecimal.ZERO;
  425. BigDecimal thisAllPrice = BigDecimal.ZERO;
  426. if (null != dataList) {
  427. for (DepotItemVo4WithInfoEx diEx : dataList) {
  428. Long mId = diEx.getMId();
  429. BigDecimal thisSum = depotItemService.getStockByParamWithDepotList(depotList,mId,null,endTime);
  430. thisAllStock = thisAllStock.add(thisSum);
  431. BigDecimal unitPrice = null;
  432. if(moveAvgPriceFlag) {
  433. unitPrice = diEx.getCurrentUnitPrice();
  434. } else {
  435. unitPrice = diEx.getPurchaseDecimal();
  436. }
  437. if(unitPrice == null) {
  438. unitPrice = BigDecimal.ZERO;
  439. }
  440. thisAllPrice = thisAllPrice.add(thisSum.multiply(unitPrice));
  441. }
  442. }
  443. map.put("totalStock", thisAllStock);
  444. map.put("totalCount", thisAllPrice);
  445. res.code = 200;
  446. res.data = map;
  447. } catch (BusinessRunTimeException e) {
  448. res.code = e.getCode();
  449. res.data = e.getData().get("message");
  450. } catch(Exception e){
  451. logger.error(e.getMessage(), e);
  452. res.code = 500;
  453. res.data = "获取数据失败";
  454. }
  455. return res;
  456. }
  457. private List<Long> parseListByDepotIds(@RequestParam("depotIds") String depotIds) throws Exception {
  458. List<Long> depotList = new ArrayList<>();
  459. if(StringUtil.isNotEmpty(depotIds)) {
  460. depotList = StringUtil.strToLongList(depotIds);
  461. } else {
  462. //未选择仓库时默认为当前用户有权限的仓库
  463. JSONArray depotArr = depotService.findDepotByCurrentUser();
  464. for(Object obj: depotArr) {
  465. JSONObject object = JSONObject.parseObject(obj.toString());
  466. depotList.add(object.getLong("id"));
  467. }
  468. //如果有权限的仓库数量太多则提示要选择仓库
  469. if(depotList.size()>20) {
  470. throw new BusinessRunTimeException(ExceptionConstants.REPORT_TWO_MANY_DEPOT_FAILED_CODE,
  471. ExceptionConstants.REPORT_TWO_MANY_DEPOT_FAILED_MSG);
  472. }
  473. }
  474. return depotList;
  475. }
  476. /**
  477. * 采购统计
  478. * @param currentPage
  479. * @param pageSize
  480. * @param beginTime
  481. * @param endTime
  482. * @param materialParam
  483. * @param mpList
  484. * @param request
  485. * @return
  486. */
  487. @GetMapping(value = "/buyIn")
  488. @ApiOperation(value = "采购统计")
  489. public BaseResponseInfo buyIn(@RequestParam("currentPage") Integer currentPage,
  490. @RequestParam("pageSize") Integer pageSize,
  491. @RequestParam("beginTime") String beginTime,
  492. @RequestParam("endTime") String endTime,
  493. @RequestParam(value = "organId", required = false) Long organId,
  494. @RequestParam(value = "depotId", required = false) Long depotId,
  495. @RequestParam(value = "categoryId", required = false) Long categoryId,
  496. @RequestParam(value = "organizationId", required = false) Long organizationId,
  497. @RequestParam("materialParam") String materialParam,
  498. @RequestParam("mpList") String mpList,
  499. HttpServletRequest request)throws Exception {
  500. BaseResponseInfo res = new BaseResponseInfo();
  501. Map<String, Object> map = new HashMap<String, Object>();
  502. beginTime = Tools.parseDayToTime(beginTime, BusinessConstants.DAY_FIRST_TIME);
  503. endTime = Tools.parseDayToTime(endTime,BusinessConstants.DAY_LAST_TIME);
  504. try {
  505. String [] creatorArray = depotHeadService.getCreatorArray();
  506. if(creatorArray == null && organizationId != null) {
  507. creatorArray = depotHeadService.getCreatorArrayByOrg(organizationId);
  508. }
  509. String [] organArray = null;
  510. List<Long> categoryList = new ArrayList<>();
  511. if(categoryId != null){
  512. categoryList = materialService.getListByParentId(categoryId);
  513. }
  514. List<Long> depotList = depotService.parseDepotList(depotId);
  515. Boolean forceFlag = systemConfigService.getForceApprovalFlag();
  516. List<DepotItemVo4WithInfoEx> dataList = depotItemService.getListWithBuyOrSale(StringUtil.toNull(materialParam),
  517. "buy", beginTime, endTime, creatorArray, organId, organArray, categoryList, depotList, forceFlag, (currentPage-1)*pageSize, pageSize);
  518. String[] mpArr = mpList.split(",");
  519. int total = depotItemService.getListWithBuyOrSaleCount(StringUtil.toNull(materialParam),
  520. "buy", beginTime, endTime, creatorArray, organId, organArray, categoryList, depotList, forceFlag);
  521. map.put("total", total);
  522. //存放数据json数组
  523. JSONArray dataArray = new JSONArray();
  524. if (null != dataList) {
  525. for (DepotItemVo4WithInfoEx diEx : dataList) {
  526. JSONObject item = new JSONObject();
  527. BigDecimal InSum = depotItemService.buyOrSale("入库", "采购", diEx.getMId(), beginTime, endTime, creatorArray, organId, organArray, depotList, forceFlag, "number");
  528. BigDecimal OutSum = depotItemService.buyOrSale("出库", "采购退货", diEx.getMId(), beginTime, endTime, creatorArray, organId, organArray, depotList, forceFlag, "number");
  529. BigDecimal InSumPrice = depotItemService.buyOrSale("入库", "采购", diEx.getMId(), beginTime, endTime, creatorArray, organId, organArray, depotList, forceFlag, "price");
  530. BigDecimal OutSumPrice = depotItemService.buyOrSale("出库", "采购退货", diEx.getMId(), beginTime, endTime, creatorArray, organId, organArray, depotList, forceFlag, "price");
  531. BigDecimal InOutSumPrice = InSumPrice.subtract(OutSumPrice);
  532. item.put("barCode", diEx.getBarCode());
  533. item.put("materialName", diEx.getMName());
  534. item.put("materialModel", diEx.getMModel());
  535. item.put("materialStandard", diEx.getMStandard());
  536. //扩展信息
  537. String materialOther = depotItemService.getOtherInfo(mpArr, diEx);
  538. item.put("materialOther", materialOther);
  539. item.put("materialColor", diEx.getMColor());
  540. item.put("materialBrand", diEx.getBrand());
  541. item.put("materialMfrs", diEx.getMMfrs());
  542. item.put("materialUnit", diEx.getMaterialUnit());
  543. item.put("unitName", diEx.getUnitName());
  544. item.put("inSum", InSum);
  545. item.put("outSum", OutSum);
  546. item.put("inSumPrice", InSumPrice);
  547. item.put("outSumPrice", OutSumPrice);
  548. item.put("inOutSumPrice",InOutSumPrice);//实际采购金额
  549. dataArray.add(item);
  550. }
  551. }
  552. BigDecimal inSumPriceTotal = depotItemService.buyOrSalePriceTotal("入库", "采购", StringUtil.toNull(materialParam),
  553. beginTime, endTime, creatorArray, organId, organArray, categoryList, depotList, forceFlag);
  554. BigDecimal outSumPriceTotal = depotItemService.buyOrSalePriceTotal("出库", "采购退货", StringUtil.toNull(materialParam),
  555. beginTime, endTime, creatorArray, organId, organArray, categoryList, depotList, forceFlag);
  556. BigDecimal realityPriceTotal = inSumPriceTotal.subtract(outSumPriceTotal);
  557. map.put("rows", dataArray);
  558. map.put("realityPriceTotal", realityPriceTotal);
  559. res.code = 200;
  560. res.data = map;
  561. } catch(Exception e){
  562. logger.error(e.getMessage(), e);
  563. res.code = 500;
  564. res.data = "获取数据失败";
  565. }
  566. return res;
  567. }
  568. /**
  569. * 零售统计
  570. * @param currentPage
  571. * @param pageSize
  572. * @param beginTime
  573. * @param endTime
  574. * @param materialParam
  575. * @param mpList
  576. * @param request
  577. * @return
  578. */
  579. @GetMapping(value = "/retailOut")
  580. @ApiOperation(value = "零售统计")
  581. public BaseResponseInfo retailOut(@RequestParam("currentPage") Integer currentPage,
  582. @RequestParam("pageSize") Integer pageSize,
  583. @RequestParam("beginTime") String beginTime,
  584. @RequestParam("endTime") String endTime,
  585. @RequestParam(value = "organId", required = false) Long organId,
  586. @RequestParam(value = "depotId", required = false) Long depotId,
  587. @RequestParam(value = "categoryId", required = false) Long categoryId,
  588. @RequestParam(value = "organizationId", required = false) Long organizationId,
  589. @RequestParam("materialParam") String materialParam,
  590. @RequestParam("mpList") String mpList,
  591. HttpServletRequest request)throws Exception {
  592. BaseResponseInfo res = new BaseResponseInfo();
  593. Map<String, Object> map = new HashMap<String, Object>();
  594. beginTime = Tools.parseDayToTime(beginTime, BusinessConstants.DAY_FIRST_TIME);
  595. endTime = Tools.parseDayToTime(endTime,BusinessConstants.DAY_LAST_TIME);
  596. try {
  597. String [] creatorArray = depotHeadService.getCreatorArray();
  598. if(creatorArray == null && organizationId != null) {
  599. creatorArray = depotHeadService.getCreatorArrayByOrg(organizationId);
  600. }
  601. String [] organArray = null;
  602. List<Long> categoryList = new ArrayList<>();
  603. if(categoryId != null){
  604. categoryList = materialService.getListByParentId(categoryId);
  605. }
  606. List<Long> depotList = depotService.parseDepotList(depotId);
  607. Boolean forceFlag = systemConfigService.getForceApprovalFlag();
  608. List<DepotItemVo4WithInfoEx> dataList = depotItemService.getListWithBuyOrSale(StringUtil.toNull(materialParam),
  609. "retail", beginTime, endTime, creatorArray, organId, organArray, categoryList, depotList, forceFlag, (currentPage-1)*pageSize, pageSize);
  610. String[] mpArr = mpList.split(",");
  611. int total = depotItemService.getListWithBuyOrSaleCount(StringUtil.toNull(materialParam),
  612. "retail", beginTime, endTime, creatorArray, organId, organArray, categoryList, depotList, forceFlag);
  613. map.put("total", total);
  614. //存放数据json数组
  615. JSONArray dataArray = new JSONArray();
  616. if (null != dataList) {
  617. for (DepotItemVo4WithInfoEx diEx : dataList) {
  618. JSONObject item = new JSONObject();
  619. BigDecimal OutSumRetail = depotItemService.buyOrSale("出库", "零售", diEx.getMId(), beginTime, endTime, creatorArray, organId, organArray, depotList, forceFlag, "number");
  620. BigDecimal InSumRetail = depotItemService.buyOrSale("入库", "零售退货", diEx.getMId(), beginTime, endTime, creatorArray, organId, organArray, depotList, forceFlag, "number");
  621. BigDecimal OutSumRetailPrice = depotItemService.buyOrSale("出库", "零售", diEx.getMId(), beginTime, endTime, creatorArray, organId, organArray, depotList, forceFlag, "price");
  622. BigDecimal InSumRetailPrice = depotItemService.buyOrSale("入库", "零售退货", diEx.getMId(), beginTime, endTime, creatorArray, organId, organArray, depotList, forceFlag, "price");
  623. BigDecimal OutInSumPrice = OutSumRetailPrice.subtract(InSumRetailPrice);
  624. item.put("barCode", diEx.getBarCode());
  625. item.put("materialName", diEx.getMName());
  626. item.put("materialModel", diEx.getMModel());
  627. item.put("materialStandard", diEx.getMStandard());
  628. //扩展信息
  629. String materialOther = depotItemService.getOtherInfo(mpArr, diEx);
  630. item.put("materialOther", materialOther);
  631. item.put("materialColor", diEx.getMColor());
  632. item.put("materialBrand", diEx.getBrand());
  633. item.put("materialMfrs", diEx.getMMfrs());
  634. item.put("materialUnit", diEx.getMaterialUnit());
  635. item.put("unitName", diEx.getUnitName());
  636. item.put("outSum", OutSumRetail);
  637. item.put("inSum", InSumRetail);
  638. item.put("outSumPrice", OutSumRetailPrice);
  639. item.put("inSumPrice", InSumRetailPrice);
  640. item.put("outInSumPrice",OutInSumPrice);//实际销售金额
  641. dataArray.add(item);
  642. }
  643. }
  644. BigDecimal outSumPriceTotal = depotItemService.buyOrSalePriceTotal("出库", "零售", StringUtil.toNull(materialParam),
  645. beginTime, endTime, creatorArray, organId, organArray, categoryList, depotList, forceFlag);
  646. BigDecimal inSumPriceTotal = depotItemService.buyOrSalePriceTotal("入库", "零售退货", StringUtil.toNull(materialParam),
  647. beginTime, endTime, creatorArray, organId, organArray, categoryList, depotList, forceFlag);
  648. BigDecimal realityPriceTotal = outSumPriceTotal.subtract(inSumPriceTotal);
  649. map.put("rows", dataArray);
  650. map.put("realityPriceTotal", realityPriceTotal);
  651. res.code = 200;
  652. res.data = map;
  653. } catch(Exception e){
  654. logger.error(e.getMessage(), e);
  655. res.code = 500;
  656. res.data = "获取数据失败";
  657. }
  658. return res;
  659. }
  660. /**
  661. * 销售统计
  662. * @param currentPage
  663. * @param pageSize
  664. * @param beginTime
  665. * @param endTime
  666. * @param materialParam
  667. * @param mpList
  668. * @param request
  669. * @return
  670. */
  671. @GetMapping(value = "/saleOut")
  672. @ApiOperation(value = "销售统计")
  673. public BaseResponseInfo saleOut(@RequestParam("currentPage") Integer currentPage,
  674. @RequestParam("pageSize") Integer pageSize,
  675. @RequestParam("beginTime") String beginTime,
  676. @RequestParam("endTime") String endTime,
  677. @RequestParam(value = "organId", required = false) Long organId,
  678. @RequestParam(value = "depotId", required = false) Long depotId,
  679. @RequestParam(value = "categoryId", required = false) Long categoryId,
  680. @RequestParam(value = "organizationId", required = false) Long organizationId,
  681. @RequestParam("materialParam") String materialParam,
  682. @RequestParam("mpList") String mpList,
  683. HttpServletRequest request)throws Exception {
  684. BaseResponseInfo res = new BaseResponseInfo();
  685. Map<String, Object> map = new HashMap<String, Object>();
  686. beginTime = Tools.parseDayToTime(beginTime, BusinessConstants.DAY_FIRST_TIME);
  687. endTime = Tools.parseDayToTime(endTime,BusinessConstants.DAY_LAST_TIME);
  688. try {
  689. String [] creatorArray = depotHeadService.getCreatorArray();
  690. if(creatorArray == null && organizationId != null) {
  691. creatorArray = depotHeadService.getCreatorArrayByOrg(organizationId);
  692. }
  693. String [] organArray = depotHeadService.getOrganArray("销售", "");
  694. List<Long> categoryList = new ArrayList<>();
  695. if(categoryId != null){
  696. categoryList = materialService.getListByParentId(categoryId);
  697. }
  698. List<Long> depotList = depotService.parseDepotList(depotId);
  699. Boolean forceFlag = systemConfigService.getForceApprovalFlag();
  700. List<DepotItemVo4WithInfoEx> dataList = depotItemService.getListWithBuyOrSale(StringUtil.toNull(materialParam),
  701. "sale", beginTime, endTime, creatorArray, organId, organArray, categoryList, depotList, forceFlag, (currentPage-1)*pageSize, pageSize);
  702. String[] mpArr = mpList.split(",");
  703. int total = depotItemService.getListWithBuyOrSaleCount(StringUtil.toNull(materialParam),
  704. "sale", beginTime, endTime, creatorArray, organId, organArray, categoryList, depotList, forceFlag);
  705. map.put("total", total);
  706. //存放数据json数组
  707. JSONArray dataArray = new JSONArray();
  708. if (null != dataList) {
  709. for (DepotItemVo4WithInfoEx diEx : dataList) {
  710. JSONObject item = new JSONObject();
  711. BigDecimal OutSum = depotItemService.buyOrSale("出库", "销售", diEx.getMId(), beginTime, endTime, creatorArray, organId, organArray, depotList, forceFlag, "number");
  712. BigDecimal InSum = depotItemService.buyOrSale("入库", "销售退货", diEx.getMId(), beginTime, endTime, creatorArray, organId, organArray, depotList, forceFlag, "number");
  713. BigDecimal OutSumPrice = depotItemService.buyOrSale("出库", "销售", diEx.getMId(), beginTime, endTime, creatorArray, organId, organArray, depotList, forceFlag, "price");
  714. BigDecimal InSumPrice = depotItemService.buyOrSale("入库", "销售退货", diEx.getMId(), beginTime, endTime, creatorArray, organId, organArray, depotList, forceFlag, "price");
  715. BigDecimal OutInSumPrice = OutSumPrice.subtract(InSumPrice);
  716. item.put("barCode", diEx.getBarCode());
  717. item.put("materialName", diEx.getMName());
  718. item.put("materialModel", diEx.getMModel());
  719. item.put("materialStandard", diEx.getMStandard());
  720. //扩展信息
  721. String materialOther = depotItemService.getOtherInfo(mpArr, diEx);
  722. item.put("materialOther", materialOther);
  723. item.put("materialColor", diEx.getMColor());
  724. item.put("materialBrand", diEx.getBrand());
  725. item.put("materialMfrs", diEx.getMMfrs());
  726. item.put("materialUnit", diEx.getMaterialUnit());
  727. item.put("unitName", diEx.getUnitName());
  728. item.put("outSum", OutSum);
  729. item.put("inSum", InSum);
  730. item.put("outSumPrice", OutSumPrice);
  731. item.put("inSumPrice", InSumPrice);
  732. item.put("outInSumPrice",OutInSumPrice);//实际销售金额
  733. dataArray.add(item);
  734. }
  735. }
  736. BigDecimal outSumPriceTotal = depotItemService.buyOrSalePriceTotal("出库", "销售", StringUtil.toNull(materialParam),
  737. beginTime, endTime, creatorArray, organId, organArray, categoryList, depotList, forceFlag);
  738. BigDecimal inSumPriceTotal = depotItemService.buyOrSalePriceTotal("入库", "销售退货", StringUtil.toNull(materialParam),
  739. beginTime, endTime, creatorArray, organId, organArray, categoryList, depotList, forceFlag);
  740. BigDecimal realityPriceTotal = outSumPriceTotal.subtract(inSumPriceTotal);
  741. map.put("rows", dataArray);
  742. map.put("realityPriceTotal", realityPriceTotal);
  743. res.code = 200;
  744. res.data = map;
  745. } catch(Exception e){
  746. logger.error(e.getMessage(), e);
  747. res.code = 500;
  748. res.data = "获取数据失败";
  749. }
  750. return res;
  751. }
  752. /**
  753. * 获取单位
  754. * @param materialUnit
  755. * @param uName
  756. * @return
  757. */
  758. public String getUName(String materialUnit, String uName) {
  759. String unitName = null;
  760. if(StringUtil.isNotEmpty(materialUnit)) {
  761. unitName = materialUnit;
  762. } else if(StringUtil.isNotEmpty(uName)) {
  763. unitName = uName;
  764. }
  765. return unitName;
  766. }
  767. /**
  768. * 库存预警报表
  769. * @param currentPage
  770. * @param pageSize
  771. * @return
  772. */
  773. @GetMapping(value = "/findStockWarningCount")
  774. @ApiOperation(value = "库存预警报表")
  775. public BaseResponseInfo findStockWarningCount(@RequestParam("currentPage") Integer currentPage,
  776. @RequestParam("pageSize") Integer pageSize,
  777. @RequestParam("materialParam") String materialParam,
  778. @RequestParam(value = "depotId", required = false) Long depotId,
  779. @RequestParam(value = "categoryId", required = false) Long categoryId,
  780. @RequestParam("mpList") String mpList)throws Exception {
  781. BaseResponseInfo res = new BaseResponseInfo();
  782. Map<String, Object> map = new HashMap<String, Object>();
  783. try {
  784. List<Long> depotList = new ArrayList<>();
  785. if(depotId != null) {
  786. depotList.add(depotId);
  787. } else {
  788. //未选择仓库时默认为当前用户有权限的仓库
  789. JSONArray depotArr = depotService.findDepotByCurrentUser();
  790. for(Object obj: depotArr) {
  791. JSONObject object = JSONObject.parseObject(obj.toString());
  792. depotList.add(object.getLong("id"));
  793. }
  794. }
  795. List<Long> categoryList = new ArrayList<>();
  796. if(categoryId != null){
  797. categoryList = materialService.getListByParentId(categoryId);
  798. }
  799. String[] mpArr = mpList.split(",");
  800. List<DepotItemStockWarningCount> list = depotItemService.findStockWarningCount((currentPage-1)*pageSize, pageSize, materialParam, depotList, categoryList);
  801. //存放数据json数组
  802. if (null != list) {
  803. for (DepotItemStockWarningCount disw : list) {
  804. DepotItemVo4WithInfoEx diEx = new DepotItemVo4WithInfoEx();
  805. diEx.setMOtherField1(disw.getMOtherField1());
  806. diEx.setMOtherField2(disw.getMOtherField2());
  807. diEx.setMOtherField3(disw.getMOtherField3());
  808. disw.setMaterialOther(depotItemService.getOtherInfo(mpArr, diEx));
  809. disw.setMaterialUnit(getUName(disw.getMaterialUnit(), disw.getUnitName()));
  810. if(null!=disw.getLowSafeStock() && disw.getCurrentNumber().compareTo(disw.getLowSafeStock())<0) {
  811. disw.setLowCritical(disw.getLowSafeStock().subtract(disw.getCurrentNumber()));
  812. }
  813. if(null!=disw.getHighSafeStock() && disw.getCurrentNumber().compareTo(disw.getHighSafeStock())>0) {
  814. disw.setHighCritical(disw.getCurrentNumber().subtract(disw.getHighSafeStock()));
  815. }
  816. }
  817. }
  818. int total = depotItemService.findStockWarningCountTotal(materialParam, depotList, categoryList);
  819. map.put("total", total);
  820. map.put("rows", list);
  821. res.code = 200;
  822. res.data = map;
  823. } catch(Exception e){
  824. logger.error(e.getMessage(), e);
  825. res.code = 500;
  826. res.data = "获取数据失败";
  827. }
  828. return res;
  829. }
  830. /**
  831. * 统计采购、销售、零售的总金额
  832. * @param request
  833. * @param response
  834. * @return
  835. * @throws Exception
  836. */
  837. @GetMapping(value = "/buyOrSalePrice")
  838. @ApiOperation(value = "统计采购、销售、零售的总金额")
  839. public BaseResponseInfo buyOrSalePrice(HttpServletRequest request,
  840. HttpServletResponse response)throws Exception {
  841. BaseResponseInfo res = new BaseResponseInfo();
  842. try {
  843. Map<String, Object> map = new HashMap<>();
  844. String loginName = userService.getCurrentUser().getLoginName();
  845. if(!"admin".equals(loginName)) {
  846. Long userId = userService.getUserId(request);
  847. List<String> monthList = Tools.getLastMonths(6);
  848. String beginTime = Tools.firstDayOfMonth(monthList.get(0)) + BusinessConstants.DAY_FIRST_TIME;
  849. String endTime = Tools.getNow() + BusinessConstants.DAY_LAST_TIME;
  850. List<InOutPriceVo> inOrOutPriceList = depotItemService.inOrOutPriceList(beginTime, endTime);
  851. String priceLimit = userService.getRoleTypeByUserId(userId).getPriceLimit();
  852. JSONArray buyPriceList = new JSONArray();
  853. for (String month : monthList) {
  854. JSONObject obj = new JSONObject();
  855. BigDecimal outPrice = BigDecimal.ZERO;
  856. BigDecimal inPrice = BigDecimal.ZERO;
  857. for (InOutPriceVo item : inOrOutPriceList) {
  858. String billOperMonth = Tools.dateToStr(item.getOperTime(), "yyyy-MM");
  859. if (month.equals(billOperMonth)) {
  860. if ("入库".equals(item.getType()) && "采购".equals(item.getSubType())) {
  861. outPrice = outPrice.add(item.getDiscountLastMoney());
  862. }
  863. if ("出库".equals(item.getType()) && "采购退货".equals(item.getSubType())) {
  864. inPrice = inPrice.add(item.getDiscountLastMoney());
  865. }
  866. }
  867. }
  868. obj.put("x", month);
  869. obj.put("y", roleService.parseHomePriceByLimit(outPrice.subtract(inPrice), "buy", priceLimit, "***", request));
  870. buyPriceList.add(obj);
  871. }
  872. map.put("buyPriceList", buyPriceList);
  873. JSONArray salePriceList = new JSONArray();
  874. for (String month : monthList) {
  875. JSONObject obj = new JSONObject();
  876. BigDecimal outPrice = BigDecimal.ZERO;
  877. BigDecimal inPrice = BigDecimal.ZERO;
  878. for (InOutPriceVo item : inOrOutPriceList) {
  879. String billOperMonth = Tools.dateToStr(item.getOperTime(), "yyyy-MM");
  880. if (month.equals(billOperMonth)) {
  881. if ("出库".equals(item.getType()) && "销售".equals(item.getSubType())) {
  882. outPrice = outPrice.add(item.getDiscountLastMoney());
  883. }
  884. if ("入库".equals(item.getType()) && "销售退货".equals(item.getSubType())) {
  885. inPrice = inPrice.add(item.getDiscountLastMoney());
  886. }
  887. }
  888. }
  889. obj.put("x", month);
  890. obj.put("y", roleService.parseHomePriceByLimit(outPrice.subtract(inPrice), "sale", priceLimit, "***", request));
  891. salePriceList.add(obj);
  892. }
  893. map.put("salePriceList", salePriceList);
  894. JSONArray retailPriceList = new JSONArray();
  895. for (String month : monthList) {
  896. JSONObject obj = new JSONObject();
  897. BigDecimal outPrice = BigDecimal.ZERO;
  898. BigDecimal inPrice = BigDecimal.ZERO;
  899. for (InOutPriceVo item : inOrOutPriceList) {
  900. String billOperMonth = Tools.dateToStr(item.getOperTime(), "yyyy-MM");
  901. if (month.equals(billOperMonth)) {
  902. if ("出库".equals(item.getType()) && "零售".equals(item.getSubType())) {
  903. outPrice = outPrice.add(item.getTotalPrice().abs());
  904. }
  905. if ("入库".equals(item.getType()) && "零售退货".equals(item.getSubType())) {
  906. inPrice = inPrice.add(item.getTotalPrice().abs());
  907. }
  908. }
  909. }
  910. obj.put("x", month);
  911. obj.put("y", roleService.parseHomePriceByLimit(outPrice.subtract(inPrice), "retail", priceLimit, "***", request));
  912. retailPriceList.add(obj);
  913. }
  914. map.put("retailPriceList", retailPriceList);
  915. }
  916. res.code = 200;
  917. res.data = map;
  918. } catch (Exception e) {
  919. logger.error(e.getMessage(), e);
  920. res.code = 500;
  921. res.data = "统计失败";
  922. }
  923. return res;
  924. }
  925. /**
  926. * 获取批次商品列表信息
  927. * @param request
  928. * @return
  929. */
  930. @GetMapping(value = "/getBatchNumberList")
  931. @ApiOperation(value = "获取批次商品列表信息")
  932. public BaseResponseInfo getBatchNumberList(@RequestParam("name") String name,
  933. @RequestParam("depotItemId") Long depotItemId,
  934. @RequestParam("barCode") String barCode,
  935. @RequestParam(value = "batchNumber", required = false) String batchNumber,
  936. HttpServletRequest request) throws Exception{
  937. BaseResponseInfo res = new BaseResponseInfo();
  938. Map<String, Object> map = new HashMap<>();
  939. try {
  940. String number = "";
  941. if(depotItemId != null) {
  942. DepotItem depotItem = depotItemService.getDepotItem(depotItemId);
  943. number = depotHeadService.getDepotHead(depotItem.getHeaderId()).getNumber();
  944. }
  945. Boolean forceFlag = systemConfigService.getForceApprovalFlag();
  946. Boolean inOutManageFlag = systemConfigService.getInOutManageFlag();
  947. List<DepotItemVoBatchNumberList> list = depotItemService.getBatchNumberList(number, name, null, barCode,
  948. batchNumber, forceFlag, inOutManageFlag);
  949. map.put("rows", list);
  950. map.put("total", list.size());
  951. res.code = 200;
  952. res.data = map;
  953. } catch (Exception e) {
  954. logger.error(e.getMessage(), e);
  955. res.code = 500;
  956. res.data = "获取数据失败";
  957. }
  958. return res;
  959. }
  960. /**
  961. * Excel导入明细
  962. * @param file
  963. * @param request
  964. * @param response
  965. * @return
  966. */
  967. @PostMapping(value = "/importItemExcel")
  968. public BaseResponseInfo importItemExcel(MultipartFile file,
  969. @RequestParam(required = false, value = "prefixNo") String prefixNo,
  970. HttpServletRequest request, HttpServletResponse response) throws Exception{
  971. BaseResponseInfo res = new BaseResponseInfo();
  972. Map<String, Object> data = new HashMap<>();
  973. String message = "";
  974. try {
  975. String batchNumbers = "";
  976. //文件合法性校验
  977. Sheet src = null;
  978. try {
  979. Workbook workbook = Workbook.getWorkbook(file.getInputStream());
  980. src = workbook.getSheet(0);
  981. } catch (Exception e) {
  982. message = "导入文件不合法,请检查";
  983. data.put("message", message);
  984. res.code = 400;
  985. res.data = data;
  986. }
  987. if(src.getRows()>1000) {
  988. message = "导入失败,明细不能超出1000条";
  989. res.code = 500;
  990. data.put("message", message);
  991. res.data = data;
  992. } else {
  993. List<Map<String, String>> detailList = new ArrayList<>();
  994. for (int i = 2; i < src.getRows(); i++) {
  995. String depotName = "", batchNumber = "", num = "", unitPrice = "", taxRate = "", remark = "";
  996. if("QGD".equals(prefixNo)) {
  997. batchNumber = ExcelUtils.getContent(src, i, 0);
  998. num = ExcelUtils.getContent(src, i, 2);
  999. remark = ExcelUtils.getContent(src, i, 3);
  1000. }
  1001. if("CGDD".equals(prefixNo) || "XSDD".equals(prefixNo)) {
  1002. batchNumber = ExcelUtils.getContent(src, i, 0);
  1003. num = ExcelUtils.getContent(src, i, 2);
  1004. unitPrice = ExcelUtils.getContent(src, i, 3);
  1005. taxRate = ExcelUtils.getContent(src, i, 4);
  1006. remark = ExcelUtils.getContent(src, i, 5);
  1007. }
  1008. if("CGRK".equals(prefixNo) || "XSCK".equals(prefixNo)) {
  1009. //采购入库
  1010. depotName = ExcelUtils.getContent(src, i, 0);
  1011. batchNumber = ExcelUtils.getContent(src, i, 1);
  1012. num = ExcelUtils.getContent(src, i, 3);
  1013. unitPrice = ExcelUtils.getContent(src, i, 4);
  1014. taxRate = ExcelUtils.getContent(src, i, 5);
  1015. remark = ExcelUtils.getContent(src, i, 6);
  1016. }
  1017. if("QTRK".equals(prefixNo) || "QTCK".equals(prefixNo)) {
  1018. depotName = ExcelUtils.getContent(src, i, 0);
  1019. batchNumber = ExcelUtils.getContent(src, i, 1);
  1020. num = ExcelUtils.getContent(src, i, 3);
  1021. unitPrice = ExcelUtils.getContent(src, i, 4);
  1022. remark = ExcelUtils.getContent(src, i, 5);
  1023. }
  1024. Map<String, String> materialMap = new HashMap<>();
  1025. materialMap.put("depotName", depotName);
  1026. materialMap.put("batchNumber", batchNumber);
  1027. materialMap.put("num", num);
  1028. materialMap.put("unitPrice", unitPrice);
  1029. materialMap.put("taxRate", taxRate);
  1030. materialMap.put("remark", remark);
  1031. detailList.add(materialMap);
  1032. batchNumbers += "'" + batchNumber + "',";
  1033. }
  1034. if (StringUtil.isNotEmpty(batchNumbers)) {
  1035. batchNumbers = batchNumbers.substring(0, batchNumbers.length() - 1);
  1036. }
  1037. JSONObject map = depotItemService.parseMapByExcelData(batchNumbers, detailList, prefixNo);
  1038. if (map != null) {
  1039. res.code = 200;
  1040. } else {
  1041. res.code = 500;
  1042. }
  1043. res.data = map;
  1044. }
  1045. } catch (BusinessRunTimeException e) {
  1046. res.code = 500;
  1047. data.put("message", e.getData().get("message"));
  1048. res.data = data;
  1049. } catch (Exception e) {
  1050. logger.error(e.getMessage(), e);
  1051. message = "导入失败,请检查表格内容";
  1052. res.code = 500;
  1053. data.put("message", message);
  1054. res.data = data;
  1055. }
  1056. return res;
  1057. }
  1058. }