From 9b3624a0aff61ac4f85e300436de44f65f561185 Mon Sep 17 00:00:00 2001 From: "lisai17@sina.com" Date: Wed, 30 Sep 2020 00:05:54 +0800 Subject: [PATCH] . --- .../main/java/com/cowr/model/OssfileLog.java | 14 ++ .../main/java/com/cowr/model/_MappingKit.java | 1 + .../com/cowr/model/base/BaseOssfileLog.java | 178 ++++++++++++++ .../src/main/java/generator/Main.java | 1 + .../invoice/log/InvoiceLogSyncService.java | 225 +++++++++++++++--- 5 files changed, 382 insertions(+), 37 deletions(-) create mode 100644 ssjygl-xsx-common/src/main/java/com/cowr/model/OssfileLog.java create mode 100644 ssjygl-xsx-common/src/main/java/com/cowr/model/base/BaseOssfileLog.java diff --git a/ssjygl-xsx-common/src/main/java/com/cowr/model/OssfileLog.java b/ssjygl-xsx-common/src/main/java/com/cowr/model/OssfileLog.java new file mode 100644 index 0000000..ad37219 --- /dev/null +++ b/ssjygl-xsx-common/src/main/java/com/cowr/model/OssfileLog.java @@ -0,0 +1,14 @@ +package com.cowr.model; + +import com.cowr.model.base.BaseOssfileLog; + +/** + * Generated by COWR Wed Sep 30 00:04:42 CST 2020 + * TableName: ossfile_log + * Remarks: 日志相关 - 文件上传至oss的状态日志 + * PrimaryKey: id + */ +@SuppressWarnings("serial") +public class OssfileLog extends BaseOssfileLog { + public static final OssfileLog dao = new OssfileLog().dao(); +} diff --git a/ssjygl-xsx-common/src/main/java/com/cowr/model/_MappingKit.java b/ssjygl-xsx-common/src/main/java/com/cowr/model/_MappingKit.java index 5ecd7d1..7415251 100644 --- a/ssjygl-xsx-common/src/main/java/com/cowr/model/_MappingKit.java +++ b/ssjygl-xsx-common/src/main/java/com/cowr/model/_MappingKit.java @@ -49,6 +49,7 @@ public class _MappingKit { arp.addMapping("prepay_truck", "id", PrepayTruck.class); arp.addMapping("sms_log", "id", SmsLog.class); arp.addMapping("sync_task", "id", SyncTask.class); + arp.addMapping("ossfile_log", "id", OssfileLog.class); arp.addMapping("modify_log", "id", ModifyLog.class); arp.addMapping("action_cmd_log", "id", ActionCmdLog.class); arp.addMapping("sysuser", "id", Sysuser.class); diff --git a/ssjygl-xsx-common/src/main/java/com/cowr/model/base/BaseOssfileLog.java b/ssjygl-xsx-common/src/main/java/com/cowr/model/base/BaseOssfileLog.java new file mode 100644 index 0000000..a0db2ff --- /dev/null +++ b/ssjygl-xsx-common/src/main/java/com/cowr/model/base/BaseOssfileLog.java @@ -0,0 +1,178 @@ +package com.cowr.model.base; + +import com.cowr.common.base.BaseModel; +import com.jfinal.plugin.activerecord.IBean; +import com.alibaba.fastjson.annotation.JSONField; + +/** + * Generated by COWR Wed Sep 30 00:04:42 CST 2020 + * TableName: ossfile_log + * Remarks: 日志相关 - 文件上传至oss的状态日志 + * PrimaryKey: id + */ +@SuppressWarnings("serial") +public abstract class BaseOssfileLog> extends BaseModel implements IBean { + + public static final String tablename = "ossfile_log"; + + @JSONField(serialize=false) + public String getTablename(){ + return tablename; + } + + /** + * name: id + * type: CHAR(32) + * isNullable: NO + * isPrimaryKey: YES + * defaultValue: + * @param id uuid + */ + @JSONField(name="id") + public void setId(String id) { + set("id", id); + } + + + /** + * @return id uuid + */ + @JSONField(name="id") + public String getId() { + return getStr("id"); + } + + /** + * name: transport_id + * type: CHAR(32) + * isNullable: NO + * isPrimaryKey: NO + * defaultValue: + * @param transportId transport id + */ + @JSONField(name="transport_id") + public void setTransportId(String transportId) { + set("transport_id", transportId); + } + + + /** + * @return transport_id transport id + */ + @JSONField(name="transport_id") + public String getTransportId() { + return getStr("transport_id"); + } + + /** + * name: state + * type: SMALLINT(5) + * isNullable: NO + * isPrimaryKey: NO + * defaultValue: + * @param state 0 待上传,1上传成功 + */ + @JSONField(name="state") + public void setState(Integer state) { + set("state", state); + } + + + /** + * @return state 0 待上传,1上传成功 + */ + @JSONField(name="state") + public Integer getState() { + return getInt("state"); + } + + /** + * name: osskey + * type: VARCHAR(255) + * isNullable: NO + * isPrimaryKey: NO + * defaultValue: + * @param osskey + */ + @JSONField(name="osskey") + public void setOsskey(String osskey) { + set("osskey", osskey); + } + + + /** + * @return osskey + */ + @JSONField(name="osskey") + public String getOsskey() { + return getStr("osskey"); + } + + /** + * name: absolutepath + * type: VARCHAR(255) + * isNullable: NO + * isPrimaryKey: NO + * defaultValue: + * @param absolutepath 文件绝对路径 + */ + @JSONField(name="absolutepath") + public void setAbsolutepath(String absolutepath) { + set("absolutepath", absolutepath); + } + + + /** + * @return absolutepath 文件绝对路径 + */ + @JSONField(name="absolutepath") + public String getAbsolutepath() { + return getStr("absolutepath"); + } + + /** + * name: create_time + * type: DATETIME(19) + * isNullable: NO + * isPrimaryKey: NO + * defaultValue: + * @param createTime 创建时间 + */ + @JSONField(name="create_time") + public void setCreateTime(java.util.Date createTime) { + set("create_time", createTime); + } + + + /** + * @return create_time 创建时间 + */ + @JSONField(name="create_time") + public java.util.Date getCreateTime() { + return get("create_time"); + } + + /** + * name: change_time + * type: TIMESTAMP(19) + * isNullable: NO + * isPrimaryKey: NO + * defaultValue: CURRENT_TIMESTAMP + * @param changeTime 最后修改时间 + */ + @JSONField(name="change_time") + public void setChangeTime(java.util.Date changeTime) { + set("change_time", changeTime); + } + + + /** + * @return change_time 最后修改时间 + */ + @JSONField(name="change_time") + public java.util.Date getChangeTime() { + return get("change_time"); + } + + +} diff --git a/ssjygl-xsx-common/src/main/java/generator/Main.java b/ssjygl-xsx-common/src/main/java/generator/Main.java index f1507fc..132a7c6 100644 --- a/ssjygl-xsx-common/src/main/java/generator/Main.java +++ b/ssjygl-xsx-common/src/main/java/generator/Main.java @@ -73,6 +73,7 @@ public class Main { "invoice_receive", "invoice_log", "sms_log", + "ossfile_log", }; PropKit.use("db.properties"); diff --git a/ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/invoice/log/InvoiceLogSyncService.java b/ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/invoice/log/InvoiceLogSyncService.java index 0d3fd7c..c2910cd 100644 --- a/ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/invoice/log/InvoiceLogSyncService.java +++ b/ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/invoice/log/InvoiceLogSyncService.java @@ -15,34 +15,34 @@ import com.jfinal.kit.StrKit; import com.jfinal.log.Log; import com.jfinal.plugin.activerecord.Db; import com.jfinal.plugin.activerecord.IAtom; +import com.jfinal.plugin.activerecord.Record; import java.sql.SQLException; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; +import java.util.*; public class InvoiceLogSyncService extends BaseSyncService { - private static Log log = Log.getLog(InvoiceLogSyncService.class); - public static InvoiceLogSyncService me = new InvoiceLogSyncService(); + private static Log log = Log.getLog(InvoiceLogSyncService.class); + public static InvoiceLogSyncService me = new InvoiceLogSyncService(); /** * 添加专票 + * * @param invoice_number * @param invoice_code * @param order_sns * @param sysuser * @return */ - public Result batchSave(String invoice_number, String invoice_code, String order_sns, Sysuser sysuser){ - String[] snarr = order_sns.split(","); - List question = new ArrayList<>(); + public Result batchSave(String invoice_number, String invoice_code, String order_sns, Sysuser sysuser) { + String[] snarr = order_sns.split(","); + List question = new ArrayList<>(); List ordersnlist = new ArrayList<>(); - if(StrKit.isBlank(order_sns) || snarr.length == 0){ + if (StrKit.isBlank(order_sns) || snarr.length == 0) { return Result.failed("订单号不能为空"); } - for(String sn : snarr){ + for (String sn : snarr) { question.add("?"); ordersnlist.add(sn); } @@ -51,14 +51,14 @@ public class InvoiceLogSyncService extends BaseSyncService { " where t.invoice_code is null \n" + " and t.sn in(" + StrKit.join(question, ", ") + ")", ordersnlist.toArray()); - if(list.size() != snarr.length){ + if (list.size() != snarr.length) { return Result.failed("部分订单号未找到,或者已开票"); } - List logs = new ArrayList<>(); - SyncTask synctask = new SyncTask(); + List logs = new ArrayList<>(); + Map map = new HashMap<>(); - for(OrderTemp o : list){ + for (OrderTemp o : list) { InvoiceLog invoiceLog = new InvoiceLog(); invoiceLog.setId(StrKit.getRandomUUID()); invoiceLog.setSettlementUserId(sysuser.getId()); @@ -73,20 +73,25 @@ public class InvoiceLogSyncService extends BaseSyncService { logs.add(invoiceLog); - synctask.addSaveData(invoiceLog); - o.setInvoiceSite(2); o.setInvoiceType(2); o.setInvoiceNumber(invoice_number); o.setInvoiceCode(invoice_code); - synctask.addUpdateData(o); + int supermarket_id = o.getSupermarketId(); + + if (!map.containsKey(supermarket_id)) { + map.put(supermarket_id, new SyncTask()); + } + + map.get(supermarket_id).addUpdateData(o); + map.get(supermarket_id).addSaveData(invoiceLog); } boolean ret = Db.tx(new IAtom() { @Override public boolean run() { - try{ + try { int[] saveret = Db.batchSave(logs, logs.size()); for (int i : saveret) { @@ -105,8 +110,16 @@ public class InvoiceLogSyncService extends BaseSyncService { } } - return SyncTaskService.me.save(synctask); - }catch (Exception e){ + + // 将订单同步到不同的超市 + for (Map.Entry entry : map.entrySet()) { + if (!SyncTaskService.me.save(entry.getValue(), entry.getKey())) { + return false; + } + } + + return true; + } catch (Exception e) { log.error(e.getMessage(), e); return false; } @@ -118,12 +131,13 @@ public class InvoiceLogSyncService extends BaseSyncService { /** * 作废发票,未关联订单的(损毁等,不是正常开票使用的发票) + * * @return */ - public Result invalid(int supermarket_id, String invoice_number, String code, String invalid_memo, Sysuser sysuser){ + public Result invalid(int supermarket_id, String invoice_number, String code, String invalid_memo, Sysuser sysuser) { Supermarket supermarket = Supermarket.dao.findById(supermarket_id); - if(supermarket == null){ + if (supermarket == null) { return Result.failed("未找到超市信息"); } @@ -143,7 +157,7 @@ public class InvoiceLogSyncService extends BaseSyncService { return Result.failed("没有可用发票"); } - if(!next_invoice_code.equals(code)){ + if (!next_invoice_code.equals(code)) { return Result.failed("只能按顺序作废发票"); } @@ -165,7 +179,7 @@ public class InvoiceLogSyncService extends BaseSyncService { try { boolean ret = finalInvoiceLog.save(); - if(!ret){ + if (!ret) { return false; } @@ -196,42 +210,50 @@ public class InvoiceLogSyncService extends BaseSyncService { return ret ? Result.success(invoiceLog) : Result.failed(false, "处理失败"); } - public Result cancelByCode(String invoice_number, String code, String invalid_memo, Sysuser sysuser){ + public Result cancelByCode(String invoice_number, String code, String invalid_memo, Sysuser sysuser) { InvoiceLog invoiceLog = InvoiceLog.dao.findFirst("select * from invoice_log t where invoice_number = ? and code = ? limit 1 ", invoice_number, code); if (invoiceLog == null) { return Result.failed("未找到发票记录"); } - return cancel(invoiceLog, invalid_memo, sysuser); + return cancelType1(invoiceLog, invalid_memo, sysuser); } - public Result cancel(String id, String invalid_memo, Sysuser sysuser){ + public Result cancel(String id, String invalid_memo, Sysuser sysuser) { InvoiceLog invoiceLog = InvoiceLog.dao.findById(id); - if(invoiceLog == null){ + if (invoiceLog == null) { return Result.failed("未找到发票记录"); } - return cancel(invoiceLog, invalid_memo, sysuser); + if (invoiceLog.getInvoiceType() == 1) { + return cancelType1(invoiceLog, invalid_memo, sysuser); + } else if (invoiceLog.getInvoiceType() == 2) { + return cancelType2(invoiceLog, invalid_memo, sysuser); + } else { + return Result.failed("发票记录错误"); + } } /** + * 取消普票 * 取消已使用的发票,必须关联了订单的 + * * @param invoiceLog * @param sysuser * @return */ - public Result cancel(InvoiceLog invoiceLog, String invalid_memo, Sysuser sysuser){ - if(invoiceLog.getState() == OrderStateEnum.INVALID.getStateid()){ + public Result cancelType1(InvoiceLog invoiceLog, String invalid_memo, Sysuser sysuser) { + if (invoiceLog.getState() == OrderStateEnum.INVALID.getStateid()) { return Result.failed("记录已作废"); } InvoiceLog old = invoiceLog.clone(); BaseModel order = OrderService.me.getOrderBySn(invoiceLog.getOrderSn()); - if(order == null){ + if (order == null) { return Result.failedstr("未找到订单信息"); } @@ -244,14 +266,13 @@ public class InvoiceLogSyncService extends BaseSyncService { boolean ret = Db.tx(new IAtom() { @Override public boolean run() { - try{ + try { order.set("invoice_code", null); order.set("invoice_number", null); - order.set("invoice_type", null); order.set("invoice_site", null); boolean ret = order.update(); - if(!ret){ + if (!ret) { return false; } @@ -260,14 +281,14 @@ public class InvoiceLogSyncService extends BaseSyncService { ret = invoiceLog.update(); - if(!ret){ + if (!ret) { return false; } synctask.addUpdateData(invoiceLog); return SyncTaskService.me.save(synctask, order.getInt("supermarket_id")) && ModifyLogService.me.save(invoiceLog, old, Enums.DataOpType.UPDATE.getId(), sysuser); - }catch (Exception e){ + } catch (Exception e) { log.error(e.getMessage(), e); } return false; @@ -276,4 +297,134 @@ public class InvoiceLogSyncService extends BaseSyncService { return ret ? Result.success() : Result.failed("作废失败"); } + + + /** + * 取消专票 + * 2020-09-29 一个专票可以关联多个订单,取消专票需要将关联的订单都取消发票信息 + * + * @param invoiceLog + * @param invalid_memo + * @param sysuser + * @return + */ + public Result cancelType2(InvoiceLog invoiceLog, String invalid_memo, Sysuser sysuser) { + if (invoiceLog.getState() == OrderStateEnum.INVALID.getStateid()) { + return Result.failed("记录已作废"); + } + + List ordlist = OrderTemp.dao.find("select * from order_temp t \n" + + " where t.state = ? \n" + + " and t.invoice_type = ? \n" + + " and t.invoice_number = ? \n" + + " and t.invoice_code = ? ", + OrderStateEnum.RECEIVED.getStateid(), + invoiceLog.getInvoiceType(), + invoiceLog.getInvoiceNumber(), + invoiceLog.getCode() + ); + + if (ordlist.isEmpty()) { + return Result.failed("关联订单信息错误"); + } + + List loglist = InvoiceLog.dao.find("select * from invoice_log t \n" + + " where t.state = ? \n" + + " and t.invoice_type = ? \n" + + " and t.invoice_number = ? \n" + + " and t.code = ? ", + OrderStateEnum.RECEIVED.getStateid(), + invoiceLog.getInvoiceType(), + invoiceLog.getInvoiceNumber(), + invoiceLog.getCode() + ); + + if (ordlist.isEmpty()) { + return Result.failed("发票使用信息错误"); + } + + Map map = new HashMap<>(); + Map ordmap = new HashMap<>(); + Date now = new Date(); + Record logrecord = new Record(); + + logrecord.set("state", OrderStateEnum.INVALID.getStateid()); + logrecord.set("invoice_type", invoiceLog.getInvoiceType()); + logrecord.set("invoice_number", invoiceLog.getInvoiceNumber()); + logrecord.set("invoice_code", invoiceLog.getCode()); + + for (OrderTemp o : ordlist) { + o.setInvoiceCode(null); + o.setInvoiceNumber(null); + o.setInvoiceSite(null); + + int supermarket_id = o.getSupermarketId(); + + if (!map.containsKey(supermarket_id)) { + map.put(supermarket_id, new SyncTask()); + } + + map.get(supermarket_id).addUpdateData(o); + ordmap.put(o.getSn(), o); + } + + for (InvoiceLog o : loglist) { + o.setInvalidMemo(invalid_memo); + o.setInvalidTime(now); + o.setInvalidUserId(sysuser.getId()); + o.setInvalidUserName(sysuser.getName()); + o.setState(OrderStateEnum.INVALID.getStateid()); + + if (!ordmap.containsKey(o.getOrderSn())) { + return Result.failedstr("发票[%s|%s]未找到订单信息", o.getInvoiceNumber(), o.getCode()); + } + + int supermarket_id = ordmap.get(o.getOrderSn()).getSupermarketId(); + + if (!map.containsKey(supermarket_id)) { + map.put(supermarket_id, new SyncTask()); + } + + map.get(supermarket_id).addUpdateData(o); + } + + boolean ret = Db.tx(new IAtom() { + @Override + public boolean run() { + try { + int[] editret = Db.batchUpdate(ordlist, ordlist.size()); + + for (int i : editret) { + // 必须是每条 sql 修改一条记录 + if (i != 1) { + return false; + } + } + + editret = Db.batchUpdate(loglist, loglist.size()); + + for (int i : editret) { + // 必须是每条 sql 修改一条记录 + if (i != 1) { + return false; + } + } + + // 将订单同步到不同的超市 + for (Map.Entry entry : map.entrySet()) { + if (!SyncTaskService.me.save(entry.getValue(), entry.getKey())) { + return false; + } + } + + return ModifyLogService.me.save(InvoiceLog.tablename, "id", logrecord.toJson(), Enums.DataOpType.SAVE.getId(), sysuser); + } catch (Exception e) { + log.error(e.getMessage(), e); + return false; + } + } + }); + + return ret ? Result.success() : Result.failed("修改失败"); + } }