Browse Source

首字母

lichao 3 years ago
parent
commit
fe87fe8952

+ 155 - 0
blade-service/blade-client/src/main/java/org/springblade/client/corps/controller/CorpsDescController.java

@@ -309,6 +309,161 @@ public class CorpsDescController extends BladeController {
 	}
 
 	/**
+	 * 按照首字母获得客户并分组
+	 */
+	@GetMapping("/initialsAllList")
+	@ApiOperationSupport(order = 2)
+	@ApiOperation(value = "按照首字母获得客户并分组", notes = "传入corpsDesc")
+	public R<List<List<CorpsDescVO>>> initialsAllList(CorpsDescVO corpsDesc) {
+		// 默认查有效的
+		LambdaQueryWrapper<CorpsDesc> lambdaQueryWrapper = new LambdaQueryWrapper<>();
+		lambdaQueryWrapper.eq(CorpsDesc::getTenantId, AuthUtil.getTenantId());
+		lambdaQueryWrapper.eq(CorpsDesc::getIsDeleted, 0);
+
+		//获得客户信息
+		List<CorpsDesc> corpsDescList = corpsDescService.list(lambdaQueryWrapper);
+		List<CorpsDescVO> voList = BeanUtil.copy(corpsDescList, CorpsDescVO.class);
+
+		List<List<CorpsDescVO>> listAll = new ArrayList<>();
+		List<CorpsDescVO> listA = new ArrayList<>();
+		List<CorpsDescVO> listB = new ArrayList<>();
+		List<CorpsDescVO> listC = new ArrayList<>();
+		List<CorpsDescVO> listD = new ArrayList<>();
+		List<CorpsDescVO> listE = new ArrayList<>();
+		List<CorpsDescVO> listF = new ArrayList<>();
+		List<CorpsDescVO> listG = new ArrayList<>();
+		List<CorpsDescVO> listH = new ArrayList<>();
+		List<CorpsDescVO> listI = new ArrayList<>();
+		List<CorpsDescVO> listJ = new ArrayList<>();
+		List<CorpsDescVO> listK = new ArrayList<>();
+		List<CorpsDescVO> listL = new ArrayList<>();
+		List<CorpsDescVO> listM = new ArrayList<>();
+		List<CorpsDescVO> listN = new ArrayList<>();
+		List<CorpsDescVO> listO = new ArrayList<>();
+		List<CorpsDescVO> listP = new ArrayList<>();
+		List<CorpsDescVO> listQ = new ArrayList<>();
+		List<CorpsDescVO> listR = new ArrayList<>();
+		List<CorpsDescVO> listS = new ArrayList<>();
+		List<CorpsDescVO> listT = new ArrayList<>();
+		List<CorpsDescVO> listU = new ArrayList<>();
+		List<CorpsDescVO> listV = new ArrayList<>();
+		List<CorpsDescVO> listW = new ArrayList<>();
+		List<CorpsDescVO> listX = new ArrayList<>();
+		List<CorpsDescVO> listY = new ArrayList<>();
+		List<CorpsDescVO> listZ = new ArrayList<>();
+		List<CorpsDescVO> listRest = new ArrayList<>();
+
+		voList.forEach(desc -> {
+			if (StringUtils.isNotBlank(desc.getInitials())){
+				if (desc.getInitials().equals("A") || desc.getInitials().equals("a")){
+					listA.add(desc);
+				} else if (desc.getInitials().equals("B") || desc.getInitials().equals("b")) {
+					listB.add(desc);
+				} else if (desc.getInitials().equals("C") || desc.getInitials().equals("c")) {
+					listC.add(desc);
+				} else if (desc.getInitials().equals("D") || desc.getInitials().equals("d")) {
+					listD.add(desc);
+				} else if (desc.getInitials().equals("E") || desc.getInitials().equals("e")) {
+					listE.add(desc);
+				} else if (desc.getInitials().equals("F") || desc.getInitials().equals("f")) {
+					listF.add(desc);
+				} else if (desc.getInitials().equals("G") || desc.getInitials().equals("g")) {
+					listG.add(desc);
+				} else if (desc.getInitials().equals("H") || desc.getInitials().equals("h")) {
+					listH.add(desc);
+				} else if (desc.getInitials().equals("I") || desc.getInitials().equals("i")) {
+					listI.add(desc);
+				} else if (desc.getInitials().equals("J") || desc.getInitials().equals("j")) {
+					listJ.add(desc);
+				} else if (desc.getInitials().equals("K") || desc.getInitials().equals("k")) {
+					listK.add(desc);
+				} else if (desc.getInitials().equals("L") || desc.getInitials().equals("l")) {
+					listL.add(desc);
+				} else if (desc.getInitials().equals("M") || desc.getInitials().equals("m")) {
+					listM.add(desc);
+				} else if (desc.getInitials().equals("N") || desc.getInitials().equals("n")) {
+					listN.add(desc);
+				} else if (desc.getInitials().equals("O") || desc.getInitials().equals("o")) {
+					listO.add(desc);
+				} else if (desc.getInitials().equals("P") || desc.getInitials().equals("p")) {
+					listP.add(desc);
+				} else if (desc.getInitials().equals("Q") || desc.getInitials().equals("q")) {
+					listQ.add(desc);
+				} else if (desc.getInitials().equals("R") || desc.getInitials().equals("r")) {
+					listR.add(desc);
+				} else if (desc.getInitials().equals("S") || desc.getInitials().equals("s")) {
+					listS.add(desc);
+				} else if (desc.getInitials().equals("T") || desc.getInitials().equals("t")) {
+					listT.add(desc);
+				} else if (desc.getInitials().equals("U") || desc.getInitials().equals("u")) {
+					listU.add(desc);
+				} else if (desc.getInitials().equals("V") || desc.getInitials().equals("v")) {
+					listV.add(desc);
+				} else if (desc.getInitials().equals("W") || desc.getInitials().equals("w")) {
+					listW.add(desc);
+				} else if (desc.getInitials().equals("X") || desc.getInitials().equals("x")) {
+					listX.add(desc);
+				} else if (desc.getInitials().equals("Y") || desc.getInitials().equals("y")) {
+					listY.add(desc);
+				} else if (desc.getInitials().equals("Z") || desc.getInitials().equals("z")) {
+					listZ.add(desc);
+				}else {
+					listRest.add(desc);
+				}
+			}else {
+				listRest.add(desc);
+			}
+		});
+		listAll.add(listA);
+		listAll.add(listB);
+		listAll.add(listC);
+		listAll.add(listD);
+		listAll.add(listE);
+		listAll.add(listF);
+		listAll.add(listG);
+		listAll.add(listH);
+		listAll.add(listI);
+		listAll.add(listJ);
+		listAll.add(listK);
+		listAll.add(listL);
+		listAll.add(listM);
+		listAll.add(listN);
+		listAll.add(listO);
+		listAll.add(listP);
+		listAll.add(listQ);
+		listAll.add(listR);
+		listAll.add(listS);
+		listAll.add(listT);
+		listAll.add(listU);
+		listAll.add(listV);
+		listAll.add(listW);
+		listAll.add(listX);
+		listAll.add(listY);
+		listAll.add(listZ);
+		listAll.add(listRest);
+		return R.data(listAll);
+	}
+
+	/**
+	 * 根据前端传值通过首字母获得客户
+	 */
+	@GetMapping("/initialsList")
+	@ApiOperationSupport(order = 2)
+	@ApiOperation(value = "根据前端传值过滤获得客户", notes = "传入corpsDesc")
+	public R<List<CorpsDescVO>> initialsList(CorpsDescVO corpsDesc) {
+		LambdaQueryWrapper<CorpsDesc> lambdaQueryWrapper = new LambdaQueryWrapper<>();
+		lambdaQueryWrapper.eq(CorpsDesc::getTenantId, AuthUtil.getTenantId());
+		lambdaQueryWrapper.eq(CorpsDesc::getIsDeleted, 0);
+		lambdaQueryWrapper.in(CorpsDesc::getInitials, corpsDesc.getInitials());
+
+		//获得客户信息
+		List<CorpsDesc> corpsDescList = corpsDescService.list(lambdaQueryWrapper);
+		List<CorpsDescVO> voList = BeanUtil.copy(corpsDescList, CorpsDescVO.class);
+
+		return R.data(voList);
+	}
+
+	/**
 	 * 客户信息
 	 */
 	@GetMapping("/corpsDescList")

