parent
ec90f78120
commit
7b88c6cc33
@ -0,0 +1,72 @@
|
||||
package cn.estsh.i3plus.core.api.iservice.busi;
|
||||
|
||||
import cn.estsh.i3plus.pojo.base.bean.ListPager;
|
||||
import cn.estsh.i3plus.pojo.base.common.Pager;
|
||||
import cn.estsh.i3plus.pojo.platform.bean.SysBarcodeRule;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description : 条码规则服务
|
||||
* @Reference :
|
||||
* @Author : yunhao
|
||||
* @CreateDate : 2019-03-12 16:01
|
||||
* @Modify:
|
||||
**/
|
||||
public interface ISysBarcodeRuleService {
|
||||
|
||||
/**
|
||||
* 添加条码规则
|
||||
* @param barcodeRule
|
||||
*/
|
||||
@ApiOperation(value = "新增条码规则信息")
|
||||
SysBarcodeRule insertSysBarcodeRule(SysBarcodeRule barcodeRule);
|
||||
|
||||
/**
|
||||
* 修改条码规则
|
||||
* @param barcodeRule
|
||||
*/
|
||||
@ApiOperation(value = "更新条码规则信息")
|
||||
void updateSysBarcodeRule(SysBarcodeRule barcodeRule);
|
||||
|
||||
/**
|
||||
* 查找全部条码规则
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "查询所有条码规则信息",notes = "查询所有条码规则信息")
|
||||
List<SysBarcodeRule> listSysBarcodeRule();
|
||||
|
||||
/**
|
||||
* 根据id查找条码规则
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "查询条码规则信息",notes = "根据ID查询条码规则信息")
|
||||
SysBarcodeRule getSysBarcodeRuleById(Long id);
|
||||
|
||||
/**
|
||||
* 根据id删除条码规则
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "根据id删除条码规则",notes = "根据id删除条码规则")
|
||||
void deleteSysBarcodeRuleById(Long id);
|
||||
|
||||
/**
|
||||
* 根据规则代码查询条码规则
|
||||
* @param code
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "根据规则代码查询条码规则",notes = "根据规则代码查询条码规则")
|
||||
SysBarcodeRule getSysBarcodeRuleByCode(String code);
|
||||
|
||||
/**
|
||||
* 条码规则复杂查询分页排序
|
||||
* @param barcodeRule
|
||||
* @param pager
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "根据规则代码查询条码规则",notes = "根据规则代码查询条码规则")
|
||||
ListPager<SysBarcodeRule> querySysBarcodeRuleByPager(SysBarcodeRule barcodeRule, Pager pager);
|
||||
}
|
@ -0,0 +1,149 @@
|
||||
package cn.estsh.i3plus.core.apiservice.controller.busi;
|
||||
|
||||
import cn.estsh.i3plus.core.api.iservice.busi.ISysBarcodeRuleService;
|
||||
import cn.estsh.i3plus.core.apiservice.util.BarcodeParseUtil;
|
||||
import cn.estsh.i3plus.platform.common.convert.ConvertBean;
|
||||
import cn.estsh.i3plus.platform.common.util.PlatformConstWords;
|
||||
import cn.estsh.i3plus.pojo.base.bean.ListPager;
|
||||
import cn.estsh.i3plus.pojo.base.common.Pager;
|
||||
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
|
||||
import cn.estsh.i3plus.pojo.base.enumutil.ResourceEnumUtil;
|
||||
import cn.estsh.i3plus.pojo.platform.bean.SessionUser;
|
||||
import cn.estsh.i3plus.pojo.platform.bean.SysBarcodeRule;
|
||||
import cn.estsh.i3plus.pojo.platform.bean.SysConfig;
|
||||
import cn.estsh.impp.framework.base.controller.CoreBaseController;
|
||||
import cn.estsh.impp.framework.boot.auth.AuthUtil;
|
||||
import cn.estsh.impp.framework.boot.exception.ImppBusiException;
|
||||
import cn.estsh.impp.framework.boot.exception.ImppExceptionBuilder;
|
||||
import cn.estsh.impp.framework.boot.exception.ImppExceptionEnum;
|
||||
import cn.estsh.impp.framework.boot.util.ResultBean;
|
||||
import cn.estsh.impp.framework.boot.util.ValidatorBean;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Description :条码规则管理服务
|
||||
* @Reference :
|
||||
* @Author : yunhao
|
||||
* @CreateDate : 2019-03-12 16:00
|
||||
* @Modify:
|
||||
**/
|
||||
@RestController
|
||||
@Api(description = "条码规则管理服务")
|
||||
@RequestMapping(PlatformConstWords.BASE_URL +"/sys-barcode-rule")
|
||||
public class SysBarcodeRuleController extends CoreBaseController {
|
||||
|
||||
public static final Logger LOGGER = LoggerFactory.getLogger(SysConfigController.class);
|
||||
|
||||
@Autowired
|
||||
private ISysBarcodeRuleService sysBarcodeRuleService;
|
||||
|
||||
@PostMapping("/insert")
|
||||
@ApiOperation(value = "添加条码规则",notes = "添加条码规则")
|
||||
public ResultBean insertSysBarcodeRule(SysBarcodeRule sysBarcodeRule) {
|
||||
try {
|
||||
// 条件验证
|
||||
ValidatorBean.beginValid(sysBarcodeRule)
|
||||
.notNull("name",sysBarcodeRule.getName())
|
||||
.notNull("barcodeRuleCode",sysBarcodeRule.getBarcodeRuleCode())
|
||||
.notNull("barcodeRule",sysBarcodeRule.getBarcodeRule());
|
||||
|
||||
sysBarcodeRuleService.insertSysBarcodeRule(sysBarcodeRule);
|
||||
return ResultBean.success("操作成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
|
||||
}catch(ImppBusiException busExcep){
|
||||
return ResultBean.fail(busExcep);
|
||||
}catch(Exception e){
|
||||
return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
|
||||
}
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@ApiOperation(value = "修改条码规则",notes = "修改条码规则")
|
||||
public ResultBean updateSysBarcodeRule(SysBarcodeRule sysBarcodeRule) {
|
||||
try {
|
||||
// 条件验证
|
||||
ValidatorBean.beginValid(sysBarcodeRule)
|
||||
.notNull("name",sysBarcodeRule.getName())
|
||||
.notNull("barcodeRuleCode",sysBarcodeRule.getBarcodeRuleCode())
|
||||
.notNull("barcodeRule",sysBarcodeRule.getBarcodeRule());
|
||||
|
||||
sysBarcodeRuleService.updateSysBarcodeRule(sysBarcodeRule);
|
||||
return ResultBean.success("操作成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
|
||||
}catch(ImppBusiException busExcep){
|
||||
return ResultBean.fail(busExcep);
|
||||
}catch(Exception e){
|
||||
return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
|
||||
}
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete/{id}")
|
||||
@ApiOperation(value = "删除条码规则",notes = "删除条码规则")
|
||||
public ResultBean deleteSysBarcodeRuleById(@PathVariable("id") String idStr) {
|
||||
try {
|
||||
// 条件验证
|
||||
ValidatorBean.checkNotNull(idStr,"id不能为空");
|
||||
SysBarcodeRule sysBarcodeRule = sysBarcodeRuleService.getSysBarcodeRuleById(Long.parseLong(idStr));
|
||||
if(sysBarcodeRule == null){
|
||||
throw ImppExceptionBuilder.newInstance()
|
||||
.setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode())
|
||||
.setErrorCode(ImppExceptionEnum.VARIFY_EXCEPTION_DATA_NOT_EXIT.getCode())
|
||||
.setErrorDetail("条码规则不存在")
|
||||
.setErrorSolution("请重新输入条码id")
|
||||
.build();
|
||||
}
|
||||
|
||||
sysBarcodeRuleService.deleteSysBarcodeRuleById(Long.parseLong(idStr));
|
||||
return ResultBean.success("操作成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
|
||||
}catch(ImppBusiException busExcep){
|
||||
return ResultBean.fail(busExcep);
|
||||
}catch(Exception e){
|
||||
return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/query")
|
||||
@ApiOperation(value = "条码规则分页复杂查询",notes = "条码规则分页复杂查询")
|
||||
public ResultBean querySysBarcodeRuleByPager(SysBarcodeRule sysBarcodeRule, Pager pager) {
|
||||
try {
|
||||
ListPager listPager = sysBarcodeRuleService.querySysBarcodeRuleByPager(sysBarcodeRule,pager);
|
||||
return ResultBean.success("操作成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode()).setListPager(listPager);
|
||||
}catch(ImppBusiException busExcep){
|
||||
return ResultBean.fail(busExcep);
|
||||
}catch(Exception e){
|
||||
return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
|
||||
}
|
||||
}
|
||||
|
||||
@PutMapping("/parser")
|
||||
@ApiOperation(value = "解析条码规则",notes = "解析条码规则")
|
||||
public ResultBean querySysBarcodeRuleByPager(String ruleCode, String barcode) {
|
||||
try {
|
||||
// 条件验证
|
||||
ValidatorBean.checkNotNull(ruleCode,"规则代码不能为空");
|
||||
SysBarcodeRule sysBarcodeRule = sysBarcodeRuleService.getSysBarcodeRuleByCode(ruleCode);
|
||||
if(sysBarcodeRule == null){
|
||||
throw ImppExceptionBuilder.newInstance()
|
||||
.setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode())
|
||||
.setErrorCode(ImppExceptionEnum.VARIFY_EXCEPTION_DATA_NOT_EXIT.getCode())
|
||||
.setErrorDetail("条码规则不存在")
|
||||
.setErrorSolution("请重新输入条码id")
|
||||
.build();
|
||||
}
|
||||
|
||||
// 解析条码规则
|
||||
Map resultMap = BarcodeParseUtil.parse(sysBarcodeRule,barcode);
|
||||
return ResultBean.success("操作成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode()).setResultMap(resultMap);
|
||||
}catch(ImppBusiException busExcep){
|
||||
return ResultBean.fail(busExcep);
|
||||
}catch(Exception e){
|
||||
return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
package cn.estsh.i3plus.core.apiservice.controller.busi;
|
||||
|
||||
/**
|
||||
* @Description :
|
||||
* @Reference :
|
||||
* @Author : yunhao
|
||||
* @CreateDate : 2019-02-19 18:13
|
||||
* @Modify:
|
||||
**/
|
||||
public class TestThread implements Runnable {
|
||||
|
||||
private Thread t;
|
||||
private int piLength = 0;
|
||||
|
||||
public TestThread (int piLength){
|
||||
this.piLength = piLength;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
ComputePi.computePi(piLength);
|
||||
}
|
||||
|
||||
public void start () {
|
||||
if (t == null) {
|
||||
t = new Thread (this);
|
||||
t.start ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,103 @@
|
||||
package cn.estsh.i3plus.core.apiservice.serviceimpl.busi;
|
||||
|
||||
import cn.estsh.i3plus.core.api.iservice.busi.ISysBarcodeRuleService;
|
||||
import cn.estsh.i3plus.pojo.base.bean.ListPager;
|
||||
import cn.estsh.i3plus.pojo.base.common.Pager;
|
||||
import cn.estsh.i3plus.pojo.base.common.PagerHelper;
|
||||
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
|
||||
import cn.estsh.i3plus.pojo.platform.bean.SysBarcodeRule;
|
||||
import cn.estsh.i3plus.pojo.platform.repository.SysBarcodeRuleRepository;
|
||||
import cn.estsh.i3plus.pojo.platform.sqlpack.CoreHqlPack;
|
||||
import cn.estsh.impp.framework.boot.exception.ImppExceptionBuilder;
|
||||
import cn.estsh.impp.framework.boot.exception.ImppExceptionEnum;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description : 条码规则服务
|
||||
* @Reference :
|
||||
* @Author : yunhao
|
||||
* @CreateDate : 2019-03-12 16:13
|
||||
* @Modify:
|
||||
**/
|
||||
@Service
|
||||
public class SysBarcodeRuleService implements ISysBarcodeRuleService {
|
||||
public static final Logger LOGGER = LoggerFactory.getLogger(SysBarcodeRuleService.class);
|
||||
|
||||
@Autowired
|
||||
private SysBarcodeRuleRepository sysBarcodeRuleRDao;
|
||||
|
||||
@Override
|
||||
@ApiOperation(value = "新增条码规则信息")
|
||||
public SysBarcodeRule insertSysBarcodeRule(SysBarcodeRule barcodeRule) {
|
||||
// 数据校验
|
||||
if (sysBarcodeRuleRDao.isExitByProperty("barcodeRuleCode",barcodeRule.getBarcodeRuleCode())) {
|
||||
throw ImppExceptionBuilder.newInstance()
|
||||
.setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode())
|
||||
.setErrorCode(ImppExceptionEnum.VARIFY_EXCEPTION_DATA_EXIT.getCode())
|
||||
.setErrorDetail("规则代码已存在")
|
||||
.setErrorSolution("请重新输入规则代码")
|
||||
.build();
|
||||
}
|
||||
|
||||
return sysBarcodeRuleRDao.insert(barcodeRule);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ApiOperation(value = "更新条码规则信息")
|
||||
public void updateSysBarcodeRule(SysBarcodeRule barcodeRule) {
|
||||
List list = sysBarcodeRuleRDao.findByHqlWhere(CoreHqlPack.packHqlSysBarcodeRuleCode(barcodeRule));
|
||||
if (list == null && list.size() == 0) {
|
||||
throw ImppExceptionBuilder.newInstance()
|
||||
.setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode())
|
||||
.setErrorCode(ImppExceptionEnum.VARIFY_EXCEPTION_DATA_EXIT.getCode())
|
||||
.setErrorDetail("规则代码已存在")
|
||||
.setErrorSolution("请重新输入规则代码")
|
||||
.build();
|
||||
}
|
||||
|
||||
sysBarcodeRuleRDao.update(barcodeRule);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ApiOperation(value = "查询所有条码规则信息",notes = "查询所有条码规则信息")
|
||||
public List<SysBarcodeRule> listSysBarcodeRule() {
|
||||
return sysBarcodeRuleRDao.list();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ApiOperation(value = "查询条码规则信息",notes = "根据ID查询条码规则信息")
|
||||
public SysBarcodeRule getSysBarcodeRuleById(Long id) {
|
||||
return sysBarcodeRuleRDao.getById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ApiOperation(value = "根据id删除条码规则",notes = "根据id删除条码规则")
|
||||
public void deleteSysBarcodeRuleById(Long id) {
|
||||
sysBarcodeRuleRDao.deleteById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ApiOperation(value = "根据规则代码查询条码规则",notes = "根据规则代码查询条码规则")
|
||||
public SysBarcodeRule getSysBarcodeRuleByCode(String code) {
|
||||
return sysBarcodeRuleRDao.getByProperty("barcodeRuleCode",code);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ApiOperation(value = "根据规则代码查询条码规则",notes = "根据规则代码查询条码规则")
|
||||
public ListPager<SysBarcodeRule> querySysBarcodeRuleByPager(SysBarcodeRule barcodeRule, Pager pager) {
|
||||
if(barcodeRule == null) {
|
||||
pager = PagerHelper.getPager(pager, sysBarcodeRuleRDao.listCount());
|
||||
return new ListPager(sysBarcodeRuleRDao.listPager(pager),pager);
|
||||
}else {
|
||||
String hqlPack = CoreHqlPack.packHqlSysBarcodeRule(barcodeRule);
|
||||
pager = PagerHelper.getPager(pager, sysBarcodeRuleRDao.findByHqlWhereCount(hqlPack));
|
||||
return new ListPager(sysBarcodeRuleRDao.findByHqlWherePage(hqlPack + barcodeRule.orderBy(),pager),pager);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
package cn.estsh.i3plus.core.apiservice.util;
|
||||
|
||||
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
|
||||
import cn.estsh.i3plus.pojo.platform.bean.SysBarcodeRule;
|
||||
import cn.estsh.impp.framework.boot.exception.ImppExceptionBuilder;
|
||||
import cn.estsh.impp.framework.boot.exception.ImppExceptionEnum;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Description : 字符串解析
|
||||
* @Reference :
|
||||
* @Author : yunhao
|
||||
* @CreateDate : 2019-03-12 14:41
|
||||
* @Modify:
|
||||
**/
|
||||
public class BarcodeParseUtil {
|
||||
|
||||
/**
|
||||
* 按指定规则解析条码
|
||||
* @param barcodeRule
|
||||
* @param barcode
|
||||
* @return
|
||||
*/
|
||||
public static Map<String,String> parse(SysBarcodeRule barcodeRule,String barcode){
|
||||
// 数据有效性校验
|
||||
if(barcodeRule == null || barcode == null){
|
||||
return null;
|
||||
}else if(barcodeRule.getBarcodeRule() == null || barcodeRule.getBarcodeSeparator() == null){
|
||||
throw ImppExceptionBuilder.newInstance()
|
||||
.setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode())
|
||||
.setErrorCode(ImppExceptionEnum.VARIFY_EXCEPTION.getCode())
|
||||
.setErrorDetail("条码规则不完善!")
|
||||
.build();
|
||||
}
|
||||
|
||||
// 分隔条码信息
|
||||
String[] barcodeKey = barcodeRule.getBarcodeRule().split(barcodeRule.getBarcodeSeparator());
|
||||
String[] barcodeValue = barcode.split(barcodeRule.getBarcodeSeparator());
|
||||
|
||||
if(barcodeKey.length != barcodeValue.length){
|
||||
throw ImppExceptionBuilder.newInstance()
|
||||
.setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode())
|
||||
.setErrorCode(ImppExceptionEnum.VARIFY_EXCEPTION.getCode())
|
||||
.setErrorDetail("条码与规则不匹配!")
|
||||
.build();
|
||||
}
|
||||
|
||||
// 匹配条码数据
|
||||
HashMap<String,String> barcodeMap = new HashMap<>();
|
||||
for (int i = 0; i < barcodeKey.length; i++) {
|
||||
barcodeMap.put(barcodeKey[i],barcodeValue[i]);
|
||||
}
|
||||
return barcodeMap;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
SysBarcodeRule barcodeRule = new SysBarcodeRule();
|
||||
barcodeRule.setName("测试条码规则");
|
||||
barcodeRule.setBarcodeRuleCode("Barcode");
|
||||
barcodeRule.setBarcodeRule("orderNo/groupId/num");
|
||||
barcodeRule.setBarcodeSeparator("/");
|
||||
barcodeRule.setBarcodeRuleDescription("描述");
|
||||
|
||||
Map barcode= parse(barcodeRule,"99/99/99");
|
||||
|
||||
System.out.println(barcode);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue