简化固定配额时段限制的判断及去掉转结功能
parent
579819554d
commit
f6fd4158ea
|
|
@ -343,19 +343,14 @@ public class OrderclusterService extends BaseService {
|
||||||
public List<Record> undonlist(int supermarket_id, String customer_name, String start_time, String cutoff_time) {
|
public List<Record> undonlist(int supermarket_id, String customer_name, String start_time, String cutoff_time) {
|
||||||
List<Object> ts = new ArrayList<>();
|
List<Object> ts = new ArrayList<>();
|
||||||
ts.add(OrderStateEnum.RECEIVED.getStateid());
|
ts.add(OrderStateEnum.RECEIVED.getStateid());
|
||||||
ts.add(start_time + " 00:00:00");
|
|
||||||
ts.add(cutoff_time + " 23:59:59");
|
ts.add(cutoff_time + " 23:59:59");
|
||||||
ts.add(start_time + " 00:00:00");
|
ts.add(start_time + " 00:00:00");
|
||||||
ts.add(cutoff_time + " 23:59:59");
|
|
||||||
ts.add(start_time + " 00:00:00");
|
|
||||||
ts.add(cutoff_time + " 23:59:59");
|
|
||||||
ts.add(supermarket_id);
|
ts.add(supermarket_id);
|
||||||
ts.add(customer_name);
|
ts.add(customer_name);
|
||||||
String sql = "select * from ordercluster t \n" +
|
String sql = "select * from ordercluster t \n" +
|
||||||
" where t.state < ? \n" +
|
" where t.state < ? \n" +
|
||||||
" and (t.start_time >= ? and t.start_time <= ?) \n" +
|
" and t.start_time <= ? \n" +
|
||||||
" or (t.start_time <= ? and t.cutoff_time >= ?) \n" +
|
" and t.cutoff_time >= ? \n" +
|
||||||
" or (t.cutoff_time >= ? and t.cutoff_time <= ?) \n" +
|
|
||||||
" and t.supermarket_id = ? \n" +
|
" and t.supermarket_id = ? \n" +
|
||||||
" and t.customer_name = ? ";
|
" and t.customer_name = ? ";
|
||||||
return Db.find(sql, ts.toArray());
|
return Db.find(sql, ts.toArray());
|
||||||
|
|
|
||||||
|
|
@ -245,45 +245,6 @@ 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");
|
|
||||||
String total_weight = get("total_weight");
|
|
||||||
Date start_time = getDate("start_time");
|
|
||||||
Date cutoff_time = getDate("cutoff_time");
|
|
||||||
|
|
||||||
renderJson(OrderclusterSyncService.me.forwardCluster(ordercluster_id, new BigDecimal(total_weight), start_time, 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");
|
|
||||||
String total_weight = get("total_weight");
|
|
||||||
Date start_time = getDate("start_time");
|
|
||||||
Date cutoff_time = getDate("cutoff_time");
|
|
||||||
String trucks = get("trucks");
|
|
||||||
|
|
||||||
renderJson(OrderclusterSyncService.me.forwardTemp(ordercluster_id, new BigDecimal(total_weight), start_time, cutoff_time, trucks, tokenuser));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void getMaximumConfiguration(){
|
public void getMaximumConfiguration(){
|
||||||
String unit_price = get("unit_price");
|
String unit_price = get("unit_price");
|
||||||
int customer_id=getInt("customer_id");
|
int customer_id=getInt("customer_id");
|
||||||
|
|
|
||||||
|
|
@ -302,19 +302,14 @@ public class OrderclusterSyncService extends BaseSyncService {
|
||||||
return Result.failed(StrKit.join(ts, ",") + " 车牌号在黑名单中");
|
return Result.failed(StrKit.join(ts, ",") + " 车牌号在黑名单中");
|
||||||
}
|
}
|
||||||
|
|
||||||
ts.add(0, query_cutoff_time + " 23:59:59");
|
|
||||||
ts.add(0, query_start_time + " 00:00:00");
|
|
||||||
ts.add(0, query_cutoff_time + " 23:59:59");
|
|
||||||
ts.add(0, query_start_time + " 00:00:00");
|
ts.add(0, query_start_time + " 00:00:00");
|
||||||
ts.add(0, query_cutoff_time + " 23:59:59");
|
ts.add(0, query_cutoff_time + " 23:59:59");
|
||||||
ts.add(0, query_start_time + " 00:00:00");
|
|
||||||
List<Record> chkduk = Db.find(
|
List<Record> chkduk = Db.find(
|
||||||
"select * from ordercluster_truck t \n" +
|
"select * from ordercluster_truck t \n" +
|
||||||
" left join ordercluster c on c.id = t.ordercluster_id\n" +
|
" left join ordercluster c on c.id = t.ordercluster_id\n" +
|
||||||
" where c.state < 5 \n" + // OrderStateEnum.RECEIVED.getStateid()
|
" where c.state < 5 \n" + // OrderStateEnum.RECEIVED.getStateid()
|
||||||
" and (c.start_time >= ? and c.start_time <= ?) \n" +
|
" and t.start_time <= ? \n" +
|
||||||
" or (c.start_time <= ? and c.cutoff_time >= ?) \n" +
|
" and t.cutoff_time >= ? \n" +
|
||||||
" or (c.cutoff_time >= ? and c.cutoff_time <= ?) \n" +
|
|
||||||
" and t.truck_license in (" + StrKit.join(tsql, ",") + ")", ts.toArray());
|
" and t.truck_license in (" + StrKit.join(tsql, ",") + ")", ts.toArray());
|
||||||
|
|
||||||
if (chkduk != null && !chkduk.isEmpty()) {
|
if (chkduk != null && !chkduk.isEmpty()) {
|
||||||
|
|
@ -575,20 +570,15 @@ public class OrderclusterSyncService extends BaseSyncService {
|
||||||
return Result.failed(StrKit.join(retts, ",") + " 车牌号在黑名单中");
|
return Result.failed(StrKit.join(retts, ",") + " 车牌号在黑名单中");
|
||||||
}
|
}
|
||||||
|
|
||||||
ts.add(0, query_cutoff_time + " 23:59:59");
|
|
||||||
ts.add(0, query_start_time + " 00:00:00");
|
|
||||||
ts.add(0, query_cutoff_time + " 23:59:59");
|
|
||||||
ts.add(0, query_start_time + " 00:00:00");
|
ts.add(0, query_start_time + " 00:00:00");
|
||||||
ts.add(0, query_cutoff_time + " 23:59:59");
|
ts.add(0, query_cutoff_time + " 23:59:59");
|
||||||
ts.add(0, query_start_time + " 00:00:00");
|
|
||||||
List<Record> chkduk = Db.find(
|
List<Record> chkduk = Db.find(
|
||||||
"select * from ordercluster_truck t \n" +
|
"select * from ordercluster_truck t \n" +
|
||||||
" left join ordercluster c on c.id = t.ordercluster_id\n" +
|
" left join ordercluster c on c.id = t.ordercluster_id\n" +
|
||||||
" where c.state < 5 \n" + // OrderStateEnum.RECEIVED.getStateid()
|
" where c.state < 5 \n" + // OrderStateEnum.RECEIVED.getStateid()
|
||||||
" and t.ordercluster_id <> " + oldobj.getId() +
|
" and t.ordercluster_id <> " + oldobj.getId() +
|
||||||
" and (c.start_time >= ? and c.start_time <= ?) \n" +
|
" and c.start_time <= ? \n" +
|
||||||
" or (c.start_time <= ? and c.cutoff_time >= ?) \n" +
|
" and c.cutoff_time >= ? \n" +
|
||||||
" or (c.cutoff_time >= ? and c.cutoff_time <= ?) \n" +
|
|
||||||
" and t.truck_license in (" + StrKit.join(tsql, ",") + ")", ts.toArray());
|
" and t.truck_license in (" + StrKit.join(tsql, ",") + ")", ts.toArray());
|
||||||
|
|
||||||
if (chkduk != null && !chkduk.isEmpty()) {
|
if (chkduk != null && !chkduk.isEmpty()) {
|
||||||
|
|
@ -935,460 +925,6 @@ public class OrderclusterSyncService extends BaseSyncService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 固定购砂结转
|
|
||||||
* /order/ordercluster/forwardCluster
|
|
||||||
*
|
|
||||||
* @param ordercluster_id ordercluster 的 id
|
|
||||||
* @param total_weight 结转的重量,默认哦那个剩余重量填充
|
|
||||||
* @param cutoff_time 结转目的日期
|
|
||||||
* @param sysuser
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public Result forwardCluster(int ordercluster_id, BigDecimal total_weight, Date start_time, Date cutoff_time, Sysuser sysuser) {
|
|
||||||
return forwardCluster(ordercluster_id, total_weight, start_time, cutoff_time, sysuser, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Result forwardCluster(int ordercluster_id, BigDecimal total_weight, Date start_time, Date cutoff_time, Sysuser sysuser, boolean isAuto) {
|
|
||||||
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("不是预付费用户");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 当前配额指定的客户、超市、品类对应的单价
|
|
||||||
BigDecimal unitprice = CustomerSupermarketProductService.me.getUnitPrice(oldobj.getCustomerId(), oldobj.getSupermarketId(), oldobj.getProductId());
|
|
||||||
if (unitprice == null) {
|
|
||||||
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(over_weight.add(surplus_weight.subtract(total_weight))); // 结转不完的,要留下
|
|
||||||
}
|
|
||||||
|
|
||||||
// 客户在所有砂站的未完成的配额中,未执行完成的总金额
|
|
||||||
BigDecimal undo_price = OrderclusterService.me.undoPrice(oldobj.getCustomerId());
|
|
||||||
BigDecimal plan_total_price;
|
|
||||||
if (total_weight.compareTo(surplus_weight) > 0) { // 修改后,比原来的大
|
|
||||||
BigDecimal surplus_weight_1 = total_weight.subtract(surplus_weight); // 本次修改增加的重量
|
|
||||||
BigDecimal offset_total_price = surplus_weight_1.multiply(unitprice); // 本次修改增加的价格
|
|
||||||
plan_total_price = offset_total_price.add(undo_price); // 剩余未完成金额加上本次增加的金额
|
|
||||||
} else { // 修改后比原来的小
|
|
||||||
BigDecimal surplus_weight_1 = surplus_weight.subtract(total_weight); // 本次修改增加的重量
|
|
||||||
BigDecimal offset_total_price = surplus_weight_1.multiply(unitprice); // 本次修改增加的价格
|
|
||||||
plan_total_price = undo_price.subtract(offset_total_price); // 剩余未完成金额加上本次增加的金额
|
|
||||||
}
|
|
||||||
|
|
||||||
BigDecimal availableBalance = RefundDetailService.me.getAvailableBalance(prepayCustomer.getCustomerId(), prepayCustomer.getSurplus());
|
|
||||||
|
|
||||||
if (plan_total_price.compareTo(availableBalance) > 0) {
|
|
||||||
return Result.failedstr("共计总配额达 %.2f元,客户可用余额(%.2f元)不足", plan_total_price, availableBalance);
|
|
||||||
}
|
|
||||||
|
|
||||||
List<OrderclusterTruck> octs = OrderclusterTruck.dao.find("select * from ordercluster_truck t where t.ordercluster_id = ?", ordercluster_id);
|
|
||||||
|
|
||||||
String query_start_time = DateTimeUtil.sdfhms.get().format(start_time);
|
|
||||||
String query_cutoff_time = DateTimeUtil.sdfhms.get().format(cutoff_time);
|
|
||||||
if (!octs.isEmpty()) {
|
|
||||||
// 已有车辆的,在结转前,需要将已经分配其他集团订单的车辆去掉
|
|
||||||
List<Object> ts = new ArrayList<>();
|
|
||||||
List<String> tsql = new ArrayList<>();
|
|
||||||
Map<String, OrderclusterTruck> 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(), oct);
|
|
||||||
}
|
|
||||||
|
|
||||||
ts.add(0, query_cutoff_time); // 加到查询参数里面
|
|
||||||
ts.add(0, query_start_time); // 加到查询参数里面
|
|
||||||
ts.add(0, query_cutoff_time); // 加到查询参数里面
|
|
||||||
ts.add(0, query_start_time); // 加到查询参数里面
|
|
||||||
ts.add(0, query_cutoff_time); // 加到查询参数里面
|
|
||||||
ts.add(0, query_start_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.start_time >= ? and o.start_time <= ?) \n" +
|
|
||||||
" or (o.start_time <= ? and o.cutoff_time >= ?) \n" +
|
|
||||||
" or (o.cutoff_time >= ? 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")));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
SyncTask synctask = new SyncTask();
|
|
||||||
Date now = new Date();
|
|
||||||
List<Object> ts2 = new ArrayList<>();
|
|
||||||
ts2.add( oldobj.getSupermarketId()); // 加到查询参数里面
|
|
||||||
ts2.add(0, query_cutoff_time); // 加到查询参数里面
|
|
||||||
ts2.add(0, query_start_time); // 加到查询参数里面
|
|
||||||
ts2.add(0, query_cutoff_time); // 加到查询参数里面
|
|
||||||
ts2.add(0, query_start_time); // 加到查询参数里面
|
|
||||||
ts2.add(0, query_cutoff_time); // 加到查询参数里面
|
|
||||||
ts2.add(0, query_start_time); // 加到查询参数里面
|
|
||||||
ts2.add(0, oldobj.getCustomerId()); // 加到查询参数里面
|
|
||||||
final Ordercluster[] forwardoldobj = {Ordercluster.dao.findFirst(
|
|
||||||
"select * from ordercluster t \n" +
|
|
||||||
" where t.customer_id = ? \n" +
|
|
||||||
" and (t.start_time >= ? and t.start_time <= ?) \n" +
|
|
||||||
" or (t.start_time <= ? and t.cutoff_time >= ?) \n" +
|
|
||||||
" or (t.cutoff_time >= ? and t.cutoff_time <= ?) \n" +
|
|
||||||
" and t.supermarket_id = ? \n" +
|
|
||||||
" and t.state < 5 limit 1", ts2.toArray())};
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (forwardoldobj[0] == null) {
|
|
||||||
// 新建一个
|
|
||||||
forwardoldobj[0] = oldobj.clone();
|
|
||||||
forwardoldobj[0].setId(null); // 等待数据库自增长
|
|
||||||
forwardoldobj[0].setUuid(StrKit.getRandomUUID());
|
|
||||||
forwardoldobj[0].setUnitPrice(unitprice); // 用最新的单价更新
|
|
||||||
forwardoldobj[0].setTotalWeight(total_weight);
|
|
||||||
forwardoldobj[0].setStartTime(start_time);
|
|
||||||
forwardoldobj[0].setCutoffTime(cutoff_time);
|
|
||||||
forwardoldobj[0].setCreateTime(now); // 当前系统时间
|
|
||||||
forwardoldobj[0].setCreateUserId(sysuser.getId()); // 当前用户id
|
|
||||||
forwardoldobj[0].setCreateUserName(sysuser.getName());
|
|
||||||
forwardoldobj[0].setState(OrderStateEnum.INITIAL.getStateid()); // 新增固定为 1
|
|
||||||
|
|
||||||
ret = forwardoldobj[0].save();
|
|
||||||
synctask.addSaveData(forwardoldobj[0]);
|
|
||||||
} else {
|
|
||||||
// 已有的,直接更新重量
|
|
||||||
forwardoldobj[0].setTotalWeight(forwardoldobj[0].getTotalWeight().add(total_weight));
|
|
||||||
forwardoldobj[0].setUnitPrice(unitprice); // 用最新的单价更新
|
|
||||||
|
|
||||||
ret = forwardoldobj[0].update();
|
|
||||||
synctask.addUpdateData(forwardoldobj[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
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[0].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[0].getSupermarketId());
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error(e.getMessage(), e);
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (ret) {
|
|
||||||
SyncTaskService.me.send(synctask);
|
|
||||||
|
|
||||||
if (forwardoldobj[0] != null && !isAuto && !Config.isDev()) {
|
|
||||||
SmsService.me.sendPeiE(forwardoldobj[0]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret ? Result.success() : Result.failed("操作失败");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 零散购砂结转
|
|
||||||
* /order/ordercluster/forwardTemp
|
|
||||||
*
|
|
||||||
* @param ordercluster_id ordercluster 的 id
|
|
||||||
* @param total_weight 结转的重量,默认哦那个剩余重量填充
|
|
||||||
* @param cutoff_time 结转目的日期
|
|
||||||
* @param trucks 默认用当前配额的车辆填充
|
|
||||||
* @param sysuser
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public Result forwardTemp(int ordercluster_id, BigDecimal total_weight, Date start_time, 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 unitprice = CustomerSupermarketProductService.me.getUnitPrice(oldobj.getCustomerId(), oldobj.getSupermarketId(), oldobj.getProductId());
|
|
||||||
if (unitprice == null) {
|
|
||||||
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(over_weight.add(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);
|
|
||||||
}
|
|
||||||
|
|
||||||
List<Blacklist> list = Blacklist.dao.find(
|
|
||||||
"select * from blacklist \n" +
|
|
||||||
" where remove_user_id is null \n" +
|
|
||||||
" and truck_license in (" + StrKit.join(tsql, ",") + ")", ts.toArray());
|
|
||||||
|
|
||||||
if (list != null && !list.isEmpty()) {
|
|
||||||
List<String> outts = new ArrayList<>();
|
|
||||||
|
|
||||||
for (Blacklist bl : list) {
|
|
||||||
outts.add(bl.getTruckLicense());
|
|
||||||
}
|
|
||||||
|
|
||||||
return Result.failed(StrKit.join(outts, ",") + " 车牌号在黑名单中");
|
|
||||||
}
|
|
||||||
|
|
||||||
String query_start_time = DateTimeUtil.sdfhms.get().format(start_time);
|
|
||||||
String query_cutoff_time = DateTimeUtil.sdfhms.get().format(cutoff_time);
|
|
||||||
|
|
||||||
ts.add(0, query_cutoff_time); // 加到查询参数里面
|
|
||||||
ts.add(0, query_start_time); // 加到查询参数里面
|
|
||||||
ts.add(0, query_cutoff_time); // 加到查询参数里面
|
|
||||||
ts.add(0, query_start_time); // 加到查询参数里面
|
|
||||||
ts.add(0, query_cutoff_time); // 加到查询参数里面
|
|
||||||
ts.add(0, query_start_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.start_time >= ? and o.start_time <= ?) \n" +
|
|
||||||
" or (o.start_time <= ? and o.cutoff_time >= ?) \n" +
|
|
||||||
" or (o.cutoff_time >= ? 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;
|
|
||||||
List<Object> ts2 = new ArrayList<>();
|
|
||||||
ts2.add(oldobj.getSupermarketId()); // 加到查询参数里面
|
|
||||||
ts2.add(0, query_cutoff_time); // 加到查询参数里面
|
|
||||||
ts2.add(0, query_start_time); // 加到查询参数里面
|
|
||||||
ts2.add(0, query_cutoff_time); // 加到查询参数里面
|
|
||||||
ts2.add(0, query_start_time); // 加到查询参数里面
|
|
||||||
ts2.add(0, query_cutoff_time); // 加到查询参数里面
|
|
||||||
ts2.add(0, query_start_time); // 加到查询参数里面
|
|
||||||
ts2.add(0, oldobj.getCustomerName()); // 加到查询参数里面
|
|
||||||
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.start_time >= ? and t.start_time <= ?) \n" +
|
|
||||||
" or (t.start_time <= ? and t.cutoff_time >= ?) \n" +
|
|
||||||
" or (t.cutoff_time >= ? and t.cutoff_time <= ?) \n" +
|
|
||||||
" and t.supermarket_id = ? \n" +
|
|
||||||
" and t.state < 5 limit 1", ts2.toArray());
|
|
||||||
|
|
||||||
if (forwardoldobj == null) {
|
|
||||||
// 新建一个
|
|
||||||
forwardoldobj = oldobj.clone();
|
|
||||||
forwardoldobj.setId(null); // 等待数据库自增长
|
|
||||||
forwardoldobj.setUuid(StrKit.getRandomUUID());
|
|
||||||
forwardoldobj.setUnitPrice(unitprice);
|
|
||||||
forwardoldobj.setTotalWeight(total_weight);
|
|
||||||
forwardoldobj.setStartTime(start_time);
|
|
||||||
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(forwardoldobj.getTotalWeight().add(total_weight));
|
|
||||||
forwardoldobj.setUnitPrice(unitprice);
|
|
||||||
|
|
||||||
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("操作失败");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*获取最大可购买重量
|
*获取最大可购买重量
|
||||||
* @param customer_id 客户ID
|
* @param customer_id 客户ID
|
||||||
|
|
|
||||||
|
|
@ -77,21 +77,17 @@ public class OrderclusterTruckSyncService extends BaseSyncService {
|
||||||
// 查询是否在某一时间段分配给其他集团订单
|
// 查询是否在某一时间段分配给其他集团订单
|
||||||
String start_time = DateTimeUtil.sdfhms.get().format(ordercluster.getStartTime());
|
String start_time = DateTimeUtil.sdfhms.get().format(ordercluster.getStartTime());
|
||||||
String cutoff_time = DateTimeUtil.sdfhms.get().format(ordercluster.getCutoffTime());
|
String cutoff_time = DateTimeUtil.sdfhms.get().format(ordercluster.getCutoffTime());
|
||||||
ts.add(0, cutoff_time); // 加到查询参数里面
|
|
||||||
ts.add(0, start_time); // 加到查询参数里面
|
ts.add(0, start_time); // 加到查询参数里面
|
||||||
ts.add(0, cutoff_time); // 加到查询参数里面
|
ts.add(0, cutoff_time); // 加到查询参数里面
|
||||||
ts.add(0, start_time); // 加到查询参数里面
|
|
||||||
ts.add(0, cutoff_time); // 加到查询参数里面
|
|
||||||
ts.add(0, start_time); // 加到查询参数里面
|
|
||||||
ts.add(0, ordercluster_id); // 加到查询参数里面
|
ts.add(0, ordercluster_id); // 加到查询参数里面
|
||||||
List<Record> chkduk = Db.find(
|
List<Record> chkduk = Db.find(
|
||||||
"select * from ordercluster_truck t\n" +
|
"select * from ordercluster_truck t\n" +
|
||||||
" left join ordercluster o on o.id = t.ordercluster_id\n" +
|
" left join ordercluster o on o.id = t.ordercluster_id\n" +
|
||||||
" where t.ordercluster_id <> ? \n" +
|
" where t.ordercluster_id <> ? \n" +
|
||||||
" and o.state < 5 \n" +
|
" and o.state < 5 \n" +
|
||||||
" and (o.start_time >= ? and o.start_time <= ?) \n" +
|
" and t.start_time <= ? \n" +
|
||||||
" or (o.start_time <= ? and o.cutoff_time >= ?) \n" +
|
" and t.cutoff_time >= ? \n" +
|
||||||
" or (o.cutoff_time >= ? and o.cutoff_time <= ?) \n" +
|
|
||||||
" and t.truck_license in (" + StrKit.join(tsql, ",") + ")", ts.toArray());
|
" and t.truck_license in (" + StrKit.join(tsql, ",") + ")", ts.toArray());
|
||||||
|
|
||||||
if (chkduk != null && !chkduk.isEmpty()) {
|
if (chkduk != null && !chkduk.isEmpty()) {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,43 @@
|
||||||
|
package com.cowr.service.ssjygl.truck.truckweightlimitmodifylog;
|
||||||
|
|
||||||
|
import com.cowr.common.view.PageParam;
|
||||||
|
import com.cowr.common.view.Result;
|
||||||
|
import com.cowr.model.TruckWeightLimitModifyLog;
|
||||||
|
import com.cowr.ssjygl.truck.weightlimitmodifylog.TruckWeightLimitModifyLogPKValidator;
|
||||||
|
import com.cowr.ssjygl.truck.weightlimitmodifylog.TruckWeightLimitModifyLogService;
|
||||||
|
import com.jfinal.aop.Before;
|
||||||
|
import com.jfinal.core.Controller;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generated by COWR Tue Aug 11 23:48:17 CST 2021
|
||||||
|
* TableName: truck_weight_limit_modify_log
|
||||||
|
* Remarks:
|
||||||
|
* PrimaryKey: id
|
||||||
|
*/
|
||||||
|
public class TruckWeightLimitModifyLogController extends Controller {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页查找 truck_weight_limit_modify_log
|
||||||
|
*/
|
||||||
|
public void find(){
|
||||||
|
PageParam pp = getBean(PageParam.class, "", true);
|
||||||
|
renderJson(Result.object(TruckWeightLimitModifyLogService.me.find(pp)));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按主键查找单个对象 truck_weight_limit_modify_log
|
||||||
|
*/
|
||||||
|
@Before(TruckWeightLimitModifyLogPKValidator.class)
|
||||||
|
public void get(){
|
||||||
|
TruckWeightLimitModifyLog model = getModel(TruckWeightLimitModifyLog.class, "", true); // 忽略不在model中的字段
|
||||||
|
renderJson(TruckWeightLimitModifyLogService.me.findByPk(model));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回所有 truck_weight_limit_modify_log
|
||||||
|
*/
|
||||||
|
public void list(){
|
||||||
|
renderJson(Result.object(TruckWeightLimitModifyLogService.me.list()));
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue