DepotItemServiceImpl.java 89 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764
  1. package com.jsh.erp.service.impl;
  2. import com.alibaba.fastjson.JSONArray;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  5. import com.jsh.erp.constants.BusinessConstants;
  6. import com.jsh.erp.constants.ExceptionConstants;
  7. import com.jsh.erp.datasource.dto.DepotItemDTO;
  8. import com.jsh.erp.datasource.entities.*;
  9. import com.jsh.erp.datasource.mappers.*;
  10. import com.jsh.erp.datasource.pda.vo.PDADepotItemVO;
  11. import com.jsh.erp.datasource.pda.vo.PDAPrintVo;
  12. import com.jsh.erp.datasource.vo.DepotHeadXsddRequestVO;
  13. import com.jsh.erp.datasource.vo.DepotItemStockWarningCount;
  14. import com.jsh.erp.datasource.vo.DepotItemVo4Stock;
  15. import com.jsh.erp.datasource.vo.DepotItemVoBatchNumberList;
  16. import com.jsh.erp.datasource.vo.DepotItemXsddRequestVO;
  17. import com.jsh.erp.datasource.vo.InOutPriceVo;
  18. import com.jsh.erp.exception.BusinessRunTimeException;
  19. import com.jsh.erp.exception.JshException;
  20. import com.jsh.erp.query.LambdaQueryWrapperX;
  21. import com.jsh.erp.service.*;
  22. import com.jsh.erp.utils.StringUtil;
  23. import com.jsh.erp.utils.Tools;
  24. import org.slf4j.Logger;
  25. import org.slf4j.LoggerFactory;
  26. import org.springframework.beans.BeanUtils;
  27. import org.springframework.stereotype.Service;
  28. import org.springframework.transaction.annotation.Transactional;
  29. import javax.annotation.Resource;
  30. import javax.servlet.http.HttpServletRequest;
  31. import java.math.BigDecimal;
  32. import java.util.*;
  33. @Service
  34. public class DepotItemServiceImpl extends ServiceImpl<DepotItemMapper, DepotItem> implements DepotItemService {
  35. private Logger logger = LoggerFactory.getLogger(DepotItemServiceImpl.class);
  36. private final static String TYPE = "入库";
  37. private final static String SUM_TYPE = "number";
  38. private final static String IN = "in";
  39. private final static String OUT = "out";
  40. @Resource
  41. private DepotItemMapper depotItemMapper;
  42. @Resource
  43. private DepotItemMapperEx depotItemMapperEx;
  44. @Resource
  45. private MaterialService materialService;
  46. @Resource
  47. private MaterialExtendService materialExtendService;
  48. @Resource
  49. private DepotHeadService depotHeadService;
  50. @Resource
  51. private DepotHeadMapper depotHeadMapper;
  52. @Resource
  53. private SerialNumberService serialNumberService;
  54. @Resource
  55. private UserService userService;
  56. @Resource
  57. private SystemConfigService systemConfigService;
  58. @Resource
  59. private DepotService depotService;
  60. @Resource
  61. private UnitService unitService;
  62. @Resource
  63. private MaterialCurrentStockMapper materialCurrentStockMapper;
  64. @Resource
  65. private MaterialCurrentStockMapperEx materialCurrentStockMapperEx;
  66. @Resource
  67. private SyncTescoSystemService syncTescoSystemService;
  68. @Resource
  69. private MaterialBatchService materialBatchService;
  70. /**
  71. * pda根据订单信息查询商品列表
  72. * @return
  73. */
  74. @Override
  75. public List<PDADepotItemVO> pdaList(Long id) throws Exception {
  76. List<PDADepotItemVO> list = depotItemMapper.pdaList(id);
  77. for (PDADepotItemVO pdaDepotItemVO : list) {
  78. Unit unitInfo = materialService.findUnit(pdaDepotItemVO.getMaterialId()); //查询多单位信息
  79. pdaDepotItemVO.setActualQuantityInStorage(this.getFinishNumber(pdaDepotItemVO.getMaterialExtendId(), pdaDepotItemVO.getId(), pdaDepotItemVO.getHeaderId(), unitInfo, pdaDepotItemVO.getMaterialUnit(), "basic").toString());
  80. BigDecimal stock;
  81. if (unitInfo != null && unitInfo.getId() != null){
  82. stock = unitService.parseStockByUnit(materialService.getCurrentStockByMaterialIdAndDepotId(pdaDepotItemVO.getMaterialId(),pdaDepotItemVO.getDepotId()),unitInfo,pdaDepotItemVO.getCommodityUnit());
  83. }else {
  84. stock = materialService.getCurrentStockByMaterialIdAndDepotId(pdaDepotItemVO.getMaterialId(),pdaDepotItemVO.getDepotId());
  85. }
  86. pdaDepotItemVO.setInventory(stock.toString());
  87. }
  88. return list;
  89. }
  90. /**
  91. * pda根据商品订单ID查询商品详情
  92. * @param id 商品订单ID
  93. * @return
  94. */
  95. @Override
  96. public PDADepotItemVO pdaDetail(Long id, Long depotId) throws Exception {
  97. PDADepotItemVO itemVO = depotItemMapper.pdaDetail(id);
  98. Unit unitInfo = materialService.findUnit(itemVO.getMaterialId()); //查询多单位信息
  99. BigDecimal stock;
  100. if (unitInfo != null && unitInfo.getId() != null){
  101. stock = unitService.parseStockByUnit(materialService.getCurrentStockByMaterialIdAndDepotId(itemVO.getMaterialId(),depotId),unitInfo,itemVO.getMaterialUnit());
  102. }else {
  103. stock = materialService.getCurrentStockByMaterialIdAndDepotId(itemVO.getMaterialId(),depotId);
  104. }
  105. itemVO.setInventory(stock.toString());
  106. return itemVO;
  107. }
  108. /**
  109. * 出入库明细列表
  110. * @param type 查询类型
  111. * @param materialId 商品ID
  112. * @param depotId 仓库ID
  113. */
  114. @Override
  115. public List<PDADepotItemVO> materialDepotDetail(String type , Long materialId, Long depotId) {
  116. return depotItemMapper.materialDepotDetail(type, materialId,depotId);
  117. }
  118. /**
  119. * pda 获取商品打印条码信息
  120. * @param depotItemId 单据子表id
  121. * @return
  122. */
  123. @Override
  124. public PDAPrintVo pdaPrintMaterial(Long depotItemId) {
  125. return depotItemMapper.pdaPrintMaterial(depotItemId);
  126. }
  127. /**
  128. * 根据id获取单据子表信息
  129. */
  130. @Override
  131. public DepotItem getDepotItem(long id) {
  132. DepotItem result=null;
  133. try{
  134. result=depotItemMapper.selectByPrimaryKey(id);
  135. }catch(Exception e){
  136. JshException.readFail(logger, e);
  137. }
  138. return result;
  139. }
  140. @Override
  141. public List<DepotItem> getDepotItem()throws Exception {
  142. DepotItemExample example = new DepotItemExample();
  143. example.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
  144. List<DepotItem> list=null;
  145. try{
  146. list=depotItemMapper.selectByExample(example);
  147. }catch(Exception e){
  148. JshException.readFail(logger, e);
  149. }
  150. return list;
  151. }
  152. @Override
  153. public List<DepotItem> select(String name, Integer type, String remark, int offset, int rows)throws Exception {
  154. List<DepotItem> list=null;
  155. try{
  156. list=depotItemMapperEx.selectByConditionDepotItem(name, type, remark, offset, rows);
  157. }catch(Exception e){
  158. JshException.readFail(logger, e);
  159. }
  160. return list;
  161. }
  162. public Long countDepotItem(String name, Integer type, String remark) throws Exception{
  163. Long result =null;
  164. try{
  165. result=depotItemMapperEx.countsByDepotItem(name, type, remark);
  166. }catch(Exception e){
  167. JshException.readFail(logger, e);
  168. }
  169. return result;
  170. }
  171. @Override
  172. @Transactional(value = "transactionManager", rollbackFor = Exception.class)
  173. public int insertDepotItem(JSONObject obj, HttpServletRequest request)throws Exception {
  174. DepotItem depotItem = JSONObject.parseObject(obj.toJSONString(), DepotItem.class);
  175. int result =0;
  176. try{
  177. result=depotItemMapper.insertSelective(depotItem);
  178. }catch(Exception e){
  179. JshException.readFail(logger, e);
  180. }
  181. return result;
  182. }
  183. @Override
  184. @Transactional(value = "transactionManager", rollbackFor = Exception.class)
  185. public int updateDepotItem(JSONObject obj, HttpServletRequest request)throws Exception {
  186. DepotItem depotItem = JSONObject.parseObject(obj.toJSONString(), DepotItem.class);
  187. int result =0;
  188. try{
  189. result=depotItemMapper.updateByPrimaryKeySelective(depotItem);
  190. }catch(Exception e){
  191. JshException.readFail(logger, e);
  192. }
  193. return result;
  194. }
  195. @Override
  196. @Transactional(value = "transactionManager", rollbackFor = Exception.class)
  197. public int deleteDepotItem(Long id, HttpServletRequest request)throws Exception {
  198. int result =0;
  199. try{
  200. result=depotItemMapper.deleteByPrimaryKey(id);
  201. }catch(Exception e){
  202. JshException.writeFail(logger, e);
  203. }
  204. return result;
  205. }
  206. @Override
  207. @Transactional(value = "transactionManager", rollbackFor = Exception.class)
  208. public int batchDeleteDepotItem(String ids, HttpServletRequest request)throws Exception {
  209. List<Long> idList = StringUtil.strToLongList(ids);
  210. DepotItemExample example = new DepotItemExample();
  211. example.createCriteria().andIdIn(idList);
  212. int result =0;
  213. try{
  214. result=depotItemMapper.deleteByExample(example);
  215. }catch(Exception e){
  216. JshException.writeFail(logger, e);
  217. }
  218. return result;
  219. }
  220. @Override
  221. public int checkIsNameExist(Long id, String name)throws Exception {
  222. DepotItemExample example = new DepotItemExample();
  223. example.createCriteria().andIdNotEqualTo(id).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
  224. List<DepotItem> list =null;
  225. try{
  226. list=depotItemMapper.selectByExample(example);
  227. }catch(Exception e){
  228. JshException.readFail(logger, e);
  229. }
  230. return list==null?0:list.size();
  231. }
  232. @Override
  233. public List<DepotItemVo4DetailByTypeAndMId> findDetailByDepotIdsAndMaterialIdList(String depotIds, Boolean forceFlag, Boolean inOutManageFlag, String sku, String batchNumber,
  234. String number, String beginTime, String endTime, Long mId, Integer offset, Integer rows)throws Exception {
  235. Long depotId = null;
  236. if(StringUtil.isNotEmpty(depotIds)) {
  237. depotId = Long.parseLong(depotIds);
  238. }
  239. List<Long> depotList = depotService.parseDepotList(depotId);
  240. Long[] depotIdArray = StringUtil.listToLongArray(depotList);
  241. List<DepotItemVo4DetailByTypeAndMId> list =null;
  242. try{
  243. list = depotItemMapperEx.findDetailByDepotIdsAndMaterialIdList(depotIdArray, forceFlag, inOutManageFlag, sku, batchNumber, number, beginTime, endTime, mId, offset, rows);
  244. }catch(Exception e){
  245. JshException.readFail(logger, e);
  246. }
  247. return list;
  248. }
  249. @Override
  250. public Long findDetailByDepotIdsAndMaterialIdCount(String depotIds, Boolean forceFlag, Boolean inOutManageFlag, String sku, String batchNumber,
  251. String number, String beginTime, String endTime, Long mId)throws Exception {
  252. Long depotId = null;
  253. if(StringUtil.isNotEmpty(depotIds)) {
  254. depotId = Long.parseLong(depotIds);
  255. }
  256. List<Long> depotList = depotService.parseDepotList(depotId);
  257. Long[] depotIdArray = StringUtil.listToLongArray(depotList);
  258. Long result =null;
  259. try{
  260. result = depotItemMapperEx.findDetailByDepotIdsAndMaterialIdCount(depotIdArray, forceFlag, inOutManageFlag, sku, batchNumber, number, beginTime, endTime, mId);
  261. }catch(Exception e){
  262. JshException.readFail(logger, e);
  263. }
  264. return result;
  265. }
  266. /**
  267. * 添加单据子表
  268. * @param depotItem 单据子表
  269. * @return
  270. * @throws Exception
  271. */
  272. @Override
  273. @Transactional(value = "transactionManager", rollbackFor = Exception.class)
  274. public int insertDepotItemWithObj(DepotItem depotItem) {
  275. User user = userService.getCurrentUser();
  276. //创建时间
  277. depotItem.setCreateTime(new Date());
  278. int result =0;
  279. try{
  280. result = depotItemMapper.insertSelective(depotItem);
  281. }catch(Exception e){
  282. JshException.writeFail(logger, e);
  283. }
  284. return result;
  285. }
  286. public int insertDepotItem(DepotItem depotItem)throws Exception {
  287. int result =0;
  288. try{
  289. depotItemMapper.insertSelective(depotItem);
  290. }catch(Exception e){
  291. JshException.readFail(logger, e);
  292. }
  293. return result;
  294. }
  295. @Override
  296. @Transactional(value = "transactionManager", rollbackFor = Exception.class)
  297. public int updateDepotItemWithObj(DepotItem depotItem)throws Exception {
  298. int result =0;
  299. try{
  300. result = depotItemMapper.updateByPrimaryKeySelective(depotItem);
  301. }catch(Exception e){
  302. JshException.writeFail(logger, e);
  303. }
  304. return result;
  305. }
  306. @Override
  307. public List<DepotItem> getListByHeaderId(Long headerId) {
  308. List<DepotItem> list =null;
  309. try{
  310. DepotItemExample example = new DepotItemExample();
  311. example.createCriteria().andHeaderIdEqualTo(headerId).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
  312. list = depotItemMapper.selectByExample(example);
  313. }catch(Exception e){
  314. JshException.readFail(logger, e);
  315. }
  316. return list;
  317. }
  318. /**
  319. * 查询当前单据中指定商品的明细信息
  320. * @param headerId
  321. * @param meId
  322. * @return
  323. * @throws Exception
  324. */
  325. @Override
  326. public DepotItem getItemByHeaderIdAndMaterial(Long headerId, Long meId)throws Exception {
  327. DepotItem depotItem = new DepotItem();
  328. try{
  329. DepotItemExample example = new DepotItemExample();
  330. example.createCriteria().andHeaderIdEqualTo(headerId).andMaterialExtendIdEqualTo(meId).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
  331. List<DepotItem> list = depotItemMapper.selectByExample(example);
  332. if(list!=null && list.size()>0) {
  333. depotItem = list.get(0);
  334. }
  335. }catch(Exception e){
  336. JshException.readFail(logger, e);
  337. }
  338. return depotItem;
  339. }
  340. /**
  341. * 查询被关联订单中指定商品的明细信息
  342. * @param linkStr
  343. * @param meId
  344. * @return
  345. * @throws Exception
  346. */
  347. @Override
  348. public DepotItem getPreItemByHeaderIdAndMaterial(String linkStr, Long meId, Long linkId) {
  349. DepotItem depotItem = new DepotItem();
  350. try{
  351. DepotHead depotHead = depotHeadService.getDepotHead(linkStr);
  352. if(null!=depotHead && null!=depotHead.getId()) {
  353. DepotItemExample example = new DepotItemExample();
  354. example.createCriteria().andHeaderIdEqualTo(depotHead.getId()).andMaterialExtendIdEqualTo(meId).andIdEqualTo(linkId).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
  355. List<DepotItem> list = depotItemMapper.selectByExample(example);
  356. if(list!=null && list.size()>0) {
  357. depotItem = list.get(0);
  358. }
  359. }
  360. }catch(Exception e){
  361. JshException.readFail(logger, e);
  362. }
  363. return depotItem;
  364. }
  365. @Override
  366. public List<DepotItemVo4WithInfoEx> getDetailList(Long headerId)throws Exception {
  367. List<DepotItemVo4WithInfoEx> list =null;
  368. try{
  369. list = depotItemMapperEx.getDetailList(headerId);
  370. }catch(Exception e){
  371. JshException.readFail(logger, e);
  372. }
  373. return list;
  374. }
  375. @Override
  376. public List<DepotItemVo4WithInfoEx> getInOutStock(String materialParam, List<Long> categoryIdList, String endTime, Integer offset, Integer rows)throws Exception {
  377. List<DepotItemVo4WithInfoEx> list =null;
  378. try{
  379. list = depotItemMapperEx.getInOutStock(materialParam, categoryIdList, endTime, offset, rows);
  380. }catch(Exception e){
  381. JshException.readFail(logger, e);
  382. }
  383. return list;
  384. }
  385. @Override
  386. public int getInOutStockCount(String materialParam, List<Long> categoryIdList, String endTime)throws Exception {
  387. int result=0;
  388. try{
  389. result = depotItemMapperEx.getInOutStockCount(materialParam, categoryIdList, endTime);
  390. }catch(Exception e){
  391. JshException.readFail(logger, e);
  392. }
  393. return result;
  394. }
  395. @Override
  396. public List<DepotItemVo4WithInfoEx> getListWithBuyOrSale(String materialParam, String billType,
  397. String beginTime, String endTime, String[] creatorArray, Long organId, String[] organArray, List<Long> categoryList, List<Long> depotList, Boolean forceFlag, Integer offset, Integer rows)throws Exception {
  398. List<DepotItemVo4WithInfoEx> list =null;
  399. try{
  400. list = depotItemMapperEx.getListWithBuyOrSale(materialParam, billType, beginTime, endTime, creatorArray, organId, organArray, categoryList, depotList, forceFlag, offset, rows);
  401. }catch(Exception e){
  402. JshException.readFail(logger, e);
  403. }
  404. return list;
  405. }
  406. @Override
  407. public int getListWithBuyOrSaleCount(String materialParam, String billType,
  408. String beginTime, String endTime, String[] creatorArray, Long organId, String[] organArray, List<Long> categoryList, List<Long> depotList, Boolean forceFlag)throws Exception {
  409. int result=0;
  410. try{
  411. result = depotItemMapperEx.getListWithBuyOrSaleCount(materialParam, billType, beginTime, endTime, creatorArray, organId, organArray, categoryList, depotList, forceFlag);
  412. }catch(Exception e){
  413. JshException.readFail(logger, e);
  414. }
  415. return result;
  416. }
  417. @Override
  418. public BigDecimal buyOrSale(String type, String subType, Long MId, String beginTime, String endTime,
  419. String[] creatorArray, Long organId, String[] organArray, List<Long> depotList, Boolean forceFlag, String sumType) throws Exception{
  420. BigDecimal result= BigDecimal.ZERO;
  421. try{
  422. if (SUM_TYPE.equals(sumType)) {
  423. result= depotItemMapperEx.buyOrSaleNumber(type, subType, MId, beginTime, endTime, creatorArray, organId, organArray, depotList, forceFlag, sumType);
  424. } else {
  425. result= depotItemMapperEx.buyOrSalePrice(type, subType, MId, beginTime, endTime, creatorArray, organId, organArray, depotList, forceFlag, sumType);
  426. }
  427. }catch(Exception e){
  428. JshException.readFail(logger, e);
  429. }
  430. return result;
  431. }
  432. @Override
  433. public BigDecimal buyOrSalePriceTotal(String type, String subType, String materialParam, String beginTime, String endTime,
  434. String[] creatorArray, Long organId, String[] organArray, List<Long> categoryList, List<Long> depotList, Boolean forceFlag) throws Exception{
  435. BigDecimal result= BigDecimal.ZERO;
  436. try{
  437. result= depotItemMapperEx.buyOrSalePriceTotal(type, subType, materialParam, beginTime, endTime, creatorArray, organId, organArray, categoryList, depotList, forceFlag);
  438. }catch(Exception e){
  439. JshException.readFail(logger, e);
  440. }
  441. return result;
  442. }
  443. /**
  444. * 统计采购、销售、零售的总金额列表
  445. * @param beginTime
  446. * @param endTime
  447. * @return
  448. * @throws Exception
  449. */
  450. @Override
  451. public List<InOutPriceVo> inOrOutPriceList(String beginTime, String endTime) throws Exception{
  452. List<InOutPriceVo> result = new ArrayList<>();
  453. try{
  454. String [] creatorArray = depotHeadService.getCreatorArray();
  455. Boolean forceFlag = systemConfigService.getForceApprovalFlag();
  456. result = depotItemMapperEx.inOrOutPriceList(beginTime, endTime, creatorArray, forceFlag);
  457. }catch(Exception e){
  458. JshException.readFail(logger, e);
  459. }
  460. return result;
  461. }
  462. /**
  463. * 保存单据子表
  464. * @param rows 子表数据字符
  465. * @param headerId 单据主表id
  466. * @param actionType 操作类型
  467. */
  468. @Override
  469. @Transactional(value = "transactionManager", rollbackFor = Exception.class)
  470. public void saveDetails(String rows, Long headerId, String actionType, HttpServletRequest request) throws Exception{
  471. //查询单据主表信息
  472. DepotHead depotHead = depotHeadService.getDepotHead(headerId);
  473. //删除序列号和回收序列号
  474. deleteOrCancelSerialNumber(actionType, depotHead, headerId);
  475. //删除单据的明细
  476. deleteDepotItemHeadId(headerId);
  477. JSONArray rowArr = JSONArray.parseArray(rows);
  478. if (null != rowArr && rowArr.size()>0) {
  479. //针对组装单、拆卸单校验是否存在组合件和普通子件
  480. checkAssembleWithMaterialType(rowArr, depotHead.getSubType());
  481. for (int i = 0; i < rowArr.size(); i++) {
  482. JSONObject rowObj = JSONObject.parseObject(rowArr.getString(i));
  483. String barCode = rowObj.getString("sku");
  484. //根据条码获取商品信息
  485. MaterialExtend materialExtend = materialExtendService.getInfoBySku(barCode);
  486. if(materialExtend == null) {
  487. throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_BARCODE_IS_NOT_EXIST_CODE,
  488. String.format(ExceptionConstants.MATERIAL_BARCODE_IS_NOT_EXIST_MSG, barCode));
  489. }
  490. //设置单据子表属性
  491. DepotItem depotItem = new DepotItem();
  492. //主表id
  493. depotItem.setHeaderId(headerId);
  494. //商品id
  495. depotItem.setMaterialId(materialExtend.getMaterialId());
  496. //商品条码id
  497. depotItem.setMaterialExtendId(materialExtend.getId());
  498. //商品单位
  499. depotItem.setMaterialUnit(rowObj.getString("unit"));
  500. //实际出入库数量
  501. // depotItem.setActualQuantityInStorage(rowObj.getBigDecimal("actualQuantityInStorage"));
  502. //出入库差异
  503. // depotItem.setWarehousingVariance(rowObj.getBigDecimal("warehousingVariance"));
  504. //出入库差异原因
  505. // depotItem.setReasonOfDifference(rowObj.getString("reasonOfDifference"));
  506. //出入库用户
  507. depotItem.setWarehousingUser(rowObj.getLong("warehousingUser"));
  508. //出入库时间
  509. depotItem.setWarehousingTime(rowObj.getDate("warehousingTime"));
  510. //生产日期
  511. depotItem.setProductionDate(rowObj.getDate("productionDate"));
  512. //保质期天数
  513. depotItem.setExpiryNum(rowObj.getInteger("expiryNum"));
  514. //仓位货架
  515. depotItem.setPosition(rowObj.getString("position"));
  516. //销售价
  517. depotItem.setWholesaleDecimal(rowObj.getBigDecimal("wholesaleDecimal"));
  518. //获取商品信息
  519. Material material= materialService.getMaterial(depotItem.getMaterialId());
  520. if (BusinessConstants.ENABLE_SERIAL_NUMBER_ENABLED.equals(material.getEnableSerialNumber()) ||
  521. BusinessConstants.ENABLE_BATCH_NUMBER_ENABLED.equals(material.getEnableBatchNumber())) {
  522. //组装拆卸单不能选择批号或序列号商品
  523. if(BusinessConstants.SUB_TYPE_ASSEMBLE.equals(depotHead.getSubType()) ||
  524. BusinessConstants.SUB_TYPE_DISASSEMBLE.equals(depotHead.getSubType())) {
  525. throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_ASSEMBLE_SELECT_ERROR_CODE,
  526. String.format(ExceptionConstants.MATERIAL_ASSEMBLE_SELECT_ERROR_MSG, barCode));
  527. }
  528. //调拨单不能选择批号或序列号商品(该场景走出库和入库单)
  529. if(BusinessConstants.SUB_TYPE_TRANSFER.equals(depotHead.getSubType())) {
  530. throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_TRANSFER_SELECT_ERROR_CODE,
  531. String.format(ExceptionConstants.MATERIAL_TRANSFER_SELECT_ERROR_MSG, barCode));
  532. }
  533. //盘点业务不能选择批号或序列号商品(该场景走出库和入库单)
  534. if(BusinessConstants.SUB_TYPE_CHECK_ENTER.equals(depotHead.getSubType())
  535. ||BusinessConstants.SUB_TYPE_REPLAY.equals(depotHead.getSubType())) {
  536. throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_STOCK_CHECK_ERROR_CODE,
  537. String.format(ExceptionConstants.MATERIAL_STOCK_CHECK_ERROR_MSG, barCode));
  538. }
  539. }
  540. if (StringUtil.isExist(rowObj.get("snList"))) {
  541. // depotItem.setSnList(rowObj.getString("snList"));
  542. if(StringUtil.isExist(rowObj.get("depotId"))) {
  543. String [] snArray = depotItem.getSnList().split(",");
  544. int operNum = rowObj.getInteger("operNumber");
  545. if(snArray.length == operNum) {
  546. Long depotId = rowObj.getLong("depotId");
  547. BigDecimal inPrice = BigDecimal.ZERO;
  548. if (StringUtil.isExist(rowObj.get("unitPrice"))) {
  549. inPrice = rowObj.getBigDecimal("unitPrice");
  550. }
  551. serialNumberService.addSerialNumberByBill(depotHead.getType(), depotHead.getSubType(),
  552. depotHead.getNumber(), materialExtend.getMaterialId(), depotId, inPrice, depotItem.getSnList());
  553. } else {
  554. throw new BusinessRunTimeException(ExceptionConstants.DEPOT_HEAD_SN_NUMBERE_FAILED_CODE,
  555. String.format(ExceptionConstants.DEPOT_HEAD_SN_NUMBERE_FAILED_MSG, barCode));
  556. }
  557. }
  558. }
  559. // else {
  560. //入库或出库
  561. // if (BusinessConstants.DEPOTHEAD_TYPE_IN.equals(depotHead.getType()) ||
  562. // BusinessConstants.DEPOTHEAD_TYPE_OUT.equals(depotHead.getType())) {
  563. //序列号不能为空 先去掉校验
  564. // if (BusinessConstants.ENABLE_SERIAL_NUMBER_ENABLED.equals(material.getEnableSerialNumber())) {
  565. //如果开启出入库管理,并且类型等于采购、采购退货、销售、销售退货,则跳过
  566. // if(systemConfigService.getInOutManageFlag() &&
  567. // (BusinessConstants.SUB_TYPE_PURCHASE.equals(depotHead.getSubType())
  568. // ||BusinessConstants.SUB_TYPE_PURCHASE_RETURN.equals(depotHead.getSubType())
  569. // ||BusinessConstants.SUB_TYPE_SALES.equals(depotHead.getSubType())
  570. // ||BusinessConstants.SUB_TYPE_SALES_RETURN.equals(depotHead.getSubType()))) {
  571. // //跳过
  572. // }
  573. // else {
  574. // throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_SERIAL_NUMBERE_EMPTY_CODE,
  575. // String.format(ExceptionConstants.MATERIAL_SERIAL_NUMBERE_EMPTY_MSG, barCode));
  576. // }
  577. // }
  578. // }
  579. // }
  580. if (StringUtil.isExist(rowObj.get("batchNumber"))) {
  581. //设置基础单位数量
  582. depotItem.setBatchNumber(rowObj.getString("batchNumber"));
  583. }
  584. // else {
  585. //入库或出库
  586. // if(BusinessConstants.DEPOTHEAD_TYPE_IN.equals(depotHead.getType()) ||
  587. // BusinessConstants.DEPOTHEAD_TYPE_OUT.equals(depotHead.getType())) {
  588. //批号不能为空
  589. // if (BusinessConstants.ENABLE_BATCH_NUMBER_ENABLED.equals(material.getEnableBatchNumber())) {
  590. // //如果开启出入库管理,并且类型等于采购、采购退货、销售、销售退货,则跳过
  591. // if(systemConfigService.getInOutManageFlag() &&
  592. // (BusinessConstants.SUB_TYPE_PURCHASE.equals(depotHead.getSubType())
  593. // ||BusinessConstants.SUB_TYPE_PURCHASE_RETURN.equals(depotHead.getSubType())
  594. // ||BusinessConstants.SUB_TYPE_SALES.equals(depotHead.getSubType())
  595. // ||BusinessConstants.SUB_TYPE_SALES_RETURN.equals(depotHead.getSubType()))) {
  596. // //跳过
  597. // } else {
  598. // throw new BusinessRunTimeException(ExceptionConstants.DEPOT_HEAD_BATCH_NUMBERE_EMPTY_CODE,
  599. // String.format(ExceptionConstants.DEPOT_HEAD_BATCH_NUMBERE_EMPTY_MSG, barCode));
  600. // }
  601. // }
  602. // }
  603. // }
  604. //设置有效期
  605. if (StringUtil.isExist(rowObj.get("expirationDate"))) {
  606. depotItem.setExpirationDate(rowObj.getDate("expirationDate"));
  607. }
  608. //设置sku属性
  609. if (StringUtil.isExist(rowObj.get("sku"))) {
  610. depotItem.setSku(rowObj.getString("sku"));
  611. }
  612. //设置关联明细id
  613. if (StringUtil.isExist(rowObj.get("linkId"))) {
  614. depotItem.setLinkId(rowObj.getLong("linkId"));
  615. }
  616. //以下进行单位换算
  617. Unit unitInfo = materialService.findUnit(materialExtend.getMaterialId()); //查询多单位信息
  618. if (StringUtil.isExist(rowObj.get("operNumber"))) {
  619. //设置子表单商品数量
  620. depotItem.setOperNumber(rowObj.getBigDecimal("operNumber"));
  621. //获取子表单商品单位
  622. String unit = rowObj.get("unit") == null ? "" :rowObj.get("unit").toString();
  623. BigDecimal oNumber = depotItem.getOperNumber();
  624. if (StringUtil.isNotEmpty(unitInfo.getName())) {
  625. String basicUnit = unitInfo.getBasicUnit(); //基本单位
  626. if (unit.equals(basicUnit)) { //如果等于基本单位
  627. depotItem.setBasicNumber(oNumber); //数量一致
  628. } else if (unit.equals(unitInfo.getOtherUnit())) { //如果等于副单位
  629. depotItem.setBasicNumber(oNumber.multiply(unitInfo.getRatio())); //数量乘以比例
  630. } else if (unit.equals(unitInfo.getOtherUnitTwo())) { //如果等于副单位2
  631. depotItem.setBasicNumber(oNumber.multiply(unitInfo.getRatioTwo())); //数量乘以比例
  632. } else if (unit.equals(unitInfo.getOtherUnitThree())) { //如果等于副单位3
  633. depotItem.setBasicNumber(oNumber.multiply(unitInfo.getRatioThree())); //数量乘以比例
  634. } else {
  635. depotItem.setBasicNumber(oNumber); //数量一致
  636. }
  637. } else {
  638. depotItem.setBasicNumber(oNumber); //其他情况
  639. }
  640. }
  641. //如果数量+已完成数量>原订单数量,给出预警(判断前提是存在关联订单|关联请购单)
  642. String linkStr = StringUtil.isNotEmpty(depotHead.getLinkNumber())? depotHead.getLinkNumber(): depotHead.getLinkApply();
  643. if (StringUtil.isNotEmpty(linkStr) && StringUtil.isExist(rowObj.get("preNumber")) && StringUtil.isExist(rowObj.get("finishNumber"))) {
  644. if("add".equals(actionType)) {
  645. //在新增模式进行状态赋值
  646. BigDecimal preNumber = rowObj.getBigDecimal("preNumber");
  647. BigDecimal finishNumber = rowObj.getBigDecimal("finishNumber");
  648. if(depotItem.getOperNumber().add(finishNumber).compareTo(preNumber)>0) {
  649. if(!systemConfigService.getOverLinkBillFlag()) {
  650. throw new BusinessRunTimeException(ExceptionConstants.DEPOT_HEAD_NUMBER_NEED_EDIT_FAILED_CODE,
  651. String.format(ExceptionConstants.DEPOT_HEAD_NUMBER_NEED_EDIT_FAILED_MSG, barCode));
  652. }
  653. }
  654. } else if("update".equals(actionType)) {
  655. //当前单据的类型
  656. String currentSubType = depotHead.getSubType();
  657. //在更新模式进行状态赋值
  658. String unit = rowObj.get("unit").toString();
  659. Long preHeaderId = depotHeadService.getDepotHead(linkStr).getId();
  660. if(null!=preHeaderId) {
  661. //前一个单据的数量
  662. BigDecimal preNumber = getPreItemByHeaderIdAndMaterial(linkStr, depotItem.getMaterialExtendId(), depotItem.getLinkId()).getOperNumber();
  663. //除去此单据之外的已入库|已出库
  664. BigDecimal realFinishNumber = getRealFinishNumber(currentSubType, depotItem.getMaterialExtendId(), depotItem.getLinkId(), preHeaderId, headerId, unitInfo, unit);
  665. if(preNumber!=null) {
  666. if (depotItem.getOperNumber().add(realFinishNumber).compareTo(preNumber) > 0) {
  667. if (!systemConfigService.getOverLinkBillFlag()) {
  668. throw new BusinessRunTimeException(ExceptionConstants.DEPOT_HEAD_NUMBER_NEED_EDIT_FAILED_CODE,
  669. String.format(ExceptionConstants.DEPOT_HEAD_NUMBER_NEED_EDIT_FAILED_MSG, barCode));
  670. }
  671. }
  672. } else {
  673. throw new BusinessRunTimeException(ExceptionConstants.DEPOT_ITEM_PRE_BILL_IS_CHANGE_CODE,
  674. ExceptionConstants.DEPOT_ITEM_PRE_BILL_IS_CHANGE_MSG);
  675. }
  676. }
  677. }
  678. }
  679. if (StringUtil.isExist(rowObj.get("unitPrice"))) {
  680. BigDecimal unitPrice = rowObj.getBigDecimal("unitPrice");
  681. depotItem.setUnitPrice(unitPrice);
  682. if(materialExtend.getLowDecimal()!=null) {
  683. //零售或销售单价低于最低售价,进行提示
  684. if("零售".equals(depotHead.getSubType()) || "销售".equals(depotHead.getSubType())) {
  685. if (unitPrice.compareTo(materialExtend.getLowDecimal()) < 0) {
  686. throw new BusinessRunTimeException(ExceptionConstants.DEPOT_HEAD_UNIT_PRICE_LOW_CODE,
  687. String.format(ExceptionConstants.DEPOT_HEAD_UNIT_PRICE_LOW_MSG, barCode));
  688. }
  689. }
  690. }
  691. }
  692. //如果是销售出库、销售退货、零售出库、零售退货则给采购单价字段赋值(如果是批次商品,则要根据批号去找之前的入库价)
  693. if(BusinessConstants.SUB_TYPE_SALES.equals(depotHead.getSubType()) ||
  694. BusinessConstants.SUB_TYPE_SALES_RETURN.equals(depotHead.getSubType()) ||
  695. BusinessConstants.SUB_TYPE_RETAIL.equals(depotHead.getSubType()) ||
  696. BusinessConstants.SUB_TYPE_RETAIL_RETURN.equals(depotHead.getSubType())) {
  697. boolean moveAvgPriceFlag = systemConfigService.getMoveAvgPriceFlag();
  698. BigDecimal currentUnitPrice = materialCurrentStockMapperEx.getCurrentUnitPriceByMId(materialExtend.getMaterialId());
  699. currentUnitPrice = unitService.parseUnitPriceByUnit(currentUnitPrice, unitInfo, depotItem.getMaterialUnit());
  700. BigDecimal unitPrice = moveAvgPriceFlag? currentUnitPrice: materialExtend.getPurchaseDecimal();
  701. depotItem.setPurchaseUnitPrice(unitPrice);
  702. if(StringUtil.isNotEmpty(depotItem.getBatchNumber())) {
  703. depotItem.setPurchaseUnitPrice(getDepotItemByBatchNumber(depotItem.getMaterialExtendId(),depotItem.getBatchNumber()).getUnitPrice());
  704. }
  705. }
  706. //含税单价
  707. if (StringUtil.isExist(rowObj.get("taxUnitPrice"))) {
  708. depotItem.setTaxUnitPrice(rowObj.getBigDecimal("taxUnitPrice"));
  709. }
  710. //总金额,不含税
  711. if (StringUtil.isExist(rowObj.get("allPrice"))) {
  712. //基本单位数量*单价
  713. depotItem.setAllPrice(rowObj.getBigDecimal("allPrice"));
  714. //depotItem.setAllPrice(depotItem.getBasicNumber().multiply(depotItem.getUnitPrice()));
  715. }
  716. if (StringUtil.isExist(rowObj.get("depotId"))) {
  717. depotItem.setDepotId(rowObj.getLong("depotId"));
  718. } else {
  719. if(!BusinessConstants.SUB_TYPE_PURCHASE_APPLY.equals(depotHead.getSubType())
  720. && !BusinessConstants.SUB_TYPE_PURCHASE_ORDER.equals(depotHead.getSubType())
  721. && !BusinessConstants.SUB_TYPE_SALES_ORDER.equals(depotHead.getSubType())) {
  722. throw new BusinessRunTimeException(ExceptionConstants.DEPOT_HEAD_DEPOT_FAILED_CODE,
  723. String.format(ExceptionConstants.DEPOT_HEAD_DEPOT_FAILED_MSG));
  724. }
  725. }
  726. if(BusinessConstants.SUB_TYPE_TRANSFER.equals(depotHead.getSubType())) {
  727. if (StringUtil.isExist(rowObj.get("anotherDepotId"))) {
  728. if(rowObj.getLong("anotherDepotId").equals(rowObj.getLong("depotId"))) {
  729. throw new BusinessRunTimeException(ExceptionConstants.DEPOT_HEAD_ANOTHER_DEPOT_EQUAL_FAILED_CODE,
  730. String.format(ExceptionConstants.DEPOT_HEAD_ANOTHER_DEPOT_EQUAL_FAILED_MSG));
  731. } else {
  732. depotItem.setAnotherDepotId(rowObj.getLong("anotherDepotId"));
  733. }
  734. } else {
  735. throw new BusinessRunTimeException(ExceptionConstants.DEPOT_HEAD_ANOTHER_DEPOT_FAILED_CODE,
  736. String.format(ExceptionConstants.DEPOT_HEAD_ANOTHER_DEPOT_FAILED_MSG));
  737. }
  738. }
  739. //税率
  740. if (StringUtil.isExist(rowObj.get("taxRate"))) {
  741. depotItem.setTaxRate(rowObj.getBigDecimal("taxRate"));
  742. //金额*税率
  743. //depotItem.setTaxMoney(depotItem.getAllPrice().multiply(depotItem.getTaxRate()).divide(new BigDecimal("100"),2,BigDecimal.ROUND_HALF_UP));
  744. }
  745. //税额
  746. if (StringUtil.isExist(rowObj.get("taxMoney"))) {
  747. depotItem.setTaxMoney(rowObj.getBigDecimal("taxMoney"));
  748. }
  749. //价税合计
  750. if (StringUtil.isExist(rowObj.get("taxLastMoney"))) {
  751. //单价总额 + 税额
  752. depotItem.setTaxLastMoney(rowObj.getBigDecimal("taxLastMoney"));
  753. //depotItem.setTaxLastMoney(depotItem.getAllPrice().add(depotItem.getTaxMoney() == null ? BigDecimal.ZERO : depotItem.getTaxMoney()));
  754. }
  755. if (StringUtil.isExist(rowObj.get("mType"))) {
  756. depotItem.setMaterialType(rowObj.getString("mType"));
  757. }
  758. if (StringUtil.isExist(rowObj.get("remark"))) {
  759. depotItem.setRemark(rowObj.getString("remark"));
  760. }
  761. //出库时判断库存是否充足
  762. if(BusinessConstants.DEPOTHEAD_TYPE_OUT.equals(depotHead.getType())){
  763. String stockMsg = material.getName() + "-" + barCode;
  764. BigDecimal stock = getCurrentStockByParam(depotItem.getDepotId(),depotItem.getMaterialId());
  765. // if(StringUtil.isNotEmpty(depotItem.getSku())) {
  766. // //对于sku商品要换个方式计算库存
  767. // stock = getSkuStockByParam(depotItem.getDepotId(),depotItem.getMaterialExtendId(),null,null);
  768. // }
  769. if(StringUtil.isNotEmpty(depotItem.getBatchNumber())) {
  770. //对于批次商品要换个方式计算库存
  771. stock = getOneBatchNumberStock(depotItem.getDepotId(), barCode, depotItem.getBatchNumber());
  772. stockMsg += "-批号" + depotItem.getBatchNumber();
  773. }
  774. BigDecimal thisRealNumber = depotItem.getBasicNumber()==null?BigDecimal.ZERO:depotItem.getBasicNumber();
  775. if(StringUtil.isNotEmpty(depotItem.getBatchNumber())) {
  776. //对于批次商品,直接使用当前填写的数量
  777. thisRealNumber = depotItem.getOperNumber()==null?BigDecimal.ZERO:depotItem.getOperNumber();
  778. }
  779. if(!systemConfigService.getMinusStockFlag() && stock.compareTo(thisRealNumber) < 0){
  780. throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_STOCK_NOT_ENOUGH_CODE,
  781. String.format(ExceptionConstants.MATERIAL_STOCK_NOT_ENOUGH_MSG, stockMsg));
  782. }
  783. //出库时处理序列号
  784. if(!BusinessConstants.SUB_TYPE_TRANSFER.equals(depotHead.getSubType())) {
  785. //判断商品是否开启序列号,开启的售出序列号,未开启的跳过
  786. if(BusinessConstants.ENABLE_SERIAL_NUMBER_ENABLED.equals(material.getEnableSerialNumber())) {
  787. //如果开启出入库管理,并且类型等于采购、采购退货、销售、销售退货,则跳过
  788. if(systemConfigService.getInOutManageFlag() &&
  789. (BusinessConstants.SUB_TYPE_PURCHASE.equals(depotHead.getSubType())
  790. ||BusinessConstants.SUB_TYPE_PURCHASE_RETURN.equals(depotHead.getSubType())
  791. ||BusinessConstants.SUB_TYPE_SALES.equals(depotHead.getSubType())
  792. ||BusinessConstants.SUB_TYPE_SALES_RETURN.equals(depotHead.getSubType()))) {
  793. //跳过
  794. } else {
  795. //售出序列号,获得当前操作人
  796. //User userInfo = userService.getCurrentUser();
  797. //serialNumberService.checkAndUpdateSerialNumber(depotItem, depotHead.getNumber(), userInfo, StringUtil.toNull(depotItem.getSnList()));
  798. }
  799. }
  800. }
  801. }
  802. this.insertDepotItemWithObj(depotItem);
  803. if ("1".equals(depotHead.getStatus())){
  804. //单据审核,处理批次商品信息
  805. if(BusinessConstants.DEPOTHEAD_TYPE_IN.equals(depotHead.getType())){
  806. //表单入库,新增批次商品信息
  807. materialBatchService.generateMaterialBatchByDepotItemId(depotItem,depotHead.getOrganId());
  808. }else if(BusinessConstants.DEPOTHEAD_TYPE_OUT.equals(depotHead.getType())){
  809. //表单出库,修改商品库存
  810. //materialExtend.setInventory(materialExtend.getInventory().subtract(depotItem.getBasicNumber()));
  811. materialBatchService.handleMaterialBatchByDepotItemId(depotItem.getId());
  812. }
  813. }
  814. //更新当前库存
  815. updateCurrentStock(depotItem);
  816. //更新当前成本价
  817. //updateCurrentUnitPrice(depotItem);
  818. //更新商品的价格
  819. updateMaterialExtendPrice(materialExtend.getId(), depotHead.getSubType(), depotHead.getBillType(), rowObj);
  820. }
  821. //如果关联单据号非空则更新订单的状态,单据类型:采购入库单、销售出库单、盘点复盘单、其它入库单、其它出库单
  822. if(BusinessConstants.SUB_TYPE_PURCHASE.equals(depotHead.getSubType())
  823. || BusinessConstants.SUB_TYPE_SALES.equals(depotHead.getSubType())
  824. || BusinessConstants.SUB_TYPE_REPLAY.equals(depotHead.getSubType())
  825. || BusinessConstants.SUB_TYPE_OTHER.equals(depotHead.getSubType())) {
  826. if(StringUtil.isNotEmpty(depotHead.getLinkNumber())) {
  827. //单据状态:是否全部完成 2-全部完成 3-部分完成(针对订单的分批出入库)
  828. String billStatus = getBillStatusByParam(depotHead, depotHead.getLinkNumber(), "normal");
  829. changeBillStatus(depotHead.getLinkNumber(), billStatus);
  830. }
  831. }
  832. //当前单据类型为采购订单的逻辑
  833. if(BusinessConstants.SUB_TYPE_PURCHASE_ORDER.equals(depotHead.getSubType())) {
  834. //如果关联单据号非空则更新订单的状态,此处针对销售订单转采购订单的场景
  835. if(StringUtil.isNotEmpty(depotHead.getLinkNumber())) {
  836. String billStatus = getBillStatusByParam(depotHead, depotHead.getLinkNumber(), "normal");
  837. changeBillPurchaseStatus(depotHead.getLinkNumber(), billStatus);
  838. }
  839. //如果关联单据号非空则更新订单的状态,此处针对请购单转采购订单的场景
  840. if(StringUtil.isNotEmpty(depotHead.getLinkApply())) {
  841. String billStatus = getBillStatusByParam(depotHead, depotHead.getLinkApply(), "apply");
  842. changeBillStatus(depotHead.getLinkApply(), billStatus);
  843. }
  844. }
  845. } else {
  846. throw new BusinessRunTimeException(ExceptionConstants.DEPOT_HEAD_ROW_FAILED_CODE,
  847. String.format(ExceptionConstants.DEPOT_HEAD_ROW_FAILED_MSG));
  848. }
  849. }
  850. @Override
  851. @Transactional(value = "transactionManager", rollbackFor = Exception.class)
  852. public void saveOrderItem(DepotHeadXsddRequestVO order, List<DepotItemXsddRequestVO> itemList) throws Exception {
  853. // 查询单据主表信息
  854. DepotHead depotHead = depotHeadMapper.selectByPrimaryKey(order.getId());
  855. if (depotHead == null) {
  856. throw new BusinessRunTimeException(ExceptionConstants.DEPOT_HEAD_NOT_EXIST_CODE, String.format(ExceptionConstants.DEPOT_HEAD_NOT_EXIST_MSG));
  857. }
  858. if (null != itemList && itemList.size() > 0) {
  859. for (DepotItemXsddRequestVO item : itemList) {
  860. DepotItem depotItem = new DepotItem();
  861. BeanUtils.copyProperties(item, depotItem);
  862. // 以下进行单位换算
  863. Unit unitInfo = materialService.findUnit(depotItem.getMaterialId()); // 查询多单位信息
  864. if (depotItem.getOperNumber() != null) {
  865. // 获取子表单商品单位
  866. String unit = depotItem.getMaterialUnit() == null ? "" : depotItem.getMaterialUnit();
  867. BigDecimal oNumber = depotItem.getOperNumber();
  868. if (StringUtil.isNotEmpty(unitInfo.getName())) {
  869. String basicUnit = unitInfo.getBasicUnit(); // 基本单位
  870. if (unit.equals(basicUnit)) { // 如果等于基本单位
  871. depotItem.setBasicNumber(oNumber); // 数量一致
  872. } else if (unit.equals(unitInfo.getOtherUnit())) { // 如果等于副单位
  873. depotItem.setBasicNumber(oNumber.multiply(unitInfo.getRatio())); // 数量乘以比例
  874. } else if (unit.equals(unitInfo.getOtherUnitTwo())) { // 如果等于副单位2
  875. depotItem.setBasicNumber(oNumber.multiply(unitInfo.getRatioTwo())); // 数量乘以比例
  876. } else if (unit.equals(unitInfo.getOtherUnitThree())) { // 如果等于副单位3
  877. depotItem.setBasicNumber(oNumber.multiply(unitInfo.getRatioThree())); // 数量乘以比例
  878. } else {
  879. depotItem.setBasicNumber(oNumber); // 数量一致
  880. }
  881. } else {
  882. depotItem.setBasicNumber(oNumber); // 其他情况
  883. }
  884. }
  885. depotItem.setHeaderId(depotHead.getId());
  886. this.insertDepotItem(depotItem);
  887. // 更新当前库存
  888. updateCurrentStock(depotItem);
  889. }
  890. } else {
  891. throw new BusinessRunTimeException(ExceptionConstants.DEPOT_HEAD_ROW_FAILED_CODE, String.format(ExceptionConstants.DEPOT_HEAD_ROW_FAILED_MSG));
  892. }
  893. }
  894. /**
  895. * 判断单据的状态
  896. * 通过数组对比:原单据的商品和商品数量(汇总) 与 分批操作后单据的商品和商品数量(汇总)
  897. * @param depotHead
  898. * @param linkStr
  899. * @return
  900. */
  901. @Override
  902. @Transactional(value = "transactionManager", rollbackFor = Exception.class)
  903. public String getBillStatusByParam(DepotHead depotHead, String linkStr, String linkType) {
  904. String res = BusinessConstants.BILLS_STATUS_SKIPED;
  905. //获取原单据的商品和商品数量(汇总)
  906. List<DepotItemVo4MaterialAndSum> linkList = depotItemMapperEx.getLinkBillDetailMaterialSum(linkStr);
  907. //获取分批操作后单据的商品和商品数量(汇总)
  908. List<DepotItemVo4MaterialAndSum> batchList = depotItemMapperEx.getBatchBillDetailMaterialSum(linkStr, linkType, depotHead.getType());
  909. //将分批操作后的单据的商品和商品数据构造成Map
  910. Map<Long, BigDecimal> materialSumMap = new HashMap<>();
  911. for(DepotItemVo4MaterialAndSum materialAndSum : batchList) {
  912. materialSumMap.put(materialAndSum.getMaterialExtendId(), materialAndSum.getOperNumber());
  913. }
  914. for(DepotItemVo4MaterialAndSum materialAndSum : linkList) {
  915. //过滤掉原单里面有数量为0的商品
  916. if(materialAndSum.getOperNumber().compareTo(BigDecimal.ZERO) != 0) {
  917. BigDecimal materialSum = materialSumMap.get(materialAndSum.getMaterialExtendId());
  918. if (materialSum != null) {
  919. if (materialSum.compareTo(materialAndSum.getOperNumber()) < 0) {
  920. res = BusinessConstants.BILLS_STATUS_SKIPING;
  921. }
  922. } else {
  923. res = BusinessConstants.BILLS_STATUS_SKIPING;
  924. }
  925. }
  926. }
  927. return res;
  928. }
  929. /**
  930. * 更新单据状态
  931. * @param linkStr
  932. * @param billStatus
  933. */
  934. @Override
  935. @Transactional(value = "transactionManager", rollbackFor = Exception.class)
  936. public void changeBillStatus(String linkStr, String billStatus) {
  937. DepotHead depotHeadOrders = new DepotHead();
  938. depotHeadOrders.setStatus(billStatus);
  939. DepotHeadExample example = new DepotHeadExample();
  940. List<String> linkNoList = StringUtil.strToStringList(linkStr);
  941. example.createCriteria().andNumberIn(linkNoList);
  942. try{
  943. depotHeadMapper.updateByExampleSelective(depotHeadOrders, example);
  944. }catch(Exception e){
  945. logger.error("异常码[{}],异常提示[{}],异常[{}]",
  946. ExceptionConstants.DATA_WRITE_FAIL_CODE,ExceptionConstants.DATA_WRITE_FAIL_MSG,e);
  947. throw new BusinessRunTimeException(ExceptionConstants.DATA_WRITE_FAIL_CODE,
  948. ExceptionConstants.DATA_WRITE_FAIL_MSG);
  949. }
  950. }
  951. /**
  952. * 更新单据状态,此处针对销售订单转采购订单的场景
  953. * @param linkStr
  954. * @param billStatus
  955. */
  956. @Override
  957. @Transactional(value = "transactionManager", rollbackFor = Exception.class)
  958. public void changeBillPurchaseStatus(String linkStr, String billStatus) {
  959. DepotHead depotHeadOrders = new DepotHead();
  960. depotHeadOrders.setPurchaseStatus(billStatus);
  961. DepotHeadExample example = new DepotHeadExample();
  962. List<String> linkNoList = StringUtil.strToStringList(linkStr);
  963. example.createCriteria().andNumberIn(linkNoList);
  964. try{
  965. depotHeadMapper.updateByExampleSelective(depotHeadOrders, example);
  966. }catch(Exception e){
  967. logger.error("异常码[{}],异常提示[{}],异常[{}]",
  968. ExceptionConstants.DATA_WRITE_FAIL_CODE,ExceptionConstants.DATA_WRITE_FAIL_MSG,e);
  969. throw new BusinessRunTimeException(ExceptionConstants.DATA_WRITE_FAIL_CODE,
  970. ExceptionConstants.DATA_WRITE_FAIL_MSG);
  971. }
  972. }
  973. /**
  974. * 根据批号查询单据明细信息
  975. * @param materialExtendId
  976. * @param batchNumber
  977. * @return
  978. */
  979. @Override
  980. public DepotItem getDepotItemByBatchNumber(Long materialExtendId, String batchNumber) {
  981. List<DepotItem> depotItemList = depotItemMapperEx.getDepotItemByBatchNumber(materialExtendId, batchNumber);
  982. if(null != depotItemList && depotItemList.size() > 0){
  983. return depotItemList.get(0);
  984. } else {
  985. return new DepotItem();
  986. }
  987. }
  988. /**
  989. * 根据主表id删除单明细
  990. * @param headerId
  991. * @throws Exception
  992. */
  993. @Override
  994. @Transactional(value = "transactionManager", rollbackFor = Exception.class)
  995. public void deleteDepotItemHeadId(Long headerId) {
  996. try{
  997. //1、查询删除前的单据明细
  998. List<DepotItem> depotItemList = getListByHeaderId(headerId);
  999. //2、删除单据明细
  1000. DepotItemExample example = new DepotItemExample();
  1001. example.createCriteria().andHeaderIdEqualTo(headerId);
  1002. depotItemMapper.deleteByExample(example);
  1003. //3、计算删除之后单据明细中商品的库存
  1004. for(DepotItem depotItem : depotItemList){
  1005. updateCurrentStock(depotItem);
  1006. }
  1007. }catch(Exception e){
  1008. JshException.writeFail(logger, e);
  1009. }
  1010. }
  1011. /**
  1012. * 删除序列号和回收序列号
  1013. * @param actionType
  1014. * @throws Exception
  1015. */
  1016. @Override
  1017. @Transactional(value = "transactionManager", rollbackFor = Exception.class)
  1018. public void deleteOrCancelSerialNumber(String actionType, DepotHead depotHead, Long headerId) {
  1019. if(actionType.equals("update")) {
  1020. User userInfo = userService.getCurrentUser();
  1021. if(BusinessConstants.DEPOTHEAD_TYPE_IN.equals(depotHead.getType())){
  1022. //入库逻辑
  1023. String number = depotHead.getNumber();
  1024. SerialNumberExample example = new SerialNumberExample();
  1025. example.createCriteria().andInBillNoEqualTo(number);
  1026. serialNumberService.deleteByExample(example);
  1027. } else if(BusinessConstants.DEPOTHEAD_TYPE_OUT.equals(depotHead.getType())){
  1028. //出库逻辑
  1029. DepotItemExample example = new DepotItemExample();
  1030. example.createCriteria().andHeaderIdEqualTo(headerId).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
  1031. List<DepotItem> depotItemList = depotItemMapper.selectByExample(example);
  1032. if(null != depotItemList && depotItemList.size() > 0){
  1033. for (DepotItem depotItem : depotItemList){
  1034. if(StringUtil.isNotEmpty(depotItem.getSnList())){
  1035. serialNumberService.cancelSerialNumber(depotItem.getMaterialId(), depotHead.getNumber(), (depotItem.getBasicNumber() == null ? 0 : depotItem.getBasicNumber()).intValue(), userInfo);
  1036. }
  1037. }
  1038. }
  1039. }
  1040. }
  1041. }
  1042. /**
  1043. * 针对组装单、拆卸单校验是否存在组合件和普通子件
  1044. * @param rowArr
  1045. * @param subType
  1046. */
  1047. @Override
  1048. public void checkAssembleWithMaterialType(JSONArray rowArr, String subType) {
  1049. if(BusinessConstants.SUB_TYPE_ASSEMBLE.equals(subType) ||
  1050. BusinessConstants.SUB_TYPE_DISASSEMBLE.equals(subType)) {
  1051. if(rowArr.size() > 1) {
  1052. JSONObject firstRowObj = JSONObject.parseObject(rowArr.getString(0));
  1053. JSONObject secondRowObj = JSONObject.parseObject(rowArr.getString(1));
  1054. String firstMaterialType = firstRowObj.getString("mType");
  1055. String secondMaterialType = secondRowObj.getString("mType");
  1056. if(!"组合件".equals(firstMaterialType) || !"普通子件".equals(secondMaterialType)) {
  1057. throw new BusinessRunTimeException(ExceptionConstants.DEPOT_HEAD_CHECK_ASSEMBLE_EMPTY_CODE,
  1058. String.format(ExceptionConstants.DEPOT_HEAD_CHECK_ASSEMBLE_EMPTY_MSG));
  1059. }
  1060. } else {
  1061. throw new BusinessRunTimeException(ExceptionConstants.DEPOT_HEAD_CHECK_ASSEMBLE_EMPTY_CODE,
  1062. String.format(ExceptionConstants.DEPOT_HEAD_CHECK_ASSEMBLE_EMPTY_MSG));
  1063. }
  1064. }
  1065. }
  1066. /**
  1067. * 针对组装单、拆卸单校验是否存在组合件和普通子件
  1068. * @param depotItems
  1069. * @param subType
  1070. */
  1071. @Override
  1072. public void checkAssembleWithMaterialType(List<DepotItemDTO> depotItems, String subType) {
  1073. if(BusinessConstants.SUB_TYPE_ASSEMBLE.equals(subType) ||
  1074. BusinessConstants.SUB_TYPE_DISASSEMBLE.equals(subType)) {
  1075. if(depotItems.size() > 1) {
  1076. DepotItem firstItem = depotItems.get(0);
  1077. DepotItem secondItem = depotItems.get(1);
  1078. String firstMaterialType = firstItem.getMaterialType();
  1079. String secondMaterialType = secondItem.getMaterialType();
  1080. if(!"组合件".equals(firstMaterialType) || !"普通子件".equals(secondMaterialType)) {
  1081. throw new BusinessRunTimeException(ExceptionConstants.DEPOT_HEAD_CHECK_ASSEMBLE_EMPTY_CODE,
  1082. String.format(ExceptionConstants.DEPOT_HEAD_CHECK_ASSEMBLE_EMPTY_MSG));
  1083. }
  1084. } else {
  1085. throw new BusinessRunTimeException(ExceptionConstants.DEPOT_HEAD_CHECK_ASSEMBLE_EMPTY_CODE,
  1086. String.format(ExceptionConstants.DEPOT_HEAD_CHECK_ASSEMBLE_EMPTY_MSG));
  1087. }
  1088. }
  1089. }
  1090. /**
  1091. * 更新商品的价格
  1092. * @param meId
  1093. * @param subType
  1094. * @param rowObj
  1095. */
  1096. @Override
  1097. @Transactional(value = "transactionManager", rollbackFor = Exception.class)
  1098. public void updateMaterialExtendPrice(Long meId, String subType, String billType, JSONObject rowObj) throws Exception {
  1099. if(systemConfigService.getUpdateUnitPriceFlag()) {
  1100. if (StringUtil.isExist(rowObj.get("unitPrice"))) {
  1101. BigDecimal unitPrice = rowObj.getBigDecimal("unitPrice");
  1102. MaterialExtend materialExtend = new MaterialExtend();
  1103. materialExtend.setId(meId);
  1104. if(BusinessConstants.SUB_TYPE_PURCHASE.equals(subType)) {
  1105. materialExtend.setPurchaseDecimal(unitPrice);
  1106. }
  1107. if(BusinessConstants.SUB_TYPE_SALES.equals(subType)) {
  1108. materialExtend.setWholesaleDecimal(unitPrice);
  1109. }
  1110. if(BusinessConstants.SUB_TYPE_RETAIL.equals(subType)) {
  1111. materialExtend.setCommodityDecimal(unitPrice);
  1112. }
  1113. //其它入库-生产入库的情况更新采购单价
  1114. if(BusinessConstants.SUB_TYPE_OTHER.equals(subType)) {
  1115. if(BusinessConstants.BILL_TYPE_PRODUCE_IN.equals(billType)) {
  1116. materialExtend.setPurchaseDecimal(unitPrice);
  1117. }
  1118. }
  1119. materialExtendService.updateMaterialExtend(materialExtend);
  1120. }
  1121. }
  1122. }
  1123. /**
  1124. * 更新商品的价格
  1125. * @param meId
  1126. * @param subType
  1127. */
  1128. @Override
  1129. @Transactional(value = "transactionManager", rollbackFor = Exception.class)
  1130. public void updateMaterialExtendPrice(Long meId, String subType, String billType, DepotItem depotItem) {
  1131. if(systemConfigService.getUpdateUnitPriceFlag()) {
  1132. if (StringUtil.isExist(depotItem.getUnitPrice())) {
  1133. BigDecimal unitPrice = depotItem.getUnitPrice();
  1134. MaterialExtend materialExtend = new MaterialExtend();
  1135. materialExtend.setId(meId);
  1136. if(BusinessConstants.SUB_TYPE_PURCHASE.equals(subType)) {
  1137. materialExtend.setPurchaseDecimal(unitPrice);
  1138. }
  1139. if(BusinessConstants.SUB_TYPE_SALES.equals(subType)) {
  1140. materialExtend.setWholesaleDecimal(unitPrice);
  1141. }
  1142. if(BusinessConstants.SUB_TYPE_RETAIL.equals(subType)) {
  1143. materialExtend.setCommodityDecimal(unitPrice);
  1144. }
  1145. //其它入库-生产入库的情况更新采购单价
  1146. if(BusinessConstants.SUB_TYPE_OTHER.equals(subType)) {
  1147. if(BusinessConstants.BILL_TYPE_PRODUCE_IN.equals(billType)) {
  1148. materialExtend.setPurchaseDecimal(unitPrice);
  1149. }
  1150. }
  1151. materialExtendService.updateMaterialExtend(materialExtend);
  1152. }
  1153. }
  1154. }
  1155. @Override
  1156. @Transactional(value = "transactionManager", rollbackFor = Exception.class)
  1157. public List<DepotItemStockWarningCount> findStockWarningCount(Integer offset, Integer rows, String materialParam, List<Long> depotList, List<Long> categoryList) {
  1158. List<DepotItemStockWarningCount> list = null;
  1159. try{
  1160. list =depotItemMapperEx.findStockWarningCount(offset, rows, materialParam, depotList, categoryList);
  1161. }catch(Exception e){
  1162. JshException.readFail(logger, e);
  1163. }
  1164. return list;
  1165. }
  1166. @Override
  1167. @Transactional(value = "transactionManager", rollbackFor = Exception.class)
  1168. public int findStockWarningCountTotal(String materialParam, List<Long> depotList, List<Long> categoryList) {
  1169. int result = 0;
  1170. try{
  1171. result =depotItemMapperEx.findStockWarningCountTotal(materialParam, depotList, categoryList);
  1172. }catch(Exception e){
  1173. JshException.readFail(logger, e);
  1174. }
  1175. return result;
  1176. }
  1177. /**
  1178. * 库存统计-sku
  1179. * @param depotId
  1180. * @param meId
  1181. * @param beginTime
  1182. * @param endTime
  1183. * @return
  1184. */
  1185. @Override
  1186. public BigDecimal getSkuStockByParam(Long depotId, Long meId, String beginTime, String endTime) throws Exception {
  1187. Boolean forceFlag = systemConfigService.getForceApprovalFlag();
  1188. Boolean inOutManageFlag = systemConfigService.getInOutManageFlag();
  1189. List<Long> depotList = depotService.parseDepotList(depotId);
  1190. //盘点复盘后数量的变动
  1191. BigDecimal stockCheckSum = depotItemMapperEx.getSkuStockCheckSumByDepotList(depotList, meId, forceFlag, beginTime, endTime);
  1192. DepotItemVo4Stock stockObj = depotItemMapperEx.getSkuStockByParamWithDepotList(depotList, meId, forceFlag, inOutManageFlag, beginTime, endTime);
  1193. BigDecimal stockSum = BigDecimal.ZERO;
  1194. if(stockObj!=null) {
  1195. BigDecimal inTotal = stockObj.getInTotal();
  1196. BigDecimal transfInTotal = stockObj.getTransfInTotal();
  1197. BigDecimal assemInTotal = stockObj.getAssemInTotal();
  1198. BigDecimal disAssemInTotal = stockObj.getDisAssemInTotal();
  1199. BigDecimal outTotal = stockObj.getOutTotal();
  1200. BigDecimal transfOutTotal = stockObj.getTransfOutTotal();
  1201. BigDecimal assemOutTotal = stockObj.getAssemOutTotal();
  1202. BigDecimal disAssemOutTotal = stockObj.getDisAssemOutTotal();
  1203. stockSum = inTotal.add(transfInTotal).add(assemInTotal).add(disAssemInTotal)
  1204. .subtract(outTotal).subtract(transfOutTotal).subtract(assemOutTotal).subtract(disAssemOutTotal);
  1205. }
  1206. return stockCheckSum.add(stockSum);
  1207. }
  1208. /**
  1209. * 库存统计-单仓库
  1210. * @param depotId
  1211. * @param mId
  1212. * @param beginTime
  1213. * @param endTime
  1214. * @return
  1215. */
  1216. @Override
  1217. public BigDecimal getStockByParam(Long depotId, Long mId, String beginTime, String endTime) {
  1218. List<Long> depotList = depotService.parseDepotList(depotId);
  1219. return getStockByParamWithDepotList(depotList, mId, beginTime, endTime);
  1220. }
  1221. /**
  1222. * 库存统计-多仓库
  1223. * @param depotList
  1224. * @param mId
  1225. * @param beginTime
  1226. * @param endTime
  1227. * @return
  1228. */
  1229. @Override
  1230. public BigDecimal getStockByParamWithDepotList(List<Long> depotList, Long mId, String beginTime, String endTime) {
  1231. Boolean forceFlag = systemConfigService.getForceApprovalFlag();
  1232. Boolean inOutManageFlag = systemConfigService.getInOutManageFlag();
  1233. //初始库存
  1234. BigDecimal stock = materialService.getInitStockByMidAndDepotList(depotList, mId);
  1235. BigDecimal initStock = stock == null ? BigDecimal.ZERO : stock;
  1236. //盘点复盘后数量的变动
  1237. BigDecimal stockCheckSum = depotItemMapperEx.getStockCheckSumByDepotList(depotList, mId, forceFlag, beginTime, endTime);
  1238. //表单的数量
  1239. DepotItemVo4Stock stockObj = depotItemMapperEx.getStockByParamWithDepotList(depotList, mId, forceFlag, inOutManageFlag, beginTime, endTime);
  1240. BigDecimal stockSum = BigDecimal.ZERO;
  1241. //获取商品子表单的库存总数
  1242. BigDecimal inventory = materialBatchService.getInventorySumByDepotAndMid(depotList,mId);
  1243. if(stockObj!=null) {
  1244. BigDecimal inTotal = stockObj.getInTotal();
  1245. BigDecimal transfInTotal = stockObj.getTransfInTotal();
  1246. BigDecimal assemInTotal = stockObj.getAssemInTotal();
  1247. BigDecimal disAssemInTotal = stockObj.getDisAssemInTotal();
  1248. BigDecimal outTotal = stockObj.getOutTotal();
  1249. BigDecimal transfOutTotal = stockObj.getTransfOutTotal();
  1250. BigDecimal assemOutTotal = stockObj.getAssemOutTotal();
  1251. BigDecimal disAssemOutTotal = stockObj.getDisAssemOutTotal();
  1252. stockSum = inTotal.add(transfInTotal).add(assemInTotal).add(disAssemInTotal)
  1253. .subtract(outTotal).subtract(transfOutTotal).subtract(assemOutTotal).subtract(disAssemOutTotal);
  1254. }
  1255. return initStock.add(stockCheckSum).add(inventory);
  1256. }
  1257. /**
  1258. * 统计时间段内的入库和出库数量-多仓库
  1259. * @param depotList
  1260. * @param mId
  1261. * @param beginTime
  1262. * @param endTime
  1263. * @return
  1264. */
  1265. @Override
  1266. public Map<String, BigDecimal> getIntervalMapByParamWithDepotList(List<Long> depotList, Long mId, String beginTime, String endTime) throws Exception {
  1267. Boolean forceFlag = systemConfigService.getForceApprovalFlag();
  1268. Boolean inOutManageFlag = systemConfigService.getInOutManageFlag();
  1269. Map<String,BigDecimal> intervalMap = new HashMap<>();
  1270. BigDecimal inSum = BigDecimal.ZERO;
  1271. BigDecimal outSum = BigDecimal.ZERO;
  1272. //盘点复盘后数量的变动
  1273. BigDecimal stockCheckSum = depotItemMapperEx.getStockCheckSumByDepotList(depotList, mId, forceFlag, beginTime, endTime);
  1274. DepotItemVo4Stock stockObj = depotItemMapperEx.getStockByParamWithDepotList(depotList, mId, forceFlag, inOutManageFlag, beginTime, endTime);
  1275. if(stockObj!=null) {
  1276. BigDecimal inTotal = stockObj.getInTotal();
  1277. BigDecimal transfInTotal = stockObj.getTransfInTotal();
  1278. BigDecimal assemInTotal = stockObj.getAssemInTotal();
  1279. BigDecimal disAssemInTotal = stockObj.getDisAssemInTotal();
  1280. inSum = inTotal.add(transfInTotal).add(assemInTotal).add(disAssemInTotal);
  1281. BigDecimal outTotal = stockObj.getOutTotal();
  1282. BigDecimal transfOutTotal = stockObj.getTransfOutTotal();
  1283. BigDecimal assemOutTotal = stockObj.getAssemOutTotal();
  1284. BigDecimal disAssemOutTotal = stockObj.getDisAssemOutTotal();
  1285. outSum = outTotal.add(transfOutTotal).add(assemOutTotal).add(disAssemOutTotal);
  1286. }
  1287. if(stockCheckSum.compareTo(BigDecimal.ZERO)>0) {
  1288. inSum = inSum.add(stockCheckSum);
  1289. } else {
  1290. //盘点复盘数量为负数代表出库
  1291. outSum = outSum.subtract(stockCheckSum);
  1292. }
  1293. intervalMap.put("inSum", inSum);
  1294. intervalMap.put("outSum", outSum);
  1295. return intervalMap;
  1296. }
  1297. /**
  1298. * 根据单据明细来批量更新当前库存
  1299. * @param depotItem 单据子表明细
  1300. */
  1301. @Override
  1302. @Transactional(value = "transactionManager", rollbackFor = Exception.class)
  1303. public void updateCurrentStock(DepotItem depotItem) {
  1304. updateCurrentStockFun(depotItem.getMaterialId(), depotItem.getDepotId());
  1305. if(depotItem.getAnotherDepotId()!=null){
  1306. updateCurrentStockFun(depotItem.getMaterialId(), depotItem.getAnotherDepotId());
  1307. }
  1308. }
  1309. /**
  1310. * 根据单据明细来批量更新当前成本价
  1311. * @param depotItem
  1312. */
  1313. @Override
  1314. @Transactional(value = "transactionManager", rollbackFor = Exception.class)
  1315. public void updateCurrentUnitPrice(DepotItem depotItem) throws Exception {
  1316. Boolean forceFlag = systemConfigService.getForceApprovalFlag();
  1317. Boolean inOutManageFlag = systemConfigService.getInOutManageFlag();
  1318. //查询多单位信息
  1319. Unit unitInfo = materialService.findUnit(depotItem.getMaterialId());
  1320. List<DepotItemVo4DetailByTypeAndMId> itemList = findDetailByDepotIdsAndMaterialIdList(null, forceFlag, inOutManageFlag, depotItem.getSku(),
  1321. depotItem.getBatchNumber(), null, null, null, depotItem.getMaterialId(), null, null);
  1322. Collections.reverse(itemList); //倒序之后变成按时间从前往后排序
  1323. BigDecimal currentNumber = BigDecimal.ZERO;
  1324. BigDecimal currentUnitPrice = BigDecimal.ZERO;
  1325. BigDecimal currentAllPrice = BigDecimal.ZERO;
  1326. for(DepotItemVo4DetailByTypeAndMId item: itemList) {
  1327. BigDecimal basicNumber = item.getBnum()!=null?item.getBnum():BigDecimal.ZERO;
  1328. //数量*单价 另外计算新的成本价
  1329. BigDecimal allPrice = unitService.parseAllPriceByUnit(item.getAllPrice()!=null?item.getAllPrice():BigDecimal.ZERO, unitInfo, item.getMaterialUnit());
  1330. if(basicNumber.compareTo(BigDecimal.ZERO)!=0 && allPrice.compareTo(BigDecimal.ZERO)!=0) {
  1331. //入库
  1332. if (BusinessConstants.DEPOTHEAD_TYPE_IN.equals(item.getType())) {
  1333. //零售退货、销售退货
  1334. if (BusinessConstants.SUB_TYPE_RETAIL_RETURN.equals(item.getSubType()) || BusinessConstants.SUB_TYPE_SALES_RETURN.equals(item.getSubType())) {
  1335. //数量*当前的成本单价
  1336. currentNumber = currentNumber.add(basicNumber);
  1337. currentAllPrice = currentAllPrice.add(basicNumber.multiply(currentUnitPrice));
  1338. } else {
  1339. currentAllPrice = currentAllPrice.add(allPrice);
  1340. currentNumber = currentNumber.add(basicNumber);
  1341. //只有当前库存总金额和当前库存数量都大于0才计算移动平均价
  1342. if (currentAllPrice.compareTo(BigDecimal.ZERO) > 0 && currentNumber.compareTo(BigDecimal.ZERO) > 0) {
  1343. currentUnitPrice = currentAllPrice.divide(currentNumber, 2, BigDecimal.ROUND_HALF_UP);
  1344. } else {
  1345. currentUnitPrice = item.getUnitPrice();
  1346. }
  1347. }
  1348. }
  1349. //出库
  1350. if (BusinessConstants.DEPOTHEAD_TYPE_OUT.equals(item.getType())) {
  1351. //采购退货
  1352. if (BusinessConstants.SUB_TYPE_PURCHASE_RETURN.equals(item.getSubType())) {
  1353. currentAllPrice = currentAllPrice.add(allPrice);
  1354. currentNumber = currentNumber.add(basicNumber);
  1355. //只有当前库存总金额和当前库存数量都大于0才计算移动平均价
  1356. if (currentAllPrice.compareTo(BigDecimal.ZERO) > 0 && currentNumber.compareTo(BigDecimal.ZERO) > 0) {
  1357. currentUnitPrice = currentAllPrice.divide(currentNumber, 2, BigDecimal.ROUND_HALF_UP);
  1358. } else {
  1359. currentUnitPrice = item.getUnitPrice();
  1360. }
  1361. } else {
  1362. currentNumber = currentNumber.add(basicNumber);
  1363. //数量*当前的成本单价
  1364. currentAllPrice = currentAllPrice.add(basicNumber.multiply(currentUnitPrice));
  1365. }
  1366. }
  1367. //防止单价金额溢出
  1368. if(currentUnitPrice.compareTo(BigDecimal.valueOf(100000000))>0 || currentUnitPrice.compareTo(BigDecimal.valueOf(-100000000))<0) {
  1369. currentUnitPrice = BigDecimal.ZERO;
  1370. }
  1371. }
  1372. }
  1373. //更新实时库存中的当前单价
  1374. materialCurrentStockMapperEx.updateUnitPriceByMId(currentUnitPrice, depotItem.getMaterialId());
  1375. }
  1376. /**
  1377. * 根据商品和仓库来更新当前库存
  1378. * @param mId
  1379. * @param dId
  1380. */
  1381. @Override
  1382. public void updateCurrentStockFun(Long mId, Long dId) {
  1383. if(mId!=null && dId!=null) {
  1384. //-先清除再插入,防止商品仓库变更,数据对不上
  1385. materialCurrentStockMapper.delete(new LambdaQueryWrapperX<MaterialCurrentStock>().eq(MaterialCurrentStock::getMaterialId,mId).eqIfPresent(MaterialCurrentStock::getDepotId,dId));
  1386. Material material = materialService.getOne(new LambdaQueryWrapperX<Material>().eq(Material::getId,mId));
  1387. MaterialCurrentStock materialCurrentStock = new MaterialCurrentStock();
  1388. materialCurrentStock.setMaterialId(mId);
  1389. materialCurrentStock.setDepotId(dId);
  1390. materialCurrentStock.setCurrentUnitPrice(material.getDefaultPurchaseDecimal());
  1391. //设置当前库存数量
  1392. materialCurrentStock.setCurrentNumber(getStockByParam(dId,mId,null,null));
  1393. //添加当前库存
  1394. materialCurrentStockMapper.insertSelective(materialCurrentStock);
  1395. //同步商品库存
  1396. syncTescoSystemService.sycnTescoStock(mId);
  1397. }
  1398. }
  1399. @Override
  1400. @Transactional(value = "transactionManager", rollbackFor = Exception.class)
  1401. public BigDecimal getFinishNumber(Long meId, Long id, Long headerId, Unit unitInfo, String materialUnit, String linkType) {
  1402. Long linkId = id;
  1403. String goToType = "";
  1404. DepotHead depotHead =depotHeadMapper.selectByPrimaryKey(headerId);
  1405. String linkStr = depotHead.getNumber(); //订单号
  1406. if("purchase".equals(linkType)) {
  1407. //针对以销定购的情况
  1408. if(BusinessConstants.SUB_TYPE_SALES_ORDER.equals(depotHead.getSubType())) {
  1409. goToType = BusinessConstants.SUB_TYPE_PURCHASE_ORDER;
  1410. }
  1411. } else if("other".equals(linkType)) {
  1412. //采购入库、采购退货、销售出库、销售退货都转其它入库
  1413. if(BusinessConstants.SUB_TYPE_PURCHASE.equals(depotHead.getSubType())
  1414. || BusinessConstants.SUB_TYPE_PURCHASE_RETURN.equals(depotHead.getSubType())
  1415. || BusinessConstants.SUB_TYPE_SALES.equals(depotHead.getSubType())
  1416. || BusinessConstants.SUB_TYPE_SALES_RETURN.equals(depotHead.getSubType())) {
  1417. goToType = BusinessConstants.SUB_TYPE_OTHER;
  1418. }
  1419. } else if("basic".equals(linkType)) {
  1420. //采购订单转采购入库
  1421. if(BusinessConstants.SUB_TYPE_PURCHASE_ORDER.equals(depotHead.getSubType())) {
  1422. goToType = BusinessConstants.SUB_TYPE_PURCHASE;
  1423. }
  1424. //销售订单转销售出库
  1425. if(BusinessConstants.SUB_TYPE_SALES_ORDER.equals(depotHead.getSubType())) {
  1426. goToType = BusinessConstants.SUB_TYPE_SALES;
  1427. }
  1428. //采购入库转采购退货
  1429. if(BusinessConstants.SUB_TYPE_PURCHASE.equals(depotHead.getSubType())) {
  1430. goToType = BusinessConstants.SUB_TYPE_PURCHASE_RETURN;
  1431. }
  1432. //销售出库转销售退货
  1433. if(BusinessConstants.SUB_TYPE_SALES.equals(depotHead.getSubType())) {
  1434. goToType = BusinessConstants.SUB_TYPE_SALES_RETURN;
  1435. }
  1436. }
  1437. String noType = "normal";
  1438. if(BusinessConstants.SUB_TYPE_PURCHASE_APPLY.equals(depotHead.getSubType())) {
  1439. noType = "apply";
  1440. }
  1441. BigDecimal count = depotItemMapperEx.getFinishNumber(meId, linkId, linkStr, noType, goToType);
  1442. //根据多单位情况进行数量的转换
  1443. if(materialUnit.equals(unitInfo.getOtherUnit()) && unitInfo.getRatio()!=null && unitInfo.getRatio().compareTo(BigDecimal.ZERO)!=0) {
  1444. count = count.divide(unitInfo.getRatio(),2,BigDecimal.ROUND_HALF_UP);
  1445. }
  1446. if(materialUnit.equals(unitInfo.getOtherUnitTwo()) && unitInfo.getRatioTwo()!=null && unitInfo.getRatioTwo().compareTo(BigDecimal.ZERO)!=0) {
  1447. count = count.divide(unitInfo.getRatioTwo(),2,BigDecimal.ROUND_HALF_UP);
  1448. }
  1449. if(materialUnit.equals(unitInfo.getOtherUnitThree()) && unitInfo.getRatioThree()!=null && unitInfo.getRatioThree().compareTo(BigDecimal.ZERO)!=0) {
  1450. count = count.divide(unitInfo.getRatioThree(),2,BigDecimal.ROUND_HALF_UP);
  1451. }
  1452. return count;
  1453. }
  1454. /**
  1455. * 除去此单据之外的已入库|已出库|已转采购
  1456. * @param currentSubType
  1457. * @param meId
  1458. * @param linkId
  1459. * @param preHeaderId
  1460. * @param currentHeaderId
  1461. * @param unitInfo
  1462. * @param materialUnit
  1463. * @return
  1464. */
  1465. @Override
  1466. @Transactional(value = "transactionManager", rollbackFor = Exception.class)
  1467. public BigDecimal getRealFinishNumber(String currentSubType, Long meId, Long linkId, Long preHeaderId, Long currentHeaderId, Unit unitInfo, String materialUnit) {
  1468. String goToType = currentSubType;
  1469. DepotHead depotHead =depotHeadMapper.selectByPrimaryKey(preHeaderId);
  1470. String linkStr = depotHead.getNumber(); //订单号
  1471. String linkType = "normal";
  1472. if(BusinessConstants.SUB_TYPE_PURCHASE_APPLY.equals(depotHead.getSubType())) {
  1473. linkType = "apply";
  1474. }
  1475. BigDecimal count = depotItemMapperEx.getRealFinishNumber(meId, linkId, linkStr, linkType, currentHeaderId, goToType);
  1476. //根据多单位情况进行数量的转换
  1477. if(materialUnit.equals(unitInfo.getOtherUnit()) && unitInfo.getRatio()!=null && unitInfo.getRatio().compareTo(BigDecimal.ZERO)!=0) {
  1478. count = count.divide(unitInfo.getRatio(),2,BigDecimal.ROUND_HALF_UP);
  1479. }
  1480. if(materialUnit.equals(unitInfo.getOtherUnitTwo()) && unitInfo.getRatioTwo()!=null && unitInfo.getRatioTwo().compareTo(BigDecimal.ZERO)!=0) {
  1481. count = count.divide(unitInfo.getRatioTwo(),2,BigDecimal.ROUND_HALF_UP);
  1482. }
  1483. if(materialUnit.equals(unitInfo.getOtherUnitThree()) && unitInfo.getRatioThree()!=null && unitInfo.getRatioThree().compareTo(BigDecimal.ZERO)!=0) {
  1484. count = count.divide(unitInfo.getRatioThree(),2,BigDecimal.ROUND_HALF_UP);
  1485. }
  1486. return count;
  1487. }
  1488. @Override
  1489. public List<DepotItemVoBatchNumberList> getBatchNumberList(String number, String name, Long depotId, String barCode,
  1490. String batchNumber, Boolean forceFlag, Boolean inOutManageFlag) throws Exception {
  1491. List<DepotItemVoBatchNumberList> reslist = new ArrayList<>();
  1492. List<DepotItemVoBatchNumberList> list = depotItemMapperEx.getBatchNumberList(StringUtil.toNull(number), name,
  1493. depotId, barCode, batchNumber, forceFlag, inOutManageFlag);
  1494. for(DepotItemVoBatchNumberList bn: list) {
  1495. if(bn.getTotalNum()!=null && bn.getTotalNum().compareTo(BigDecimal.ZERO)>0) {
  1496. bn.setExpirationDateStr(Tools.parseDateToStr(bn.getExpirationDate()));
  1497. if(bn.getUnitId()!=null) {
  1498. Unit unit = unitService.getUnit(bn.getUnitId());
  1499. String commodityUnit = bn.getCommodityUnit();
  1500. bn.setTotalNum(unitService.parseStockByUnit(bn.getTotalNum(), unit, commodityUnit));
  1501. }
  1502. reslist.add(bn);
  1503. }
  1504. }
  1505. return reslist;
  1506. }
  1507. /**
  1508. * 查询某个批号的商品库存
  1509. * @param depotId
  1510. * @param barCode
  1511. * @param batchNumber
  1512. * @return
  1513. * @throws Exception
  1514. */
  1515. @Override
  1516. public BigDecimal getOneBatchNumberStock(Long depotId, String barCode, String batchNumber) {
  1517. BigDecimal totalNum = BigDecimal.ZERO;
  1518. Boolean forceFlag = systemConfigService.getForceApprovalFlag();
  1519. Boolean inOutManageFlag = systemConfigService.getInOutManageFlag();
  1520. List<DepotItemVoBatchNumberList> list = depotItemMapperEx.getBatchNumberList(null, null,
  1521. depotId, barCode, batchNumber, forceFlag, inOutManageFlag);
  1522. if(list!=null && list.size()>0) {
  1523. DepotItemVoBatchNumberList bn = list.get(0);
  1524. totalNum = bn.getTotalNum();
  1525. if(bn.getTotalNum()!=null && bn.getTotalNum().compareTo(BigDecimal.ZERO)>0) {
  1526. if(bn.getUnitId()!=null) {
  1527. Unit unit = unitService.getUnit(bn.getUnitId());
  1528. String commodityUnit = bn.getCommodityUnit();
  1529. totalNum = unitService.parseStockByUnit(bn.getTotalNum(), unit, commodityUnit);
  1530. }
  1531. }
  1532. }
  1533. return totalNum;
  1534. }
  1535. @Override
  1536. public Long getCountByMaterialAndDepot(Long mId, Long depotId) {
  1537. return depotItemMapperEx.getCountByMaterialAndDepot(mId, depotId);
  1538. }
  1539. @Override
  1540. public JSONObject parseMapByExcelData(String barCodes, List<Map<String, String>> detailList, String prefixNo) throws Exception {
  1541. JSONObject map = new JSONObject();
  1542. JSONArray arr = new JSONArray();
  1543. //根据批次号获取商品数据
  1544. List<MaterialVo4Unit> list = depotItemMapperEx.getBillItemByParam(barCodes);
  1545. //商品数据集合
  1546. Map<String, MaterialVo4Unit> materialMap = new HashMap<>();
  1547. //仓库集合
  1548. Map<String, Long> depotMap = new HashMap<>();
  1549. for (MaterialVo4Unit material: list) {
  1550. materialMap.put(material.getSku(), material);
  1551. }
  1552. //获取当前用户所有仓库
  1553. JSONArray depotArr = depotService.findDepotByCurrentUser();
  1554. for (Object depotObj: depotArr) {
  1555. if(depotObj!=null) {
  1556. JSONObject depotObject = JSONObject.parseObject(depotObj.toString());
  1557. depotMap.put(depotObject.getString("depotName"), depotObject.getLong("id"));
  1558. }
  1559. }
  1560. for (Map<String, String> detailMap: detailList) {
  1561. JSONObject item = new JSONObject();
  1562. String barCode = detailMap.get("sku");
  1563. if(StringUtil.isNotEmpty(barCode)) {
  1564. MaterialVo4Unit m = materialMap.get(barCode);
  1565. if(m!=null) {
  1566. //判断仓库是否存在
  1567. String depotName = detailMap.get("depotName");
  1568. if(StringUtil.isNotEmpty(depotName)) {
  1569. if(depotMap.get(depotName)!=null) {
  1570. item.put("depotName", depotName);
  1571. item.put("depotId", depotMap.get(depotName));
  1572. } else {
  1573. throw new BusinessRunTimeException(ExceptionConstants.DEPOT_ITEM_DEPOTNAME_IS_NOT_EXIST_CODE,
  1574. String.format(ExceptionConstants.DEPOT_ITEM_DEPOTNAME_IS_NOT_EXIST_MSG, depotName));
  1575. }
  1576. }
  1577. item.put("barCode", barCode);
  1578. item.put("name", m.getName());
  1579. item.put("standard", m.getStandard());
  1580. if(StringUtil.isNotEmpty(m.getModel())) {
  1581. item.put("model", m.getModel());
  1582. }
  1583. if(StringUtil.isNotEmpty(m.getColor())) {
  1584. item.put("color", m.getColor());
  1585. }
  1586. if(StringUtil.isNotEmpty(m.getSku())) {
  1587. item.put("sku", m.getSku());
  1588. }
  1589. BigDecimal stock = BigDecimal.ZERO;
  1590. if(StringUtil.isNotEmpty(m.getSku())){
  1591. stock = getSkuStockByParam(null, m.getMeId(),null,null);
  1592. } else {
  1593. stock = getCurrentStockByParam(null, m.getId());
  1594. }
  1595. item.put("stock", stock);
  1596. item.put("unit", m.getCommodityUnit());
  1597. BigDecimal operNumber = BigDecimal.ZERO;
  1598. BigDecimal unitPrice = BigDecimal.ZERO;
  1599. BigDecimal taxRate = BigDecimal.ZERO;
  1600. if(StringUtil.isNotEmpty(detailMap.get("num"))) {
  1601. operNumber = new BigDecimal(detailMap.get("num"));
  1602. }
  1603. if(StringUtil.isNotEmpty(detailMap.get("unitPrice"))) {
  1604. unitPrice = new BigDecimal(detailMap.get("unitPrice"));
  1605. } else {
  1606. if("CGDD".equals(prefixNo)) {
  1607. unitPrice = m.getPurchaseDecimal();
  1608. } else if("XSDD".equals(prefixNo)) {
  1609. unitPrice = m.getWholesaleDecimal();
  1610. }
  1611. }
  1612. if(StringUtil.isNotEmpty(detailMap.get("taxRate"))) {
  1613. taxRate = new BigDecimal(detailMap.get("taxRate"));
  1614. }
  1615. String remark = detailMap.get("remark");
  1616. item.put("operNumber", operNumber);
  1617. item.put("unitPrice", unitPrice);
  1618. item.put("productionDate",detailMap.get("productionDate"));
  1619. BigDecimal allPrice = BigDecimal.ZERO;
  1620. if(unitPrice!=null && unitPrice.compareTo(BigDecimal.ZERO)!=0) {
  1621. allPrice = unitPrice.multiply(operNumber);
  1622. }
  1623. BigDecimal taxMoney = BigDecimal.ZERO;
  1624. if(taxRate.compareTo(BigDecimal.ZERO) != 0) {
  1625. taxMoney = taxRate.multiply(allPrice).divide(BigDecimal.valueOf(100), 2, BigDecimal.ROUND_HALF_UP);
  1626. }
  1627. BigDecimal taxLastMoney = allPrice.add(taxMoney);
  1628. item.put("allPrice", allPrice);
  1629. item.put("taxRate", taxRate);
  1630. item.put("taxMoney", taxMoney);
  1631. item.put("taxLastMoney", taxLastMoney);
  1632. item.put("remark", remark);
  1633. item.put("expiryNum",m.getExpiryNum());
  1634. item.put("wholesaleDecimal",m.getDefaultWholesaleDecimal());
  1635. item.put("defaultPurchaseDecimal",m.getDefaultPurchaseDecimal());
  1636. item.put("defaultWholesaleDecimal",m.getDefaultWholesaleDecimal());
  1637. arr.add(item);
  1638. } else {
  1639. throw new BusinessRunTimeException(ExceptionConstants.DEPOT_ITEM_BARCODE_IS_NOT_EXIST_CODE,
  1640. String.format(ExceptionConstants.DEPOT_ITEM_BARCODE_IS_NOT_EXIST_MSG, barCode));
  1641. }
  1642. }
  1643. }
  1644. map.put("rows", arr);
  1645. return map;
  1646. }
  1647. @Override
  1648. public BigDecimal getLastUnitPriceByParam(Long organId, Long meId, String prefixNo) {
  1649. String type = "";
  1650. String subType = "";
  1651. if("XSDD".equals(prefixNo)) {
  1652. type = "其它";
  1653. subType = "销售订单";
  1654. } else if("XSCK".equals(prefixNo)) {
  1655. type = "出库";
  1656. subType = "销售";
  1657. } else if("XSTH".equals(prefixNo)) {
  1658. type = "入库";
  1659. subType = "销售退货";
  1660. } else if("QTCK".equals(prefixNo)) {
  1661. type = "出库";
  1662. subType = "其它";
  1663. }
  1664. return depotItemMapperEx.getLastUnitPriceByParam(organId, meId, type, subType);
  1665. }
  1666. @Override
  1667. public BigDecimal getCurrentStockByParam(Long depotId, Long mId) {
  1668. BigDecimal stock = depotItemMapperEx.getCurrentStockByParam(depotId, mId);
  1669. return stock!=null? stock: BigDecimal.ZERO;
  1670. }
  1671. /**
  1672. * 获取扩展信息
  1673. *
  1674. * @return
  1675. */
  1676. @Override
  1677. public String getOtherInfo(String[] mpArr, DepotItemVo4WithInfoEx diEx)throws Exception {
  1678. String materialOther = "";
  1679. for (int i = 0; i < mpArr.length; i++) {
  1680. if (mpArr[i].equals("自定义1")) {
  1681. materialOther = materialOther + ((diEx.getMOtherField1() == null || diEx.getMOtherField1().equals("")) ? "" : "(" + diEx.getMOtherField1() + ")");
  1682. }
  1683. if (mpArr[i].equals("自定义2")) {
  1684. materialOther = materialOther + ((diEx.getMOtherField2() == null || diEx.getMOtherField2().equals("")) ? "" : "(" + diEx.getMOtherField2() + ")");
  1685. }
  1686. if (mpArr[i].equals("自定义3")) {
  1687. materialOther = materialOther + ((diEx.getMOtherField3() == null || diEx.getMOtherField3().equals("")) ? "" : "(" + diEx.getMOtherField3() + ")");
  1688. }
  1689. }
  1690. return materialOther;
  1691. }
  1692. }