| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435 |
- package com.ydtech.modules.inv.service.impl;
- import com.alibaba.excel.util.ListUtils;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- 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.core.page.HttpResult;
- import com.ydtech.core.page.PageRequest;
- import com.ydtech.exception.SystemException;
- import com.ydtech.modules.admin.constants.BusinessTypeEnum;
- import com.ydtech.modules.inv.dao.InvAccountMapper;
- import com.ydtech.modules.inv.model.*;
- import com.ydtech.modules.inv.model.dto.InvAccountCardQueryDto;
- import com.ydtech.modules.inv.model.dto.InvAccountOpDto;
- import com.ydtech.modules.inv.model.excel.AccountExcel;
- import com.ydtech.modules.inv.model.vo.InvAccountQueryVo;
- import com.ydtech.modules.inv.service.InvAccountOpService;
- import com.ydtech.modules.inv.service.InvAccountProfitService;
- import com.ydtech.modules.inv.service.InvAccountService;
- import com.ydtech.modules.inv.utils.EasyExcelUtils;
- import com.ydtech.modules.inv.utils.LocalDateTimeUtils;
- import com.ydtech.modules.order.entity.BasePageResult;
- import org.joda.time.LocalDateTime;
- 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.math.RoundingMode;
- import java.text.DecimalFormat;
- import java.util.*;
- import java.util.stream.Collectors;
- /**
- * @author Administrator
- * @description 针对表【ins_account(账户信息表)】的数据库操作Service实现
- * @createDate 2024-01-04 18:29:20
- */
- @Service
- public class InvAccountServiceImpl extends ServiceImpl<InvAccountMapper, InvAccount>
- implements InvAccountService {
- @Autowired
- private InvAccountMapper insAccountMapper;
- @Autowired
- private InvAccountProfitService invAccountProfitService;
- @Autowired
- private InvAccountOpService invAccountOpService;
- @Value("${upload.file.path}")
- String uploadFilePath;
- /**
- * 分页查询
- *
- * @return
- */
- @Override
- public IPage<InvAccount> selectAccountsListPage(InvAccountQueryVo invAccountQueryVo) {
- PageRequest pageRequest = new PageRequest();
- pageRequest.setPageNum(invAccountQueryVo.getPageNo());
- pageRequest.setPageSize(invAccountQueryVo.getPageSize());
- invAccountQueryVo.setInvoiceTimeStart(LocalDateTimeUtils.get12MonthsBefore()); // 获取12月前月的第一天
- invAccountQueryVo.setInvoiceTimeEnd(LocalDateTimeUtils.getTodayLastDay()); //获取当前月最后一天
- List<InvAccount> invAccountIPage = insAccountMapper.selectAccountsListPage(invAccountQueryVo);
- for (InvAccount invAccount : invAccountIPage) {
- if (invAccount.getInvoicingAmountExcess() != null) {
- String invoicingAmountExcess = invAccount.getInvoicingAmountExcess();
- BigDecimal amount = new BigDecimal(invoicingAmountExcess);
- BigDecimal roundedAmount = amount.setScale(2, RoundingMode.HALF_UP);
- invAccount.setInvoicingAmountExcess(roundedAmount.toString());
- } else {
- invAccount.setInvoicingAmountExcess(null);
- }
- }
- //计算当前季度剩余300000减去
- invAccountQueryVo.setInvoiceTimeStart(LocalDateTimeUtils.quarterStartTime());
- invAccountQueryVo.setInvoiceTimeEnd(LocalDateTimeUtils.quarterEndTime());
- List<InvAccount> invAccountIPage1 = insAccountMapper.selectAccountsListPage(invAccountQueryVo);
- //将当前季度额度赋值
- List<InvAccount> collect = invAccountIPage.stream()
- .map(rel -> invAccountIPage1.stream()
- .filter(ord -> Objects.equals(rel.getAccountId(), ord.getAccountId()))
- .findFirst()
- .map(ord -> {
- if (ord.getInvoicingAmountExcess() != null) {
- rel.setQuarterAmountExcess(new BigDecimal("300000").subtract(new BigDecimal("5000000").subtract(new BigDecimal(ord.getInvoicingAmountExcess()))).toString());
- rel.setSumInvoicingAmount("0");
- } else {
- if (!rel.getBusinessQuality().equals("0")&&rel.getOuterFlag().equals("0")) {
- rel.setQuarterAmountExcess("300000");
- }
- rel.setSumInvoicingAmount("0");
- if (rel.getInvoicingAmountExcess() == null){
- rel.setInvoicingAmountExcess(rel.getInvoicingAmount());
- }
- }
- return rel;
- }).orElse(null)
- ).collect(Collectors.toList());
- //将总开票额度赋值
- List<InvAccount> sumInvoicingAmount = insAccountMapper.getSumInvoicingAmount(invAccountQueryVo);
- List<InvAccount> collect1 = collect.stream()
- .map(rel -> sumInvoicingAmount.stream()
- .filter(ord -> Objects.equals(rel.getAccountId(), ord.getAccountId()))
- .findFirst()
- .map(ord -> {
- if (ord.getSumInvoicingAmount() != null) {
- BigDecimal sumInvoicingAmountDecimal = new BigDecimal(rel.getSumInvoicingAmount()).add(new BigDecimal(ord.getSumInvoicingAmount()));
- DecimalFormat df = new DecimalFormat("0.00");
- String sumInvoicingAmountString = df.format(sumInvoicingAmountDecimal);
- rel.setSumInvoicingAmount(sumInvoicingAmountString);
- }
- return rel;
- }).orElse(null)
- ).collect(Collectors.toList());
- //本季度开票总额度和本年开票总额度
- List<InvAccountSumAmount> sumYearAmount = insAccountMapper.getYearAndQuarterAmount();
- collect1.forEach(invAccount -> {
- if (invAccount != null) {
- if (invAccount.getInvAccountCardList().size() < 2) {
- if (invAccount.getInvAccountCardList().get(0).getBankCardNum() == null) {
- invAccount.setInvAccountCardList(null);
- }
- }
- if (invAccount.getBusinessQuality().equals("3")) {
- invAccount.setQuarterAmountExcess(null);
- invAccount.setInvoicingAmountExcess(null);
- }
- }
- boolean found = false;
- for (InvAccountSumAmount yearAmount : sumYearAmount) {
- if (yearAmount.getAccountId().equals(invAccount.getAccountId())) {
- DecimalFormat df = new DecimalFormat("0.00");
- String formattedYearAmount = df.format(Double.parseDouble(yearAmount.getYearAmount()));
- String formattedQuarterAmount = df.format(Double.parseDouble(yearAmount.getQuarterAmount()));
- invAccount.setYearAmount(formattedYearAmount);
- invAccount.setQuarterAmount(formattedQuarterAmount);
- found = true;
- }
- }
- if (!found) {
- invAccount.setYearAmount("0.00");
- invAccount.setQuarterAmount("0.00");
- }
- });
- IPage ipage = PageRequest.buildPageRequest(pageRequest);
- ipage.setRecords(collect1.stream().skip((invAccountQueryVo.getPageNo() - 1) * invAccountQueryVo.getPageSize()).limit(invAccountQueryVo.getPageSize()).
- collect(Collectors.toList()));
- ipage.setTotal(collect1.size());
- return ipage;
- }
- /**
- * 根据户名分类
- *
- * @return
- */
- @Override
- public HttpResult selectByAccountName() {
- InvAccountQueryVo invAccountQueryVo = new InvAccountQueryVo();
- List<InvAccount> insAccounts = insAccountMapper.selectAccountsList(invAccountQueryVo);
- if (!insAccounts.isEmpty()) {
- insAccounts.forEach(invAccountN -> {
- if (invAccountN.getInvAccountCardList().size() < 2) {
- if (invAccountN.getInvAccountCardList().get(0).getBankCardNum() == null) {
- invAccountN.setInvAccountCardList(null);
- }
- }
- invAccountN.setBusinessQuality(BusinessTypeEnum.getBusinessType(invAccountN.getBusinessQuality()));
- });
- return HttpResult.ok("", insAccounts);
- }
- return HttpResult.error("查询错误");
- }
- @Override
- public HttpResult selectAccountExcel(InvAccountQueryVo invAccountQueryVo) {
- List<InvAccount> insAccounts = insAccountMapper.selectAccountsList(invAccountQueryVo);
- List<InvAccountProfit> invAccountProfitList = invAccountProfitService.list();
- LambdaQueryWrapper<InvAccountOp> lambdaQueryWrapper = new LambdaQueryWrapper<>();
- lambdaQueryWrapper.eq(InvAccountOp::getDelFlag,"0");
- List<InvAccountOp> list = invAccountOpService.list(lambdaQueryWrapper);
- File folder = new File(uploadFilePath);
- if (folder.exists()) {
- return HttpResult.ok("", EasyExcelUtils.noModelWrite(uploadFilePath, invAccountProfitList, insAccounts, list));
- } else {
- if (folder.mkdirs()) {
- return HttpResult.ok("", EasyExcelUtils.noModelWrite(uploadFilePath, invAccountProfitList, insAccounts, list));
- } else {
- throw new SystemException("文件导出失败");
- }
- }
- }
- @Override
- public HttpResult selectAccountList(InvAccountQueryVo invAccountQueryVo) {
- invAccountQueryVo.setInvoiceTimeStart(LocalDateTimeUtils.get12MonthsBefore()); // 获取12月前月的第一天
- invAccountQueryVo.setInvoiceTimeEnd(LocalDateTimeUtils.getTodayLastDay()); //获取当前月最后一天
- List<InvAccount> invAccountIPage = insAccountMapper.selectAccountsListPage(invAccountQueryVo);
- //计算当前季度剩余300000减去
- invAccountQueryVo.setInvoiceTimeStart(LocalDateTimeUtils.quarterStartTime());
- invAccountQueryVo.setInvoiceTimeEnd(LocalDateTimeUtils.quarterEndTime());
- List<InvAccount> invAccountIPage1 = insAccountMapper.selectAccountsListPage(invAccountQueryVo);
- //将当前季度额度赋值
- List<InvAccount> collect = invAccountIPage.stream()
- .map(rel -> invAccountIPage1.stream()
- .filter(ord -> Objects.equals(rel.getAccountId(), ord.getAccountId()))
- .findFirst()
- .map(ord -> {
- rel.setSumInvoicingAmount("0");
- if (ord.getInvoicingAmountExcess() != null) {
- rel.setQuarterAmountExcess(new BigDecimal("300000").subtract(new BigDecimal("5000000").subtract(new BigDecimal(ord.getInvoicingAmountExcess()))).toString());
- } else {
- if (!rel.getBusinessQuality().equals("0")&&rel.getOuterFlag().equals("0")) {
- rel.setQuarterAmountExcess("300000");
- }
- rel.setSumInvoicingAmount("0");
- if (rel.getInvoicingAmountExcess() == null){
- rel.setInvoicingAmountExcess(rel.getInvoicingAmount());
- }
- }
- return rel;
- }).orElse(null)
- ).collect(Collectors.toList());
- //将总开票额度赋值
- List<InvAccount> sumInvoicingAmount = insAccountMapper.getSumInvoicingAmount(invAccountQueryVo);
- List<InvAccount> collect1 = collect.stream()
- .map(rel -> sumInvoicingAmount.stream()
- .filter(ord -> Objects.equals(rel.getAccountId(), ord.getAccountId()))
- .findFirst()
- .map(ord -> {
- if (ord.getSumInvoicingAmount() != null) {
- BigDecimal sumSumInvoicingAmountDecimal = new BigDecimal(rel.getSumInvoicingAmount()).add(new BigDecimal(ord.getSumInvoicingAmount()));
- DecimalFormat df = new DecimalFormat("0.00");
- String sumQuarterAmountExcessString = df.format(sumSumInvoicingAmountDecimal);
- rel.setSumInvoicingAmount(sumQuarterAmountExcessString);
- }
- return rel;
- }).orElse(null)
- ).collect(Collectors.toList());
- collect1.forEach(invAccount -> {
- if (invAccount != null) {
- if (invAccount.getInvAccountCardList().size() < 2) {
- if (invAccount.getInvAccountCardList().get(0).getBankCardNum() == null) {
- invAccount.setInvAccountCardList(null);
- }
- }
- if (invAccount.getBusinessQuality().equals("3")) {
- invAccount.setQuarterAmountExcess(null);
- invAccount.setInvoicingAmountExcess(null);
- }
- }
- });
- List<AccountExcel> accountExcels = new ArrayList<>();
- collect1.forEach(invAccount -> {
- if (invAccount.getInvAccountCardList() != null) {
- AccountExcel accountExcel = new AccountExcel();
- accountExcel.setAccountId(invAccount.getAccountId());
- accountExcel.setAccountName(invAccount.getAccountName());
- if (invAccount.getBusinessQuality() != null) {
- if (invAccount.getBusinessQuality().equals("3")) {
- accountExcel.setBusinessQuality("一般纳税");
- } else if (invAccount.getBusinessQuality().equals("1")) {
- accountExcel.setBusinessQuality("个体户");
- } else if (invAccount.getBusinessQuality().equals("2")) {
- accountExcel.setBusinessQuality("小规模");
- }
- }
- accountExcel.setOwned(invAccount.getOwned());
- if (invAccount.getEstablishTime() != null) {
- LocalDateTime establishTime = LocalDateTime.fromDateFields(invAccount.getEstablishTime());
- accountExcel.setEstablishTime(establishTime.toString().substring(0, establishTime.toString().indexOf("T")));
- }
- List<InvAccountSumAmount> sumYearAmount = insAccountMapper.getYearAndQuarterAmount();
- boolean found = false;
- for (InvAccountSumAmount yearAmount : sumYearAmount) {
- if (yearAmount.getAccountId().equals(invAccount.getAccountId())) {
- DecimalFormat df = new DecimalFormat("0.00");
- String formattedYearAmount = df.format(Double.parseDouble(yearAmount.getYearAmount()));
- String formattedQuarterAmount = df.format(Double.parseDouble(yearAmount.getQuarterAmount()));
- accountExcel.setYearAmount(formattedYearAmount);
- accountExcel.setQuarterAmount(formattedQuarterAmount);
- found = true;
- }
- }
- if (!found) {
- accountExcel.setYearAmount("0.00");
- accountExcel.setQuarterAmount("0.00");
- }
- accountExcel.setSumInvoicingAmount(invAccount.getSumInvoicingAmount());
- accountExcel.setQuarterAmountExcess(invAccount.getQuarterAmountExcess());
- accountExcel.setInvoicingAmountExcess(invAccount.getInvoicingAmountExcess());
- accountExcel.setEstimate(invAccount.getTentativeEstimates());
- accountExcels.add(accountExcel);
- }
- });
- return HttpResult.ok("", EasyExcelUtils.downExcel(uploadFilePath, AccountExcel.class, accountExcels));
- }
- @Override
- public HttpResult look(InvAccountQueryVo invAccountQueryVo) {
- List<InvAccount> insAccounts = insAccountMapper.selectAccountsList(invAccountQueryVo);
- List<InvAccountProfit> invAccountProfitList = invAccountProfitService.list();
- LambdaQueryWrapper<InvAccountOp> queryWrapper = new LambdaQueryWrapper<InvAccountOp>();
- queryWrapper.eq(InvAccountOp::getDelFlag,"0");
- List<InvAccountOp> list = invAccountOpService.list(queryWrapper);
- List<Map<String, String>> head = head(invAccountProfitList);
- List<Map<String, String>> maps = dataList(insAccounts, list, invAccountProfitList);
- List<Map<String, String>> subList = maps.stream().skip((invAccountQueryVo.getPageNo()-1)*invAccountQueryVo.getPageSize()).limit(invAccountQueryVo.getPageSize()).
- collect(Collectors.toList());
- InvAccountOpDto invAccountOpDto = new InvAccountOpDto();
- invAccountOpDto.setHead(head);
- invAccountOpDto.setMaps(subList);
- invAccountOpDto.setTotal(maps.size());
- invAccountOpDto.setPageSize(invAccountQueryVo.getPageSize());
- invAccountOpDto.setPageNo(invAccountQueryVo.getPageNo());
- return HttpResult.ok("",invAccountOpDto);
- }
- private static List<Map<String, String>> head(List<InvAccountProfit> invAccountProfitList) {
- List<Map<String, String>> list = ListUtils.newArrayList();
- Map<String, String> mm = new HashMap<>();
- mm.put("accountXing", "账户性质");
- mm.put("accountName", "户名");
- mm.put("bank", "开户银行");
- mm.put("banlce", "银行卡余额");
- for (Map.Entry<String, String> m : mm.entrySet()) {
- Map<String, String> map = new HashMap<>();
- map.put(m.getKey(), m.getValue());
- map.put("eng",m.getKey());
- list.add(map);
- }
- invAccountProfitList.forEach(invAccountProfit -> {
- Map<String, String> map = new HashMap<>();
- map.put(invAccountProfit.getProfitEng(), invAccountProfit.getProfitName());
- map.put("eng",invAccountProfit.getProfitEng());
- list.add(map);
- });
- return list;
- }
- private static List<Map<String,String>> dataList(List<InvAccount> invAccounts, List<InvAccountOp> invAccountOpList, List<InvAccountProfit> invAccountProfitList) {
- List<Map<String,String>> map = new ArrayList<>();
- invAccounts.forEach(invAccount -> {
- invAccount.getInvAccountCardList().forEach(invAccountCard -> {
- Map<String, String> data = new HashMap<>();
- if (invAccountCard.getBankCardNum() != null) {
- data.put("accountXing",invAccount.getOuterFlag().equals("0") ? "内部账户" : "外部账户");
- data.put("accountName",invAccount.getAccountName());
- data.put("bank",invAccountCard.getBankName());
- data.put("banlce",invAccountCard.getBalance());
- invAccountProfitList.forEach(invAccountProfitList1 -> {
- String a = "0";
- for (InvAccountOp invAccountProfit : invAccountOpList) {
- if (invAccountProfitList1.getProfitEng().equals(invAccountProfit.getProfit()) && invAccountCard.getBankCardNum().equals(invAccountProfit.getCardNum())) {
- a = new BigDecimal(a).add(new BigDecimal(invAccountProfit.getMoney())).toString();
- }
- }
- data.put(invAccountProfitList1.getProfitEng(),a);
- });
- map.add(data);
- }
- });
- });
- return map;
- }
- /**
- * @version
- * @author: hxl
- * @Date: 2024/7/8 10:43
- * @Description: 通过银行卡号和户名分页查询对象
- */
- @Override
- public BasePageResult<InvAccountCard> queryPage(InvAccountCardQueryDto invAccountCardQueryDto) {
- Page<InvAccountCard> page = new Page<>(invAccountCardQueryDto.getPageNum(),
- invAccountCardQueryDto.getPageSize());
- Page<InvAccountCard> result = insAccountMapper.queryPage(page, invAccountCardQueryDto);
- return new BasePageResult<>(invAccountCardQueryDto.getPageNum(), page.getSize(), result.getTotal(), page.getPages(),
- result.getRecords());
- }
- @Override
- public List<InvAccount> getInvAccountList(InvAccountQueryVo invAccountQueryVo) {
- return baseMapper.selectAccountsListPage(invAccountQueryVo);
- }
- }
|