| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298 |
- package com.ydtech.modules.inv.service.impl;
- import cn.hutool.extra.spring.SpringUtil;
- import com.alibaba.fastjson.JSONObject;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
- import com.baomidou.mybatisplus.core.metadata.IPage;
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
- import com.ydtech.constants.enums.inv.InvPayMethodEnum;
- import com.ydtech.core.page.HttpResult;
- import com.ydtech.core.page.PageRequest;
- import com.ydtech.exception.SystemException;
- import com.ydtech.modules.base.controller.BaseController;
- import com.ydtech.modules.inv.dao.InvAccountOperateMapper;
- import com.ydtech.modules.inv.model.*;
- import com.ydtech.modules.inv.service.*;
- import com.ydtech.modules.inv.utils.EasyExcelUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.stereotype.Service;
- import java.io.File;
- import java.math.BigDecimal;
- import java.text.ParseException;
- import java.text.SimpleDateFormat;
- import java.time.LocalDateTime;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.List;
- import java.util.Map;
- import java.util.stream.Collectors;
- import static com.ydtech.modules.inv.utils.TransferUtils.*;
- /**
- * @author Administrator
- * @description 针对表【ins_account_operate(账户操作记录表)】的数据库操作Service实现
- * @createDate 2024-01-04 18:29:20
- */
- @Service
- public class InvAccountOperateServiceImpl extends ServiceImpl<InvAccountOperateMapper, InvAccountOperate>
- implements InvAccountOperateService {
- @Autowired
- private InvAccountOperateMapper invAccountOperateMapper;
- @Autowired
- private InvAccountOpService invAccountOpService;
- @Autowired
- private InvAccountCardService invAccountCardService;
- @Autowired
- private InvAccountService invAccountService;
- @Autowired
- private InvAccountExcelService invAccountExcelService;
- @Autowired
- private InvAccountProfitService invAccountProfitService;
- @Autowired
- private InvAccountIncoiceService invAccountIncoiceService;
- @Value("${upload.file.path}")
- String uploadFilePath;
- /**
- * 查询操作列表
- *
- * @param accountOperate
- * @return
- */
- @Override
- public IPage<InvAccountOperate> selectList(InvAccountOperate accountOperate) throws ParseException {
- PageRequest pageRequest = new PageRequest();
- pageRequest.setPageNum(accountOperate.getPageNo());
- pageRequest.setPageSize(accountOperate.getPageSize());
- Page page = PageRequest.buildPageRequest(pageRequest);
- IPage<InvAccountOperate> invAccountOperateIPage = invAccountOperateMapper.selectInsAccountOperate(page, accountOperate);
- List<InvAccountOperate> records = invAccountOperateIPage.getRecords();
- for (InvAccountOperate record : records) {
- String createTime = record.getCreateTime();
- SimpleDateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- SimpleDateFormat outputFormat = new SimpleDateFormat("yyyy-MM-dd");
- String outputDate = outputFormat.format(inputFormat.parse(createTime));
- record.setCreateTime(outputDate);
- StringBuilder a = new StringBuilder();
- if (record.getPayMethod() != null) {
- String[] split = record.getPayMethod().split(",");
- for (int i = 0; i < split.length; i++) {
- a.append(InvPayMethodEnum.getNameByCode(split[i]));
- if (i < split.length - 1) {
- a.append(",");
- }
- }
- record.setPayMethod(a.toString());
- }
- }
- invAccountOperateIPage.setRecords(records);
- return invAccountOperateIPage;
- }
- /**
- * 外部转内部
- *
- * @param invAccountOperate
- * @return
- */
- @Override
- public HttpResult insert(InvAccountOperate invAccountOperate) {
- InvAccountCard entAccountCard = invAccountCardService.getById(invAccountOperate.getEnterCardId());
- InvAccountCard outAccountCard = invAccountCardService.getById(invAccountOperate.getOutCardId());
- InvAccount entAccount = invAccountService.getById(entAccountCard.getAccountId());
- InvAccount outAccount = invAccountService.getById(outAccountCard.getAccountId());
- String applyAmount = invAccountOperate.getApplyAmount();
- JSONObject outProfit = invAccountOperate.getOutProfit();
- JSONObject entProfit = invAccountOperate.getEntProfit();
- if (entAccount.getOuterFlag().equals("1")) {
- return HttpResult.error("此操作收入账户不可为外部账户");
- }
- if (entAccountCard.equals(outAccountCard)) {
- for (Map.Entry<String, Object> entry : outProfit.entrySet()) {
- for (Map.Entry<String, Object> entry2 : entProfit.entrySet()) {
- if (new BigDecimal(entry.getValue().toString()).compareTo(BigDecimal.ZERO) != 0 && new BigDecimal(entry2.getValue().toString()).compareTo(BigDecimal.ZERO) != 0) {
- if (entry.getKey().equals(entry2.getKey())) {
- throw new SystemException("无法向同公司同板块互相转账");
- }
- }
- }
- }
- }
- if (entAccount.getOuterFlag().equals("0") && !entAccountCard.getAccountId().equals(outAccountCard.getAccountId())) {
- InvAccountCard invAccount = outsideTransfer(outAccountCard, outAccount, entAccountCard, entAccount, applyAmount);
- invAccountCardService.updateById(invAccount);
- BaseController baseController = new BaseController();
- invAccountOperate.setCreateTime(LocalDateTime.now().toString());
- invAccountOperate.setOutProfit(null);
- invAccountOperate.setEnterCardNum(entAccountCard.getBankCardNum());
- invAccountOperate.setCreateBy(baseController.getUserName());
- invAccountOperate.setCreateId(baseController.getUserId());
- invAccountOperateMapper.insert(invAccountOperate);
- }
- List<InvAccountOp> list = invAccountEntOpList(entProfit, entAccount, entAccountCard,invAccountOperate.getAccountOperateId());
- if (!entAccountCard.getAccountId().equals(outAccountCard.getAccountId())){
- list.forEach(invAccountOp -> {
- invAccountOp.setInvoiceId(invAccountOperate.getAccountOperateId());
- });
- }else {
- List<InvAccountOp> list1 = invAccountOutOpList(outProfit, outAccount, outAccountCard, invAccountOperate.getAccountOperateId());
- list.forEach(invAccountOp -> {
- invAccountOp.setInvoiceId(invAccountOperate.getAccountOperateId());
- });
- list1.forEach(invAccountOp -> {
- invAccountOp.setInvoiceId(invAccountOperate.getAccountOperateId());
- });
- list.addAll(list1);
- }
- invAccountOpService.saveBatch(list);
- return HttpResult.ok("新增收入成功");
- }
- @Override
- public int updateOperateByIncoiceId(InvAccountOperate invAccountIncoiceId) {
- return invAccountOperateMapper.updateOperateByIncoiceId(invAccountIncoiceId);
- }
- @Override
- public HttpResult excelAccount(InvAccountOperate accountOperate) {
- List<InvAccountOperate> invAccountOperates = invAccountOperateMapper.selectInsAccountOperateList(accountOperate);
- List<InvAccountProfit> list = invAccountProfitService.list();
- for (InvAccountOperate record : invAccountOperates) {
- StringBuilder a = new StringBuilder();
- if (record.getPayMethod() != null) {
- String[] split = record.getPayMethod().split(",");
- for (String i : split) {
- a.append(InvPayMethodEnum.getNameByCode(i)).append(",");
- }
- record.setPayMethod(a.toString());
- }
- if (record.getOutProfit() != null) {
- StringBuffer buffer = new StringBuffer();
- for (Map.Entry<String, Object> entry : record.getOutProfit().entrySet()) {
- list.forEach(invAccountProfit -> {
- if (invAccountProfit.getProfitEng().equals(entry.getKey())) {
- buffer.append(invAccountProfit.getProfitName()).append(" ");
- }
- });
- }
- record.setPlate(buffer.toString());
- }
- }
- File folder = new File(uploadFilePath);
- if (folder.exists()) {
- return HttpResult.ok("", EasyExcelUtils.noModelOperateWrite(uploadFilePath, list, invAccountOperates));
- } else {
- if (folder.mkdirs()) {
- return HttpResult.ok("", EasyExcelUtils.noModelOperateWrite(uploadFilePath, list, invAccountOperates));
- } else {
- throw new SystemException("文件导出失败");
- }
- }
- }
- @Override
- public HttpResult deleteById(String accountOperateId) {
- InvAccountOperate invAccountOperate = invAccountOperateMapper.selectById(accountOperateId);
- if (invAccountOperate == null) {
- throw new SystemException("操作为空无法删除");
- }
- List<InvAccountOperate> invAccountOperates = new ArrayList<>();
- if (invAccountOperate.getDel() != null) {
- LambdaQueryWrapper<InvAccountOperate> queryWrapper = new LambdaQueryWrapper<InvAccountOperate>();
- queryWrapper.eq(InvAccountOperate::getDel, invAccountOperate.getDel());
- invAccountOperates = invAccountOperateMapper.selectList(queryWrapper);
- }
- if (invAccountOperates.isEmpty()){
- invAccountOperates.add(invAccountOperate);
- }
- if (invAccountOperate.getRevenueOutlay().equals("0")) {
- String outCardNum = invAccountOperate.getOutCardNum();
- String enterCardNum = invAccountOperate.getEnterCardNum();
- InvAccountCard outAccountCard = invAccountCardService.getById(outCardNum);
- InvAccountCard entAccountCard = invAccountCardService.getById(enterCardNum);
- InvAccount entAccount = invAccountService.getById(entAccountCard.getAccountId());
- List<InvAccountCard> invAccountCards = quashOutsideTransfer(outAccountCard, entAccountCard, new BigDecimal(invAccountOperate.getApplyAmount()),entAccount);
- List<String> accountOperateIds = invAccountOperates.stream()
- .map(InvAccountOperate::getAccountOperateId)
- .distinct()
- .collect(Collectors.toList());
- BaseController baseController = new BaseController();
- invAccountOperates.forEach(invAccountOperate1 -> {
- invAccountOperate1.setUpdateBy(baseController.getUserName());
- invAccountOperate1.setUpdateId(baseController.getUserId());
- invAccountOperate1.setUpdateTime(LocalDateTime.now());
- invAccountOperate1.setDelFlag("1");
- });
- LambdaUpdateWrapper<InvAccountOp> lambdaUpdateWrapper = new LambdaUpdateWrapper<InvAccountOp>();
- lambdaUpdateWrapper.in(InvAccountOp::getAccountOperateId, accountOperateIds);
- lambdaUpdateWrapper.set(InvAccountOp::getDelFlag,"1");
- if(invAccountOperate.getInvoiceId() != null){
- InvAccountIncoice byId = invAccountIncoiceService.getById(invAccountOperate.getInvoiceId());
- if (new BigDecimal(byId.getPayoutMoney()).compareTo(new BigDecimal(invAccountOperate.getApplyAmount())) < 0){
- throw new SystemException("撤销金额大于已进账金额");
- }
- byId.setPayoutMoney(new BigDecimal(byId.getPayoutMoney()).subtract(new BigDecimal(invAccountOperate.getApplyAmount())).toString());
- byId.setNotPayoutMoney(new BigDecimal(byId.getNotPayoutMoney()).add(new BigDecimal(invAccountOperate.getApplyAmount())).toString());
- byId.setClearFlag("0");
- invAccountIncoiceService.updateById(byId);
- }
- if (invAccountOperate.getExcelAccountOperateId() != null){
- InvAccountExcel invAccountExcel = invAccountExcelService.getById(invAccountOperate.getExcelAccountOperateId());
- invAccountExcel.setExcelAccountOperateId(invAccountOperate.getExcelAccountOperateId());
- invAccountExcel.setUpdateBy(baseController.getUserName());
- invAccountExcel.setUpdateTime(new Date());
- invAccountExcel.setPayoutAmount(String.valueOf(Integer.parseInt(invAccountExcel.getPayoutAmount()) - Integer.parseInt(invAccountOperate.getApplyAmount())));
- invAccountExcel.setTransferFlag("1");
- invAccountExcelService.updateById(invAccountExcel);
- }
- invAccountOpService.update(lambdaUpdateWrapper);
- invAccountCardService.updateBatchById(invAccountCards);
- InvAccountOperateService invAccountOperateService = new InvAccountOperateServiceImpl();
- invAccountOperateService.updateBatchById(invAccountOperates);
- return HttpResult.ok("删除成功");
- } else {
- return HttpResult.error("此操作为收入账户,无法删除");
- }
- }
- }
|