FengChaoYu il y a 9 mois
Parent
commit
a9f52da14a

+ 12 - 0
mall-server-api/src/main/java/com/gree/mall/manager/bean/settle/repair/DailyImportSummaryVO.java

@@ -0,0 +1,12 @@
+package com.gree.mall.manager.bean.settle.repair;
+
+import com.gree.mall.manager.annotation.ZfireField;
+import io.swagger.annotations.ApiModel;
+import lombok.Data;
+
+@Data
+@ApiModel
+@ZfireField(tbName = "a")
+public class DailyImportSummaryVO {
+
+}

+ 38 - 0
mall-server-api/src/main/java/com/gree/mall/manager/bean/settle/repair/DailyTotalCostBean.java

@@ -0,0 +1,38 @@
+package com.gree.mall.manager.bean.settle.repair;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.math.BigDecimal;
+
+@ApiModel
+@Data
+public class DailyTotalCostBean {
+
+    @ApiModelProperty(value = "维修工Id")
+    private String workerNumber;
+    @ApiModelProperty(value = "维修工姓名")
+    private String repairWorkerName;
+    @ApiModelProperty(value = "日结总费用")
+    private BigDecimal totalFee;
+    @ApiModelProperty(value = "结算单位")
+    private String summaryName;
+    @ApiModelProperty(value = "结算单位编号")
+    private String summaryNumber;
+    @ApiModelProperty(value = "网点单位")
+    private String websitNumber;
+    @ApiModelProperty(value = "网点编号")
+    private String websitName;
+    @ApiModelProperty(value="该单工单数量")
+    private Integer repairCount;
+    @ApiModelProperty(value="身份证")
+    private String idCard;
+    @ApiModelProperty(value="手机号")
+    private String mobile;
+    @ApiModelProperty(value="商户名称")
+    private String companyWechatName;
+    @ApiModelProperty(value="商户id")
+    private String companyWechatId;
+
+}

+ 9 - 0
mall-server-api/src/main/java/com/gree/mall/manager/commonmapper/CommonMapper.java

@@ -29,6 +29,7 @@ import com.gree.mall.manager.bean.settle.SettleExpenseVO;
 import com.gree.mall.manager.bean.settle.SettleMonthWagesVO;
 import com.gree.mall.manager.bean.settle.SettleMonthWagesWorkerVO;
 import com.gree.mall.manager.bean.settle.repair.DailyBankAccountVO;
+import com.gree.mall.manager.bean.settle.repair.DailyImportSummaryVO;
 import com.gree.mall.manager.bean.settle.repair.DailyWithholdVO;
 import com.gree.mall.manager.bean.workorder.*;
 import com.gree.mall.manager.enums.UserTypeEnum;
@@ -637,4 +638,12 @@ public interface CommonMapper {
      * @return
      */
     IPage<DailyWithholdVO> repairSettleDailyWithholdList(Page page, @Param("ex") ZfireParamBean zfireParamBean);
+
+    /**
+     * 维修日结算扣款配置列表
+     * @param page
+     * @param zfireParamBean
+     * @return
+     */
+    IPage<DailyImportSummaryVO> repairSettleDailyImportSummaryList(Page page, @Param("ex") ZfireParamBean zfireParamBean);
 }

+ 38 - 0
mall-server-api/src/main/java/com/gree/mall/manager/commonmapper/DailyMapper.java

@@ -0,0 +1,38 @@
+package com.gree.mall.manager.commonmapper;
+
+import com.baomidou.mybatisplus.annotation.SqlParser;
+import com.gree.mall.manager.bean.settle.repair.DailyTotalCostBean;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+@Mapper
+public interface DailyMapper {
+    /**
+     * 扣回的
+     * @param importBatchNo
+     */
+    @SqlParser(filter = true)
+    void bindWorkerNumber2(@Param("importBatchNo") String importBatchNo);
+
+    /**
+     * 汇总结算-绑定师傅编号
+     * @param importBatchNo
+     */
+    @SqlParser(filter = true)
+    void bindWorkerNumber(@Param("importBatchNo") String importBatchNo);
+    /**
+     * 汇总结算-查询重复的
+     */
+    @SqlParser(filter = true)
+    List<String> queryDistinctOrderNo();
+
+    @SqlParser(filter = true)
+    List<DailyTotalCostBean> queryDailyTotalCost(
+            @Param("importBatchNo") String importBatchNo,
+            @Param("status") List<Integer> status,
+            @Param("needSummaryStatus") List<String> needSummaryStatus
+    );
+
+}

+ 1 - 0
mall-server-api/src/main/java/com/gree/mall/manager/constant/Constant.java

