35 changed files with 578 additions and 47 deletions
@ -0,0 +1,107 @@ |
|||||
|
package com.qs.serve.common.util; |
||||
|
|
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.springframework.util.StringUtils; |
||||
|
|
||||
|
import java.sql.*; |
||||
|
import java.util.ArrayList; |
||||
|
import java.util.HashMap; |
||||
|
import java.util.List; |
||||
|
import java.util.Map; |
||||
|
|
||||
|
/** |
||||
|
* 原生JDBC工具类 |
||||
|
* @Author JcYen |
||||
|
* @Date 2021/6/4 |
||||
|
*/ |
||||
|
@Slf4j |
||||
|
public class JdbcUtil { |
||||
|
|
||||
|
private static final String[] FILTER_WORD = new String[]{"truncate","create","alter","eval","delete","sp_password"}; |
||||
|
|
||||
|
/** |
||||
|
* 执行SQL(为安全,拦截delete语句) |
||||
|
* @param username |
||||
|
* @param password |
||||
|
* @param url |
||||
|
* @param driverName |
||||
|
* @param sql |
||||
|
* @return |
||||
|
*/ |
||||
|
public static List<Map<String,Object>> query(String username, String password, String url, String driverName, String sql) { |
||||
|
//检查SQL,防止SQL执行DDL语句
|
||||
|
doSqlFilter(sql); |
||||
|
List<Map<String,Object>> list = new ArrayList(); |
||||
|
Connection conn = null; |
||||
|
Statement stmt = null; |
||||
|
ResultSet rs = null; |
||||
|
try { |
||||
|
Class.forName(driverName); |
||||
|
conn = DriverManager.getConnection(url, username, password); |
||||
|
stmt = conn.createStatement(); |
||||
|
log.debug("JDBC工具类 Preparing SQL: {}",url); |
||||
|
rs = stmt.executeQuery(sql); |
||||
|
ResultSetMetaData md = rs.getMetaData(); |
||||
|
int columnCount = md.getColumnCount(); |
||||
|
while (rs.next()) { |
||||
|
Map<String,Object> rowData = new HashMap<>(); |
||||
|
for (int i = 1; i <= columnCount; i++) { |
||||
|
rowData.put(md.getColumnName(i), rs.getObject(i)); |
||||
|
} |
||||
|
list.add(rowData); |
||||
|
} |
||||
|
} catch (ClassNotFoundException e) { |
||||
|
log.warn(e.getMessage()); |
||||
|
} catch (SQLException throwables) { |
||||
|
log.error(throwables.getMessage()); |
||||
|
}finally { |
||||
|
if(rs!=null){ |
||||
|
try { |
||||
|
rs.close(); |
||||
|
} catch (SQLException e) { |
||||
|
e.printStackTrace(); |
||||
|
} |
||||
|
} |
||||
|
if (stmt!=null){ |
||||
|
try { |
||||
|
stmt.close(); |
||||
|
} catch (SQLException e) { |
||||
|
e.printStackTrace(); |
||||
|
} |
||||
|
} |
||||
|
if(conn!=null){ |
||||
|
try { |
||||
|
conn.close(); |
||||
|
} catch (SQLException e) { |
||||
|
e.printStackTrace(); |
||||
|
} |
||||
|
} |
||||
|
rs = null; |
||||
|
stmt = null; |
||||
|
conn = null; |
||||
|
} |
||||
|
return list; |
||||
|
} |
||||
|
|
||||
|
private static void doSqlFilter(String sql){ |
||||
|
boolean unsafe = false; |
||||
|
String[] parts = sql.split(" "); |
||||
|
for (String part : parts) { |
||||
|
if(unsafe){ break; } |
||||
|
if(StringUtils.isEmpty(part)){ |
||||
|
continue; |
||||
|
} |
||||
|
part = part.trim(); |
||||
|
for (String filterWord : FILTER_WORD) { |
||||
|
if(part.equalsIgnoreCase(filterWord)){ |
||||
|
unsafe = true; |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
if(unsafe){ |
||||
|
//AssertUtil.("非法SQL被拦截 ==> "+sql);
|
||||
|
} |
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,72 @@ |
|||||
|
package com.qs.serve.modules.erp.controller; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
||||
|
import com.qs.serve.common.model.dto.PageVo; |
||||
|
import com.qs.serve.common.model.dto.R; |
||||
|
import com.qs.serve.common.util.PageUtil; |
||||
|
import com.qs.serve.modules.bms.entity.BmsSupplier; |
||||
|
import com.qs.serve.modules.bms.service.BmsSupplierService; |
||||
|
import com.qs.serve.modules.erp.entity.dto.ErpCustomerAmountResult; |
||||
|
import com.qs.serve.modules.erp.service.ErpCustomerService; |
||||
|
import com.qs.serve.modules.goods.entity.GoodsBrand; |
||||
|
import lombok.AllArgsConstructor; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.springframework.security.access.prepost.PreAuthorize; |
||||
|
import org.springframework.web.bind.annotation.GetMapping; |
||||
|
import org.springframework.web.bind.annotation.PathVariable; |
||||
|
import org.springframework.web.bind.annotation.RequestMapping; |
||||
|
import org.springframework.web.bind.annotation.RestController; |
||||
|
|
||||
|
import java.math.BigDecimal; |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* ERP客户 |
||||
|
* @author YenHex |
||||
|
* @since 2023/9/5 |
||||
|
*/ |
||||
|
@Slf4j |
||||
|
@AllArgsConstructor |
||||
|
@RestController |
||||
|
@RequestMapping("erp/customer") |
||||
|
public class ErpCustomerController { |
||||
|
|
||||
|
private final ErpCustomerService erpCustomerService; |
||||
|
private final BmsSupplierService supplierService; |
||||
|
|
||||
|
/** |
||||
|
* 获取客户帐余 |
||||
|
* @param code |
||||
|
* @return |
||||
|
*/ |
||||
|
@GetMapping("/getAmount/{code}") |
||||
|
public R<ErpCustomerAmountResult> getAmount(@PathVariable String code){ |
||||
|
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(); |
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,19 @@ |
|||||
|
package com.qs.serve.modules.erp.entity.dto; |
||||
|
|
||||
|
import lombok.Data; |
||||
|
|
||||
|
import java.math.BigDecimal; |
||||
|
|
||||
|
/** |
||||
|
* @author YenHex |
||||
|
* @since 2023/9/5 |
||||
|
*/ |
||||
|
@Data |
||||
|
public class ErpCustomerAmountResult { |
||||
|
|
||||
|
/** |
||||
|
* 余额 |
||||
|
*/ |
||||
|
BigDecimal amount; |
||||
|
|
||||
|
} |
@ -0,0 +1,25 @@ |
|||||
|
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 |
||||
|
* @since 2023/9/5 |
||||
|
*/ |
||||
|
public interface ErpCustomerService { |
||||
|
|
||||
|
/** |
||||
|
* 获取客户帐余额 |
||||
|
* @param supplierCode |
||||
|
* @return |
||||
|
*/ |
||||
|
ErpCustomerAmountResult getCustomerAmount(String supplierCode); |
||||
|
|
||||
|
/** |
||||
|
* 初始化 |
||||
|
* @param code |
||||
|
*/ |
||||
|
void initAmount( String code); |
||||
|
|
||||
|
} |
@ -0,0 +1,68 @@ |
|||||
|
package com.qs.serve.modules.erp.service.impl; |
||||
|
|
||||
|
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; |
||||
|
import lombok.AllArgsConstructor; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
|
||||
|
import java.math.BigDecimal; |
||||
|
import java.util.List; |
||||
|
import java.util.Map; |
||||
|
|
||||
|
/** |
||||
|
* @author YenHex |
||||
|
* @since 2023/9/5 |
||||
|
*/ |
||||
|
@Slf4j |
||||
|
@Service |
||||
|
@AllArgsConstructor |
||||
|
public class ErpCustomerServiceImpl implements ErpCustomerService { |
||||
|
|
||||
|
private final RedisService redisService; |
||||
|
|
||||
|
@Override |
||||
|
public ErpCustomerAmountResult getCustomerAmount(String supplierCode) { |
||||
|
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; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
this.initAmount(supplierCode); |
||||
|
return null; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void initAmount(String code) { |
||||
|
String userId = AuthContextUtils.getSysUserId(); |
||||
|
String lockKey = "customer_price_lock:"+userId+":"+code; |
||||
|
// lockState=1 锁
|
||||
|
Integer lockState = redisService.getInteger(lockKey); |
||||
|
log.debug("customer_price_lock_value:"+lockState); |
||||
|
if(lockState==null||lockState==0){ |
||||
|
//设置值到redis
|
||||
|
AsyncManager.me().execute(AsyncFactory.initCustomerPrice(userId,code)); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,32 @@ |
|||||
|
package com.qs.serve.modules.goods.entity.dto; |
||||
|
|
||||
|
import lombok.Data; |
||||
|
|
||||
|
import java.math.BigDecimal; |
||||
|
import java.util.Date; |
||||
|
|
||||
|
/** |
||||
|
* 客户存货商品价格 |
||||
|
* @author YenHex |
||||
|
* @since 2021/10/28 |
||||
|
*/ |
||||
|
@Data |
||||
|
public class InventoryCusPrice { |
||||
|
|
||||
|
private String cusCode; |
||||
|
|
||||
|
private String invCode; |
||||
|
|
||||
|
private BigDecimal price; |
||||
|
|
||||
|
/** |
||||
|
* 开始时间 |
||||
|
*/ |
||||
|
private Date startDate; |
||||
|
|
||||
|
/** |
||||
|
* 结束时间 |
||||
|
*/ |
||||
|
private Date endDate; |
||||
|
|
||||
|
} |
@ -0,0 +1,17 @@ |
|||||
|
package com.qs.serve.modules.goods.entity.so; |
||||
|
|
||||
|
import lombok.Data; |
||||
|
|
||||
|
import java.util.List; |
||||
|
|
||||
|
/** |
||||
|
* @author YenHex |
||||
|
* @since 2023/9/6 |
||||
|
*/ |
||||
|
@Data |
||||
|
public class InventoryCusPriceQuery { |
||||
|
|
||||
|
String cusCode; |
||||
|
List<String> invCodes; |
||||
|
|
||||
|
} |
Loading…
Reference in new issue