diff --git a/ssjygl-xsx-common/src/main/java/com/cowr/model/base/BaseInvoiceReceive.java b/ssjygl-xsx-common/src/main/java/com/cowr/model/base/BaseInvoiceReceive.java index 11d64dd..f9ef088 100644 --- a/ssjygl-xsx-common/src/main/java/com/cowr/model/base/BaseInvoiceReceive.java +++ b/ssjygl-xsx-common/src/main/java/com/cowr/model/base/BaseInvoiceReceive.java @@ -5,7 +5,7 @@ import com.jfinal.plugin.activerecord.IBean; import com.alibaba.fastjson.annotation.JSONField; /** - * Generated by COWR Mon Aug 17 10:47:18 CST 2020 + * Generated by COWR Fri Aug 28 00:25:03 CST 2020 * TableName: invoice_receive * Remarks: 发票管理 - 领用记录 * PrimaryKey: id @@ -22,46 +22,24 @@ public abstract class BaseInvoiceReceive> extend /** * name: id - * type: CHAR(32) + * type: INT(10) * isNullable: NO * isPrimaryKey: YES * defaultValue: - * @param id uuid + * @param id */ @JSONField(name="id") - public void setId(String id) { + public void setId(Integer id) { set("id", id); } /** - * @return id uuid + * @return id */ @JSONField(name="id") - public String getId() { - return getStr("id"); - } - - /** - * name: num - * type: INT(10) - * isNullable: NO - * isPrimaryKey: NO - * defaultValue: - * @param num 领取数量 - */ - @JSONField(name="num") - public void setNum(Integer num) { - set("num", num); - } - - - /** - * @return num 领取数量 - */ - @JSONField(name="num") - public Integer getNum() { - return getInt("num"); + public Integer getId() { + return getInt("id"); } /** @@ -108,6 +86,28 @@ public abstract class BaseInvoiceReceive> extend return getStr("start_code"); } + /** + * name: end_code + * type: VARCHAR(20) + * isNullable: NO + * isPrimaryKey: NO + * defaultValue: + * @param endCode 发票截止号码 + */ + @JSONField(name="end_code") + public void setEndCode(String endCode) { + set("end_code", endCode); + } + + + /** + * @return end_code 发票截止号码 + */ + @JSONField(name="end_code") + public String getEndCode() { + return getStr("end_code"); + } + /** * name: current_code * type: VARCHAR(20) @@ -224,7 +224,7 @@ public abstract class BaseInvoiceReceive> extend * isNullable: NO * isPrimaryKey: NO * defaultValue: - * @param supermarketId 领取砂站id + * @param supermarketId 领取超市id */ @JSONField(name="supermarket_id") public void setSupermarketId(Integer supermarketId) { @@ -233,7 +233,7 @@ public abstract class BaseInvoiceReceive> extend /** - * @return supermarket_id 领取砂站id + * @return supermarket_id 领取超市id */ @JSONField(name="supermarket_id") public Integer getSupermarketId() { diff --git a/ssjygl-xsx-common/src/main/java/com/cowr/ssjygl/invoice/receive/InvoiceReceiveService.java b/ssjygl-xsx-common/src/main/java/com/cowr/ssjygl/invoice/receive/InvoiceReceiveService.java index 74cbdee..6de409f 100644 --- a/ssjygl-xsx-common/src/main/java/com/cowr/ssjygl/invoice/receive/InvoiceReceiveService.java +++ b/ssjygl-xsx-common/src/main/java/com/cowr/ssjygl/invoice/receive/InvoiceReceiveService.java @@ -21,6 +21,18 @@ import java.util.List; public class InvoiceReceiveService extends BaseService { public static final InvoiceReceiveService me = new InvoiceReceiveService(); + public InvoiceReceive foremostReceive(int supermarket_id) { + String sql = "select * from invoice_receive t\n" + + " where t.supermarket_id = ? \n" + + " and t.surplus > 0\n" + + " order by t.start_code asc\n" + + " limit 1"; + + InvoiceReceive receive = InvoiceReceive.dao.findFirst(sql, supermarket_id); + + return receive; + } + public Page find(PageParam pp) { String selectsql = "select * "; String fromsql = "from invoice_receive t where 1=1 "; diff --git a/ssjygl-xsx-common/src/main/java/com/cowr/ssjygl/invoice/receive/InvoiceReceiveValidator.java b/ssjygl-xsx-common/src/main/java/com/cowr/ssjygl/invoice/receive/InvoiceReceiveValidator.java index ae1d29d..1985417 100644 --- a/ssjygl-xsx-common/src/main/java/com/cowr/ssjygl/invoice/receive/InvoiceReceiveValidator.java +++ b/ssjygl-xsx-common/src/main/java/com/cowr/ssjygl/invoice/receive/InvoiceReceiveValidator.java @@ -20,12 +20,18 @@ public class InvoiceReceiveValidator extends CrudParamValidator { validateRequired("id", "id", "id 必填"); validateString("id", 1, 32, "id", "id 长度 1~32"); } - - validateInteger("num", 1, 2147483647, "num", "num 范围 1~2147483647"); + validateString("start_code", 1, 20, "start_code", "start_code 长度 1~20"); + validateString("end_code", 1, 20, "end_code", "end_code 长度 1~20"); validateInteger("receive_user_id", 1, 2147483647, "receive_user_id", "receive_user_id 范围 1~2147483647"); validateInteger("supermarket_id", 1, 2147483647, "supermarket_id", "supermarket_id 范围 1~2147483647"); + if(StrKit.notBlank(c.get("start_code"), c.get("end_code"))){ + if(c.getInt("end_code") - c.getInt("start_code") < 0){ + addError("end_code", "end_code 必须大于等于 start_code"); + } + } + // 使用 model 更新时,model 不能只有主键有值 // 这里用 getActionMethodName 写死,判断是 update 时,才做验证 // 如果确实是需要将主键外的字段置为 null,可以在代码生成后删掉这段 diff --git a/ssjygl-xsx-common/src/main/java/com/cowr/ssjygl/prepay/PrepayService.java b/ssjygl-xsx-common/src/main/java/com/cowr/ssjygl/prepay/PrepayService.java index 94f744a..d505b65 100644 --- a/ssjygl-xsx-common/src/main/java/com/cowr/ssjygl/prepay/PrepayService.java +++ b/ssjygl-xsx-common/src/main/java/com/cowr/ssjygl/prepay/PrepayService.java @@ -1,5 +1,6 @@ package com.cowr.ssjygl.prepay; +import com.cowr.common.enums.OrderTypeEnum; import com.cowr.common.utils.DateTimeUtil; import com.cowr.model.*; import com.cowr.ssjygl.CacheData; @@ -18,29 +19,27 @@ import org.apache.poi.ss.usermodel.*; import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.xssf.usermodel.XSSFWorkbook; -import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Comparator; import java.util.List; public class PrepayService { - private static Log log = Log.getLog(PrepayService.class); - public static PrepayService me = new PrepayService(); + private static Log log = Log.getLog(PrepayService.class); + public static PrepayService me = new PrepayService(); /** * 预付费用户列表 * - * @param pp 分页参数 - * @param name 客户名称 - * @param customer_id 客户id - * @param supermarket_id 超时id - * @param stm 开始时间 - * @param etm 截止时间 - * @param start 开始金额 - * @param end 截止金额 + * @param pp 分页参数 + * @param name 客户名称 + * @param customer_id 客户id + * @param stm 开始时间 + * @param etm 截止时间 + * @param start 开始金额 + * @param end 截止金额 * @return */ - public Page find(PageParam pp, String name, Integer customer_id, Integer supermarket_id, String stm, String etm, Double start, Double end) { + public Page find(PageParam pp, String name, Integer customer_id, String stm, String etm, Double start, Double end) { String selectsql = " select p.*, c.name customer_name, c.address, c.texpayer_name, c.texpayer_num, c.memo, pc.surplus, s.name supermarket_name \n"; String fromsql = " from ( \n" + " select t.customer_id, t.supermarket_id, max(t.create_time) maxtm, max(t.id) maxid from prepay_detail t \n" + @@ -49,7 +48,7 @@ public class PrepayService { " ) a \n" + " left join prepay_detail p on p.id = a.maxid \n" + " left join customer c on c.id = p.customer_id \n" + - " left join prepay_customer pc on pc.customer_id = p.customer_id and pc.supermarket_id = a.supermarket_id\n" + + " left join prepay_customer pc on pc.customer_id = p.customer_id \n" + " left join supermarket s on s.id = a.supermarket_id\n" + " where 1 = 1"; List paraList = new ArrayList<>(); @@ -64,11 +63,6 @@ public class PrepayService { paraList.add(customer_id); } - if (supermarket_id != null) { - fromsql += " and a.supermarket_id = ? \n"; - paraList.add(supermarket_id); - } - if (StrKit.notBlank(stm)) { fromsql += " and p.create_time >= ?"; paraList.add(stm); @@ -115,20 +109,24 @@ public class PrepayService { return null; } - PrepayTruck pt = PrepayTruck.dao.findFirst("select * from prepay_truck t \n" + - " where t.supermarket_id = ? \n" + - " and t.truck_license = ? \n" + + OrderclusterTruck ot = OrderclusterTruck.dao.findFirst("select * from ordercluster_truck t \n" + + " where t.truck_license = ? \n" + " and t.valid_date = ? ", - transport.getSupermarketId(), transport.getTruckLicense(), DateTimeUtil.sdf.get().format(transport.getInTime()) ); - if (pt == null) { + if (ot == null) { return null; } - Customer customer = Customer.dao.findById(pt.getCustomerId()); + Ordercluster ordercluster = Ordercluster.dao.findById(ot.getOrderclusterId()); + + if (ordercluster == null) { + return null; + } + + Customer customer = Customer.dao.findById(ordercluster.getCustomerId()); if (customer == null) { return null; @@ -142,7 +140,7 @@ public class PrepayService { PrepayCustomer prepayCustomer = PrepayCustomerService.me.getPrepayCustomer(customer.getId()); if (prepayCustomer == null) { - log.debug("未找到预付费信息 %s, %s" + customer.getId() + ", " + transport.getSupermarketId()); + log.debug("未找到预付费信息 %s, %s" + customer.getId() + ", " + transport.getSupermarketId()); return null; } @@ -158,7 +156,7 @@ public class PrepayService { out.set("prepay_truck", true); out.set("prepay_threshold", prepayCustomer.getThreshold()); - out.set("prepay_truck_type", pt.getType()); + out.set("prepay_truck_type", OrderTypeEnum.TEMP.getTypeid()); // 浠水固定只有外销 out.set("prepay_customer_id", customer.getId()); out.set("prepay_customer_name", customer.getName()); out.set("prepay_contact_name", pd.getContactName()); @@ -166,25 +164,7 @@ public class PrepayService { out.set("prepay_surplus", prepayCustomer.getSurplus()); out.set("prepay_customer", customer); out.set("prepay_customer_info", prepayCustomer); - - Truck truck = Truck.dao.findById(transport.getTruckLicense()); - - if(truck != null){ - // 预付费关联集团客户订单 - List list = Db.find("select t.*, c.`name` customer_name from ordercluster t\n" + - " left join customer c on c.id = t.customer_id\n" + - " where t.state < ? \n" + - " and t.supermarket_id = ? \n" + - " and t.trans_co_id = ? \n" + - " and t.customer_id = ? ", - OrderStateEnum.RECEIVED.getStateid(), - transport.getSupermarketId(), - truck.getTransCoId(), - pt.getCustomerId() - ); - - out.set("prepay_ordercluster", list); - } + out.set("prepay_ordercluster", ordercluster); // 预付费关联集团客户订单 List list = CustomerReceiverService.me.list(customer.getId(), null, null, transport.getSupermarketId()); @@ -332,7 +312,7 @@ public class PrepayService { // 设置表头 // 表头 start - font = wb.createFont(); + font = wb.createFont(); cellStyle = wb.createCellStyle(); font.setFontHeight((short) (10 * 20)); font.setFontName("宋体"); @@ -366,7 +346,7 @@ public class PrepayService { sum_price += DataUtil.getDefaultByRecord(record, "total_price"); row = sheet.createRow(i + 3); - a = 0; + a = 0; row.createCell(a++).setCellValue(record.getStr("sn")); row.createCell(a++).setCellValue(DateTimeUtil.sdfhms.get().format(record.getDate("arrive_time"))); row.createCell(a++).setCellValue(record.getStr("supermarket_name")); @@ -377,7 +357,7 @@ public class PrepayService { // 合计 start row = sheet.createRow(datalen + 3); - a = 0; + a = 0; row.createCell(a++).setCellValue("合计"); row.createCell(a++).setCellValue(""); row.createCell(a++).setCellValue(""); @@ -588,7 +568,7 @@ public class PrepayService { // 设置表头 // 表头 start - font = wb.createFont(); + font = wb.createFont(); cellStyle = wb.createCellStyle(); font.setFontHeight((short) (10 * 20)); font.setFontName("宋体"); @@ -618,7 +598,7 @@ public class PrepayService { sum_price += DataUtil.getDefaultByRecord(record, "amount"); row = sheet.createRow(i + 3); - a = 0; + a = 0; row.createCell(a++).setCellValue(DateTimeUtil.sdfhms.get().format(record.getDate("tm"))); row.createCell(a++).setCellValue(record.getStr("type")); row.createCell(a++).setCellValue(DataUtil.getDefaultByRecord(record, "amount")); @@ -627,7 +607,7 @@ public class PrepayService { // 合计 start row = sheet.createRow(datalen + 3); - a = 0; + a = 0; row.createCell(a++).setCellValue("合计"); row.createCell(a++).setCellValue(""); row.createCell(a++).setCellValue(sum_price); diff --git a/ssjygl-xsx-local/src/main/java/com/cowr/local/ssjygl/invoice/log/InvoiceLogSyncService.java b/ssjygl-xsx-local/src/main/java/com/cowr/local/ssjygl/invoice/log/InvoiceLogSyncService.java index 1f064fa..d13c5f1 100644 --- a/ssjygl-xsx-local/src/main/java/com/cowr/local/ssjygl/invoice/log/InvoiceLogSyncService.java +++ b/ssjygl-xsx-local/src/main/java/com/cowr/local/ssjygl/invoice/log/InvoiceLogSyncService.java @@ -1,35 +1,10 @@ package com.cowr.local.ssjygl.invoice.log; -import com.cowr.common.view.Result; import com.cowr.local.ssjygl.base.BaseSyncService; -import com.cowr.model.InvoiceReceive; import com.jfinal.log.Log; public class InvoiceLogSyncService extends BaseSyncService { private static Log log = Log.getLog(InvoiceLogSyncService.class); public static InvoiceLogSyncService me = new InvoiceLogSyncService(); - /** - * 通过第三方税盘接口获取当前的 发票号码 - * - * @param supermarket_id - * @return - */ - public String taxationLastCode(int supermarket_id) { - // TODO: 通过税盘获取当前发票号码 - return null; - } - - public InvoiceReceive lastReceive(int supermarket_id) { - String sql = "select * from invoice_receive t\n" + - " where t.supermarket_id = ? \n" + - " and t.surplus > 0\n" + - " order by t.start_code asc\n" + - " limit 1"; - - InvoiceReceive receive = InvoiceReceive.dao.findFirst(sql, supermarket_id); - - - return receive; - } } diff --git a/ssjygl-xsx-local/src/main/java/com/cowr/local/ssjygl/order/OrderService.java b/ssjygl-xsx-local/src/main/java/com/cowr/local/ssjygl/order/OrderService.java index c549eda..daa86ea 100644 --- a/ssjygl-xsx-local/src/main/java/com/cowr/local/ssjygl/order/OrderService.java +++ b/ssjygl-xsx-local/src/main/java/com/cowr/local/ssjygl/order/OrderService.java @@ -603,7 +603,6 @@ public class OrderService { return Result.failed("没有可用发票"); } - String taxation_invoice_code = InvoiceLogSyncService.me.taxationLastCode(order.getInt("supermarket_id")); String next_invoice_code; if (receive.getCurrentCode() == null) { next_invoice_code = String.format("%0" + receive.getStartCode().length() + "d", Integer.parseInt(receive.getStartCode() + 1)); @@ -611,10 +610,6 @@ public class OrderService { next_invoice_code = String.format("%0" + receive.getStartCode().length() + "d", Integer.parseInt(receive.getCurrentCode() + 1)); } - if (!next_invoice_code.equals(taxation_invoice_code)) { - return Result.failed("本地记录和税务系统不一致"); - } - order.set("invoice_code", next_invoice_code); boolean ret = Db.tx(new IAtom() { 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 939d836..0a0d3f7 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 @@ -5,10 +5,10 @@ import com.cowr.common.enums.OrderStateEnum; import com.cowr.common.enums.OrderTypeEnum; import com.cowr.common.utils.DateTimeUtil; import com.cowr.common.view.Result; -import com.cowr.local.ssjygl.invoice.log.InvoiceLogSyncService; import com.cowr.local.ssjygl.main.Config; import com.cowr.local.ssjygl.order.OrderService; import com.cowr.local.ssjygl.order.orderseq.OrderSeqService; +import com.cowr.ssjygl.invoice.receive.InvoiceReceiveService; import com.cowr.ssjygl.supermarket.product.SupermarketProductService; import com.cowr.local.ssjygl.synctask.SyncTaskService; import com.cowr.local.ssjygl.system.sysuser.SysuserSyncService; @@ -84,14 +84,14 @@ public class OrderTempSyncService { return Result.failedstr("重量数据有误,第一次称重:%.4f,第二次称重:%.4f", transport.getFirstWeight(), transport.getSecondWeight()); } - if(transport.getSecondWeight().compareTo(BigDecimal.valueOf(Config.configprop.getInt("weigh.max"))) > 0){ + if (transport.getSecondWeight().compareTo(BigDecimal.valueOf(Config.configprop.getInt("weigh.max"))) > 0) { return Result.failedstr("毛重不能超过 %.2f 吨", Config.configprop.getInt("weigh.max")); } BigDecimal net_weight = transport.getSecondWeight().subtract(transport.getFirstWeight()); // 销售的用第二次减第一次 if (req_receipt == 1) { // 需要同时开具发票 - receive = InvoiceLogSyncService.me.lastReceive(transport.getSupermarketId()); + receive = InvoiceReceiveService.me.foremostReceive(transport.getSupermarketId()); if (receive == null) { return Result.failed("没有有效的领用记录"); @@ -134,8 +134,8 @@ public class OrderTempSyncService { // 更新 transport 出入场信息 // 线下支付才同步将出入场记录设置为完成 // if (order.getPayType() == 1) { - transport.setArriveTime(now); - order.setState(OrderStateEnum.RECEIVED.getStateid()); // 直接完成,没有前面的过程 + transport.setArriveTime(now); + order.setState(OrderStateEnum.RECEIVED.getStateid()); // 直接完成,没有前面的过程 // } else { // order.setState(OrderStateEnum.LEAVE.getStateid()); // 等等付款 // } @@ -183,14 +183,24 @@ public class OrderTempSyncService { return false; } - // 各种信息都保存成功后,再提交税务系统,获取当前发票信息 // TODO:税盘接口是不是还要提交金额等开票相关的信息 - String taxation_invoice_code = InvoiceLogSyncService.me.taxationLastCode(order.getInt("supermarket_id")); + InvoiceLog invoiceLog = new InvoiceLog(); + invoiceLog.setId(StrKit.getRandomUUID()); + invoiceLog.setInvoiceReceiveId(finalReceive.getId()); + invoiceLog.setCode(finalNext_invoice_code); + invoiceLog.setState(OrderStateEnum.RECEIVED.getStateid()); + invoiceLog.setSettlementTime(now); + invoiceLog.setSettlementUserId(order.getSettlementUserId()); + invoiceLog.setSettlementUserName(order.getSettlementUserName()); + invoiceLog.setOrderSn(order.getSn()); + invoiceLog.setType(OrderTypeEnum.TEMP.getTypeid()); - if (!finalNext_invoice_code.equals(taxation_invoice_code)) { - log.error("本地记录和税务系统不一致"); + ret = invoiceLog.save(); + + if(!ret){ return false; } + synctask.addSaveData(invoiceLog); synctask.addUpdateData(finalReceive); } @@ -207,7 +217,7 @@ public class OrderTempSyncService { }); // if (order.getPayType() == 1) { - return OrderService.me.orderPayComplete(ret, order.toRecord(), transport, printerId); + return OrderService.me.orderPayComplete(ret, order.toRecord(), transport, printerId); // } else { // return ret ? Result.success(order) : Result.failed("结算失败"); // } @@ -237,7 +247,7 @@ public class OrderTempSyncService { return Result.failedstr("集团订单【%s】信息不存在", ordercluster_id); } - if(!DateTimeUtil.isToday(ordercluster.getCutoffTime())){ + if (!DateTimeUtil.isToday(ordercluster.getCutoffTime())) { return Result.failedstr("集团订单只能在%s使用", DateTimeUtil.sdfymd.get().format(ordercluster.getCutoffTime())); } @@ -279,14 +289,14 @@ public class OrderTempSyncService { return Result.failedstr("重量数据有误,第一次称重:%.4f,第二次称重:%.4f", transport.getFirstWeight(), transport.getSecondWeight()); } - if(transport.getSecondWeight().compareTo(BigDecimal.valueOf(Config.configprop.getInt("weigh.max"))) > 0){ + if (transport.getSecondWeight().compareTo(BigDecimal.valueOf(Config.configprop.getInt("weigh.max"))) > 0) { return Result.failedstr("毛重不能超过 %.2f 吨", Config.configprop.getInt("weigh.max")); } BigDecimal net_weight = transport.getSecondWeight().subtract(transport.getFirstWeight()); // 销售的用第二次减第一次 if (req_receipt == 1) { // 需要同时开具发票 - receive = InvoiceLogSyncService.me.lastReceive(transport.getSupermarketId()); + receive = InvoiceReceiveService.me.foremostReceive(transport.getSupermarketId()); if (receive == null) { return Result.failed("没有有效的领用记录"); @@ -380,6 +390,18 @@ public class OrderTempSyncService { return false; } + if(ordercluster.getState() == OrderStateEnum.INITIAL.getStateid()){ + ordercluster.setState(OrderStateEnum.ENTERED.getStateid()); + + ret = ordercluster.update(); + + if (!ret) { + return false; + } + + synctask.addUpdateData(ordercluster); + } + Stock stock = Stock.dao.findByIds(transport.getSupermarketId(), order.getProductId()); if (stock == null) { log.error("未找到库存信息 %s, %s", order.getSupermarketId(), order.getProductId()); @@ -405,14 +427,24 @@ public class OrderTempSyncService { return false; } - // 各种信息都保存成功后,再提交税务系统,获取当前发票信息 // TODO:税盘接口是不是还要提交金额等开票相关的信息 - String taxation_invoice_code = InvoiceLogSyncService.me.taxationLastCode(order.getInt("supermarket_id")); + InvoiceLog invoiceLog = new InvoiceLog(); + invoiceLog.setId(StrKit.getRandomUUID()); + invoiceLog.setInvoiceReceiveId(finalReceive.getId()); + invoiceLog.setCode(finalNext_invoice_code); + invoiceLog.setState(OrderStateEnum.RECEIVED.getStateid()); + invoiceLog.setSettlementTime(now); + invoiceLog.setSettlementUserId(order.getSettlementUserId()); + invoiceLog.setSettlementUserName(order.getSettlementUserName()); + invoiceLog.setOrderSn(order.getSn()); + invoiceLog.setType(OrderTypeEnum.TEMP.getTypeid()); - if (!finalNext_invoice_code.equals(taxation_invoice_code)) { - log.error("本地记录和税务系统不一致"); + ret = invoiceLog.save(); + + if(!ret){ return false; } + synctask.addSaveData(invoiceLog); synctask.addUpdateData(finalReceive); } @@ -459,22 +491,28 @@ public class OrderTempSyncService { return Result.failed("进出场记录已完结或者已作废,不能使用"); } - PrepayTruck pt = PrepayTruck.dao.findFirst("select * from prepay_truck t \n" + - " where t.supermarket_id = ? \n" + - " and t.truck_license = ? \n" + + OrderclusterTruck ot = OrderclusterTruck.dao.findFirst("select * from ordercluster_truck t \n" + + " where t.truck_license = ? \n" + " and t.valid_date = ? ", - transport.getSupermarketId(), transport.getTruckLicense(), DateTimeUtil.sdf.get().format(transport.getInTime()) ); - if (pt == null) { + if (ot == null) { return Result.failedstr("【%s】不是今日预付费车辆", transport.getTruckLicense()); } Customer customer; Product product; - Ordercluster ordercluster = null; + Ordercluster ordercluster = Ordercluster.dao.findById(ordercluster_id); + + if (ordercluster == null) { + return Result.failedstr("集团订单【%s】信息不存在", ordercluster_id); + } + + if (ordercluster.getState() == OrderStateEnum.INVALID.getStateid()) { + return Result.failedstr("集团订单【%s】已完结,请重新下单", ordercluster_id); + } // 验证重量 if (transport.getFirstWeight() == null @@ -486,53 +524,38 @@ public class OrderTempSyncService { return Result.failedstr("重量数据有误,第一次称重:%.4f,第二次称重:%.4f", transport.getFirstWeight(), transport.getSecondWeight()); } - if(transport.getSecondWeight().compareTo(BigDecimal.valueOf(Config.configprop.getInt("weigh.max"))) > 0){ + if (transport.getSecondWeight().compareTo(BigDecimal.valueOf(Config.configprop.getInt("weigh.max"))) > 0) { return Result.failedstr("毛重不能超过 %.2f 吨", Config.configprop.getInt("weigh.max")); } BigDecimal net_weight = transport.getSecondWeight().subtract(transport.getFirstWeight()); // 销售的用第二次减第一次 - if (ordercluster_id != null) { - ordercluster = Ordercluster.dao.findById(ordercluster_id); - if (ordercluster == null) { - return Result.failedstr("集团订单【%s】信息不存在", ordercluster_id); - } - - if (ordercluster.getState() == OrderStateEnum.INVALID.getStateid()) { - return Result.failedstr("集团订单【%s】已完结,请重新下单", ordercluster_id); - } - - if(!DateTimeUtil.isToday(ordercluster.getCutoffTime())){ - return Result.failedstr("集团订单只能在%s使用", DateTimeUtil.sdfymd.get().format(ordercluster.getCutoffTime())); - } - - customer = Customer.dao.findById(ordercluster.getCustomerId()); - product = Product.dao.findById(ordercluster.getProductId()); - - // 物流公司信息 - order.setTransCoId(ordercluster.getTransCoId()); - order.setTransCoAddress(ordercluster.getTransCoAddress()); - order.setTransCoBankAccount(ordercluster.getTransCoBankAccount()); - order.setTransCoBankName(ordercluster.getTransCoBankName()); - order.setTransCoName(ordercluster.getTransCoName()); - order.setTransCoPhone(ordercluster.getTransCoPhone()); - order.setTransCoTexpayerName(ordercluster.getTransCoTexpayerName()); - order.setTransCoTexpayerNum(ordercluster.getTransCoTexpayerNum()); - - transport.setTransCoId(ordercluster.getTransCoId()); - transport.setTransCoAddress(ordercluster.getTransCoAddress()); - transport.setTransCoBankAccount(ordercluster.getTransCoBankAccount()); - transport.setTransCoBankName(ordercluster.getTransCoBankName()); - transport.setTransCoName(ordercluster.getTransCoName()); - transport.setTransCoPhone(ordercluster.getTransCoPhone()); - transport.setTransCoTexpayerName(ordercluster.getTransCoTexpayerName()); - transport.setTransCoTexpayerNum(ordercluster.getTransCoTexpayerNum()); - } else { - customer = Customer.dao.findById(pt.getCustomerId()); - - product = Product.dao.findById(product_id); + if (!DateTimeUtil.isToday(ordercluster.getCutoffTime())) { + return Result.failedstr("集团订单只能在%s使用", DateTimeUtil.sdfymd.get().format(ordercluster.getCutoffTime())); } + customer = Customer.dao.findById(ordercluster.getCustomerId()); + product = Product.dao.findById(ordercluster.getProductId()); + + // 物流公司信息 + order.setTransCoId(ordercluster.getTransCoId()); + order.setTransCoAddress(ordercluster.getTransCoAddress()); + order.setTransCoBankAccount(ordercluster.getTransCoBankAccount()); + order.setTransCoBankName(ordercluster.getTransCoBankName()); + order.setTransCoName(ordercluster.getTransCoName()); + order.setTransCoPhone(ordercluster.getTransCoPhone()); + order.setTransCoTexpayerName(ordercluster.getTransCoTexpayerName()); + order.setTransCoTexpayerNum(ordercluster.getTransCoTexpayerNum()); + + transport.setTransCoId(ordercluster.getTransCoId()); + transport.setTransCoAddress(ordercluster.getTransCoAddress()); + transport.setTransCoBankAccount(ordercluster.getTransCoBankAccount()); + transport.setTransCoBankName(ordercluster.getTransCoBankName()); + transport.setTransCoName(ordercluster.getTransCoName()); + transport.setTransCoPhone(ordercluster.getTransCoPhone()); + transport.setTransCoTexpayerName(ordercluster.getTransCoTexpayerName()); + transport.setTransCoTexpayerNum(ordercluster.getTransCoTexpayerNum()); + if (product == null) { return Result.failedstr("未找到有效的品类信息"); } @@ -567,7 +590,7 @@ public class OrderTempSyncService { String next_invoice_code = null; if (req_receipt == 1) { // 需要同时开具发票 - receive = InvoiceLogSyncService.me.lastReceive(transport.getSupermarketId()); + receive = InvoiceReceiveService.me.foremostReceive(transport.getSupermarketId()); if (receive == null) { return Result.failed("没有有效的领用记录"); @@ -626,6 +649,10 @@ public class OrderTempSyncService { transport.setArriveTime(now); transport.setType(OrderTypeEnum.TEMP.getTypeid()); + if (prepayCustomer.getSurplus().compareTo(order.getTotalPrice()) < 1) { + return Result.failedstr("总价 %.2f,客户余额(%.2f)不足以支付"); + } + InvoiceReceive finalReceive = receive; String finalNext_invoice_code = next_invoice_code; boolean ret = Db.tx(new IAtom() { @@ -641,75 +668,12 @@ public class OrderTempSyncService { order.setPrepayCustomerId(prepayCustomer.getId()); prepayCustomer.setSpendTime(now); - if (prepayCustomer.getSurplus().compareTo(order.getTotalPrice()) > -1) { - prepayCustomer.setSurplus(prepayCustomer.getSurplus().subtract(order.getTotalPrice())); - } else { - // 对于支付的差额,算作一次即充即用的预付费充值 - prepayCustomer.setSurplus(new BigDecimal(0)); - - String paidmemo = "现场补足预付金额:" + order.getPaid().intValue() + "元"; - - if (StrKit.isBlank(order.getMemo())) { - order.setMemo(paidmemo); - } else { - order.setMemo(order.getMemo() + "。" + paidmemo); - } - - PrepayDetail pd = new PrepayDetail(); - pd.setId(StrKit.getRandomUUID()); - pd.setCustomerId(order.getCustomerId()); - pd.setSupermarketId(order.getSupermarketId()); - pd.setAmount(order.getTotalPrice().subtract(prepayCustomer.getSurplus())); // 订单总价减去余额,就是本次补的差价 - pd.setType(2); - pd.setContactName(""); - pd.setContactPhone(""); - pd.setBankName(""); - pd.setSerialnum(""); - pd.setState(2); - pd.setChangeTime(now); - pd.setCreateTime(now); - pd.setVerifyTime(now); - - ret = pd.save(); - if (!ret) { - return false; - } - - synctask.addSaveData(pd); - - PrepayDetailStateHistory his = new PrepayDetailStateHistory(); - his.setId(StrKit.getRandomUUID()); - his.setPrepayDetailId(pd.getId()); - his.setChangeUserId(sysuser.getId()); - his.setChangeUserName(sysuser.getName()); - his.setState(1); - his.setChangeTime(now); - his.setMemo(paidmemo); - - ret = his.save(); - if (!ret) { - return false; - } - - synctask.addSaveData(his); - - his = new PrepayDetailStateHistory(); - his.setId(StrKit.getRandomUUID()); - his.setPrepayDetailId(pd.getId()); - his.setChangeUserId(sysuser.getId()); - his.setChangeUserName(sysuser.getName()); - his.setState(2); - his.setChangeTime(now); - his.setMemo(paidmemo); - - ret = his.save(); - if (!ret) { - return false; - } - - synctask.addSaveData(his); + if (prepayCustomer.getSurplus().compareTo(order.getTotalPrice()) < 1) { + return false; } + prepayCustomer.setSurplus(prepayCustomer.getSurplus().subtract(order.getTotalPrice())); + synctask.addUpdateData(prepayCustomer); ret = prepayCustomer.update(); @@ -724,8 +688,16 @@ public class OrderTempSyncService { return false; } - if (!ret) { - return false; + if(ordercluster.getState() == OrderStateEnum.INITIAL.getStateid()){ + ordercluster.setState(OrderStateEnum.ENTERED.getStateid()); + + ret = ordercluster.update(); + + if (!ret) { + return false; + } + + synctask.addUpdateData(ordercluster); } Stock stock = Stock.dao.findByIds(transport.getSupermarketId(), order.getProductId()); @@ -753,14 +725,24 @@ public class OrderTempSyncService { return false; } - // 各种信息都保存成功后,再提交税务系统,获取当前发票信息 // TODO:税盘接口是不是还要提交金额等开票相关的信息 - String taxation_invoice_code = InvoiceLogSyncService.me.taxationLastCode(order.getInt("supermarket_id")); + InvoiceLog invoiceLog = new InvoiceLog(); + invoiceLog.setId(StrKit.getRandomUUID()); + invoiceLog.setInvoiceReceiveId(finalReceive.getId()); + invoiceLog.setCode(finalNext_invoice_code); + invoiceLog.setState(OrderStateEnum.RECEIVED.getStateid()); + invoiceLog.setSettlementTime(now); + invoiceLog.setSettlementUserId(order.getSettlementUserId()); + invoiceLog.setSettlementUserName(order.getSettlementUserName()); + invoiceLog.setOrderSn(order.getSn()); + invoiceLog.setType(OrderTypeEnum.TEMP.getTypeid()); - if (!finalNext_invoice_code.equals(taxation_invoice_code)) { - log.error("本地记录和税务系统不一致"); + ret = invoiceLog.save(); + + if(!ret){ return false; } + synctask.addSaveData(invoiceLog); synctask.addUpdateData(finalReceive); } diff --git a/ssjygl-xsx-local/src/main/java/com/cowr/local/ssjygl/prepay/PrepayController.java b/ssjygl-xsx-local/src/main/java/com/cowr/local/ssjygl/prepay/PrepayController.java index 2443279..5cc9934 100644 --- a/ssjygl-xsx-local/src/main/java/com/cowr/local/ssjygl/prepay/PrepayController.java +++ b/ssjygl-xsx-local/src/main/java/com/cowr/local/ssjygl/prepay/PrepayController.java @@ -14,14 +14,12 @@ public class PrepayController extends BaseController { public void find() { String name = get("name"); Integer customer_id = getInt("customer_id"); - - Integer supermarket_id = getInt("supermarket_id"); String stm = get("stm"); String etm = get("etm"); Double start = getParaToDouble("start"); Double end = getParaToDouble("end"); PageParam pp = getBean(PageParam.class, "", true); - renderJson(Result.object(PrepayService.me.find(pp, name, customer_id, supermarket_id, stm, etm, start, end))); + renderJson(Result.object(PrepayService.me.find(pp, name, customer_id, stm, etm, start, end))); } @Before(StartAndEndTimeValidator.class) diff --git a/ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/invoice/receive/InvoiceReceiveSyncService.java b/ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/invoice/receive/InvoiceReceiveSyncService.java index acd04a6..7f76a3f 100644 --- a/ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/invoice/receive/InvoiceReceiveSyncService.java +++ b/ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/invoice/receive/InvoiceReceiveSyncService.java @@ -18,13 +18,13 @@ import com.jfinal.plugin.activerecord.IAtom; import java.util.List; public class InvoiceReceiveSyncService extends BaseSyncService { - private static Log log = Log.getLog(InvoiceReceiveSyncService.class); - public static InvoiceReceiveSyncService me = new InvoiceReceiveSyncService(); + private static Log log = Log.getLog(InvoiceReceiveSyncService.class); + public static InvoiceReceiveSyncService me = new InvoiceReceiveSyncService(); - public Result save(InvoiceReceive receive, Sysuser user){ + public Result save(InvoiceReceive receive, Sysuser user) { Sysuser receive_user = Sysuser.dao.findById(receive.getReceiveUserId()); - if(receive_user == null){ + if (receive_user == null) { return Result.failed("未找到关联用户信息"); } @@ -32,14 +32,29 @@ public class InvoiceReceiveSyncService extends BaseSyncService { Supermarket supermarket = SvrCacheData.SUP_CACHE.get(receive.getSupermarketId()); - if(supermarket == null){ + if (supermarket == null) { return Result.failed("未找到对应砂站信息"); } - // TODO: 这里需要验证输入的起始发票号码和领用份数,避免多个批次的领用和多个砂站的领用出现发票代码重复的情况 + try { + // 十位或者更长的发票号码要转 long,否则可能超过 Integer.MAX_VALUE 2147483647 + Long start = Long.parseLong(receive.getStartCode()); + Long end = Long.parseLong(receive.getEndCode()); - receive.setId(StrKit.getRandomUUID()); - receive.setSurplus(receive.getNum()); + List chklist = InvoiceReceive.dao.find("select * from invoice_receive t\n" + + " where ( t.start_code <= ? and t.end_code >= ? )\n" + + " or ( t.start_code <= ? and t.end_code >= ? )", start, start, end, end); + + if (!chklist.isEmpty()) { + return Result.failed("发票段和已领用的记录冲突"); + } + + receive.setSurplus((int) (end - start) + 1); + } catch (Exception e) { + log.error(e.getMessage(), e); + + return Result.failed("数据检查错误"); + } try { boolean ret = Db.tx(new IAtom() { diff --git a/ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/prepay/PrepayController.java b/ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/prepay/PrepayController.java index 4f9a5d8..9d28bf0 100644 --- a/ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/prepay/PrepayController.java +++ b/ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/prepay/PrepayController.java @@ -28,13 +28,12 @@ public class PrepayController extends BaseController { customer_id = tokenuser.getEntityId(); } - Integer supermarket_id = getInt("supermarket_id"); String stm = get("stm"); String etm = get("etm"); Double start = getParaToDouble("start"); Double end = getParaToDouble("end"); PageParam pp = getBean(PageParam.class, "", true); - renderJson(Result.object(PrepayService.me.find(pp, name, customer_id, supermarket_id, stm, etm, start, end))); + renderJson(Result.object(PrepayService.me.find(pp, name, customer_id, stm, etm, start, end))); } @Before(StartAndEndTimeValidator.class)