AuditPathsServiceImpl.java 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824
  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. if (auditItems.getActId() >= 110 && auditItems.getActId() <= 160) {
  231. List<Map<String, Object>> mapList = auditItemsMapper.selectWarehouseApprover(auditItems);
  232. return AjaxResult.success(mapList);
  233. } else if (auditItems.getActId() >= 210 && auditItems.getActId() <= 230) {
  234. // 财务审批
  235. List<Map<String, Object>> mapList = auditItemsMapper.selectWarehouseApprover(auditItems);
  236. return AjaxResult.success(mapList);
  237. } else if (auditItems.getActId() >= 310 && auditItems.getActId() <= 320) {
  238. // 协议审批
  239. List<Map<String, Object>> mapList = auditItemsMapper.selectWarehouseApprover(auditItems);
  240. return AjaxResult.success(mapList);
  241. } else if (auditItems.getActId() == 410 ) {
  242. // 协议审批
  243. List<Map<String, Object>> mapList = auditItemsMapper.selectWarehouseApprover(auditItems);
  244. return AjaxResult.success(mapList);
  245. } else if (auditItems.getActId() == 420 ) {
  246. // 协议审批
  247. List<Map<String, Object>> mapList = auditItemsMapper.selectWarehouseApprover(auditItems);
  248. return AjaxResult.success(mapList);
  249. } else if (auditItems.getActId() == 460 ) {
  250. // 协议审批
  251. List<Map<String, Object>> mapList = auditItemsMapper.selectWarehouseApprover(auditItems);
  252. return AjaxResult.success(mapList);
  253. }else if (auditItems.getActId() == 470 ){
  254. List<Map<String, Object>> mapList = auditItemsMapper.selectWarehouseApprover(auditItems);
  255. return AjaxResult.success(mapList);
  256. }else if (auditItems.getActId() >= 430 && auditItems.getActId() <= 450 ){
  257. List<Map<String, Object>> mapList = auditItemsMapper.selectWarehouseApprover(auditItems);
  258. return AjaxResult.success(mapList);
  259. }
  260. return AjaxResult.success();
  261. }
  262. /**
  263. * 首页点击查看审批流 获取对应数据
  264. *
  265. * @param auditItems 查询条件
  266. * @return 结果
  267. */
  268. @Override
  269. public AjaxResult selectAllAuditItems(AuditItems auditItems) {
  270. return AjaxResult.success(auditItemsMapper.selectAuditItems(auditItems));
  271. }
  272. /**
  273. * 查询审批流配置主信息条数
  274. * @return 结果
  275. */
  276. @Override
  277. public int selectCountAuditItems(){
  278. return auditItemsMapper.selectCountAuditItems();
  279. }
  280. /**
  281. * 审批通过
  282. *
  283. * @param auditItems 审核人、单据信息
  284. * @return 结果
  285. */
  286. @Override
  287. @Transactional
  288. public AjaxResult approved(AuditItems auditItems) {
  289. // 审核通过时间
  290. Date auditItemtem = auditItems.getAuditItem();
  291. long fettle = 0L;
  292. int number = 0;
  293. AuditItems item = new AuditItems();
  294. item.setBillId(auditItems.getId());
  295. item.setActId(auditItems.getActId());
  296. List<AuditItems> auditItemsList = auditItemsMapper.selectAuditItemsList(item);
  297. if (auditItemsList.size() <= 0) {
  298. return AjaxResult.error("未找到审批信息,请确认");
  299. }
  300. for (AuditItems at : auditItemsList) {
  301. if (!"S".equals(at.getAuditStatus())) {
  302. continue;
  303. }
  304. AuditItemsUsers itemsUsers = new AuditItemsUsers();
  305. itemsUsers.setPid(at.getId());
  306. List<AuditItemsUsers> auditItemsUsers = auditItemsUsersMapper.selectAuditItemsUsersList(itemsUsers);
  307. for (AuditItemsUsers au : auditItemsUsers) {
  308. if (au.getUserId().equals(auditItems.getSendUserId()) && "S".equals(au.getAuditStatus())) {
  309. number++;
  310. if (StringUtils.isEmpty(auditItems.getAuditMsg())) {
  311. at.setAuditMsg("同意");
  312. } else {
  313. at.setAuditMsg(auditItems.getAuditMsg());
  314. }
  315. at.setAuditStatus("A");
  316. //at.setAuditItem(new Date());
  317. at.setAuditOpTime(new Date());
  318. at.setAuditUserId(au.getUserId());
  319. at.setAuditItem(auditItemtem);
  320. int updateAuditItems = auditItemsMapper.updateAuditItems(at);
  321. if (updateAuditItems <= 0) {
  322. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  323. return AjaxResult.error("审批通过失败: 更新审批状态失败");
  324. }
  325. au.setAuditStatus("A");
  326. int updateAuditItemsUsers = auditItemsUsersMapper.updateAuditItemsUsers(au);
  327. if (updateAuditItemsUsers <= 0) {
  328. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  329. return AjaxResult.error("审批通过失败: 更新审批状态失败");
  330. }
  331. if (auditItems.getActId() >= 110 && auditItems.getActId() <= 160) {
  332. if ("T".equals(at.getIffinalItem())) {
  333. fettle = 6L;
  334. } else if ("F".equals(at.getIffinalItem())) {
  335. fettle = 5L;
  336. }
  337. // 仓库模块
  338. tWarehouseBillsMapper.warehouseFollowUpdate(auditItems.getBillId(), fettle, at.getAuditItem());
  339. tWarehousebillsfeesMapper.warehouseFeesFollowUpdate(auditItems.getBillId(), fettle, at.getAuditItem());
  340. if (Objects.equals(auditItems.getActId(), 150)) {
  341. List<TWarehousebillsfees> feesList = tWarehousebillsfeesMapper.selectWarehousebillsfeesByPId(auditItems.getBillId());
  342. if (StringUtils.isNull(feesList) || Objects.equals(feesList.size(), 0)) {
  343. for (TWarehousebillsfees f : feesList) {
  344. if ("KCZZ".equals(f.getfBilltype())) {
  345. TWhgenleg whgenleg = new TWhgenleg();
  346. whgenleg.setfId(f.getSrcId());
  347. whgenleg.setfChargedate(DateUtils.dateAdd(f.getfBillingDeadline(), 1));
  348. tWhgenlegMapper.updateTWhgenleg(whgenleg);
  349. } else {
  350. TWarehousebillsitems billsItem = new TWarehousebillsitems();
  351. billsItem.setfId(f.getSrcId());
  352. billsItem.setfChargedate(DateUtils.dateAdd(f.getfBillingDeadline(), 1));
  353. if ("SJCK".equals(f.getfBilltype())) {
  354. billsItem.setfStorageFeeDeadline(f.getfBillingDeadline());
  355. }
  356. tWarehousebillsitemsMapper.updateTWarehousebillsitems(billsItem);
  357. }
  358. }
  359. }
  360. }
  361. } else if (auditItems.getActId() >= 210 && auditItems.getActId() <= 230) {
  362. // 财务模块
  363. if ("T".equals(at.getIffinalItem())) {
  364. fettle = 6L;
  365. // 更新费用明细
  366. AjaxResult ajaxResult = tFeeServiceImpl.billsfeesFollow(auditItems.getBillId());
  367. String code = ajaxResult.get("code").toString();
  368. if ("500".equals(code)) {
  369. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  370. return ajaxResult;
  371. }
  372. } else if ("F".equals(at.getIffinalItem())) {
  373. fettle = 5L;
  374. }
  375. // 变更财务状态
  376. AjaxResult ajaxResult = tFeeServiceImpl.tfeeFollow(auditItems.getBillId(), fettle);
  377. String code = ajaxResult.get("code").toString();
  378. if ("500".equals(code)) {
  379. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  380. return ajaxResult;
  381. }
  382. } else if (auditItems.getActId() >= 310 && auditItems.getActId() <= 320) {
  383. // 协议模块
  384. if ("T".equals(at.getIffinalItem())) {
  385. fettle = 6L;
  386. } else if ("F".equals(at.getIffinalItem())) {
  387. fettle = 5L;
  388. }
  389. // 变更财务状态
  390. AjaxResult ajaxResult = tWarehouseAgreementService.agreementFollow(auditItems.getBillId(), fettle);
  391. String code = ajaxResult.get("code").toString();
  392. if ("500".equals(code)) {
  393. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  394. return ajaxResult;
  395. }
  396. }else if (auditItems.getActId()== 410 ){
  397. if (StringUtils.isEmpty(auditItems.getRefno3())){
  398. return AjaxResult.error("提单号不能为空");
  399. }
  400. if ("T".equals(at.getIffinalItem())) {
  401. fettle = 6L;
  402. } else if ("F".equals(at.getIffinalItem())) {
  403. fettle = 5L;
  404. }
  405. //变更凯和订单状态
  406. AjaxResult ajaxResult = tWarehouseBillsService.updateKaHeOrder(auditItems.getBillId(), fettle, at.getAuditItem());
  407. String code = ajaxResult.get("code").toString();
  408. if ("500".equals(code)) {
  409. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  410. return ajaxResult;
  411. }
  412. TWarehouseBills tWarehouseBills = new TWarehouseBills();
  413. tWarehouseBills.setfId(auditItems.getBillId());
  414. tWarehouseBills.setfMblno(auditItems.getRefno3());
  415. AjaxResult orderMessage = tWarehouseBillsService.updateOrderMessage(tWarehouseBills);
  416. String orderMessageCode = orderMessage.get("code").toString();
  417. if ("500".equals(orderMessageCode)) {
  418. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  419. return orderMessage;
  420. }
  421. }else if (auditItems.getActId()== 420 ){
  422. if ("T".equals(at.getIffinalItem())) {
  423. fettle = 11L;
  424. } else if ("F".equals(at.getIffinalItem())) {
  425. fettle = 10L;
  426. }
  427. //变更凯和订单状态
  428. AjaxResult ajaxResult = tWarehouseBillsService.updateKaHeOrder(auditItems.getBillId(), fettle, at.getAuditItem());
  429. String code = ajaxResult.get("code").toString();
  430. if ("500".equals(code)) {
  431. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  432. return ajaxResult;
  433. }
  434. } else if (auditItems.getActId() >= 430 && auditItems.getActId() <= 450) {
  435. // 财务模块
  436. if ("T".equals(at.getIffinalItem())) {
  437. fettle = 6L;
  438. // 更新费用明细
  439. AjaxResult ajaxResult = tFeeServiceImpl.billsfeesFollow(auditItems.getBillId());
  440. String code = ajaxResult.get("code").toString();
  441. if ("500".equals(code)) {
  442. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  443. return ajaxResult;
  444. }
  445. } else if ("F".equals(at.getIffinalItem())) {
  446. fettle = 5L;
  447. }
  448. // 变更财务状态
  449. AjaxResult ajaxResult = tFeeServiceImpl.tfeeFollow(auditItems.getBillId(), fettle);
  450. String code = ajaxResult.get("code").toString();
  451. if ("500".equals(code)) {
  452. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  453. return ajaxResult;
  454. }
  455. }else if (auditItems.getActId() == 470) {
  456. // 财务模块
  457. if ("T".equals(at.getIffinalItem())) {
  458. fettle = 6L;
  459. // 更新费用明细
  460. AjaxResult ajaxResult = tFeeServiceImpl.billsfeesFollow(auditItems.getBillId());
  461. String code = ajaxResult.get("code").toString();
  462. if ("500".equals(code)) {
  463. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  464. return ajaxResult;
  465. }
  466. } else if ("F".equals(at.getIffinalItem())) {
  467. fettle = 5L;
  468. }
  469. // 变更财务状态
  470. AjaxResult ajaxResult = tFeeServiceImpl.tfeeFollow(auditItems.getBillId(), fettle);
  471. String code = ajaxResult.get("code").toString();
  472. if ("500".equals(code)) {
  473. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  474. return ajaxResult;
  475. }
  476. }else if (auditItems.getActId()== 460 ){
  477. if ("T".equals(at.getIffinalItem())) {
  478. fettle = 6L;
  479. } else if ("F".equals(at.getIffinalItem())) {
  480. fettle = 5L;
  481. }
  482. //变更凯和订单状态
  483. Integer i = tWarehousebillsfeesMapper.warehouseFeesFollowUpdate(auditItems.getBillId(), fettle, at.getAuditItem());
  484. if (i != null && i>0) {
  485. }else {
  486. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  487. return AjaxResult.error("审核失败,更新费用状态失败");
  488. }
  489. }
  490. if ("F".equals(at.getIffinalItem())) {
  491. at.setLevelId(at.getLevelId() + 1);
  492. int updateNum = auditItemsMapper.updateAuditStatus(at);
  493. if (updateNum <= 0) {
  494. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  495. return AjaxResult.error("审批通过失败: 更新审批状态失败");
  496. }
  497. }
  498. break;
  499. }
  500. }
  501. }
  502. if (number <= 0) {
  503. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  504. return AjaxResult.error("该审批已被操作");
  505. }
  506. return AjaxResult.success();
  507. }
  508. /**
  509. * 审批驳回
  510. *
  511. * @param auditItems 审核人、单据信息
  512. * @return 结果
  513. */
  514. @Override
  515. @Transactional
  516. public AjaxResult approvalRejected(AuditItems auditItems) {
  517. long fettle = 0L;
  518. if (auditItems.getActId() >= 110 && auditItems.getActId() <= 160) {
  519. fettle = 3L;
  520. tWarehouseBillsMapper.warehouseFollowUpdate(auditItems.getBillId(), fettle, auditItems.getAuditItem());
  521. tWarehousebillsfeesMapper.warehouseFeesFollowUpdate(auditItems.getBillId(), fettle, auditItems.getAuditItem());
  522. if (Objects.equals(auditItems.getActId(), 150)) {
  523. List<TWarehousebillsfees> feesList = tWarehousebillsfeesMapper.selectWarehousebillsfeesByPId(auditItems.getBillId());
  524. for (TWarehousebillsfees wareItem : feesList) {
  525. if (StringUtils.isNull(wareItem.getSrcId())) {
  526. continue;
  527. }
  528. if ("KCZZ".equals(wareItem.getfBilltype())) {
  529. TWhgenleg whgenleg = new TWhgenleg();
  530. whgenleg.setfId(wareItem.getSrcId());
  531. whgenleg.setfChargedate(wareItem.getfChargedate());
  532. int i = tWhgenlegMapper.updateTWhgenleg(whgenleg);
  533. if (i <= 0) {
  534. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  535. return AjaxResult.error("更新库存费用状态失败,请联系管理员");
  536. }
  537. } else {
  538. TWarehousebillsitems billsItem = new TWarehousebillsitems();
  539. billsItem.setfId(wareItem.getSrcId());
  540. billsItem.setfBilltype(wareItem.getfBilltype());
  541. if (!"SJCK".equals(wareItem.getfBilltype())) {
  542. billsItem.setfChargedate(wareItem.getfBillingDeadline());
  543. tWarehousebillsitemsMapper.updateTWarehousebillsitems(billsItem);
  544. } else {
  545. billsItem.setfChargedate(wareItem.getfChargedate());
  546. }
  547. tWarehousebillsitemsMapper.agreementApprovalRejected(billsItem);
  548. }
  549. }
  550. }
  551. } else if (auditItems.getActId() >= 210 && auditItems.getActId() <= 230) {
  552. fettle = 3L;
  553. // 财务模块
  554. AjaxResult ajaxResult = tFeeServiceImpl.tfeeFollow(auditItems.getBillId(), fettle);
  555. String code = ajaxResult.get("code").toString();
  556. if ("500".equals(code)) {
  557. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  558. return ajaxResult;
  559. }
  560. } else if (auditItems.getActId() >= 310 && auditItems.getActId() <= 320) {
  561. fettle = 3L;
  562. // 协议模块
  563. AjaxResult ajaxResult = tWarehouseAgreementService.agreementFollow(auditItems.getBillId(), fettle);
  564. String code = ajaxResult.get("code").toString();
  565. if ("500".equals(code)) {
  566. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  567. return ajaxResult;
  568. }
  569. }else if (auditItems.getActId()== 410){
  570. fettle = 3L;
  571. AjaxResult ajaxResult = tWarehouseBillsService.updateKaHeOrder(auditItems.getBillId(), fettle,auditItems.getAuditItem());
  572. String code = ajaxResult.get("code").toString();
  573. if ("500".equals(code)) {
  574. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  575. return ajaxResult;
  576. }
  577. }else if (auditItems.getActId()== 420){
  578. fettle = 8L;
  579. AjaxResult ajaxResult = tWarehouseBillsService.updateKaHeOrder(auditItems.getBillId(), fettle,auditItems.getAuditItem());
  580. String code = ajaxResult.get("code").toString();
  581. if ("500".equals(code)) {
  582. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  583. return ajaxResult;
  584. }
  585. }else if (auditItems.getActId() >= 430 && auditItems.getActId() <= 450) {
  586. fettle = 3L;
  587. // 财务模块
  588. AjaxResult ajaxResult = tFeeServiceImpl.tfeeFollow(auditItems.getBillId(), fettle);
  589. String code = ajaxResult.get("code").toString();
  590. if ("500".equals(code)) {
  591. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  592. return ajaxResult;
  593. }
  594. } else if (auditItems.getActId()== 460){
  595. fettle = 3L;
  596. Integer i = tWarehousebillsfeesMapper.warehouseFeesFollowUpdate(auditItems.getBillId(), fettle, auditItems.getAuditItem());
  597. if (i != null && i>0){
  598. }else{
  599. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  600. return AjaxResult.error("审批驳回失败,更新费用状态失败");
  601. }
  602. }else if (auditItems.getActId() == 470) {
  603. fettle = 3L;
  604. // 财务模块
  605. AjaxResult ajaxResult = tFeeServiceImpl.tfeeFollow(auditItems.getBillId(), fettle);
  606. String code = ajaxResult.get("code").toString();
  607. if ("500".equals(code)) {
  608. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  609. return ajaxResult;
  610. }
  611. }
  612. AuditItems item = new AuditItems();
  613. item.setBillId(auditItems.getId());
  614. item.setActId(auditItems.getActId());
  615. List<AuditItems> auditItem = auditItemsMapper.selectAuditItemsList(item);
  616. int number = 0;
  617. for (AuditItems at : auditItem) {
  618. if (!"S".equals(at.getAuditStatus())) {
  619. continue;
  620. }
  621. AuditItemsUsers itemsUsers = new AuditItemsUsers();
  622. itemsUsers.setPid(at.getId());
  623. List<AuditItemsUsers> auditItemsUsersList = auditItemsUsersMapper.selectAuditItemsUsersList(itemsUsers);
  624. for (AuditItemsUsers au : auditItemsUsersList) {
  625. if (Objects.equals(au.getUserId(), auditItems.getSendUserId())) {
  626. number++;
  627. at.setAuditStatus("B");
  628. if (auditItems.getAuditMsg() == null || "".equals(auditItems.getAuditMsg())) {
  629. at.setAuditMsg("不同意");
  630. } else {
  631. at.setAuditMsg(auditItems.getAuditMsg());
  632. }
  633. //at.setAuditItem(new Date());
  634. at.setAuditOpTime(new Date());
  635. at.setAuditUserId(au.getUserId());
  636. int updateAuditItems = auditItemsMapper.updateAuditItems(at);
  637. if (updateAuditItems <= 0) {
  638. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  639. return AjaxResult.error("审批驳回失败: 更新审批状态失败");
  640. }
  641. au.setAuditStatus("B");
  642. int updateAuditItemUser = auditItemsUsersMapper.updateAuditItemsUsers(au);
  643. if (updateAuditItemUser <= 0) {
  644. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  645. return AjaxResult.error("审批驳回失败: 更新审批状态失败");
  646. }
  647. if ("F".equals(at.getIffinalItem())) {
  648. int deleteNum = auditItemsMapper.deleteUpLevelId(at);
  649. if (deleteNum <= 0) {
  650. return AjaxResult.error("未找到后续除审批信息");
  651. }
  652. }
  653. }
  654. }
  655. }
  656. if (number <= 0) {
  657. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  658. return AjaxResult.error("该审批已被操作");
  659. }
  660. return AjaxResult.success();
  661. }
  662. /**
  663. * 审批撤销(我提交的 没人审核)
  664. *
  665. * @param auditItems 审核人、单据信息
  666. * @return
  667. */
  668. @Override
  669. @Transactional
  670. public AjaxResult revoke(AuditItems auditItems) {
  671. long fettle = 0L;
  672. if (auditItems.getActId() >= 110 && auditItems.getActId() <= 160) {
  673. fettle = 2L;
  674. // 查询仓库状态
  675. TWarehouseBills tWarehouseBills = tWarehouseBillsMapper.selectTWarehousebillsById(auditItems.getBillId());
  676. if (!tWarehouseBills.getfBillstatus().equals(4L)) {
  677. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  678. return AjaxResult.error("审批撤销失败: 已经过审批");
  679. }
  680. tWarehouseBillsMapper.warehouseFollowUpdate(auditItems.getBillId(), fettle, auditItems.getAuditItem());
  681. tWarehousebillsfeesMapper.warehouseFeesFollowUpdate(auditItems.getBillId(), fettle, auditItems.getAuditItem());
  682. } else if (auditItems.getActId() >= 210 && auditItems.getActId() <= 230) {
  683. fettle = 2L;
  684. // 查询财务状态
  685. TFee tFee = tFeeMapper.selectTFeeById(auditItems.getBillId());
  686. if (!"4".equals(tFee.getfBillstatus())) {
  687. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  688. return AjaxResult.error("审批撤销失败: 已经过审批");
  689. }
  690. // 财务模块
  691. AjaxResult ajaxResult = tFeeServiceImpl.tfeeFollow(auditItems.getBillId(), fettle);
  692. String code = ajaxResult.get("code").toString();
  693. if ("500".equals(code)) {
  694. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  695. return AjaxResult.error("审批撤销失败: 更新审批状态失败");
  696. }
  697. } else if (auditItems.getActId() >= 310 && auditItems.getActId() <= 320) {
  698. fettle = 2L;
  699. // 查询协议状态
  700. TWarehouseAgreement tWarehouseAgreement = tWarehouseAgreementMapper.selectTWarehouseAgreementById(auditItems.getBillId());
  701. if (!"4".equals(tWarehouseAgreement.getfBillstatus())) {
  702. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  703. return AjaxResult.error("审批撤销失败: 已经过审批");
  704. }
  705. // 协议模块
  706. AjaxResult ajaxResult = tWarehouseAgreementService.agreementFollow(auditItems.getBillId(), fettle);
  707. String code = ajaxResult.get("code").toString();
  708. if ("500".equals(code)) {
  709. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  710. return AjaxResult.error("审批撤销失败: 更新审批状态失败");
  711. }
  712. }else if (auditItems.getActId()== 410 ){
  713. fettle = 2L;
  714. TWarehouseBills tWarehouseBills = tWarehouseBillsService.selectKaHeById(auditItems.getBillId());
  715. if (tWarehouseBills.getfBillstatus()!= 4L){
  716. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  717. return AjaxResult.error("审批撤销失败: 已经过审批");
  718. }
  719. AjaxResult ajaxResult = tWarehouseBillsService.updateKaHeOrder(auditItems.getBillId(), fettle,auditItems.getAuditItem());
  720. String code = ajaxResult.get("code").toString();
  721. if ("500".equals(code)) {
  722. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  723. return ajaxResult;
  724. }
  725. }else if (auditItems.getActId()== 420 ){
  726. fettle = 7L;
  727. TWarehouseBills tWarehouseBills = tWarehouseBillsService.selectKaHeById(auditItems.getBillId());
  728. if (tWarehouseBills.getfBillstatus() != 9L){
  729. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  730. return AjaxResult.error("审批撤销失败: 已经过审批");
  731. }
  732. AjaxResult ajaxResult = tWarehouseBillsService.updateKaHeOrder(auditItems.getBillId(), fettle,auditItems.getAuditItem());
  733. String code = ajaxResult.get("code").toString();
  734. if ("500".equals(code)) {
  735. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  736. return ajaxResult;
  737. }
  738. }else if (auditItems.getActId() >= 430 && auditItems.getActId() <= 450) {
  739. fettle = 2L;
  740. // 查询财务状态
  741. TFee tFee = tFeeMapper.selectTFeeById(auditItems.getBillId());
  742. if (!"4".equals(tFee.getfBillstatus())) {
  743. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  744. return AjaxResult.error("审批撤销失败: 已经过审批");
  745. }
  746. // 财务模块
  747. AjaxResult ajaxResult = tFeeServiceImpl.tfeeFollow(auditItems.getBillId(), fettle);
  748. String code = ajaxResult.get("code").toString();
  749. if ("500".equals(code)) {
  750. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  751. return AjaxResult.error("审批撤销失败: 更新审批状态失败");
  752. }
  753. }else if (auditItems.getActId()== 460 ){
  754. fettle = 2L;
  755. TWarehousebillsfees warehousebillsfees = new TWarehousebillsfees();
  756. warehousebillsfees.setfPid(auditItems.getBillId());
  757. List<TWarehousebillsfees> tWarehousebillsfees = tWarehousebillsfeesMapper.selectTWarehousebillsfeesList(warehousebillsfees);
  758. if (CollectionUtils.isNotEmpty(tWarehousebillsfees) && tWarehousebillsfees.get(0).getfBillstatus() != 4L){
  759. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  760. return AjaxResult.error("审批撤销失败: 已经过审批");
  761. }
  762. Integer i = tWarehousebillsfeesMapper.warehouseFeesFollowUpdate(auditItems.getBillId(), fettle, auditItems.getAuditItem());
  763. if (i != null && i>0){}else {
  764. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  765. return AjaxResult.error("审核失败,更新费用状态失败");
  766. }
  767. }else if (auditItems.getActId() == 470) {
  768. fettle = 2L;
  769. // 查询财务状态
  770. TFee tFee = tFeeMapper.selectTFeeById(auditItems.getBillId());
  771. if (!"4".equals(tFee.getfBillstatus())) {
  772. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  773. return AjaxResult.error("审批撤销失败: 已经过审批");
  774. }
  775. // 财务模块
  776. AjaxResult ajaxResult = tFeeServiceImpl.tfeeFollow(auditItems.getBillId(), fettle);
  777. String code = ajaxResult.get("code").toString();
  778. if ("500".equals(code)) {
  779. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  780. return AjaxResult.error("审批撤销失败: 更新审批状态失败");
  781. }
  782. }
  783. AuditItems item = new AuditItems();
  784. item.setBillId(auditItems.getId());
  785. item.setActId(auditItems.getActId());
  786. int deleteNum = auditItemsMapper.deletePurchaseApproval(item);
  787. if (deleteNum == 0) {
  788. TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  789. return AjaxResult.error("审批撤销失败: 更新审批状态失败");
  790. }
  791. return AjaxResult.success();
  792. }
  793. }