DepotItemController.java 71 KB

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