| | |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | import com.ruoyi.common.utils.LongUtil; |
| | | import com.ruoyi.system.domain.SysTaskEmergency; |
| | | import com.ruoyi.system.mapper.SysTaskEmergencyMapper; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | |
| | | @Autowired |
| | | private SysUserMapper sysUserMapper; |
| | | |
| | | @Autowired |
| | | private SysTaskEmergencyMapper sysTaskEmergencyMapper; |
| | | |
| | | /** |
| | | * 查询发票申请 |
| | |
| | | @Override |
| | | public int insertSysInvoice(SysInvoice sysInvoice) |
| | | { |
| | | Long taskId = sysInvoice.getServiceOrderId(); |
| | | Long legacyServiceOrdId = sysInvoice.getLegacyServiceOrderId(); |
| | | if(LongUtil.isNotEmpty(taskId) && LongUtil.isEmpty(legacyServiceOrdId)){ |
| | | SysTaskEmergency taskEmergency= sysTaskEmergencyMapper.selectSysTaskEmergencyByTaskId(taskId); |
| | | if(taskEmergency!=null){ |
| | | legacyServiceOrdId=taskEmergency.getLegacyServiceOrdId(); |
| | | } |
| | | |
| | | } |
| | | sysInvoice.setLegacyServiceOrderId(legacyServiceOrdId); |
| | | sysInvoice.setApplyTime(DateUtils.getNowDate()); |
| | | sysInvoice.setStatus(0); // 待审核 |
| | | sysInvoice.setSyncStatus(0); // 未同步 |
| | |
| | | } |
| | | |
| | | /** |
| | | * 编辑后同步更新到旧系统 |
| | | * - 已有 legacyInvoiceId:直接 UPDATE 旧系统记录 |
| | | * - 无 legacyInvoiceId(历史同步失败):重新 INSERT |
| | | */ |
| | | @Override |
| | | public void syncUpdateToLegacySystem(Long invoiceId) { |
| | | SysInvoice invoice = sysInvoiceMapper.selectSysInvoiceByInvoiceId(invoiceId); |
| | | if (invoice == null) return; |
| | | |
| | | Map<String, Object> params = new HashMap<>(); |
| | | params.put("InvoiceType", invoice.getInvoiceType()); |
| | | params.put("InvoiceName", invoice.getInvoiceName()); |
| | | params.put("InvoiceMakeout", invoice.getInvoiceRemarks()); |
| | | params.put("InvoiceCompanyPhone", invoice.getContactPhone()); |
| | | params.put("InvoiceCompanyID", ""); |
| | | params.put("InvoiceCompanyAdd", invoice.getCompanyAddress()); |
| | | params.put("InvoiceCompanyBank", invoice.getCompanyBank()); |
| | | params.put("InvoiceCompanyBankNo",invoice.getCompanyBankNo()); |
| | | params.put("InvoiceZipCode", invoice.getZipCode()); |
| | | params.put("Invoice_strAdd", invoice.getMailAddress()); |
| | | params.put("Invoice_strName", invoice.getContactName()); |
| | | params.put("Invoice_strPhone", invoice.getContactPhone()); |
| | | params.put("Invoice_strEmail", invoice.getContactEmail()); |
| | | params.put("ServiceOrderIDPK", invoice.getLegacyServiceOrderId()); |
| | | params.put("InvoiceMoney", invoice.getInvoiceMoney()); |
| | | |
| | | Integer oaUserId = 0; |
| | | if (invoice.getApplyUserId() != null) { |
| | | SysUser user = sysUserMapper.selectUserById(invoice.getApplyUserId()); |
| | | if (user != null && user.getOaUserId() != null) { |
| | | oaUserId = user.getOaUserId(); |
| | | } |
| | | } |
| | | params.put("ApplyOAID", oaUserId); |
| | | |
| | | try { |
| | | if (invoice.getLegacyInvoiceId() != null && invoice.getLegacyInvoiceId() > 0) { |
| | | // 旧系统已有记录,UPDATE |
| | | params.put("InvoiceID", invoice.getLegacyInvoiceId()); |
| | | int rows = legacyInvoiceMapper.updateLegacyInvoice(params); |
| | | if (rows > 0) { |
| | | invoice.setSyncStatus(1); |
| | | sysInvoiceMapper.updateSysInvoice(invoice); |
| | | log.info("发票编辑同步旧系统成功(UPDATE), invoiceId={}, legacyId={}", invoiceId, invoice.getLegacyInvoiceId()); |
| | | } |
| | | } else { |
| | | // 旧系统无记录,重新 INSERT |
| | | params.put("ServiceOrderIDPK", invoice.getLegacyServiceOrderId()); |
| | | int rows = legacyInvoiceMapper.insertLegacyInvoice(params); |
| | | if (rows > 0) { |
| | | Object legacyId = params.get("InvoiceID"); |
| | | if (legacyId != null) { |
| | | invoice.setLegacyInvoiceId(Integer.valueOf(legacyId.toString())); |
| | | } |
| | | invoice.setSyncStatus(1); |
| | | sysInvoiceMapper.updateSysInvoice(invoice); |
| | | log.info("发票编辑同步旧系统成功(INSERT), invoiceId={}", invoiceId); |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("发票编辑同步旧系统异常, invoiceId={}: {}", invoiceId, e.getMessage()); |
| | | invoice.setSyncStatus(2); |
| | | sysInvoiceMapper.updateSysInvoice(invoice); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 从旧系统同步发票状态变化 |
| | | */ |
| | | @Override |