StatisticsFinancePageselectServiceImpl.java 8.47 KB
package com.lhcredit.project.business.statisticsFinancePageselect.service;

import java.util.*;

import com.alibaba.fastjson.JSONObject;
import com.lhcredit.project.business.apiFinance.domain.ApiFinance;
import com.lhcredit.project.business.apiFinance.service.IApiFinanceService;
import com.lhcredit.project.business.bCreditReport.domain.BCreditReport;
import com.lhcredit.project.business.bCreditReport.service.IBCreditReportService;
import com.lhcredit.project.business.frontDept.domain.FrontDept;
import com.lhcredit.project.business.frontDept.service.IFrontDeptService;
import com.lhcredit.project.business.frontUser.service.IFrontUserService;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service;
import com.lhcredit.project.business.statisticsFinancePageselect.mapper.StatisticsFinancePageselectMapper;
import com.lhcredit.project.business.statisticsFinancePageselect.domain.StatisticsFinancePageselect;
import com.lhcredit.common.utils.text.Convert;

import javax.annotation.Resource;

/**
 * 前台财务调用统计 服务层实现
 *
 * @author lhcredit
 * @date 2025-03-03
 */
@Service
public class StatisticsFinancePageselectServiceImpl implements IStatisticsFinancePageselectService {

    @Resource
    private StatisticsFinancePageselectMapper statisticsFinancePageselectMapper;
    @Resource
    private IFrontUserService userService;
    @Resource
    private IFrontDeptService deptService;
    @Resource
    private IApiFinanceService apiFinanceService;
    @Resource
    private IBCreditReportService bCreditReportService;

    /**
     * 查询前台财务调用统计信息
     *
     * @param id 前台财务调用统计ID
     * @return 前台财务调用统计信息
     */
    @Override
    public StatisticsFinancePageselect selectStatisticsFinancePageselectById(Integer id) {
        return statisticsFinancePageselectMapper.selectStatisticsFinancePageselectById(id);
    }

    /**
     * 查询前台财务调用统计列表
     *
     * @param statisticsFinancePageselect 前台财务调用统计信息
     * @return 前台财务调用统计集合
     */
    @Override
    public List<StatisticsFinancePageselect> selectStatisticsFinancePageselectList(StatisticsFinancePageselect statisticsFinancePageselect) {
        return statisticsFinancePageselectMapper.selectStatisticsFinancePageselectList(statisticsFinancePageselect);
    }



    /**
     * 字段转换
     * @param statisticsFinancePageselect 前台财务调用统计信息
     * @return 前台财务调用统计信息
     */
    @Override
    public StatisticsFinancePageselect changeModel(StatisticsFinancePageselect statisticsFinancePageselect) {
//        //这里写各字段转换逻辑
        if(statisticsFinancePageselect!=null){
//            if(null!=(statisticsFinancePageselect.getUserId())){
//                FrontUser frontUser = userService.selectFrontUserById(statisticsFinancePageselect.getUserId());
//                statisticsFinancePageselect.setUserName(frontUser.getUserName());
//            }
//            if(null!=(statisticsFinancePageselect.getOrgId())){
//                String allDeptNameForAdmin = deptService.getAllDeptNameForAdmin(statisticsFinancePageselect.getOrgId());
//                statisticsFinancePageselect.setCreateBy(allDeptNameForAdmin);
//            }
        }
        return statisticsFinancePageselect;
    }

    /**
     * 列表转换
     *
     * @param statisticsFinancePageselectList 前台财务调用统计集合
     * @return 前台财务调用统计集合
     */
    @Override
    public List<StatisticsFinancePageselect> changeModel(List<StatisticsFinancePageselect> statisticsFinancePageselectList) {
        List<StatisticsFinancePageselect> result = new ArrayList<StatisticsFinancePageselect>();
        if (statisticsFinancePageselectList.size() > 0) {
            for (StatisticsFinancePageselect statisticsFinancePageselect:statisticsFinancePageselectList){
                result.add(changeModel(statisticsFinancePageselect));
            }
        }
        return result;
    }

