AuditPathsServiceImpl.java 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813
  1. package com.ruoyi.approvalFlow.service.impl;
  2. import com.alibaba.fastjson.JSONArray;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
  5. import com.ruoyi.approvalFlow.domain.*;
  6. import com.ruoyi.approvalFlow.mapper.*;
  7. import com.ruoyi.approvalFlow.service.IAuditPathsService;
  8. import com.ruoyi.common.core.domain.AjaxResult;
  9. import com.ruoyi.common.core.domain.model.LoginUser;
  10. import com.ruoyi.common.utils.DateUtils;
  11. import com.ruoyi.common.utils.StringUtils;
  12. import com.ruoyi.finance.domain.TFee;
  13. import com.ruoyi.finance.mapper.TFeeMapper;
  14. import com.ruoyi.finance.service.impl.TFeeServiceImpl;
  15. import com.ruoyi.reportManagement.domain.TWhgenleg;
  16. import com.ruoyi.reportManagement.mapper.TWhgenlegMapper;
  17. import com.ruoyi.system.mapper.SysUserMapper;
  18. import com.ruoyi.warehouseBusiness.domain.TWarehouseAgreement;
  19. import com.ruoyi.warehouseBusiness.domain.TWarehouseBills;
  20. import com.ruoyi.warehouseBusiness.domain.TWarehousebillsfees;
  21. import com.ruoyi.warehouseBusiness.domain.TWarehousebillsitems;
  22. import com.ruoyi.warehouseBusiness.mapper.TWarehouseAgreementMapper;
  23. import com.ruoyi.warehouseBusiness.mapper.TWarehouseBillsMapper;
  24. import com.ruoyi.warehouseBusiness.mapper.TWarehousebillsfeesMapper;
  25. import com.ruoyi.warehouseBusiness.mapper.TWarehousebillsitemsMapper;
  26. import com.ruoyi.warehouseBusiness.service.impl.TWarehouseAgreementServiceImpl;
  27. import com.ruoyi.warehouseBusiness.service.impl.TWarehouseBillsServiceImpl;
  28. import org.springframework.beans.factory.annotation.Autowired;
  29. import org.springframework.stereotype.Service;
  30. import org.springframework.transaction.annotation.Transactional;
  31. import org.springframework.transaction.interceptor.TransactionAspectSupport;
  32. import java.util.*;
  33. /**
  34. * 审批流配置主Service业务层处理
  35. *
  36. * @author ruoyi
  37. * @date 2021-01-21
  38. */
  39. @Service
  40. public class AuditPathsServiceImpl implements IAuditPathsService {
  41. @Autowired
  42. private SysUserMapper sysUserMapper;
  43. @Autowired
  44. private AuditPathsMapper auditPathsMapper;
  45. @Autowired
  46. private AuditItemsMapper auditItemsMapper;
  47. @Autowired
  48. private TWhgenlegMapper tWhgenlegMapper;
  49. @Autowired
  50. private AuditItemsUsersMapper auditItemsUsersMapper;
  51. @Autowired
  52. private AuditPathsActsMapper auditPathsActsMapper;
  53. @Autowired
  54. private AuditPathsLevelsMapper auditPathsLevelsMapper;
  55. @Autowired
  56. private TWarehouseBillsMapper tWarehouseBillsMapper;
  57. @Autowired
  58. private TWarehouseBillsServiceImpl tWarehouseBillsService;
  59. @Autowired
  60. private TWarehousebillsfeesMapper tWarehousebillsfeesMapper;
  61. @Autowired
  62. private TWarehousebillsitemsMapper tWarehousebillsitemsMapper;
  63. @Autowired
  64. private TFeeServiceImpl tFeeServiceImpl;
  65. @Autowired
  66. private TWarehouseAgreementServiceImpl tWarehouseAgreementService;
  67. @Autowired
  68. private TFeeMapper tFeeMapper;
  69. @Autowired
  70. private TWarehouseAgreementMapper tWarehouseAgreementMapper;
  71. /**
  72. * 查询审批流配置主
  73. *
  74. * @param id 审批流配置主ID
  75. * @return 审批流配置主
  76. */
  77. @Override
  78. public AjaxResult selectAuditPathsById(Long id) {
  79. Map<String, Object> map = new HashMap<>();
  80. AuditPaths auditPaths = auditPathsMapper.selectAuditPathsById(id);
  81. if (StringUtils.isNull(auditPaths)) {
  82. return AjaxResult.error("该审批流不存在,请确认");
  83. }
  84. map.put("auditPaths", auditPaths);
  85. AuditPathsLevels auditPathsLevels = new AuditPathsLevels();
  86. auditPathsLevels.setPathId(id);
  87. List<AuditPathsLevels> pathsLevelsList = auditPathsLevelsMapper.selectAuditPathsLevelsList(auditPathsLevels);
  88. if (StringUtils.isNotNull(pathsLevelsList)) {
  89. List<List<Long>> longs = new ArrayList<>();
  90. for (AuditPathsLevels ap : pathsLevelsList) {
  91. List<Long> longList = new ArrayList<>();
  92. if (ap.getAuditUserId() != null) {
  93. JSONArray jsonArray = JSONArray.parseArray(ap.getAuditUserId());
  94. longList = JSONObject.parseArray(jsonArray.toJSONString(), Long.class);
  95. }
  96. longs.add(longList);
  97. }
  98. map.put("auditUserIds", longs);
  99. map.put("auditPathsLevels", pathsLevelsList);
  100. }
  101. return AjaxResult.success(map);
  102. }
  103. /**
  104. * 查询审批流配置主列表
  105. *
  106. * @param auditPaths 审批流配置主
  107. * @return 审批流配置主
  108. */
  109. @Override
  110. public List<AuditPaths> selectAuditPathsList(AuditPaths auditPaths) {
  111. return auditPathsMapper.selectAuditPathsList(auditPaths);
  112. }
  113. /**
  114. * 新增审批流配置主
  115. *
  116. * @param auditPaths 审批流配置主
  117. * @return 结果
  118. */
  119. @Override
  120. @Transactional
  121. public AjaxResult insertAuditPaths(String auditPaths, String auditPathsLevels, LoginUser loginUser) {
  122. AuditPaths apath = JSONArray.parseObject(auditPaths, AuditPaths.class);
  123. if ("A".equals(apath.getStatus()) && (StringUtils.isNull(auditPathsLevels) || "[]".equals(auditPathsLevels))) {
  124. return AjaxResult.error("未找到级次信息无法提交,请确认");
  125. }
  126. long fPid = 0L;
  127. if (StringUtils.isNotNull(apath.getId())) {
  128. if ("S".equals(apath.getStatus())) {
  129. AuditPathsActs auditPathsActs = new AuditPathsActs();
  130. auditPathsActs.setPathId(apath.getId());
  131. int sum = auditPathsActsMapper.selectCountAuditPathsActs(auditPathsActs);
  132. if (sum > 0) {
  133. return AjaxResult.error("该审批配置已被使用,请取消使用后提交");
  134. }
  135. }
  136. auditPathsLevelsMapper.deleteAuditPathsLevelsBypathId(apath.getId());
  137. auditPathsMapper.updateAuditPaths(apath);
  138. fPid = apath.getId();
  139. } else {
  140. AuditPaths paths = new AuditPaths();
  141. paths.setPathName(apath.getPathName());
  142. List<AuditPaths> audiList = auditPathsMapper.selectAuditPathsList(paths);
  143. if (audiList.size() > 0) {
  144. return AjaxResult.error("审核路径名已存在,请确认");
  145. }
  146. apath.setOpUserId(loginUser.getUser().getUserId());
  147. apath.setOpDate(new Date());
  148. apath.setOpUserName(loginUser.getUsername());
  149. auditPathsMapper.insertAuditPaths(apath);
  150. fPid = apath.getId();
  151. }
  152. if (StringUtils.isNotNull(auditPathsLevels) && !"[]".equals(auditPathsLevels)) {
  153. JSONArray warehouseJSON = JSONArray.parseArray(auditPathsLevels);
  154. List<AuditPathsLevels> auditPathsLevelsList = JSONObject.parseArray(warehouseJSON.toJSONString(), AuditPathsLevels.class);
  155. if ("F".equals(auditPathsLevelsList.get(auditPathsLevelsList.size() - 1).getIffinalItem())) {
  156. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  157. return AjaxResult.error("操作失败:最后一级状态有误,请确认");
  158. }
  159. Long level = 0L;
  160. boolean last = false;
  161. for (AuditPathsLevels lev : auditPathsLevelsList) {
  162. if (StringUtils.isNull(lev.getAuditUserId())) {
  163. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  164. return AjaxResult.error("操作失败:请维护审核人");
  165. }
  166. if ("T".equals(lev.getIffinalItem()) && !last) {
  167. last = true;
  168. } else if ("T".equals(lev.getIffinalItem()) && last) {
  169. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  170. return AjaxResult.error("操作失败:最后一级只能存在一个");
  171. }
  172. level++;
  173. lev.setPathId(fPid);
  174. lev.setLevelId(level);
  175. auditPathsLevelsMapper.insertAuditPathsLevels(lev);
  176. }
  177. }
  178. return AjaxResult.success();
  179. }
  180. /**
  181. * 修改审批流配置主
  182. *
  183. * @param auditPaths 审批流配置主
  184. * @return 结果
  185. */
  186. @Override
  187. public int updateAuditPaths(AuditPaths auditPaths) {
  188. return auditPathsMapper.updateAuditPaths(auditPaths);
  189. }
  190. /**
  191. * 批量删除审批流配置主
  192. *
  193. * @param ids 需要删除的审批流配置主ID
  194. * @return 结果
  195. */
  196. @Override
  197. @Transactional
  198. public AjaxResult deleteAuditPathsByIds(Long[] ids) {
  199. int line = 0;
  200. for (Long lo : ids) {
  201. line++;
  202. AuditPathsActs auditPathsActs = new AuditPathsActs();
  203. auditPathsActs.setPathId(lo);
  204. int sum = auditPathsActsMapper.selectCountAuditPathsActs(auditPathsActs);
  205. if (sum > 0) {
  206. return AjaxResult.error("第" + line + "行,审批已被使用无法删除");
  207. }
  208. }
  209. auditPathsMapper.deleteAuditPathsByIds(ids);
  210. return AjaxResult.success();
  211. }
  212. /**
  213. * 删除审批流配置主信息
  214. *
  215. * @param id 审批流配置主ID
  216. * @return 结果
  217. */
  218. @Override
  219. public int deleteAuditPathsById(Long id) {
  220. return auditPathsMapper.deleteAuditPathsById(id);
  221. }
  222. /**
  223. * 单据点击查看审批流
  224. *
  225. * @param auditItems 条件
  226. * @return 结果
  227. */
  228. @Override
  229. public AjaxResult projectEndQueryPendingVal(AuditItems auditItems) {
  230. List<Map<String, Object>> mapList = auditItemsMapper.selectWarehouseApprover(auditItems);
  231. return AjaxResult.success(mapList);
  232. }
  233. /**
  234. * 首页点击查看审批流 获取对应数据
  235. *
  236. * @param auditItems 查询条件
  237. * @return 结果
  238. */
  239. @Override
  240. public List<Map<String, Object>> selectAllAuditItems(AuditItems auditItems) {
  241. return auditItemsMapper.selectAuditItems(auditItems);
  242. }
  243. /**
  244. * 查询审批流配置主信息条数
  245. * @return 结果
  246. */
  247. @Override
  248. public int selectCountAuditItems(){
  249. return auditItemsMapper.selectCountAuditItems();
  250. }
  251. /**
  252. * 审批通过
  253. *
  254. * @param auditItems 审核人、单据信息
  255. * @return 结果
  256. */
  257. @Override
  258. @Transactional
  259. public AjaxResult approved(AuditItems auditItems) {
  260. // 审核通过时间
  261. Date auditItemtem = auditItems.getAuditItem();
  262. long fettle = 0L;
  263. int number = 0;
  264. AuditItems item = new AuditItems();
  265. item.setBillId(auditItems.getId());
  266. item.setActId(auditItems.getActId());
  267. item.setFidStatus(auditItems.getFidStatus());
  268. List<AuditItems> auditItemsList = auditItemsMapper.selectAuditItemsList(item);
  269. if (auditItemsList.size() <= 0) {
  270. return AjaxResult.error("未找到审批信息,请确认");
  271. }
  272. for (AuditItems at : auditItemsList) {
  273. if (!"S".equals(at.getAuditStatus())) {
  274. continue;
  275. }
  276. AuditItemsUsers itemsUsers = new AuditItemsUsers();
  277. itemsUsers.setPid(at.getId());
  278. List<AuditItemsUsers> auditItemsUsers = auditItemsUsersMapper.selectAuditItemsUsersList(itemsUsers);
  279. for (AuditItemsUsers au : auditItemsUsers) {
  280. if (au.getUserId().equals(auditItems.getSendUserId()) && "S".equals(au.getAuditStatus())) {
  281. number++;
  282. if (StringUtils.isEmpty(auditItems.getAuditMsg())) {
  283. at.setAuditMsg("同意");
  284. } else {
  285. at.setAuditMsg(auditItems.getAuditMsg());
  286. }
  287. at.setAuditStatus("A");
  288. //at.setAuditItem(new Date());
  289. at.setAuditOpTime(new Date());
  290. at.setAuditUserId(au.getUserId());
  291. at.setAuditItem(auditItemtem);
  292. int updateAuditItems = auditItemsMapper.updateAuditItems(at);
  293. if (updateAuditItems <= 0) {
  294. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  295. return AjaxResult.error("审批通过失败: 更新审批状态失败");
  296. }
  297. au.setAuditStatus("A");
  298. int updateAuditItemsUsers = auditItemsUsersMapper.updateAuditItemsUsers(au);
  299. if (updateAuditItemsUsers <= 0) {
  300. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  301. return AjaxResult.error("审批通过失败: 更新审批状态失败");
  302. }
  303. if (auditItems.getActId() >= 110 && auditItems.getActId() <= 160) {
  304. if ("T".equals(at.getIffinalItem())) {
  305. fettle = 6L;
  306. } else if ("F".equals(at.getIffinalItem())) {
  307. fettle = 5L;
  308. }
  309. // 仓库模块
  310. if ("warehouse_status".equals(auditItems.getFidStatus())) {
  311. tWarehouseBillsMapper.warehouseApprovalUpdate(auditItems, fettle);
  312. } else {
  313. tWarehouseBillsMapper.warehouseFollowUpdate(auditItems.getBillId(), fettle, at.getAuditItem());
  314. }
  315. tWarehousebillsfeesMapper.warehouseFeesFollowUpdate(auditItems.getBillId(), fettle, at.getAuditItem());
  316. if (Objects.equals(auditItems.getActId(), 150)) {
  317. List<TWarehousebillsfees> feesList = tWarehousebillsfeesMapper.selectWarehousebillsfeesByPId(auditItems.getBillId());
  318. if (StringUtils.isNull(feesList) || Objects.equals(feesList.size(), 0)) {
  319. for (TWarehousebillsfees f : feesList) {
  320. if ("KCZZ".equals(f.getfBilltype())) {
  321. TWhgenleg whgenleg = new TWhgenleg();
  322. whgenleg.setfId(f.getSrcId());
  323. whgenleg.setfChargedate(DateUtils.dateAdd(f.getfBillingDeadline(), 1));
  324. tWhgenlegMapper.updateTWhgenleg(whgenleg);
  325. } else {
  326. TWarehousebillsitems billsItem = new TWarehousebillsitems();
  327. billsItem.setfId(f.getSrcId());
  328. billsItem.setfChargedate(DateUtils.dateAdd(f.getfBillingDeadline(), 1));
  329. if ("SJCK".equals(f.getfBilltype())) {
  330. billsItem.setfStorageFeeDeadline(f.getfBillingDeadline());
  331. }
  332. tWarehousebillsitemsMapper.updateTWarehousebillsitems(billsItem);
  333. }
  334. }
  335. }
  336. }
  337. } else if (auditItems.getActId() >= 210 && auditItems.getActId() <= 230) {
  338. // 财务模块
  339. if ("T".equals(at.getIffinalItem())) {
  340. fettle = 6L;
  341. // 更新费用明细
  342. AjaxResult ajaxResult = tFeeServiceImpl.billsfeesFollow(auditItems.getBillId());
  343. String code = ajaxResult.get("code").toString();
  344. if ("500".equals(code)) {
  345. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  346. return ajaxResult;
  347. }
  348. } else if ("F".equals(at.getIffinalItem())) {
  349. fettle = 5L;
  350. }
  351. // 变更财务状态
  352. AjaxResult ajaxResult = tFeeServiceImpl.tfeeFollow(auditItems.getBillId(), fettle);
  353. String code = ajaxResult.get("code").toString();
  354. if ("500".equals(code)) {
  355. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  356. return ajaxResult;
  357. }
  358. } else if (auditItems.getActId() >= 310 && auditItems.getActId() <= 320) {
  359. // 协议模块
  360. if ("T".equals(at.getIffinalItem())) {
  361. fettle = 6L;
  362. } else if ("F".equals(at.getIffinalItem())) {
  363. fettle = 5L;
  364. }
  365. // 变更财务状态
  366. AjaxResult ajaxResult = tWarehouseAgreementService.agreementFollow(auditItems.getBillId(), fettle);
  367. String code = ajaxResult.get("code").toString();
  368. if ("500".equals(code)) {
  369. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  370. return ajaxResult;
  371. }
  372. }else if (auditItems.getActId()== 410 ){
  373. if (StringUtils.isEmpty(auditItems.getRefno3())){
  374. return AjaxResult.error("提单号不能为空");
  375. }
  376. if ("T".equals(at.getIffinalItem())) {
  377. fettle = 6L;
  378. } else if ("F".equals(at.getIffinalItem())) {
  379. fettle = 5L;
  380. }
  381. //变更凯和订单状态
  382. AjaxResult ajaxResult = tWarehouseBillsService.updateKaHeOrder(auditItems.getBillId(), fettle, at.getAuditItem());
  383. String code = ajaxResult.get("code").toString();
  384. if ("500".equals(code)) {
  385. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  386. return ajaxResult;
  387. }
  388. TWarehouseBills tWarehouseBills = new TWarehouseBills();
  389. tWarehouseBills.setfId(auditItems.getBillId());
  390. tWarehouseBills.setfMblno(auditItems.getRefno3());
  391. AjaxResult orderMessage = tWarehouseBillsService.updateOrderMessage(tWarehouseBills);
  392. String orderMessageCode = orderMessage.get("code").toString();
  393. if ("500".equals(orderMessageCode)) {
  394. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  395. return orderMessage;
  396. }
  397. }else if (auditItems.getActId()== 420 ){
  398. if ("T".equals(at.getIffinalItem())) {
  399. fettle = 11L;
  400. } else if ("F".equals(at.getIffinalItem())) {
  401. fettle = 10L;
  402. }
  403. //变更凯和订单状态
  404. AjaxResult ajaxResult = tWarehouseBillsService.updateKaHeOrder(auditItems.getBillId(), fettle, at.getAuditItem());
  405. String code = ajaxResult.get("code").toString();
  406. if ("500".equals(code)) {
  407. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  408. return ajaxResult;
  409. }
  410. } else if (auditItems.getActId() >= 430 && auditItems.getActId() <= 450) {
  411. // 财务模块
  412. if ("T".equals(at.getIffinalItem())) {
  413. fettle = 6L;
  414. // 更新费用明细
  415. AjaxResult ajaxResult = tFeeServiceImpl.billsfeesFollow(auditItems.getBillId());
  416. String code = ajaxResult.get("code").toString();
  417. if ("500".equals(code)) {
  418. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  419. return ajaxResult;
  420. }
  421. } else if ("F".equals(at.getIffinalItem())) {
  422. fettle = 5L;
  423. }
  424. // 变更财务状态
  425. AjaxResult ajaxResult = tFeeServiceImpl.tfeeFollow(auditItems.getBillId(), fettle);
  426. String code = ajaxResult.get("code").toString();
  427. if ("500".equals(code)) {
  428. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  429. return ajaxResult;
  430. }
  431. }else if (auditItems.getActId() == 470) {
  432. // 财务模块
  433. if ("T".equals(at.getIffinalItem())) {
  434. fettle = 6L;
  435. // 更新费用明细
  436. AjaxResult ajaxResult = tFeeServiceImpl.billsfeesFollow(auditItems.getBillId());
  437. String code = ajaxResult.get("code").toString();
  438. if ("500".equals(code)) {
  439. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  440. return ajaxResult;
  441. }
  442. } else if ("F".equals(at.getIffinalItem())) {
  443. fettle = 5L;
  444. }
  445. // 变更财务状态
  446. AjaxResult ajaxResult = tFeeServiceImpl.tfeeFollow(auditItems.getBillId(), fettle);
  447. String code = ajaxResult.get("code").toString();
  448. if ("500".equals(code)) {
  449. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  450. return ajaxResult;
  451. }
  452. //生成销项发票
  453. AjaxResult invoiceFp = tFeeServiceImpl.copyInvoiceFp(auditItems.getBillId(), "INV");
  454. String string = invoiceFp.get("code").toString();
  455. if ("500".equals(string)) {
  456. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  457. return invoiceFp;
  458. }
  459. }else if (auditItems.getActId()== 460 ){
  460. if ("T".equals(at.getIffinalItem())) {
  461. fettle = 6L;
  462. } else if ("F".equals(at.getIffinalItem())) {
  463. fettle = 5L;
  464. }
  465. //变更凯和订单状态
  466. Integer i = tWarehousebillsfeesMapper.warehouseFeesFollowUpdate(auditItems.getBillId(), fettle, at.getAuditItem());
  467. if (i != null && i>0) {
  468. }else {
  469. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  470. return AjaxResult.error("审核失败,更新费用状态失败");
  471. }
  472. }
  473. if ("F".equals(at.getIffinalItem())) {
  474. at.setLevelId(at.getLevelId() + 1);
  475. int updateNum = auditItemsMapper.updateAuditStatus(at);
  476. if (updateNum <= 0) {
  477. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  478. return AjaxResult.error("审批通过失败: 更新审批状态失败");
  479. }
  480. }
  481. break;
  482. }
  483. }
  484. }
  485. if (number <= 0) {
  486. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  487. return AjaxResult.error("该审批已被操作");
  488. }
  489. return AjaxResult.success();
  490. }
  491. /**
  492. * 审批驳回
  493. *
  494. * @param auditItems 审核人、单据信息
  495. * @return 结果
  496. */
  497. @Override
  498. @Transactional
  499. public AjaxResult approvalRejected(AuditItems auditItems) {
  500. long fettle = 0L;
  501. if (auditItems.getActId() >= 110 && auditItems.getActId() <= 160) {
  502. fettle = 3L;
  503. if ("f_billstatus".equals(auditItems.getFidStatus())) {
  504. tWarehouseBillsMapper.warehouseFollowUpdate(auditItems.getBillId(), fettle, auditItems.getAuditItem());
  505. } else {
  506. tWarehouseBillsMapper.warehouseApprovalUpdate(auditItems, fettle);
  507. }
  508. tWarehousebillsfeesMapper.warehouseFeesFollowUpdate(auditItems.getBillId(), fettle, auditItems.getAuditItem());
  509. if (Objects.equals(auditItems.getActId(), 150)) {
  510. List<TWarehousebillsfees> feesList = tWarehousebillsfeesMapper.selectWarehousebillsfeesByPId(auditItems.getBillId());
  511. for (TWarehousebillsfees wareItem : feesList) {
  512. if (StringUtils.isNull(wareItem.getSrcId())) {
  513. continue;
  514. }
  515. if ("KCZZ".equals(wareItem.getfBilltype())) {
  516. TWhgenleg whgenleg = new TWhgenleg();
  517. whgenleg.setfId(wareItem.getSrcId());
  518. whgenleg.setfChargedate(wareItem.getfChargedate());
  519. int i = tWhgenlegMapper.updateTWhgenleg(whgenleg);
  520. if (i <= 0) {
  521. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  522. return AjaxResult.error("更新库存费用状态失败,请联系管理员");
  523. }
  524. } else {
  525. TWarehousebillsitems billsItem = new TWarehousebillsitems();
  526. billsItem.setfId(wareItem.getSrcId());
  527. billsItem.setfBilltype(wareItem.getfBilltype());
  528. if (!"SJCK".equals(wareItem.getfBilltype())) {
  529. billsItem.setfChargedate(wareItem.getfBillingDeadline());
  530. tWarehousebillsitemsMapper.updateTWarehousebillsitems(billsItem);
  531. } else {
  532. billsItem.setfChargedate(wareItem.getfChargedate());
  533. }
  534. tWarehousebillsitemsMapper.agreementApprovalRejected(billsItem);
  535. }
  536. }
  537. }
  538. } else if (auditItems.getActId() >= 210 && auditItems.getActId() <= 230) {
  539. fettle = 3L;
  540. // 财务模块
  541. AjaxResult ajaxResult = tFeeServiceImpl.tfeeFollow(auditItems.getBillId(), fettle);
  542. String code = ajaxResult.get("code").toString();
  543. if ("500".equals(code)) {
  544. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  545. return ajaxResult;
  546. }
  547. } else if (auditItems.getActId() >= 310 && auditItems.getActId() <= 320) {
  548. fettle = 3L;
  549. // 协议模块
  550. AjaxResult ajaxResult = tWarehouseAgreementService.agreementFollow(auditItems.getBillId(), fettle);
  551. String code = ajaxResult.get("code").toString();
  552. if ("500".equals(code)) {
  553. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  554. return ajaxResult;
  555. }
  556. }else if (auditItems.getActId()== 410){
  557. fettle = 3L;
  558. AjaxResult ajaxResult = tWarehouseBillsService.updateKaHeOrder(auditItems.getBillId(), fettle,auditItems.getAuditItem());
  559. String code = ajaxResult.get("code").toString();
  560. if ("500".equals(code)) {
  561. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  562. return ajaxResult;
  563. }
  564. }else if (auditItems.getActId()== 420){
  565. fettle = 8L;
  566. AjaxResult ajaxResult = tWarehouseBillsService.updateKaHeOrder(auditItems.getBillId(), fettle,auditItems.getAuditItem());
  567. String code = ajaxResult.get("code").toString();
  568. if ("500".equals(code)) {
  569. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  570. return ajaxResult;
  571. }
  572. }else if (auditItems.getActId() >= 430 && auditItems.getActId() <= 450) {
  573. fettle = 3L;
  574. // 财务模块
  575. AjaxResult ajaxResult = tFeeServiceImpl.tfeeFollow(auditItems.getBillId(), fettle);
  576. String code = ajaxResult.get("code").toString();
  577. if ("500".equals(code)) {
  578. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  579. return ajaxResult;
  580. }
  581. } else if (auditItems.getActId()== 460){
  582. fettle = 3L;
  583. Integer i = tWarehousebillsfeesMapper.warehouseFeesFollowUpdate(auditItems.getBillId(), fettle, auditItems.getAuditItem());
  584. if (i != null && i>0){
  585. }else{
  586. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  587. return AjaxResult.error("审批驳回失败,更新费用状态失败");
  588. }
  589. }else if (auditItems.getActId() == 470) {
  590. fettle = 3L;
  591. // 财务模块
  592. AjaxResult ajaxResult = tFeeServiceImpl.tfeeFollow(auditItems.getBillId(), fettle);
  593. String code = ajaxResult.get("code").toString();
  594. if ("500".equals(code)) {
  595. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  596. return ajaxResult;
  597. }
  598. }
  599. AuditItems item = new AuditItems();
  600. item.setBillId(auditItems.getId());
  601. item.setActId(auditItems.getActId());
  602. item.setFidStatus(auditItems.getFidStatus());
  603. List<AuditItems> auditItem = auditItemsMapper.selectAuditItemsList(item);
  604. int number = 0;
  605. for (AuditItems at : auditItem) {
  606. if (!"S".equals(at.getAuditStatus())) {
  607. continue;
  608. }
  609. AuditItemsUsers itemsUsers = new AuditItemsUsers();
  610. itemsUsers.setPid(at.getId());
  611. List<AuditItemsUsers> auditItemsUsersList = auditItemsUsersMapper.selectAuditItemsUsersList(itemsUsers);
  612. for (AuditItemsUsers au : auditItemsUsersList) {
  613. if (Objects.equals(au.getUserId(), auditItems.getSendUserId())) {
  614. number++;
  615. at.setAuditStatus("B");
  616. if (auditItems.getAuditMsg() == null || "".equals(auditItems.getAuditMsg())) {
  617. at.setAuditMsg("不同意");
  618. } else {
  619. at.setAuditMsg(auditItems.getAuditMsg());
  620. }
  621. //at.setAuditItem(new Date());
  622. at.setAuditOpTime(new Date());
  623. at.setAuditUserId(au.getUserId());
  624. int updateAuditItems = auditItemsMapper.updateAuditItems(at);
  625. if (updateAuditItems <= 0) {
  626. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  627. return AjaxResult.error("审批驳回失败: 更新审批状态失败");
  628. }
  629. au.setAuditStatus("B");
  630. int updateAuditItemUser = auditItemsUsersMapper.updateAuditItemsUsers(au);
  631. if (updateAuditItemUser <= 0) {
  632. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  633. return AjaxResult.error("审批驳回失败: 更新审批状态失败");
  634. }
  635. if ("F".equals(at.getIffinalItem())) {
  636. int deleteNum = auditItemsMapper.deleteUpLevelId(at);
  637. if (deleteNum <= 0) {
  638. return AjaxResult.error("未找到后续除审批信息");
  639. }
  640. }
  641. }
  642. }
  643. }
  644. if (number <= 0) {
  645. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  646. return AjaxResult.error("该审批已被操作");
  647. }
  648. return AjaxResult.success();
  649. }
  650. /**
  651. * 审批撤销(我提交的 没人审核)
  652. *
  653. * @param auditItems 审核人、单据信息
  654. * @return
  655. */
  656. @Override
  657. @Transactional
  658. public AjaxResult revoke(AuditItems auditItems) {
  659. long fettle = 0L;
  660. if (auditItems.getActId() >= 110 && auditItems.getActId() <= 160) {
  661. fettle = 2L;
  662. // 查询仓库状态
  663. TWarehouseBills tWarehouseBills = tWarehouseBillsMapper.selectTWarehousebillsById(auditItems.getBillId());
  664. if ("f_billstatus".equals(auditItems.getFidStatus())) {
  665. if (!tWarehouseBills.getfBillstatus().equals(4L)) {
  666. return AjaxResult.error("审批撤销失败: 已经过审批");
  667. }
  668. } else {
  669. if (!tWarehouseBills.getWarehouseStatus().equals(4L)) {
  670. return AjaxResult.error("审批撤销失败: 已经过审批");
  671. }
  672. }
  673. tWarehouseBillsMapper.warehouseApprovalUpdate(auditItems, fettle);
  674. tWarehousebillsfeesMapper.warehouseFeesFollowUpdate(auditItems.getBillId(), fettle, auditItems.getAuditItem());
  675. } else if (auditItems.getActId() >= 210 && auditItems.getActId() <= 230) {
  676. fettle = 2L;
  677. // 查询财务状态
  678. TFee tFee = tFeeMapper.selectTFeeById(auditItems.getBillId());
  679. if (!"4".equals(tFee.getfBillstatus())) {
  680. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  681. return AjaxResult.error("审批撤销失败: 已经过审批");
  682. }
  683. // 财务模块
  684. AjaxResult ajaxResult = tFeeServiceImpl.tfeeFollow(auditItems.getBillId(), fettle);
  685. String code = ajaxResult.get("code").toString();
  686. if ("500".equals(code)) {
  687. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  688. return AjaxResult.error("审批撤销失败: 更新审批状态失败");
  689. }
  690. } else if (auditItems.getActId() >= 310 && auditItems.getActId() <= 320) {
  691. fettle = 2L;
  692. // 查询协议状态
  693. TWarehouseAgreement tWarehouseAgreement = tWarehouseAgreementMapper.selectTWarehouseAgreementById(auditItems.getBillId());
  694. if (!"4".equals(tWarehouseAgreement.getfBillstatus())) {
  695. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  696. return AjaxResult.error("审批撤销失败: 已经过审批");
  697. }
  698. // 协议模块
  699. AjaxResult ajaxResult = tWarehouseAgreementService.agreementFollow(auditItems.getBillId(), fettle);
  700. String code = ajaxResult.get("code").toString();
  701. if ("500".equals(code)) {
  702. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  703. return AjaxResult.error("审批撤销失败: 更新审批状态失败");
  704. }
  705. }else if (auditItems.getActId()== 410 ){
  706. fettle = 2L;
  707. TWarehouseBills tWarehouseBills = tWarehouseBillsService.selectKaHeById(auditItems.getBillId());
  708. if (tWarehouseBills.getfBillstatus()!= 4L){
  709. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  710. return AjaxResult.error("审批撤销失败: 已经过审批");
  711. }
  712. AjaxResult ajaxResult = tWarehouseBillsService.updateKaHeOrder(auditItems.getBillId(), fettle,auditItems.getAuditItem());
  713. String code = ajaxResult.get("code").toString();
  714. if ("500".equals(code)) {
  715. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  716. return ajaxResult;
  717. }
  718. }else if (auditItems.getActId()== 420 ){
  719. fettle = 7L;
  720. TWarehouseBills tWarehouseBills = tWarehouseBillsService.selectKaHeById(auditItems.getBillId());
  721. if (tWarehouseBills.getfBillstatus() != 9L){
  722. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  723. return AjaxResult.error("审批撤销失败: 已经过审批");
  724. }
  725. AjaxResult ajaxResult = tWarehouseBillsService.updateKaHeOrder(auditItems.getBillId(), fettle,auditItems.getAuditItem());
  726. String code = ajaxResult.get("code").toString();
  727. if ("500".equals(code)) {
  728. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  729. return ajaxResult;
  730. }
  731. }else if (auditItems.getActId() >= 430 && auditItems.getActId() <= 450) {
  732. fettle = 2L;
  733. // 查询财务状态
  734. TFee tFee = tFeeMapper.selectTFeeById(auditItems.getBillId());
  735. if (!"4".equals(tFee.getfBillstatus())) {
  736. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  737. return AjaxResult.error("审批撤销失败: 已经过审批");
  738. }
  739. // 财务模块
  740. AjaxResult ajaxResult = tFeeServiceImpl.tfeeFollow(auditItems.getBillId(), fettle);
  741. String code = ajaxResult.get("code").toString();
  742. if ("500".equals(code)) {
  743. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  744. return AjaxResult.error("审批撤销失败: 更新审批状态失败");
  745. }
  746. }else if (auditItems.getActId()== 460 ){
  747. fettle = 2L;
  748. TWarehousebillsfees warehousebillsfees = new TWarehousebillsfees();
  749. warehousebillsfees.setfPid(auditItems.getBillId());
  750. List<TWarehousebillsfees> tWarehousebillsfees = tWarehousebillsfeesMapper.selectTWarehousebillsfeesList(warehousebillsfees);
  751. if (CollectionUtils.isNotEmpty(tWarehousebillsfees) && tWarehousebillsfees.get(0).getfBillstatus() != 4L){
  752. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  753. return AjaxResult.error("审批撤销失败: 已经过审批");
  754. }
  755. Integer i = tWarehousebillsfeesMapper.warehouseFeesFollowUpdate(auditItems.getBillId(), fettle, auditItems.getAuditItem());
  756. if (i != null && i>0){}else {
  757. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  758. return AjaxResult.error("审核失败,更新费用状态失败");
  759. }
  760. }else if (auditItems.getActId() == 470) {
  761. fettle = 2L;
  762. // 查询财务状态
  763. TFee tFee = tFeeMapper.selectTFeeById(auditItems.getBillId());
  764. if (!"4".equals(tFee.getfBillstatus())) {
  765. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  766. return AjaxResult.error("审批撤销失败: 已经过审批");
  767. }
  768. // 财务模块
  769. AjaxResult ajaxResult = tFeeServiceImpl.tfeeFollow(auditItems.getBillId(), fettle);
  770. String code = ajaxResult.get("code").toString();
  771. if ("500".equals(code)) {
  772. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  773. return AjaxResult.error("审批撤销失败: 更新审批状态失败");
  774. }
  775. }
  776. int deleteNum = auditItemsMapper.deletePurchaseApproval(auditItems);
  777. if (deleteNum == 0) {
  778. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  779. return AjaxResult.error("审批撤销失败: 更新审批状态失败");
  780. }
  781. return AjaxResult.success();
  782. }
  783. }