|
@ -4,6 +4,10 @@ import cn.hutool.core.collection.CollectionUtil; |
|
|
import cn.hutool.crypto.Mode; |
|
|
import cn.hutool.crypto.Mode; |
|
|
import cn.hutool.crypto.Padding; |
|
|
import cn.hutool.crypto.Padding; |
|
|
import cn.hutool.crypto.symmetric.AES; |
|
|
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.common.util.JdbcUtil; |
|
|
import com.qs.serve.modules.erp.entity.dto.ErpCustomerAmountResult; |
|
|
import com.qs.serve.modules.erp.entity.dto.ErpCustomerAmountResult; |
|
|
import com.qs.serve.modules.erp.service.ErpCustomerService; |
|
|
import com.qs.serve.modules.erp.service.ErpCustomerService; |
|
@ -24,63 +28,40 @@ import java.util.Map; |
|
|
@AllArgsConstructor |
|
|
@AllArgsConstructor |
|
|
public class ErpCustomerServiceImpl implements ErpCustomerService { |
|
|
public class ErpCustomerServiceImpl implements ErpCustomerService { |
|
|
|
|
|
|
|
|
|
|
|
private final RedisService redisService; |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public ErpCustomerAmountResult getCustomerAmount(String supplierCode) { |
|
|
public ErpCustomerAmountResult getCustomerAmount(String supplierCode) { |
|
|
String iv = "1234567812345678"; |
|
|
String userId = AuthContextUtils.getSysUserId(); |
|
|
AES aes = new AES(Mode.CBC, Padding.PKCS5Padding, iv.getBytes(), iv.getBytes()); |
|
|
String priceDataKey = "customer_price_data:"+userId; |
|
|
String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver"; |
|
|
//数据格式:supplierCode_&_amount 如 A235654_&_612.00
|
|
|
String url = "jdbc:sqlserver://59.37.164.96:14333;DatabaseName=UFDATA_001_2020"; |
|
|
String data = redisService.getString(priceDataKey); |
|
|
String username = "sa"; |
|
|
if(data != null){ |
|
|
String password = aes.decryptStr("h7wNWH4mf7mzmLZmkYgIdA=="); |
|
|
String[] vals = data.split("_&_"); |
|
|
String tmpTableName = "z_qs_cus_"+supplierCode; |
|
|
if(vals.length==2){ |
|
|
ErpCustomerAmountResult amountResult = new ErpCustomerAmountResult(); |
|
|
String code = vals[0]; |
|
|
String sql = "DECLARE @return_value int " + |
|
|
String amountStr = vals[1]; |
|
|
" EXEC @return_value = [dbo].[Sa_saleCreReport] " + |
|
|
if(code.equals(supplierCode)){ |
|
|
" @tmptableName = '"+tmpTableName+"'," + |
|
|
ErpCustomerAmountResult amountResult = new ErpCustomerAmountResult(); |
|
|
" @repStytle = 1, " + |
|
|
amountResult.setAmount(new BigDecimal(amountStr)); |
|
|
" @chrWhereDate = NULL, " + |
|
|
return amountResult; |
|
|
" @chrWhereCus = \"and ccuscode = '"+supplierCode+"'\"," + |
|
|
|
|
|
" @chrWhereDep = NULL, " + |
|
|
|
|
|
" @chrWherePer = NULL, " + |
|
|
|
|
|
" @chrCreSys = N'SA', " + |
|
|
|
|
|
" @chrWhereOth = NULL " + |
|
|
|
|
|
" SELECT 'Return Value' = @return_value"; |
|
|
|
|
|
List<Map<String,Object>> result = JdbcUtil.query(username,password,url,driverName,sql); |
|
|
|
|
|
int rsNum = -1; |
|
|
|
|
|
if(CollectionUtil.isNotEmpty(result)){ |
|
|
|
|
|
for (Map<String, Object> 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<Map<String,Object>> resultList = JdbcUtil.query(username,password,url,driverName,sql4Data); |
|
|
|
|
|
if(CollectionUtil.isNotEmpty(resultList)){ |
|
|
|
|
|
BigDecimal sumBalance = BigDecimal.ZERO; |
|
|
|
|
|
for (Map<String, Object> objectMap : resultList) { |
|
|
|
|
|
Object obj = objectMap.get("信用余额"); |
|
|
|
|
|
if(obj!=null){ |
|
|
|
|
|
BigDecimal objBal = new BigDecimal(obj.toString().trim()); |
|
|
|
|
|
sumBalance = sumBalance.add(objBal); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
dropTmpTable(tmpTableName,username,password,url,driverName); |
|
|
|
|
|
amountResult.setAmount(sumBalance); |
|
|
|
|
|
} |
|
|
} |
|
|
dropTmpTable(tmpTableName,username,password,url,driverName); |
|
|
|
|
|
} |
|
|
} |
|
|
return amountResult; |
|
|
this.initAmount(supplierCode); |
|
|
|
|
|
return null; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
private void dropTmpTable(String tmpTable,String username,String password,String url,String driverName){ |
|
|
public void initAmount(String code) { |
|
|
String sql = "drop table tempdb.."+tmpTable; |
|
|
String userId = AuthContextUtils.getSysUserId(); |
|
|
JdbcUtil.query(username,password,url,driverName,sql); |
|
|
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)); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|