TWarehouseBillsServiceImpl.java 121 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469
  1. package com.ruoyi.warehouseBusiness.service.impl;
  2. import com.alibaba.fastjson.JSONArray;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.ruoyi.approvalFlow.domain.AuditItems;
  5. import com.ruoyi.approvalFlow.mapper.AuditItemsMapper;
  6. import com.ruoyi.approvalFlow.service.impl.AuditItemsServiceImpl;
  7. import com.ruoyi.basicData.domain.TCorps;
  8. import com.ruoyi.basicData.domain.TFees;
  9. import com.ruoyi.basicData.domain.TGoods;
  10. import com.ruoyi.basicData.domain.TWarehouseArea;
  11. import com.ruoyi.basicData.mapper.*;
  12. import com.ruoyi.common.core.domain.AjaxResult;
  13. import com.ruoyi.common.core.domain.entity.SysDept;
  14. import com.ruoyi.common.core.domain.entity.SysDictData;
  15. import com.ruoyi.common.core.domain.entity.SysUser;
  16. import com.ruoyi.common.core.domain.entity.TWarehouse;
  17. import com.ruoyi.common.core.domain.model.LoginUser;
  18. import com.ruoyi.common.utils.DateUtils;
  19. import com.ruoyi.common.utils.StringUtils;
  20. import com.ruoyi.reportManagement.domain.TWareHouseItemsExcel;
  21. import com.ruoyi.reportManagement.domain.TWhgenleg;
  22. import com.ruoyi.reportManagement.mapper.TWhgenlegMapper;
  23. import com.ruoyi.system.domain.SysConfig;
  24. import com.ruoyi.system.mapper.SysConfigMapper;
  25. import com.ruoyi.system.mapper.SysDeptMapper;
  26. import com.ruoyi.system.mapper.SysDictDataMapper;
  27. import com.ruoyi.system.mapper.SysUserMapper;
  28. import com.ruoyi.warehouseBusiness.domain.*;
  29. import com.ruoyi.warehouseBusiness.excel.*;
  30. import com.ruoyi.warehouseBusiness.mapper.*;
  31. import com.ruoyi.warehouseBusiness.service.ITWarehouseBillsService;
  32. import org.springframework.beans.factory.annotation.Autowired;
  33. import org.springframework.stereotype.Service;
  34. import org.springframework.transaction.annotation.Transactional;
  35. import org.springframework.transaction.interceptor.TransactionAspectSupport;
  36. import java.math.BigDecimal;
  37. import java.text.SimpleDateFormat;
  38. import java.util.*;
  39. import java.util.stream.Collectors;
  40. import static java.util.stream.Collectors.toList;
  41. /**
  42. * 详情主表Service业务层处理
  43. *
  44. * @author ruoyi
  45. * @date 2020-12-11
  46. */
  47. @Service
  48. public class TWarehouseBillsServiceImpl implements ITWarehouseBillsService {
  49. @Autowired
  50. private TWhgenlegMapper tWhgenlegMapper;
  51. @Autowired
  52. private TGoodsMapper tGoodsMapper;
  53. @Autowired
  54. private SysConfigMapper sysConfigMapper;
  55. @Autowired
  56. private AuditItemsServiceImpl auditItemsService;
  57. @Autowired
  58. private AuditItemsMapper auditItemsMapper;
  59. @Autowired
  60. private SysDeptMapper sysDeptMapper;
  61. @Autowired
  62. private SysUserMapper sysUserMapper;
  63. @Autowired
  64. private TCorpsMapper tCorpsMapper;
  65. @Autowired
  66. private TFeesMapper tFeesMapper;
  67. @Autowired
  68. private TWarehouseMapper tWarehouseMapper;
  69. @Autowired
  70. private SysDictDataMapper sysDictDataMapper;
  71. @Autowired
  72. private TWarehouseAreaMapper tWarehouseAreaMapper;
  73. @Autowired
  74. private TEnclosureMapper tEnclosureMapper;
  75. @Autowired
  76. private TWarehouseBillsMapper tWarehouseBillsMapper;
  77. @Autowired
  78. private TWarehousebillsfeesMapper tWarehousebillsfeesMapper;
  79. @Autowired
  80. private TWarehousebillsitemsMapper tWarehousebillsitemsMapper;
  81. @Autowired
  82. private BillnoSerialServiceImpl billnoSerialServiceImpl;
  83. @Autowired
  84. private BillnoDelMapper billnoDelMapper;
  85. @Autowired
  86. private TWarehousebillsLogMapper tWarehousebillsLogMapper;
  87. @Autowired
  88. private TWarehouseAgreementServiceImpl tWarehouseAgreementService;
  89. /**
  90. * 查询详情主表
  91. *
  92. * @param fId 详情主表ID
  93. * @return 详情主表
  94. */
  95. @Override
  96. public Map<String, Object> selectTWarehousebillsById(Long fId) {
  97. Map<String, Object> map = new HashMap<>();
  98. // 查询仓库主表数据
  99. TWarehouseBills tWarehousebills = tWarehouseBillsMapper.selectTWarehousebillsById(fId);
  100. // 客户表
  101. List<Long> corpsId = new ArrayList<>();
  102. // 用户表
  103. List<SysUser> sysUserList = new ArrayList<>();
  104. // 仓库表
  105. List<TWarehouse> warehouseList = new ArrayList<>();
  106. // 商品
  107. List<Long> goodsId = new ArrayList<>();
  108. // 费用
  109. List<Long> feesId = new ArrayList<>();
  110. // 库区
  111. List<Long> warehouseAreaId = new ArrayList<>();
  112. if (!StringUtils.isNull(tWarehousebills)) {
  113. if (StringUtils.isNotNull(tWarehousebills.getfTocorpid())) {
  114. corpsId.add(tWarehousebills.getfTocorpid());
  115. }
  116. if (StringUtils.isNotNull(tWarehousebills.getfLabour())) {
  117. corpsId.add(tWarehousebills.getfLabour());
  118. }
  119. if (StringUtils.isNotNull(tWarehousebills.getfFleet())) {
  120. corpsId.add(tWarehousebills.getfFleet());
  121. }
  122. corpsId.add(tWarehousebills.getfCorpid());
  123. corpsId.add(tWarehousebills.getfCorpid());
  124. corpsId.add(tWarehousebills.getfCorpid());
  125. // 查询制单人
  126. SysUser logUser = sysUserMapper.selectUserByUserName(tWarehousebills.getCreateBy());
  127. if (StringUtils.isNotNull(logUser)) {
  128. SysDept sysDept = sysDeptMapper.selectDeptById(logUser.getDeptId());
  129. sysUserList.add(logUser);
  130. map.put("dept", sysDept);
  131. }
  132. SysUser sysUser = sysUserMapper.selectUserByUserName(tWarehousebills.getfStorekeeper());
  133. if (StringUtils.isNotNull(sysUser)) {
  134. sysUserList.add(sysUser);
  135. }
  136. // 查询仓库
  137. TWarehouse tWarehouse = tWarehouseMapper.selectTWarehouseById(tWarehousebills.getfWarehouseid());
  138. if (StringUtils.isNotNull(tWarehouse)) {
  139. warehouseList.add(tWarehouse);
  140. }
  141. // 查询经营单位
  142. corpsId.add(tWarehousebills.getfSbu());
  143. map.put("warehousebills", tWarehousebills);
  144. }
  145. // 查询仓库明细从表数据
  146. TWarehousebillsitems tWarehousebillsitems = new TWarehousebillsitems();
  147. tWarehousebillsitems.setfPid(fId);
  148. List<Map<String, Object>> mapList = tWarehousebillsitemsMapper.selectGoodsTransferitemsList(tWarehousebillsitems);
  149. if (StringUtils.isNotEmpty(mapList)) {
  150. for (Map<String, Object> wb : mapList) {
  151. /*TWhgenleg tWhgenleg = new TWhgenleg();
  152. tWhgenleg.setfCorpid(tWarehousebills.getfCorpid());
  153. if (StringUtils.isNotNull(wb.get("fGoodsid"))) {
  154. tWhgenleg.setfGoodsid(((Integer) wb.get("fGoodsid")).longValue());
  155. }
  156. if (StringUtils.isNotNull(wb.get("fWarehouselocid"))) {
  157. tWhgenleg.setfWarehouseLocationid(((Integer) wb.get("fWarehouselocid")).longValue());
  158. }
  159. tWhgenleg.setfTrademodeid(tWarehousebills.getfTrademodeid());
  160. tWhgenleg.setfMblno(tWarehousebills.getfMblno());
  161. TWhgenleg whgenleg = tWhgenlegMapper.selectTWhgenleg(tWhgenleg);
  162. if (StringUtils.isNotNull(whgenleg)) {
  163. wb.put("fQtyblc", whgenleg.getfQtyblc());
  164. }*/
  165. if (StringUtils.isNotNull(wb.get("fGoodsid"))) {
  166. Integer fGoodsid = (Integer) wb.get("fGoodsid");
  167. goodsId.add(fGoodsid.longValue());
  168. }
  169. if (StringUtils.isNotNull(wb.get("fWarehouselocid"))) {
  170. Long fWarehouselocid = Long.valueOf(String.valueOf(wb.get("fWarehouselocid")));
  171. if (wb.get("fTransferWarehouselocid") != null) {
  172. Long fTransferWarehouselocid = Long.valueOf(String.valueOf(wb.get("fTransferWarehouselocid")));
  173. warehouseAreaId.add(fTransferWarehouselocid);
  174. }
  175. warehouseAreaId.add(fWarehouselocid);
  176. }
  177. }
  178. map.put("warehouseBillsItem", mapList);
  179. }
  180. // 查询仓库费用明细表数据
  181. TWarehousebillsfees tWarehousebillsfees = new TWarehousebillsfees();
  182. tWarehousebillsfees.setfPid(fId);
  183. List<TWarehousebillsfees> warehousebillsfeesDr = new ArrayList<>();
  184. List<TWarehousebillsfees> warehousebillsfeesCr = new ArrayList<>();
  185. List<TWarehousebillsfees> warehousebillsfees = tWarehousebillsfeesMapper.selectTWarehousebillsfeesList(tWarehousebillsfees);
  186. if (StringUtils.isNotEmpty(warehousebillsfees)) {
  187. for (TWarehousebillsfees fees : warehousebillsfees) {
  188. if ("C".equals(fees.getfDc())) {
  189. warehousebillsfeesCr.add(fees);
  190. } else {
  191. warehousebillsfeesDr.add(fees);
  192. }
  193. corpsId.add(fees.getfCorpid());
  194. feesId.add(fees.getfFeeid());
  195. }
  196. }
  197. // 查询附件表数据
  198. TEnclosure enclosure = new TEnclosure();
  199. enclosure.setfPid(fId);
  200. List<TEnclosure> enclosures = tEnclosureMapper.selectTEnclosureList(enclosure);
  201. if (StringUtils.isNotEmpty(enclosures)) {
  202. map.put("enclosures", enclosures);
  203. }
  204. List<TCorps> corpsList = new ArrayList<>();
  205. List<Long> corpsIdList = StringUtils.integerDeduplication(corpsId);
  206. for (Long corpId : corpsIdList) {
  207. TCorps corps = tCorpsMapper.selectTCorpsById(corpId);
  208. if (StringUtils.isNotNull(corps)) {
  209. corpsList.add(corps);
  210. }
  211. }
  212. List<TWarehouseArea> warehouseAreaList = new ArrayList<>();
  213. /*List<Long> warehouseAreaIdList = StringUtils.integerDeduplication(warehouseAreaId);
  214. for (Long warehouseArea : warehouseAreaIdList) {
  215. TWarehouseArea tWarehouseArea = tWarehouseAreaMapper.selectTWarehouseAreaById(warehouseArea);
  216. if (StringUtils.isNotNull(tWarehouseArea)) {
  217. warehouseAreaList.add(tWarehouseArea);
  218. }
  219. }*/
  220. List<TGoods> goodsList = new ArrayList<>();
  221. List<Long> goodsIdList = StringUtils.integerDeduplication(goodsId);
  222. for (Long goods : goodsIdList) {
  223. TGoods tGoods = tGoodsMapper.selectTGoodsById(goods);
  224. if (StringUtils.isNotNull(tGoods)) {
  225. goodsList.add(tGoods);
  226. }
  227. }
  228. List<TFees> feesList = new ArrayList<>();
  229. List<Long> longList = StringUtils.integerDeduplication(feesId);
  230. for (Long fees : longList) {
  231. TFees tFees = tFeesMapper.selectTFeesById(fees);
  232. if (StringUtils.isNotNull(tFees)) {
  233. feesList.add(tFees);
  234. }
  235. }
  236. map.put("corps", corpsList);
  237. map.put("goodsList", goodsList);
  238. map.put("feesList", feesList);
  239. map.put("sysUser", sysUserList);
  240. map.put("warehouse", warehouseList);
  241. map.put("warehouseAreas", warehouseAreaList);
  242. map.put("warehousebillsfeesDr", warehousebillsfeesDr);
  243. map.put("warehousebillsfeesCr", warehousebillsfeesCr);
  244. map.put("dept", sysDeptMapper.selectDeptById(tWarehousebills.getfDeptid()));
  245. return map;
  246. }
  247. /**
  248. * 查询详情主表列表
  249. *
  250. * @param tWarehousebills 详情主表
  251. * @return 详情主表
  252. */
  253. @Override
  254. public List<Map<String, Object>> selectWarehouseBusinessList(TWarehouseBills tWarehousebills) {
  255. if(tWarehousebills.getfBilltype().equals("JSCCF") | tWarehousebills.getfBilltype().equals("HQZY")){
  256. return tWarehouseBillsMapper.selectWarehouseBusinessList1(tWarehousebills);
  257. }else {
  258. return tWarehouseBillsMapper.selectWarehouseBusinessList(tWarehousebills);
  259. }
  260. }
  261. /**
  262. * 查询导出所需主表列表
  263. *
  264. * @param tWarehousebills 详情主表
  265. * @return 详情主表
  266. */
  267. @Override
  268. public List<TWarehouseBills> selectTWarehousebillsList(TWarehouseBills tWarehousebills) {
  269. return tWarehouseBillsMapper.selectTWarehousebillsList(tWarehousebills);
  270. }
  271. /**
  272. * 根据条件查询总账是否存在
  273. *
  274. * @param warehouseBills 仓库主表
  275. * @param warehousebillsitems 仓库明细表
  276. * @return 库存总账
  277. */
  278. public TWhgenleg queryTWhgenleg(TWarehouseBills warehouseBills, TWarehousebillsitems warehousebillsitems) {
  279. TWhgenleg tWhgenleg = new TWhgenleg();
  280. // 客户
  281. tWhgenleg.setfCorpid(warehouseBills.getfCorpid());
  282. // 提单号
  283. if ("HQZY".equals(warehouseBills.getfBilltype()) || "CKDB".equals(warehouseBills.getfBilltype()) || "HWTG".equals(warehouseBills.getfBilltype()) ) {
  284. tWhgenleg.setfMblno(warehousebillsitems.getfMblno());
  285. } else {
  286. tWhgenleg.setfMblno(warehouseBills.getfMblno());
  287. }
  288. // 库区
  289. tWhgenleg.setfWarehouseLocationid(warehousebillsitems.getfWarehouselocid());
  290. // 货物品名
  291. tWhgenleg.setfGoodsid(warehousebillsitems.getfGoodsid());
  292. // 贸易方式
  293. tWhgenleg.setfTrademodeid(warehouseBills.getfTrademodeid());
  294. return tWhgenlegMapper.selectTWhgenleg(tWhgenleg);
  295. }
  296. /**
  297. * 新增库存总账
  298. *
  299. * @param warehouseBills 仓库主表
  300. * @param warehousebillsitems 仓库明细表
  301. * @return 结果
  302. */
  303. @Transactional
  304. public int instalTWhgenleg(TWarehouseBills warehouseBills, TWarehousebillsitems warehousebillsitems, SysUser user) {
  305. TWhgenleg tWhgenleg = new TWhgenleg();
  306. if ("SJRK".equals(warehouseBills.getfBilltype())) {
  307. tWhgenleg.setfOriginalbilldate(warehousebillsitems.getfBsdate());
  308. }
  309. if ("HQZY".equals(warehouseBills.getfBilltype()) | "CKDB".equals(warehouseBills.getfBilltype()) | "HWTG".equals(warehouseBills.getfBilltype()) ) {
  310. tWhgenleg.setfOriginalbilldate(warehousebillsitems.getfOriginalbilldate());
  311. if ("CKDB".equals(warehouseBills.getfBilltype()) | "HWTG".equals(warehouseBills.getfBilltype()) ) {
  312. tWhgenleg.setfCorpid(warehouseBills.getfCorpid());
  313. } else {
  314. // 客户
  315. tWhgenleg.setfCorpid(warehouseBills.getfTocorpid());
  316. }
  317. // 提单号
  318. tWhgenleg.setfMblno(warehousebillsitems.getfMblno());
  319. // 原始单号
  320. tWhgenleg.setfOriginalbillno(warehousebillsitems.getfMblno());
  321. } else {
  322. // 客户
  323. tWhgenleg.setfCorpid(warehouseBills.getfCorpid());
  324. // 提单号
  325. tWhgenleg.setfMblno(warehouseBills.getfMblno());
  326. // 原始单号
  327. tWhgenleg.setfOriginalbillno(warehouseBills.getfMblno());
  328. }
  329. // 明细类型
  330. tWhgenleg.setfBusinessType(warehousebillsitems.getfBusinessType());
  331. // 仓库
  332. tWhgenleg.setfWarehouseid(warehouseBills.getfWarehouseid());
  333. // 库区
  334. tWhgenleg.setfWarehouseLocationid(warehousebillsitems.getfWarehouselocid());
  335. // 货物品名
  336. tWhgenleg.setfGoodsid(warehousebillsitems.getfGoodsid());
  337. // 计费方式
  338. tWhgenleg.setfBillingway(warehousebillsitems.getfBillingway());
  339. // 仓储计费日期
  340. tWhgenleg.setfChargedate(warehousebillsitems.getfChargedate());
  341. // 贸易方式
  342. tWhgenleg.setfTrademodeid(warehouseBills.getfTrademodeid());
  343. // 入库数
  344. tWhgenleg.setfQtyd(warehousebillsitems.getfQty());
  345. // 入库尺码
  346. tWhgenleg.setfVolumnd(warehousebillsitems.getfVolumn());
  347. // 唛头
  348. tWhgenleg.setfMarks(warehousebillsitems.getfMarks());
  349. // 入库毛重
  350. tWhgenleg.setfGrossweightd(warehousebillsitems.getfGrossweight());
  351. // 入库净重
  352. tWhgenleg.setfNetweightd(warehousebillsitems.getfNetweight());
  353. // 入库箱号
  354. tWhgenleg.setfCntrno(warehousebillsitems.getfCntrno());
  355. // 创建人
  356. tWhgenleg.setCreateBy(user.getUserName());
  357. // 创建人
  358. tWhgenleg.setCreateTime(new Date());
  359. // 状态
  360. tWhgenleg.setfStatus("T");
  361. // 结余件数
  362. tWhgenleg.setfQtyblc(warehousebillsitems.getfQty());
  363. return tWhgenlegMapper.insertTWhgenleg(tWhgenleg);
  364. }
  365. @Transactional
  366. public int updateTWhgenlegData(TWarehousebillsitems warehousebillsitems, long whgenlegId, String billtype) {
  367. Map<String, Object> map = new HashMap<>();
  368. map.put("whgenlegId", whgenlegId);
  369. map.put("billType", billtype);
  370. map.put("warehousebillsitems", warehousebillsitems);
  371. return tWhgenlegMapper.updateTWhgenlegData(map);
  372. }
  373. /**
  374. * 仓库暂存接口
  375. *
  376. * @param tWarehouseBills 仓库主表
  377. * @param tWarehousebillsfeesCr 仓库费付款用明细表
  378. * @param tWarehousebillsfeesDr 仓库费收
  379. * 款用明细表
  380. * @param tWarehousebillsitems 仓库货物明细表
  381. * @param loginUser 当前登陆人
  382. * @param billsType 判断标识
  383. * @return 结果
  384. */
  385. @Override
  386. @Transactional
  387. public AjaxResult insertTWarehousebills(String tWarehouseBills, String tWarehousebillsfeesCr, String tWarehousebillsfeesDr
  388. , String tWarehousebillsitems, String tEnclosure, LoginUser loginUser, String billsType) {
  389. Long fPid = null;
  390. Map<String, Object> map = new HashMap<>();
  391. TWarehouseBills warehouseBills = JSONArray.parseObject(tWarehouseBills, TWarehouseBills.class);
  392. if (StringUtils.isNull(warehouseBills.getfId())) {
  393. // 如果是新数据
  394. warehouseBills.setfBillstatus(2L);
  395. warehouseBills.setfItemsStatus(1L);
  396. warehouseBills.setCreateBy(loginUser.getUser().getUserName());
  397. warehouseBills.setfBilltype(billsType);
  398. warehouseBills.setfBsdeptid(loginUser.getUser().getDeptId());
  399. // 业务编码
  400. String billNo = billnoSerialServiceImpl.getBillNo(billsType, warehouseBills.getfBsdate());
  401. warehouseBills.setfBillno(billNo);
  402. if ("SJRK".equals(billsType)) {
  403. // 存货编码
  404. Date time = new Date();
  405. String bscorpno = billnoSerialServiceImpl.getCorpNo(warehouseBills.getfCorpid(), time);
  406. warehouseBills.setfBscorpno(bscorpno);
  407. } else {
  408. warehouseBills.setfChargedate(warehouseBills.getfBsdate());
  409. }
  410. tWarehouseBillsMapper.insertTWarehousebills(warehouseBills);
  411. fPid = warehouseBills.getfId();
  412. } else {
  413. fPid = warehouseBills.getfId();
  414. if (!"SJRK".equals(billsType)) {
  415. warehouseBills.setfChargedate(warehouseBills.getfBsdate());
  416. }
  417. warehouseBills.setUpdateBy(loginUser.getUser().getUserName());
  418. warehouseBills.setUpdateTime(new Date());
  419. tWarehouseBillsMapper.updateTWarehousebills(warehouseBills);
  420. tWarehousebillsfeesMapper.deleteByFPid(fPid);
  421. tEnclosureMapper.deleteByFPid(fPid);
  422. // 删除 从表中 未打印账单的数据
  423. deleteBillsitems(fPid, tWarehousebillsitems);
  424. }
  425. // 库存明细添加
  426. if (StringUtils.isNotNull(tWarehousebillsitems) && !"[]".equals(tWarehousebillsitems)) {
  427. JSONArray warehouseJSON = JSONArray.parseArray(tWarehousebillsitems);
  428. List<TWarehousebillsitems> warehousebillsitemsList = JSONObject.parseArray(warehouseJSON.toJSONString(), TWarehousebillsitems.class);
  429. for (TWarehousebillsitems wbItem : warehousebillsitemsList) {
  430. boolean warehouseStatus = "SJRK".equals(billsType) || "SJCK".equals(billsType) || "CKDB".equals(billsType) || "HWTG".equals(billsType) ;
  431. // 仓储计费日期
  432. wbItem.setfBilltype(billsType);
  433. if ("SJRK".equals(billsType)) {
  434. wbItem.setfChargedate(warehouseBills.getfChargedate());
  435. wbItem.setfBillingway(warehouseBills.getfBillingway());
  436. wbItem.setfMblno(warehouseBills.getfMblno());// 入库更新库存前执行update更新明细的提单号等于主表的提单号
  437. }
  438. if (null != wbItem.getfId()) {
  439. wbItem.setUpdateTime(new Date());
  440. wbItem.setUpdateBy(loginUser.getUser().getUserName());
  441. tWarehousebillsitemsMapper.updateTWarehousebillsitems(wbItem);
  442. } else {
  443. // 添加主表 业务单号
  444. wbItem.setfBillno(warehouseBills.getfBillno());
  445. if (!warehouseStatus) {
  446. // wbItem.setfMblno(warehouseBills.getfMblno());
  447. wbItem.setfBillstatus(1L);
  448. } else {
  449. wbItem.setfBillstatus(10L);
  450. }
  451. wbItem.setfPid(fPid);
  452. wbItem.setCreateBy(loginUser.getUser().getUserName());
  453. wbItem.setCreateTime(new Date());
  454. tWarehousebillsitemsMapper.insertTWarehousebillsitems(wbItem);
  455. if (!warehouseStatus) {
  456. // 添加状态log
  457. insertTWarehousebillsLog(wbItem, 10L, loginUser);
  458. }
  459. }
  460. }
  461. }else {
  462. warehouseBills.setfItemsStatus(1L);
  463. tWarehouseBillsMapper.updateTWarehousebills(warehouseBills);
  464. }
  465. // 附件添加
  466. if (StringUtils.isNotNull(tEnclosure) && !"[]".equals(tEnclosure)) {
  467. JSONArray jsonDrArray = JSONArray.parseArray(tEnclosure);
  468. List<TEnclosure> tEnclosureList = JSONObject.parseArray(jsonDrArray.toJSONString(), TEnclosure.class);
  469. for (TEnclosure enclosure : tEnclosureList) {
  470. enclosure.setfPid(fPid);
  471. enclosure.setCreateBy(loginUser.getUser().getUserName());
  472. enclosure.setCreateTime(new Date());
  473. tEnclosureMapper.insertTEnclosure(enclosure);
  474. }
  475. }
  476. // 收款明细添加
  477. if (StringUtils.isNotNull(tWarehousebillsfeesDr) && !"[]".equals(tWarehousebillsfeesDr)) {
  478. JSONArray jsonDrArray = JSONArray.parseArray(tWarehousebillsfeesDr);
  479. List<TWarehousebillsfees> warehousebillsfeesDrList = JSONObject.parseArray(jsonDrArray.toJSONString(), TWarehousebillsfees.class);
  480. for (TWarehousebillsfees wbDr : warehousebillsfeesDrList) {
  481. // 检验 数量*单价=金额
  482. wbDr.setfPid(fPid);
  483. wbDr.setfDc("D");
  484. wbDr.setfBilltype(billsType);
  485. wbDr.setCreateTime(new Date());
  486. wbDr.setSrcBillNo(warehouseBills.getfBillno());
  487. wbDr.setfChargedate(warehouseBills.getfChargedate());
  488. wbDr.setfBillingDeadline(warehouseBills.getfChargedate());
  489. wbDr.setCreateBy(loginUser.getUser().getUserName());
  490. if (warehouseBills.getfBsdate() != null && !warehouseBills.getfBsdate().equals("")) {
  491. wbDr.setfBsdate(warehouseBills.getfBsdate());
  492. }
  493. tWarehousebillsfeesMapper.insertTWarehousebillsfees(wbDr);
  494. }
  495. }
  496. // 付款明细添加
  497. if (StringUtils.isNotNull(tWarehousebillsfeesCr) && !"[]".equals(tWarehousebillsfeesCr)) {
  498. JSONArray jsonCrArray = JSONArray.parseArray(tWarehousebillsfeesCr);
  499. List<TWarehousebillsfees> warehousebillsfeesCrList = JSONObject.parseArray(jsonCrArray.toJSONString(), TWarehousebillsfees.class);
  500. for (TWarehousebillsfees wbCr : warehousebillsfeesCrList) {
  501. wbCr.setfPid(fPid);
  502. wbCr.setfDc("C");
  503. wbCr.setfBilltype(billsType);
  504. wbCr.setCreateTime(new Date());
  505. wbCr.setSrcBillNo(warehouseBills.getfBillno());
  506. wbCr.setCreateBy(loginUser.getUser().getUserName());
  507. wbCr.setfChargedate(warehouseBills.getfChargedate());
  508. wbCr.setfBillingDeadline(warehouseBills.getfChargedate());
  509. if (warehouseBills.getfBsdate() != null && !warehouseBills.getfBsdate().equals("")) {
  510. wbCr.setfBsdate(warehouseBills.getfBsdate());
  511. }
  512. tWarehousebillsfeesMapper.insertTWarehousebillsfees(wbCr);
  513. }
  514. }
  515. TWarehousebillsitems warehousebillsitems = new TWarehousebillsitems();
  516. warehousebillsitems.setfPid(fPid);
  517. map.put("warehouseBills", warehouseBills);
  518. map.put("warehousebillsitems", tWarehousebillsitemsMapper.selectGoodsTransferitemsList(warehousebillsitems));
  519. return AjaxResult.success("成功", map);
  520. }
  521. /**
  522. * 仓库模块提交接口
  523. *
  524. * @param tWarehouseBills 仓库主表
  525. * @param tWarehousebillsfeesCr 仓库费用付款明细表
  526. * @param tWarehousebillsfeesDr 仓库费用收款明细表
  527. * @param tWarehousebillsitems 仓库货物明细表
  528. * @param tEnclosure
  529. * @param loginUser 当前登陆人
  530. * @param billsType 操作状态
  531. * @return
  532. */
  533. @Override
  534. @Transactional
  535. public AjaxResult warehouseSubmission(String tWarehouseBills, String tWarehousebillsfeesCr, String tWarehousebillsfeesDr,
  536. String tWarehousebillsitems, String tEnclosure, LoginUser loginUser, String billsType) {
  537. Long fPid = null;
  538. boolean isApprove = false;
  539. String key = "";
  540. long actId = 0L;
  541. if ("SJRK".equals(billsType)) {
  542. actId = 110L;
  543. key = "warehouse.inStock.ApprovalFlow";
  544. } else if ("SJCK".equals(billsType)) {
  545. actId = 120L;
  546. key = "warehouse.outStock.ApprovalFlow";
  547. } else if ("CKDB".equals(billsType)) {
  548. actId = 140L;
  549. key = "warehouse.stockTransfer.ApprovalFlow";
  550. } else if ("HQZY".equals(billsType)) {
  551. actId = 130L;
  552. key = "warehouse.transfer.ApprovalFlow";
  553. } else if ("HWTG".equals(billsType)) {
  554. actId = 160L;
  555. key = "warehouse.cargoClearance.ApprovalFlow";
  556. }
  557. SysConfig sysConfig = sysConfigMapper.checkConfigKeyUnique(key);
  558. if (StringUtils.isNull(sysConfig)) {
  559. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  560. return AjaxResult.error("系统参数异常,未找到开启审批流参数");
  561. }
  562. if ("0".equals(sysConfig.getConfigValue())) {
  563. isApprove = true;
  564. }
  565. TWarehouseBills warehouseBills = JSONArray.parseObject(tWarehouseBills, TWarehouseBills.class);
  566. warehouseBills.setfItemsStatus(4L);
  567. if (StringUtils.isNull(warehouseBills.getfId())) {
  568. if (isApprove) {
  569. warehouseBills.setfBillstatus(4L);
  570. } else {
  571. warehouseBills.setfBillstatus(6L);
  572. warehouseBills.setfReviewDate(new Date());
  573. }
  574. warehouseBills.setfBilltype(billsType);
  575. if (!"SJRK".equals(billsType)) {
  576. warehouseBills.setfChargedate(warehouseBills.getfBsdate());
  577. }
  578. warehouseBills.setfBsdeptid(loginUser.getUser().getDeptId());
  579. warehouseBills.setCreateBy(loginUser.getUser().getUserName());
  580. String billNo = billnoSerialServiceImpl.getBillNo(billsType, warehouseBills.getfBsdate());
  581. warehouseBills.setfBillno(billNo);
  582. Date time = new Date();
  583. String bscorpno = billnoSerialServiceImpl.getCorpNo(warehouseBills.getfCorpid(), time);
  584. warehouseBills.setfBscorpno(bscorpno);
  585. tWarehouseBillsMapper.insertTWarehousebills(warehouseBills);
  586. fPid = warehouseBills.getfId();
  587. } else {
  588. fPid = warehouseBills.getfId();
  589. if (isApprove) {
  590. warehouseBills.setfBillstatus(4L);
  591. } else {
  592. warehouseBills.setfBillstatus(6L);
  593. warehouseBills.setfReviewDate(new Date());
  594. }
  595. warehouseBills.setUpdateTime(new Date());
  596. if (!"SJRK".equals(billsType)) {
  597. warehouseBills.setfChargedate(warehouseBills.getfBsdate());
  598. }
  599. warehouseBills.setUpdateBy(loginUser.getUser().getUserName());
  600. tEnclosureMapper.deleteByFPid(fPid);
  601. tWarehousebillsfeesMapper.deleteByFPid(fPid);
  602. tWarehousebillsitemsMapper.deleteByFPid(fPid);
  603. tWarehouseBillsMapper.updateTWarehousebills(warehouseBills);
  604. }
  605. JSONArray warehouseJSON = JSONArray.parseArray(tWarehousebillsitems);
  606. List<TWarehousebillsitems> warehousebillsitemsList = JSONObject.parseArray(warehouseJSON.toJSONString(), TWarehousebillsitems.class);
  607. int line = 0;
  608. for (TWarehousebillsitems wbItem : warehousebillsitemsList) {
  609. line++;
  610. if ("SJRK".equals(billsType) || "SJCK".equals(billsType) || "CKDB".equals(billsType) || "HWTG".equals(billsType) ) {
  611. // 除了入库其他模块不需要更新主表的 仓储费计费日期到明细表,其他模块 应从库存总账把仓储费计费日期 赋给明细表
  612. if ("SJRK".equals(billsType)) {
  613. wbItem.setfMblno(warehouseBills.getfMblno());
  614. wbItem.setfBillingway(warehouseBills.getfBillingway());
  615. wbItem.setfChargedate(warehouseBills.getfChargedate());
  616. wbItem.setfOriginalbilldate(warehouseBills.getfBsdate());
  617. wbItem.setfMblno(warehouseBills.getfMblno());// 入库更新库存前执行update更新明细的提单号等于主表的提单号
  618. }
  619. if (!wbItem.getfBillstatus().equals(40L)) {
  620. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  621. return AjaxResult.error("库存明细第" + line + "行状态异常,请确认");
  622. }
  623. } else {
  624. if (!wbItem.getfBillstatus().equals(6L)) {
  625. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  626. return AjaxResult.error("库存明细第" + line + "行状态异常,请确认");
  627. }
  628. }
  629. if (StringUtils.isNull(wbItem.getfChargedate())) {
  630. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  631. return AjaxResult.error("库存明细第" + line + "行未找到仓储费计费日期,请确认");
  632. }
  633. if (StringUtils.isNull(wbItem.getfBillingway())) {
  634. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  635. return AjaxResult.error("库存明细第" + line + "行未找到计费方式,请确认");
  636. }
  637. if (StringUtils.isNull(wbItem.getfOriginalbilldate())) {
  638. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  639. return AjaxResult.error("库存明细第" + line + "行未找到入库日期,请确认");
  640. }
  641. wbItem.setfPid(fPid);
  642. wbItem.setfBilltype(billsType);
  643. wbItem.setCreateTime(new Date());
  644. wbItem.setfBillno(warehouseBills.getfBillno());
  645. wbItem.setCreateBy(loginUser.getUser().getUserName());
  646. tWarehousebillsitemsMapper.insertTWarehousebillsitems(wbItem);
  647. }
  648. if (StringUtils.isNotNull(tWarehousebillsfeesCr) && !"[]".equals(tWarehousebillsfeesCr)) {
  649. JSONArray jsonCrArray = JSONArray.parseArray(tWarehousebillsfeesCr);
  650. List<TWarehousebillsfees> warehousebillsfeesCrList = JSONObject.parseArray(jsonCrArray.toJSONString(), TWarehousebillsfees.class);
  651. for (TWarehousebillsfees wbCr : warehousebillsfeesCrList) {
  652. wbCr.setfPid(fPid);
  653. wbCr.setfDc("C");
  654. wbCr.setfBilltype(billsType);
  655. wbCr.setCreateTime(new Date());
  656. wbCr.setSrcBillNo(warehouseBills.getfBillno());
  657. wbCr.setCreateBy(loginUser.getUser().getUserName());
  658. wbCr.setfChargedate(warehouseBills.getfChargedate());
  659. wbCr.setfBillingDeadline(warehouseBills.getfChargedate());
  660. if (warehouseBills.getfBsdate() != null && !warehouseBills.getfBsdate().equals("")) {
  661. wbCr.setfBsdate(warehouseBills.getfBsdate());
  662. }
  663. tWarehousebillsfeesMapper.insertTWarehousebillsfees(wbCr);
  664. }
  665. }
  666. if (StringUtils.isNotNull(tWarehousebillsfeesDr) && !"[]".equals(tWarehousebillsfeesDr)) {
  667. JSONArray jsonCrArray = JSONArray.parseArray(tWarehousebillsfeesDr);
  668. List<TWarehousebillsfees> warehousebillsfeesDrList = JSONObject.parseArray(jsonCrArray.toJSONString(), TWarehousebillsfees.class);
  669. for (TWarehousebillsfees wbDr : warehousebillsfeesDrList) {
  670. wbDr.setfPid(fPid);
  671. wbDr.setfDc("D");
  672. wbDr.setfBillstatus(4L);
  673. wbDr.setfBilltype(billsType);
  674. wbDr.setCreateTime(new Date());
  675. wbDr.setSrcBillNo(warehouseBills.getfBillno());
  676. wbDr.setCreateBy(loginUser.getUser().getUserName());
  677. wbDr.setfChargedate(warehouseBills.getfChargedate());
  678. wbDr.setfBillingDeadline(warehouseBills.getfChargedate());
  679. if (warehouseBills.getfBsdate() != null && !warehouseBills.getfBsdate().equals("")) {
  680. wbDr.setfBsdate(warehouseBills.getfBsdate());
  681. }
  682. tWarehousebillsfeesMapper.insertTWarehousebillsfees(wbDr);
  683. }
  684. }
  685. if (StringUtils.isNotNull(tEnclosure) && !"[]".equals(tEnclosure)) {
  686. JSONArray jsonEnclosureArray = JSONArray.parseArray(tEnclosure);
  687. List<TEnclosure> enclosuresList = JSONObject.parseArray(jsonEnclosureArray.toJSONString(), TEnclosure.class);
  688. long lineNo = 0L;
  689. for (TEnclosure enclosure : enclosuresList) {
  690. lineNo++;
  691. enclosure.setfPid(fPid);
  692. enclosure.setfLineno(lineNo);
  693. enclosure.setCreateTime(new Date());
  694. enclosure.setCreateBy(loginUser.getUser().getUserName());
  695. tEnclosureMapper.insertTEnclosure(enclosure);
  696. }
  697. }
  698. // 这里加个判断取系统参数来确定是否需要启用审批流
  699. if (isApprove) {
  700. AuditItems auditItems = new AuditItems();
  701. auditItems.setLevelId(0L);
  702. auditItems.setBillId(fPid);
  703. auditItems.setActId(actId);
  704. auditItems.setIffinalItem("F");
  705. auditItems.setBillNo(warehouseBills.getfBillno());
  706. // 存储委托方(货权方)
  707. auditItems.setRefno1(warehouseBills.getfCorpid() + "");
  708. // 存储业务类型(业务类型)
  709. auditItems.setRefno2(warehouseBills.getfBilltype());
  710. // 存储提单号(提单号)
  711. auditItems.setRefno3(warehouseBills.getfMblno());
  712. auditItems.setSendUserId(loginUser.getUser().getUserId());
  713. auditItems.setSendName(loginUser.getUsername());
  714. auditItems.setSendTime(new Date());
  715. auditItems.setAuditUserId(loginUser.getUser().getUserId());
  716. auditItems.setAuditItem(new Date());
  717. auditItems.setAuditOpTime(new Date());
  718. auditItems.setAuditMsg("提交");
  719. auditItems.setAuditStatus("O");
  720. AjaxResult approvalFlow = auditItemsService.createApprovalFlow(auditItems);
  721. // Long code = Long.valueOf(String.valueOf(approvalFlow.get("code"))).longValue();
  722. String code = approvalFlow.get("code").toString();
  723. // Long code = Long.valueOf(String.valueOf(ajaxResult.get("code"))).longValue();
  724. if ("500".equals(code)) {
  725. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  726. }
  727. return approvalFlow;
  728. } else {
  729. AjaxResult ajaxResult = warehouseFollow(fPid, 6L);
  730. String code = ajaxResult.get("code").toString();
  731. // Long code = Long.valueOf(String.valueOf(ajaxResult.get("code"))).longValue();
  732. if ("500".equals(code)) {
  733. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  734. }
  735. return ajaxResult;
  736. }
  737. }
  738. @Override
  739. public List<TWareHouseExcelItems> selectTWarehousebillsItemsList(Long fId) {
  740. return tWarehouseBillsMapper.selectTWarehousebillsItemsList(fId);
  741. }
  742. @Override
  743. public List<Map<String, Object>> selectInventoryList(TWarehouseBills tWarehouseBills) {
  744. if(StringUtils.isNotNull(tWarehouseBills.getfWarehouseid())){
  745. // 获取仓库信息
  746. TWarehouse tWarehouse = tWarehouseMapper.selectTWarehouseById(tWarehouseBills.getfWarehouseid());
  747. if(tWarehouse.getfLocation()==1){
  748. tWarehouseBills.setfLocation(1L);
  749. }else {
  750. tWarehouseBills.setfLocation(0L);
  751. }
  752. }
  753. if(tWarehouseBills.getfBilltype().equals("SJRK")){
  754. return tWarehouseBillsMapper.selectInventorySJRKList(tWarehouseBills);
  755. }else {
  756. return tWarehouseBillsMapper.selectInventorySJCKList(tWarehouseBills);
  757. }
  758. }
  759. @Override
  760. public List<TWareHouseItemsExcel> selectTWarehousebillsItemsList(TWarehouseBills tWarehouseBills) {
  761. return tWarehouseBillsMapper.selectTWarehousebillsItemList(tWarehouseBills);
  762. }
  763. @Override
  764. public AjaxResult serialNumber(String billsType) {
  765. Map<String, Object> map = new HashMap<>();
  766. Date time = new Date();
  767. String serialNumber = null;
  768. // 查询流水号
  769. if ("SJRK".equals(billsType)) {
  770. serialNumber = billnoSerialServiceImpl.getFictitiousNumber("RK", time);
  771. } else if ("SJCK".equals(billsType)) {
  772. serialNumber = billnoSerialServiceImpl.getFictitiousNumber("CK", time);
  773. } else if ("CKDB".equals(billsType)) {
  774. serialNumber = billnoSerialServiceImpl.getFictitiousNumber("DB", time);
  775. }
  776. map.put("fSerialNumber",serialNumber);
  777. return AjaxResult.success("成功",map);
  778. }
  779. @Override
  780. public int derecognition(Long fId) {
  781. // 查询对账
  782. int reconciliation = tWarehousebillsfeesMapper.selectReconciliation(fId);
  783. // 查询收费
  784. int charge = tWarehousebillsfeesMapper.selectCharge(fId);
  785. // 查询付费
  786. int pay = tWarehousebillsfeesMapper.selectPay(fId);
  787. if(reconciliation >0 ){
  788. return 1;
  789. }else if(charge >0){
  790. return 2;
  791. }else if(pay >0){
  792. return 3;
  793. }else {
  794. return 4;
  795. }
  796. }
  797. @Override
  798. public List<Map<String, Object>> selectWareHouseNumber() {
  799. List<Map<String, Object>> map= new ArrayList<>();
  800. Map<String, Object> maps = new HashMap<>();
  801. // 入库待办数量
  802. maps.put("inStock",tWarehousebillsitemsMapper.inStock());
  803. // 出库待办数量
  804. maps.put("outStock",tWarehousebillsitemsMapper.outStock());
  805. List<String> timeInterval =new ArrayList<>();
  806. SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
  807. //获取当前月第一天:
  808. Calendar c = Calendar.getInstance();
  809. c.add(Calendar.MONTH, 0);
  810. c.set(Calendar.DAY_OF_MONTH,1);//设置为1号,当前日期既为本月第一天
  811. timeInterval.add(format.format(c.getTime()));
  812. //获取前月的最后一天
  813. Calendar ca = Calendar.getInstance();
  814. ca.set(Calendar.DAY_OF_MONTH, ca.getActualMaximum(Calendar.DAY_OF_MONTH));
  815. timeInterval.add(format.format(ca.getTime()));
  816. maps.put("monthInStock",tWarehousebillsitemsMapper.monthInStock(timeInterval));
  817. // 当月出库待办数量
  818. maps.put("monthOutStock",tWarehousebillsitemsMapper.monthOutStock(timeInterval));
  819. map.add(maps);
  820. return map;
  821. }
  822. @Override
  823. public List<Map<String, Object>> selectWarehouseBusinessInStockList(TWarehousebillsitems tWarehousebillsitems) {
  824. if(tWarehousebillsitems.getfBilltype().equals("SJRK")){
  825. return tWarehousebillsitemsMapper.selectWarehouseBusinesInList(tWarehousebillsitems);
  826. }else {
  827. return tWarehousebillsitemsMapper.selectWarehouseBusinesOutList(tWarehousebillsitems);
  828. }
  829. }
  830. @Override
  831. @Transactional
  832. public AjaxResult waitWarehousingItems(TWarehousebillsitems tWarehousebillsitems) {
  833. // 先查询是否已经处理
  834. TWarehousebillsitems tWarehousebillsitems1=tWarehousebillsitemsMapper.selectTWarehousebillsitemsById(tWarehousebillsitems.getfId());
  835. if(tWarehousebillsitems1.getfBillstatus().equals(30)){
  836. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  837. return AjaxResult.error("更新库存明细失败,该信息已操作,请重新加载");
  838. }
  839. tWarehousebillsitems.setfSerialNumber(tWarehousebillsitems1.getfSerialNumber());
  840. int num = tWarehousebillsitemsMapper.updateTWarehousebillsitems(tWarehousebillsitems);
  841. // 主表变更状态
  842. TWarehouseBills tWarehousebills = new TWarehouseBills();
  843. tWarehousebills.setfId(tWarehousebillsitems1.getfPid());
  844. tWarehousebills.setfItemsStatus(3L);
  845. int num1 = tWarehouseBillsMapper.updateTWarehousebills(tWarehousebills);
  846. if (num <= 0 && num1 <= 0 ) {
  847. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  848. return AjaxResult.error("更新库存明细失败");
  849. }else{
  850. return AjaxResult.success();
  851. }
  852. }
  853. @Override
  854. @Transactional
  855. public AjaxResult addCreditItems(String tEnclosure ,String tWarehousebillsitems, String billsType,LoginUser loginUser) {
  856. TWarehouseBills tWarehouseBills =new TWarehouseBills();
  857. TWarehousebillsitems warehousebillsitemsList=JSONArray.parseObject(tWarehousebillsitems, TWarehousebillsitems.class);
  858. if(billsType.equals("SJRK")){
  859. if(null!=warehousebillsitemsList){
  860. // 先查询是否已经处理
  861. TWarehousebillsitems tWarehousebillsitems1=tWarehousebillsitemsMapper.selectTWarehousebillsitemsById(warehousebillsitemsList.getfId());
  862. if(tWarehousebillsitems1.getfBillstatus().equals(40)){
  863. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  864. return AjaxResult.error("更新库存明细失败,该信息已操作,请重新加载");
  865. }
  866. // 查询主表
  867. tWarehouseBills = tWarehouseBillsMapper.selectTWarehousebillsById(warehousebillsitemsList.getfPid());
  868. // 明细原本数据
  869. TWarehousebillsitems tWarehousebillsitems2 = tWarehousebillsitemsMapper.selectTWarehousebillsitemsById(warehousebillsitemsList.getfId());
  870. // 查询库容量 是否可入库
  871. int m = calculation(tWarehouseBills.getfWarehouseid(), warehousebillsitemsList.getfGrossweight());
  872. if (m == 0) {
  873. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  874. return AjaxResult.error("更新库存总账失败-->入库毛重大于库容");
  875. }
  876. warehousebillsitemsList.setfBillingway(tWarehouseBills.getfBillingway());
  877. warehousebillsitemsList.setfChargedate(tWarehouseBills.getfChargedate());
  878. TWhgenleg tWhgenle = queryTWhgenleg(tWarehouseBills, tWarehousebillsitems2);
  879. if (StringUtils.isNotNull(tWhgenle)) {
  880. int i = updateTWhgenlegData(warehousebillsitemsList, tWhgenle.getfId(), billsType);
  881. if (i <= 0) {
  882. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  883. return AjaxResult.error("更新库存总账失败");
  884. }
  885. } else {
  886. tWarehousebillsitems2.setfQty(warehousebillsitemsList.getfQty());
  887. tWarehousebillsitems2.setfGrossweight(warehousebillsitemsList.getfGrossweight());
  888. tWarehousebillsitems2.setfNetweight(warehousebillsitemsList.getfNetweight());
  889. if (instalTWhgenleg(tWarehouseBills, tWarehousebillsitems2, loginUser.getUser()) <= 0) {
  890. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  891. return AjaxResult.error("新增库存总账失败");
  892. }
  893. }
  894. warehousebillsitemsList.setfIsInventory(0L);
  895. warehousebillsitemsList.setfSerialNumber(tWarehousebillsitems2.getfSerialNumber());
  896. int num = 0;
  897. if (StringUtils.isNotNull(warehousebillsitemsList.getfId())) {
  898. warehousebillsitemsList.setfBillstatus(40L);
  899. warehousebillsitemsList.setUpdateBy(loginUser.getUser().getUserName());
  900. warehousebillsitemsList.setUpdateTime(new Date());
  901. num = tWarehousebillsitemsMapper.updateTWarehousebillsitems(warehousebillsitemsList);
  902. // 添加状态log
  903. insertTWarehousebillsLog(warehousebillsitemsList, 40L, loginUser);
  904. }
  905. if (num <= 0) {
  906. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  907. return AjaxResult.error("新增库存明细失败");
  908. }
  909. }
  910. }else {
  911. if(null!=warehousebillsitemsList){
  912. // 先查询是否已经处理
  913. TWarehousebillsitems tWarehousebillsitems1=tWarehousebillsitemsMapper.selectTWarehousebillsitemsById(warehousebillsitemsList.getfId());
  914. if(tWarehousebillsitems1.getfBillstatus().equals(40)){
  915. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  916. return AjaxResult.error("更新库存明细失败,该信息已操作,请重新加载");
  917. }
  918. // 查询主表
  919. tWarehouseBills = tWarehouseBillsMapper.selectTWarehousebillsById(warehousebillsitemsList.getfPid());
  920. // 明细原本数据
  921. TWarehousebillsitems tWarehousebillsitems2 = tWarehousebillsitemsMapper.selectTWarehousebillsitemsById(warehousebillsitemsList.getfId());
  922. // 查询总账是否存在
  923. TWhgenleg tWhgenle = queryTWhgenleg(tWarehouseBills, tWarehousebillsitems2);
  924. if (StringUtils.isNull(tWhgenle)) { // 为空 提示没有库存
  925. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  926. return AjaxResult.error("库存明细库存为空");
  927. } else { // 非空修改库存总账
  928. // 库存 < 出库件数
  929. if (tWhgenle.getfQtyblc() < warehousebillsitemsList.getfQty()) {
  930. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  931. return AjaxResult.error("库存明细库存不足");
  932. }
  933. // 更新库存总账
  934. warehousebillsitemsList.setfVolumn(tWarehousebillsitems2.getfVolumn());
  935. updateTWhgenlegData(warehousebillsitemsList, tWhgenle.getfId(), billsType);
  936. if (StringUtils.isNull(tWarehouseBills.getfBsdate()) ) {
  937. return AjaxResult.error("库存明细请检查日期,操作终止");
  938. }
  939. if (StringUtils.isNull(tWarehouseBills.getfCorpid())) {
  940. return AjaxResult.error("库存明细请检查客户信息,操作终止");
  941. }
  942. }
  943. warehousebillsitemsList.setfBillstatus(40L);
  944. warehousebillsitemsList.setfSerialNumber(tWarehousebillsitems2.getfSerialNumber());
  945. int num = 0;
  946. warehousebillsitemsList.setfPid(tWarehouseBills.getfId());
  947. warehousebillsitemsList.setfBilltype(billsType);
  948. warehousebillsitemsList.setfBillno(tWarehouseBills.getfBillno());
  949. warehousebillsitemsList.setfBsdate(tWarehouseBills.getfBsdate());
  950. if (StringUtils.isNotNull(warehousebillsitemsList.getfId())) {
  951. warehousebillsitemsList.setUpdateBy(loginUser.getUser().getUserName());
  952. warehousebillsitemsList.setUpdateTime(new Date());
  953. num = tWarehousebillsitemsMapper.updateTWarehousebillsitems(warehousebillsitemsList);
  954. // 添加状态log
  955. insertTWarehousebillsLog(warehousebillsitemsList, 40L, loginUser);
  956. }
  957. if (num <= 0) {
  958. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  959. return AjaxResult.error("库存明细更新失败");
  960. }
  961. }
  962. }
  963. // 主表修改
  964. tWarehouseBills.setfItemsStatus(4L);
  965. tWarehouseBills.setfBilltype(billsType);
  966. tWarehouseBills.setUpdateBy(loginUser.getUser().getUserName());
  967. tWarehouseBills.setUpdateTime(new Date());
  968. tWarehouseBillsMapper.updateTWarehousebills(tWarehouseBills);
  969. // 附件添加
  970. if (StringUtils.isNotEmpty(tEnclosure) && !"[]".equals(tEnclosure)) {
  971. JSONArray jsonDrArray = JSONArray.parseArray(tEnclosure);
  972. List<TEnclosure> tEnclosureList = JSONObject.parseArray(jsonDrArray.toJSONString(), TEnclosure.class);
  973. for (TEnclosure enclosure : tEnclosureList) {
  974. enclosure.setfPid(tWarehouseBills.getfId());
  975. enclosure.setCreateBy(loginUser.getUser().getUserName());
  976. enclosure.setCreateTime(new Date());
  977. tEnclosureMapper.insertTEnclosure(enclosure);
  978. }
  979. }
  980. return AjaxResult.success();
  981. }
  982. @Override
  983. public List<InStock> inStockExport(TWarehouseBills tWarehousebills) throws Exception {
  984. List<Map<String, Object>> list = tWarehouseBillsMapper.selectWarehouseBusinessList(tWarehousebills);
  985. List<InStock> list1 = ListMapToBeanUtils.castMapToBean(list,InStock.class);
  986. return list1;
  987. }
  988. @Override
  989. public List<OutStock> outStockExport(TWarehouseBills tWarehousebills) throws Exception {
  990. List<Map<String, Object>> list = tWarehouseBillsMapper.selectWarehouseBusinessList(tWarehousebills);
  991. List<OutStock> list1 = ListMapToBeanUtils.castMapToBean(list,OutStock.class);
  992. return list1;
  993. }
  994. @Override
  995. public List<StockTransfer> stockTransferExport(TWarehouseBills tWarehousebills) throws Exception {
  996. List<Map<String, Object>> list = tWarehouseBillsMapper.selectWarehouseBusinessList(tWarehousebills);
  997. List<StockTransfer> list1 = ListMapToBeanUtils.castMapToBean(list,StockTransfer.class);
  998. return list1;
  999. }
  1000. @Override
  1001. public List<GoodsTransfer> goodsTransferExport(TWarehouseBills tWarehousebills) throws Exception {
  1002. List<Map<String, Object>> list = tWarehouseBillsMapper.selectWarehouseBusinessList1(tWarehousebills);
  1003. List<GoodsTransfer> list1 = ListMapToBeanUtils.castMapToBean(list,GoodsTransfer.class);
  1004. return list1;
  1005. }
  1006. @Override
  1007. public List<StorageFee> storageFeeExport(TWarehouseBills tWarehousebills) throws Exception {
  1008. List<Map<String, Object>> list = tWarehouseBillsMapper.selectWarehouseBusinessList1(tWarehousebills);
  1009. List<StorageFee> list1 = ListMapToBeanUtils.castMapToBean(list,StorageFee.class);
  1010. return list1;
  1011. }
  1012. /**
  1013. * 根据仓库主表id 更新对应明细表状态
  1014. *
  1015. * @param fPid 仓库主表id
  1016. * @return 结果
  1017. */
  1018. @Transactional
  1019. public AjaxResult warehouseFollow(Long fPid, long fettle) {
  1020. if (StringUtils.isNull(fPid)) {
  1021. return AjaxResult.error("仓库更新状态未找到主表信息,请与管理员联系");
  1022. }
  1023. try {
  1024. tWarehouseBillsMapper.warehouseFollowUpdate(fPid, fettle, new Date());
  1025. tWarehousebillsfeesMapper.warehouseFeesFollowUpdate(fPid, fettle, new Date());
  1026. TWarehouseBills tWarehouseBills = tWarehouseBillsMapper.selectTWarehousebillsById(fPid);
  1027. if ("SJRK".equals(tWarehouseBills.getfBilltype()) || "SJCK".equals(tWarehouseBills.getfBilltype())) {
  1028. fettle = 40L;
  1029. }
  1030. tWarehousebillsitemsMapper.warehouseItemFollowUpdate(fPid, fettle);
  1031. } catch (Exception e) {
  1032. return AjaxResult.error("更新库存费用状态失败,请联系管理员");
  1033. }
  1034. return AjaxResult.success();
  1035. }
  1036. /**
  1037. * 根据仓库主表id 更新对应明细表状态
  1038. *
  1039. * @param fPid 仓库主表id
  1040. * @return 结果
  1041. */
  1042. @Transactional
  1043. public AjaxResult storageFeeFollow(Long fPid, long fettle) {
  1044. if (StringUtils.isNull(fPid)) {
  1045. return AjaxResult.error("仓库更新状态未找到主表信息,请与管理员联系");
  1046. }
  1047. int warehouseUpdateResult = tWarehouseBillsMapper.warehouseFollowUpdate(fPid, fettle, new Date());
  1048. if (warehouseUpdateResult <= 0) {
  1049. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1050. return AjaxResult.error("更新库存明细状态失败,请联系管理员");
  1051. }
  1052. TWarehousebillsfees warehousebillsfees = new TWarehousebillsfees();
  1053. warehousebillsfees.setfPid(fPid);
  1054. List<TWarehousebillsfees> warehousebillsfeesList = tWarehousebillsfeesMapper.selectTWarehousebillsfeesList(warehousebillsfees);
  1055. for (TWarehousebillsfees wareItem : warehousebillsfeesList) {
  1056. if (StringUtils.isNull(wareItem.getSrcId())) {
  1057. continue;
  1058. }
  1059. if ("KCZZ".equals(wareItem.getfBilltype())) {
  1060. TWhgenleg tWhgenleg = tWhgenlegMapper.selectTWhgenlegById(wareItem.getSrcId());
  1061. tWhgenleg.setfChargedate(DateUtils.dateAdd(wareItem.getfBillingDeadline(), 1));
  1062. int i = tWhgenlegMapper.updateTWhgenleg(tWhgenleg);
  1063. if (i <= 0) {
  1064. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1065. return AjaxResult.error("更新库存费用状态失败,请联系管理员");
  1066. }
  1067. } else {
  1068. TWarehousebillsitems tWarehousebillsitems = tWarehousebillsitemsMapper.selectTWarehousebillsitemsById(wareItem.getSrcId());
  1069. tWarehousebillsitems.setfChargedate(DateUtils.dateAdd(wareItem.getfBillingDeadline(), 1));
  1070. if ("SJCK".equals(wareItem.getfBilltype())) {
  1071. tWarehousebillsitems.setfStorageFeeDeadline(wareItem.getfBillingDeadline());
  1072. }
  1073. tWarehousebillsitemsMapper.updateTWarehousebillsitems(tWarehousebillsitems);
  1074. }
  1075. }
  1076. int feesUpdateResult = tWarehousebillsfeesMapper.warehouseFeesFollowUpdate(fPid, fettle, new Date());
  1077. if (feesUpdateResult <= 0) {
  1078. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1079. return AjaxResult.error("更新库存费用状态失败,请联系管理员");
  1080. }
  1081. return AjaxResult.success();
  1082. }
  1083. /**
  1084. * 入库详情入账
  1085. *
  1086. * @param warehouseBills 主表
  1087. * @param warehousebillsitems 明细
  1088. * @param loginUser 当前登录人
  1089. * @param billsType 状态
  1090. * @return 结果
  1091. */
  1092. @Override
  1093. @Transactional
  1094. public AjaxResult addCredit(String warehouseBills, String warehousebillsitems, String tEnclosure, String warehousebillsfeesCr,
  1095. String warehousebillsfeesDr, LoginUser loginUser, String billsType) {
  1096. Map<String, Object> map = new HashMap<>();
  1097. if (StringUtils.isNull(warehouseBills) || "[]".equals(warehouseBills)) {
  1098. return AjaxResult.error("未找到主表信息");
  1099. }
  1100. if (StringUtils.isNull(warehousebillsitems) || "[]".equals(warehousebillsitems)) {
  1101. return AjaxResult.error("未找到入账信息");
  1102. }
  1103. TWarehouseBills tWarehouseBills = JSONArray.parseObject(warehouseBills, TWarehouseBills.class);
  1104. tWarehouseBills.setfItemsStatus(4L);
  1105. tWarehouseBills.setfBilltype(billsType);
  1106. tWarehouseBills.setUpdateBy(loginUser.getUser().getUserName());
  1107. tWarehouseBills.setUpdateTime(new Date());
  1108. tWarehouseBillsMapper.updateTWarehousebills(tWarehouseBills);
  1109. tEnclosureMapper.deleteByFPid(tWarehouseBills.getfId());
  1110. tWarehousebillsfeesMapper.deleteByFPid(tWarehouseBills.getfId());
  1111. boolean businessStatus = "场地直装".equals(tWarehouseBills.getfBusinessType());
  1112. JSONArray warehouseJSON = JSONArray.parseArray(warehousebillsitems);
  1113. List<TWarehousebillsitems> warehousebillsitemsList = JSONObject.parseArray(warehouseJSON.toJSONString(), TWarehousebillsitems.class);
  1114. int i=1;
  1115. for (TWarehousebillsitems item : warehousebillsitemsList) {
  1116. // 查询是否可以修改
  1117. TWarehousebillsitems tWarehousebillsitems = tWarehousebillsitemsMapper.selectTWarehousebillsitemsById(item.getfId());
  1118. if(tWarehousebillsitems.getfBillstatus()==40){
  1119. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1120. return AjaxResult.error("更新库存明细第"+i+"行失败,已处理,请刷新网页");
  1121. }
  1122. if (!businessStatus) {
  1123. // 查询库容量 是否可入库
  1124. int m = calculation(tWarehouseBills.getfWarehouseid(), item.getfGrossweight());
  1125. if (m == 0) {
  1126. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1127. return AjaxResult.error("更新库存总账失败-->入库毛重大于库容");
  1128. }
  1129. item.setfBillingway(tWarehouseBills.getfBillingway());
  1130. item.setfChargedate(tWarehouseBills.getfChargedate());
  1131. TWhgenleg tWhgenle = queryTWhgenleg(tWarehouseBills, item);
  1132. if (StringUtils.isNotNull(tWhgenle)) {
  1133. int i1 = updateTWhgenlegData(item, tWhgenle.getfId(), billsType);
  1134. if (i1 <= 0) {
  1135. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1136. return AjaxResult.error("更新库存总账失败");
  1137. }
  1138. } else {
  1139. if (instalTWhgenleg(tWarehouseBills, item, loginUser.getUser()) <= 0) {
  1140. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1141. return AjaxResult.error("新增库存总账失败");
  1142. }
  1143. }
  1144. item.setfIsInventory(0L);
  1145. } else {
  1146. item.setfIsInventory(1L);
  1147. }
  1148. int num = 0;
  1149. if (StringUtils.isNotNull(item.getfId())) {
  1150. item.setfBillstatus(40L);
  1151. item.setUpdateBy(loginUser.getUser().getUserName());
  1152. item.setUpdateTime(new Date());
  1153. if("SJRK".equals(billsType)){
  1154. item.setfMblno(tWarehouseBills.getfMblno());// 入库更新库存前执行update更新明细的提单号等于主表的提单号
  1155. }
  1156. num = tWarehousebillsitemsMapper.updateTWarehousebillsitems(item);
  1157. // 添加状态log
  1158. insertTWarehousebillsLog(item, 40L, loginUser);
  1159. }
  1160. if (num <= 0) {
  1161. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1162. return AjaxResult.error("新增库存明细失败");
  1163. }
  1164. i++;
  1165. }
  1166. // 附件添加
  1167. if (StringUtils.isNotEmpty(tEnclosure) && !"[]".equals(tEnclosure)) {
  1168. JSONArray jsonDrArray = JSONArray.parseArray(tEnclosure);
  1169. List<TEnclosure> tEnclosureList = JSONObject.parseArray(jsonDrArray.toJSONString(), TEnclosure.class);
  1170. for (TEnclosure enclosure : tEnclosureList) {
  1171. enclosure.setfPid(tWarehouseBills.getfId());
  1172. enclosure.setCreateBy(loginUser.getUser().getUserName());
  1173. enclosure.setCreateTime(new Date());
  1174. tEnclosureMapper.insertTEnclosure(enclosure);
  1175. }
  1176. }
  1177. // 收款明细添加
  1178. if (StringUtils.isNotEmpty(warehousebillsfeesDr) && !"[]".equals(warehousebillsfeesDr)) {
  1179. JSONArray jsonDrArray = JSONArray.parseArray(warehousebillsfeesDr);
  1180. List<TWarehousebillsfees> warehousebillsfeesDrList = JSONObject.parseArray(jsonDrArray.toJSONString(), TWarehousebillsfees.class);
  1181. for (TWarehousebillsfees wbDr : warehousebillsfeesDrList) {
  1182. wbDr.setfPid(tWarehouseBills.getfId());
  1183. wbDr.setfDc("D");
  1184. wbDr.setCreateBy(loginUser.getUser().getUserName());
  1185. wbDr.setCreateTime(new Date());
  1186. if (tWarehouseBills.getfBsdate() != null && !tWarehouseBills.getfBsdate().equals("")) {
  1187. wbDr.setfBsdate(tWarehouseBills.getfBsdate());
  1188. }
  1189. tWarehousebillsfeesMapper.insertTWarehousebillsfees(wbDr);
  1190. }
  1191. }
  1192. // 付款明细添加
  1193. if (StringUtils.isNotNull(warehousebillsfeesCr) && !"[]".equals(warehousebillsfeesCr)) {
  1194. JSONArray jsonCrArray = JSONArray.parseArray(warehousebillsfeesCr);
  1195. List<TWarehousebillsfees> warehousebillsfeesCrList = JSONObject.parseArray(jsonCrArray.toJSONString(), TWarehousebillsfees.class);
  1196. for (TWarehousebillsfees wbCr : warehousebillsfeesCrList) {
  1197. wbCr.setfPid(tWarehouseBills.getfId());
  1198. wbCr.setfDc("C");
  1199. wbCr.setCreateBy(loginUser.getUser().getUserName());
  1200. wbCr.setCreateTime(new Date());
  1201. if (tWarehouseBills.getfBsdate() != null && !tWarehouseBills.getfBsdate().equals("")) {
  1202. wbCr.setfBsdate(tWarehouseBills.getfBsdate());
  1203. }
  1204. tWarehousebillsfeesMapper.insertTWarehousebillsfees(wbCr);
  1205. }
  1206. }
  1207. map.put("warehousebillsitems", warehousebillsitemsList);
  1208. return AjaxResult.success("成功", map);
  1209. }
  1210. /**
  1211. * 出库、调拨、货转 确认
  1212. *
  1213. * @param warehouseBills
  1214. * @param warehousebillsitems
  1215. * @param loginUser
  1216. * @param billsType
  1217. * @return
  1218. */
  1219. @Override
  1220. @Transactional
  1221. public AjaxResult updateCredit(String warehouseBills, String warehousebillsitems, String tEnclosure, String warehousebillsfeesCr,
  1222. String warehousebillsfeesDr, LoginUser loginUser, String billsType) {
  1223. Long fPid = null;
  1224. Map<String, Object> map = new HashMap<>();
  1225. TWarehouseBills tWarehouseBills = JSONArray.parseObject(warehouseBills, TWarehouseBills.class);
  1226. tWarehouseBills.setfItemsStatus(4L);
  1227. if (StringUtils.isNotNull(tWarehouseBills.getfId())) {
  1228. tWarehouseBills.setUpdateBy(loginUser.getUser().getUserName());
  1229. tWarehouseBills.setUpdateTime(new Date());
  1230. tWarehouseBillsMapper.updateTWarehousebills(tWarehouseBills);
  1231. fPid = tWarehouseBills.getfId();
  1232. } else {
  1233. tWarehouseBills.setfBsdeptid(loginUser.getUser().getDeptId());
  1234. tWarehouseBills.setCreateBy(loginUser.getUser().getUserName());
  1235. tWarehouseBills.setCreateTime(new Date());
  1236. String billNo = billnoSerialServiceImpl.getBillNo(billsType, tWarehouseBills.getfBsdate());
  1237. tWarehouseBills.setfBillno(billNo);
  1238. tWarehouseBillsMapper.insertTWarehousebills(tWarehouseBills);
  1239. fPid = tWarehouseBills.getfId();
  1240. }
  1241. tEnclosureMapper.deleteByFPid(fPid);
  1242. tWarehousebillsfeesMapper.deleteByFPid(fPid);
  1243. JSONArray warehouseJSON = JSONArray.parseArray(warehousebillsitems);
  1244. List<TWarehousebillsitems> warehousebillsitemsList = JSONObject.parseArray(warehouseJSON.toJSONString(), TWarehousebillsitems.class);
  1245. int i = 1;
  1246. List<TFees> feesList = new ArrayList<>();
  1247. List<TWarehousebillsfees> warehousebillsfees = new ArrayList<>();
  1248. for (TWarehousebillsitems wbItem : warehousebillsitemsList) {
  1249. // 查询是否可以修改
  1250. TWarehousebillsitems tWarehousebillsitems = tWarehousebillsitemsMapper.selectTWarehousebillsitemsById(wbItem.getfId());
  1251. if(tWarehousebillsitems.getfBillstatus()==40){
  1252. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1253. return AjaxResult.error("更新库存明细第"+i+"行失败,已处理,请刷新网页");
  1254. }
  1255. long warehouselocId = 0L;
  1256. long transferWarehouselocid = 0L;
  1257. if ("CKDB".equals(billsType) | "HWTG".equals(billsType)) {
  1258. warehouselocId = wbItem.getfWarehouselocid();
  1259. transferWarehouselocid = wbItem.getfTransferWarehouselocid();
  1260. // wbItem.setfWarehouselocid(transferWarehouselocid);
  1261. }
  1262. // 查询总账是否存在
  1263. TWhgenleg tWhgenle = queryTWhgenleg(tWarehouseBills, wbItem);
  1264. // 入库数特殊不判断入账
  1265. if ("SJCK".equals(billsType)) { // 出库 查询
  1266. if (StringUtils.isNull(tWhgenle)) { // 为空 提示没有库存
  1267. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1268. return AjaxResult.error("库存明细第" + i + "行库存为空");
  1269. } else { // 非空修改库存总账
  1270. // 库存 < 出库件数
  1271. if (tWhgenle.getfQtyblc() < wbItem.getfQty()) {
  1272. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1273. return AjaxResult.error("库存明细第" + i + "行库存不足");
  1274. }
  1275. // 更新库存总账
  1276. updateTWhgenlegData(wbItem, tWhgenle.getfId(), billsType);
  1277. if (StringUtils.isNull(tWarehouseBills.getfBsdate()) || StringUtils.isNull(wbItem.getfChargedate())) {
  1278. return AjaxResult.error("库存明细第" + i + "行请检查日期,操作终止");
  1279. }
  1280. long dateDay = DateUtils.getDateDay(tWarehouseBills.getfBsdate(), wbItem.getfChargedate());
  1281. if (StringUtils.isNull(tWarehouseBills.getfCorpid())) {
  1282. return AjaxResult.error("库存明细第" + i + "行请检查客户信息,操作终止");
  1283. }
  1284. /*long fCorpid = tWarehouseBills.getfCorpid();
  1285. TGoods tGoods = tGoodsMapper.selectTGoodsById(wbItem.getfGoodsid());
  1286. long fGoodsid = tGoods.getfTypeid();
  1287. long fBillingway = wbItem.getfBillingway();
  1288. long fQty = wbItem.getfQty();
  1289. // 计算仓储费明细
  1290. Map<String, Object> objectMap = tWarehouseAgreementService.getCarryingCost(fCorpid, fGoodsid, dateDay, fBillingway, fQty , 0L);
  1291. if (StringUtils.isNull(objectMap)) {
  1292. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1293. return AjaxResult.error("库存明细第" + i + "行没有维护出库明细的仓储协议,操作终止");
  1294. }
  1295. Long feeId = (Long) objectMap.get("feeId");
  1296. BigDecimal amt = (BigDecimal) objectMap.get("amt");
  1297. TFees tFees = tFeesMapper.selectTFeesById(feeId);
  1298. if (StringUtils.isNotNull(tFees)) {
  1299. feesList.add(tFees);
  1300. }
  1301. TWarehousebillsfees fees = new TWarehousebillsfees();
  1302. fees.setfPid(fPid);
  1303. fees.setfFeeid(feeId);
  1304. fees.setfCorpid(tWarehouseBills.getfCorpid());
  1305. fees.setfFeeUnitid(fBillingway);
  1306. fees.setfQty(new BigDecimal(1));
  1307. fees.setfUnitprice(amt);
  1308. fees.setfAmount(amt);
  1309. fees.setfExrate(new BigDecimal(1));
  1310. fees.setfCurrency("RMB");
  1311. fees.setRemark(dateDay + "天" + tFees.getfName());
  1312. warehousebillsfees.add(fees);*/
  1313. }
  1314. wbItem.setfBillstatus(40L);
  1315. } else if ("CKDB".equals(billsType) || "HWTG".equals(billsType)) { // 调拨查询
  1316. if (StringUtils.isNull(tWhgenle)) { // 为空 提示没有库存
  1317. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1318. return AjaxResult.error("库存明细第" + i + "行库存为空");
  1319. } else { // 非空修改库存总账
  1320. if (tWhgenle.getfQtyblc() < wbItem.getfQty()) { // 1、 库存 < 调拨件数 提示库存不足
  1321. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1322. return AjaxResult.error("库存明细第" + i + "行库存不足");
  1323. } else { // 2、 库存足够 先 进行出库操作
  1324. wbItem.setfWarehouselocid(warehouselocId);
  1325. updateTWhgenlegData(wbItem, tWhgenle.getfId(), "SJCK");
  1326. }
  1327. if("HWTG".equals(billsType)){
  1328. tWarehouseBills.setfTrademodeid(tWarehouseBills.getfNewTrademodeid());
  1329. }
  1330. // 3、 进行入库操作 查询是否存在库存
  1331. wbItem.setfWarehouselocid(transferWarehouselocid); // 新库区
  1332. TWhgenleg tWhgenle1 = queryTWhgenleg(tWarehouseBills, wbItem);
  1333. if (StringUtils.isNull(tWhgenle1)) { // 5、 不存在 进行新增库存
  1334. instalTWhgenleg(tWarehouseBills, wbItem, loginUser.getUser());
  1335. } else { // 4、 存在 进行跟新库存
  1336. updateTWhgenlegData(wbItem, tWhgenle1.getfId(), "SJRK");
  1337. }
  1338. }
  1339. wbItem.setfWarehouselocid(warehouselocId);
  1340. wbItem.setfBillstatus(40L);
  1341. } else if ("HQZY".equals(billsType)) { // 货转
  1342. wbItem.setfBillstatus(6L);
  1343. wbItem.setfChargedate(tWarehouseBills.getfChargedate());
  1344. wbItem.setfBillingway(tWarehouseBills.getfBillingway());
  1345. if (StringUtils.isNull(tWhgenle)) { // 为空 提示没有库存
  1346. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1347. return AjaxResult.error("库存明细第" + i + "行库存为空");
  1348. } else { // 非空修改库存总账
  1349. if (tWhgenle.getfQtyblc() < wbItem.getfQty()) { // 1、 库存 < 调拨件数 提示库存不足
  1350. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1351. return AjaxResult.error("库存明细第" + i + "行库存不足");
  1352. } else { // 2、 库存足够 先 进行出库操作
  1353. updateTWhgenlegData(wbItem, tWhgenle.getfId(), "SJCK");
  1354. }
  1355. long corpId = tWarehouseBills.getfCorpid();
  1356. tWarehouseBills.setfCorpid(tWarehouseBills.getfTocorpid());
  1357. // 3、 进行入库操作 查询是否存在库存
  1358. TWhgenleg tWhgenle1 = queryTWhgenleg(tWarehouseBills, wbItem);
  1359. if (StringUtils.isNull(tWhgenle1)) { // 5、 不存在 进行新增库存
  1360. instalTWhgenleg(tWarehouseBills, wbItem, loginUser.getUser());
  1361. } else { // 4、 存在 进行跟新库存
  1362. updateTWhgenlegData(wbItem, tWhgenle1.getfId(), "SJRK");
  1363. }
  1364. tWarehouseBills.setfCorpid(corpId);
  1365. }
  1366. }
  1367. i++;
  1368. int num = 0;
  1369. wbItem.setfPid(fPid);
  1370. wbItem.setfBilltype(billsType);
  1371. wbItem.setfBillno(tWarehouseBills.getfBillno());
  1372. wbItem.setfBsdate(tWarehouseBills.getfBsdate());
  1373. if (StringUtils.isNotNull(wbItem.getfId())) {
  1374. wbItem.setUpdateBy(loginUser.getUser().getUserName());
  1375. wbItem.setUpdateTime(new Date());
  1376. num = tWarehousebillsitemsMapper.updateTWarehousebillsitems(wbItem);
  1377. if ("SJCK".equals(billsType)) {
  1378. // 添加状态log
  1379. insertTWarehousebillsLog(wbItem, 40L, loginUser);
  1380. }
  1381. } else {
  1382. wbItem.setCreateTime(new Date());
  1383. wbItem.setCreateBy(loginUser.getUsername());
  1384. num = tWarehousebillsitemsMapper.insertTWarehousebillsitems(wbItem);
  1385. }
  1386. if (num <= 0) {
  1387. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1388. return AjaxResult.error("库存明细更新失败");
  1389. }
  1390. }
  1391. // 附件添加
  1392. if (StringUtils.isNotEmpty(tEnclosure) && !"[]".equals(tEnclosure)) {
  1393. JSONArray jsonDrArray = JSONArray.parseArray(tEnclosure);
  1394. List<TEnclosure> tEnclosureList = JSONObject.parseArray(jsonDrArray.toJSONString(), TEnclosure.class);
  1395. for (TEnclosure enclosure : tEnclosureList) {
  1396. enclosure.setfPid(tWarehouseBills.getfId());
  1397. enclosure.setCreateBy(loginUser.getUser().getUserName());
  1398. enclosure.setCreateTime(new Date());
  1399. tEnclosureMapper.insertTEnclosure(enclosure);
  1400. }
  1401. }
  1402. // 收款明细添加
  1403. if (StringUtils.isNotEmpty(warehousebillsfeesDr) && !"[]".equals(warehousebillsfeesDr)) {
  1404. JSONArray jsonDrArray = JSONArray.parseArray(warehousebillsfeesDr);
  1405. List<TWarehousebillsfees> warehousebillsfeesDrList = JSONObject.parseArray(jsonDrArray.toJSONString(), TWarehousebillsfees.class);
  1406. for (TWarehousebillsfees wbDr : warehousebillsfeesDrList) {
  1407. wbDr.setfPid(tWarehouseBills.getfId());
  1408. wbDr.setfDc("D");
  1409. wbDr.setCreateBy(loginUser.getUser().getUserName());
  1410. wbDr.setCreateTime(new Date());
  1411. tWarehousebillsfeesMapper.insertTWarehousebillsfees(wbDr);
  1412. }
  1413. }
  1414. // 付款明细添加
  1415. if (StringUtils.isNotNull(warehousebillsfeesCr) && !"[]".equals(warehousebillsfeesCr)) {
  1416. JSONArray jsonCrArray = JSONArray.parseArray(warehousebillsfeesCr);
  1417. List<TWarehousebillsfees> warehousebillsfeesCrList = JSONObject.parseArray(jsonCrArray.toJSONString(), TWarehousebillsfees.class);
  1418. for (TWarehousebillsfees wbCr : warehousebillsfeesCrList) {
  1419. wbCr.setfPid(tWarehouseBills.getfId());
  1420. wbCr.setfDc("C");
  1421. wbCr.setCreateBy(loginUser.getUser().getUserName());
  1422. wbCr.setCreateTime(new Date());
  1423. tWarehousebillsfeesMapper.insertTWarehousebillsfees(wbCr);
  1424. }
  1425. }
  1426. map.put("fPid", fPid);
  1427. map.put("warehouse", tWarehouseBills);
  1428. map.put("warehouseItem", warehousebillsitemsList);
  1429. map.put("fees", feesList);
  1430. map.put("warehousebillsfees", warehousebillsfees);
  1431. // 添加成功 主键返回 前台
  1432. return AjaxResult.success("成功", map);
  1433. }
  1434. /**
  1435. * 打印作业单
  1436. *
  1437. * @param warehouseBills
  1438. * @param warehousebillsitems
  1439. * @param tEnclosure
  1440. * @param tWarehousebillsfeesCr
  1441. * @param tWarehousebillsfeesDr
  1442. * @param loginUser
  1443. * @param status
  1444. * @param billtystatus
  1445. * @return
  1446. */
  1447. @Override
  1448. @Transactional
  1449. public AjaxResult waitWarehousing(String warehouseBills, String warehousebillsitems,
  1450. String tEnclosure, String tWarehousebillsfeesCr, String tWarehousebillsfeesDr,
  1451. LoginUser loginUser, Long status, String billtystatus) {
  1452. Map<String, Object> map = new HashMap<>();
  1453. List<TWarehousebillsitems> mapList= new ArrayList<>();
  1454. if (StringUtils.isNull(warehouseBills) || "[]".equals(warehouseBills)) {
  1455. return AjaxResult.error("未找到主表信息");
  1456. }
  1457. if (StringUtils.isNull(warehousebillsitems) || "[]".equals(warehousebillsitems)) {
  1458. return AjaxResult.error("未找到入账信息");
  1459. }
  1460. TWarehouseBills tWarehouseBills = JSONArray.parseObject(warehouseBills, TWarehouseBills.class);
  1461. if(status==20){
  1462. tWarehouseBills.setfItemsStatus(2L);
  1463. }else if(status==30){
  1464. tWarehouseBills.setfItemsStatus(3L);
  1465. }
  1466. if (StringUtils.isNotNull(tWarehouseBills.getfId())) {
  1467. tWarehouseBills.setUpdateBy(loginUser.getUser().getUserName());
  1468. tWarehouseBills.setUpdateTime(new Date());
  1469. tWarehouseBillsMapper.updateTWarehousebills(tWarehouseBills);
  1470. }
  1471. tEnclosureMapper.deleteByFPid(tWarehouseBills.getfId());
  1472. tWarehousebillsfeesMapper.deleteByFPid(tWarehouseBills.getfId());
  1473. JSONArray warehouseJSON = JSONArray.parseArray(warehousebillsitems);
  1474. List<TWarehousebillsitems> warehousebillsitemsList = JSONObject.parseArray(warehouseJSON.toJSONString(), TWarehousebillsitems.class);
  1475. /**
  1476. * 1、 查询回收表是否有可用数据
  1477. * 2、 流水号生成 --> 打印一次 只记录一个号
  1478. */
  1479. Date time = new Date();
  1480. String serialNumber = null;
  1481. if(status==20){
  1482. if ("RK".equals(billtystatus)) {
  1483. serialNumber = billnoSerialServiceImpl.getSerialNumber("RK", time);
  1484. } else if ("CK".equals(billtystatus)) { //生成 出库 流水号
  1485. serialNumber = billnoSerialServiceImpl.getSerialNumber("CK", time);
  1486. } else if ("DB".equals(billtystatus)) { //生成 出库 流水号
  1487. serialNumber = billnoSerialServiceImpl.getSerialNumber("DB", time);
  1488. } else if ("TG".equals(billtystatus)) { //生成 出库 流水号
  1489. serialNumber = billnoSerialServiceImpl.getSerialNumber("TG", time);
  1490. }
  1491. }
  1492. int i=1;
  1493. for (TWarehousebillsitems item : warehousebillsitemsList) {
  1494. // 查询是否可以修改
  1495. TWarehousebillsitems tWarehousebillsitems = tWarehousebillsitemsMapper.selectTWarehousebillsitemsById(item.getfId());
  1496. if(tWarehousebillsitems.getfBillstatus()==30){
  1497. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1498. return AjaxResult.error("更新库存明细第"+i+"行失败,已处理,请刷新网页");
  1499. }
  1500. if (item.getfBillstatus() < 30L) {
  1501. if(item.getfSerialNumber()==null || item.getfSerialNumber().equals("")){
  1502. item.setfSerialNumber(serialNumber);
  1503. }
  1504. item.setfBillstatus(status);
  1505. item.setUpdateTime(new Date());
  1506. item.setUpdateBy(loginUser.getUser().getUserName());
  1507. int num = tWarehousebillsitemsMapper.updateTWarehousebillsitems(item);
  1508. // 添加状态log
  1509. insertTWarehousebillsLog(item, status, loginUser);
  1510. if (num <= 0) {
  1511. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1512. return AjaxResult.error("更新库存明细失败");
  1513. }
  1514. }
  1515. mapList.add(item);
  1516. i++;
  1517. }
  1518. // 附件添加
  1519. if (StringUtils.isNotEmpty(tEnclosure) && !"[]".equals(tEnclosure)) {
  1520. JSONArray jsonDrArray = JSONArray.parseArray(tEnclosure);
  1521. List<TEnclosure> tEnclosureList = JSONObject.parseArray(jsonDrArray.toJSONString(), TEnclosure.class);
  1522. for (TEnclosure enclosure : tEnclosureList) {
  1523. enclosure.setfPid(tWarehouseBills.getfId());
  1524. enclosure.setCreateBy(loginUser.getUser().getUserName());
  1525. enclosure.setCreateTime(new Date());
  1526. tEnclosureMapper.insertTEnclosure(enclosure);
  1527. }
  1528. }
  1529. // 收款明细添加
  1530. if (StringUtils.isNotEmpty(tWarehousebillsfeesDr) && !"[]".equals(tWarehousebillsfeesDr)) {
  1531. JSONArray jsonDrArray = JSONArray.parseArray(tWarehousebillsfeesDr);
  1532. List<TWarehousebillsfees> warehousebillsfeesDrList = JSONObject.parseArray(jsonDrArray.toJSONString(), TWarehousebillsfees.class);
  1533. for (TWarehousebillsfees wbDr : warehousebillsfeesDrList) {
  1534. wbDr.setfPid(tWarehouseBills.getfId());
  1535. wbDr.setfDc("D");
  1536. wbDr.setCreateBy(loginUser.getUser().getUserName());
  1537. wbDr.setCreateTime(new Date());
  1538. if (tWarehouseBills.getfBsdate() != null && !tWarehouseBills.getfBsdate().equals("")) {
  1539. wbDr.setfBsdate(tWarehouseBills.getfBsdate());
  1540. }
  1541. tWarehousebillsfeesMapper.insertTWarehousebillsfees(wbDr);
  1542. }
  1543. }
  1544. // 付款明细添加
  1545. if (StringUtils.isNotNull(tWarehousebillsfeesCr) && !"[]".equals(tWarehousebillsfeesCr)) {
  1546. JSONArray jsonCrArray = JSONArray.parseArray(tWarehousebillsfeesCr);
  1547. List<TWarehousebillsfees> warehousebillsfeesCrList = JSONObject.parseArray(jsonCrArray.toJSONString(), TWarehousebillsfees.class);
  1548. for (TWarehousebillsfees wbCr : warehousebillsfeesCrList) {
  1549. wbCr.setfPid(tWarehouseBills.getfId());
  1550. wbCr.setfDc("C");
  1551. wbCr.setCreateBy(loginUser.getUser().getUserName());
  1552. wbCr.setCreateTime(new Date());
  1553. if (tWarehouseBills.getfBsdate() != null && !tWarehouseBills.getfBsdate().equals("")) {
  1554. wbCr.setfBsdate(tWarehouseBills.getfBsdate());
  1555. }
  1556. tWarehousebillsfeesMapper.insertTWarehousebillsfees(wbCr);
  1557. }
  1558. }
  1559. // 添加成功 返回 前台
  1560. TWarehousebillsitems tWarehousebillsitems = new TWarehousebillsitems();
  1561. tWarehousebillsitems.setfPid(tWarehouseBills.getfId());
  1562. List<TWarehousebillsitems> mapList1 = tWarehousebillsitemsMapper.selectTWarehousebillsitemsList(tWarehousebillsitems);
  1563. map.put("warehousebillsitems", mapList);
  1564. map.put("warehousebillsitems1", mapList1);
  1565. return AjaxResult.success("成功", map);
  1566. }
  1567. /**
  1568. * 生成计算仓储费信息
  1569. *
  1570. * @param warehouseBills
  1571. * @param mapItem
  1572. * @param loginUser
  1573. * @return
  1574. */
  1575. public Map<String, Object> getWarehouseItems(TWarehouseBills warehouseBills, List<Map<String, Object>> mapItem, LoginUser loginUser) {
  1576. Map<String, Object> map = new HashMap<>();
  1577. long feeId = 0L;
  1578. BigDecimal sumAmt = new BigDecimal(0);
  1579. List<TWarehousebillsfees> itemsList = new ArrayList<>();
  1580. List<SysDictData> taxRate = sysDictDataMapper.selectDictDataByType("tax_rate");
  1581. for (Map<String, Object> item : mapItem) {
  1582. if (StringUtils.isNull(item.get("fBillingway"))) {
  1583. map.put("error", "单号:" + item.get("fBillno") + ",业务日期:" + item.get("fBsdate") + "未找到库存总账的计费单位,请确认");
  1584. return map;
  1585. }
  1586. Date fBsdate = (Date) item.get("fBsdate");
  1587. long fCorpid = warehouseBills.getfCorpid();
  1588. String fBilltype = (String) item.get("fBilltype");
  1589. long fGoodsid = Long.parseLong((String) item.get("fTypeid"));
  1590. long fId = Long.valueOf(String.valueOf(item.get("fId"))).longValue();
  1591. // 累计计费天数
  1592. long accumulatedDays = DateUtils.getDateDay((Date) item.get("fChargedate"), (Date) item.get("fOriginalbilldate"));
  1593. // 库存天数
  1594. long fInventoryDays = 0L;
  1595. // 要计费天数
  1596. long fBillingDays = DateUtils.getDateDay(warehouseBills.getfBillingDeadline(), (Date) item.get("fOriginalbilldate"));
  1597. if ("SJCK".equals(fBilltype)) {
  1598. fInventoryDays = DateUtils.getDateDay(fBsdate, (Date) item.get("fOriginalbilldate"));
  1599. fBillingDays = fInventoryDays;
  1600. } else if ("HQZY".equals(fBilltype)) {
  1601. fInventoryDays = DateUtils.getDateDay(warehouseBills.getfBillingDeadline(), fBsdate);
  1602. } else {
  1603. fBillingDays = DateUtils.getDateDay(warehouseBills.getfBillingDeadline(), (Date) item.get("fChargedate"));
  1604. fInventoryDays = DateUtils.getDateDay(warehouseBills.getfBillingDeadline(), (Date) item.get("fOriginalbilldate"));
  1605. }
  1606. /*if ("KCZZ".equals(fBilltype)) {
  1607. } else {
  1608. fInventoryDays = Long.valueOf(String.valueOf(item.get("fBillingDays")));
  1609. }*/
  1610. Long dictLabel = Long.valueOf(String.valueOf(item.get("fBillingway")));
  1611. BigDecimal fQty = acquiredQuantity(item, dictLabel);
  1612. if (fQty.equals(BigDecimal.ZERO)) {
  1613. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1614. return AjaxResult.error("单号:" + item.get("fBillno") + ",业务日期:" + item.get("fBsdate") + "未找到计费单位,请确认");
  1615. }
  1616. // 计算仓储费明细
  1617. Map<String, Object> objectMap = tWarehouseAgreementService.getCarryingCost(fCorpid, fGoodsid, fBillingDays, dictLabel, fQty, accumulatedDays);
  1618. if (StringUtils.isNull(objectMap)) {
  1619. map.put("error", "单号:" + item.get("fBillno") + ",业务日期:" + item.get("fBsdate") + "未找到仓储费协议,请确认");
  1620. return map;
  1621. }
  1622. String mblno = "";
  1623. if (StringUtils.isNotNull(item.get("fMblno"))) {
  1624. mblno = item.get("fMblno").toString();
  1625. }
  1626. String remark = objectMap.get("remark").toString();
  1627. feeId = Long.valueOf(String.valueOf(objectMap.get("feeId"))).longValue();
  1628. BigDecimal amt = (BigDecimal) objectMap.get("amt");
  1629. map.put("feeId", feeId);
  1630. map.put("itemFeeId", objectMap.get("feeId"));
  1631. sumAmt = sumAmt.add(amt).setScale(2, BigDecimal.ROUND_HALF_UP);
  1632. TWarehousebillsfees fees = new TWarehousebillsfees();
  1633. fees.setfFeeid(feeId);
  1634. fees.setfDc("D");
  1635. fees.setfAmt(amt);
  1636. fees.setSrcId(fId);
  1637. fees.setfMblno(mblno);
  1638. fees.setRemark(remark);
  1639. fees.setfFeeunitid(2L);
  1640. fees.setfAmount(sumAmt);
  1641. fees.setfBillstatus(2L);
  1642. fees.setfCurrency("RMB");
  1643. fees.setfBsdate(fBsdate);
  1644. fees.setfBillingQty(fQty);
  1645. fees.setfUnitprice(sumAmt);
  1646. fees.setfBilltype(fBilltype);
  1647. fees.setfBillingDays(fBillingDays);
  1648. fees.setCreateTime(new Date());
  1649. fees.setfQty(new BigDecimal(1));
  1650. fees.setfPid(warehouseBills.getfId());
  1651. fees.setfInventoryDays(fInventoryDays);
  1652. fees.setfExrate(new BigDecimal(1));
  1653. fees.setfCorpid(warehouseBills.getfCorpid());
  1654. fees.setfMarks(item.get("fMarks").toString());
  1655. fees.setSrcBillNo((String) item.get("fBillno"));
  1656. fees.setfChargedate((Date) item.get("fChargedate"));
  1657. fees.setCreateBy(loginUser.getUser().getUserName());
  1658. fees.setfProductName(item.get("fGoodsids").toString());
  1659. if ("SJCK".equals(fBilltype)) {
  1660. fees.setfBillingDeadline(fBsdate);
  1661. } else {
  1662. fees.setfBillingDeadline(warehouseBills.getfBillingDeadline());
  1663. }
  1664. fees.setfTaxrate(new BigDecimal(taxRate.get(0).getDictValue()));
  1665. fees.setfOriginalbilldate((Date) item.get("fOriginalbilldate"));
  1666. fees.setfBillingway(Long.valueOf(String.valueOf(item.get("fBillingway"))).longValue());
  1667. tWarehousebillsfeesMapper.insertTWarehousebillsfees(fees);
  1668. itemsList.add(fees);
  1669. }
  1670. map.put("sumAmt", sumAmt);
  1671. map.put("itemsList", itemsList);
  1672. return map;
  1673. }
  1674. /**
  1675. * 新增库存费计算
  1676. *
  1677. * @param tWarehouseBills 主表的查询条件
  1678. * @param loginUser 登录用户
  1679. * @param billsType 状态
  1680. * @return 结果
  1681. */
  1682. @Override
  1683. @Transactional
  1684. public AjaxResult calculateStorageFees(TWarehouseBills tWarehouseBills, LoginUser loginUser, String billsType) {
  1685. if (StringUtils.isNull(tWarehouseBills.getfCorpid())) {
  1686. return AjaxResult.error("请选择客户信息");
  1687. }
  1688. long fPid = 0L;
  1689. if (StringUtils.isNull(tWarehouseBills.getfId())) {
  1690. // 生成流水号
  1691. Date time = new Date();
  1692. String billNo = billnoSerialServiceImpl.getSerialNumber("JSCCF", time);
  1693. tWarehouseBills.setfBillno(billNo);
  1694. if (StringUtils.isNull(tWarehouseBills.getfBillstatus())) {
  1695. tWarehouseBills.setfBillstatus(2L);
  1696. }
  1697. tWarehouseBills.setfBilltype(billsType);
  1698. tWarehouseBills.setfBsdeptid(loginUser.getUser().getDeptId());
  1699. tWarehouseBills.setCreateBy(loginUser.getUser().getUserName());
  1700. tWarehouseBills.setCreateTime(new Date());
  1701. tWarehouseBillsMapper.insertTWarehousebills(tWarehouseBills);
  1702. fPid = tWarehouseBills.getfId();
  1703. } else {
  1704. tWarehousebillsfeesMapper.deleteByFPid(tWarehouseBills.getfId());
  1705. tWarehousebillsitemsMapper.deleteByFPid(tWarehouseBills.getfId());
  1706. tWarehouseBills.setUpdateBy(loginUser.getUser().getUserName());
  1707. tWarehouseBills.setUpdateTime(new Date());
  1708. tWarehouseBillsMapper.updateTWarehousebills(tWarehouseBills);
  1709. fPid = tWarehouseBills.getfId();
  1710. }
  1711. // 计划物资明细
  1712. List<TWarehousebillsfees> itemsList = new ArrayList<>();
  1713. BigDecimal bigDecimal = new BigDecimal(0);
  1714. Map<String, Object> map = new HashMap<>();
  1715. // 库存总账id
  1716. long whgenlegFeeId = 0;
  1717. // 计费单位
  1718. long feeUnitid = 1;
  1719. // 查询 出库 货转的库存明细
  1720. List<Map<String, Object>> warehousebillsitemsList = tWarehousebillsitemsMapper.selectStorageFeeItemList(tWarehouseBills);
  1721. if (warehousebillsitemsList.size() != 0) {
  1722. Map<String, Object> mapItem = getWarehouseItems(tWarehouseBills, warehousebillsitemsList, loginUser);
  1723. if (mapItem.containsKey("error")) {
  1724. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1725. return AjaxResult.error((String) mapItem.get("error"));
  1726. }
  1727. itemsList = (List<TWarehousebillsfees>) mapItem.get("itemsList");
  1728. }
  1729. List<Map<String, Object>> tWhgenlegs = tWhgenlegMapper.selectStorageFeeItemList(tWarehouseBills);
  1730. if (tWhgenlegs.size() != 0) {
  1731. Map<String, Object> mapItem = getWarehouseItems(tWarehouseBills, tWhgenlegs, loginUser);
  1732. if (mapItem.containsKey("error")) {
  1733. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1734. return AjaxResult.error((String) mapItem.get("error"));
  1735. }
  1736. List<TWarehousebillsfees> itemList = (List<TWarehousebillsfees>) mapItem.get("itemsList");
  1737. if (itemList.size() != 0) {
  1738. for (TWarehousebillsfees ite : itemList) {
  1739. itemsList.add(ite);
  1740. }
  1741. }
  1742. }
  1743. TFees tFees = new TFees();
  1744. tFees.setfStatus("2");
  1745. tFees.setDelFlag("0");
  1746. List<TFees> feesList = tFeesMapper.selectTFeesList(tFees);
  1747. if (itemsList.size() <= 0) {
  1748. return AjaxResult.error("未找到合适的库存明细");
  1749. }
  1750. map.put("feesList", feesList);
  1751. map.put("warehouseBills", tWarehouseBills);
  1752. map.put("warehouseItemList", itemsList);
  1753. return AjaxResult.success(map);
  1754. }
  1755. /**
  1756. * 仓储费计算提交以及暂存
  1757. *
  1758. * @param warehouseBills
  1759. * @param warehouseItems
  1760. * @param warehouseFees
  1761. * @param loginUser
  1762. * @param billsType
  1763. * @return
  1764. */
  1765. @Override
  1766. @Transactional
  1767. public AjaxResult insertStorageFee(String warehouseBills, String warehouseItems, String warehouseFees, LoginUser loginUser, String billsType) {
  1768. TWarehouseBills tWarehousebills = JSONArray.parseObject(warehouseBills, TWarehouseBills.class);
  1769. long fPid = 0L;
  1770. boolean billstatus = tWarehousebills.getfBillstatus().equals(4L);
  1771. if (billstatus && (StringUtils.isNull(warehouseItems) || "[]".equals(warehouseItems))) {
  1772. return AjaxResult.error("未找到计费物资明细无法提交");
  1773. }
  1774. /*if (billstatus && (StringUtils.isNull(warehouseFees) || "[]".equals(warehouseFees))) {
  1775. return AjaxResult.error("未找到应收款明细无法提交");
  1776. }*/
  1777. if (StringUtils.isNotNull(tWarehousebills.getfId())) {
  1778. fPid = tWarehousebills.getfId();
  1779. tWarehousebills.setUpdateTime(new Date());
  1780. tWarehousebills.setUpdateBy(loginUser.getUser().getUserName());
  1781. tWarehouseBillsMapper.updateTWarehousebills(tWarehousebills);
  1782. tWarehousebillsfeesMapper.deleteByFPid(fPid);
  1783. tWarehousebillsitemsMapper.deleteByFPid(fPid);
  1784. } else {
  1785. // 生成流水号
  1786. Date time = new Date();
  1787. String billNo = billnoSerialServiceImpl.getSerialNumber("JSCCF", time);
  1788. tWarehousebills.setfBillno(billNo);
  1789. tWarehousebills.setfDeptid(loginUser.getUser().getDeptId());
  1790. tWarehousebills.setfBsdeptid(loginUser.getUser().getDeptId());
  1791. tWarehousebills.setCreateBy(loginUser.getUser().getUserName());
  1792. tWarehousebills.setCreateTime(new Date());
  1793. tWarehousebills.setfBilltype(billsType);
  1794. tWarehouseBillsMapper.insertTWarehousebills(tWarehousebills);
  1795. fPid = tWarehousebills.getfId();
  1796. }
  1797. JSONArray warehouseJSON = JSONArray.parseArray(warehouseItems);
  1798. List<TWarehousebillsfees> itemsList = JSONObject.parseArray(warehouseJSON.toJSONString(), TWarehousebillsfees.class);
  1799. for (TWarehousebillsfees item : itemsList) {
  1800. item.setfId(null);
  1801. item.setSrcBillNo(tWarehousebills.getfBillno());
  1802. item.setfPid(fPid);
  1803. item.setfBillstatus(tWarehousebills.getfBillstatus());
  1804. tWarehousebillsfeesMapper.insertTWarehousebillsfees(item);
  1805. }
  1806. if (StringUtils.isNotNull(warehouseFees) && !"[]".equals(warehouseFees)) {
  1807. JSONArray feesJSON = JSONArray.parseArray(warehouseFees);
  1808. List<TWarehousebillsfees> warehousebillsfeesList = JSONObject.parseArray(feesJSON.toJSONString(), TWarehousebillsfees.class);
  1809. for (TWarehousebillsfees fees : warehousebillsfeesList) {
  1810. fees.setfId(null);
  1811. fees.setfPid(fPid);
  1812. fees.setfDc("D");
  1813. fees.setfBilltype("JSCCF");
  1814. fees.setSrcBillNo(tWarehousebills.getfBillno());
  1815. fees.setfBillstatus(tWarehousebills.getfBillstatus());
  1816. tWarehousebillsfeesMapper.insertTWarehousebillsfees(fees);
  1817. }
  1818. }
  1819. if (billstatus) {
  1820. String key = "warehouse.storageFeeCalculation.ApprovalFlow";
  1821. SysConfig sysConfig = sysConfigMapper.checkConfigKeyUnique(key);
  1822. if (StringUtils.isNull(sysConfig)) {
  1823. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1824. return AjaxResult.error("系统参数异常,未找到开启审批流参数");
  1825. }
  1826. if ("0".equals(sysConfig.getConfigValue())) {
  1827. AuditItems auditItems = new AuditItems();
  1828. auditItems.setLevelId(0L);
  1829. auditItems.setBillId(fPid);
  1830. auditItems.setActId(150L);
  1831. auditItems.setIffinalItem("F");
  1832. auditItems.setBillNo(tWarehousebills.getfBillno());
  1833. // 存储委托方(货权方)
  1834. auditItems.setRefno1(tWarehousebills.getfCorpid() + "");
  1835. // 存储业务类型(业务类型)
  1836. auditItems.setRefno2(tWarehousebills.getfBilltype());
  1837. // 存储提单号(提单号)
  1838. auditItems.setRefno3(tWarehousebills.getfMblno());
  1839. auditItems.setSendUserId(loginUser.getUser().getUserId());
  1840. auditItems.setSendName(loginUser.getUsername());
  1841. auditItems.setSendTime(new Date());
  1842. auditItems.setAuditUserId(loginUser.getUser().getUserId());
  1843. auditItems.setAuditItem(new Date());
  1844. auditItems.setAuditOpTime(new Date());
  1845. auditItems.setAuditMsg("提交");
  1846. auditItems.setAuditStatus("O");
  1847. AjaxResult approvalFlow = auditItemsService.createApprovalFlow(auditItems);
  1848. String code = approvalFlow.get("code").toString();
  1849. // Long code = Long.valueOf(String.valueOf(ajaxResult.get("code"))).longValue();
  1850. if ("500".equals(code)) {
  1851. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1852. }
  1853. return approvalFlow;
  1854. } else {
  1855. AjaxResult ajaxResult = storageFeeFollow(fPid, 6L);
  1856. String code = ajaxResult.get("code").toString();
  1857. // Long code = Long.valueOf(String.valueOf(ajaxResult.get("code"))).longValue();
  1858. if ("500".equals(code)) {
  1859. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  1860. }
  1861. return ajaxResult;
  1862. }
  1863. }
  1864. return AjaxResult.success(tWarehousebills);
  1865. }
  1866. /**
  1867. * 根据id查询仓储费计算信息
  1868. *
  1869. * @param fId
  1870. * @return
  1871. */
  1872. @Override
  1873. public AjaxResult selectStorageFeeById(Long fId) {
  1874. TWarehouseBills tWarehouseBills = tWarehouseBillsMapper.selectTWarehousebillsById(fId);
  1875. if (StringUtils.isNull(tWarehouseBills)) {
  1876. return AjaxResult.error("未找到信息,请刷新页面重试");
  1877. }
  1878. Map<String, Object> map = new HashMap<>();
  1879. List<TWarehousebillsfees> feesList = new ArrayList<>();
  1880. List<TWarehousebillsfees> itemsList = new ArrayList<>();
  1881. TWarehousebillsfees warehousebillsfees = new TWarehousebillsfees();
  1882. warehousebillsfees.setfPid(fId);
  1883. List<TWarehousebillsfees> warehouseFeesList = tWarehousebillsfeesMapper.selectTWarehousebillsfeesList(warehousebillsfees);
  1884. for (TWarehousebillsfees fees : warehouseFeesList) {
  1885. if (StringUtils.isNotNull(fees.getSrcId())) {
  1886. itemsList.add(fees);
  1887. } else {
  1888. feesList.add(fees);
  1889. }
  1890. }
  1891. TGoods tGoods = new TGoods();
  1892. tGoods.setfStatus("0");
  1893. tGoods.setDelFlag("0");
  1894. List<TGoods> goods = tGoodsMapper.selectTGoodsList(tGoods);
  1895. TFees tFees = new TFees();
  1896. tFees.setfStatus("2");
  1897. tFees.setDelFlag("0");
  1898. List<TFees> feesLists = tFeesMapper.selectTFeesList(tFees);
  1899. // 查询联系人
  1900. List<SysUser> sysUserList = new ArrayList<>();
  1901. SysUser sysUser = sysUserMapper.selectUserByUserName(tWarehouseBills.getCreateBy());
  1902. if (StringUtils.isNotNull(sysUser)) {
  1903. sysUserList.add(sysUser);
  1904. }
  1905. TCorps corps = tCorpsMapper.selectTCorpsById(tWarehouseBills.getfCorpid());
  1906. map.put("corps", corps);
  1907. map.put("goodsList", goods);
  1908. map.put("feesList", feesLists);
  1909. map.put("sysUser", sysUserList);
  1910. map.put("warehouse", tWarehouseBills);
  1911. map.put("warehouseFeesList", feesList);
  1912. map.put("warehouseItemsList", itemsList);
  1913. return AjaxResult.success(map);
  1914. }
  1915. /**
  1916. * 根据不同计费单位获取不同 计算库存明细数量
  1917. *
  1918. * @param item 库存明细
  1919. * @param dictLabel 计费单位
  1920. * @return 结果
  1921. */
  1922. public BigDecimal acquiredQuantity(Map<String, Object> item, Long dictLabel) {
  1923. BigDecimal fQty = new BigDecimal(0);
  1924. // 件数
  1925. long boxNum = 1;
  1926. // 毛重
  1927. long grossWeight = 2;
  1928. // 净重
  1929. long netWeight = 3;
  1930. // 尺码
  1931. long size = 4;
  1932. // 统一
  1933. long fixed = 5;
  1934. if (dictLabel.equals(boxNum)) {
  1935. fQty = new BigDecimal(((Number) item.get("fQty")).doubleValue());
  1936. return fQty.setScale(2, BigDecimal.ROUND_HALF_UP);
  1937. } else if (dictLabel.equals(grossWeight)) {
  1938. fQty = new BigDecimal(((Number) item.get("fGrossweight")).doubleValue());
  1939. } else if (dictLabel.equals(netWeight)) {
  1940. fQty = new BigDecimal(((Number) item.get("fNetweight")).doubleValue());
  1941. } else if (dictLabel.equals(size)) {
  1942. fQty = new BigDecimal(((Number) item.get("fVolumn")).doubleValue());
  1943. } else if (dictLabel.equals(fixed)) {
  1944. fQty = new BigDecimal(1);
  1945. }
  1946. //return fQty.setScale(2, BigDecimal.ROUND_HALF_UP);
  1947. // 结果值除以1000 保留两位
  1948. BigDecimal divisor = new BigDecimal("1000");
  1949. BigDecimal result = fQty.divide(divisor, 2, BigDecimal.ROUND_HALF_UP);
  1950. return result;
  1951. }
  1952. // 入库 收费明细 校验
  1953. public Long check(BigDecimal number, BigDecimal unitPrice) {
  1954. BigDecimal result1 = number.multiply(unitPrice);
  1955. // 保留两位小数且四舍五入
  1956. result1 = result1.setScale(2, BigDecimal.ROUND_HALF_UP);
  1957. // 转换去掉小数点
  1958. String result = result1.toString().replace(".", "");
  1959. return Long.valueOf(result);
  1960. }
  1961. /**
  1962. * 修改详情主表
  1963. *
  1964. * @param tWarehousebills 详情主表
  1965. * @return 结果
  1966. */
  1967. @Override
  1968. public int updateTWarehousebills(TWarehouseBills tWarehousebills) {
  1969. tWarehousebills.setUpdateTime(DateUtils.getNowDate());
  1970. return tWarehouseBillsMapper.updateTWarehousebills(tWarehousebills);
  1971. }
  1972. /**
  1973. * 批量删除详情主表
  1974. *
  1975. * @param fIds 需要删除的详情主表ID
  1976. * @return 结果
  1977. */
  1978. @Override
  1979. public int deleteTWarehousebillsByIds(Long[] fIds) {
  1980. // 取出业务编号、 放入 billno_del
  1981. for (Long id : fIds) {
  1982. // 1、查询主表信息
  1983. TWarehouseBills tWarehousebills = tWarehouseBillsMapper.selectTWarehousebillsById(id);
  1984. // 2、业务编号、客存编号 放入 billno_del
  1985. BillnoDel billnoDel = new BillnoDel();
  1986. billnoDel.setBillType(tWarehousebills.getfBilltype());
  1987. billnoDel.setBillNo(tWarehousebills.getfBillno());
  1988. billnoDelMapper.insertBillnoDel(billnoDel);
  1989. }
  1990. return tWarehouseBillsMapper.deleteTWarehousebillsByIds(fIds);
  1991. }
  1992. @Override
  1993. public AjaxResult queryRemove(Long fId) {
  1994. // 查询主表明细
  1995. TWarehouseBills tWarehousebills = tWarehouseBillsMapper.selectTWarehousebillsById(fId);
  1996. // 查询仓库明细从表数据
  1997. TWarehousebillsitems tWarehousebillsitems = new TWarehousebillsitems();
  1998. tWarehousebillsitems.setfPid(tWarehousebills.getfId());
  1999. List<Map<String, Object>> mapList = tWarehousebillsitemsMapper.selectGoodsTransferitemsList(tWarehousebillsitems);
  2000. // 查询仓库费用明细表数据
  2001. TWarehousebillsfees tWarehousebillsfees = new TWarehousebillsfees();
  2002. tWarehousebillsfees.setfPid(tWarehousebills.getfId());
  2003. List<TWarehousebillsfees> warehousebillsfees = tWarehousebillsfeesMapper.selectTWarehousebillsfeesList(tWarehousebillsfees);
  2004. // 查询附件表数据
  2005. TEnclosure enclosure = new TEnclosure();
  2006. enclosure.setfPid(tWarehousebills.getfId());
  2007. List<TEnclosure> enclosures = tEnclosureMapper.selectTEnclosureList(enclosure);
  2008. if (StringUtils.isNull(tWarehousebills)) {
  2009. return AjaxResult.success("0");
  2010. } else if (StringUtils.isNotNull(tWarehousebills)
  2011. && StringUtils.isEmpty(warehousebillsfees)
  2012. && StringUtils.isEmpty(enclosures)
  2013. && StringUtils.isEmpty(mapList)) {
  2014. return AjaxResult.success("1");
  2015. } else {
  2016. return AjaxResult.success("2");
  2017. }
  2018. }
  2019. /**
  2020. * 删除详情主表信息
  2021. *
  2022. * @param fId 详情主表ID
  2023. * @return 结果
  2024. */
  2025. @Override
  2026. public int deleteTWarehousebillsById(Long fId) {
  2027. return tWarehouseBillsMapper.deleteTWarehousebillsById(fId);
  2028. }
  2029. @Override
  2030. public String getWarehouseInStockBillsNo(TWarehouseBills tWarehouseBills) {
  2031. return null;
  2032. }
  2033. @Override
  2034. public String getWarehouseOutStockBillsNo(TWarehouseBills tWarehouseBills) {
  2035. return null;
  2036. }
  2037. /**
  2038. * 撤销入库
  2039. *
  2040. * @param fId
  2041. * @param loginUser
  2042. * @param billsType
  2043. * @return
  2044. */
  2045. @Override
  2046. @Transactional
  2047. public AjaxResult revokeTWarehousebillsById(Long fId, LoginUser loginUser, String billsType) {
  2048. // 查询 仓库主表信息、库存明细信息
  2049. TWarehouseBills tWarehousebills = tWarehouseBillsMapper.selectTWarehousebillsById(fId);
  2050. // 修改主表信息
  2051. tWarehousebills.setUpdateBy(loginUser.getUser().getUserName());
  2052. tWarehousebills.setUpdateTime(new Date());
  2053. tWarehousebills.setfBillstatus(2L); //撤销状态
  2054. tWarehousebills.setfReviewDate(null);// 审核通过时间清空
  2055. tWarehouseBillsMapper.updateTWarehousebills(tWarehousebills);
  2056. tWarehousebillsfeesMapper.warehouseFeesFollowUpdate(tWarehousebills.getfId(), 2L, new Date());
  2057. if ("JSCCF".equals(tWarehousebills.getfBilltype())) {
  2058. List<TWarehousebillsfees> feesList = tWarehousebillsfeesMapper.selectWarehousebillsfeesByPId(fId);
  2059. for (TWarehousebillsfees wareItem : feesList) {
  2060. if (StringUtils.isNull(wareItem.getSrcId())) {
  2061. continue;
  2062. }
  2063. if ("KCZZ".equals(wareItem.getfBilltype())) {
  2064. TWhgenleg whgenleg = new TWhgenleg();
  2065. whgenleg.setfId(wareItem.getSrcId());
  2066. whgenleg.setfChargedate(wareItem.getfChargedate());
  2067. int i = tWhgenlegMapper.updateTWhgenleg(whgenleg);
  2068. if (i <= 0) {
  2069. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  2070. return AjaxResult.error("更新库存费用状态失败,请联系管理员");
  2071. }
  2072. } else {
  2073. TWarehousebillsitems billsItem = new TWarehousebillsitems();
  2074. billsItem.setfId(wareItem.getSrcId());
  2075. billsItem.setfBilltype(wareItem.getfBilltype());
  2076. if (!"SJCK".equals(wareItem.getfBilltype())) {
  2077. billsItem.setfChargedate(wareItem.getfBillingDeadline());
  2078. tWarehousebillsitemsMapper.updateTWarehousebillsitems(billsItem);
  2079. } else {
  2080. billsItem.setfChargedate(wareItem.getfChargedate());
  2081. }
  2082. tWarehousebillsitemsMapper.agreementApprovalRejected(billsItem);
  2083. }
  2084. }
  2085. }
  2086. return AjaxResult.success();
  2087. }
  2088. /**
  2089. * 撤销入账
  2090. *
  2091. * @param warehouseBills 主表
  2092. * @param warehousebillsitems 明细
  2093. * @param loginUser 当前登录人
  2094. * @param billsType 状态
  2095. * @return 结果
  2096. */
  2097. @Override
  2098. @Transactional
  2099. public AjaxResult revokeTWarehousebillsById1(String warehouseBills, String warehousebillsitems, String tEnclosure,
  2100. String warehousebillsfeesCr, String warehousebillsfeesDr, LoginUser loginUser, String billsType) {
  2101. if (StringUtils.isNull(warehouseBills) || "[]".equals(warehouseBills)) {
  2102. return AjaxResult.error("未找到主表信息");
  2103. }
  2104. if (StringUtils.isNull(warehousebillsitems) || "[]".equals(warehousebillsitems)) {
  2105. return AjaxResult.error("未找到入账信息");
  2106. }
  2107. TWarehouseBills tWarehousebills = JSONArray.parseObject(warehouseBills, TWarehouseBills.class);
  2108. tWarehousebills.setfItemsStatus(1L); //撤销状态
  2109. tWarehouseBillsMapper.updateTWarehousebills(tWarehousebills);
  2110. tEnclosureMapper.deleteByFPid(tWarehousebills.getfId());
  2111. tWarehousebillsfeesMapper.deleteByFPid(tWarehousebills.getfId());
  2112. JSONArray warehouseJSON = JSONArray.parseArray(warehousebillsitems);
  2113. List<TWarehousebillsitems> warehousebillsitemsList = JSONObject.parseArray(warehouseJSON.toJSONString(), TWarehousebillsitems.class);
  2114. /**
  2115. * 流水号回收
  2116. * 1、 获取所有流水号
  2117. */
  2118. List<String> SerialNumberList= new ArrayList<>();
  2119. if (StringUtils.isNotEmpty(warehousebillsitemsList)) {
  2120. int i = 1;
  2121. for (TWarehousebillsitems wb : warehousebillsitemsList) {
  2122. SerialNumberList.add(wb.getfSerialNumber()); // 流水号回收
  2123. // 查询库存总账
  2124. TWhgenleg tWhgenle = queryTWhgenleg(tWarehousebills, wb);
  2125. if ("SJRKRevoke".equals(billsType)) { // 撤销 入库
  2126. if (wb.getfIsInventory().equals(0L)) {
  2127. if (StringUtils.isNotNull(tWhgenle) && (wb.getfQty() <= tWhgenle.getfQtyblc())) { // 非空 且 撤销数 <= 结余数
  2128. updateTWhgenlegData(wb, tWhgenle.getfId(), billsType);
  2129. } else { // 撤销数>结余数
  2130. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  2131. return AjaxResult.error("第" + i + "行撤销数大于库存结余数");
  2132. }
  2133. }
  2134. wb.setfBillstatus(10L);
  2135. } else if ("SJCKRevoke".equals(billsType)) { // 撤销出库
  2136. if (StringUtils.isNotNull(tWhgenle)) { // 非空
  2137. updateTWhgenlegData(wb, tWhgenle.getfId(), billsType);
  2138. } else {
  2139. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  2140. return AjaxResult.error("第" + i + "行未查询到库存信息");
  2141. }
  2142. wb.setfBillstatus(10L);
  2143. } else if ("CKDBRevoke".equals(billsType)) { // 调拨 撤销
  2144. Long warehouselocid = wb.getfWarehouselocid();// 原货仓库
  2145. Long transferWarehouselocid = wb.getfTransferWarehouselocid(); // 新仓库
  2146. // 1、新货权方撤销入库
  2147. // 查询库存总账
  2148. wb.setfWarehouselocid(transferWarehouselocid);
  2149. TWhgenleg tWhgenle1 = queryTWhgenleg(tWarehousebills, wb);
  2150. if (StringUtils.isNotNull(tWhgenle1) && (wb.getfQty() <= tWhgenle1.getfQtyblc())) {
  2151. updateTWhgenlegData(wb, tWhgenle1.getfId(), "SJRKRevoke");
  2152. } else {
  2153. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  2154. return AjaxResult.error("第" + i + "行撤销数大于库存结余数");
  2155. }
  2156. // 2、原货权方撤销出库
  2157. // 查询库存总账
  2158. wb.setfWarehouselocid(warehouselocid);
  2159. TWhgenleg tWhgenle2 = queryTWhgenleg(tWarehousebills, wb);
  2160. updateTWhgenlegData(wb, tWhgenle2.getfId(), "SJCKRevoke");
  2161. wb.setfBillstatus(10L);
  2162. } else if ("HWTGRevoke".equals(billsType)) { // 调拨 撤销
  2163. // 贸易方式
  2164. Long oldfTrademodeid = tWarehousebills.getfTrademodeid();
  2165. // 新贸易方式
  2166. Long newfTrademodeid = tWarehousebills.getfNewTrademodeid();
  2167. Long warehouselocid = wb.getfWarehouselocid();// 原货仓库
  2168. Long transferWarehouselocid = wb.getfTransferWarehouselocid(); // 新仓库
  2169. // 1、新货权方撤销入库
  2170. // 查询库存总账
  2171. wb.setfWarehouselocid(transferWarehouselocid);
  2172. tWarehousebills.setfTrademodeid(newfTrademodeid); // 查询用新的
  2173. TWhgenleg tWhgenle1 = queryTWhgenleg(tWarehousebills, wb);
  2174. if (StringUtils.isNotNull(tWhgenle1) && (wb.getfQty() <= tWhgenle1.getfQtyblc())) {
  2175. updateTWhgenlegData(wb, tWhgenle1.getfId(), "SJRKRevoke");
  2176. } else {
  2177. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  2178. return AjaxResult.error("第" + i + "行撤销数大于库存结余数");
  2179. }
  2180. // 2、原货权方撤销出库
  2181. // 查询库存总账
  2182. wb.setfWarehouselocid(warehouselocid);
  2183. tWarehousebills.setfTrademodeid(oldfTrademodeid); // 撤销回到旧的
  2184. TWhgenleg tWhgenle2 = queryTWhgenleg(tWarehousebills, wb);
  2185. updateTWhgenlegData(wb, tWhgenle2.getfId(), "SJCKRevoke");
  2186. wb.setfBillstatus(10L);
  2187. } else if ("HQZYRevoke".equals(billsType)) { // 货转撤销
  2188. Long fCorpid = tWarehousebills.getfCorpid();// 原货权方
  2189. Long fTocorpid = tWarehousebills.getfTocorpid(); // 新货权方
  2190. // 1、新货权方撤销入库
  2191. // 查询库存总账
  2192. tWarehousebills.setfCorpid(fTocorpid);
  2193. TWhgenleg tWhgenle1 = queryTWhgenleg(tWarehousebills, wb);
  2194. if (StringUtils.isNotNull(tWhgenle1) && (wb.getfQty() <= tWhgenle1.getfQtyblc())) {
  2195. updateTWhgenlegData(wb, tWhgenle1.getfId(), "SJRKRevoke");
  2196. } else {
  2197. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  2198. return AjaxResult.error("第" + i + "行撤销数大于库存结余数");
  2199. }
  2200. // 2、原货权方撤销出库
  2201. // 查询库存总账
  2202. tWarehousebills.setfCorpid(fCorpid);
  2203. TWhgenleg tWhgenle2 = queryTWhgenleg(tWarehousebills, wb);
  2204. updateTWhgenlegData(wb, tWhgenle2.getfId(), "SJCKRevoke");
  2205. wb.setfBillstatus(1L);
  2206. }
  2207. i++;
  2208. wb.setUpdateBy(loginUser.getUser().getUserName());
  2209. wb.setUpdateTime(new Date());
  2210. wb.setfSerialNumber(null);
  2211. if (tWarehousebillsitemsMapper.updateTWarehousebillsitems(wb) <= 0) {
  2212. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  2213. return AjaxResult.error("新增库存明细失败");
  2214. }
  2215. }
  2216. }
  2217. /**
  2218. * 流水号回收
  2219. * 2、 流水号去重
  2220. * 3、 添加到 billno_del
  2221. */
  2222. List<String> serialNumberNewList =delRepeat(SerialNumberList);
  2223. serialNumberNewList.forEach(item -> {
  2224. BillnoDel billnoDel = new BillnoDel();
  2225. billnoDel.setBillType(item.substring(0,2));
  2226. billnoDel.setBillNo(item);
  2227. billnoDelMapper.insertBillnoDel(billnoDel);
  2228. });
  2229. // 附件添加
  2230. if (StringUtils.isNotEmpty(tEnclosure) && !"[]".equals(tEnclosure)) {
  2231. JSONArray jsonDrArray = JSONArray.parseArray(tEnclosure);
  2232. List<TEnclosure> tEnclosureList = JSONObject.parseArray(jsonDrArray.toJSONString(), TEnclosure.class);
  2233. for (TEnclosure enclosure : tEnclosureList) {
  2234. enclosure.setfPid(tWarehousebills.getfId());
  2235. enclosure.setCreateBy(loginUser.getUser().getUserName());
  2236. enclosure.setCreateTime(new Date());
  2237. tEnclosureMapper.insertTEnclosure(enclosure);
  2238. }
  2239. }
  2240. // 收款明细添加
  2241. if (StringUtils.isNotEmpty(warehousebillsfeesDr) && !"[]".equals(warehousebillsfeesDr)) {
  2242. JSONArray jsonDrArray = JSONArray.parseArray(warehousebillsfeesDr);
  2243. List<TWarehousebillsfees> warehousebillsfeesDrList = JSONObject.parseArray(jsonDrArray.toJSONString(), TWarehousebillsfees.class);
  2244. for (TWarehousebillsfees wbDr : warehousebillsfeesDrList) {
  2245. wbDr.setfPid(tWarehousebills.getfId());
  2246. wbDr.setfDc("D");
  2247. wbDr.setCreateBy(loginUser.getUser().getUserName());
  2248. wbDr.setCreateTime(new Date());
  2249. if (tWarehousebills.getfBsdate() != null && !tWarehousebills.getfBsdate().equals("")) {
  2250. wbDr.setfBsdate(tWarehousebills.getfBsdate());
  2251. }
  2252. tWarehousebillsfeesMapper.insertTWarehousebillsfees(wbDr);
  2253. }
  2254. }
  2255. // 付款明细添加
  2256. if (StringUtils.isNotNull(warehousebillsfeesCr) && !"[]".equals(warehousebillsfeesCr)) {
  2257. JSONArray jsonCrArray = JSONArray.parseArray(warehousebillsfeesCr);
  2258. List<TWarehousebillsfees> warehousebillsfeesCrList = JSONObject.parseArray(jsonCrArray.toJSONString(), TWarehousebillsfees.class);
  2259. for (TWarehousebillsfees wbCr : warehousebillsfeesCrList) {
  2260. wbCr.setfPid(tWarehousebills.getfId());
  2261. wbCr.setfDc("C");
  2262. wbCr.setCreateBy(loginUser.getUser().getUserName());
  2263. wbCr.setCreateTime(new Date());
  2264. if (tWarehousebills.getfBsdate() != null && !tWarehousebills.getfBsdate().equals("")) {
  2265. wbCr.setfBsdate(tWarehousebills.getfBsdate());
  2266. }
  2267. tWarehousebillsfeesMapper.insertTWarehousebillsfees(wbCr);
  2268. }
  2269. }
  2270. return AjaxResult.success();
  2271. }
  2272. public static List<String> delRepeat(List<String> list) {
  2273. List<String> myList = list.stream().distinct().collect(Collectors.toList());
  2274. return myList ;
  2275. }
  2276. /**
  2277. * 添加 库存明细状态
  2278. *
  2279. * @param wbItem
  2280. * @param status
  2281. * @param loginUser
  2282. */
  2283. public void insertTWarehousebillsLog(TWarehousebillsitems wbItem, Long status, LoginUser loginUser) {
  2284. // 添加状态log
  2285. TWarehousebillsLog tWarehousebillsLog = new TWarehousebillsLog();
  2286. tWarehousebillsLog.setfPid(wbItem.getfPid());
  2287. tWarehousebillsLog.setfItmeid(wbItem.getfId());
  2288. tWarehousebillsLog.setfItmestatus(status);
  2289. tWarehousebillsLog.setCreateTime(new Date());
  2290. tWarehousebillsLog.setCreateBy(loginUser.getUser().getUserName());
  2291. tWarehousebillsLogMapper.insertTWarehousebillsLog(tWarehousebillsLog);
  2292. }
  2293. /**
  2294. * 删除 库存明细
  2295. *
  2296. * @param fid
  2297. * @param tWarehousebillsitems
  2298. */
  2299. public void deleteBillsitems(Long fid, String tWarehousebillsitems) {
  2300. List<Long> oldList = new ArrayList<Long>();
  2301. List<Long> newList = new ArrayList<Long>();
  2302. // 查询所有从表数据
  2303. TWarehousebillsitems tWarehousebillsitem = new TWarehousebillsitems();
  2304. tWarehousebillsitem.setfPid(fid);
  2305. List<TWarehousebillsitems> warehousebillsitemsList = tWarehousebillsitemsMapper.selectTWarehousebillsitemsList(tWarehousebillsitem);
  2306. warehousebillsitemsList.forEach(wb ->
  2307. oldList.add(wb.getfId())
  2308. );
  2309. // 获取提交从表数据ID
  2310. if (tWarehousebillsitems != null) {
  2311. JSONArray warehouseJSON = JSONArray.parseArray(tWarehousebillsitems);
  2312. List<TWarehousebillsitems> warehousebillsitemsLists = JSONObject.parseArray(warehouseJSON.toJSONString(), TWarehousebillsitems.class);
  2313. warehousebillsitemsLists.forEach(wb ->
  2314. newList.add(wb.getfId())
  2315. );
  2316. }
  2317. // 删除多余的ID
  2318. List<Long> reduce1 = oldList.stream().filter(item -> !newList.contains(item)).collect(toList());
  2319. reduce1.forEach(id ->
  2320. tWarehousebillsitemsMapper.deleteTWarehousebillsitemsById(id)
  2321. );
  2322. }
  2323. /**
  2324. * 库容-结余毛重
  2325. *
  2326. * @param fTotalgross
  2327. * @param fGrossweightblc
  2328. * @return
  2329. */
  2330. public static BigDecimal calculation1(String fTotalgross, String fGrossweightblc) {
  2331. BigDecimal num1 = new BigDecimal(fTotalgross);
  2332. BigDecimal num2 = new BigDecimal(fGrossweightblc);
  2333. BigDecimal result = num1.subtract(num2);
  2334. return result.setScale(2, BigDecimal.ROUND_HALF_UP);
  2335. }
  2336. /**
  2337. * 判断 是否允许 入库
  2338. *
  2339. * @param fId
  2340. */
  2341. public int calculation(Long fId, BigDecimal fGrossweight) {
  2342. // 仓库库容
  2343. TWarehouse tWarehouse = tWarehouseMapper.selectTWarehouseById(fId);
  2344. // 毛重公斤转化为吨
  2345. fGrossweight = fGrossweight.divide(new BigDecimal(1000), 0, BigDecimal.ROUND_HALF_UP);
  2346. // 总账使用
  2347. List<Map<String, Object>> whouseList = tWhgenlegMapper.selectWareHouseListWhouse(fId);
  2348. if (whouseList != null && whouseList.size() > 0) {
  2349. String fTotalgross = null;
  2350. String fGrossweightblc = null;
  2351. for (Map<String, Object> m : whouseList) {
  2352. for (String k : m.keySet()) {
  2353. // 获取毛重库容
  2354. if (k.equals("fTotalgross")) {
  2355. fTotalgross = m.get(k).toString();
  2356. }
  2357. if (k.equals("fGrossweightD")) {
  2358. fGrossweightblc = m.get(k).toString();
  2359. }
  2360. }
  2361. }
  2362. BigDecimal bd=new BigDecimal(fGrossweightblc);
  2363. fGrossweightblc = bd.divide(new BigDecimal(1000), 0, BigDecimal.ROUND_HALF_UP).toString();
  2364. BigDecimal result = calculation1(fTotalgross, fGrossweightblc);
  2365. if (result.compareTo(fGrossweight) == -1) {
  2366. return 0;// 结余库容小于入库数
  2367. } else {
  2368. return 1;
  2369. }
  2370. } else {
  2371. if(tWarehouse.getfTotalgross()!=null){
  2372. if (tWarehouse.getfTotalgross().compareTo(fGrossweight) == -1) {
  2373. return 0;// 库容小于入库数
  2374. } else {
  2375. return 1;
  2376. }
  2377. }else {
  2378. return 0;// 库容小于入库数
  2379. }
  2380. }
  2381. }
  2382. }