diff --git a/src/main/java/com/qs/serve/common/framework/manager/AsyncFactory.java b/src/main/java/com/qs/serve/common/framework/manager/AsyncFactory.java index 386267fa..e45b4be3 100644 --- a/src/main/java/com/qs/serve/common/framework/manager/AsyncFactory.java +++ b/src/main/java/com/qs/serve/common/framework/manager/AsyncFactory.java @@ -3,12 +3,16 @@ package com.qs.serve.common.framework.manager; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.qs.serve.common.config.DevEnvironmentConfig; +import com.qs.serve.common.framework.redis.RedisService; +import com.qs.serve.common.model.dto.R; import com.qs.serve.common.util.AuthContextUtils; import com.qs.serve.common.util.JsonUtil; import com.qs.serve.common.util.SpringUtils; import com.qs.serve.modules.data.entity.DataAffairCommit; import com.qs.serve.modules.data.service.DataAffairCommitService; import com.qs.serve.modules.seeyon.service.SeeYonOperationService; +import com.qs.serve.modules.seeyon.service.SeeYonRequestService; +import com.qs.serve.modules.seeyon.service.impl.SeeYonRequestBaseService; import com.qs.serve.modules.sys.entity.SysOperationLog; import com.qs.serve.modules.sys.mapper.SysOperationLogMapper; import com.qs.serve.modules.tbs.entity.TbsBudget; @@ -30,6 +34,9 @@ import org.springframework.scheduling.annotation.Async; import java.math.BigDecimal; import java.util.TimerTask; +import java.util.concurrent.TimeUnit; + +import static com.qs.serve.modules.tbs.common.TbsSeeYonConst.ERP_CUS_AMOUNT; /** * 异步工厂 @@ -53,6 +60,38 @@ public class AsyncFactory { }; } + /** + * 异步保存政策状态 + * @param userId + * @param supplierCode + * @return + */ + public static TimerTask initCustomerPrice(String userId,String supplierCode) { + return new TimerTask() { + @Override + public void run() { + String lockKey = "customer_price_lock:"+userId; + String priceDataKey = "customer_price_data:"+userId; + RedisService redisService = SpringUtils.getBean(RedisService.class); + redisService.set(lockKey,1); + //请求获取金额 + SeeYonRequestBaseService seeYonRequestService = SpringUtils.getBean(SeeYonRequestBaseService.class); + R reqResult = seeYonRequestService.getBase(ERP_CUS_AMOUNT,"获取客户["+supplierCode+"]金额"); + if(reqResult==null || !reqResult.getStatus().equals(200)){ + //有错误退出 + redisService.set(lockKey,0); + return; + } + String amount = reqResult.getData()==null?"0":reqResult.getData(); + //数据格式:supplierCode_&_amount 如 A235654_&_612.00 + String value = supplierCode+"_&_"+amount; + //缓存15分钟 + redisService.set(priceDataKey,value,15, TimeUnit.MINUTES); + redisService.set(lockKey,0); + } + }; + } + /** * 异步保存政策状态 * @param policyId diff --git a/src/main/java/com/qs/serve/modules/erp/controller/ErpCustomerController.java b/src/main/java/com/qs/serve/modules/erp/controller/ErpCustomerController.java index 3eab973b..a20c52fc 100644 --- a/src/main/java/com/qs/serve/modules/erp/controller/ErpCustomerController.java +++ b/src/main/java/com/qs/serve/modules/erp/controller/ErpCustomerController.java @@ -42,9 +42,29 @@ public class ErpCustomerController { BmsSupplier supplier = supplierService.getByCode(code,null); if(supplier!=null){ ErpCustomerAmountResult amountResult = erpCustomerService.getCustomerAmount(code); + if(amountResult==null){ + //初始化帐余 + erpCustomerService.initAmount(code); + return new R(201,"客户帐余初始中"); + } return R.ok(amountResult); } return R.error(); } + /** + * 初始化客户帐余 + * @param code + * @return + */ + @GetMapping("/initAmount/{code}") + public R initAmount(@PathVariable String code){ + BmsSupplier supplier = supplierService.getByCode(code,null); + if(supplier!=null){ + erpCustomerService.initAmount(code); + return R.ok(); + } + return R.error(); + } + } diff --git a/src/main/java/com/qs/serve/modules/erp/service/ErpCustomerService.java b/src/main/java/com/qs/serve/modules/erp/service/ErpCustomerService.java index b216c152..b18c4dd5 100644 --- a/src/main/java/com/qs/serve/modules/erp/service/ErpCustomerService.java +++ b/src/main/java/com/qs/serve/modules/erp/service/ErpCustomerService.java @@ -1,6 +1,7 @@ package com.qs.serve.modules.erp.service; import com.qs.serve.modules.erp.entity.dto.ErpCustomerAmountResult; +import org.springframework.web.bind.annotation.PathVariable; /** * @author YenHex @@ -15,4 +16,10 @@ public interface ErpCustomerService { */ ErpCustomerAmountResult getCustomerAmount(String supplierCode); + /** + * 初始化 + * @param code + */ + void initAmount( String code); + } diff --git a/src/main/java/com/qs/serve/modules/erp/service/impl/ErpCustomerServiceImpl.java b/src/main/java/com/qs/serve/modules/erp/service/impl/ErpCustomerServiceImpl.java index 2f67e4a2..29ddeaa6 100644 --- a/src/main/java/com/qs/serve/modules/erp/service/impl/ErpCustomerServiceImpl.java +++ b/src/main/java/com/qs/serve/modules/erp/service/impl/ErpCustomerServiceImpl.java @@ -4,6 +4,10 @@ import cn.hutool.core.collection.CollectionUtil; import cn.hutool.crypto.Mode; import cn.hutool.crypto.Padding; import cn.hutool.crypto.symmetric.AES; +import com.qs.serve.common.framework.manager.AsyncFactory; +import com.qs.serve.common.framework.manager.AsyncManager; +import com.qs.serve.common.framework.redis.RedisService; +import com.qs.serve.common.util.AuthContextUtils; import com.qs.serve.common.util.JdbcUtil; import com.qs.serve.modules.erp.entity.dto.ErpCustomerAmountResult; import com.qs.serve.modules.erp.service.ErpCustomerService; @@ -24,63 +28,40 @@ import java.util.Map; @AllArgsConstructor public class ErpCustomerServiceImpl implements ErpCustomerService { + private final RedisService redisService; + @Override public ErpCustomerAmountResult getCustomerAmount(String supplierCode) { - String iv = "1234567812345678"; - AES aes = new AES(Mode.CBC, Padding.PKCS5Padding, iv.getBytes(), iv.getBytes()); - String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver"; - String url = "jdbc:sqlserver://59.37.164.96:14333;DatabaseName=UFDATA_001_2020"; - String username = "sa"; - String password = aes.decryptStr("h7wNWH4mf7mzmLZmkYgIdA=="); - String tmpTableName = "z_qs_cus_"+supplierCode; - ErpCustomerAmountResult amountResult = new ErpCustomerAmountResult(); - String sql = "DECLARE @return_value int " + - " EXEC @return_value = [dbo].[Sa_saleCreReport] " + - " @tmptableName = '"+tmpTableName+"'," + - " @repStytle = 1, " + - " @chrWhereDate = NULL, " + - " @chrWhereCus = \"and ccuscode = '"+supplierCode+"'\"," + - " @chrWhereDep = NULL, " + - " @chrWherePer = NULL, " + - " @chrCreSys = N'SA', " + - " @chrWhereOth = NULL " + - " SELECT 'Return Value' = @return_value"; - List> result = JdbcUtil.query(username,password,url,driverName,sql); - int rsNum = -1; - if(CollectionUtil.isNotEmpty(result)){ - for (Map objectMap : result) { - for (String key : objectMap.keySet()) { - Object obj = objectMap.get(key); - if(obj!=null&&obj.toString().equals("0")){ - rsNum = 0; - break; - } - } - } - } - if(rsNum==0){ - String sql4Data = "Select * from tempdb.."+tmpTableName+" order by '单据日期' desc"; - List> resultList = JdbcUtil.query(username,password,url,driverName,sql4Data); - if(CollectionUtil.isNotEmpty(resultList)){ - BigDecimal sumBalance = BigDecimal.ZERO; - for (Map objectMap : resultList) { - Object obj = objectMap.get("信用余额"); - if(obj!=null){ - BigDecimal objBal = new BigDecimal(obj.toString().trim()); - sumBalance = sumBalance.add(objBal); - } + String userId = AuthContextUtils.getSysUserId(); + String priceDataKey = "customer_price_data:"+userId; + //数据格式:supplierCode_&_amount 如 A235654_&_612.00 + String data = redisService.getString(priceDataKey); + if(data != null){ + String[] vals = data.split("_&_"); + if(vals.length==2){ + String code = vals[0]; + String amountStr = vals[1]; + if(code.equals(supplierCode)){ + ErpCustomerAmountResult amountResult = new ErpCustomerAmountResult(); + amountResult.setAmount(new BigDecimal(amountStr)); + return amountResult; } - dropTmpTable(tmpTableName,username,password,url,driverName); - amountResult.setAmount(sumBalance); } - dropTmpTable(tmpTableName,username,password,url,driverName); } - return amountResult; + this.initAmount(supplierCode); + return null; } - - private void dropTmpTable(String tmpTable,String username,String password,String url,String driverName){ - String sql = "drop table tempdb.."+tmpTable; - JdbcUtil.query(username,password,url,driverName,sql); + @Override + public void initAmount(String code) { + String userId = AuthContextUtils.getSysUserId(); + String lockKey = "customer_price_lock:"+userId; + // lockState=1 锁 + Integer lockState = redisService.getInteger(lockKey); + if(lockState==null||lockState==0){ + //设置值到redis + AsyncManager.me().execute(AsyncFactory.initCustomerPrice(userId,code)); + } } + } diff --git a/src/main/java/com/qs/serve/modules/oms/controller/api/OmsShoppingCartApi.java b/src/main/java/com/qs/serve/modules/oms/controller/api/OmsShoppingCartApi.java index 31481e73..4511f03d 100644 --- a/src/main/java/com/qs/serve/modules/oms/controller/api/OmsShoppingCartApi.java +++ b/src/main/java/com/qs/serve/modules/oms/controller/api/OmsShoppingCartApi.java @@ -60,6 +60,7 @@ public class OmsShoppingCartApi { } LambdaQueryWrapper shoppingCartWrapper = new LambdaQueryWrapper<>(param); shoppingCartWrapper.eq(OmsShoppingCart::getUserId,sysUserId); + shoppingCartWrapper.eq(OmsShoppingCart::getSupplierId,supplier.getId()); PageUtil.startPage(); List shoppingCarts = omsShoppingCartService.list(shoppingCartWrapper); omsShoppingCartService.checkShoppingCarts(supplier,shoppingCarts,false); @@ -99,6 +100,7 @@ public class OmsShoppingCartApi { shoppingCart.setPicUrl(goodsSku.getPicUrl()); shoppingCart.setSpuId(goodsSku.getSpuId()); shoppingCart.setAddPrice(goodsSku.getSalesPrice()); + shoppingCart.setSupplierId(Long.parseLong(supplier.getId())); GoodsSpu goodsSpu = goodsSpuService.getById(shoppingCart.getSpuId()); if(!goodsSpu.getShelf().equals(1)){ return R.error("商品已下架"); @@ -129,6 +131,9 @@ public class OmsShoppingCartApi { @DeleteMapping("/deleteById/{ids}") public R deleteById(@PathVariable("ids") String ids){ List idsLong = StringUtils.splitIdLong(ids); + LambdaQueryWrapper lqw = new LambdaQueryWrapper<>(); + lqw.eq(OmsShoppingCart::getId,idsLong); + lqw.eq(OmsShoppingCart::getSupplierId,AuthContextUtils.getSupplierId()); omsShoppingCartService.removeBatchByIds(idsLong); return R.ok(); } diff --git a/src/main/java/com/qs/serve/modules/tbs/common/TbsSeeYonConst.java b/src/main/java/com/qs/serve/modules/tbs/common/TbsSeeYonConst.java index 4d814d05..04436776 100644 --- a/src/main/java/com/qs/serve/modules/tbs/common/TbsSeeYonConst.java +++ b/src/main/java/com/qs/serve/modules/tbs/common/TbsSeeYonConst.java @@ -78,6 +78,9 @@ public interface TbsSeeYonConst { String OA_USER_INFO = "/process/getUserByCode"; String OA_USER_LIST_1 = "/process/getUsersList"; + /** 客户账单余额 */ + String ERP_CUS_AMOUNT = "/erp/customer/amount"; + String XLT_SAVE_CHECK = "/xlt/saveCheck"; String XLT_SAVE_PAYMENT = "/xlt/savePayment"; String XLT_SAVE_POLICY = "/xlt/savePolicyItem"; diff --git a/src/main/java/com/qs/serve/modules/tbs/controller/TbsCostApplyController.java b/src/main/java/com/qs/serve/modules/tbs/controller/TbsCostApplyController.java index 028e4584..8ea60880 100644 --- a/src/main/java/com/qs/serve/modules/tbs/controller/TbsCostApplyController.java +++ b/src/main/java/com/qs/serve/modules/tbs/controller/TbsCostApplyController.java @@ -80,7 +80,7 @@ public class TbsCostApplyController { * @param param * @return */ - //@PostMapping("/testChangeAmt") + @PostMapping("/testChangeAmt") public R testChangeAmt(@RequestBody TbsAffairCommitBo param){ TbsCostApplyOperationServiceImpl impl = SpringUtils.getBean(TbsCostApplyOperationServiceImpl.class); impl.doFinished(param); diff --git a/src/main/java/com/qs/serve/modules/tbs/service/impl/TbsBudgetBatchOperationServiceImpl.java b/src/main/java/com/qs/serve/modules/tbs/service/impl/TbsBudgetBatchOperationServiceImpl.java index a6d1737c..c1e44327 100644 --- a/src/main/java/com/qs/serve/modules/tbs/service/impl/TbsBudgetBatchOperationServiceImpl.java +++ b/src/main/java/com/qs/serve/modules/tbs/service/impl/TbsBudgetBatchOperationServiceImpl.java @@ -62,6 +62,9 @@ public class TbsBudgetBatchOperationServiceImpl implements SeeYonOperationServic @Override public Object doFinished(TbsAffairCommitBo param) { TbsBudgetBatch budgetBatch = budgetBatchService.getById(param.getTargetId()); + if(!budgetBatch.getBatchState().equals(TbsBudgetCheckState.State_1_apply)){ + return null; + } List budgetBatchItemList = budgetBatchItemService.listByBatchId(budgetBatch.getId()); for (TbsBudgetBatchItem batchItem : budgetBatchItemList) { if(batchItem.getChangeId()==null){ @@ -83,6 +86,9 @@ public class TbsBudgetBatchOperationServiceImpl implements SeeYonOperationServic @Override public Object doRefuse(TbsAffairCommitBo param) { TbsBudgetBatch budgetBatch = budgetBatchService.getById(param.getTargetId()); + if(!budgetBatch.getBatchState().equals(TbsBudgetCheckState.State_1_apply)){ + return null; + } List budgetBatchItemList = budgetBatchItemService.listByBatchId(budgetBatch.getId()); for (TbsBudgetBatchItem batchItem : budgetBatchItemList) { if(batchItem.getChangeId()==null){ diff --git a/src/main/java/com/qs/serve/modules/tbs/service/impl/TbsBudgetChangeOperationServiceImpl.java b/src/main/java/com/qs/serve/modules/tbs/service/impl/TbsBudgetChangeOperationServiceImpl.java index f7083721..46f4783a 100644 --- a/src/main/java/com/qs/serve/modules/tbs/service/impl/TbsBudgetChangeOperationServiceImpl.java +++ b/src/main/java/com/qs/serve/modules/tbs/service/impl/TbsBudgetChangeOperationServiceImpl.java @@ -92,6 +92,8 @@ public class TbsBudgetChangeOperationServiceImpl implements SeeYonOperationServi if(budgetChange.getBudgetCheckState().equals(TbsBudgetCheckState.State_1_apply)){ budgetChange.setBudgetCheckState(TbsBudgetCheckState.State_2_finished); budgetChangeMapper.updateById(budgetChange); + }else { + return; } TbsBudget tbsBudget = budgetMapper.selectById(budgetChange.getBudgetId()); if(budgetChange.getNewAttachIds()!=null&& budgetChange.getNewAttachIds().length>0){