+ 77 - 0
blade-service/blade-client/src/main/java/org/springblade/client/corps/service/impl/CorpsDescServiceImpl.java

@@ -58,6 +58,14 @@ public class CorpsDescServiceImpl extends ServiceImpl<CorpsDescMapper, CorpsDesc
 
 	private final ISysClient sysClient;
 
+	static final int GB_SP_DIFF = 160;
+	// 存放国标一级汉字不同读音的起始区位码
+	static final int[] secPosValueList = { 1601, 1637, 1833, 2078, 2274, 2302, 2433, 2594, 2787, 3106, 3212, 3472, 3635,
+		3722, 3730, 3858, 4027, 4086, 4390, 4558, 4684, 4925, 5249, 5600 };
+	// 存放国标一级汉字不同读音的起始区位码对应读音
+	static final char[] firstLetter = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q',
+		'R', 'S', 'T', 'W', 'X', 'Y', 'Z' };
+
 	@Override
 	public IPage<CorpsDescVO> selectCorpsDescPage(IPage<CorpsDescVO> page, CorpsDescVO corpsDesc) {
 		//获取客户子类别
@@ -90,6 +98,11 @@ public class CorpsDescServiceImpl extends ServiceImpl<CorpsDescMapper, CorpsDesc
 	public R submit(CorpsDesc corpsDesc) {
 		Long userId = SecureUtil.getUserId();
 		Date date = new Date();
+		if (null == corpsDesc.getInitials() || "" == corpsDesc.getInitials()){//首字母为空
+			//获得名称首字母
+			String initials = getSpells(corpsDesc.getCname());
+			corpsDesc.setInitials(initials.substring(0, 1));
+		}
 		//保存客户信息
 		if (corpsDesc.getId() == null) {
 			corpsDesc.setTenantId(SecureUtil.getTenantId());
@@ -773,4 +786,68 @@ public class CorpsDescServiceImpl extends ServiceImpl<CorpsDescMapper, CorpsDesc
 	}
 
 
+	/**
+	 * 提取汉字字符串的首字母
+	 * @param characters 汉字字符串
+	 * @return
+	 */
+	public static String getSpells(String characters) {
+		StringBuffer buffer = new StringBuffer();
+		for (int i = 0; i < characters.length(); i++) {
+
+			char ch = characters.charAt(i);
+			if ((ch >> 7) == 0) {
+				// 判断是否为汉字,如果左移7为为0就不是汉字,否则是汉字
+				buffer.append('#');
+			} else {
+				char spell = getFirstLetter(ch);
+				buffer.append(String.valueOf(spell));
+			}
+		}
+		return buffer.toString();
+	}
+
+	/**
+	 * 获取一个汉字的首字母
+	 * @param ch 汉字
+	 * @return
+	 */
+	public static Character getFirstLetter(char ch) {
+
+		byte[] uniCode = null;
+		try {
+			uniCode = String.valueOf(ch).getBytes("GBK");
+		}  catch (Exception e) {
+			e.printStackTrace();
+			return null;
+		}
+		if (uniCode[0] < 128 && uniCode[0] > 0) { // 非汉字
+			return null;
+		} else {
+			return convert(uniCode);
+		}
+	}
+
+	/**
+	 * 获取一个汉字的拼音首字母。 GB码两个字节分别减去160,转换成10进制码组合就可以得到区位码
+	 * 例如汉字“你”的GB码是0xC4/0xE3,分别减去0xA0(160)就是0x24/0x43
+	 * 0x24转成10进制就是36,0x43是67,那么它的区位码就是3667,在对照表中读音为‘n’
+	 */
+	private static char convert(byte[] bytes) {
+		char result = '#';
+		int secPosValue = 0;
+		int i;
+		for (i = 0; i < bytes.length; i++) {
+			bytes[i] -= GB_SP_DIFF;
+		}
+		secPosValue = bytes[0] * 100 + bytes[1];
+		for (i = 0; i < 23; i++) {
+			if (secPosValue >= secPosValueList[i] && secPosValue < secPosValueList[i + 1]) {
+				result = firstLetter[i];
+				break;
+			}
+		}
+		return result;
+	}
+
 }

+ 1 - 1
blade-service/blade-purchase-sales/src/main/java/org/springblade/purchase/sales/export/ExportOrderController.java

@@ -584,7 +584,7 @@ public class ExportOrderController extends BladeController {
 		wrapper.eq(Order::getIsDeleted,0);
 		wrapper.eq(Order::getTenantId,SecureUtil.getTenantId());
 		wrapper.eq(Order::getTradeType,order.getTradeType());
-		wrapper.eq(Order::getBillType,OrderTypeEnum.ENQUIRY.getType());//采购
+		wrapper.eq(Order::getBillType,OrderTypeEnum.ENQUIRY.getType());//报价
 		wrapper.gt(Order::getStatus,0);
 		wrapper.lt(Order::getStatus,3);
 		checkDate.setOfferNumber(orderService.count(wrapper));