Commit c3ee0fa6 by ZhangYunfei

修改条码生成逻辑

parent caf6edcd
......@@ -34,8 +34,11 @@ public class BarcodeGenerationController {
*/
@Login
@PostMapping("/api/createQRcode")
public R createQRcode(@RequestBody Map<String,String> param) {
String url = this.barcodeGenerationService.createPicture(param.get("content"));
public R createQRcode(@RequestBody String[] param) {
if(param.length==0){
return R.error("参数有误");
}
String url = this.barcodeGenerationService.createPicture(param);
return R.ok().put("pictureUrl", url);
}
@Login
......@@ -59,4 +62,5 @@ public class BarcodeGenerationController {
String result = CheckAICodeUtil.ckeckCode(body.getCode(),body.getContent());
return R.ok().put("result",result);
}
}
......@@ -10,4 +10,6 @@ public interface QRcodeDao extends BaseMapper<GS1CodeListEntity> {
List<GS1CodeListEntity> getGS1CodeList();
GS1CodeListEntity getGS1ByMark();
GS1CodeListEntity getFixedLengthResult(String aiCode);
}
......@@ -12,6 +12,7 @@ import lombok.Setter;
@Getter
@ApiModel(value = "GS1CodeList")
public class GS1CodeListEntity {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "标识符ID")
public String id;
......
......@@ -13,7 +13,7 @@ import java.util.List;
*/
@Service
public interface BarcodeGenerationService {
String createPicture(String content);
String createPicture(String[] param);
List<GS1CodeListEntity> getGS1CodeListSSCC();
......
package io.office.modules.manage.service.impl;
import com.sun.javaws.jnl.RContentDesc;
import io.office.common.exception.RRException;
import io.office.modules.manage.dao.QRcodeDao;
import io.office.modules.manage.entity.GS1CodeListEntity;
import io.office.modules.manage.service.BarcodeGenerationService;
import io.office.modules.manage.utils.CheckAICodeUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -17,11 +19,47 @@ public class BarcodeGenerationServiceImpl implements BarcodeGenerationService {
private QRcodeDao qRcodeDao;
private final Log logger = LogFactory.getLog(getClass());
public static final String SEPERATOR = "ñ";
public static final String prefix_host="http://localhost:9091/office/";
public static final String prefix_url= "barcodegeneration/api/gensvg?type=";
@Override
public String createPicture(String content) {
public String createPicture(String[] param) {
String content="";
//遍历参数数组
for (int i = 0; i < param.length; i++) {
//获取ai标识符
String[] split = param[i].split(",");
String aiCode=split[0];
//根据ai标识符查ai详情
GS1CodeListEntity fixedLengthResult = qRcodeDao.getFixedLengthResult(aiCode);
//不定长处理
if(fixedLengthResult.getIsVariable()==1){
if(split[1].trim().length()<=fixedLengthResult.getMaxLength()
&&split[1].trim().length()>=fixedLengthResult.getMinLength()){
content= content+split[0]+split[1]+SEPERATOR;
}else {
throw new RRException("AI为"+aiCode+" 的信息需要填充"+fixedLengthResult.getMaxLength()+"位数字");
}
//定长处理
}else if(fixedLengthResult.getIsVariable()==0){
if(split[1].trim().length()==fixedLengthResult.getMinLength()){
//是否需要校验码
if(fixedLengthResult.getIsCheck()==1){
content= content+split[0]+split[1]+ CheckAICodeUtil.antoFixCheckCode(split[1]);
}else{
content= content+split[0]+split[1];
}
}else {
throw new RRException("AI为"+aiCode+" 的信息需要填充"+fixedLengthResult.getMaxLength()+"位数字");
}
}
}
if(content.lastIndexOf("ñ")==content.length()-1){
content=content.substring(0,content.length()-1);
}else if(content.length()>48){
throw new RRException("总长度不能超过48位");
}
String url = "";
if (content.length() > 50) {
throw new RRException("最大50位!");
......
......@@ -29,7 +29,7 @@ public class CheckAICodeUtil {
}
//00 01
//返回一位校验码
private static String antoFixCheckCode(String gtinNo){
public static String antoFixCheckCode(String gtinNo){
//gtinNo = "0690123456789";
int sum = 0;
char[] charArray = gtinNo.toCharArray();
......
......@@ -14,4 +14,10 @@
is_decimal isDecimal,is_check isCheck, is_num isNum, format, is_fnc1 isFnc1, data_name dataName ,is_date isDate, prompt
FROM gs1_standard where mark='8003'
</select>
<select id="getFixedLengthResult" resultType="io.office.modules.manage.entity.GS1CodeListEntity">
SELECT id, CONCAT(mark,'(',meaning,')') as codeName,mark codeValue, is_variable isVariable, min_length minLength, enable_max_length maxLength,
is_decimal isDecimal,is_check isCheck, is_num isNum, format, is_fnc1 isFnc1, data_name dataName ,is_date isDate, prompt
FROM gs1_standard where mark=#{aiCode};
</select>
</mapper>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment