AuditPathsServiceImpl.java 31 KB

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