    /**
     * 新增前台财务调用统计
     *
     * @param statisticsFinancePageselect 前台财务调用统计信息
     * @return 结果
     */
    @Override
    public int insertStatisticsFinancePageselect(StatisticsFinancePageselect statisticsFinancePageselect) {
        return statisticsFinancePageselectMapper.insertStatisticsFinancePageselect(statisticsFinancePageselect);
    }

    /**
     * 修改前台财务调用统计
     *
     * @param statisticsFinancePageselect 前台财务调用统计信息
     * @return 结果
     */
    @Override
    public int updateStatisticsFinancePageselect(StatisticsFinancePageselect statisticsFinancePageselect) {
        return statisticsFinancePageselectMapper.updateStatisticsFinancePageselect(statisticsFinancePageselect);
    }

    /**
     * 删除前台财务调用统计对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteStatisticsFinancePageselectByIds(String ids) {
        return statisticsFinancePageselectMapper.deleteStatisticsFinancePageselectByIds(Convert.toStrArray(ids));
    }

    @Override
    public Integer selectCountByOrgId(String headId) {
        return statisticsFinancePageselectMapper.selectCountByOrgId(headId);
    }

    @Override
    public List<Object> selectCountByFinanceStatistics(Long orgId, String name) {
        return statisticsFinancePageselectMapper.selectCountByFinanceStatistics(orgId,name);
    }

    @Override
    public List<StatisticsFinancePageselect> getOrder(StatisticsFinancePageselect statisticsFinancePageselect) {
        Long contractId = statisticsFinancePageselect.getParams().getLong("contractId");

        if (Objects.nonNull(contractId)){
            FrontDept frontDept = new FrontDept();
            frontDept.setContractNum(contractId);
            frontDept.setContractType("1");

            FrontDept firstDept = Optional.ofNullable(deptService.selectFrontDeptList(frontDept))
                    .filter(depts -> !depts.isEmpty())
                    .map(depts -> depts.get(0))
                    .orElse(null);
            if (Objects.nonNull(firstDept)){
                Long orgId = firstDept.getId();
                statisticsFinancePageselect.setOrgId(orgId);
            }
        }
        List<StatisticsFinancePageselect> statisticsFinancePageselects = statisticsFinancePageselectMapper.selectStatisticsFinancePageselectList(statisticsFinancePageselect);

        if (CollectionUtils.isEmpty(statisticsFinancePageselects)){
            return new ArrayList<>();
        }
        statisticsFinancePageselects.forEach(statistics -> {
            FrontDept frontDept = deptService.selectFrontDeptById(statistics.getOrgId());
            statistics.setDeptName(frontDept.getDeptName());
        });
        return statisticsFinancePageselects;
    }

    @Override
    public Integer updateStatus(String requestJson) {
        JSONObject jsonObject = JSONObject.parseObject(requestJson);
        List idList = jsonObject.getObject("idList", List.class);
        if (CollectionUtils.isNotEmpty(idList)){

            idList.forEach(id -> { //修改对账状态  type=1 信用报告数据 type=2 财务信息数据 type=3 税务信息数据
                if (jsonObject.get("type").equals("1")){
                    BCreditReport bCreditReport = new BCreditReport();
                    bCreditReport.setId(id.toString());
                    bCreditReport.setReconciliation(jsonObject.getString("reconciliation"));
                    bCreditReportService.updateBCreditReport(bCreditReport);
                }
                if (jsonObject.get("type").equals("2")){
                    StatisticsFinancePageselect statisticsFinancePageselect = new StatisticsFinancePageselect();
                    statisticsFinancePageselect.setId(Integer.valueOf(id.toString()));
                    statisticsFinancePageselect.setReconciliation(jsonObject.getString("reconciliation"));
                    statisticsFinancePageselectMapper.updateStatisticsFinancePageselect(statisticsFinancePageselect);
                }
                if (jsonObject.get("type").equals("3")){
                    ApiFinance apiFinance = new ApiFinance();
                    apiFinance.setId(Integer.valueOf(id.toString()));
                    apiFinance.setReconciliation(jsonObject.getString("reconciliation"));
                    apiFinanceService.updateApiFinance(apiFinance);
                }
            });

            return 1;
        }
        return 0;
    }
}