@@ -64,6 +64,7 @@ public class Constant {
 
         //维修日结汇总
         public final static String LOCK_DAILY_BANKACCOUNT = "jsm:SETTLE:LOCK:BANKACCOUNT:";
+        public final static String LOCK_DAILY_SUMMARY = "jsm:SETTLE:LOCK:DAILY:SUMMARY";
     }
     public class ChatMessage {
         public final static String MSG_TYPE_DOC = "docmsg";

+ 71 - 0
mall-server-api/src/main/java/com/gree/mall/manager/constant/DailyConstant.java

@@ -0,0 +1,71 @@
+package com.gree.mall.manager.constant;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+public class DailyConstant {
+
+    /**
+     * 汇总状态 1.已汇总 2.未汇总 3.暂不结算 4.驳回
+     */
+    public final static Integer SUMMARY_STATUS_HAS = 1;
+
+    public final static Integer SUMMARY_STATUS_NOT = 2;
+
+    public final static Integer SUMMARY_STATUS_WAIT = 3;
+
+    public final static Integer SUMMARY_STATUS_REJECT = 4;
+
+    public static List<Integer>   SUMMARY_STATUS_CAN_DO = Arrays.asList(2, 4);
+
+    public static List<Integer>   SUMMARY_STATUS_CAN_DEL = Arrays.asList(2,3,4);
+
+    /**
+     * 发放状态 1.未发放 2.已发放 3.银行受理中 4.发放失败 5.驳回
+     */
+    public final static Integer ISSUE_STATUS_NOT = 1;
+    public final static Integer ISSUE_STATUS_SUCCESS = 2;
+    public final static Integer ISSUE_STATUS_BANK_DO = 3;
+    public final static Integer ISSUE_STATUS_FAILED = 4;
+    public final static Integer ISSUE_STATUS_REJECT = 5;
+
+    //app展示未发放
+    public static List<Integer>   ISSUE_STATUS_APP_NOT = Arrays.asList(1,3,4);
+
+    public static List<Integer>   ISSUE_STATUS_SUCCESS_ARRY = Arrays.asList(2);
+
+
+    public final static String TRANSFER_RESP_WAIT[] = {"W"};
+    public final static String TRANSFER_RESP_SUCCESS[] = {"S"};
+    public final static String TRANSFER_RESP_FAILED[] = {"E"};
+
+    // 调用银行接口返回数据
+    public final static String CMC_RESPONSE_FAIL_CODE = "201";
+    public final static String CMC_RESPONSE_SUCCESS_CODE = "200";
+
+    public final static String CMC_BUS_MOD = "00002";
+
+    //执行状态
+    public final static Integer DO_STATUS_HAS = 1;
+
+    public final static Integer DO_STATUS_NOT = 2;
+
+    public final static List<String> SUMMARY_STATUS_ARRAY = new ArrayList<String>(){
+        {
+            add("已转结算待汇总");
+            add("待退旧件");
+            add("待总部日审");
+            add("待总部审批");
+            add("待总部日结审批");
+            add("已汇总");
+        }
+    };
+
+
+    public static List<String>   WARN_COMPANY = Arrays.asList("广州嘉讯茂机电工程有限公司","广东家盛茂科技有限公司");
+
+
+    public final static  String WARN_TEMPLEATE = "SMS_250916318";
+
+}

+ 94 - 0
mall-server-api/src/main/java/com/gree/mall/manager/controller/settle/repair/DailyImportSummaryController.java

@@ -0,0 +1,94 @@
+package com.gree.mall.manager.controller.settle.repair;
+
+import cn.hutool.core.lang.TypeReference;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.gree.mall.manager.annotation.ZfireList;
+import com.gree.mall.manager.bean.settle.repair.DailyImportSummaryVO;
+import com.gree.mall.manager.constant.Constant;
+import com.gree.mall.manager.exception.RemoteServiceException;
+import com.gree.mall.manager.helper.ResponseHelper;
+import com.gree.mall.manager.logic.settle.repair.DailyImportSummaryLogic;
+import com.gree.mall.manager.utils.excel.ExcelUtils;
+import com.gree.mall.manager.zfire.bean.ZfireParamBean;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.integration.redis.util.RedisLockRegistry;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.locks.Lock;
+
+@Slf4j
+@RestController
+@Api(value = "结算API", tags = {"结算API"})
+@RequestMapping(value = "/daily/summary", produces = "application/json; charset=utf-8")
+@RequiredArgsConstructor
+public class DailyImportSummaryController {
+
+    private final DailyImportSummaryLogic dailyImportSummaryLogic;
+    private final RedisLockRegistry redisLockRegistry;
+
+    @ZfireList
+    @PostMapping("/list")
+    @ApiOperation(value = "列表")
+    public ResponseHelper<IPage<DailyImportSummaryVO>> page(
+            @RequestBody ZfireParamBean zfireParamBean
+    ) {
+        IPage<DailyImportSummaryVO> page = dailyImportSummaryLogic.page(zfireParamBean);
+        return ResponseHelper.success(page, new TypeReference<DailyImportSummaryVO>() {
+        });
+    }
+
+    @ApiOperation("结算/扣回工单-导入")
+    @PostMapping("/order/import")
+    public ResponseHelper importOrderData(
+            @ApiParam(required = true, value = "附件") @RequestPart("file") MultipartFile file,
+            @ApiParam(required = true, value = "类型 1. repair.结算工单 2. reduce.需扣回工单") @RequestParam String type,
+            @ApiParam(required = false, value = "导入批次号(覆盖导入时传入)") @RequestParam(required = false) String importBatchNo,
+            HttpServletRequest request
+    ) throws Exception {
+        List<Object> datas = ExcelUtils.importExcel(file);
+        String s = dailyImportSummaryLogic.importOrderData(type, importBatchNo, datas, request);
+        return ResponseHelper.success(s);
+    }
+
+    @PostMapping("/repair/delete")
+    @ApiOperation(value = "结算数据导入-删除")
+    public ResponseHelper repairDelete(
+            @ApiParam(required = true, value = "导入批次号") @RequestParam String importBatchNo
+    ){
+        dailyImportSummaryLogic.repairDelete(importBatchNo);
+        return ResponseHelper.success();
+    }
+
+    @PostMapping("/repair/summary")
+    @ApiOperation(value = "结算数据导入-汇总/批量汇总")
+    public ResponseHelper repairSummary(
+            @ApiParam(value = "导入批次号", required = true) @RequestParam List<String> importBatchNos,
+            @ApiParam(value = "是否为安装费用") @RequestParam(required = false) Boolean install
+    ) throws InterruptedException {
+        Lock obtain = redisLockRegistry.obtain(Constant.RedisPrefix.LOCK_DAILY_SUMMARY);
+        if(!obtain.tryLock(10, TimeUnit.SECONDS)){
+            throw new RemoteServiceException("正在汇总中,请稍后再试");
+        }
+        try{
+            for(String importBatchNo:importBatchNos) {
+                try {
+                    dailyImportSummaryLogic.repairSummary(importBatchNo,install);
+                }catch(Exception e){
+                    log.error("结算数据汇总失败",e);
+                    return ResponseHelper.error("批次号:"+importBatchNo+"汇总失败");
+                }
+            }
+        }finally {
+            obtain.unlock();
+        }
+        return ResponseHelper.success();
+    }
+}

+ 29 - 0
mall-server-api/src/main/java/com/gree/mall/manager/enums/repair/settle/SummaryStatusEnum.java

@@ -0,0 +1,29 @@
+package com.gree.mall.manager.enums.repair.settle;
+
+import com.baomidou.mybatisplus.annotation.EnumValue;
+import com.baomidou.mybatisplus.annotation.IEnum;
+import com.fasterxml.jackson.annotation.JsonValue;
+import com.gree.mall.manager.enums.base.BaseEnum;
+import lombok.AccessLevel;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+@Getter
+@AllArgsConstructor(access = AccessLevel.PRIVATE)
+public enum SummaryStatusEnum implements BaseEnum, IEnum<Integer> {
+    END("1","已汇总"),
+    NOT("2","未汇总"),
+    HOLD("3","暂不结算"),
+    REJECT("4","驳回"),
+    ;
+
+    @EnumValue
+    @JsonValue
+    private final String key;
+    private final String remark;
+
+    @Override
+    public Integer getValue() {
+        return Integer.parseInt(key);
+    }
+}

+ 407 - 0
mall-server-api/src/main/java/com/gree/mall/manager/logic/settle/repair/DailyImportSummaryLogic.java

@@ -0,0 +1,407 @@
+package com.gree.mall.manager.logic.settle.repair;
+
+import cn.hutool.core.date.DateUtil;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.gree.mall.manager.bean.admin.AdminUserCom;
+import com.gree.mall.manager.bean.settle.repair.DailyImportSummaryVO;
+import com.gree.mall.manager.bean.settle.repair.DailyTotalCostBean;
+import com.gree.mall.manager.commonmapper.CommonMapper;
+import com.gree.mall.manager.commonmapper.DailyMapper;
+import com.gree.mall.manager.constant.DailyConstant;
+import com.gree.mall.manager.constant.SysDictConstant;
+import com.gree.mall.manager.exception.RemoteServiceException;
+import com.gree.mall.manager.logic.common.CommonLogic;
+import com.gree.mall.manager.plus.entity.*;
+import com.gree.mall.manager.plus.service.*;
+import com.gree.mall.manager.utils.CommonUtils;
+import com.gree.mall.manager.utils.DateUtils;
+import com.gree.mall.manager.zfire.bean.ZfireParamBean;
+import com.gree.mall.manager.zfire.util.FieldUtils;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.BeanUtils;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.CollectionUtils;
+
+import javax.servlet.http.HttpServletRequest;
+import java.math.BigDecimal;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.stream.Collectors;
+
+@Service
+@Slf4j
+@RequiredArgsConstructor
+public class DailyImportSummaryLogic {
+
+    private final CommonLogic commonLogic;
+    private final CommonMapper commonMapper;
+    private final SettleDailyImportSummaryItemService settleDailyImportSummaryItemService;
+    private final SettleDailyReduceCostService settleDailyReduceCostService;
+    private final DailyMapper dailyMapper;
+    private final SettleWebsitWorkerDirectorService settleWebsitWorkerDirectorService;
+    private final SettleDailyIssueSummaryRecordService settleDailyIssueSummaryRecordService;
+    private final SysDictCompanyService sysDictCompanyService;
+    private final SettleDailyWithholdService settleDailyWithholdService;
+
+
+    public IPage<DailyImportSummaryVO> page(ZfireParamBean zfireParamBean) {
+        AdminUserCom adminUser = commonLogic.getAdminUser();
+        FieldUtils.supplyParam(zfireParamBean, DailyImportSummaryVO.class, adminUser);
+
+        return commonMapper.repairSettleDailyImportSummaryList(new Page(zfireParamBean.getPageNum(), zfireParamBean.getPageSize()), zfireParamBean);
+    }
+
+    /**
+     * 导入结算/工单扣回数据
+     */
+    @Transactional
+    public String importOrderData(String type, String importBatchNo, List<Object> datas, HttpServletRequest request) throws Exception {
+        StringBuffer errorData = new StringBuffer();
+        AdminUserCom adminUser = commonLogic.getAdminUser();
+        log.info("【导入结算】:{}", DateUtils.formatDate(new Date()));
+        List<SettleDailyReduceCost> reduceList = new ArrayList<>();
+        //生成导入批次号
+        List<SettleDailyImportSummaryItem> summaryItemList = new ArrayList<>();
+        String batchNo = commonLogic.generateNo("reduce".equals(type) ? "HK" : "JS", "repair_daily", 11);
+        //传入批次号删除数据
+        if (StringUtils.isNotEmpty(importBatchNo)) {
+            if ("reduce".equals(type)) {
+                Integer count = settleDailyReduceCostService.lambdaQuery()
+                        .eq(SettleDailyReduceCost::getImportBatchNo, importBatchNo)
+                        .eq(SettleDailyReduceCost::getDoStatus, DailyConstant.DO_STATUS_HAS)
+                        .count();
+
+                if (count > 0) {
+                    throw new RemoteServiceException("存在已执行的数据");
+                }
+                settleDailyReduceCostService.lambdaUpdate().eq(SettleDailyReduceCost::getImportBatchNo, importBatchNo).remove();
+            } else {
+                Integer count = settleDailyImportSummaryItemService.lambdaQuery()
+                        .eq(SettleDailyImportSummaryItem::getImportBatchNo, importBatchNo)
+                        .eq(SettleDailyImportSummaryItem::getSummaryStatus, DailyConstant.SUMMARY_STATUS_HAS)
+                        .count();
+                if (count > 0) {
+                    throw new RemoteServiceException("存在已汇总的数据");
+                }
+                settleDailyImportSummaryItemService.lambdaUpdate().eq(SettleDailyImportSummaryItem::getImportBatchNo, importBatchNo)
+                        .remove();
+            }
+        }
+
+        for (int i = 0; i < datas.size(); i++) {
+            List<String> row = (List<String>) datas.get(i);
+            CommonUtils.initList(row, 100);
+//            DailyWorkerNumberBean workerNumberBean = dailyMapper.queryWorkerNumber(row.get(33),row.get(34),row.get(44));
+//            if(workerNumberBean == null){
+//                throw new RemoteServiceException("行数" + row.get(0) + "姓名:"+row.get(33) +"找不到对应的工号");
+//            }
+            SettleDailyReduceCost bean = new SettleDailyReduceCost();
+//            bean.setWorkerNumber(workerNumberBean.getWorkerNumber());
+//            bean.setBelongCompany(workerNumberBean.getBelongCompany());
+//            bean.setBelongCompanyId(workerNumberBean.getBelongCompanyId());
+            bean.setImportBatchNo(batchNo);
+            bean.setDispatchOrderNo(row.get(1));
+            bean.setSelfNo(row.get(2));
+            bean.setOrderStatus(row.get(3));
+            bean.setSummaryNumber(row.get(4));
+            bean.setOldSummaryNumber(row.get(5));
+            bean.setSummaryName(row.get(6));
+            bean.setRepairType(row.get(7));
+            bean.setInOutMachine(row.get(8));
+            bean.setMachineCode(row.get(9));
+            bean.setOutMachineType(row.get(10));
+            bean.setOutMachineDescribe(row.get(11));
+            bean.setInMachineCode(row.get(12));
+            bean.setInMachineType(row.get(13));
+            bean.setInMachineDescribe(row.get(14));
+            bean.setUserName(row.get(15));
+            bean.setAreaCode(row.get(16));
+            bean.setMobile(row.get(17));
+            bean.setTel(row.get(18));
+            bean.setProvince(row.get(19));
+            bean.setCity(row.get(20));
+            bean.setCounty(row.get(21));
+            bean.setUserAddr(row.get(22));
+            bean.setGpsAddr(row.get(23));
+            bean.setPostalCode(row.get(24));
+            bean.setSaleDeptNo(row.get(25));
+            bean.setSaleDeptName(row.get(26));
+            bean.setInvoiceCode(row.get(27));
+
+            if (StringUtils.isNotBlank(row.get(28))) {
+                bean.setBuyDate(new SimpleDateFormat("yyyy年MM月dd日").parse(row.get(28)));
+            }
+            if (StringUtils.isNotBlank(row.get(29))) {
+                bean.setInstallDate(new SimpleDateFormat("yyyy年MM月dd日").parse(row.get(29)));
+            }
+
+            if (StringUtils.isNotBlank(row.get(30))) {
+                bean.setReportDate(new SimpleDateFormat("yyyy年MM月dd日").parse(row.get(30)));
+            }
+            if (StringUtils.isNotBlank(row.get(31))) {
+                bean.setRepairDate(new SimpleDateFormat("yyyy年MM月dd日").parse(row.get(31)));
+            }
+            bean.setRepairWorkerId(row.get(32));
+            bean.setRepairWorkerName(row.get(33));
+            bean.setRepairWorkerMobile(row.get(34));
+            if (StringUtils.isNotBlank(row.get(35))) {
+                bean.setRepairFee(new BigDecimal(row.get(35)));
+            }
+            if (StringUtils.isNotBlank(row.get(36))) {
+                bean.setTrafficFee(new BigDecimal(row.get(36)));
+            }
+            if (StringUtils.isNotBlank(row.get(37))) {
+                bean.setAccommodationFee(new BigDecimal(row.get(37)));
+            }
+            if (StringUtils.isNotBlank(row.get(38))) {
+                bean.setLiftingFee(new BigDecimal(row.get(38)));
+            }
+            if (StringUtils.isNotBlank(row.get(39))) {
+                bean.setOtherFee(new BigDecimal(row.get(39)));
+            }
+            if (StringUtils.isNotBlank(row.get(40))) {
+                bean.setTotalFee(new BigDecimal(row.get(40)));
+            }
+            bean.setSettlementBatchNo(row.get(41));
+            bean.setInstallWebsitNo(row.get(42));
+            bean.setInstallWebsitName(row.get(43));
+            bean.setRepairUnit(row.get(44));
+            bean.setOldRepairUnit(row.get(45));
+            bean.setRepairName(row.get(46));
+            bean.setFaultPhenomenon(row.get(47));
+            bean.setFaultAnalysis(row.get(48));
+            bean.setRepairDetail(row.get(49));
+            bean.setRemark(row.get(50));
+            bean.setImportBy(adminUser.getNickName());
+            bean.setImportTime(new Date());
+            bean.setCreateTime(new Date());
+            bean.setWebsitName(row.get(46));
+            bean.setWebsitNumber(row.get(44));
+            if (StringUtils.isNotBlank(row.get(51))) {
+                bean.setSettlementTime(new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss").parse(row.get(51)));
+            }
+            if (("reduce").equals(type)) {
+                //设置执行状态未未执行
+                bean.setDoStatus(DailyConstant.DO_STATUS_NOT);
+                reduceList.add(bean);
+            } else {
+                SettleDailyImportSummaryItem item = new SettleDailyImportSummaryItem();
+                BeanUtils.copyProperties(bean, item);
+                item.setSummaryStatus(DailyConstant.SUMMARY_STATUS_NOT);
+                summaryItemList.add(item);
+                //查询在系统中已存在的
+//                Integer count = dailyImportSummaryItemService.lambdaQuery()
+//                            .eq(DailyImportSummaryItem::getDispatchOrderNo,item.getDispatchOrderNo())
+//                            .eq(DailyImportSummaryItem::getSelfNo,item.getSelfNo())
+//                            .in(DailyImportSummaryItem::getOrderStatus,DailyConstant.SUMMARY_STATUS_ARRAY).count();
+//                if(count > 0){
+//                    errorData.append("工单"+ item.getDispatchOrderNo());
+//                }
+            }
+
+        }
+        if (("reduce").equals(type)) {
+            settleDailyReduceCostService.saveBatch(reduceList);
+            dailyMapper.bindWorkerNumber2(batchNo);
+            //判断是否有匹配失败的师傅编号的
+            List<SettleDailyReduceCost> list = settleDailyReduceCostService.lambdaQuery()
+                    .eq(SettleDailyReduceCost::getWorkerNumber, "")
+                    .eq(SettleDailyReduceCost::getImportBatchNo, batchNo)
+                    .last("limit 1")
+                    .list();
+            if (list.size() > 0)
+                throw new RemoteServiceException("姓名:" + list.get(0).getRepairName() + ",派工序号:" + list.get(0).getDispatchOrderNo() + "找不到对应的师傅编号");
+            //判断是否存在导入重复的工单号
+        } else {
+            settleDailyImportSummaryItemService.saveBatch(summaryItemList);
+            dailyMapper.bindWorkerNumber(batchNo);
+            //判断是否有匹配失败的师傅编号的
+            List<SettleDailyImportSummaryItem> list = settleDailyImportSummaryItemService.lambdaQuery()
+                    .eq(SettleDailyImportSummaryItem::getWorkerNumber, "")
+                    .eq(SettleDailyImportSummaryItem::getImportBatchNo, batchNo)
+                    .last("limit 1")
+                    .list();
+            if (list.size() > 0)
+                throw new RemoteServiceException("姓名:" + list.get(0).getRepairName() + ",派工序号:" + list.get(0).getDispatchOrderNo() + "找不到对应的师傅编号");
+            //判断是否存在导入重复的工单号
+            List<String> errList = dailyMapper.queryDistinctOrderNo();
+            if (!CollectionUtils.isEmpty(errList)) {
+                errorData = errorData.append(StringUtils.join(errList, ","));
+            }
+        }
+
+        if (errorData.length() > 0) {
+            errorData.append("已存在,导入失败");
+        }
+        return errorData.toString();
+    }
+
+    /**
+     * 结算数据导入 -删除
+     */
+    public void repairDelete(String importBatchNo) {
+        AdminUserCom adminUser = commonLogic.getAdminUser();
+
+        if (adminUser.getType() == 2) {
+            throw new RemoteServiceException("平台账号禁止操作");
+        }
+
+        Integer count = settleDailyImportSummaryItemService.lambdaQuery()
+                .eq(SettleDailyImportSummaryItem::getCompanyWechatId, adminUser.getAdminCompanyWechat().getCompanyWechatId())
+                .eq(SettleDailyImportSummaryItem::getImportBatchNo, importBatchNo)
+                .eq(SettleDailyImportSummaryItem::getSummaryStatus, DailyConstant.SUMMARY_STATUS_HAS).count();
+        if (count > 0) {
+            throw new RemoteServiceException("已汇总,无法删除");
+        }
+
+        settleDailyImportSummaryItemService.lambdaUpdate()
+                .eq(SettleDailyImportSummaryItem::getCompanyWechatId, adminUser.getAdminCompanyWechat().getCompanyWechatId())
+                .eq(SettleDailyImportSummaryItem::getImportBatchNo, importBatchNo)
+                .in(SettleDailyImportSummaryItem::getSummaryStatus, DailyConstant.SUMMARY_STATUS_CAN_DEL).remove();
+    }
+
+    @Transactional
+    public void repairSummary(String importBatchNo, Boolean install) {
+        AdminUserCom adminUser = commonLogic.getAdminUser();
+
+        if (adminUser.getType() == 2) {
+            throw new RemoteServiceException("平台账号禁止操作");
+        }
+        //不结算主管的身份证
+        List<SettleWebsitWorkerDirector> list = settleWebsitWorkerDirectorService.lambdaQuery().list();
+        List<String> notSettleIdcards = list.stream().map(SettleWebsitWorkerDirector::getIdcard).collect(Collectors.toList());
+        //结算数据导入明细
+        List<SettleDailyImportSummaryItem> updateList = settleDailyImportSummaryItemService.lambdaQuery().
+                eq(SettleDailyImportSummaryItem::getImportBatchNo, importBatchNo)
+                .in(SettleDailyImportSummaryItem::getSummaryStatus, DailyConstant.SUMMARY_STATUS_CAN_DO)
+                .in(SettleDailyImportSummaryItem::getOrderStatus, DailyConstant.SUMMARY_STATUS_ARRAY).list();
+
+        if (updateList.size() <= 0) {
+            throw new RemoteServiceException("该批次已汇总,请勿重复汇总。");
+        }
+        String opName = adminUser.getNickName();
+        String summaryBatchNo = updateList.get(0).getSummaryBatchNo();
+        if (StringUtils.isEmpty(summaryBatchNo)) {
+            summaryBatchNo = commonLogic.generateNo("HZ", "dailyBatch", 13);
+        }
+        settleDailyIssueSummaryRecordService.lambdaUpdate().eq(SettleDailyIssueSummaryRecord::getSummaryBatchNo, summaryBatchNo).remove();
+        //查询统计数据
+        List<DailyTotalCostBean> costBeans = dailyMapper.queryDailyTotalCost(importBatchNo, DailyConstant.SUMMARY_STATUS_CAN_DO, DailyConstant.SUMMARY_STATUS_ARRAY);
+
+        String nowMonth = DateUtil.format(new Date(), "yyyyMM");
+        List<SettleDailyIssueSummaryRecord> issueList = new ArrayList<>();
+        SysDictCompany dict = sysDictCompanyService.lambdaQuery()
+                .eq(SysDictCompany::getCompanyWechatId, adminUser.getAdminCompanyWechat().getCompanyWechatId())
+                .eq(SysDictCompany::getDictCode, SysDictConstant.REPAIR_DAILY)
+                .last("limit 1")
+                .one();
+        if (dict == null) {
+            throw new RemoteServiceException("未配置暂扣比例。");
+        }
+        List<SettleDailyWithhold> withholds = settleDailyWithholdService.lambdaQuery().list();
+
+        //1.标记为非新的历史待扣费用(防止驳回的时候误删)
+//        dailyRemaineBuckleService.lambdaUpdate()
+//                .set(DailyRemaineBuckle::getSummaryBatchNo,summaryBatchNo)
+//                .set(DailyRemaineBuckle::getUpdateTime,new Date())
+//                .set(DailyRemaineBuckle::getUpdateBy,opName)
+//                .eq(DailyRemaineBuckle::getSummaryBatchNo,"").update();
+
+        //1.应发金额 = 维修费用 + 增减费用 - 扣回费用
+        //2.应发金额 = 应发金额 - 工伤残保
+        //3.应发金额 = 应发金额 - 暂扣款
+        //ps.如果不够扣,则有多少扣多少,然后留给下次扣。一个身份证只扣1次工伤残保
+        for (DailyTotalCostBean cost : costBeans) {
+            SettleDailyIssueSummaryRecord issue = new SettleDailyIssueSummaryRecord();
+            String BatchNo = commonLogic.generateNo("SF", "dailySalaryNo", 16);
+            //维修费
+            BigDecimal totalFee = cost.getTotalFee();
+            if (totalFee.doubleValue() < 0) {
+                continue;
+            }
+            //不结算主管过滤直接成0
+            if (notSettleIdcards.contains(cost.getIdCard()) && (install == null || !install)) {
+                issue.setRemark("安维主管结算费用0,原可结算金额:" + totalFee);
+                totalFee = BigDecimal.valueOf(0);
+            }
+
+            //获取身份证
+            issue.setMobile(cost.getMobile());
+            issue.setIdCard(cost.getIdCard());
+            issue.setRepairCount(cost.getRepairCount());
+            issue.setWebsitName(cost.getWebsitName());
+            issue.setWebsitNumber(cost.getWebsitNumber());
+            issue.setCompanyWechatId(cost.getCompanyWechatId());
+            issue.setCompanyWechatName(cost.getCompanyWechatName());
+            issue.setMonth(nowMonth);
+            issue.setServiceName(cost.getRepairWorkerName());
+            issue.setServiceNumber(cost.getWorkerNumber());
+            issue.setSummaryName(cost.getSummaryName());
+            issue.setSummaryNumber(cost.getSummaryNumber());
+            issue.setSalaryNo(BatchNo);
+            issue.setStatus(DailyConstant.SUMMARY_STATUS_HAS);
+            issue.setRepairTotalAmount(totalFee);
+            issue.setCreateTime(new Date());
+            issue.setCreateBy(opName);
+            issue.setSummaryBatchNo(summaryBatchNo);
+            issue.setSummaryTime(new Date());
+            issue.setSummaryBy(opName);
+            issue.setIsMonthSummary(false);
+            issue.setReduceCost(new BigDecimal(0));
+            issue.setIncrDecrCost(new BigDecimal(0));
+            issue.setShouldResidualInsuranceCost(BigDecimal.valueOf(0));
+            issue.setShouldEmpInsuranceCost(BigDecimal.valueOf(0));
+            issue.setEmpInsuranceCost(BigDecimal.valueOf(0));
+            issue.setResidualInsuranceCost(BigDecimal.valueOf(0));
+            issue.setShouldReduceCost(BigDecimal.valueOf(0));
+            issue.setWithholdTotalCost(BigDecimal.valueOf(0));
+            issue.setWithholdCost(BigDecimal.valueOf(0));
+            issue.setIssueCost(totalFee);
+            issue.setInstall(install);
+
+            if (install == null || !install) {
+                //暂扣金额
+                if (issue.getIssueCost().doubleValue() >= 0) {
+                    BigDecimal withholdCost = issue.getIssueCost()
+                            .multiply(new BigDecimal(dict.getDictValue()))
+                            .setScale(2, BigDecimal.ROUND_HALF_UP);
+                    if (withholdCost.doubleValue() > 0) {
+                        issue.setWithholdCost(withholdCost);
+                        issue.setWithholdTotalCost(withholdCost);
+
+                        issue.setIssueCost(issue.getIssueCost().subtract(withholdCost));
+                    }
+                }
+                //处理本月要扣的工伤残保金,扣不完则留到历史费用
+                //2.扣工伤残保,并产生新的待扣记录
+//                issue = this.deductGscb(opName, nowMonth, summaryBatchNo, issue, cost, withholds);
+                //3.处理历史待扣
+//                issue = this.historyAmount(issue, summaryBatchNo, opName);
+            }
+            issueList.add(issue);
+        }
+        //生成数据到日结发放表
+        settleDailyIssueSummaryRecordService.saveOrUpdateBatch(issueList);
+
+        for (SettleDailyIssueSummaryRecord issueSummaryRecord : issueList) {
+            for (SettleDailyImportSummaryItem importSummaryItem : updateList) {
+                importSummaryItem.setSummaryBy(opName);
+                importSummaryItem.setSummaryTime(new Date());
+                importSummaryItem.setSummaryStatus(DailyConstant.SUMMARY_STATUS_HAS);
+                importSummaryItem.setSummaryBatchNo(summaryBatchNo);
+                importSummaryItem.setMonth(nowMonth);
+                if (issueSummaryRecord.getServiceNumber().equals(importSummaryItem.getWorkerNumber())
+                        && issueSummaryRecord.getSummaryNumber().equals(importSummaryItem.getSummaryNumber())) {
+                    importSummaryItem.setIssueSalaryId(issueSummaryRecord.getId());
+                }
+            }
+        }
+        settleDailyImportSummaryItemService.updateBatchById(updateList, 500);
+    }
+}

+ 27 - 0
mall-server-api/src/main/resources/mapper/CommonMapper.xml

@@ -112,6 +112,7 @@
         select
         ${ex.selected}
         from user a
+        join websit_user b on a.user_id = b.user_id
         ${ex.query}
         and a.apply_type='SERVICE'
         ORDER BY FIELD(a.examine_status,'WAIT','OK','FAIL'),a.create_time DESC
@@ -1065,6 +1066,32 @@
         </if>
         ${ex.orderBy}
     </select>
+    <select id="repairSettleDailyImportSummaryList"
+            resultType="com.gree.mall.manager.bean.settle.repair.DailyImportSummaryVO">
+        SELECT
+            a.company_wechat_id,
+            a.company_wechat_name,
+            a.import_batch_no,
+            COUNT(DISTINCT a.repair_worker_mobile) AS personNums,
+            COUNT(1) AS 'orderNums',
+            SUM(a.total_fee) AS 'totalAmount',
+            IF(find_in_set('1', group_concat(DISTINCT a.summary_status)) > 0 , 1, 2) AS 'summaryStatus',
+            import_by ,
+            import_time ,
+            group_concat(DISTINCT summary_by) AS 'summaryBy',
+            summary_time AS 'summaryTime',
+            group_concat(DISTINCT summary_batch_no) AS 'summaryBatchNo' ,
+            group_concat(DISTINCT month) AS 'month'
+        FROM
+            settle_daily_import_summary_item a
+        ${ex.query}
+        GROUP BY
+            a.company_wechat_id, a.import_batch_no
+        <if test="ex.orderBy == null or ex.orderBy ==''">
+            ORDER BY a.create_time DESC
+        </if>
+        ${ex.orderBy}
+    </select>
 
 
 </mapper>

+ 77 - 0
mall-server-api/src/main/resources/mapper/DailyMapper.xml

@@ -0,0 +1,77 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.gree.mall.manager.commonmapper.DailyMapper">
+    <update id="bindWorkerNumber2">
+        UPDATE
+            user a
+            JOIN
+            websit_user b ON b.user_id = a.user_id
+            JOIN
+            settle_daily_reduce_cost c
+                ON c.repair_worker_name = a.nick_name AND c.repair_worker_mobile = a.mobile AND c.websit_number = b.websit_id
+        SET c.worker_number = b.worker_number,
+            c.company_wechat_id = a.company_wechat_id,
+            c.company_wechat_name = a.company_name
+        WHERE
+            c.import_batch_no = #{importBatchNo}
+    </update>
+    <update id="bindWorkerNumber">
+        UPDATE
+            user a
+            JOIN
+            websit_user b ON b.user_id = a.user_id
+            JOIN settle_daily_import_summary_item c
+                ON c.repair_worker_name = a.nick_name AND c.repair_worker_mobile = a.mobile AND c.websit_number = b.websit_id
+        SET c.worker_number = b.worker_number,
+            c.company_wechat_id = a.company_wechat_id,
+            c.company_wechat_name = a.company_name
+        WHERE
+            c.import_batch_no = #{importBatchNo}
+    </update>
+    <select id="queryDistinctOrderNo" resultType="java.lang.String">
+        select dispatch_order_no from settle_daily_import_summary_item
+        where order_status in ('已转结算待汇总','待退旧件','待总部日审','待总部审批','待总部日结审批','已汇总')
+        group by concat(self_no,dispatch_order_no)
+        having count(1)>1
+    </select>
+    <select id="queryDailyTotalCost" resultType="com.gree.mall.manager.bean.settle.repair.DailyTotalCostBean">
+        select
+        b.idcard as 'idCard',
+        a.worker_number ,
+        a.repair_worker_name ,
+        a.summary_name,
+        a.summary_number,
+        a.websit_number,
+        a.websit_name,
+        a.company_wechat_id,
+        a.company_wechat_name,
+        sum(a.total_fee) 'total_fee',
+        count(a.dispatch_order_no) as repairCount,
+        a.repair_worker_mobile 'mobile'
+        from settle_daily_import_summary_item a
+        join (select DISTINCT c.worker_number,a.idcard from settle_daily_bank_account a
+        join user b on a.idcard=b.id_card
+        join websit_user c on b.user_id=c.user_id) b on a.worker_number=b.worker_number
+        where 1=1
+
+        <if test="status != null and status.size()> 0">
+            and summary_status in
+            <foreach collection="status" item="statusSItem" index="index"
+                     open="(" close=")" separator=",">
+                #{statusSItem}
+            </foreach>
+        </if>
+        <if test="needSummaryStatus != null and needSummaryStatus.size()> 0">
+            and order_status in
+            <foreach collection="needSummaryStatus" item="statusItem" index="index"
+                     open="(" close=")" separator=",">
+                #{statusItem}
+            </foreach>
+        </if>
+        <if test="importBatchNo !=null and importBatchNo !=''">
+            and import_batch_no =#{importBatchNo}
+        </if>
+        group by worker_number
+        order by total_fee desc
+    </select>
+</mapper>