|
@@ -1,10 +1,29 @@
|
|
|
package com.yh.saas.plugin.yiliangyiyun.service.impl;
|
|
|
|
|
|
-import com.yh.saas.plugin.yiliangyiyun.entity.TranSettlementReport;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.alipay.sofa.runtime.api.annotation.SofaReference;
|
|
|
+import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
|
|
+import com.baomidou.mybatisplus.plugins.Page;
|
|
|
+import com.google.common.collect.Lists;
|
|
|
+import com.winsea.svc.base.base.entity.CommonRoleResource;
|
|
|
+import com.winsea.svc.base.base.service.ICommonRoleResourceService;
|
|
|
+import com.winsea.svc.base.security.entity.User;
|
|
|
+import com.winsea.svc.base.security.util.AuthSecurityUtils;
|
|
|
+import com.yh.saas.plugin.yiliangyiyun.constant.StatusEnum;
|
|
|
+import com.yh.saas.plugin.yiliangyiyun.entity.*;
|
|
|
import com.yh.saas.plugin.yiliangyiyun.mapper.TranSettlementReportMapper;
|
|
|
-import com.yh.saas.plugin.yiliangyiyun.service.ITranSettlementReportService;
|
|
|
+import com.yh.saas.plugin.yiliangyiyun.service.*;
|
|
|
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -17,4 +36,251 @@ import org.springframework.stereotype.Service;
|
|
|
@Service
|
|
|
public class TranSettlementReportServiceImpl extends ServiceImpl<TranSettlementReportMapper, TranSettlementReport> implements ITranSettlementReportService {
|
|
|
|
|
|
+// @Autowired
|
|
|
+// private INewWorkflowService workflowService;
|
|
|
+
|
|
|
+// @SofaReference
|
|
|
+// private ICommonRoleResourceService roleResourceService;
|
|
|
+ @Autowired
|
|
|
+ private IDriverPayeeInfoService driverPayeeInfoService;
|
|
|
+ @Autowired
|
|
|
+ private IDriverViewInfoService driverViewInfoService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IContractManagementInfoService contractManagementInfoService;
|
|
|
+ /**
|
|
|
+ * 汽运结算统计列表
|
|
|
+ *
|
|
|
+ * @param tranSettlementReport
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Page<TranSettlementReport> selectTranSettlementReport(TranSettlementReport tranSettlementReport) {
|
|
|
+ Map<String, Object> pageView = new HashMap<>();
|
|
|
+ pageView.put("startRecord", (tranSettlementReport.getCurrentPage() - 1)
|
|
|
+ * tranSettlementReport.getPageSize());
|
|
|
+// List<String> businessKeys = null;
|
|
|
+// if("1".equals(tranSettlementReport.getSearchType())){
|
|
|
+// businessKeys = workflowService.getTaskBusinessKeysByCode("PROCUREMENT-CLOSE-REPORT");
|
|
|
+// }
|
|
|
+// List<String> statusSet = new ArrayList<>();
|
|
|
+// List<String> resourceIdList = this.getResourceIdList();
|
|
|
+// if (resourceIdList.contains("procurementCloseReport-Edit")) { // 填写,提交 权限做完以后替换
|
|
|
+// List<String> statusList = Lists.newArrayList(StatusEnum.PUR_RETURN.getFlag());
|
|
|
+// statusSet.addAll(statusList);
|
|
|
+// }
|
|
|
+
|
|
|
+ //公司id
|
|
|
+ pageView.put("compId", tranSettlementReport.getCompId());
|
|
|
+ pageView.put("searchKeyWord", tranSettlementReport.getSearchKeyWord());
|
|
|
+ pageView.put("searchType", tranSettlementReport.getSearchType());
|
|
|
+ pageView.put("pageSize", tranSettlementReport.getPageSize());
|
|
|
+ pageView.put("currentPage", tranSettlementReport.getCurrentPage());
|
|
|
+ pageView.put("contractNo", tranSettlementReport.getContractNo());
|
|
|
+// pageView.put("roleFlag", tranSettlementReport.getRoleFlag());
|
|
|
+ pageView.put("statusFlag", tranSettlementReport.getStatusFlag());
|
|
|
+// pageView.put("businessKeys", businessKeys);
|
|
|
+// pageView.put("statusSet", statusSet);
|
|
|
+
|
|
|
+
|
|
|
+ // 查询采购订单总数
|
|
|
+ Integer dataCount = baseMapper.getCountByCondition(pageView);
|
|
|
+ List<TranSettlementReport> dataList = baseMapper.getListByCondition(pageView);
|
|
|
+
|
|
|
+ if (!CollectionUtils.isEmpty(dataList)) {
|
|
|
+ for (TranSettlementReport tranSettlementReport1 : dataList) {
|
|
|
+ //查询账户信息
|
|
|
+ List<DriverViewInfo> driverViewInfoList = driverViewInfoService.selectList(new EntityWrapper<DriverViewInfo>()
|
|
|
+ .eq("driver_name", tranSettlementReport1.getName())
|
|
|
+ .eq("delete_flag", "0"));
|
|
|
+ if (!CollectionUtils.isEmpty(driverViewInfoList)){
|
|
|
+ for (DriverViewInfo driverViewInfo:driverViewInfoList){
|
|
|
+ List<DriverPayeeInfo> driverPayeeInfoList=driverPayeeInfoService.selectList(new EntityWrapper<DriverPayeeInfo>()
|
|
|
+ .eq("driver_id", driverViewInfo.getId())
|
|
|
+ .eq("delete_flag", "0"));
|
|
|
+ tranSettlementReport1.setDriverPayeeInfoList(driverPayeeInfoList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //损耗
|
|
|
+ if(tranSettlementReport1.getUnloadingWeight() != null){
|
|
|
+ tranSettlementReport1.setLossWeight(tranSettlementReport1.getLoadingWeight() - tranSettlementReport1.getUnloadingWeight());
|
|
|
+ }
|
|
|
+ //扣款
|
|
|
+ if(tranSettlementReport1.getLossWeight() <= (tranSettlementReport1.getLoadingWeight()/1000)){
|
|
|
+ tranSettlementReport1.setDeductionAmount("0");
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ tranSettlementReport1.setDeductionAmount(String.valueOf((Float.valueOf(tranSettlementReport1.getLossWeight()) - (tranSettlementReport1.getLoadingWeight()/1000)) * tranSettlementReport1.getTransportPrice()));
|
|
|
+ }
|
|
|
+ //结算重量
|
|
|
+ if ("0".equals(tranSettlementReport1.getManualFlag())){
|
|
|
+ //卸车为空时,结算重量=装车重量
|
|
|
+ if (tranSettlementReport1.getUnloadingWeight() == null){
|
|
|
+ tranSettlementReport1.setSettlementWeight(tranSettlementReport1.getLoadingWeight());
|
|
|
+ }
|
|
|
+ //卸车不为空时,结算重量=装卸取小
|
|
|
+ else {
|
|
|
+ tranSettlementReport1.setSettlementWeight(tranSettlementReport1.getLoadingWeight() > tranSettlementReport1.getUnloadingWeight() ? tranSettlementReport1.getUnloadingWeight() : tranSettlementReport1.getLoadingWeight());
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //应付金额
|
|
|
+ //已付金额
|
|
|
+ //未付金额
|
|
|
+ }
|
|
|
+// String taskId = "";
|
|
|
+// // 只有待审核状态才有taskId
|
|
|
+// if (StringUtils.isNotBlank(tranSettlementReport1.getWorkflowId())) {
|
|
|
+// JSONObject jsonObject = workflowService.getActiveTask(Lists.newArrayList(tranSettlementReport1.getWorkflowId()), tranSettlementReport1.getId());
|
|
|
+// taskId = jsonObject.getString("taskId");
|
|
|
+// tranSettlementReport1.setTaskId(taskId);
|
|
|
+// }
|
|
|
+// }
|
|
|
+ }
|
|
|
+ Page<TranSettlementReport> page = new Page<>();
|
|
|
+ page.setRecords(dataList == null ? Lists.newArrayList() : dataList);
|
|
|
+ page.setTotal(dataCount == null ? 0 : dataCount);
|
|
|
+ page.setCurrent(tranSettlementReport.getCurrentPage());
|
|
|
+ page.setSize(tranSettlementReport.getPageSize());
|
|
|
+ return page;
|
|
|
+ }
|
|
|
+// private List<String> getResourceIdList() {
|
|
|
+// User currentUser = AuthSecurityUtils.getCurrentUserInfo();
|
|
|
+// // 当前登录人主要角色
|
|
|
+// return roleResourceService.getBindResourcesByUserId(currentUser.getUserId()).stream()
|
|
|
+// .map(CommonRoleResource::getResourceId).collect(Collectors.toList());
|
|
|
+//
|
|
|
+// }
|
|
|
+ /**
|
|
|
+ * 修改结算重量0修改扣款1修改已开发票2
|
|
|
+ * @param tranSettlementReport
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public String editTranSettlementReport(TranSettlementReport tranSettlementReport) {
|
|
|
+ //查询汽运结算信息
|
|
|
+ TranSettlementReport tranSettlementReport1 = this.selectById(tranSettlementReport.getId());
|
|
|
+ if (tranSettlementReport1 != null ){
|
|
|
+ //0 修改结算重量
|
|
|
+ if(tranSettlementReport.getFlag()==0) {
|
|
|
+ tranSettlementReport1.setSettlementWeight(tranSettlementReport.getSettlementWeight());
|
|
|
+ tranSettlementReport1.setManualFlag("1");
|
|
|
+ //更改汽运结算信息
|
|
|
+ this.updateById(tranSettlementReport1);
|
|
|
+ return "OK";
|
|
|
+ }
|
|
|
+ //1 修改扣款
|
|
|
+ else if(tranSettlementReport.getFlag()==1){
|
|
|
+ tranSettlementReport1.setDeductionAmount(tranSettlementReport.getDeductionAmount());
|
|
|
+ //更改汽运结算信息
|
|
|
+ this.updateById(tranSettlementReport1);
|
|
|
+ return "OK";
|
|
|
+ }
|
|
|
+ //2 修改已开发票
|
|
|
+ else {
|
|
|
+ tranSettlementReport1.setAlreadyInvoice(tranSettlementReport1.getAlreadyInvoice() + tranSettlementReport.getAlreadyInvoice());
|
|
|
+ //更改汽运结算信息
|
|
|
+ this.updateById(tranSettlementReport1);
|
|
|
+ return "OK";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return "NG";
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 合同编号下拉列表
|
|
|
+ * @param compId
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<ContractManagementInfo> selectContractNoList(String compId) {
|
|
|
+ //查我方承运的合同
|
|
|
+ List<ContractManagementInfo> contractManagementInfoList = contractManagementInfoService.selectList(new EntityWrapper<ContractManagementInfo>()
|
|
|
+ .eq("comp_id", compId)
|
|
|
+ .eq("deliver_type", "1")
|
|
|
+ .eq("delete_flag", "0")
|
|
|
+ .orderBy("update_date", false));
|
|
|
+ for(ContractManagementInfo contractManagementInfo: contractManagementInfoList){
|
|
|
+ Float money=0.0f;
|
|
|
+ //查汽运结算报表
|
|
|
+ List<TranSettlementReport> tranSettlementReportList = this.selectList(new EntityWrapper<TranSettlementReport>()
|
|
|
+ .eq("contract_no", contractManagementInfo.getContractNo())
|
|
|
+ .eq("delete_flag", "0"));
|
|
|
+ if (!CollectionUtils.isEmpty(tranSettlementReportList)){
|
|
|
+ for (TranSettlementReport tranSettlementReport:tranSettlementReportList){
|
|
|
+ money=money+tranSettlementReport.getAmountNotPayable();
|
|
|
+ }
|
|
|
+ //有未付金额
|
|
|
+ if (money > 0) {
|
|
|
+ contractManagementInfo.setReportStatus("待结算");
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ contractManagementInfo.setReportStatus("已结算");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return contractManagementInfoList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 出纳付款
|
|
|
+ *
|
|
|
+ * @param tranSettlementReport
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public String payMoney(TranSettlementReport tranSettlementReport) {
|
|
|
+ List<TranSettlementReport> tranSettlementReportList = tranSettlementReport.getTranSettlementReportList();
|
|
|
+ Float money = tranSettlementReport.getMoney();
|
|
|
+ //付款多条
|
|
|
+ if (!CollectionUtils.isEmpty(tranSettlementReportList)) {
|
|
|
+ for (TranSettlementReport tranSettlementReport1 : tranSettlementReportList) {
|
|
|
+ TranSettlementReport tranSettlementReport2 = this.selectById(tranSettlementReport1.getId());
|
|
|
+ //付款金额大于本次循环未付金额
|
|
|
+ if (money >= tranSettlementReport1.getAmountNotPayable()) {
|
|
|
+ money = money - tranSettlementReport1.getAmountNotPayable();
|
|
|
+ //全部付款
|
|
|
+ tranSettlementReport1.setStatus(StatusEnum.PUR_PAYaLL.getName());
|
|
|
+ tranSettlementReport1.setStatusFlag(StatusEnum.PUR_PAYaLL.getFlag());
|
|
|
+ tranSettlementReport1.setPaymentDate(tranSettlementReport.getPaymentDate());
|
|
|
+ tranSettlementReport1.setPaymentScreenshot(tranSettlementReport2.getPaymentScreenshot() != null ? tranSettlementReport2.getPaymentScreenshot() + '$' + tranSettlementReport.getPaymentScreenshot() : tranSettlementReport.getPaymentScreenshot());
|
|
|
+ tranSettlementReport1.setAmountEdPayable(tranSettlementReport1.getAmountEdPayable() + tranSettlementReport1.getAmountNotPayable());
|
|
|
+ tranSettlementReport1.setAmountNotPayable(0.0f);
|
|
|
+ this.updateById(tranSettlementReport1);
|
|
|
+ } else if (money > 0) {
|
|
|
+ Float moneyTmp = money - tranSettlementReport1.getAmountNotPayable();
|
|
|
+ //部分付款
|
|
|
+ tranSettlementReport1.setStatus(StatusEnum.PUR_PAY.getName());
|
|
|
+ tranSettlementReport1.setStatusFlag(StatusEnum.PUR_PAY.getFlag());
|
|
|
+ tranSettlementReport1.setPaymentDate(tranSettlementReport.getPaymentDate());
|
|
|
+ tranSettlementReport1.setPaymentScreenshot(tranSettlementReport2.getPaymentScreenshot() != null ? tranSettlementReport2.getPaymentScreenshot() + '$' + tranSettlementReport.getPaymentScreenshot() : tranSettlementReport.getPaymentScreenshot());
|
|
|
+ tranSettlementReport1.setAmountEdPayable(tranSettlementReport1.getAmountEdPayable() + money);
|
|
|
+ tranSettlementReport1.setAmountNotPayable(tranSettlementReport1.getAmountNotPayable() - money);
|
|
|
+ this.updateById(tranSettlementReport1);
|
|
|
+ money = moneyTmp;
|
|
|
+ } else {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return "ok";
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 批量开发票
|
|
|
+ *
|
|
|
+ * @param tranSettlementReport
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public String openInvoiceList(TranSettlementReport tranSettlementReport) {
|
|
|
+ List<TranSettlementReport> tranSettlementReportList = tranSettlementReport.getTranSettlementReportList();
|
|
|
+ //批量
|
|
|
+ if (!CollectionUtils.isEmpty(tranSettlementReportList)) {
|
|
|
+ for (TranSettlementReport tranSettlementReport1 : tranSettlementReportList) {
|
|
|
+ //已开发票金额等于已付金额
|
|
|
+ tranSettlementReport1.setAlreadyInvoice(tranSettlementReport1.getAmountEdPayable());
|
|
|
+ this.updateById(tranSettlementReport1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return "ok";
|
|
|
+ }
|
|
|
+
|
|
|
}
|