TWarehouseBillsServiceImpl.java 67 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423
  1. package com.ruoyi.warehouseBusiness.service.impl;
  2. import com.alibaba.fastjson.JSONArray;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.ruoyi.basicData.domain.*;
  5. import com.ruoyi.basicData.mapper.*;
  6. import com.ruoyi.common.core.domain.AjaxResult;
  7. import com.ruoyi.common.core.domain.entity.SysDictData;
  8. import com.ruoyi.common.core.domain.entity.SysUser;
  9. import com.ruoyi.common.core.domain.model.LoginUser;
  10. import com.ruoyi.common.utils.DateUtils;
  11. import com.ruoyi.common.utils.StringUtils;
  12. import com.ruoyi.reportManagement.domain.TWhgenleg;
  13. import com.ruoyi.reportManagement.mapper.TWhgenlegMapper;
  14. import com.ruoyi.system.mapper.SysDeptMapper;
  15. import com.ruoyi.system.mapper.SysDictDataMapper;
  16. import com.ruoyi.system.mapper.SysUserMapper;
  17. import com.ruoyi.warehouseBusiness.domain.*;
  18. import com.ruoyi.warehouseBusiness.mapper.*;
  19. import com.ruoyi.warehouseBusiness.service.ITWarehouseBillsService;
  20. import org.springframework.beans.factory.annotation.Autowired;
  21. import org.springframework.stereotype.Service;
  22. import org.springframework.transaction.annotation.Transactional;
  23. import org.springframework.transaction.interceptor.TransactionAspectSupport;
  24. import java.math.BigDecimal;
  25. import java.util.*;
  26. import static java.util.stream.Collectors.toList;
  27. /**
  28. * 详情主表Service业务层处理
  29. *
  30. * @author ruoyi
  31. * @date 2020-12-11
  32. */
  33. @Service
  34. public class TWarehouseBillsServiceImpl implements ITWarehouseBillsService {
  35. @Autowired
  36. private TWhgenlegMapper tWhgenlegMapper;
  37. @Autowired
  38. private TGoodsMapper tGoodsMapper;
  39. @Autowired
  40. private SysDeptMapper sysDeptMapper;
  41. @Autowired
  42. private SysUserMapper sysUserMapper;
  43. @Autowired
  44. private TCorpsMapper tCorpsMapper;
  45. @Autowired
  46. private TFeesMapper tFeesMapper;
  47. @Autowired
  48. private TWarehouseMapper tWarehouseMapper;
  49. @Autowired
  50. private SysDictDataMapper sysDictDataMapper;
  51. @Autowired
  52. private TWarehouseAreaMapper tWarehouseAreaMapper;
  53. @Autowired
  54. private TEnclosureMapper tEnclosureMapper;
  55. @Autowired
  56. private TWarehouseBillsMapper tWarehouseBillsMapper;
  57. @Autowired
  58. private TWarehousebillsfeesMapper tWarehousebillsfeesMapper;
  59. @Autowired
  60. private TWarehousebillsitemsMapper tWarehousebillsitemsMapper;
  61. @Autowired
  62. private BillnoSerialServiceImpl billnoSerialServiceImpl;
  63. @Autowired
  64. private BillnoDelMapper billnoDelMapper;
  65. @Autowired
  66. private TWarehousebillsLogMapper tWarehousebillsLogMapper;
  67. @Autowired
  68. private TWarehouseAgreementServiceImpl tWarehouseAgreementService;
  69. /**
  70. * 查询详情主表
  71. *
  72. * @param fId 详情主表ID
  73. * @return 详情主表
  74. */
  75. @Override
  76. public Map<String, Object> selectTWarehousebillsById(Long fId) {
  77. Map<String, Object> map = new HashMap<>();
  78. // 查询仓库主表数据
  79. TWarehouseBills tWarehousebills = tWarehouseBillsMapper.selectTWarehousebillsById(fId);
  80. // 客户表
  81. List<Long> corpsId = new ArrayList<>();
  82. // 用户表
  83. List<SysUser> sysUserList = new ArrayList<>();
  84. // 仓库表
  85. List<TWarehouse> warehouseList = new ArrayList<>();
  86. // 商品
  87. List<Long> goodsId = new ArrayList<>();
  88. // 费用
  89. List<Long> feesId = new ArrayList<>();
  90. // 库区
  91. List<Long> warehouseAreaId = new ArrayList<>();
  92. if (!StringUtils.isNull(tWarehousebills)) {
  93. if (StringUtils.isNotNull(tWarehousebills.getfTocorpid())) {
  94. corpsId.add(tWarehousebills.getfTocorpid());
  95. }
  96. corpsId.add(tWarehousebills.getfCorpid());
  97. // 查询联系人
  98. SysUser sysUser = sysUserMapper.selectUserByUserName(tWarehousebills.getfStorekeeper());
  99. if (StringUtils.isNotNull(sysUser)) {
  100. sysUserList.add(sysUser);
  101. }
  102. // 查询仓库
  103. TWarehouse tWarehouse = tWarehouseMapper.selectTWarehouseById(tWarehousebills.getfWarehouseid());
  104. if (StringUtils.isNotNull(tWarehouse)) {
  105. warehouseList.add(tWarehouse);
  106. }
  107. // 查询经营单位
  108. corpsId.add(tWarehousebills.getfSbu());
  109. map.put("warehousebills", tWarehousebills);
  110. }
  111. // 查询仓库明细从表数据
  112. TWarehousebillsitems tWarehousebillsitems = new TWarehousebillsitems();
  113. tWarehousebillsitems.setfPid(fId);
  114. List<Map<String, Object>> mapList = tWarehousebillsitemsMapper.selectGoodsTransferitemsList(tWarehousebillsitems);
  115. if (StringUtils.isNotEmpty(mapList)) {
  116. for (Map<String, Object> wb : mapList) {
  117. /*TWhgenleg tWhgenleg = new TWhgenleg();
  118. tWhgenleg.setfCorpid(tWarehousebills.getfCorpid());
  119. if (StringUtils.isNotNull(wb.get("fGoodsid"))) {
  120. tWhgenleg.setfGoodsid(((Integer) wb.get("fGoodsid")).longValue());
  121. }
  122. if (StringUtils.isNotNull(wb.get("fWarehouselocid"))) {
  123. tWhgenleg.setfWarehouseLocationid(((Integer) wb.get("fWarehouselocid")).longValue());
  124. }
  125. tWhgenleg.setfTrademodeid(tWarehousebills.getfTrademodeid());
  126. tWhgenleg.setfMblno(tWarehousebills.getfMblno());
  127. TWhgenleg whgenleg = tWhgenlegMapper.selectTWhgenleg(tWhgenleg);
  128. if (StringUtils.isNotNull(whgenleg)) {
  129. wb.put("fQtyblc", whgenleg.getfQtyblc());
  130. }*/
  131. if (StringUtils.isNotNull(wb.get("fGoodsid"))) {
  132. Integer fGoodsid = (Integer) wb.get("fGoodsid");
  133. goodsId.add(fGoodsid.longValue());
  134. }
  135. if (StringUtils.isNotNull(wb.get("fWarehouselocid"))) {
  136. Integer fWarehouselocid = (Integer) wb.get("fWarehouselocid");
  137. warehouseAreaId.add(fWarehouselocid.longValue());
  138. }
  139. }
  140. map.put("warehouseBillsItem", mapList);
  141. }
  142. // 查询仓库费用明细表数据
  143. TWarehousebillsfees tWarehousebillsfees = new TWarehousebillsfees();
  144. tWarehousebillsfees.setfPid(fId);
  145. List<TWarehousebillsfees> warehousebillsfeesDr = new ArrayList<>();
  146. List<TWarehousebillsfees> warehousebillsfeesCr = new ArrayList<>();
  147. List<TWarehousebillsfees> warehousebillsfees = tWarehousebillsfeesMapper.selectTWarehousebillsfeesList(tWarehousebillsfees);
  148. if (StringUtils.isNotEmpty(warehousebillsfees)) {
  149. for (TWarehousebillsfees fees : warehousebillsfees) {
  150. if ("C".equals(fees.getfDc())) {
  151. warehousebillsfeesCr.add(fees);
  152. } else {
  153. warehousebillsfeesDr.add(fees);
  154. }
  155. corpsId.add(fees.getfCorpid());
  156. feesId.add(fees.getfFeeid());
  157. }
  158. }
  159. // 查询附件表数据
  160. TEnclosure enclosure = new TEnclosure();
  161. enclosure.setfPid(fId);
  162. List<TEnclosure> enclosures = tEnclosureMapper.selectTEnclosureList(enclosure);
  163. if (StringUtils.isNotEmpty(enclosures)) {
  164. map.put("enclosures", enclosures);
  165. }
  166. List<TCorps> corpsList = new ArrayList<>();
  167. List<Long> corpsIdList = StringUtils.integerDeduplication(corpsId);
  168. for (Long corpId : corpsIdList) {
  169. TCorps corps = tCorpsMapper.selectTCorpsById(corpId);
  170. if (StringUtils.isNotNull(corps)) {
  171. corpsList.add(corps);
  172. }
  173. }
  174. List<TWarehouseArea> warehouseAreaList = new ArrayList<>();
  175. List<Long> warehouseAreaIdList = StringUtils.integerDeduplication(warehouseAreaId);
  176. for (Long warehouseArea : warehouseAreaIdList) {
  177. TWarehouseArea tWarehouseArea = tWarehouseAreaMapper.selectTWarehouseAreaById(warehouseArea);
  178. if (StringUtils.isNotNull(tWarehouseArea)) {
  179. warehouseAreaList.add(tWarehouseArea);
  180. }
  181. }
  182. List<TGoods> goodsList = new ArrayList<>();
  183. List<Long> goodsIdList = StringUtils.integerDeduplication(goodsId);
  184. for (Long goods : goodsIdList) {
  185. TGoods tGoods = tGoodsMapper.selectTGoodsById(goods);
  186. if (StringUtils.isNotNull(tGoods)) {
  187. goodsList.add(tGoods);
  188. }
  189. }
  190. List<TFees> feesList = new ArrayList<>();
  191. List<Long> longList = StringUtils.integerDeduplication(feesId);
  192. for (Long fees : longList) {
  193. TFees tFees = tFeesMapper.selectTFeesById(fees);
  194. if (StringUtils.isNotNull(tFees)) {
  195. feesList.add(tFees);
  196. }
  197. }
  198. map.put("corps", corpsList);
  199. map.put("goodsList", goodsList);
  200. map.put("feesList", feesList);
  201. map.put("sysUser", sysUserList);
  202. map.put("warehouse", warehouseList);
  203. map.put("warehouseAreas", warehouseAreaList);
  204. map.put("warehousebillsfeesDr", warehousebillsfeesDr);
  205. map.put("warehousebillsfeesCr", warehousebillsfeesCr);
  206. map.put("dept", sysDeptMapper.selectDeptById(tWarehousebills.getfDeptid()));
  207. return map;
  208. }
  209. /**
  210. * 查询详情主表列表
  211. *
  212. * @param tWarehousebills 详情主表
  213. * @return 详情主表
  214. */
  215. @Override
  216. public List<Map<String, Object>> selectWarehouseBusinessList(TWarehouseBills tWarehousebills) {
  217. return tWarehouseBillsMapper.selectWarehouseBusinessList(tWarehousebills);
  218. }
  219. /**
  220. * 查询导出所需主表列表
  221. *
  222. * @param tWarehousebills 详情主表
  223. * @return 详情主表
  224. */
  225. @Override
  226. public List<TWarehouseBills> selectTWarehousebillsList(TWarehouseBills tWarehousebills) {
  227. return tWarehouseBillsMapper.selectTWarehousebillsList(tWarehousebills);
  228. }
  229. /**
  230. * 根据条件查询总账是否存在
  231. *
  232. * @param warehouseBills 仓库主表
  233. * @param warehousebillsitems 仓库明细表
  234. * @return 库存总账
  235. */
  236. public TWhgenleg queryTWhgenleg(TWarehouseBills warehouseBills, TWarehousebillsitems warehousebillsitems) {
  237. TWhgenleg tWhgenleg = new TWhgenleg();
  238. // 客户
  239. tWhgenleg.setfCorpid(warehouseBills.getfCorpid());
  240. // 提单号
  241. if ("HQZY".equals(warehouseBills.getfBilltype())) {
  242. tWhgenleg.setfMblno(warehousebillsitems.getfMblno());
  243. } else {
  244. tWhgenleg.setfMblno(warehouseBills.getfMblno());
  245. }
  246. // 库区
  247. tWhgenleg.setfWarehouseLocationid(warehousebillsitems.getfWarehouselocid());
  248. // 货物品名
  249. tWhgenleg.setfGoodsid(warehousebillsitems.getfGoodsid());
  250. // 贸易方式
  251. tWhgenleg.setfTrademodeid(warehouseBills.getfTrademodeid());
  252. return tWhgenlegMapper.selectTWhgenleg(tWhgenleg);
  253. }
  254. /**
  255. * 新增库存总账
  256. *
  257. * @param warehouseBills 仓库主表
  258. * @param warehousebillsitems 仓库明细表
  259. * @return 结果
  260. */
  261. @Transactional
  262. public int instalTWhgenleg(TWarehouseBills warehouseBills, TWarehousebillsitems warehousebillsitems, SysUser user) {
  263. TWhgenleg tWhgenleg = new TWhgenleg();
  264. if ("SJRK".equals(warehouseBills.getfBilltype()) || "HQZY".equals(warehouseBills.getfBilltype())) {
  265. tWhgenleg.setfOriginalbilldate(new Date());
  266. }
  267. // 客户
  268. tWhgenleg.setfCorpid(warehouseBills.getfCorpid());
  269. // 提单号
  270. tWhgenleg.setfMblno(warehouseBills.getfMblno());
  271. // 原始单号
  272. tWhgenleg.setfOriginalbillno(warehouseBills.getfMblno());
  273. // 仓库
  274. tWhgenleg.setfWarehouseid(warehouseBills.getfWarehouseid());
  275. // 库区
  276. tWhgenleg.setfWarehouseLocationid(warehousebillsitems.getfWarehouselocid());
  277. // 货物品名
  278. tWhgenleg.setfGoodsid(warehousebillsitems.getfGoodsid());
  279. // 计费方式
  280. tWhgenleg.setfBillingway(warehousebillsitems.getfBillingway());
  281. // 仓储计费日期
  282. tWhgenleg.setfChargedate(warehousebillsitems.getfChargedate());
  283. // 贸易方式
  284. tWhgenleg.setfTrademodeid(warehouseBills.getfTrademodeid());
  285. // 入库数
  286. tWhgenleg.setfQtyd(warehousebillsitems.getfQty());
  287. // 入库尺码
  288. tWhgenleg.setfVolumnd(warehousebillsitems.getfVolumn());
  289. // 唛头
  290. tWhgenleg.setfMarks(warehousebillsitems.getfMarks());
  291. // 入库毛重
  292. tWhgenleg.setfGrossweightd(warehousebillsitems.getfGrossweight());
  293. // 入库净重
  294. tWhgenleg.setfNetweightd(warehousebillsitems.getfNetweight());
  295. // 入库箱号
  296. tWhgenleg.setfCntrno(warehousebillsitems.getfCntrno());
  297. // 创建人
  298. tWhgenleg.setCreateBy(user.getUserName());
  299. // 创建人
  300. tWhgenleg.setCreateTime(new Date());
  301. // 状态
  302. tWhgenleg.setfStatus("T");
  303. // 结余件数
  304. tWhgenleg.setfQtyblc(warehousebillsitems.getfQty());
  305. System.out.println("主表新增:" + warehouseBills.toString());
  306. System.out.println("要添加的总账:" + tWhgenleg.toString());
  307. return tWhgenlegMapper.insertTWhgenleg(tWhgenleg);
  308. }
  309. @Transactional
  310. public int updateTWhgenlegData(TWarehousebillsitems warehousebillsitems, long whgenlegId, String billtype) {
  311. Map<String, Object> map = new HashMap<>();
  312. map.put("whgenlegId", whgenlegId);
  313. map.put("billType", billtype);
  314. map.put("warehousebillsitems", warehousebillsitems);
  315. return tWhgenlegMapper.updateTWhgenlegData(map);
  316. }
  317. /**
  318. * 新增详情主表
  319. *
  320. * @param tWarehouseBills 仓库主表
  321. * @param tWarehousebillsfeesCr 仓库费付款用明细表
  322. * @param tWarehousebillsfeesDr 仓库费收
  323. * 款用明细表
  324. * @param tWarehousebillsitems 仓库货物明细表
  325. * @param loginUser 当前登陆人
  326. * @param billsType 判断标识
  327. * @return 结果
  328. */
  329. @Override
  330. @Transactional
  331. public AjaxResult insertTWarehousebills(String tWarehouseBills, String tWarehousebillsfeesCr, String tWarehousebillsfeesDr
  332. , String tWarehousebillsitems, String tWhgenleg, LoginUser loginUser, String billsType) {
  333. Long fPid = null;
  334. Map<String, Object> map = new HashMap<>();
  335. TWarehouseBills warehouseBills = JSONArray.parseObject(tWarehouseBills, TWarehouseBills.class);
  336. if (StringUtils.isNull(warehouseBills.getfId())) {
  337. // 如果是新数据
  338. warehouseBills.setCreateBy(loginUser.getUser().getUserName());
  339. warehouseBills.setfChargedate(warehouseBills.getfBsdate());
  340. warehouseBills.setfBilltype(billsType);
  341. warehouseBills.setfBsdeptid(loginUser.getUser().getDeptId());
  342. // 业务编码
  343. String billNo = billnoSerialServiceImpl.getBillNo(billsType, warehouseBills.getfBsdate());
  344. warehouseBills.setfBillno(billNo);
  345. // 存货编码
  346. Date time = new Date();
  347. String bscorpno = billnoSerialServiceImpl.getCorpNo(warehouseBills.getfCorpid(), time);
  348. warehouseBills.setfBscorpno(bscorpno);
  349. tWarehouseBillsMapper.insertTWarehousebills(warehouseBills);
  350. fPid = warehouseBills.getfId();
  351. } else {
  352. fPid = warehouseBills.getfId();
  353. warehouseBills.setfChargedate(warehouseBills.getfBsdate());
  354. warehouseBills.setUpdateBy(loginUser.getUser().getUserName());
  355. warehouseBills.setUpdateTime(new Date());
  356. tWarehouseBillsMapper.updateTWarehousebills(warehouseBills);
  357. tWarehousebillsfeesMapper.deleteByFPid(fPid);
  358. tEnclosureMapper.deleteByFPid(fPid);
  359. // 删除 从表中 未打印账单的数据
  360. deleteBillsitems(fPid, tWarehousebillsitems);
  361. }
  362. // 库存明细添加
  363. List<TWarehousebillsitems> tWarehousebillsitemsList = new ArrayList<>();
  364. if (tWarehousebillsitems != null) {
  365. JSONArray warehouseJSON = JSONArray.parseArray(tWarehousebillsitems);
  366. List<TWarehousebillsitems> warehousebillsitemsList = JSONObject.parseArray(warehouseJSON.toJSONString(), TWarehousebillsitems.class);
  367. for (TWarehousebillsitems wbItem : warehousebillsitemsList) {
  368. // 仓储计费日期
  369. wbItem.setfChargedate(warehouseBills.getfChargedate());
  370. wbItem.setfBilltype(billsType);
  371. if (null != wbItem.getfId()) {
  372. wbItem.setUpdateBy(loginUser.getUser().getUserName());
  373. wbItem.setUpdateTime(new Date());
  374. tWarehousebillsitemsMapper.updateTWarehousebillsitems(wbItem);
  375. } else {
  376. // 添加主表 业务单号
  377. wbItem.setfBillno(warehouseBills.getfBillno());
  378. wbItem.setfMblno(warehouseBills.getfMblno());
  379. wbItem.setfPid(fPid);
  380. wbItem.setCreateBy(loginUser.getUser().getUserName());
  381. wbItem.setCreateTime(new Date());
  382. wbItem.setfBillstatus(10L);
  383. tWarehousebillsitemsMapper.insertTWarehousebillsitems(wbItem);
  384. if (!billsType.equals("HQZY")) {
  385. // 添加状态log
  386. insertTWarehousebillsLog(wbItem, 10L, loginUser);
  387. }
  388. }
  389. tWarehousebillsitemsList.add(wbItem);
  390. }
  391. // 录入库存明细整体状态 --> 更新主表 入账状态
  392. updateWarehousebillsItemsStatus(warehouseBills);
  393. }
  394. // 附件添加
  395. if (StringUtils.isNotNull(tWhgenleg)) {
  396. JSONArray jsonDrArray = JSONArray.parseArray(tWhgenleg);
  397. List<TEnclosure> tEnclosureList = JSONObject.parseArray(jsonDrArray.toJSONString(), TEnclosure.class);
  398. for (TEnclosure tEnclosure : tEnclosureList) {
  399. tEnclosure.setfPid(fPid);
  400. tEnclosure.setCreateBy(loginUser.getUser().getUserName());
  401. tEnclosure.setCreateTime(new Date());
  402. tEnclosureMapper.insertTEnclosure(tEnclosure);
  403. }
  404. }
  405. // 收款明细添加
  406. if (tWarehousebillsfeesDr != null) {
  407. JSONArray jsonDrArray = JSONArray.parseArray(tWarehousebillsfeesDr);
  408. List<TWarehousebillsfees> warehousebillsfeesDrList = JSONObject.parseArray(jsonDrArray.toJSONString(), TWarehousebillsfees.class);
  409. for (TWarehousebillsfees wbDr : warehousebillsfeesDrList) {
  410. // 检验 数量*单价=金额
  411. wbDr.setfPid(fPid);
  412. wbDr.setfDc("D");
  413. wbDr.setCreateBy(loginUser.getUser().getUserName());
  414. wbDr.setCreateTime(new Date());
  415. tWarehousebillsfeesMapper.insertTWarehousebillsfees(wbDr);
  416. }
  417. }
  418. // 付款明细添加
  419. if (tWarehousebillsfeesCr != null) {
  420. JSONArray jsonCrArray = JSONArray.parseArray(tWarehousebillsfeesCr);
  421. List<TWarehousebillsfees> warehousebillsfeesCrList = JSONObject.parseArray(jsonCrArray.toJSONString(), TWarehousebillsfees.class);
  422. for (TWarehousebillsfees wbCr : warehousebillsfeesCrList) {
  423. wbCr.setfPid(fPid);
  424. wbCr.setfDc("C");
  425. wbCr.setCreateBy(loginUser.getUser().getUserName());
  426. wbCr.setCreateTime(new Date());
  427. tWarehousebillsfeesMapper.insertTWarehousebillsfees(wbCr);
  428. }
  429. }
  430. if ("2".equals(warehouseBills.getfBillstatus())) {
  431. map.put("warehouseBills", warehouseBills);
  432. map.put("warehousebillsitems", tWarehousebillsitemsList);
  433. return AjaxResult.success("成功", map);
  434. }
  435. return AjaxResult.success();
  436. }
  437. /**
  438. * 入库详情入账
  439. *
  440. * @param warehouseBills 主表
  441. * @param warehousebillsitems 明细
  442. * @param loginUser 当前登录人
  443. * @param billsType 状态
  444. * @return 结果
  445. */
  446. @Override
  447. @Transactional
  448. public AjaxResult addCredit(String warehouseBills, String warehousebillsitems, LoginUser loginUser, String billsType) {
  449. Long fPid = null;
  450. Map<String, Object> map = new HashMap<>();
  451. if (StringUtils.isNull(warehouseBills) || "[]".equals(warehouseBills)) {
  452. return AjaxResult.error("未找到主表信息");
  453. }
  454. if (StringUtils.isNull(warehousebillsitems) || "[]".equals(warehousebillsitems)) {
  455. return AjaxResult.error("未找到入账信息");
  456. }
  457. TWarehouseBills tWarehouseBills = JSONArray.parseObject(warehouseBills, TWarehouseBills.class);
  458. if (StringUtils.isNotNull(tWarehouseBills.getfId())) {
  459. tWarehouseBills.setUpdateBy(loginUser.getUser().getUserName());
  460. tWarehouseBills.setUpdateTime(new Date());
  461. tWarehouseBillsMapper.updateTWarehousebills(tWarehouseBills);
  462. }
  463. JSONArray warehouseJSON = JSONArray.parseArray(warehousebillsitems);
  464. List<TWarehousebillsitems> warehousebillsitemsList = JSONObject.parseArray(warehouseJSON.toJSONString(), TWarehousebillsitems.class);
  465. for (TWarehousebillsitems item : warehousebillsitemsList) {
  466. // 查询库容量 是否可入库
  467. int m = calculation(tWarehouseBills.getfWarehouseid(), item.getfGrossweight());
  468. if (m == 0) {
  469. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  470. return AjaxResult.error("更新库存总账失败-->入库毛重大于库容");
  471. }
  472. item.setfBillingway(tWarehouseBills.getfBillingway());
  473. item.setfChargedate(tWarehouseBills.getfChargedate());
  474. TWhgenleg tWhgenle = queryTWhgenleg(tWarehouseBills, item);
  475. if (StringUtils.isNotNull(tWhgenle)) {
  476. int i = updateTWhgenlegData(item, tWhgenle.getfId(), billsType);
  477. if (i <= 0) {
  478. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  479. return AjaxResult.error("更新库存总账失败");
  480. }
  481. } else {
  482. if (instalTWhgenleg(tWarehouseBills, item, loginUser.getUser()) <= 0) {
  483. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  484. return AjaxResult.error("新增库存总账失败");
  485. }
  486. }
  487. int num = 0;
  488. if (StringUtils.isNotNull(item.getfId())) {
  489. item.setfBillstatus(40L);
  490. item.setUpdateBy(loginUser.getUser().getUserName());
  491. item.setUpdateTime(new Date());
  492. num = tWarehousebillsitemsMapper.updateTWarehousebillsitems(item);
  493. // 添加状态log
  494. insertTWarehousebillsLog(item, 40L, loginUser);
  495. }
  496. if (num <= 0) {
  497. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  498. return AjaxResult.error("新增库存明细失败");
  499. }
  500. }
  501. // 查询所有库存明细 修改仓库主表状态
  502. updateWarehousebillsItemsStatus(tWarehouseBills);
  503. map.put("warehousebillsitems", warehousebillsitemsList);
  504. return AjaxResult.success("成功", map);
  505. }
  506. /**
  507. * 出库、调拨、货转 确认
  508. *
  509. * @param warehouseBills
  510. * @param warehousebillsitems
  511. * @param loginUser
  512. * @param billsType
  513. * @return
  514. */
  515. @Override
  516. @Transactional
  517. public AjaxResult updateCredit(String warehouseBills, String warehousebillsitems, LoginUser loginUser, String billsType) {
  518. Long fPid = null;
  519. Map<String, Object> map = new HashMap<>();
  520. if (StringUtils.isNull(warehouseBills) || "[]".equals(warehouseBills)) {
  521. return AjaxResult.error("未找到主表信息");
  522. }
  523. if (StringUtils.isNull(warehousebillsitems) || "[]".equals(warehousebillsitems)) {
  524. return AjaxResult.error("未找到入账信息");
  525. }
  526. TWarehouseBills tWarehouseBills = JSONArray.parseObject(warehouseBills, TWarehouseBills.class);
  527. if (StringUtils.isNotNull(tWarehouseBills.getfId())) {
  528. tWarehouseBills.setUpdateBy(loginUser.getUser().getUserName());
  529. tWarehouseBills.setUpdateTime(new Date());
  530. tWarehouseBillsMapper.updateTWarehousebills(tWarehouseBills);
  531. fPid = tWarehouseBills.getfId();
  532. }
  533. JSONArray warehouseJSON = JSONArray.parseArray(warehousebillsitems);
  534. List<TWarehousebillsitems> warehousebillsitemsList = JSONObject.parseArray(warehouseJSON.toJSONString(), TWarehousebillsitems.class);
  535. int i = 1;
  536. List<TFees> feesList = new ArrayList<>();
  537. List<TWarehousebillsfees> warehousebillsfees = new ArrayList<>();
  538. for (TWarehousebillsitems wbItem : warehousebillsitemsList) {
  539. // 查询总账是否存在
  540. TWhgenleg tWhgenle = queryTWhgenleg(tWarehouseBills, wbItem);
  541. // 入库数特殊不判断入账
  542. if ("SJCK".equals(billsType)) { // 出库 查询
  543. if (StringUtils.isNull(tWhgenle)) { // 为空 提示没有库存
  544. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  545. return AjaxResult.error("库存明细第" + i + "行库存为空");
  546. } else { // 非空修改库存总账
  547. // 库存 < 出库件数 、
  548. if (tWhgenle.getfQtyblc() < wbItem.getfQty()) {
  549. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  550. return AjaxResult.error("库存明细第" + i + "行库存不足");
  551. }
  552. // 更新库存总账
  553. updateTWhgenlegData(wbItem, tWhgenle.getfId(), billsType);
  554. if (StringUtils.isNull(tWarehouseBills.getfBsdate()) || StringUtils.isNull(wbItem.getfChargedate())) {
  555. return AjaxResult.error("库存明细第" + i + "行请检查日期,操作终止");
  556. }
  557. long dateDay = DateUtils.getDateDay(tWarehouseBills.getfBsdate(), wbItem.getfChargedate());
  558. if (StringUtils.isNull(tWarehouseBills.getfCorpid())) {
  559. return AjaxResult.error("库存明细第" + i + "行请检查客户信息,操作终止");
  560. }
  561. /*long fCorpid = tWarehouseBills.getfCorpid();
  562. TGoods tGoods = tGoodsMapper.selectTGoodsById(wbItem.getfGoodsid());
  563. long fGoodsid = tGoods.getfTypeid();
  564. long fBillingway = wbItem.getfBillingway();
  565. long fQty = wbItem.getfQty();
  566. // 计算仓储费明细
  567. Map<String, Object> objectMap = tWarehouseAgreementService.getCarryingCost(fCorpid, fGoodsid, dateDay, fBillingway, fQty , 0L);
  568. if (StringUtils.isNull(objectMap)) {
  569. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  570. return AjaxResult.error("库存明细第" + i + "行没有维护出库明细的仓储协议,操作终止");
  571. }
  572. Long feeId = (Long) objectMap.get("feeId");
  573. BigDecimal amt = (BigDecimal) objectMap.get("amt");
  574. TFees tFees = tFeesMapper.selectTFeesById(feeId);
  575. if (StringUtils.isNotNull(tFees)) {
  576. feesList.add(tFees);
  577. }
  578. TWarehousebillsfees fees = new TWarehousebillsfees();
  579. fees.setfPid(fPid);
  580. fees.setfFeeid(feeId);
  581. fees.setfCorpid(tWarehouseBills.getfCorpid());
  582. fees.setfFeeUnitid(fBillingway);
  583. fees.setfQty(new BigDecimal(1));
  584. fees.setfUnitprice(amt);
  585. fees.setfAmount(amt);
  586. fees.setfExrate(new BigDecimal(1));
  587. fees.setfCurrency("RMB");
  588. fees.setRemark(dateDay + "天" + tFees.getfName());
  589. warehousebillsfees.add(fees);*/
  590. }
  591. } else if ("CKDB".equals(billsType)) { // 调拨查询
  592. if (StringUtils.isNull(tWhgenle)) { // 为空 提示没有库存
  593. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  594. return AjaxResult.error("库存明细第" + i + "行库存为空");
  595. } else { // 非空修改库存总账
  596. if (tWhgenle.getfQtyblc() < wbItem.getfQty()) { // 1、 库存 < 调拨件数 提示库存不足
  597. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  598. return AjaxResult.error("库存明细第" + i + "行库存不足");
  599. } else { // 2、 库存足够 先 进行出库操作
  600. updateTWhgenlegData(wbItem, tWhgenle.getfId(), "SJCK");
  601. }
  602. // 3、 进行入库操作 查询是否存在库存
  603. tWarehouseBills.setfCorpid(tWarehouseBills.getfTocorpid()); // 新货权方
  604. TWhgenleg tWhgenle1 = queryTWhgenleg(tWarehouseBills, wbItem);
  605. if (StringUtils.isNull(tWhgenle1)) { // 5、 不存在 进行新增库存
  606. instalTWhgenleg(tWarehouseBills, wbItem, loginUser.getUser());
  607. } else { // 4、 存在 进行跟新库存
  608. updateTWhgenlegData(wbItem, tWhgenle1.getfId(), "SJRK");
  609. }
  610. }
  611. } else if ("HQZY".equals(billsType)) { // 货转
  612. if (StringUtils.isNull(tWhgenle)) { // 为空 提示没有库存
  613. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  614. return AjaxResult.error("库存明细第" + i + "行库存为空");
  615. } else { // 非空修改库存总账
  616. if (tWhgenle.getfQtyblc() < wbItem.getfQty()) { // 1、 库存 < 调拨件数 提示库存不足
  617. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  618. return AjaxResult.error("库存明细第" + i + "行库存不足");
  619. } else { // 2、 库存足够 先 进行出库操作
  620. updateTWhgenlegData(wbItem, tWhgenle.getfId(), "SJCK");
  621. }
  622. // 3、 进行入库操作 查询是否存在库存
  623. tWarehouseBills.setfCorpid(tWarehouseBills.getfTocorpid()); // 新货权方
  624. TWhgenleg tWhgenle1 = queryTWhgenleg(tWarehouseBills, wbItem);
  625. if (StringUtils.isNull(tWhgenle1)) { // 5、 不存在 进行新增库存
  626. instalTWhgenleg(tWarehouseBills, wbItem, loginUser.getUser());
  627. } else { // 4、 存在 进行跟新库存
  628. updateTWhgenlegData(wbItem, tWhgenle1.getfId(), "SJRK");
  629. }
  630. }
  631. }
  632. i++;
  633. int num = 0;
  634. if (StringUtils.isNotNull(wbItem.getfId())) {
  635. wbItem.setfBillstatus(40L);
  636. wbItem.setfBsdate(tWarehouseBills.getfBsdate());
  637. wbItem.setUpdateBy(loginUser.getUser().getUserName());
  638. wbItem.setUpdateTime(new Date());
  639. num = tWarehousebillsitemsMapper.updateTWarehousebillsitems(wbItem);
  640. if ("SJCK".equals(billsType)) {
  641. // 添加状态log
  642. insertTWarehousebillsLog(wbItem, 40L, loginUser);
  643. }
  644. }
  645. if (num <= 0) {
  646. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  647. return AjaxResult.error("库存明细更新失败");
  648. }
  649. }
  650. // 查询所有库存明细 修改仓库主表状态
  651. updateWarehousebillsItemsStatus(tWarehouseBills);
  652. map.put("fPid", fPid);
  653. map.put("fees", feesList);
  654. map.put("warehousebillsfees", warehousebillsfees);
  655. // 添加成功 主键返回 前台
  656. return AjaxResult.success("成功", map);
  657. }
  658. @Override
  659. public AjaxResult waitWarehousing(String warehouseBills, String warehousebillsitems, LoginUser loginUser, Long status, String billtystatus) {
  660. Map<String, Object> map = new HashMap<>();
  661. if (StringUtils.isNull(warehouseBills) || "[]".equals(warehouseBills)) {
  662. return AjaxResult.error("未找到主表信息");
  663. }
  664. if (StringUtils.isNull(warehousebillsitems) || "[]".equals(warehousebillsitems)) {
  665. return AjaxResult.error("未找到入账信息");
  666. }
  667. TWarehouseBills tWarehouseBills = JSONArray.parseObject(warehouseBills, TWarehouseBills.class);
  668. if (StringUtils.isNotNull(tWarehouseBills.getfId())) {
  669. tWarehouseBills.setUpdateBy(loginUser.getUser().getUserName());
  670. tWarehouseBills.setUpdateTime(new Date());
  671. tWarehouseBillsMapper.updateTWarehousebills(tWarehouseBills);
  672. }
  673. List<TWarehousebillsitems> tWarehousebillsitemsList = new ArrayList<>();
  674. JSONArray warehouseJSON = JSONArray.parseArray(warehousebillsitems);
  675. List<TWarehousebillsitems> warehousebillsitemsList = JSONObject.parseArray(warehouseJSON.toJSONString(), TWarehousebillsitems.class);
  676. for (TWarehousebillsitems item : warehousebillsitemsList) {
  677. // 生成流水号
  678. Date time = new Date();
  679. String serialNumber;
  680. if (billtystatus.equals("20")) { // 生成 入库 流水号
  681. serialNumber = billnoSerialServiceImpl.getSerialNumber("RK", time);
  682. item.setfSerialNumber(serialNumber);
  683. } else if (billtystatus.equals("70")) { //生成 出库 流水号
  684. serialNumber = billnoSerialServiceImpl.getSerialNumber("CK", time);
  685. item.setfSerialNumber(serialNumber);
  686. }
  687. int num = 0;
  688. if (StringUtils.isNotNull(item.getfId())) {
  689. item.setfBillstatus(status);
  690. item.setUpdateTime(new Date());
  691. item.setUpdateBy(loginUser.getUser().getUserName());
  692. num = tWarehousebillsitemsMapper.updateTWarehousebillsitems(item);
  693. // 添加状态log
  694. insertTWarehousebillsLog(item, status, loginUser);
  695. } else {
  696. item.setfPid(tWarehouseBills.getfId());
  697. item.setfBillno(tWarehouseBills.getfBillno());
  698. item.setfBillstatus(status);
  699. item.setCreateTime(new Date());
  700. item.setCreateBy(loginUser.getUser().getUserName());
  701. num = tWarehousebillsitemsMapper.insertTWarehousebillsitems(item);
  702. // 添加状态log
  703. insertTWarehousebillsLog(item, 10L, loginUser);
  704. insertTWarehousebillsLog(item, status, loginUser);
  705. }
  706. if (num <= 0) {
  707. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  708. return AjaxResult.error("更新库存明细失败");
  709. }
  710. tWarehousebillsitemsList.add(item);
  711. }
  712. // 添加成功 返回 前台
  713. map.put("warehousebillsitems", tWarehousebillsitemsList);
  714. return AjaxResult.success("成功", map);
  715. }
  716. public Map<String, Object> getWarehouseItems(TWarehouseBills warehouseBills, List<Map<String, Object>> mapItem, LoginUser loginUser) {
  717. Map<String, Object> map = new HashMap<>();
  718. long feeId = 0L;
  719. BigDecimal sumAmt = new BigDecimal(0);
  720. List<TWarehousebillsitems> itemsList = new ArrayList<>();
  721. for (Map<String, Object> item : mapItem) {
  722. if (StringUtils.isNull(item.get("fBillingway"))) {
  723. map.put("error", "单号:" + item.get("fBillno") + ",业务日期:" + item.get("fBsdate") + "未找到库存总账的计费单位,请确认");
  724. return map;
  725. }
  726. long fGoodsid = Long.parseLong((String) item.get("fTypeid"));
  727. long fCorpid = warehouseBills.getfCorpid();
  728. long dateDay = DateUtils.getDateDay(warehouseBills.getfBillingDeadline(), (Date) item.get("fChargedate"));
  729. long fInventoryDays = DateUtils.getDateDay(warehouseBills.getfBillingDeadline(), (Date) item.get("fOriginalbilldate"));
  730. Long dictLabel = Long.valueOf(String.valueOf(item.get("fBillingway")));
  731. BigDecimal fQty = this.acquiredQuantity(item, dictLabel);
  732. if (fQty.equals(BigDecimal.ZERO)) {
  733. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  734. return AjaxResult.error("单号:" + item.get("fBillno") + ",业务日期:" + item.get("fBsdate") + "未找到计费单位,请确认");
  735. }
  736. // 计算仓储费明细
  737. Map<String, Object> objectMap = tWarehouseAgreementService.getCarryingCost(fCorpid, fGoodsid, dateDay, dictLabel, fQty, fInventoryDays);
  738. if (StringUtils.isNull(objectMap)) {
  739. map.put("error", "单号:" + item.get("fBillno") + ",业务日期:" + item.get("fBsdate") + "未找到仓储费协议,请确认");
  740. return map;
  741. }
  742. String fBilltype = (String) objectMap.get("fBilltype");
  743. feeId = Long.valueOf(String.valueOf(objectMap.get("feeId"))).longValue();
  744. BigDecimal amt = (BigDecimal) objectMap.get("amt");
  745. map.put("feeId", feeId);
  746. map.put("itemFeeId", objectMap.get("feeId"));
  747. sumAmt = sumAmt.add(amt);
  748. TWarehousebillsitems tWarehousebillsitems = new TWarehousebillsitems();
  749. tWarehousebillsitems.setfAmt(amt);
  750. tWarehousebillsitems.setfBillstatus(50L);
  751. tWarehousebillsitems.setfBillingQty(fQty);
  752. tWarehousebillsitems.setfBilltype(fBilltype);
  753. tWarehousebillsitems.setfBillingDays(dateDay);
  754. tWarehousebillsitems.setCreateTime(new Date());
  755. tWarehousebillsitems.setfPid(warehouseBills.getfId());
  756. tWarehousebillsitems.setfInventoryDays(fInventoryDays);
  757. tWarehousebillsitems.setfBsdate((Date) item.get("fBsdate"));
  758. tWarehousebillsitems.setfBillno((String) item.get("fBillno"));
  759. tWarehousebillsitems.setfGoodsid(Long.valueOf(String.valueOf(item.get("fGoodsid"))).longValue());
  760. tWarehousebillsitems.setCreateBy(loginUser.getUser().getUserName());
  761. tWarehousebillsitems.setfBillingway(Long.valueOf(String.valueOf(item.get("fBillingway"))).longValue());
  762. tWarehousebillsitems.setfChargedate((Date) item.get("fChargedate"));
  763. tWarehousebillsitems.setfOriginalbilldate((Date) item.get("fOriginalbilldate"));
  764. tWarehousebillsitems.setfBillingDeadline(warehouseBills.getfBillingDeadline());
  765. tWarehousebillsitemsMapper.insertTWarehousebillsitems(tWarehousebillsitems);
  766. itemsList.add(tWarehousebillsitems);
  767. }
  768. TWarehousebillsfees fees = new TWarehousebillsfees();
  769. fees.setfPid(warehouseBills.getfId());
  770. fees.setfFeeid(feeId);
  771. fees.setfCorpid(warehouseBills.getfCorpid());
  772. fees.setfFeeunitid(2L);
  773. fees.setfQty(new BigDecimal(1));
  774. fees.setfUnitprice(sumAmt);
  775. fees.setfAmount(sumAmt);
  776. fees.setfExrate(new BigDecimal(1));
  777. fees.setfCurrency("RMB");
  778. List<SysDictData> taxRate = sysDictDataMapper.selectDictDataByType("tax_rate");
  779. fees.setfDc("D");
  780. fees.setfTaxrate(new BigDecimal(taxRate.get(0).getDictValue()));
  781. fees.setCreateBy(loginUser.getUser().getUserName());
  782. fees.setCreateTime(new Date());
  783. map.put("fees", fees);
  784. map.put("sumAmt", sumAmt);
  785. map.put("itemsList", itemsList);
  786. return map;
  787. }
  788. /**
  789. * 新增库存费计算
  790. *
  791. * @param tWarehouseBills 主表的查询条件
  792. * @param loginUser 登录用户
  793. * @param billsType 状态
  794. * @return 结果
  795. */
  796. @Override
  797. @Transactional
  798. public AjaxResult calculateStorageFees(TWarehouseBills tWarehouseBills, LoginUser loginUser, String billsType) {
  799. if (StringUtils.isNull(tWarehouseBills.getfCorpid())) {
  800. return AjaxResult.error("请选择客户信息");
  801. }
  802. long fPid = 0L;
  803. if (StringUtils.isNull(tWarehouseBills.getfId())) {
  804. tWarehouseBills.setfBilltype(billsType);
  805. tWarehouseBills.setfBillstatus(6L);
  806. tWarehouseBills.setfBsdeptid(loginUser.getUser().getDeptId());
  807. tWarehouseBills.setCreateBy(loginUser.getUser().getUserName());
  808. tWarehouseBills.setCreateTime(new Date());
  809. tWarehouseBillsMapper.insertTWarehousebills(tWarehouseBills);
  810. fPid = tWarehouseBills.getfId();
  811. } else {
  812. tWarehousebillsfeesMapper.deleteByFPid(tWarehouseBills.getfId());
  813. tWarehousebillsitemsMapper.deleteByFPid(tWarehouseBills.getfId());
  814. tWarehouseBills.setUpdateBy(loginUser.getUser().getUserName());
  815. tWarehouseBills.setUpdateTime(new Date());
  816. tWarehouseBillsMapper.updateTWarehousebills(tWarehouseBills);
  817. fPid = tWarehouseBills.getfId();
  818. }
  819. // 应收费用明细
  820. List<TWarehousebillsfees> warehousebillsfeesList = new ArrayList<>();
  821. // 计划物资明细
  822. List<TWarehousebillsitems> itemsList = new ArrayList<>();
  823. BigDecimal bigDecimal = new BigDecimal(0);
  824. Map<String, Object> map = new HashMap<>();
  825. // 库存总账id
  826. long whgenlegFeeId = 0;
  827. // 计费单位
  828. long feeUnitid = 1;
  829. // 查询 出库 货转的库存明细
  830. List<Map<String, Object>> warehousebillsitemsList = tWarehousebillsitemsMapper.selectStorageFeeItemList(tWarehouseBills);
  831. if (StringUtils.isNotNull(warehousebillsitemsList)) {
  832. Map<String, Object> mapItem = getWarehouseItems(tWarehouseBills, warehousebillsitemsList, loginUser);
  833. if (mapItem.containsKey("error")) {
  834. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  835. return AjaxResult.error((String) mapItem.get("error"));
  836. }
  837. TWarehousebillsfees fees = (TWarehousebillsfees) mapItem.get("fees");
  838. tWarehousebillsfeesMapper.insertTWarehousebillsfees(fees);
  839. itemsList = (List<TWarehousebillsitems>) mapItem.get("itemsList");
  840. warehousebillsfeesList.add(fees);
  841. }
  842. List<Map<String, Object>> tWhgenlegs = tWhgenlegMapper.selectStorageFeeItemList(tWarehouseBills);
  843. if (StringUtils.isNotNull(tWhgenlegs) && "[]".equals(tWhgenlegs)) {
  844. System.out.println(tWhgenlegs);
  845. Map<String, Object> mapItem = getWarehouseItems(tWarehouseBills, tWhgenlegs, loginUser);
  846. if (mapItem.containsKey("error")) {
  847. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  848. return AjaxResult.error((String) mapItem.get("error"));
  849. }
  850. TWarehousebillsfees fees = (TWarehousebillsfees) mapItem.get("fees");
  851. tWarehousebillsfeesMapper.insertTWarehousebillsfees(fees);
  852. List<TWarehousebillsitems> itemList = (List<TWarehousebillsitems>) mapItem.get("itemsList");
  853. if (itemList.size() != 0) {
  854. for (TWarehousebillsitems ite : itemList) {
  855. itemsList.add(ite);
  856. }
  857. }
  858. warehousebillsfeesList.add(fees);
  859. }
  860. TGoods tGoods = new TGoods();
  861. tGoods.setfStatus("0");
  862. tGoods.setDelFlag("0");
  863. List<TGoods> goods = tGoodsMapper.selectTGoodsList(tGoods);
  864. TFees tFees = new TFees();
  865. tFees.setfStatus("2");
  866. tFees.setDelFlag("0");
  867. List<TFees> feesList = tFeesMapper.selectTFeesList(tFees);
  868. map.put("goodsList", goods);
  869. map.put("feesList", feesList);
  870. map.put("warehouseBills", tWarehouseBills);
  871. map.put("warehouseItemList", itemsList);
  872. map.put("warehouseFeesList", warehousebillsfeesList);
  873. return AjaxResult.success(map);
  874. }
  875. /**
  876. * 仓储费计算提交以及暂存
  877. *
  878. * @param warehouseBills
  879. * @param warehouseItems
  880. * @param warehouseFees
  881. * @param loginUser
  882. * @param billsType
  883. * @return
  884. */
  885. @Override
  886. @Transactional
  887. public AjaxResult insertStorageFee(String warehouseBills, String warehouseItems, String warehouseFees, LoginUser loginUser, String billsType) {
  888. TWarehouseBills tWarehousebills = JSONArray.parseObject(warehouseBills, TWarehouseBills.class);
  889. long fPid = 0L;
  890. Long billstatus = tWarehousebills.getfBillstatus();
  891. if (billstatus.equals(6L) && (StringUtils.isNull(warehouseItems) || "[]".equals(warehouseItems))) {
  892. return AjaxResult.error("未找到计费物资明细无法提交");
  893. }
  894. if (billstatus.equals(6L) && (StringUtils.isNull(warehouseFees) || "[]".equals(warehouseFees))) {
  895. return AjaxResult.error("未找到应收款明细无法提交");
  896. }
  897. if (StringUtils.isNotNull(tWarehousebills.getfId())) {
  898. fPid = tWarehousebills.getfId();
  899. tWarehousebills.setUpdateTime(new Date());
  900. tWarehousebills.setUpdateBy(loginUser.getUser().getUserName());
  901. tWarehouseBillsMapper.updateTWarehousebills(tWarehousebills);
  902. tWarehousebillsfeesMapper.deleteByFPid(fPid);
  903. tWarehousebillsitemsMapper.deleteByFPid(fPid);
  904. } else {
  905. tWarehousebills.setCreateBy(loginUser.getUser().getUserName());
  906. tWarehousebills.setCreateTime(new Date());
  907. tWarehousebills.setfBilltype(billsType);
  908. tWarehouseBillsMapper.insertTWarehousebills(tWarehousebills);
  909. fPid = tWarehousebills.getfId();
  910. }
  911. if (StringUtils.isNotNull(warehouseItems) && !"[]".equals(warehouseItems)) {
  912. JSONArray warehouseJSON = JSONArray.parseArray(warehouseItems);
  913. List<TWarehousebillsitems> warehousebillsitemsList = JSONObject.parseArray(warehouseJSON.toJSONString(), TWarehousebillsitems.class);
  914. for (TWarehousebillsitems item : warehousebillsitemsList) {
  915. item.setfId(null);
  916. item.setfPid(fPid);
  917. item.setfBilltype(billsType);
  918. item.setfBillstatus(billstatus);
  919. tWarehousebillsitemsMapper.insertTWarehousebillsitems(item);
  920. }
  921. }
  922. if (StringUtils.isNotNull(warehouseFees) && !"[]".equals(warehouseFees)) {
  923. JSONArray feesJSON = JSONArray.parseArray(warehouseFees);
  924. List<TWarehousebillsfees> warehousebillsfeesList = JSONObject.parseArray(feesJSON.toJSONString(), TWarehousebillsfees.class);
  925. for (TWarehousebillsfees fees : warehousebillsfeesList) {
  926. fees.setfId(null);
  927. fees.setfPid(fPid);
  928. fees.setfDc("D");
  929. fees.setfBillstatus(billstatus);
  930. tWarehousebillsfeesMapper.insertTWarehousebillsfees(fees);
  931. }
  932. }
  933. return AjaxResult.success();
  934. }
  935. /**
  936. * 根据id查询仓储费计算信息
  937. * @param fId
  938. * @return
  939. */
  940. @Override
  941. public AjaxResult selectStorageFeeById(Long fId) {
  942. TWarehouseBills tWarehouseBills = tWarehouseBillsMapper.selectTWarehousebillsById(fId);
  943. if (StringUtils.isNull(tWarehouseBills)) {
  944. return AjaxResult.error("未找到信息,请刷新页面重试");
  945. }
  946. Map<String, Object> map = new HashMap<>();
  947. TWarehousebillsitems tWarehousebillsitems = new TWarehousebillsitems();
  948. tWarehousebillsitems.setfPid(fId);
  949. List<TWarehousebillsitems> warehouseItemsList = tWarehousebillsitemsMapper.selectTWarehousebillsitemsList(tWarehousebillsitems);
  950. TWarehousebillsfees warehousebillsfees = new TWarehousebillsfees();
  951. warehousebillsfees.setfPid(fId);
  952. List<TWarehousebillsfees> warehouseFeesList = tWarehousebillsfeesMapper.selectTWarehousebillsfeesList(warehousebillsfees);
  953. TGoods tGoods = new TGoods();
  954. tGoods.setfStatus("0");
  955. tGoods.setDelFlag("0");
  956. List<TGoods> goods = tGoodsMapper.selectTGoodsList(tGoods);
  957. TFees tFees = new TFees();
  958. tFees.setfStatus("2");
  959. tFees.setDelFlag("0");
  960. List<TFees> feesList = tFeesMapper.selectTFeesList(tFees);
  961. // 查询联系人
  962. List<SysUser> sysUserList = new ArrayList<>();
  963. SysUser sysUser = sysUserMapper.selectUserByUserName(tWarehouseBills.getCreateBy());
  964. if (StringUtils.isNotNull(sysUser)) {
  965. sysUserList.add(sysUser);
  966. }
  967. TCorps corps = tCorpsMapper.selectTCorpsById(tWarehouseBills.getfCorpid());
  968. map.put("corps", corps);
  969. map.put("goodsList", goods);
  970. map.put("feesList", feesList);
  971. map.put("sysUser", sysUserList);
  972. map.put("warehouse", tWarehouseBills);
  973. map.put("warehouseFeesList", warehouseFeesList);
  974. map.put("warehouseItemsList", warehouseItemsList);
  975. return AjaxResult.success(map);
  976. }
  977. /**
  978. * 根据不同计费单位获取不同 计算库存明细数量
  979. *
  980. * @param item 库存明细
  981. * @param dictLabel 计费单位
  982. * @return 结果
  983. */
  984. public BigDecimal acquiredQuantity(Map<String, Object> item, Long dictLabel) {
  985. BigDecimal fQty = new BigDecimal(0);
  986. // 件数
  987. long boxNum = 1;
  988. // 毛重
  989. long grossWeight = 2;
  990. // 净重
  991. long netWeight = 3;
  992. // 尺码
  993. long size = 4;
  994. // 统一
  995. long fixed = 5;
  996. if (dictLabel.equals(boxNum)) {
  997. fQty = new BigDecimal(((Number) item.get("fQty")).doubleValue());
  998. } else if (dictLabel.equals(grossWeight)) {
  999. fQty = new BigDecimal(((Number) item.get("fGrossweight")).doubleValue());
  1000. } else if (dictLabel.equals(netWeight)) {
  1001. fQty = new BigDecimal(((Number) item.get("fNetweight")).doubleValue());
  1002. } else if (dictLabel.equals(size)) {
  1003. fQty = new BigDecimal(((Number) item.get("fVolumn")).doubleValue());
  1004. } else if (dictLabel.equals(fixed)) {
  1005. fQty = new BigDecimal(1);
  1006. }
  1007. return fQty;
  1008. }
  1009. // 入库 收费明细 校验
  1010. public Long check(BigDecimal number, BigDecimal unitPrice) {
  1011. BigDecimal result1 = number.multiply(unitPrice);
  1012. // 保留两位小数且四舍五入
  1013. result1 = result1.setScale(2, BigDecimal.ROUND_HALF_UP);
  1014. // 转换去掉小数点
  1015. String result = result1.toString().replace(".", "");
  1016. return Long.valueOf(result);
  1017. }
  1018. /**
  1019. * 修改详情主表
  1020. *
  1021. * @param tWarehousebills 详情主表
  1022. * @return 结果
  1023. */
  1024. @Override
  1025. public int updateTWarehousebills(TWarehouseBills tWarehousebills) {
  1026. tWarehousebills.setUpdateTime(DateUtils.getNowDate());
  1027. return tWarehouseBillsMapper.updateTWarehousebills(tWarehousebills);
  1028. }
  1029. /**
  1030. * 批量删除详情主表
  1031. *
  1032. * @param fIds 需要删除的详情主表ID
  1033. * @return 结果
  1034. */
  1035. @Override
  1036. public int deleteTWarehousebillsByIds(Long[] fIds) {
  1037. // 取出业务编号、 放入 billno_del
  1038. for (Long id : fIds) {
  1039. // 1、查询主表信息
  1040. TWarehouseBills tWarehousebills = tWarehouseBillsMapper.selectTWarehousebillsById(id);
  1041. // 2、业务编号、客存编号 放入 billno_del
  1042. BillnoDel billnoDel = new BillnoDel();
  1043. billnoDel.setBillType(tWarehousebills.getfBilltype());
  1044. billnoDel.setBillNo(tWarehousebills.getfBillno());
  1045. billnoDelMapper.insertBillnoDel(billnoDel);
  1046. }
  1047. return tWarehouseBillsMapper.deleteTWarehousebillsByIds(fIds);
  1048. }
  1049. /**
  1050. * 删除详情主表信息
  1051. *
  1052. * @param fId 详情主表ID
  1053. * @return 结果
  1054. */
  1055. @Override
  1056. public int deleteTWarehousebillsById(Long fId) {
  1057. return tWarehouseBillsMapper.deleteTWarehousebillsById(fId);
  1058. }
  1059. @Override
  1060. public String getWarehouseInStockBillsNo(TWarehouseBills tWarehouseBills) {
  1061. return null;
  1062. }
  1063. @Override
  1064. public String getWarehouseOutStockBillsNo(TWarehouseBills tWarehouseBills) {
  1065. return null;
  1066. }
  1067. @Override
  1068. public AjaxResult revokeTWarehousebillsById(Long fId, LoginUser loginUser, String billsType) {
  1069. // 查询 仓库主表信息、库存明细信息
  1070. TWarehouseBills tWarehousebills = tWarehouseBillsMapper.selectTWarehousebillsById(fId);
  1071. // 修改主表信息
  1072. tWarehousebills.setUpdateBy(loginUser.getUser().getUserName());
  1073. tWarehousebills.setUpdateTime(new Date());
  1074. tWarehousebills.setfBillstatus(3L); //撤销状态
  1075. tWarehouseBillsMapper.updateTWarehousebills(tWarehousebills);
  1076. // 查询库存明细从表数据
  1077. TWarehousebillsitems tWarehousebillsitems = new TWarehousebillsitems();
  1078. tWarehousebillsitems.setfPid(fId);
  1079. List<TWarehousebillsitems> warehousebillsitems = tWarehousebillsitemsMapper.selectTWarehousebillsitemsList(tWarehousebillsitems);
  1080. // 撤销 库存总账
  1081. if (StringUtils.isNotEmpty(warehousebillsitems)) {
  1082. int i = 1;
  1083. for (TWarehousebillsitems wb : warehousebillsitems) {
  1084. // 查询库存总账
  1085. TWhgenleg tWhgenle = queryTWhgenleg(tWarehousebills, wb);
  1086. if ("SJRKRevoke".equals(billsType)) { // 撤销 入库
  1087. if (StringUtils.isNotNull(tWhgenle) && (wb.getfQty() <= tWhgenle.getfQtyblc())) { // 非空 且 撤销数 <= 结余数
  1088. updateTWhgenlegData(wb, tWhgenle.getfId(), billsType);
  1089. } else { // 撤销数>结余数
  1090. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1091. return AjaxResult.error("第" + i + "行撤销数大于库存结余数");
  1092. }
  1093. } else if ("SJCKRevoke".equals(billsType)) { // 撤销出库
  1094. if (StringUtils.isNotNull(tWhgenle)) { // 非空
  1095. updateTWhgenlegData(wb, tWhgenle.getfId(), billsType);
  1096. } else {
  1097. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1098. return AjaxResult.error("第" + i + "行未查询到库存信息");
  1099. }
  1100. } else if ("CKDBRevoke".equals(billsType)) { // 调拨 撤销
  1101. Long fCorpid = tWarehousebills.getfCorpid();// 原货权方
  1102. Long fTocorpid = tWarehousebills.getfTocorpid(); // 新货权方
  1103. // 1、新货权方撤销入库
  1104. // 查询库存总账
  1105. tWarehousebills.setfCorpid(fTocorpid);
  1106. TWhgenleg tWhgenle1 = queryTWhgenleg(tWarehousebills, wb);
  1107. if (StringUtils.isNotNull(tWhgenle1) && (wb.getfQty() <= tWhgenle1.getfQtyblc())) {
  1108. updateTWhgenlegData(wb, tWhgenle1.getfId(), "SJRKRevoke");
  1109. } else {
  1110. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1111. return AjaxResult.error("第" + i + "行撤销数大于库存结余数");
  1112. }
  1113. // 2、原货权方撤销出库
  1114. // 查询库存总账
  1115. tWarehousebills.setfCorpid(fCorpid);
  1116. TWhgenleg tWhgenle2 = queryTWhgenleg(tWarehousebills, wb);
  1117. updateTWhgenlegData(wb, tWhgenle2.getfId(), "SJCKRevoke");
  1118. } else if ("HQZYRevoke".equals(billsType)) { // 货转撤销 HQZYRevoke
  1119. Long fCorpid = tWarehousebills.getfCorpid();// 原货权方
  1120. Long fTocorpid = tWarehousebills.getfTocorpid(); // 新货权方
  1121. // 1、新货权方撤销入库
  1122. // 查询库存总账
  1123. tWarehousebills.setfCorpid(fTocorpid);
  1124. TWhgenleg tWhgenle1 = queryTWhgenleg(tWarehousebills, wb);
  1125. if (StringUtils.isNotNull(tWhgenle1) && (wb.getfQty() <= tWhgenle1.getfQtyblc())) {
  1126. updateTWhgenlegData(wb, tWhgenle1.getfId(), "SJRKRevoke");
  1127. } else {
  1128. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1129. return AjaxResult.error("第" + i + "行撤销数大于库存结余数");
  1130. }
  1131. // 2、原货权方撤销出库
  1132. // 查询库存总账
  1133. tWarehousebills.setfCorpid(fCorpid);
  1134. TWhgenleg tWhgenle2 = queryTWhgenleg(tWarehousebills, wb);
  1135. updateTWhgenlegData(wb, tWhgenle2.getfId(), "SJCKRevoke");
  1136. }
  1137. i++;
  1138. }
  1139. }
  1140. return AjaxResult.success();
  1141. }
  1142. /**
  1143. * 撤销入账
  1144. *
  1145. * @param warehouseBills 主表
  1146. * @param warehousebillsitems 明细
  1147. * @param loginUser 当前登录人
  1148. * @param billsType 状态
  1149. * @return 结果
  1150. */
  1151. @Override
  1152. @Transactional
  1153. public AjaxResult revokeTWarehousebillsById1(String warehouseBills, String warehousebillsitems, LoginUser loginUser, String billsType) {
  1154. Long fPid = null;
  1155. if (StringUtils.isNull(warehouseBills) || "[]".equals(warehouseBills)) {
  1156. return AjaxResult.error("未找到主表信息");
  1157. }
  1158. if (StringUtils.isNull(warehousebillsitems) || "[]".equals(warehousebillsitems)) {
  1159. return AjaxResult.error("未找到入账信息");
  1160. }
  1161. TWarehouseBills tWarehousebills = JSONArray.parseObject(warehouseBills, TWarehouseBills.class);
  1162. fPid = tWarehousebills.getfId();
  1163. JSONArray warehouseJSON = JSONArray.parseArray(warehousebillsitems);
  1164. List<TWarehousebillsitems> warehousebillsitemsList = JSONObject.parseArray(warehouseJSON.toJSONString(), TWarehousebillsitems.class);
  1165. if (StringUtils.isNotEmpty(warehousebillsitemsList)) {
  1166. int i = 1;
  1167. for (TWarehousebillsitems wb : warehousebillsitemsList) {
  1168. // 查询库存总账
  1169. TWhgenleg tWhgenle = queryTWhgenleg(tWarehousebills, wb);
  1170. if ("SJRKRevoke".equals(billsType)) { // 撤销 入库
  1171. if (StringUtils.isNotNull(tWhgenle) && (wb.getfQty() <= tWhgenle.getfQtyblc())) { // 非空 且 撤销数 <= 结余数
  1172. updateTWhgenlegData(wb, tWhgenle.getfId(), billsType);
  1173. } else { // 撤销数>结余数
  1174. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1175. return AjaxResult.error("第" + i + "行撤销数大于库存结余数");
  1176. }
  1177. } else if ("SJCKRevoke".equals(billsType)) { // 撤销出库
  1178. if (StringUtils.isNotNull(tWhgenle)) { // 非空
  1179. updateTWhgenlegData(wb, tWhgenle.getfId(), billsType);
  1180. } else {
  1181. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1182. return AjaxResult.error("第" + i + "行未查询到库存信息");
  1183. }
  1184. } else if ("CKDBRevoke".equals(billsType)) { // 调拨 撤销
  1185. Long fCorpid = tWarehousebills.getfCorpid();// 原货权方
  1186. Long fTocorpid = tWarehousebills.getfTocorpid(); // 新货权方
  1187. // 1、新货权方撤销入库
  1188. // 查询库存总账
  1189. tWarehousebills.setfCorpid(fTocorpid);
  1190. TWhgenleg tWhgenle1 = queryTWhgenleg(tWarehousebills, wb);
  1191. if (StringUtils.isNotNull(tWhgenle1) && (wb.getfQty() <= tWhgenle1.getfQtyblc())) {
  1192. updateTWhgenlegData(wb, tWhgenle1.getfId(), "SJRKRevoke");
  1193. } else {
  1194. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1195. return AjaxResult.error("第" + i + "行撤销数大于库存结余数");
  1196. }
  1197. // 2、原货权方撤销出库
  1198. // 查询库存总账
  1199. tWarehousebills.setfCorpid(fCorpid);
  1200. TWhgenleg tWhgenle2 = queryTWhgenleg(tWarehousebills, wb);
  1201. updateTWhgenlegData(wb, tWhgenle2.getfId(), "SJCKRevoke");
  1202. } else if ("HQZYRevoke".equals(billsType)) { // 货转撤销 HQZYRevoke
  1203. Long fCorpid = tWarehousebills.getfCorpid();// 原货权方
  1204. Long fTocorpid = tWarehousebills.getfTocorpid(); // 新货权方
  1205. // 1、新货权方撤销入库
  1206. // 查询库存总账
  1207. tWarehousebills.setfCorpid(fTocorpid);
  1208. TWhgenleg tWhgenle1 = queryTWhgenleg(tWarehousebills, wb);
  1209. if (StringUtils.isNotNull(tWhgenle1) && (wb.getfQty() <= tWhgenle1.getfQtyblc())) {
  1210. updateTWhgenlegData(wb, tWhgenle1.getfId(), "SJRKRevoke");
  1211. } else {
  1212. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1213. return AjaxResult.error("第" + i + "行撤销数大于库存结余数");
  1214. }
  1215. // 2、原货权方撤销出库
  1216. // 查询库存总账
  1217. tWarehousebills.setfCorpid(fCorpid);
  1218. TWhgenleg tWhgenle2 = queryTWhgenleg(tWarehousebills, wb);
  1219. updateTWhgenlegData(wb, tWhgenle2.getfId(), "SJCKRevoke");
  1220. }
  1221. i++;
  1222. wb.setfBillstatus(1L);
  1223. wb.setUpdateBy(loginUser.getUser().getUserName());
  1224. wb.setUpdateTime(new Date());
  1225. if (tWarehousebillsitemsMapper.updateTWarehousebillsitems(wb) <= 0) {
  1226. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1227. return AjaxResult.error("新增库存明细失败");
  1228. }
  1229. }
  1230. }
  1231. updateWarehousebillsItemsStatus(tWarehousebills);
  1232. return AjaxResult.success();
  1233. }
  1234. /**
  1235. * 主表、库存明细表 更新 入账状态
  1236. */
  1237. public void updateWarehousebillsItemsStatus(TWarehouseBills warehouseBill) {
  1238. // 查询所有库存明细 修改仓库主表状态
  1239. int notInStorage = 0;
  1240. int Stored = 0;
  1241. TWarehousebillsitems tWarehousebillsitems = new TWarehousebillsitems();
  1242. tWarehousebillsitems.setfPid(warehouseBill.getfId());
  1243. List<TWarehousebillsitems> warehousebillsitemsList1 = tWarehousebillsitemsMapper.selectTWarehousebillsitemsList(tWarehousebillsitems);
  1244. for (TWarehousebillsitems item : warehousebillsitemsList1) {
  1245. if (item.getfBillstatus().equals(40L) | item.getfBillstatus().equals(90L)) {
  1246. Stored++;
  1247. } else {
  1248. notInStorage++;
  1249. }
  1250. }
  1251. // 录入库存明细整体状态
  1252. TWarehouseBills warehouseBill1 = new TWarehouseBills();
  1253. warehouseBill1.setfId(warehouseBill.getfId());
  1254. if (Objects.equals(Stored, 0)) { // 未入库
  1255. warehouseBill1.setfItemsStatus(1L);
  1256. } else if (Objects.equals(notInStorage, 0)) { // 已入库
  1257. warehouseBill1.setfItemsStatus(6L);
  1258. } else { // 有已入库、有未入库
  1259. warehouseBill1.setfItemsStatus(2L);
  1260. }
  1261. tWarehouseBillsMapper.updateTWarehousebills(warehouseBill1);
  1262. }
  1263. /**
  1264. * 添加 库存明细状态
  1265. *
  1266. * @param wbItem
  1267. * @param status
  1268. * @param loginUser
  1269. */
  1270. public void insertTWarehousebillsLog(TWarehousebillsitems wbItem, Long status, LoginUser loginUser) {
  1271. // 添加状态log
  1272. TWarehousebillsLog tWarehousebillsLog = new TWarehousebillsLog();
  1273. tWarehousebillsLog.setfPid(wbItem.getfPid());
  1274. tWarehousebillsLog.setfItmeid(wbItem.getfId());
  1275. tWarehousebillsLog.setfItmestatus(status);
  1276. tWarehousebillsLog.setCreateTime(new Date());
  1277. tWarehousebillsLog.setCreateBy(loginUser.getUser().getUserName());
  1278. tWarehousebillsLogMapper.insertTWarehousebillsLog(tWarehousebillsLog);
  1279. }
  1280. /**
  1281. * 删除 库存明细
  1282. *
  1283. * @param fid
  1284. * @param tWarehousebillsitems
  1285. */
  1286. public void deleteBillsitems(Long fid, String tWarehousebillsitems) {
  1287. List<Long> oldList = new ArrayList<Long>();
  1288. List<Long> newList = new ArrayList<Long>();
  1289. // 查询所有从表数据
  1290. TWarehousebillsitems tWarehousebillsitem = new TWarehousebillsitems();
  1291. tWarehousebillsitem.setfPid(fid);
  1292. List<TWarehousebillsitems> warehousebillsitemsList = tWarehousebillsitemsMapper.selectTWarehousebillsitemsList(tWarehousebillsitem);
  1293. warehousebillsitemsList.forEach(wb ->
  1294. oldList.add(wb.getfId())
  1295. );
  1296. // 获取提交从表数据ID
  1297. if (tWarehousebillsitems != null) {
  1298. JSONArray warehouseJSON = JSONArray.parseArray(tWarehousebillsitems);
  1299. List<TWarehousebillsitems> warehousebillsitemsLists = JSONObject.parseArray(warehouseJSON.toJSONString(), TWarehousebillsitems.class);
  1300. warehousebillsitemsLists.forEach(wb ->
  1301. newList.add(wb.getfId())
  1302. );
  1303. }
  1304. // 删除多余的ID
  1305. List<Long> reduce1 = oldList.stream().filter(item -> !newList.contains(item)).collect(toList());
  1306. reduce1.forEach(id ->
  1307. tWarehousebillsitemsMapper.deleteByFPid(id)
  1308. );
  1309. }
  1310. /**
  1311. * 库容-结余毛重
  1312. *
  1313. * @param fTotalgross
  1314. * @param fGrossweightblc
  1315. * @return
  1316. */
  1317. public static BigDecimal calculation1(String fTotalgross, String fGrossweightblc) {
  1318. BigDecimal num1 = new BigDecimal(fTotalgross);
  1319. BigDecimal num2 = new BigDecimal(fGrossweightblc);
  1320. BigDecimal result = num1.subtract(num2);
  1321. return result.setScale(2, BigDecimal.ROUND_HALF_UP);
  1322. }
  1323. /**
  1324. * 判断 是否允许 入库
  1325. *
  1326. * @param fId
  1327. */
  1328. public int calculation(Long fId, BigDecimal fGrossweight) {
  1329. // 仓库库容
  1330. TWarehouse tWarehouse = tWarehouseMapper.selectTWarehouseById(fId);
  1331. // 总账使用
  1332. List<Map<String, Object>> whouseList = tWhgenlegMapper.selectWareHouseListWhouse(fId);
  1333. if (whouseList != null && whouseList.size() > 0) {
  1334. String fTotalgross = null;
  1335. String fGrossweightblc = null;
  1336. for (Map<String, Object> m : whouseList) {
  1337. for (String k : m.keySet()) {
  1338. // 获取毛重库容
  1339. if (k.equals("fTotalgross")) {
  1340. fTotalgross = m.get(k).toString();
  1341. }
  1342. if (k.equals("fGrossweightD")) {
  1343. fGrossweightblc = m.get(k).toString();
  1344. }
  1345. }
  1346. }
  1347. BigDecimal result = calculation1(fTotalgross, fGrossweightblc);
  1348. if (result.compareTo(fGrossweight) == -1) {
  1349. return 0;// 结余库容小于入库数
  1350. } else {
  1351. return 1;
  1352. }
  1353. } else {
  1354. if (tWarehouse.getfTotalgross().compareTo(fGrossweight) == -1) {
  1355. return 0;// 库容小于入库数
  1356. } else {
  1357. return 1;
  1358. }
  1359. }
  1360. }
  1361. }