商品价格修改
parent
3bd78b9ae8
commit
1188bdad47
|
|
@ -118,7 +118,7 @@ public class SupermarketService extends BaseService {
|
|||
}
|
||||
Record out = supermarket.toRecord();
|
||||
|
||||
out.set("products", Db.find("select t.supermarket_id, p.id, p.name, t.unit_price from supermarket_product t\n" +
|
||||
out.set("products", Db.find("select t.supermarket_id, p.id, p.name, t.unit_price,t.product_id from supermarket_product t\n" +
|
||||
" left join product p on t.product_id = p.id \n" +
|
||||
" where t.supermarket_id = ?", id));
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,18 @@
|
|||
package com.cowr.service.ssjygl.supermarket;
|
||||
|
||||
import com.cowr.common.validator.CrudParamValidator;
|
||||
import com.cowr.common.view.Result;
|
||||
import com.jfinal.core.Controller;
|
||||
|
||||
public class SupEditProductValidator extends CrudParamValidator {
|
||||
@Override
|
||||
protected void validate(Controller c) {
|
||||
validateRequired("supermarket_id", "supermarket_id", "supermarket_id 必填");
|
||||
validateRequired("product_id", "product_id", "product_id 必填");
|
||||
validateRequired("unit_price", "unit_price", "unit_price 必填");
|
||||
}
|
||||
|
||||
protected void handleError(Controller c) {
|
||||
c.renderJson(Result.failed(getErrmsg()));
|
||||
}
|
||||
}
|
||||
|
|
@ -125,4 +125,21 @@ public class SupermarketController extends BaseController {
|
|||
|
||||
renderJson(SupermarketSyncService.me.removeProduct(supermarket_id, product_id, tokenuser));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Before(SupEditProductValidator.class)
|
||||
public void editUnitPrice() {
|
||||
Sysuser tokenuser = SysuserSyncService.me.getSysuserByToken(get("token"));
|
||||
|
||||
if (tokenuser == null) {
|
||||
renderJson(Result.noauth());
|
||||
return;
|
||||
}
|
||||
|
||||
int supermarket_id = getInt("supermarket_id");
|
||||
int product_id = getInt("product_id");
|
||||
Double unit_price = getParaToDouble("unit_price");
|
||||
renderJson(SupermarketSyncService.me.editUnitPrice(supermarket_id, product_id,unit_price, tokenuser));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.cowr.service.ssjygl.supermarket;
|
||||
|
||||
import com.cowr.common.base.BaseModel;
|
||||
import com.cowr.common.enums.Enums;
|
||||
import com.cowr.common.view.Result;
|
||||
import com.cowr.model.*;
|
||||
|
|
@ -14,6 +15,7 @@ import com.jfinal.plugin.activerecord.IAtom;
|
|||
import java.math.BigDecimal;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class SupermarketSyncService extends BaseSyncService {
|
||||
private static Log log = Log.getLog(SupermarketSyncService.class);
|
||||
|
|
@ -150,4 +152,74 @@ public class SupermarketSyncService extends BaseSyncService {
|
|||
|
||||
return Result.object(ret);
|
||||
}
|
||||
|
||||
|
||||
public Result editUnitPrice(int supermarket_id, int product_id,Double unit_price, Sysuser sysuser) {
|
||||
SupermarketProduct sp = SupermarketProduct.dao.findByIds(supermarket_id, product_id);
|
||||
BaseModel saveold = (BaseModel) sp.clone();
|
||||
if (sp == null) {
|
||||
return Result.failed("商品配置信息不存在");
|
||||
}
|
||||
if(unit_price==null ||unit_price<=0){
|
||||
return Result.failed("商品单价不能小于0");
|
||||
}
|
||||
sp.setUnitPrice(BigDecimal.valueOf(unit_price));
|
||||
String sql="select t.* from ordercluster t where t.state<5 and t.supermarket_id=? and product_id=? " +
|
||||
"and t.id not in (select b.id from customer_supermarket_product a," +
|
||||
"ordercluster b where a.customer_id=b.customer_id and a.supermarket_id=b.supermarket_id and a.product_id=b.product_id)";
|
||||
List<Ordercluster> orderclusterList=Ordercluster.dao.find(sql,supermarket_id, product_id);
|
||||
Map<Integer, SyncTask> map = new HashMap<>();
|
||||
if (orderclusterList!=null &&!orderclusterList.isEmpty()) {
|
||||
for (Ordercluster ordercluster : orderclusterList) {
|
||||
ordercluster.setUnitPrice(BigDecimal.valueOf(unit_price));
|
||||
if (!map.containsKey(ordercluster.getId())) {
|
||||
map.put(ordercluster.getSupermarketId(), new SyncTask());
|
||||
}
|
||||
map.get(ordercluster.getSupermarketId()).addUpdateData(ordercluster);
|
||||
}
|
||||
}
|
||||
boolean ret = Db.tx(new IAtom() {
|
||||
@Override
|
||||
public boolean run() {
|
||||
try {
|
||||
boolean ret = true;
|
||||
SyncTask synctask = new SyncTask();
|
||||
synctask.addUpdateData(sp);
|
||||
|
||||
Stock stock = Stock.dao.findByIds(supermarket_id, product_id);
|
||||
|
||||
if (stock != null) {
|
||||
stock.setStockWeight(new BigDecimal(0));
|
||||
synctask.addUpdateData(stock);
|
||||
|
||||
ret = stock.update();
|
||||
}
|
||||
|
||||
if (orderclusterList!=null &&!orderclusterList.isEmpty()) {
|
||||
int[] editret = Db.batchUpdate(orderclusterList, orderclusterList.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 ret && sp.update()
|
||||
&& SyncTaskService.me.save(synctask)
|
||||
&& ModifyLogService.me.save(sp, saveold, Enums.DataOpType.UPDATE.getId(), sysuser);
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return Result.object(ret);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue