diff --git a/ssjygl-xsx-common/src/main/java/com/cowr/model/CustomerSupermarketProduct.java b/ssjygl-xsx-common/src/main/java/com/cowr/model/CustomerSupermarketProduct.java new file mode 100644 index 0000000..73b9621 --- /dev/null +++ b/ssjygl-xsx-common/src/main/java/com/cowr/model/CustomerSupermarketProduct.java @@ -0,0 +1,14 @@ +package com.cowr.model; + +import com.cowr.model.base.BaseCustomerSupermarketProduct; + +/** + * Generated by COWR Mon Oct 19 10:49:48 CST 2020 + * TableName: customer_supermarket_product + * Remarks: 客户相关 - 特殊客户购买单价 + * PrimaryKey: customer_id,supermarket_id,product_id + */ +@SuppressWarnings("serial") +public class CustomerSupermarketProduct extends BaseCustomerSupermarketProduct { + public static final CustomerSupermarketProduct dao = new CustomerSupermarketProduct().dao(); +} diff --git a/ssjygl-xsx-common/src/main/java/com/cowr/model/_MappingKit.java b/ssjygl-xsx-common/src/main/java/com/cowr/model/_MappingKit.java index 7415251..9255ebd 100644 --- a/ssjygl-xsx-common/src/main/java/com/cowr/model/_MappingKit.java +++ b/ssjygl-xsx-common/src/main/java/com/cowr/model/_MappingKit.java @@ -41,6 +41,8 @@ public class _MappingKit { arp.addMapping("customer_receiver", "id", CustomerReceiver.class); arp.addMapping("customer_register", "id", CustomerRegister.class); arp.addMapping("customer_contact", "id", CustomerContact.class); + // Composite Primary Key order: customer_id,supermarket_id,product_id + arp.addMapping("customer_supermarket_product", "customer_id,supermarket_id,product_id", CustomerSupermarketProduct.class); arp.addMapping("prepay_detail", "id", PrepayDetail.class); arp.addMapping("prepay_detail_state_history", "id", PrepayDetailStateHistory.class); arp.addMapping("refund_detail", "id", RefundDetail.class); diff --git a/ssjygl-xsx-common/src/main/java/com/cowr/model/base/BaseCustomerSupermarketProduct.java b/ssjygl-xsx-common/src/main/java/com/cowr/model/base/BaseCustomerSupermarketProduct.java new file mode 100644 index 0000000..5ac6a9b --- /dev/null +++ b/ssjygl-xsx-common/src/main/java/com/cowr/model/base/BaseCustomerSupermarketProduct.java @@ -0,0 +1,112 @@ +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 Mon Oct 19 10:49:48 CST 2020 + * TableName: customer_supermarket_product + * Remarks: 客户相关 - 特殊客户购买单价 + * PrimaryKey: customer_id,supermarket_id,product_id + */ +@SuppressWarnings("serial") +public abstract class BaseCustomerSupermarketProduct> extends BaseModel implements IBean { + + public static final String tablename = "customer_supermarket_product"; + + @JSONField(serialize=false) + public String getTablename(){ + return tablename; + } + + /** + * name: customer_id + * type: INT(10) + * isNullable: NO + * isPrimaryKey: YES + * defaultValue: + * @param customerId 客户id + */ + @JSONField(name="customer_id") + public void setCustomerId(Integer customerId) { + set("customer_id", customerId); + } + + + /** + * @return customer_id 客户id + */ + @JSONField(name="customer_id") + public Integer getCustomerId() { + return getInt("customer_id"); + } + + /** + * name: supermarket_id + * type: INT(10) + * isNullable: NO + * isPrimaryKey: YES + * defaultValue: + * @param supermarketId 超市id + */ + @JSONField(name="supermarket_id") + public void setSupermarketId(Integer supermarketId) { + set("supermarket_id", supermarketId); + } + + + /** + * @return supermarket_id 超市id + */ + @JSONField(name="supermarket_id") + public Integer getSupermarketId() { + return getInt("supermarket_id"); + } + + /** + * name: product_id + * type: INT(10) + * isNullable: NO + * isPrimaryKey: YES + * defaultValue: + * @param productId 商品id + */ + @JSONField(name="product_id") + public void setProductId(Integer productId) { + set("product_id", productId); + } + + + /** + * @return product_id 商品id + */ + @JSONField(name="product_id") + public Integer getProductId() { + return getInt("product_id"); + } + + /** + * name: unit_price + * type: DECIMAL(12,2) + * isNullable: NO + * isPrimaryKey: NO + * defaultValue: + * @param unitPrice 商品在超市的销售单价 + */ + @JSONField(name="unit_price") + public void setUnitPrice(java.math.BigDecimal unitPrice) { + set("unit_price", unitPrice); + } + + + /** + * @return unit_price 商品在超市的销售单价 + */ + @JSONField(name="unit_price") + public java.math.BigDecimal getUnitPrice() { + return get("unit_price"); + } + + +} diff --git a/ssjygl-xsx-common/src/main/java/com/cowr/ssjygl/customer/supermarketproduct/CustomerSupermarketProductPKValidator.java b/ssjygl-xsx-common/src/main/java/com/cowr/ssjygl/customer/supermarketproduct/CustomerSupermarketProductPKValidator.java new file mode 100644 index 0000000..9c93f4a --- /dev/null +++ b/ssjygl-xsx-common/src/main/java/com/cowr/ssjygl/customer/supermarketproduct/CustomerSupermarketProductPKValidator.java @@ -0,0 +1,28 @@ +package com.cowr.ssjygl.customer.supermarketproduct; + + +import com.cowr.common.validator.CrudParamValidator; +import com.cowr.common.view.Result; +import com.jfinal.core.Controller; + +/** + * Generated by COWR Mon Oct 19 10:49:54 CST 2020 + * TableName: customer_supermarket_product + * Remarks: 客户相关 - 特殊客户购买单价 + * PrimaryKey: customer_id,supermarket_id,product_id + */ +public class CustomerSupermarketProductPKValidator extends CrudParamValidator { + @Override + protected void validate(Controller c) { + validateRequired("customer_id", "customer_id", "customer_id 必填"); + validateInteger("customer_id", 1, 2147483647, "customer_id", "customer_id 范围 1~2147483647"); + validateRequired("supermarket_id", "supermarket_id", "supermarket_id 必填"); + validateInteger("supermarket_id", 1, 2147483647, "supermarket_id", "supermarket_id 范围 1~2147483647"); + validateRequired("product_id", "product_id", "product_id 必填"); + validateInteger("product_id", 1, 2147483647, "product_id", "product_id 范围 1~2147483647"); + } + + protected void handleError(Controller c) { + c.renderJson(Result.failed(getErrmsg())); + } +} \ No newline at end of file diff --git a/ssjygl-xsx-common/src/main/java/com/cowr/ssjygl/customer/supermarketproduct/CustomerSupermarketProductService.java b/ssjygl-xsx-common/src/main/java/com/cowr/ssjygl/customer/supermarketproduct/CustomerSupermarketProductService.java new file mode 100644 index 0000000..c11e1fb --- /dev/null +++ b/ssjygl-xsx-common/src/main/java/com/cowr/ssjygl/customer/supermarketproduct/CustomerSupermarketProductService.java @@ -0,0 +1,199 @@ +package com.cowr.ssjygl.customer.supermarketproduct; + +import com.cowr.common.base.BaseService; +import com.cowr.common.view.PageParam; +import com.cowr.common.view.Result; +import com.cowr.model.*; +import com.cowr.ssjygl.supermarket.SupermarketService; +import com.cowr.ssjygl.supermarket.product.SupermarketProductService; +import com.jfinal.kit.StrKit; +import com.jfinal.plugin.activerecord.Db; +import com.jfinal.plugin.activerecord.Page; +import com.jfinal.plugin.activerecord.Record; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * Generated by COWR Mon Oct 19 10:49:54 CST 2020 + * TableName: customer_supermarket_product + * Remarks: 客户相关 - 特殊客户购买单价 + * PrimaryKey: customer_id,supermarket_id,product_id + */ +public class CustomerSupermarketProductService extends BaseService { + public static final CustomerSupermarketProductService me = new CustomerSupermarketProductService(); + + public BigDecimal getUnitPrice(Integer customer_id, Integer supermarket_id, Integer product_id) { + BigDecimal up = null; + + if (customer_id != null) { + CustomerSupermarketProduct csp = CustomerSupermarketProduct.dao.findByIds(customer_id, supermarket_id, product_id); + + if (csp != null) { + up = csp.getUnitPrice(); + } + } + + if (up == null) { + up = SupermarketProductService.me.getUnitPrice(supermarket_id, product_id); + } + + return up; + } + + public List getAllSupProduct(Integer customer_id) { + List list = Db.find("select t.* from customer_supermarket_product t\n" + + " where t.customer_id = ? ", customer_id); + List sups = SupermarketService.me.list(); + + // 没有找到特殊的客户单价时,直接返回砂站原始单价 + if (!list.isEmpty()) { + Map map = new HashMap<>(); + for (Record record : list) { + int supermarket_id = record.getInt("supermarket_id"); + int product_id = record.getInt("product_id"); + + map.put(supermarket_id + "_" + product_id, record); + } + + for (Record record : sups) { + int supermarket_id = record.getInt("id"); + List products = record.get("products"); + + if (products != null && !products.isEmpty()) { + for (Record product : products) { + int product_id = product.getInt("id"); + String key = supermarket_id + "_" + product_id; + + if (map.containsKey(key)) { + product.set("unit_price", map.get(key).get("unit_price")); + } + } + } + } + } + + return sups; + } + + public Result get(CustomerSupermarketProduct model) { + CustomerSupermarketProduct old = model.findByPk(); + + if (old == null) { + return Result.failed("按主键未找到记录"); + } else { + Record out = old.toRecord(); + + Customer customer = Customer.dao.findById(model.getCustomerId()); + if (customer != null) { + out.set("customer_name", customer.getName()); + } + + Supermarket supermarket = Supermarket.dao.findById(model.getSupermarketId()); + + if (supermarket != null) { + out.set("supermarket_name", supermarket.getName()); + } + + Product product = Product.dao.findById(model.getProductId()); + + if (product != null) { + out.set("product_name", product.getName()); + } + + return Result.success(out); + } + } + + public Record findAllSupermarket(PageParam pp, Integer customer_id, String customer_name) { + List cols = Supermarket.dao.find("select id, name, name2 from supermarket where del = 0"); + + String selectsql = " select a.customer_id, c.name customer_name "; + String fromsql = " from (\n" + + " select t.*\n" + + " from customer_supermarket_product t\n" + + " group by t.customer_id\n" + + " ) a\n" + + " left join customer c on c.id = a.customer_id \n" + + " where 1 = 1 \n"; + List paraList = new ArrayList<>(); + + if (customer_id != null) { + fromsql += " and c.id = ? \n"; + paraList.add(customer_id); + } + + if (StrKit.notBlank(customer_name)) { + fromsql += " and c.name like ? \n"; + paraList.add("%" + customer_name.trim() + "%"); + } + + String totalRowSql = "select count(*) " + fromsql; + String findSql = selectsql + fromsql; + + findSql += " order by a.customer_id "; + + Page page = Db.paginateByFullSql(pp.getPage(), pp.getSize(), totalRowSql, findSql, paraList.toArray()); + List list = page.getList(); + + Map>> map = new HashMap<>(); + List sqlparams = new ArrayList<>(); + List params = new ArrayList<>(); + + for (Record record : list) { + sqlparams.add("?"); + params.add(record.get("customer_id")); + } + + if (!sqlparams.isEmpty()) { + List records = Db.find("select t.*, p.name product_name from customer_supermarket_product t\n" + + " left join product p on p.id = t.product_id\n" + + " where t.customer_id in (" + StrKit.join(sqlparams, ",") + ")", params.toArray()); + + for (Record record : records) { + int customer_id_product = record.getInt("customer_id"); + int supermarket_id = record.getInt("supermarket_id"); + int product_id = record.getInt("product_id"); + + if (!map.containsKey(customer_id_product)) { + map.put(customer_id_product, new HashMap<>()); + } + + if (!map.get(customer_id_product).containsKey(supermarket_id)) { + map.get(customer_id_product).put(supermarket_id, new ArrayList<>()); + } + + map.get(customer_id_product) + .get(supermarket_id) + .add( + new Record() + .set("id", product_id) + .set("name", record.get("product_name")) + .set("unit_price", record.get("unit_price")) + ); + } + + + for (Record record : list) { + int customer_id_product = record.getInt("customer_id"); + + if (map.containsKey(customer_id_product)) { + Map> smap = map.get(customer_id_product); + + for (Map.Entry> entry : smap.entrySet()) { + record.set("supermarket_" + entry.getKey(), entry.getValue()); + } + } + } + } + + Record out = new Record(); + out.set("cols", cols); + out.set("page", page); + + return out; + } +} diff --git a/ssjygl-xsx-common/src/main/java/com/cowr/ssjygl/customer/supermarketproduct/CustomerSupermarketProductValidator.java b/ssjygl-xsx-common/src/main/java/com/cowr/ssjygl/customer/supermarketproduct/CustomerSupermarketProductValidator.java new file mode 100644 index 0000000..bd9c85a --- /dev/null +++ b/ssjygl-xsx-common/src/main/java/com/cowr/ssjygl/customer/supermarketproduct/CustomerSupermarketProductValidator.java @@ -0,0 +1,50 @@ +package com.cowr.ssjygl.customer.supermarketproduct; + +import com.cowr.common.validator.CrudParamValidator; +import com.cowr.common.view.Result; +import com.cowr.model.CustomerSupermarketProduct; +import com.jfinal.core.Controller; + +/** + * Generated by COWR Mon Oct 19 10:49:54 CST 2020 + * TableName: customer_supermarket_product + * Remarks: 客户相关 - 特殊客户购买单价 + * PrimaryKey: customer_id,supermarket_id,product_id + */ +public class CustomerSupermarketProductValidator extends CrudParamValidator { + @Override + protected void validate(Controller c) { + // 默认新增时,前端不需要传主键。若需要前端传主键,需要去掉这个判断 + if (!"save".equals(getActionMethodName())) { + validateRequired("customer_id", "customer_id", "customer_id 必填"); + + validateInteger("customer_id", 1, 2147483647, "customer_id", "customer_id 范围 1~2147483647"); + } + // 默认新增时,前端不需要传主键。若需要前端传主键,需要去掉这个判断 + if (!"save".equals(getActionMethodName())) { + validateRequired("supermarket_id", "supermarket_id", "supermarket_id 必填"); + + validateInteger("supermarket_id", 1, 2147483647, "supermarket_id", "supermarket_id 范围 1~2147483647"); + } + // 默认新增时,前端不需要传主键。若需要前端传主键,需要去掉这个判断 + if (!"save".equals(getActionMethodName())) { + validateRequired("product_id", "product_id", "product_id 必填"); + + validateInteger("product_id", 1, 2147483647, "product_id", "product_id 范围 1~2147483647"); + } + + validateBigDecimal("unit_price", new java.math.BigDecimal(-9.9999999999E10), new java.math.BigDecimal(9.9999999999E10), "unit_price", "unit_price 范围 -9.9999999999E10~9.9999999999E10"); + + + // 使用 model 更新时,model 不能只有主键有值 + // 这里用 getActionMethodName 写死,判断是 update 时,才做验证 + // 如果确实是需要将主键外的字段置为 null,可以在代码生成后删掉这段 + if ("edit".equals(getActionMethodName())) { + validateUpdateModel(CustomerSupermarketProduct.class, "", true); // 忽略不在model中的字段 + } + } + + protected void handleError(Controller c) { + c.renderJson(Result.failed(getErrmsg())); + } +} \ No newline at end of file diff --git a/ssjygl-xsx-common/src/main/resources/db.properties b/ssjygl-xsx-common/src/main/resources/db.properties index cfb3e26..7a9592b 100644 --- a/ssjygl-xsx-common/src/main/resources/db.properties +++ b/ssjygl-xsx-common/src/main/resources/db.properties @@ -1,4 +1,4 @@ # mysql -jdbcUrl=jdbc:mysql://rm-wz9wa070076b2uge2ro.mysql.rds.aliyuncs.com:3306/ssjy_xsx_dev?characterEncoding=utf8&useSSL=false&zeroDateTimeBehavior=convertToNull&useInformationSchema=true&serverTimezone=GMT%2B8&autoReconnect=true +jdbcUrl=jdbc:mysql://rm-wz9wa070076b2uge2ro.mysql.rds.aliyuncs.com:3306/ssjy_xsx_service_dev?characterEncoding=utf8&useSSL=false&zeroDateTimeBehavior=convertToNull&useInformationSchema=true&serverTimezone=GMT%2B8&autoReconnect=true user=dev_ssjy_xsx password=Ssjy_xs_890 \ No newline at end of file diff --git a/ssjygl-xsx-local/src/main/java/com/cowr/local/ssjygl/customer/supermarketproduct/CustomerSupermarketProductController.java b/ssjygl-xsx-local/src/main/java/com/cowr/local/ssjygl/customer/supermarketproduct/CustomerSupermarketProductController.java new file mode 100644 index 0000000..4b2be37 --- /dev/null +++ b/ssjygl-xsx-local/src/main/java/com/cowr/local/ssjygl/customer/supermarketproduct/CustomerSupermarketProductController.java @@ -0,0 +1,41 @@ +package com.cowr.local.ssjygl.customer.supermarketproduct; + +import com.cowr.common.view.PageParam; +import com.cowr.common.view.Result; +import com.cowr.model.CustomerSupermarketProduct; +import com.cowr.model.Sysuser; +import com.cowr.local.ssjygl.system.sysuser.SysuserSyncService; +import com.cowr.ssjygl.customer.supermarketproduct.CustomerSupermarketProductPKValidator; +import com.cowr.ssjygl.customer.supermarketproduct.CustomerSupermarketProductService; +import com.cowr.ssjygl.customer.supermarketproduct.CustomerSupermarketProductValidator; +import com.jfinal.aop.Before; +import com.jfinal.core.Controller; + +/** + * Generated by COWR Mon Oct 19 10:49:54 CST 2020 + * TableName: customer_supermarket_product + * Remarks: 客户相关 - 特殊客户购买单价 + * PrimaryKey: customer_id,supermarket_id,product_id + */ +public class CustomerSupermarketProductController extends Controller { + /** + * 按主键查找单个对象 customer_supermarket_product 客户相关 - 特殊客户购买单价 + */ + @Before(CustomerSupermarketProductPKValidator.class) + public void get(){ + CustomerSupermarketProduct model = getModel(CustomerSupermarketProduct.class, "", true); // 忽略不在model中的字段 + renderJson(CustomerSupermarketProductService.me.get(model)); + } + + public void findAllSupermarket() { + PageParam pp = getBean(PageParam.class, "", true); + Integer customer_id = getInt("customer_id"); + String customer_name = get("customer_name"); + renderJson(Result.object(CustomerSupermarketProductService.me.findAllSupermarket(pp, customer_id, customer_name))); + } + + public void getAllSupProduct(){ + Integer customer_id = getInt("customer_id"); + renderJson(Result.object(CustomerSupermarketProductService.me.getAllSupProduct(customer_id))); + } +} diff --git a/ssjygl-xsx-local/src/main/java/com/cowr/local/ssjygl/main/Config.java b/ssjygl-xsx-local/src/main/java/com/cowr/local/ssjygl/main/Config.java index 5ae5084..4186d22 100644 --- a/ssjygl-xsx-local/src/main/java/com/cowr/local/ssjygl/main/Config.java +++ b/ssjygl-xsx-local/src/main/java/com/cowr/local/ssjygl/main/Config.java @@ -5,6 +5,7 @@ import com.alibaba.druid.wall.WallFilter; import com.cowr.common.ctrl.HomeController; import com.cowr.common.oss.OSSKit; import com.cowr.local.ssjygl.customer.pact.CustomerPactController; +import com.cowr.local.ssjygl.customer.supermarketproduct.CustomerSupermarketProductController; import com.cowr.ssjygl.actioncmdlog.ActionCmdLogController; import com.cowr.local.ssjygl.authlicense.AuthLicenseController; import com.cowr.local.ssjygl.authlicense.AuthLicenseSyncService; @@ -91,7 +92,7 @@ public class Config extends JFinalConfig { public static DeviceThread deviceThread = new DeviceThread(); public static SocketIOService socketio = null; private static boolean client_run = true; - public static final String CLINET_VERSION = "20201018"; + public static final String CLINET_VERSION = "20201019"; public static String getRootPath() { return PathKit.getWebRootPath() @@ -195,6 +196,7 @@ public class Config extends JFinalConfig { me.add("/customer/contact", CustomerContactController.class); me.add("/customer/receiver", CustomerReceiverController.class); me.add("/customer/pact", CustomerPactController.class); + me.add("/customer/csp", CustomerSupermarketProductController.class); // -- 预付费 me.add("/prepay", PrepayController.class); diff --git a/ssjygl-xsx-local/src/main/java/com/cowr/local/ssjygl/order/ordersale/OrderSaleSyncService.java b/ssjygl-xsx-local/src/main/java/com/cowr/local/ssjygl/order/ordersale/OrderSaleSyncService.java index 250e8cd..782635e 100644 --- a/ssjygl-xsx-local/src/main/java/com/cowr/local/ssjygl/order/ordersale/OrderSaleSyncService.java +++ b/ssjygl-xsx-local/src/main/java/com/cowr/local/ssjygl/order/ordersale/OrderSaleSyncService.java @@ -7,6 +7,7 @@ import com.cowr.common.utils.DateTimeUtil; import com.cowr.common.view.Result; import com.cowr.local.ssjygl.order.LocalOrderService; import com.cowr.local.ssjygl.order.orderseq.OrderSeqService; +import com.cowr.ssjygl.customer.supermarketproduct.CustomerSupermarketProductService; import com.cowr.ssjygl.supermarket.product.SupermarketProductService; import com.cowr.local.ssjygl.synctask.SyncTaskService; import com.cowr.local.ssjygl.system.sysuser.SysuserSyncService; @@ -76,7 +77,7 @@ public class OrderSaleSyncService { return Result.failedstr("集团订单【%s】没有配置有效的物流公司", ordercluster_id); } - BigDecimal up = SupermarketProductService.me.getUnitPrice(transport.getSupermarketId(), ordercluster.getProductId()); + BigDecimal up = CustomerSupermarketProductService.me.getUnitPrice(customer.getId(), transport.getSupermarketId(), ordercluster.getProductId()); if (up == null) { return Result.failedstr("未查到有效的单价信息"); @@ -298,7 +299,7 @@ public class OrderSaleSyncService { return Result.failedstr("【%s】不是配送预付费车辆", transport.getTruckLicense()); } - BigDecimal up = SupermarketProductService.me.getUnitPrice(transport.getSupermarketId(), ordercluster.getProductId()); + BigDecimal up = CustomerSupermarketProductService.me.getUnitPrice(customer.getId(), transport.getSupermarketId(), ordercluster.getProductId()); if (up == null) { return Result.failedstr("未查到有效的单价信息"); diff --git a/ssjygl-xsx-local/src/main/java/com/cowr/local/ssjygl/order/ordertemp/OrderTempSyncService.java b/ssjygl-xsx-local/src/main/java/com/cowr/local/ssjygl/order/ordertemp/OrderTempSyncService.java index c225ebe..e8f74b1 100644 --- a/ssjygl-xsx-local/src/main/java/com/cowr/local/ssjygl/order/ordertemp/OrderTempSyncService.java +++ b/ssjygl-xsx-local/src/main/java/com/cowr/local/ssjygl/order/ordertemp/OrderTempSyncService.java @@ -11,6 +11,7 @@ import com.cowr.local.ssjygl.main.CliCacheData; import com.cowr.local.ssjygl.main.Config; import com.cowr.local.ssjygl.order.LocalOrderService; import com.cowr.local.ssjygl.order.orderseq.OrderSeqService; +import com.cowr.ssjygl.customer.supermarketproduct.CustomerSupermarketProductService; import com.cowr.ssjygl.invoice.log.InvoiceLogService; import com.cowr.ssjygl.invoice.receive.InvoiceReceiveService; import com.cowr.ssjygl.order.ordercluster.OrderclusterService; @@ -117,7 +118,7 @@ public class OrderTempSyncService { order.setProductName(product.getName()); // 支付信息 - order.setUnitPrice(SupermarketProductService.me.getUnitPrice(transport.getSupermarketId(), product.getId())); + order.setUnitPrice(up); order.setWeight(net_weight); // 使用净重更新重量 order.setTotalPrice(TransPriceService.me.caleTotalPrice(up, net_weight)); // 获取根据净重和单价计算的总价,作为实付金额 order.setPaid(order.getTotalPrice()); // 实际应付金额,预付费走另外的接口 @@ -312,12 +313,6 @@ public class OrderTempSyncService { return Result.failedstr("净重 %.2f 吨,超过了剩余的 %.2f 余量", net_weight, ordercluster.getTotalWeight().subtract(overweight)); } - BigDecimal up = SupermarketProductService.me.getUnitPrice(transport.getSupermarketId(), ordercluster.getProductId()); - - if (up == null) { - return Result.failedstr("未查到有效的单价信息"); - } - InvoiceReceive receive = null; // 零散客户需要开具发票的,需要检查是否有有效的领用记录 @@ -355,15 +350,9 @@ public class OrderTempSyncService { order.setProductId(ordercluster.getProductId()); order.setProductName(ordercluster.getProductName()); - // 支付信息 - order.setUnitPrice(up); - order.setWeight(net_weight); // 使用净重更新重量 - order.setTotalPrice(TransPriceService.me.caleTotalPrice(up, net_weight)); // 获取根据净重和单价计算的总价,作为应付金额 - order.setPaid(order.getTotalPrice()); // 如果有预付费,该字段根据预付费情况设置。实付金额 - order.setPayType(ordercluster.getPayType()); - order.setOrderclusterId(ordercluster_id); + BigDecimal up = null; - // 客户信息 + // 客户信息 Customer customer = Customer.dao.findById(ordercluster.getCustomerId()); if (customer != null) { order.setCustomerId(customer.getId()); @@ -374,6 +363,8 @@ public class OrderTempSyncService { order.setCustomerPhone(customer.getPhone()); order.setCustomerTexpayerName(customer.getTexpayerName()); order.setCustomerTexpayerNum(customer.getTexpayerNum()); + + up = CustomerSupermarketProductService.me.getUnitPrice(customer.getId(), transport.getSupermarketId(), ordercluster.getProductId()); } else { // 可能是零散购砂客户,没有对应的客户信息记录,但是有客户名称之类的信息 order.setCustomerId(ordercluster.getCustomerId()); @@ -384,8 +375,22 @@ public class OrderTempSyncService { order.setCustomerPhone(ordercluster.getCustomerPhone()); order.setCustomerTexpayerName(ordercluster.getCustomerTexpayerName()); order.setCustomerTexpayerNum(ordercluster.getCustomerTexpayerNum()); + + up = SupermarketProductService.me.getUnitPrice(transport.getSupermarketId(), ordercluster.getProductId()); } + if (up == null) { + return Result.failedstr("未查到有效的单价信息"); + } + + // 支付信息 + order.setUnitPrice(up); + order.setWeight(net_weight); // 使用净重更新重量 + order.setTotalPrice(TransPriceService.me.caleTotalPrice(up, net_weight)); // 获取根据净重和单价计算的总价,作为应付金额 + order.setPaid(order.getTotalPrice()); // 如果有预付费,该字段根据预付费情况设置。实付金额 + order.setPayType(ordercluster.getPayType()); + order.setOrderclusterId(ordercluster_id); + // 物流公司信息 order.setTransCoId(ordercluster.getTransCoId()); order.setTransCoAddress(ordercluster.getTransCoAddress()); @@ -673,7 +678,7 @@ public class OrderTempSyncService { transport.setTransCoTexpayerName(ordercluster.getTransCoTexpayerName()); transport.setTransCoTexpayerNum(ordercluster.getTransCoTexpayerNum()); - BigDecimal up = SupermarketProductService.me.getUnitPrice(transport.getSupermarketId(), product.getId()); + BigDecimal up = CustomerSupermarketProductService.me.getUnitPrice(customer.getId(), transport.getSupermarketId(), product.getId()); if (up == null) { return Result.failedstr("未查到有效的单价信息"); @@ -858,174 +863,6 @@ public class OrderTempSyncService { return LocalOrderService.me.orderPayComplete(ret, order.toRecord(), transport, printerId); } - /** - * @param sn - * @param invalid_memo - * @param sysuser - * @param password - * @return - * @deprecated - */ - public Result cancel(String sn, String invalid_memo, Sysuser sysuser, String password) { - // TODO: 判断权限 - - OrderTemp order = OrderTemp.dao.findById(sn); - - if (order == null) { - return Result.failedstr("按订单号【%s】未找到记录", sn); - } - - int orderstate = order.getState(); - - // 订单已经完成 - if (orderstate == OrderStateEnum.RECEIVED.getStateid()) { - // 已完成订单,再删除时需要重新验证密码 - Sysuser chkuser = SysuserSyncService.me.getUserByWhere(null, sysuser.getPhone(), password); - - if (chkuser == null) { - log.debug("用户输入密码错误"); - return Result.permissionDenied(); - } - } - - if (orderstate == OrderStateEnum.INVALID.getStateid()) { - return Result.failed("订单已经取消"); - } - - order.setState(OrderStateEnum.INVALID.getStateid()); // 将订单状态置为 9 - - SyncTask synctask = new SyncTask(); - Record logrecord = new Record(); - logrecord.set("sn", sn); - logrecord.set("state", OrderStateEnum.INVALID.getStateid()); - - boolean ret = Db.tx(new IAtom() { - @Override - public boolean run() { - try { - synctask.addUpdateData(order); - - boolean ret = order.update(); - - if (!ret) { - return false; - } - -// if(oldstate == OrderStateEnum.LEAVE.getStateid() ){ -// Bocomm bocomm = Bocomm.dao.findFirst( -// "select * from bocomm t where t.order_sn = ? and t.state <= ? limit 0,1", -// sn, -// OrderStateEnum.RECEIVED.getStateid() -// ); -// -// if(bocomm != null){ -// ret = BocommService.me.closeTran(bocomm); -// } -// } - - // 是集团客户订单 -// if (order.getOrderclusterId() != null) { -// Ordercluster ordercluster = Ordercluster.dao.findById(order.getOrderclusterId()); -// -// if (ordercluster == null) { -// log.error("关联集团订单信息未找到,ordercluster_id:【%s】", order.getOrderclusterId()); -// return false; -// } -// } - - // 已开具发票 - if (order.getInvoiceCode() != null) { - InvoiceLog invoiceLog = InvoiceLog.dao.findFirst("select * from invoice_log t where code = ? limit 1 ", order.getInvoiceCode()); - - if (invoiceLog != null) { - invoiceLog.setInvalidUserId(sysuser.getId()); - invoiceLog.setInvalidUserName(sysuser.getName()); - invoiceLog.setInvalidTime(new Date()); - invoiceLog.setInvalidMemo(invalid_memo); - invoiceLog.setState(OrderStateEnum.INVALID.getStateid()); - - ret = invoiceLog.update(); - - if (!ret) { - return false; - } - - synctask.addUpdateData(invoiceLog); - } else { - log.error("订单[%s]没有找到开票记录", order.getSn()); - } - } - - // 是预付费订单 - if (order.getIsprepaid() == 1) { - Customer customer = Customer.dao.findById(order.getCustomerId()); - - if (customer == null) { - log.error("关联预付费客户信息未找到,customer_id:【%s】", order.getCustomerId()); - return false; - } - - PrepayCustomer prepayCustomer = PrepayCustomerService.me.getPrepayCustomer(customer.getId()); - - if (prepayCustomer != null) { - - if (prepayCustomer.getSurplus() == null) { - prepayCustomer.setSurplus(order.getTotalPrice()); - } else { - prepayCustomer.setSurplus(prepayCustomer.getSurplus().add(order.getTotalPrice())); - } - - synctask.addUpdateData(prepayCustomer); - - ret = prepayCustomer.update(); - } - } - - if (!ret) { - return false; - } - - Stock stock = Stock.dao.findByIds(order.getSupermarketId(), order.getProductId()); - if (stock == null) { - log.error("未找到库存信息 %s, %s", order.getSupermarketId(), order.getProductId()); - - stock = new Stock(); - stock.setProductId(order.getProductId()); - stock.setSupermarketId(order.getSupermarketId()); - stock.setStockWeight(order.getWeight()); - ret = stock.save(); - - if (!ret) { - return false; - } - synctask.addSaveData(stock); - } else { - stock.setStockWeight(order.getWeight()); // 销售减库存 - ret = stock.update(); - - if (!ret) { - return false; - } - - synctask.addUpdateData(stock); - } - - return ret && SyncTaskService.me.save(synctask) - && ModifyLogSyncService.me.save(order.tablename, "sn", logrecord.toJson(), Enums.DataOpType.UPDATE.getId(), sysuser); - } catch (Exception e) { - log.error(e.getMessage(), e); - return false; - } - } - }); - - if (ret) { - SyncTaskService.me.send(synctask); - } - - return ret ? Result.success(order) : Result.failed("取消失败"); - } - public Result invoice(String sn, String invoice_number, String invoice_code, String printerId, Sysuser sysuser) { // TODO: 判断权限 diff --git a/ssjygl-xsx-local/src/main/java/com/cowr/local/ssjygl/transport/TransportQueryService.java b/ssjygl-xsx-local/src/main/java/com/cowr/local/ssjygl/transport/TransportQueryService.java index 4df3d71..0bb17ff 100644 --- a/ssjygl-xsx-local/src/main/java/com/cowr/local/ssjygl/transport/TransportQueryService.java +++ b/ssjygl-xsx-local/src/main/java/com/cowr/local/ssjygl/transport/TransportQueryService.java @@ -8,6 +8,7 @@ import com.cowr.common.utils.ImageUtil; import com.cowr.common.view.Result; import com.cowr.local.ssjygl.main.Config; import com.cowr.local.ssjygl.order.LocalOrderService; +import com.cowr.ssjygl.customer.supermarketproduct.CustomerSupermarketProductService; import com.cowr.ssjygl.invoice.receive.InvoiceReceiveService; import com.cowr.ssjygl.order.OrderService; import com.cowr.ssjygl.order.ordercluster.truck.OrderclusterTruckService; @@ -198,7 +199,7 @@ public class TransportQueryService { } BigDecimal net_weight = transport.getSecondWeight().subtract(transport.getFirstWeight()).abs(); - BigDecimal up = SupermarketProductService.me.getUnitPrice(transport.getSupermarketId(), ordercluster.getProductId()); + BigDecimal up = CustomerSupermarketProductService.me.getUnitPrice(ordercluster.getCustomerId(), transport.getSupermarketId(), ordercluster.getProductId()); // 这里的 ordercluster.getCustomerId() 可能是 null BigDecimal total = TransPriceService.me.caleTotalPrice(up, net_weight); Record out = new Record(); diff --git a/ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/customer/supermarketproduct/CustomerSupermarketProductController.java b/ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/customer/supermarketproduct/CustomerSupermarketProductController.java new file mode 100644 index 0000000..9d921a5 --- /dev/null +++ b/ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/customer/supermarketproduct/CustomerSupermarketProductController.java @@ -0,0 +1,72 @@ +package com.cowr.service.ssjygl.customer.supermarketproduct; + +import com.cowr.common.view.PageParam; +import com.cowr.common.view.Result; +import com.cowr.model.CustomerSupermarketProduct; +import com.cowr.model.Sysuser; +import com.cowr.service.ssjygl.system.sysuser.SysuserSyncService; +import com.cowr.ssjygl.customer.supermarketproduct.CustomerSupermarketProductPKValidator; +import com.cowr.ssjygl.customer.supermarketproduct.CustomerSupermarketProductService; +import com.cowr.ssjygl.customer.supermarketproduct.CustomerSupermarketProductValidator; +import com.jfinal.aop.Before; +import com.jfinal.core.Controller; + +/** + * Generated by COWR Mon Oct 19 10:49:54 CST 2020 + * TableName: customer_supermarket_product + * Remarks: 客户相关 - 特殊客户购买单价 + * PrimaryKey: customer_id,supermarket_id,product_id + */ +public class CustomerSupermarketProductController extends Controller { + /** + * 新增 customer_supermarket_product 客户相关 - 特殊客户购买单价 + */ + @Before(CustomerSupermarketProductValidator.class) + public void saveOrUpdate(){ + Sysuser tokenuser = SysuserSyncService.me.getSysuserByToken(get("token")); + + if (tokenuser == null) { + renderJson(Result.noauth()); + return; + } + + CustomerSupermarketProduct model = getModel(CustomerSupermarketProduct.class, "", true); // 忽略不在model中的字段 + renderJson(CustomerSupermarketProductSyncService.me.saveOrUpdate(model, tokenuser)); + } + + /** + * 删除 customer_supermarket_product 客户相关 - 特殊客户购买单价 + */ + @Before(CustomerSupermarketProductPKValidator.class) + public void del(){ + Sysuser tokenuser = SysuserSyncService.me.getSysuserByToken(get("token")); + + if (tokenuser == null) { + renderJson(Result.noauth()); + return; + } + + CustomerSupermarketProduct model = getModel(CustomerSupermarketProduct.class, "", true); // 忽略不在model中的字段 + renderJson(CustomerSupermarketProductSyncService.me.delete(model, tokenuser)); + } + /** + * 按主键查找单个对象 customer_supermarket_product 客户相关 - 特殊客户购买单价 + */ + @Before(CustomerSupermarketProductPKValidator.class) + public void get(){ + CustomerSupermarketProduct model = getModel(CustomerSupermarketProduct.class, "", true); // 忽略不在model中的字段 + renderJson(CustomerSupermarketProductService.me.get(model)); + } + + public void findAllSupermarket() { + PageParam pp = getBean(PageParam.class, "", true); + Integer customer_id = getInt("customer_id"); + String customer_name = get("customer_name"); + renderJson(Result.object(CustomerSupermarketProductService.me.findAllSupermarket(pp, customer_id, customer_name))); + } + + public void getAllSupProduct(){ + Integer customer_id = getInt("customer_id"); + renderJson(Result.object(CustomerSupermarketProductService.me.getAllSupProduct(customer_id))); + } +} diff --git a/ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/customer/supermarketproduct/CustomerSupermarketProductSyncService.java b/ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/customer/supermarketproduct/CustomerSupermarketProductSyncService.java new file mode 100644 index 0000000..b556b3f --- /dev/null +++ b/ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/customer/supermarketproduct/CustomerSupermarketProductSyncService.java @@ -0,0 +1,39 @@ +package com.cowr.service.ssjygl.customer.supermarketproduct; + +import com.cowr.common.view.Result; +import com.cowr.model.*; +import com.cowr.service.ssjygl.base.BaseSyncService; +import com.cowr.service.ssjygl.main.SvrCacheData; +import com.jfinal.log.Log; + +public class CustomerSupermarketProductSyncService extends BaseSyncService { + private static Log log = Log.getLog(CustomerSupermarketProductSyncService.class); + public static CustomerSupermarketProductSyncService me = new CustomerSupermarketProductSyncService(); + + public Result saveOrUpdate(CustomerSupermarketProduct model, Sysuser sysuser) { + Customer customer = Customer.dao.findById(model.getCustomerId()); + if (customer == null) { + return Result.failed("没有找到对应客户信息"); + } + + Supermarket supermarket = SvrCacheData.SUP_CACHE.get(model.getSupermarketId()); + + if (supermarket == null) { + return Result.failed("没找到砂站信息"); + } + + Product product = Product.dao.findById(model.getProductId()); + + if (product == null) { + return Result.failed("没有找到品类信息"); + } + + CustomerSupermarketProduct old = CustomerSupermarketProduct.dao.findByIds(model.getCustomerId(), model.getSupermarketId(), model.getProductId()); + + if (old == null) { + return super.save(model, sysuser); + } else { + return super.update(model, sysuser); + } + } +} diff --git a/ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/main/Config.java b/ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/main/Config.java index 00bd121..91375dc 100644 --- a/ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/main/Config.java +++ b/ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/main/Config.java @@ -10,6 +10,7 @@ import com.cowr.service.ssjygl.customer.contact.CustomerContactController; import com.cowr.service.ssjygl.customer.pact.CustomerPactController; import com.cowr.service.ssjygl.customer.receiver.CustomerReceiverController; import com.cowr.service.ssjygl.customer.register.CustomerRegisterController; +import com.cowr.service.ssjygl.customer.supermarketproduct.CustomerSupermarketProductController; import com.cowr.service.ssjygl.driver.DriverController; import com.cowr.service.ssjygl.invoice.log.InvoiceLogController; import com.cowr.service.ssjygl.invoice.receive.InvoiceReceiveController; @@ -165,6 +166,7 @@ public class Config extends JFinalConfig { me.add("/customer/receiver", CustomerReceiverController.class); me.add("/customer/register", CustomerRegisterController.class); me.add("/customer/pact", CustomerPactController.class); + me.add("/customer/csp", CustomerSupermarketProductController.class); // -- 预付费 me.add("/prepay", PrepayController.class); diff --git a/ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/order/ordercluster/OrderclusterController.java b/ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/order/ordercluster/OrderclusterController.java index 4b4cb06..934ea8c 100644 --- a/ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/order/ordercluster/OrderclusterController.java +++ b/ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/order/ordercluster/OrderclusterController.java @@ -2,7 +2,6 @@ package com.cowr.service.ssjygl.order.ordercluster; import com.alibaba.fastjson.JSONArray; import com.cowr.common.base.BaseController; -import com.cowr.common.enums.RoleEnum; import com.cowr.common.enums.UserTypeEnum; import com.cowr.common.view.PageParam; import com.cowr.common.view.Result; @@ -60,7 +59,7 @@ public class OrderclusterController extends BaseController { int supermarket_id = getInt("supermarket_id"); String trucks = get("trucks"); - renderJson(OrderclusterSyncService.me.save(customer_name, customer_texpayer_name, customer_texpayer_num, req_receipt, total_weight, cutoff_time, supermarket_id, trucks, tokenuser)); + renderJson(OrderclusterSyncService.me.saveTemp(customer_name, customer_texpayer_name, customer_texpayer_num, req_receipt, total_weight, cutoff_time, supermarket_id, trucks, tokenuser)); } /** diff --git a/ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/order/ordercluster/OrderclusterSyncService.java b/ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/order/ordercluster/OrderclusterSyncService.java index 6fb25af..a59bcd5 100644 --- a/ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/order/ordercluster/OrderclusterSyncService.java +++ b/ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/order/ordercluster/OrderclusterSyncService.java @@ -12,6 +12,7 @@ import com.cowr.service.ssjygl.base.BaseSyncService; import com.cowr.service.ssjygl.main.SvrCacheData; import com.cowr.service.ssjygl.smslog.SmsService; import com.cowr.service.ssjygl.synctask.SyncTaskService; +import com.cowr.ssjygl.customer.supermarketproduct.CustomerSupermarketProductService; import com.cowr.ssjygl.modifylog.ModifyLogService; import com.cowr.ssjygl.order.ordercluster.OrderclusterService; import com.cowr.ssjygl.prepay.prepaycustomer.PrepayCustomerService; @@ -120,7 +121,7 @@ public class OrderclusterSyncService extends BaseSyncService { return Result.failedstr("客户[%s]在砂站[%s]还有未完成的配额", customerObj.getName(), SvrCacheData.SUP_CACHE.get(supermarket_id).getName()); } - BigDecimal unitprice = SupermarketProductService.me.getUnitPrice(supermarket_id, product.getId()); + BigDecimal unitprice = CustomerSupermarketProductService.me.getUnitPrice(customer_id, supermarket_id, product.getId()); if (unitprice == null) { return Result.failed("未配置商品单价"); } @@ -212,7 +213,7 @@ public class OrderclusterSyncService extends BaseSyncService { return ret ? Result.success() : Result.failed("创建失败"); } - public Result save( + public Result saveTemp( String customer_name, String customer_texpayer_name, String customer_texpayer_num, @@ -441,7 +442,8 @@ public class OrderclusterSyncService extends BaseSyncService { return Result.failedstr("没有找到商品信息【%s】", model.getProductId()); } - BigDecimal unitprice = SupermarketProductService.me.getUnitPrice(model.getSupermarketId(), model.getProductId()); + // 这里用 model 中的 customer_id ,不能用 customerObj 中的, customerObj 可能为 null + BigDecimal unitprice = CustomerSupermarketProductService.me.getUnitPrice(model.getCustomerId(), model.getSupermarketId(), model.getProductId()); if (unitprice == null) { return Result.failed("未配置商品单价"); }