lisai17@sina.com 2020-09-30 00:05:54 +08:00
parent 487b31b81a
commit 9b3624a0af
5 changed files with 382 additions and 37 deletions

View File

@ -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<OssfileLog> {
public static final OssfileLog dao = new OssfileLog().dao();
}

View File

@ -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);

View File

@ -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<M extends BaseOssfileLog<M>> extends BaseModel<M> 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");
}
}

View File

@ -73,6 +73,7 @@ public class Main {
"invoice_receive",
"invoice_log",
"sms_log",
"ossfile_log",
};
PropKit.use("db.properties");

View File

@ -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<String> question = new ArrayList<>();
public Result batchSave(String invoice_number, String invoice_code, String order_sns, Sysuser sysuser) {
String[] snarr = order_sns.split(",");
List<String> question = new ArrayList<>();
List<String> 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<InvoiceLog> logs = new ArrayList<>();
SyncTask synctask = new SyncTask();
List<InvoiceLog> logs = new ArrayList<>();
Map<Integer, SyncTask> 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<Integer, SyncTask> 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<OrderTemp> 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<InvoiceLog> 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<Integer, SyncTask> map = new HashMap<>();
Map<String, OrderTemp> 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<Integer, SyncTask> 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("修改失败");
}
}