dev
parent
051be87f3c
commit
4d59db7568
|
|
@ -18,6 +18,16 @@ public class InvoiceUseService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 票据使用情况统计
|
* 票据使用情况统计
|
||||||
|
* @param tm 日期 yyyy-DD-dd
|
||||||
|
* @param supermarket_id 砂站id
|
||||||
|
* @param invoice_type 发票类型 1 普票、2 专票
|
||||||
|
* @param invoice_number 发票代码
|
||||||
|
* @param invoice_code 发票号码
|
||||||
|
* @param invoice_state 发票状态 5 已使用 9 已取消
|
||||||
|
* @param order_sn 订单号
|
||||||
|
* @param truck_license 车牌号
|
||||||
|
* @param order_state 订单状态 5 已出货 9 已取消
|
||||||
|
* @return
|
||||||
*/
|
*/
|
||||||
public Record statuse(
|
public Record statuse(
|
||||||
String tm,
|
String tm,
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,26 @@
|
||||||
|
package com.cowr.service.ssjygl.order.ordercluster;
|
||||||
|
|
||||||
|
import com.cowr.common.utils.DateTimeUtil;
|
||||||
|
import com.cowr.common.validator.CrudParamValidator;
|
||||||
|
import com.cowr.common.view.Result;
|
||||||
|
import com.jfinal.core.Controller;
|
||||||
|
import com.jfinal.kit.StrKit;
|
||||||
|
|
||||||
|
public class ForwardClusterValidator extends CrudParamValidator {
|
||||||
|
@Override
|
||||||
|
protected void validate(Controller c) {
|
||||||
|
validateRequired("id", "id", "id 必填");
|
||||||
|
validateInteger("id", 1, 2147483647, "id", "id 范围 1~2147483647");
|
||||||
|
validateBigDecimal("total_weight", new java.math.BigDecimal("0.01"), new java.math.BigDecimal(9.9999999999E10), "total_weight", "total_weight 范围 0.01~9.9999999999E10");
|
||||||
|
validateDate("cutoff_time", "yyyy-MM-dd HH:mm:ss", false, "cutoff_time", "cutoff_time 格式 yyyy-MM-dd HH:mm:ss"); // 默认时间时间字符串格式,生成后根据情况调整
|
||||||
|
|
||||||
|
if (StrKit.notBlank(c.get("cutoff_time")) && DateTimeUtil.isEarlyToday(c.get("cutoff_time"))) {
|
||||||
|
addError("cutoff_time", "截止时间不能早于今天");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void handleError(Controller c) {
|
||||||
|
c.renderJson(Result.failed(getErrmsg()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,28 @@
|
||||||
|
package com.cowr.service.ssjygl.order.ordercluster;
|
||||||
|
|
||||||
|
import com.cowr.common.utils.DateTimeUtil;
|
||||||
|
import com.cowr.common.validator.CrudParamValidator;
|
||||||
|
import com.cowr.common.view.Result;
|
||||||
|
import com.jfinal.core.Controller;
|
||||||
|
import com.jfinal.kit.StrKit;
|
||||||
|
|
||||||
|
public class ForwardTempValidator extends CrudParamValidator {
|
||||||
|
@Override
|
||||||
|
protected void validate(Controller c) {
|
||||||
|
validateRequired("id", "id", "id 必填");
|
||||||
|
validateInteger("id", 1, 2147483647, "id", "id 范围 1~2147483647");
|
||||||
|
validateBigDecimal("total_weight", new java.math.BigDecimal("0.01"), new java.math.BigDecimal(9.9999999999E10), "total_weight", "total_weight 范围 0.01~9.9999999999E10");
|
||||||
|
validateDate("cutoff_time", "yyyy-MM-dd HH:mm:ss", false, "cutoff_time", "cutoff_time 格式 yyyy-MM-dd HH:mm:ss"); // 默认时间时间字符串格式,生成后根据情况调整
|
||||||
|
|
||||||
|
if (StrKit.notBlank(c.get("cutoff_time")) && DateTimeUtil.isEarlyToday(c.get("cutoff_time"))) {
|
||||||
|
addError("cutoff_time", "截止时间不能早于今天");
|
||||||
|
}
|
||||||
|
|
||||||
|
validateString("trucks", 1, 2000, "trucks", "trucks 长度 1~2000");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void handleError(Controller c) {
|
||||||
|
c.renderJson(Result.failed(getErrmsg()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -14,6 +14,7 @@ import com.cowr.ssjygl.order.ordercluster.OrderclusterValidator;
|
||||||
import com.jfinal.aop.Before;
|
import com.jfinal.aop.Before;
|
||||||
import com.jfinal.log.Log;
|
import com.jfinal.log.Log;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
public class OrderclusterController extends BaseController {
|
public class OrderclusterController extends BaseController {
|
||||||
|
|
@ -91,7 +92,7 @@ public class OrderclusterController extends BaseController {
|
||||||
}
|
}
|
||||||
|
|
||||||
Ordercluster model = getModel(Ordercluster.class, "", true); // 忽略不在model中的字段
|
Ordercluster model = getModel(Ordercluster.class, "", true); // 忽略不在model中的字段
|
||||||
renderJson(OrderclusterSyncService.me.update(model, tokenuser));
|
renderJson(OrderclusterSyncService.me.updateCluster(model, tokenuser));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Before(EditTempClusterValidator.class)
|
@Before(EditTempClusterValidator.class)
|
||||||
|
|
@ -241,4 +242,41 @@ public class OrderclusterController extends BaseController {
|
||||||
|
|
||||||
renderJson(Result.object(OrderclusterSyncService.me.complete(ordercluster_id, tokenuser)));
|
renderJson(Result.object(OrderclusterSyncService.me.complete(ordercluster_id, tokenuser)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改 ordercluster 订单簇 - 集团客户订单
|
||||||
|
*/
|
||||||
|
@Before(ForwardClusterValidator.class)
|
||||||
|
public void forwardCluster() {
|
||||||
|
Sysuser tokenuser = SysuserSyncService.me.getSysuserByToken(get("token"));
|
||||||
|
|
||||||
|
if (tokenuser == null) {
|
||||||
|
renderJson(Result.noauth());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ordercluster_id = getInt("id");
|
||||||
|
double total_weight = getParaToDouble("total_weight");
|
||||||
|
Date cutoff_time = getDate("cutoff_time");
|
||||||
|
|
||||||
|
renderJson(OrderclusterSyncService.me.forwardCluster(ordercluster_id, new BigDecimal(total_weight), cutoff_time, tokenuser));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Before(ForwardTempValidator.class)
|
||||||
|
public void forwardTemp() {
|
||||||
|
Sysuser tokenuser = SysuserSyncService.me.getSysuserByToken(get("token"));
|
||||||
|
|
||||||
|
if (tokenuser == null) {
|
||||||
|
renderJson(Result.noauth());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ordercluster_id = getInt("id");
|
||||||
|
double total_weight = getParaToDouble("total_weight");
|
||||||
|
Date cutoff_time = getDate("cutoff_time");
|
||||||
|
String trucks = get("trucks");
|
||||||
|
|
||||||
|
renderJson(OrderclusterSyncService.me.forwardTemp(ordercluster_id, new BigDecimal(total_weight), cutoff_time, trucks, tokenuser));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -711,7 +711,7 @@ public class OrderclusterSyncService extends BaseSyncService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Result update(Ordercluster model, Sysuser sysuser) {
|
public Result updateCluster(Ordercluster model, Sysuser sysuser) {
|
||||||
Ordercluster oldobj = model.findByPk();
|
Ordercluster oldobj = model.findByPk();
|
||||||
|
|
||||||
if (oldobj == null) {
|
if (oldobj == null) {
|
||||||
|
|
@ -747,7 +747,7 @@ public class OrderclusterSyncService extends BaseSyncService {
|
||||||
BigDecimal overweight = OrderclusterService.me.getOverWeightByCustomer(oldobj.getCustomerId()); // 按客户找集团订单已完成量
|
BigDecimal overweight = OrderclusterService.me.getOverWeightByCustomer(oldobj.getCustomerId()); // 按客户找集团订单已完成量
|
||||||
|
|
||||||
if (plan_total_weight.subtract(overweight).multiply(oldobj.getUnitPrice()).compareTo(prepayCustomer.getSurplus()) > 0) {
|
if (plan_total_weight.subtract(overweight).multiply(oldobj.getUnitPrice()).compareTo(prepayCustomer.getSurplus()) > 0) {
|
||||||
return Result.failedstr("剩余总配额 %.2f,客户余额(%.2f)不足", plan_total_weight.subtract(overweight), prepayCustomer.getSurplus());
|
return Result.failedstr("计划总配额 %.2f,超过了客户余额(%.2f)", plan_total_weight.subtract(overweight), prepayCustomer.getSurplus());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -851,6 +851,41 @@ public class OrderclusterSyncService extends BaseSyncService {
|
||||||
if (oldobj.getState() >= OrderStateEnum.RECEIVED.getStateid()) {
|
if (oldobj.getState() >= OrderStateEnum.RECEIVED.getStateid()) {
|
||||||
return Result.failed("已经完结或者取消的,不能再修改");
|
return Result.failed("已经完结或者取消的,不能再修改");
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
List<OrderclusterTruck> otlist = OrderclusterTruck.dao.find(
|
||||||
|
"select * from ordercluster_truck \n" +
|
||||||
|
" where ordercluster_id = ? \n", oldobj.getId());
|
||||||
|
|
||||||
|
if (!otlist.isEmpty()) {
|
||||||
|
List<String> trlist = new ArrayList<>();
|
||||||
|
List<String> chktpsql = new ArrayList<>();
|
||||||
|
|
||||||
|
// 数据库中,提交上的数据中没有的,要删掉
|
||||||
|
for (OrderclusterTruck ot : otlist) {
|
||||||
|
trlist.add(ot.getTruckLicense());
|
||||||
|
chktpsql.add("?");
|
||||||
|
}
|
||||||
|
|
||||||
|
List<String> querydel = new ArrayList<>();
|
||||||
|
querydel.add(oldobj.getSupermarketId().toString());
|
||||||
|
querydel.add(DateTimeUtil.sdf.get().format(oldobj.getCutoffTime()) + "%");
|
||||||
|
querydel.addAll(trlist);
|
||||||
|
|
||||||
|
List<Transport> chktp = Transport.dao.find("select * from transport t \n" +
|
||||||
|
" where t.state < 5 \n" +
|
||||||
|
" and t.supermarket_id = ? \n" +
|
||||||
|
" and t.in_time like ? \n" +
|
||||||
|
" and t.truck_license in(" + StrKit.join(chktpsql, ",") + ")", querydel.toArray());
|
||||||
|
|
||||||
|
if (!chktp.isEmpty()) {
|
||||||
|
List<String> errarr = new ArrayList<>();
|
||||||
|
for (Transport t : chktp) {
|
||||||
|
errarr.add(t.getTruckLicense());
|
||||||
|
}
|
||||||
|
|
||||||
|
return Result.failedstr("配额中的车辆[%s]还未结算出场,或者砂站数据还未同步至结算中心,不能结束", StrKit.join(errarr, ","));
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
|
||||||
oldobj.setState(OrderStateEnum.RECEIVED.getStateid()); // 将订单状态置为 5
|
oldobj.setState(OrderStateEnum.RECEIVED.getStateid()); // 将订单状态置为 5
|
||||||
oldobj.setCompleteTime(new Date());
|
oldobj.setCompleteTime(new Date());
|
||||||
|
|
@ -878,4 +913,377 @@ public class OrderclusterSyncService extends BaseSyncService {
|
||||||
return Result.failed("修改失败");
|
return Result.failed("修改失败");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 固定购砂结转
|
||||||
|
*
|
||||||
|
* @param ordercluster_id
|
||||||
|
* @param total_weight
|
||||||
|
* @param cutoff_time
|
||||||
|
* @param sysuser
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public Result forwardCluster(int ordercluster_id, BigDecimal total_weight, Date cutoff_time, Sysuser sysuser) {
|
||||||
|
Ordercluster oldobj = Ordercluster.dao.findById(ordercluster_id);
|
||||||
|
|
||||||
|
if (oldobj == null) {
|
||||||
|
return Result.failed(false, "按主键未找到对应记录");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (oldobj.getState() >= OrderStateEnum.RECEIVED.getStateid()) {
|
||||||
|
return Result.failed("已经完结或者取消的,不能再修改");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (oldobj.getCustomerId() == null) {
|
||||||
|
return Result.failed("固定供砂配额信息错误");
|
||||||
|
}
|
||||||
|
|
||||||
|
PrepayCustomer prepayCustomer = PrepayCustomerService.me.getPrepayCustomer(oldobj.getCustomerId());
|
||||||
|
if (prepayCustomer == null) {
|
||||||
|
return Result.failed("不是预付费用户");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 按客户查询未完成的订单量
|
||||||
|
List<Record> undonlist = OrderclusterService.me.undonlist(oldobj.getCustomerId());
|
||||||
|
|
||||||
|
if (undonlist != null && !undonlist.isEmpty()) {
|
||||||
|
BigDecimal plan_total_weight = total_weight;
|
||||||
|
|
||||||
|
for (Record record : undonlist) {
|
||||||
|
if (oldobj.getId().equals(record.getInt("id"))) {
|
||||||
|
continue; // 当前修改的记录已经做为初始值了,不再累计
|
||||||
|
}
|
||||||
|
|
||||||
|
// 累加总量
|
||||||
|
plan_total_weight = plan_total_weight.add(record.getBigDecimal("total_weight"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 按客户统计已完成量
|
||||||
|
BigDecimal overweight = OrderclusterService.me.getOverWeightByCustomer(oldobj.getCustomerId()); // 按客户找集团订单已完成量
|
||||||
|
|
||||||
|
if (plan_total_weight.subtract(overweight).multiply(oldobj.getUnitPrice()).compareTo(prepayCustomer.getSurplus()) > 0) {
|
||||||
|
return Result.failedstr("计划总配额 %.2f,超过了客户余额(%.2f)", plan_total_weight.subtract(overweight), prepayCustomer.getSurplus());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 按客户统计已完成量
|
||||||
|
BigDecimal over_weight = OrderclusterService.me.getOverWeight(oldobj.getId()); // 按客户找集团订单已完成量
|
||||||
|
BigDecimal surplus_weight = oldobj.getTotalWeight().subtract(over_weight); // 剩余未完成量
|
||||||
|
|
||||||
|
/*
|
||||||
|
1. total_weight >= surplus_weight 将旧的剩余量清 0
|
||||||
|
2. total_weight < surplus_weight 将旧的剩余量调整到 surplus_weight - total_weight
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (total_weight.compareTo(surplus_weight) >= 0) {
|
||||||
|
oldobj.setTotalWeight(over_weight); // 将总量设置成和已完成量一样,就是将余量设置为 0 了
|
||||||
|
} else {
|
||||||
|
oldobj.setTotalWeight(surplus_weight.subtract(total_weight)); // 结转不完的,要留下
|
||||||
|
}
|
||||||
|
|
||||||
|
List<OrderclusterTruck> octs = OrderclusterTruck.dao.find("select * from ordercluster_truck t where t.ordercluster_id = ?", ordercluster_id);
|
||||||
|
|
||||||
|
if (!octs.isEmpty()) {
|
||||||
|
// 已有车辆的,在结转前,需要将已经分配其他集团订单的车辆去掉
|
||||||
|
List<Object> ts = new ArrayList<>();
|
||||||
|
List<String> tsql = new ArrayList<>();
|
||||||
|
Map<String, Integer> delmap = new HashMap<>();
|
||||||
|
|
||||||
|
// 检查提交上来的车辆字符串是否用重复的
|
||||||
|
for (int i = 0; i < octs.size(); i++) {
|
||||||
|
OrderclusterTruck oct = octs.get(i);
|
||||||
|
ts.add(oct.getTruckLicense());
|
||||||
|
tsql.add("?");
|
||||||
|
|
||||||
|
delmap.put(oct.getTruckLicense(), i);
|
||||||
|
}
|
||||||
|
|
||||||
|
ts.add(0, cutoff_time); // 加到查询参数里面
|
||||||
|
ts.add(0, ordercluster_id); // 加到查询参数里面
|
||||||
|
List<Record> chkduk = Db.find(
|
||||||
|
"select * from ordercluster_truck t\n" +
|
||||||
|
" left join ordercluster o on o.id = t.ordercluster_id\n" +
|
||||||
|
" where t.ordercluster_id <> ? \n" +
|
||||||
|
" and o.state < 5 \n" +
|
||||||
|
" and o.cutoff_time = ? \n" +
|
||||||
|
" and t.truck_license in (" + StrKit.join(tsql, ",") + ")", ts.toArray());
|
||||||
|
|
||||||
|
if (chkduk != null && !chkduk.isEmpty()) {
|
||||||
|
for (Record record : chkduk) {
|
||||||
|
if (delmap.containsKey(record.getStr("truck_license"))) {
|
||||||
|
octs.remove(delmap.get(record.getStr("truck_license")).intValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SyncTask synctask = new SyncTask();
|
||||||
|
Date now = new Date();
|
||||||
|
|
||||||
|
boolean ret = Db.tx(new IAtom() {
|
||||||
|
@Override
|
||||||
|
public boolean run() throws SQLException {
|
||||||
|
try {
|
||||||
|
boolean ret = false;
|
||||||
|
|
||||||
|
if (oldobj.getState() < OrderStateEnum.RECEIVED.getStateid()) { // 没有完结的进行完结,已经完结的就不动了
|
||||||
|
oldobj.setState(OrderStateEnum.RECEIVED.getStateid()); // 将订单状态置为 5
|
||||||
|
oldobj.setCompleteTime(now);
|
||||||
|
|
||||||
|
ret = oldobj.update();
|
||||||
|
|
||||||
|
if (!ret) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
synctask.addUpdateData(oldobj);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ordercluster forwardoldobj = Ordercluster.dao.findFirst(
|
||||||
|
"select * from ordercluster t \n" +
|
||||||
|
" where t.customer_id = ? \n" +
|
||||||
|
" and t.cutoff_time = ? \n" +
|
||||||
|
" and t.state < 5 limit 1", oldobj.getCustomerId(), cutoff_time);
|
||||||
|
|
||||||
|
if (forwardoldobj == null) {
|
||||||
|
// 新建一个
|
||||||
|
forwardoldobj = oldobj.clone();
|
||||||
|
forwardoldobj.setId(null); // 等待数据库自增长
|
||||||
|
forwardoldobj.setUuid(StrKit.getRandomUUID());
|
||||||
|
forwardoldobj.setTotalWeight(total_weight);
|
||||||
|
forwardoldobj.setCutoffTime(cutoff_time);
|
||||||
|
forwardoldobj.setCreateTime(now); // 当前系统时间
|
||||||
|
forwardoldobj.setCreateUserId(sysuser.getId()); // 当前用户id
|
||||||
|
forwardoldobj.setCreateUserName(sysuser.getName());
|
||||||
|
forwardoldobj.setState(OrderStateEnum.INITIAL.getStateid()); // 新增固定为 1
|
||||||
|
|
||||||
|
ret = forwardoldobj.save();
|
||||||
|
synctask.addSaveData(forwardoldobj);
|
||||||
|
} else {
|
||||||
|
// 已有的,直接更新重量
|
||||||
|
forwardoldobj.setTotalWeight(total_weight);
|
||||||
|
|
||||||
|
ret = forwardoldobj.update();
|
||||||
|
synctask.addUpdateData(forwardoldobj);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ret) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!octs.isEmpty()) {
|
||||||
|
List<OrderclusterTruck> savelist = new ArrayList<>();
|
||||||
|
|
||||||
|
for (int i = 0; i < octs.size(); i++) {
|
||||||
|
OrderclusterTruck oldoct = octs.get(i);
|
||||||
|
|
||||||
|
OrderclusterTruck oct = new OrderclusterTruck();
|
||||||
|
oct.setId(StrKit.getRandomUUID());
|
||||||
|
oct.setOrderclusterId(forwardoldobj.getId());
|
||||||
|
oct.setTruckLicense(oldoct.getTruckLicense());
|
||||||
|
|
||||||
|
synctask.addSaveData(oct);
|
||||||
|
savelist.add(oct);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!savelist.isEmpty()) {
|
||||||
|
int[] retarr = Db.batchSave(savelist, savelist.size());
|
||||||
|
|
||||||
|
for (int i : retarr) {
|
||||||
|
// 必须是每条 sql 修改一条记录
|
||||||
|
if (i != 1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return SyncTaskService.me.save(synctask, forwardoldobj.getSupermarketId());
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error(e.getMessage(), e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (ret) {
|
||||||
|
SyncTaskService.me.send(synctask);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret ? Result.success() : Result.failed("操作失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 临时购砂结转
|
||||||
|
*
|
||||||
|
* @param ordercluster_id
|
||||||
|
* @param total_weight
|
||||||
|
* @param trucks
|
||||||
|
* @param cutoff_time
|
||||||
|
* @param sysuser
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public Result forwardTemp(int ordercluster_id, BigDecimal total_weight, Date cutoff_time, String trucks, Sysuser sysuser) {
|
||||||
|
Ordercluster oldobj = Ordercluster.dao.findById(ordercluster_id);
|
||||||
|
|
||||||
|
if (oldobj == null) {
|
||||||
|
return Result.failed(false, "按主键未找到对应记录");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (oldobj.getState() >= OrderStateEnum.RECEIVED.getStateid()) {
|
||||||
|
return Result.failed("已经完结或者取消的,不能再修改");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 按客户统计已完成量
|
||||||
|
BigDecimal over_weight = OrderclusterService.me.getOverWeight(oldobj.getId()); // 按客户找集团订单已完成量
|
||||||
|
BigDecimal surplus_weight = oldobj.getTotalWeight().subtract(over_weight); // 剩余未完成量
|
||||||
|
|
||||||
|
/*
|
||||||
|
1. total_weight >= surplus_weight 将旧的剩余量清 0
|
||||||
|
2. total_weight < surplus_weight 将旧的剩余量调整到 surplus_weight - total_weight
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (total_weight.compareTo(surplus_weight) >= 0) {
|
||||||
|
oldobj.setTotalWeight(over_weight); // 将总量设置成和已完成量一样,就是将余量设置为 0 了
|
||||||
|
} else {
|
||||||
|
oldobj.setTotalWeight(surplus_weight.subtract(total_weight)); // 结转不完的,要留下
|
||||||
|
}
|
||||||
|
|
||||||
|
String[] truckarr = trucks.split(",");
|
||||||
|
|
||||||
|
// 已有车辆的,在结转前,需要将已经分配其他集团订单的车辆去掉
|
||||||
|
List<Object> ts = new ArrayList<>();
|
||||||
|
List<String> tsql = new ArrayList<>();
|
||||||
|
Map<String, Integer> delmap = new HashMap<>();
|
||||||
|
|
||||||
|
// 检查提交上来的车辆字符串是否用重复的
|
||||||
|
for (int i = 0; i < truckarr.length; i++) {
|
||||||
|
String truck_license = truckarr[i];
|
||||||
|
ts.add(truck_license);
|
||||||
|
tsql.add("?");
|
||||||
|
|
||||||
|
delmap.put(truck_license, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
ts.add(0, cutoff_time); // 加到查询参数里面
|
||||||
|
ts.add(0, ordercluster_id); // 加到查询参数里面
|
||||||
|
List<Record> chkduk = Db.find(
|
||||||
|
"select * from ordercluster_truck t\n" +
|
||||||
|
" left join ordercluster o on o.id = t.ordercluster_id\n" +
|
||||||
|
" where t.ordercluster_id <> ? \n" +
|
||||||
|
" and o.state < 5 \n" +
|
||||||
|
" and o.cutoff_time = ? \n" +
|
||||||
|
" and t.truck_license in (" + StrKit.join(tsql, ",") + ")", ts.toArray());
|
||||||
|
|
||||||
|
if (chkduk != null && !chkduk.isEmpty()) {
|
||||||
|
for (Record record : chkduk) {
|
||||||
|
if (delmap.containsKey(record.getStr("truck_license"))) {
|
||||||
|
delmap.remove(record.getStr("truck_license"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String[] newarr = new String[delmap.keySet().size()];
|
||||||
|
delmap.keySet().toArray(newarr);
|
||||||
|
truckarr = newarr;
|
||||||
|
}
|
||||||
|
|
||||||
|
SyncTask synctask = new SyncTask();
|
||||||
|
Date now = new Date();
|
||||||
|
String[] finalTruckarr = truckarr;
|
||||||
|
|
||||||
|
boolean ret = Db.tx(new IAtom() {
|
||||||
|
@Override
|
||||||
|
public boolean run() throws SQLException {
|
||||||
|
try {
|
||||||
|
boolean ret = false;
|
||||||
|
|
||||||
|
if (oldobj.getState() < OrderStateEnum.RECEIVED.getStateid()) { // 没有完结的进行完结,已经完结的就不动了
|
||||||
|
oldobj.setState(OrderStateEnum.RECEIVED.getStateid()); // 将订单状态置为 5
|
||||||
|
oldobj.setCompleteTime(now);
|
||||||
|
|
||||||
|
ret = oldobj.update();
|
||||||
|
|
||||||
|
if (!ret) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
synctask.addUpdateData(oldobj);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Ordercluster forwardoldobj = Ordercluster.dao.findFirst(
|
||||||
|
"select * from ordercluster t \n" +
|
||||||
|
" where t.customer_name = ? \n" +
|
||||||
|
" and t.cutoff_time = ? \n" +
|
||||||
|
" and t.state < 5 limit 1", oldobj.getCustomerName(), cutoff_time);
|
||||||
|
|
||||||
|
if (forwardoldobj == null) {
|
||||||
|
// 新建一个
|
||||||
|
forwardoldobj = oldobj.clone();
|
||||||
|
forwardoldobj.setId(null); // 等待数据库自增长
|
||||||
|
forwardoldobj.setUuid(StrKit.getRandomUUID());
|
||||||
|
forwardoldobj.setTotalWeight(total_weight);
|
||||||
|
forwardoldobj.setCutoffTime(cutoff_time);
|
||||||
|
forwardoldobj.setCreateTime(now); // 当前系统时间
|
||||||
|
forwardoldobj.setCreateUserId(sysuser.getId()); // 当前用户id
|
||||||
|
forwardoldobj.setCreateUserName(sysuser.getName());
|
||||||
|
forwardoldobj.setState(OrderStateEnum.INITIAL.getStateid()); // 新增固定为 1
|
||||||
|
|
||||||
|
ret = forwardoldobj.save();
|
||||||
|
synctask.addSaveData(forwardoldobj);
|
||||||
|
} else {
|
||||||
|
// 已有的,直接更新重量
|
||||||
|
forwardoldobj.setTotalWeight(total_weight);
|
||||||
|
|
||||||
|
ret = forwardoldobj.update();
|
||||||
|
synctask.addUpdateData(forwardoldobj);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ret) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (finalTruckarr.length > 0) {
|
||||||
|
List<OrderclusterTruck> savelist = new ArrayList<>();
|
||||||
|
|
||||||
|
for (int i = 0; i < finalTruckarr.length; i++) {
|
||||||
|
String truck_license = finalTruckarr[i];
|
||||||
|
|
||||||
|
OrderclusterTruck oct = new OrderclusterTruck();
|
||||||
|
oct.setId(StrKit.getRandomUUID());
|
||||||
|
oct.setOrderclusterId(forwardoldobj.getId());
|
||||||
|
oct.setTruckLicense(truck_license);
|
||||||
|
|
||||||
|
synctask.addSaveData(oct);
|
||||||
|
savelist.add(oct);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!savelist.isEmpty()) {
|
||||||
|
int[] retarr = Db.batchSave(savelist, savelist.size());
|
||||||
|
|
||||||
|
for (int i : retarr) {
|
||||||
|
// 必须是每条 sql 修改一条记录
|
||||||
|
if (i != 1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return SyncTaskService.me.save(synctask, forwardoldobj.getSupermarketId());
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error(e.getMessage(), e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (ret) {
|
||||||
|
SyncTaskService.me.send(synctask);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret ? Result.success() : Result.failed("操作失败");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue