添加数据处理脚本
parent
e22dd3d2cf
commit
77c8911c72
File diff suppressed because one or more lines are too long
|
|
@ -0,0 +1,136 @@
|
|||
package dataadjustment;
|
||||
|
||||
import com.cowr.common.enums.OrderStateEnum;
|
||||
import com.cowr.common.enums.OrderTypeEnum;
|
||||
import com.cowr.model.*;
|
||||
import com.cowr.service.ssjygl.supermarket.SupermarketSyncService;
|
||||
import com.cowr.service.ssjygl.synctask.SyncTaskService;
|
||||
import com.cowr.ssjygl.CacheData;
|
||||
import com.cowr.ssjygl.invoice.receive.InvoiceReceiveService;
|
||||
import com.jfinal.kit.PropKit;
|
||||
import com.jfinal.kit.StrKit;
|
||||
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
|
||||
import com.jfinal.plugin.activerecord.Db;
|
||||
import com.jfinal.plugin.activerecord.IAtom;
|
||||
import com.jfinal.plugin.druid.DruidPlugin;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author 李赛
|
||||
* @date 2022-09-28 0:30
|
||||
*/
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
|
||||
PropKit.use("db.properties");
|
||||
CacheData.service_enable = true;
|
||||
|
||||
// 在 jdbc 连接 url 字符串中添加 useInformationSchema=true 这个参数,才能通过 Connection 直接获取表的描述
|
||||
DruidPlugin dp = new DruidPlugin(PropKit.get("jdbcUrl"), PropKit.get("user"), PropKit.get("password").trim());
|
||||
dp.start();
|
||||
|
||||
ActiveRecordPlugin arp = new ActiveRecordPlugin(dp);
|
||||
arp.setTransactionLevel(Connection.TRANSACTION_READ_COMMITTED);
|
||||
_MappingKit.mapping(arp);
|
||||
|
||||
arp.start();
|
||||
|
||||
SupermarketSyncService.me.initSupCache();
|
||||
|
||||
Date now = new Date();
|
||||
List<OrderTemp> orders = OrderTemp.dao.find("select * from order_temp where customer_id = 172 and state = 5 and create_time >= '2022-03-04' and create_time < '2022-04-25'");
|
||||
|
||||
Main m = new Main();
|
||||
|
||||
Db.tx(new IAtom() {
|
||||
@Override
|
||||
public boolean run() {
|
||||
try {
|
||||
for (int i = 0; i < orders.size(); i++) {
|
||||
System.out.println("处理 " + i);
|
||||
OrderTemp o = orders.get(i);
|
||||
if (!m.pass(o, now)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private boolean pass(OrderTemp order, Date now) {
|
||||
InvoiceReceive receive = InvoiceReceiveService.me.checkReceive(order.getSupermarketId(), order.getInvoiceNumber(), order.getInvoiceCode());
|
||||
|
||||
if (receive == null) {
|
||||
System.out.println("没有有效的发票领用记录,或者订单没有开具有效的发票 " + order.getSn());
|
||||
return false;
|
||||
}
|
||||
|
||||
InvoiceInvalidVerify model = new InvoiceInvalidVerify();
|
||||
model.setId(StrKit.getRandomUUID());
|
||||
model.setSupermarketId(order.getSupermarketId());
|
||||
model.setCreateTime(now);
|
||||
|
||||
if (order.getSupermarketId() == 3) {
|
||||
model.setCreateUserId(29);
|
||||
model.setCreateUserName("瞿佳");
|
||||
} else if (order.getSupermarketId() == 5) {
|
||||
model.setCreateUserId(65);
|
||||
model.setCreateUserName("黄建阳");
|
||||
} else {
|
||||
System.out.println("supermarket 错误 " + order.getSn());
|
||||
return false;
|
||||
}
|
||||
|
||||
model.setInvoiceReceiveId(receive.getId());
|
||||
model.setOrderSn(order.getSn());
|
||||
model.setType(OrderTypeEnum.TEMP.getTypeid());
|
||||
|
||||
model.setInvalidMemo("跟换票据");
|
||||
model.setInvoiceNumber(order.getInvoiceNumber());
|
||||
model.setInvoiceCode(order.getInvoiceCode());
|
||||
|
||||
model.setVerifyUserId(48);
|
||||
model.setVerifyUserName("王乐");
|
||||
model.setMemo("同意更换");
|
||||
model.setState(2);
|
||||
|
||||
SyncTask synctask = new SyncTask();
|
||||
|
||||
InvoiceLog invoiceLog = InvoiceLog.dao.findFirst("select * from invoice_log t \n" +
|
||||
" where t.invoice_number = ? and t.code = ? limit 1 ", model.getInvoiceNumber(), model.getInvoiceCode());
|
||||
|
||||
invoiceLog.setInvalidUserId(48);
|
||||
invoiceLog.setInvalidUserName("王乐");
|
||||
invoiceLog.setInvalidTime(now);
|
||||
invoiceLog.setInvalidMemo(model.getInvalidMemo());
|
||||
invoiceLog.setState(OrderStateEnum.INVALID.getStateid());
|
||||
invoiceLog.setCode(model.getInvoiceCode());
|
||||
invoiceLog.setInvoiceNumber(model.getInvoiceNumber());
|
||||
|
||||
receive.setInvalidCount(receive.getInvalidCount() + 1); // 每次作废,作废数量加 1
|
||||
|
||||
order.setInvoiceCode(null);
|
||||
order.setInvoiceNumber(null);
|
||||
order.setInvoiceSite(2);
|
||||
order.setInvoiceType(2);
|
||||
order.setTicketCode("21070309");
|
||||
|
||||
synctask.addSaveData(model);
|
||||
|
||||
synctask.addUpdateData(receive);
|
||||
synctask.addUpdateData(invoiceLog);
|
||||
synctask.addUpdateData(order);
|
||||
|
||||
return model.save() && receive.update() && invoiceLog.update() && order.update() && SyncTaskService.me.save(synctask, model.getSupermarketId());
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue