DepotItemController.java 58 KB

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