diff --git a/emis-biz-web/src/main/java/com/xdadan/erp/web/emis/EmisElectronicPagController.java b/emis-biz-web/src/main/java/com/xdadan/erp/web/emis/EmisElectronicPagController.java index 9f75c0b36..98505bb2e 100644 --- a/emis-biz-web/src/main/java/com/xdadan/erp/web/emis/EmisElectronicPagController.java +++ b/emis-biz-web/src/main/java/com/xdadan/erp/web/emis/EmisElectronicPagController.java @@ -83,15 +83,35 @@ public class EmisElectronicPagController extends BaseController return AjaxResult.success(emisElectronicPagService.selectEmisElectronicPagById(id)); } + /** + * 获取电子面单单号 + */ + @PostMapping(value = "/realMatchWaybill") + public AjaxResult realMatchWaybill() + { + try { + String waybillNo = emisElectronicPagService.realMatchWaybill(); + return AjaxResult.success("处理成功",waybillNo); + }catch (Exception ex){ + ex.printStackTrace(); + return AjaxResult.error(ex.getMessage()); + } + } + /** * 新增电子面单 */ @PreAuthorize("@ss.hasPermi('emis:emisElectronicPag:add')") - @Log(title = "电子面单", businessType = BusinessType.INSERT) + @Log(title = "新增电子面单", businessType = BusinessType.INSERT) @PostMapping public AjaxResult add(@RequestBody EmisElectronicPag emisElectronicPag) { - return toAjax(emisElectronicPagService.insertEmisElectronicPag(emisElectronicPag)); + try{ + return toAjax(emisElectronicPagService.insertEmisElectronicPag(emisElectronicPag)); + }catch (Exception ex){ + ex.printStackTrace(); + return AjaxResult.error(ex.getMessage()); + } } /** diff --git a/emis-biz/src/main/java/com/xdadan/erp/emis/mapper/EmisElectronicPagMapper.java b/emis-biz/src/main/java/com/xdadan/erp/emis/mapper/EmisElectronicPagMapper.java index a9c2ed2ce..439a0a859 100644 --- a/emis-biz/src/main/java/com/xdadan/erp/emis/mapper/EmisElectronicPagMapper.java +++ b/emis-biz/src/main/java/com/xdadan/erp/emis/mapper/EmisElectronicPagMapper.java @@ -13,6 +13,11 @@ package com.xdadan.erp.emis.mapper; import java.util.List; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.xdadan.erp.emis.domain.EmisElectronicPag; +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.ResultMap; +import org.apache.ibatis.annotations.Select; +import org.apache.ibatis.annotations.Update; + /** * @ClassName EmisElectronicPagMapper * @Description

电子面单 Mapper 接口

@@ -67,4 +72,16 @@ public interface EmisElectronicPagMapper extends BaseMapper * @return 结果 */ public int deleteEmisElectronicPagByIds(Long[] ids); + + @Select("select count(1) from emis_electronic_pag where (${startNo}>=start_no and ${startNo}<=end_no) or (${endNo}>=start_no and ${endNo}<=end_no) ") + public int checkPagIsExists(@Param("startNo") String startNo,@Param("endNo") String endNo); + + + @Select("select * from emis_electronic_pag where has_bill_count>0 limit 1 ") + @ResultMap("EmisElectronicPagResult") + public EmisElectronicPag getOneAvailablePag(); + + + @Update("update emis_electronic_pag set cur_start_no=${curStartNo},has_bill_count=has_bill_count-1 where id=${id} ") + public int updateRealMatchWaybill(@Param("curStartNo")String curStartNo,@Param("id")Long id); } diff --git a/emis-biz/src/main/java/com/xdadan/erp/emis/service/IEmisElectronicPagService.java b/emis-biz/src/main/java/com/xdadan/erp/emis/service/IEmisElectronicPagService.java index a48b097b6..9563bc8dd 100644 --- a/emis-biz/src/main/java/com/xdadan/erp/emis/service/IEmisElectronicPagService.java +++ b/emis-biz/src/main/java/com/xdadan/erp/emis/service/IEmisElectronicPagService.java @@ -27,6 +27,11 @@ public interface IEmisElectronicPagService */ public EmisElectronicPag selectEmisElectronicPagById(Long id); + + public String realMatchWaybill() throws Exception; + + + /** * 查询电子面单列表 * @@ -41,7 +46,7 @@ public interface IEmisElectronicPagService * @param emisElectronicPag 电子面单 * @return 结果 */ - public int insertEmisElectronicPag(EmisElectronicPag emisElectronicPag); + public int insertEmisElectronicPag(EmisElectronicPag emisElectronicPag) throws Exception; /** * 修改电子面单 diff --git a/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisElectronicPagServiceImpl.java b/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisElectronicPagServiceImpl.java index 8e37e272a..11a235ec6 100644 --- a/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisElectronicPagServiceImpl.java +++ b/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisElectronicPagServiceImpl.java @@ -10,7 +10,14 @@ package com.xdadan.erp.emis.service.impl; +import java.util.Date; import java.util.List; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.xdadan.erp.common.core.redis.RedissonService; +import org.apache.commons.lang3.StringUtils; +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Select; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.xdadan.erp.emis.domain.EmisElectronicPag; @@ -29,6 +36,11 @@ public class EmisElectronicPagServiceImpl implements IEmisElectronicPagService @Autowired private EmisElectronicPagMapper emisElectronicPagMapper; + @Autowired + RedissonService redissonService; + + public static String PAG_PREFIX="T7080"; + /** * 查询电子面单 * @@ -41,6 +53,43 @@ public class EmisElectronicPagServiceImpl implements IEmisElectronicPagService return emisElectronicPagMapper.selectEmisElectronicPagById(id); } + + /** + * 分配电子面单 + * @return + */ + @Override + public String realMatchWaybill() throws Exception { + // 获取电子面单号 + // 获取分段电子面单数量 + String waybillNo = ""; + String lockKey="REALMATCHWAYBILL_LOCK"; + redissonService.lock(lockKey, 120L); + // 需要加锁 + EmisElectronicPag emisElectronicPag=emisElectronicPagMapper.getOneAvailablePag(); + if(emisElectronicPag==null){ + redissonService.unlock(lockKey); + throw new Exception("无可用面单号"); + } + + // 产生新单号 + String curStartNo = emisElectronicPag.getCurStartNo(); + if(StringUtils.isEmpty(curStartNo)) { + curStartNo = emisElectronicPag.getStartNo(); + } + + long newStartNumber = Long.valueOf(curStartNo.replace(PAG_PREFIX,"")); + newStartNumber= newStartNumber+1; + + waybillNo=PAG_PREFIX+String.valueOf(newStartNumber); + + // 更新当前值并且递减数量 + emisElectronicPagMapper.updateRealMatchWaybill(waybillNo,emisElectronicPag.getId()); + redissonService.unlock(lockKey); + return waybillNo; + } + + /** * 查询电子面单列表 * @@ -60,8 +109,16 @@ public class EmisElectronicPagServiceImpl implements IEmisElectronicPagService * @return 结果 */ @Override - public int insertEmisElectronicPag(EmisElectronicPag emisElectronicPag) - { + public int insertEmisElectronicPag(EmisElectronicPag emisElectronicPag) throws Exception { + // 检查段是否有重复 + int existsCount=emisElectronicPagMapper.checkPagIsExists(emisElectronicPag.getStartNo(),emisElectronicPag.getEndNo()); + if(existsCount > 0){ + throw new Exception("号段已存在"); + } + + emisElectronicPag.setHasBillCount(emisElectronicPag.getBillCount()); + emisElectronicPag.setStatus("0"); + emisElectronicPag.setProvideDate(new Date()); return emisElectronicPagMapper.insertEmisElectronicPag(emisElectronicPag); } @@ -101,4 +158,6 @@ public class EmisElectronicPagServiceImpl implements IEmisElectronicPagService return emisElectronicPagMapper.deleteEmisElectronicPagById(id); } + + } diff --git a/emis-biz/src/main/resources/mapper/EmisElectronicPagMapper.xml b/emis-biz/src/main/resources/mapper/EmisElectronicPagMapper.xml index e00591fae..bf9c76795 100644 --- a/emis-biz/src/main/resources/mapper/EmisElectronicPagMapper.xml +++ b/emis-biz/src/main/resources/mapper/EmisElectronicPagMapper.xml @@ -143,4 +143,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{id} + + \ No newline at end of file diff --git a/emis-biz/src/main/resources/mapper/EmisTransProductMapper.xml b/emis-biz/src/main/resources/mapper/EmisTransProductMapper.xml index 764467330..9bd9fe061 100644 --- a/emis-biz/src/main/resources/mapper/EmisTransProductMapper.xml +++ b/emis-biz/src/main/resources/mapper/EmisTransProductMapper.xml @@ -40,7 +40,7 @@ and prod_name_en like concat('%', #{prodNameEn}, '%') and status = #{status} and country like concat('%', #{country}, '%') - and trans_line_code like concat('%', #{transLineCode}, '%') + and trans_line_code=#{transLineCode} and trans_line like concat('%', #{transLine}, '%') and carry_type like concat('%', #{carryType}, '%') and trans_type like concat('%', #{transType}, '%') diff --git a/emis-wms-web/src/main/java/com/xdadan/erp/web/utils/ConfigHelper.java b/emis-wms-web/src/main/java/com/xdadan/erp/web/utils/ConfigHelper.java new file mode 100644 index 000000000..9ed446f2b --- /dev/null +++ b/emis-wms-web/src/main/java/com/xdadan/erp/web/utils/ConfigHelper.java @@ -0,0 +1,61 @@ +package com.xdadan.erp.web.utils; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.security.InvalidKeyException; +import java.security.Key; +import java.security.NoSuchAlgorithmException; +import javax.crypto.Cipher; +import javax.crypto.NoSuchPaddingException; +import javax.crypto.spec.SecretKeySpec; + +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.codec.binary.Hex; + +@Slf4j +public class ConfigHelper { + + private static byte[] keybytes = new byte[] { + 49, 50, 51, 52, 53, 80, 55, 56, 57, 64, + 65, 66, 67, + 68, 69, 70 }; + + public static String encrypt(String value) { + String s = null; + int mode = 1; + try { + Cipher cipher = initCipher(mode); + byte[] outBytes = cipher.doFinal(value.getBytes()); + s = String.valueOf(Hex.encodeHex(outBytes)); + } catch (Exception e) { + log.error(e.getMessage()); + } + return s; + } + + public static String decrypt(String value) { + String s = null; + int mode = 2; + try { + Cipher cipher = initCipher(mode); + byte[] outBytes = cipher.doFinal(Hex.decodeHex(value.toCharArray())); + s = new String(outBytes); + } catch (Exception e) { + log.error(e.getMessage()); + } + return s; + } + + private static Cipher initCipher(int mode) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException { + Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding"); + Key key = new SecretKeySpec(keybytes, "AES"); + cipher.init(mode, key); + return cipher; + } + + public static void main(String[] args) { + String m=ConfigHelper.decrypt("513953ec53422e6d503172d5a1db9578e824220d54f5634094c6728e95e80895b510317a83f7f0b1a01998fda0d73ffc"); + System.out.println(m); + } +} +