OwnBillController.java 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  1. package com.huyi.service.bill.controller;
  2. import com.alibaba.fastjson.JSON;
  3. import com.alibaba.fastjson.JSONArray;
  4. import com.alibaba.fastjson.JSONObject;
  5. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  6. import com.baomidou.mybatisplus.core.metadata.IPage;
  7. import com.huyi.service.base.entity.ZcBillFileRel;
  8. import com.huyi.service.base.entity.ZcBillInf;
  9. import com.huyi.service.base.entity.ZcBillInvoiceRel;
  10. import com.huyi.service.base.entity.ZcInvoiceInf;
  11. import com.huyi.service.base.service.*;
  12. import com.huyi.service.bill.service.IOwnBillService;
  13. import com.keao.tianhu.starter.mybatis.plus.entity.QueryRequest;
  14. import com.tianhu.common.core.constant.SalaryConstants;
  15. import com.tianhu.common.core.domain.R;
  16. import com.tianhu.common.core.utils.*;
  17. import com.tianhu.common.core.web.controller.BaseController;
  18. import com.tianhu.common.core.web.domain.AjaxResult;
  19. import com.tianhu.common.log.annotation.Log;
  20. import com.tianhu.common.log.enums.BusinessType;
  21. import com.tianhu.common.security.annotation.PreAuthorize;
  22. import com.tianhu.common.security.service.TokenService;
  23. import com.tianhu.system.api.RemoteFileService;
  24. import com.tianhu.system.api.domain.PubFileInf;
  25. import com.tianhu.system.api.domain.SysUser;
  26. import com.tianhu.system.api.model.LoginUser;
  27. import lombok.SneakyThrows;
  28. import org.springframework.beans.factory.annotation.Autowired;
  29. import org.springframework.cglib.beans.BeanMap;
  30. import org.springframework.transaction.annotation.Transactional;
  31. import org.springframework.web.bind.annotation.*;
  32. import org.springframework.web.multipart.MultipartFile;
  33. import java.text.ParseException;
  34. import java.text.SimpleDateFormat;
  35. import java.util.*;
  36. /**
  37. * 往来账款管理
  38. *
  39. * @author dudm@minpay.cc
  40. * @date 2021-08-17
  41. */
  42. @RestController
  43. @RequestMapping("ownBill")
  44. public class OwnBillController extends BaseController {
  45. /**
  46. * 验证状态 0未验证1成功2失败
  47. */
  48. private static String CHECK_SUCCESS = "1";
  49. @Autowired
  50. private IOwnBillService iOwnBillService;
  51. @Autowired
  52. private IZcBillInfService iZcBillInfService;
  53. @Autowired
  54. private TokenService tokenService;
  55. @Autowired
  56. private IZcInvoiceInfService iZcInvoiceInfService;
  57. @Autowired
  58. private IZcBillInvoiceRelService iZcBillInvoiceRelService;
  59. @Autowired
  60. private IZcBillFileRelService iZcBillFileRelService;
  61. @Autowired
  62. private IPubFileInfService iPubFileInfService;
  63. @Autowired
  64. private ISysUserService iSysUserService;
  65. @Autowired
  66. private RemoteFileService remoteFileService;
  67. /**
  68. * 往来账款列表
  69. *
  70. * @param zbiName 账款名称
  71. * @param zbiNumber 账款编号
  72. * @param payerName 应付方
  73. * @param payeeName 应收方
  74. * @param zbiType 账款类型
  75. * @param zbiStatus 账款状态
  76. * @return
  77. */
  78. @GetMapping("/billList")
  79. public R list(
  80. @RequestParam(required=false) String zbiName,
  81. @RequestParam(required=false) String zbiNumber,
  82. @RequestParam(required=false) String payerName,
  83. @RequestParam(required=false) String payeeName,
  84. @RequestParam(required=false) String zbiType,
  85. @RequestParam(required=false) String zbiStatus,
  86. QueryRequest request) {
  87. //查询当前操作员
  88. LoginUser userInfo = tokenService.getLoginUser();
  89. SysUser user = userInfo.getSysUser();
  90. //获取企业
  91. String companyId = user.getCompanyId();
  92. Map map = new HashMap();
  93. //账款类型
  94. if("00".equals(zbiType)){
  95. map.put("payerId", companyId);
  96. }else if ("01".equals(zbiType)){
  97. map.put("payeeId", companyId);
  98. }
  99. if (!SalaryConstants.OPEX.equals(companyId)) {
  100. map.put("companyId", companyId);
  101. }
  102. //账款名称
  103. map.put("zbiName", zbiName);
  104. //账款编号
  105. map.put("zbiNumber", zbiNumber);
  106. //应付方
  107. map.put("payerName", payerName);
  108. //应收方
  109. map.put("payeeName", payeeName);
  110. //账款状态
  111. map.put("zbiStatus", zbiStatus);
  112. IPage<Map> list = iOwnBillService.selectBillInfList(map,request);
  113. return R.ok(list);
  114. }
  115. /**
  116. * 获取往来账款明细信息
  117. */
  118. @GetMapping(value = "/{zbiId}")
  119. public AjaxResult getBillInf(@PathVariable("zbiId") String zbiId) {
  120. //获取用户信息
  121. LoginUser userInfo = tokenService.getLoginUser();
  122. //企业id
  123. String companyId = userInfo.getSysUser().getCompanyId();
  124. //查询往来账款
  125. ZcBillInf zcBillInf = iZcBillInfService.getById(zbiId);
  126. Map map = new HashMap();
  127. if (zcBillInf != null) {
  128. com.huyi.service.base.entity.SysUser user = iSysUserService.getById(zcBillInf.getCreateBy());
  129. BeanMap beanMap = BeanMap.create(zcBillInf);
  130. for (Object key : beanMap.keySet()) {
  131. map.put(key+"", beanMap.get(key));
  132. }
  133. //创建人
  134. map.put("createUser",user.getNickName());
  135. }
  136. return AjaxResult.success(map);
  137. }
  138. /**
  139. * 初始化账款信息
  140. *
  141. * @param map 账款信息
  142. * @return
  143. */
  144. @Log(title = "初始化往来账款信息", businessType = BusinessType.UPDATE)
  145. @PostMapping("/add")
  146. public R add(@RequestBody Map map) throws ParseException {
  147. //获取登录用户
  148. LoginUser user = tokenService.getLoginUser();
  149. ZcBillInf zcBillInf = new ZcBillInf();
  150. //账款名称
  151. String zbiId = CommonUtil.objToString(map.get("zbiId"));
  152. //账款名称
  153. String zbiName = CommonUtil.objToString(map.get("zbiName"));
  154. zcBillInf.setZbiName(zbiName);
  155. //应付方
  156. String zbiPayerId = CommonUtil.objToString(map.get("zbiPayerId"));
  157. zcBillInf.setZbiPayerId(zbiPayerId);
  158. //应收方
  159. String zbiPayeeId = CommonUtil.objToString(map.get("zbiPayeeId"));
  160. zcBillInf.setZbiPayeeId(zbiPayeeId);
  161. //时间格式化
  162. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  163. //贸易日期
  164. String zbiDate = CommonUtil.objToString(map.get("zbiDate"));
  165. Date date = sdf.parse(zbiDate);
  166. zcBillInf.setZbiDate(date);
  167. //预计收付款日期
  168. String zbiPayDate = CommonUtil.objToString(map.get("zbiPayDate"));
  169. Date payDate = sdf.parse(zbiPayDate);
  170. zcBillInf.setZbiPayDate(payDate);
  171. //贸易金额
  172. String zbiAmount = CommonUtil.objToString(map.get("zbiAmount"));
  173. zcBillInf.setZbiAmount(zbiAmount);
  174. //合同编号
  175. String zbiContractNo = CommonUtil.objToString(map.get("zbiContractNo"));
  176. zcBillInf.setZbiContractNo(zbiContractNo);
  177. //账款服务
  178. String zbiService = CommonUtil.objToString(map.get("zbiService"));
  179. zcBillInf.setZbiService(zbiService);
  180. //配送订单
  181. String zbiOrderNo = CommonUtil.objToString(map.get("zbiOrderNo"));
  182. zcBillInf.setZbiOrderNo(zbiOrderNo);
  183. //配送企业
  184. String zbiDistributor = CommonUtil.objToString(map.get("zbiDistributor"));
  185. zcBillInf.setZbiDistributor(zbiDistributor);
  186. //备注
  187. String zbiRemark = CommonUtil.objToString(map.get("zbiRemark"));
  188. zcBillInf.setZbiRemark(zbiRemark);
  189. if(CommonUtil.isEmpty(zbiId)){
  190. //主键
  191. zbiId = IdUtils.fastSimpleUUID();
  192. zcBillInf.setZbiId(zbiId);
  193. //编号
  194. String number = "ASSET1121" + System.currentTimeMillis();
  195. zcBillInf.setZbiNumber(number);
  196. //创建人
  197. zcBillInf.setCreateBy(user.getUserid().toString());
  198. //创建时间
  199. zcBillInf.setCreateTime(DateUtils.getNowDate());
  200. iZcBillInfService.createZcBillInf(zcBillInf);
  201. }else{
  202. zcBillInf.setZbiId(zbiId);
  203. //创建人
  204. zcBillInf.setUpdateBy(user.getUserid().toString());
  205. //创建时间
  206. zcBillInf.setUpdateTime(DateUtils.getNowDate());
  207. iZcBillInfService.updateZcBillInf(zcBillInf);
  208. }
  209. Map res = new HashMap();
  210. //返回账款id
  211. res.put("zbiId", zbiId);
  212. return R.ok(res);
  213. }
  214. /**
  215. * 获取往来账款发票信息
  216. */
  217. @GetMapping(value = "getInvoice/{zbiId}")
  218. public AjaxResult getBillInvoice(@PathVariable("zbiId") String zbiId) {
  219. //获取用户信息
  220. LoginUser userInfo = tokenService.getLoginUser();
  221. //企业id
  222. String companyId = userInfo.getSysUser().getCompanyId();
  223. //查询关联往来账款的发票
  224. LambdaQueryWrapper<ZcBillInvoiceRel> lambdaQueryWrapper = new LambdaQueryWrapper<>();
  225. //往来账款id
  226. lambdaQueryWrapper.eq(ZcBillInvoiceRel::getZbirBillId,zbiId);
  227. List<ZcBillInvoiceRel> relList = iZcBillInvoiceRelService.findZcBillInvoiceRels(lambdaQueryWrapper);
  228. List<Map> list = new ArrayList<>();
  229. for (ZcBillInvoiceRel zcBillInvoiceRel : relList) {
  230. //查询发票
  231. ZcInvoiceInf zcInvoiceInf = iZcInvoiceInfService.getById(zcBillInvoiceRel.getZbirInvoiceId());
  232. Map map = new HashMap();
  233. if (zcInvoiceInf != null) {
  234. com.huyi.service.base.entity.PubFileInf pubFileInf = iPubFileInfService.getById(zcInvoiceInf.getZiiFile());
  235. BeanMap beanMap = BeanMap.create(zcInvoiceInf);
  236. for (Object key : beanMap.keySet()) {
  237. map.put(key+"", beanMap.get(key));
  238. }
  239. //文件名称
  240. map.put("name",pubFileInf.getPfiFileName());
  241. //文件url
  242. map.put("url",pubFileInf.getPfiUrl());
  243. //时间格式化
  244. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  245. String date = sdf.format(map.get("ziiDate"));
  246. map.put("ziiDate",date);
  247. }
  248. list.add(map);
  249. }
  250. return AjaxResult.success(list);
  251. }
  252. /**
  253. * 发票识别
  254. *
  255. * @param file 文件
  256. * @return
  257. */
  258. @Transactional(rollbackFor=Exception.class)
  259. @Log(title = "上传往来账款发票", businessType = BusinessType.INSERT)
  260. @PostMapping("/getInvoiceText")
  261. public R getInvoiceText(@RequestParam("file")MultipartFile file, @RequestParam("zbiId") String zbiId) {
  262. if(CommonUtil.isEmpty(zbiId)){
  263. R.fail(500,"未获取到要上传发票的账款");
  264. }
  265. //获取登录用户
  266. LoginUser user = tokenService.getLoginUser();
  267. String companyId = user.getSysUser().getCompanyId();
  268. //获取发票信息
  269. ZcInvoiceInf zcInvoiceInf = iOwnBillService.getInvoice(file);
  270. LambdaQueryWrapper<ZcInvoiceInf> queryWrapper = new LambdaQueryWrapper<>();
  271. //发票代码
  272. queryWrapper.eq(ZcInvoiceInf::getZiiNo,zcInvoiceInf.getZiiNo());
  273. //发票号码
  274. queryWrapper.eq(ZcInvoiceInf::getZiiNumber,zcInvoiceInf.getZiiNumber());
  275. //发票状态
  276. queryWrapper.eq(ZcInvoiceInf::getZiiStatus,"00");
  277. List<ZcInvoiceInf> list = iZcInvoiceInfService.findZcInvoiceInfs(queryWrapper);
  278. String id = IdUtils.fastSimpleUUID();
  279. zcInvoiceInf.setZiiId(id);
  280. zcInvoiceInf.setZiiCompanyId(companyId);
  281. zcInvoiceInf.setCreateBy(user.getUserid().toString());
  282. zcInvoiceInf.setCreateTime(DateUtils.getNowDate());
  283. //不重复则储存发票并上传
  284. if(list.size() == 0){
  285. zcInvoiceInf.setZiiCheckStt("0");
  286. }else{
  287. zcInvoiceInf.setZiiCheckStt("3");
  288. }
  289. //获取上传文件token
  290. String token = SecurityUtils.getToken(ServletUtils.getRequest());
  291. //文件传输
  292. R<PubFileInf> fileResult = remoteFileService.uploadFile(file,"01","04","00", companyId, token);
  293. zcInvoiceInf.setZiiFile(fileResult.getData().getPfiFileId());
  294. //创建发票
  295. iZcInvoiceInfService.createZcInvoiceInf(zcInvoiceInf);
  296. //创建账款发票关联
  297. ZcBillInvoiceRel zcBillInvoiceRel = new ZcBillInvoiceRel();
  298. zcBillInvoiceRel.setZbirBillId(zbiId);
  299. zcBillInvoiceRel.setZbirInvoiceId(id);
  300. iZcBillInvoiceRelService.createZcBillInvoiceRel(zcBillInvoiceRel);
  301. Map map = new HashMap();
  302. map.put("name",fileResult.getData().getPfiFileName());
  303. map.put("url",fileResult.getData().getPfiUrl());
  304. //将发票对象转换成Map集合重新组合
  305. if (zcInvoiceInf != null) {
  306. BeanMap beanMap = BeanMap.create(zcInvoiceInf);
  307. for (Object key : beanMap.keySet()) {
  308. map.put(key+"", beanMap.get(key));
  309. }
  310. //时间格式化
  311. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  312. String date = sdf.format(map.get("ziiDate"));
  313. map.put("ziiDate",date);
  314. }
  315. //返回发票信息
  316. return R.ok(map);
  317. }
  318. /**
  319. * 重新验真
  320. *
  321. * @param fileList 发票信息列表
  322. * @return
  323. */
  324. @SneakyThrows
  325. @Transactional(rollbackFor=Exception.class)
  326. @Log(title = "往来账款发票验真", businessType = BusinessType.UPDATE)
  327. @PostMapping("/invoiceVerification")
  328. public List<ZcInvoiceInf> invoiceVerification(@RequestParam(required = false,value = "fileList") String fileList) {
  329. JSONArray jsonArray = JSONArray.parseArray(fileList);
  330. //获取登录用户
  331. LoginUser user = tokenService.getLoginUser();
  332. //默认第二条
  333. int checkNum = 1;
  334. //大于3条则获取随机一条
  335. if(jsonArray.size() > 3){
  336. Random random = new Random();
  337. int num = random.nextInt(jsonArray.size());
  338. //如果不是第一条或最后一条则使用随机数
  339. if(num != 0 && num != (jsonArray.size() - 1)){
  340. checkNum = num;
  341. }
  342. }
  343. List<ZcInvoiceInf> zcInvoiceInfs = new ArrayList<>();
  344. //批量验真
  345. for (int i = 0; i < jsonArray.size(); i++){
  346. JSONObject jsonObject = jsonArray.getJSONObject(i);
  347. ZcInvoiceInf zcInvoiceInf = iZcInvoiceInfService.getById(jsonObject.getString("ziiId"));
  348. LambdaQueryWrapper<ZcInvoiceInf> queryWrapper = new LambdaQueryWrapper<>();
  349. //时间格式化
  350. SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");
  351. //发票代码
  352. String ziiNo = jsonObject.getString("ziiNo");
  353. //发票号码
  354. String ziiNumber = jsonObject.getString("ziiNumber");
  355. //发票日期
  356. String ziiDate = jsonObject.getString("ziiDate");
  357. //购方纳税人识别号
  358. String ziiPurchaserNo = jsonObject.getString("ziiPurchaserNo");
  359. //销方纳税人识别号
  360. String ziiSellerNo = jsonObject.getString("ziiSellerNo");
  361. //发票金额
  362. String ziiAmount = jsonObject.getString("ziiAmount");
  363. //价税合计
  364. String ziiTotalAmount = jsonObject.getString("ziiTotalAmount");
  365. //校验状态
  366. String ziiCheckStt = jsonObject.getString("ziiCheckStt");
  367. queryWrapper.eq(ZcInvoiceInf::getZiiNo,ziiNo);
  368. //发票号码
  369. queryWrapper.eq(ZcInvoiceInf::getZiiNumber,ziiNumber);
  370. //发票主键
  371. queryWrapper.ne(ZcInvoiceInf::getZiiId,jsonObject.getString("ziiId"));
  372. //发票状态
  373. queryWrapper.eq(ZcInvoiceInf::getZiiStatus,"00");
  374. List<ZcInvoiceInf> list = iZcInvoiceInfService.findZcInvoiceInfs(queryWrapper);
  375. //不重复则储存发票并上传
  376. if(list.size() == 0){
  377. if(i != 0 && i != (jsonArray.size() - 1) && i != checkNum){
  378. //没有验真的默认成功
  379. zcInvoiceInf.setZiiCheckStt("1");
  380. }else{
  381. //验真发票
  382. zcInvoiceInf = iOwnBillService.invoiceVerification(zcInvoiceInf);
  383. }
  384. }else{
  385. if(!"1".equals(ziiCheckStt)){
  386. zcInvoiceInf.setZiiCheckStt("3");
  387. }
  388. }
  389. zcInvoiceInf.setZiiNo(ziiNo);
  390. zcInvoiceInf.setZiiNumber(ziiNumber);
  391. zcInvoiceInf.setZiiDate(sdf.parse(ziiDate));
  392. zcInvoiceInf.setZiiPurchaserNo(ziiPurchaserNo);
  393. zcInvoiceInf.setZiiSellerNo(ziiSellerNo);
  394. zcInvoiceInf.setZiiAmount(ziiAmount);
  395. zcInvoiceInf.setZiiExcludedAmount(ziiAmount);
  396. zcInvoiceInf.setZiiTotalAmount(ziiTotalAmount);
  397. zcInvoiceInf.setUpdateBy(user.getUserid().toString());
  398. zcInvoiceInf.setUpdateTime(DateUtils.getNowDate());
  399. //修改发票信息
  400. iZcInvoiceInfService.updateZcInvoiceInf(zcInvoiceInf);
  401. zcInvoiceInfs.add(zcInvoiceInf);
  402. }
  403. return zcInvoiceInfs;
  404. }
  405. /**
  406. * 删除发票
  407. *
  408. * @param ziiIds 发票id集合
  409. * @return
  410. */
  411. @SneakyThrows
  412. @Transactional(rollbackFor=Exception.class)
  413. @Log(title = "删除往来账款发票", businessType = BusinessType.DELETE)
  414. @DeleteMapping("/{ziiIds}")
  415. public R delete(@PathVariable("ziiIds") String[] ziiIds) {
  416. //获取登录用户
  417. LoginUser user = tokenService.getLoginUser();
  418. String companyId = user.getSysUser().getCompanyId();
  419. //获取上传文件token
  420. String token = SecurityUtils.getToken(ServletUtils.getRequest());
  421. for (String ziiId : ziiIds) {
  422. ZcInvoiceInf zcInvoiceInf = iZcInvoiceInfService.getById(ziiId);
  423. zcInvoiceInf.setZiiStatus("99");
  424. //删除发票
  425. iZcInvoiceInfService.updateZcInvoiceInf(zcInvoiceInf);
  426. LambdaQueryWrapper<ZcBillInvoiceRel> queryWrapper = new LambdaQueryWrapper<>();
  427. //发票id
  428. queryWrapper.eq(ZcBillInvoiceRel::getZbirInvoiceId, ziiId);
  429. //删除发票关联
  430. iZcBillInvoiceRelService.deleteZcBillInvoiceRel(queryWrapper);
  431. //删除附件
  432. remoteFileService.delete(zcInvoiceInf.getZiiFile(), companyId, token);
  433. }
  434. return R.ok();
  435. }
  436. /**
  437. * 上传合同物流附件
  438. *
  439. * @param file 文件
  440. * @return
  441. */
  442. @Transactional(rollbackFor=Exception.class)
  443. @Log(title = "上传往来账款附件", businessType = BusinessType.INSERT)
  444. @PostMapping("/uploadBillFile")
  445. public R uploadBillFile(@RequestParam("file")MultipartFile file, @RequestParam("zbiId") String zbiId, @RequestParam("type") String type) {
  446. if(CommonUtil.isEmpty(zbiId)){
  447. R.fail(500,"未获取到要上传发票的账款");
  448. }
  449. //获取登录用户
  450. LoginUser user = tokenService.getLoginUser();
  451. String companyId = user.getSysUser().getCompanyId();
  452. //获取上传文件token
  453. String token = SecurityUtils.getToken(ServletUtils.getRequest());
  454. //文件传输
  455. R<PubFileInf> fileResult = remoteFileService.uploadFile(file,"01","04","00", companyId, token);
  456. //创建账款附件关联
  457. ZcBillFileRel zcBillFileRel = new ZcBillFileRel();
  458. zcBillFileRel.setZbfrBillId(zbiId);
  459. zcBillFileRel.setZbfrFileId(fileResult.getData().getPfiFileId());
  460. zcBillFileRel.setZbfrType(type);
  461. iZcBillFileRelService.createZcBillFileRel(zcBillFileRel);
  462. Map map = new HashMap();
  463. map.put("id",fileResult.getData().getPfiFileId());
  464. map.put("name",fileResult.getData().getPfiFileName());
  465. map.put("url",fileResult.getData().getPfiUrl());
  466. //返回附件信息
  467. return R.ok(map);
  468. }
  469. /**
  470. * 获取往来账款附件信息
  471. */
  472. @GetMapping(value = "getFile/{type}/{zbiId}")
  473. public AjaxResult getFile(@PathVariable("type") String type, @PathVariable("zbiId") String zbiId) {
  474. //获取用户信息
  475. LoginUser userInfo = tokenService.getLoginUser();
  476. //企业id
  477. String companyId = userInfo.getSysUser().getCompanyId();
  478. //查询关联往来账款的发票
  479. LambdaQueryWrapper<ZcBillFileRel> lambdaQueryWrapper = new LambdaQueryWrapper<>();
  480. //往来账款id
  481. lambdaQueryWrapper.eq(ZcBillFileRel::getZbfrBillId,zbiId);
  482. //附件类型
  483. lambdaQueryWrapper.eq(ZcBillFileRel::getZbfrType,type);
  484. List<ZcBillFileRel> relList = iZcBillFileRelService.findZcBillFileRels(lambdaQueryWrapper);
  485. List<Map> list = new ArrayList<>();
  486. for (ZcBillFileRel zcBillFileRel : relList) {
  487. //查询发票
  488. Map map = new HashMap();
  489. com.huyi.service.base.entity.PubFileInf pubFileInf = iPubFileInfService.getById(zcBillFileRel.getZbfrFileId());
  490. //文件id
  491. map.put("id",zcBillFileRel.getZbfrFileId());
  492. //文件名称
  493. map.put("name",pubFileInf.getPfiFileName());
  494. //文件url
  495. map.put("url",pubFileInf.getPfiUrl());
  496. list.add(map);
  497. }
  498. return AjaxResult.success(list);
  499. }
  500. /**
  501. * 删除附件
  502. *
  503. * @param ids 发票id集合
  504. * @return
  505. */
  506. @SneakyThrows
  507. @Transactional(rollbackFor=Exception.class)
  508. @Log(title = "删除往来账款附件", businessType = BusinessType.DELETE)
  509. @DeleteMapping("delFile/{ids}")
  510. public R delFile(@PathVariable("ids") String[] ids) {
  511. //获取登录用户
  512. LoginUser user = tokenService.getLoginUser();
  513. String companyId = user.getSysUser().getCompanyId();
  514. //获取上传文件token
  515. String token = SecurityUtils.getToken(ServletUtils.getRequest());
  516. for (String id : ids) {
  517. LambdaQueryWrapper<ZcBillFileRel> queryWrapper = new LambdaQueryWrapper<>();
  518. //附件id
  519. queryWrapper.eq(ZcBillFileRel::getZbfrFileId, id);
  520. //删除附件关联
  521. iZcBillFileRelService.deleteZcBillFileRel(queryWrapper);
  522. //删除附件
  523. remoteFileService.delete(id, companyId, token);
  524. }
  525. return R.ok();
  526. }
  527. /**
  528. * 提交账款信息
  529. *
  530. * @param zbiId 账款id
  531. * @return
  532. */
  533. @PostMapping("/commitBill/{zbiId}")
  534. @Log(title = "提交往来账款信息", businessType = BusinessType.UPDATE)
  535. public R commitBill(@PathVariable("zbiId") String zbiId) throws ParseException {
  536. //获取登录用户
  537. LoginUser user = tokenService.getLoginUser();
  538. ZcBillInf zcBillInf = new ZcBillInf();
  539. zcBillInf.setZbiId(zbiId);
  540. //创建人
  541. zcBillInf.setUpdateBy(user.getUserid().toString());
  542. //创建时间
  543. zcBillInf.setUpdateTime(DateUtils.getNowDate());
  544. //修改为正常状态
  545. zcBillInf.setZbiStatus("00");
  546. iZcBillInfService.updateZcBillInf(zcBillInf);
  547. return R.ok();
  548. }
  549. /**
  550. * 删除往来账款信息
  551. *
  552. * @param zbiIds 往来账款id集合
  553. * @return
  554. */
  555. @SneakyThrows
  556. @PreAuthorize(hasPermi = "service:bill:del")
  557. @Transactional(rollbackFor=Exception.class)
  558. @Log(title = "删除往来账款信息", businessType = BusinessType.DELETE)
  559. @DeleteMapping("deleteBill/{zbiIds}")
  560. public R deleteBill(@PathVariable("zbiIds") String[] zbiIds) {
  561. //获取登录用户
  562. LoginUser user = tokenService.getLoginUser();
  563. String companyId = user.getSysUser().getCompanyId();
  564. //获取上传文件token
  565. String token = SecurityUtils.getToken(ServletUtils.getRequest());
  566. for (String zbiId : zbiIds) {
  567. ZcBillInf zcBillInf = iZcBillInfService.getById(zbiId);
  568. zcBillInf.setZbiStatus("99");
  569. zcBillInf.setUpdateBy(user.getUserid().toString());
  570. zcBillInf.setUpdateTime(DateUtils.getNowDate());
  571. //删除往来账款
  572. iZcBillInfService.updateZcBillInf(zcBillInf);
  573. LambdaQueryWrapper<ZcBillFileRel> queryWrapper = new LambdaQueryWrapper<>();
  574. //往来账款id
  575. queryWrapper.eq(ZcBillFileRel::getZbfrBillId, zbiId);
  576. List<ZcBillFileRel> billFileRels = iZcBillFileRelService.findZcBillFileRels(queryWrapper);
  577. for (ZcBillFileRel zcBillFileRel : billFileRels) {
  578. //删除附件
  579. remoteFileService.delete(zcBillFileRel.getZbfrFileId(), companyId, token);
  580. }
  581. //删除附件关联
  582. iZcBillFileRelService.deleteZcBillFileRel(queryWrapper);
  583. LambdaQueryWrapper<ZcBillInvoiceRel> queryWrapperInvoice = new LambdaQueryWrapper<>();
  584. //往来账款id
  585. queryWrapperInvoice.eq(ZcBillInvoiceRel::getZbirBillId, zbiId);
  586. List<ZcBillInvoiceRel> billInvoiceRels = iZcBillInvoiceRelService.findZcBillInvoiceRels(queryWrapperInvoice);
  587. for (ZcBillInvoiceRel zcBillInvoiceRel : billInvoiceRels) {
  588. ZcInvoiceInf zcInvoiceInf = iZcInvoiceInfService.getById(zcBillInvoiceRel.getZbirInvoiceId());
  589. zcInvoiceInf.setZiiStatus("99");
  590. //删除发票
  591. iZcInvoiceInfService.updateZcInvoiceInf(zcInvoiceInf);
  592. //删除附件
  593. remoteFileService.delete(zcInvoiceInf.getZiiFile(), companyId, token);
  594. }
  595. //删除发票关联
  596. iZcBillInvoiceRelService.deleteZcBillInvoiceRel(queryWrapperInvoice);
  597. }
  598. return R.ok();
  599. }
  600. }