From 5f03fabb381507f23742eb998aab1282699c1972 Mon Sep 17 00:00:00 2001 From: zengchenxi Date: Tue, 6 Aug 2024 15:35:36 +0800 Subject: [PATCH] month --- .../service/YysMonthlyProductionService.java | 3 +- .../impl/YysMonthlyProductionServiceImpl.java | 312 ++++++++++-------- .../YysMonthlyProductionController.java | 7 +- .../views/yys/yysmonthlyproduction/form.vue | 1 + 4 files changed, 182 insertions(+), 141 deletions(-) diff --git a/jnpf-java-boot/jnpf-example/jnpf-example-biz/src/main/java/jnpf/service/YysMonthlyProductionService.java b/jnpf-java-boot/jnpf-example/jnpf-example-biz/src/main/java/jnpf/service/YysMonthlyProductionService.java index 1d1a09e..8762fdb 100644 --- a/jnpf-java-boot/jnpf-example/jnpf-example-biz/src/main/java/jnpf/service/YysMonthlyProductionService.java +++ b/jnpf-java-boot/jnpf-example/jnpf-example-biz/src/main/java/jnpf/service/YysMonthlyProductionService.java @@ -4,7 +4,6 @@ import jnpf.model.yysmonthlyproduction.*; import jnpf.entity.*; import java.util.*; import com.baomidou.mybatisplus.extension.service.IService; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; /** * yysMonthlyProduction @@ -30,6 +29,6 @@ public interface YysMonthlyProductionService extends IService implements YysMonthlyProductionService{ +public class YysMonthlyProductionServiceImpl extends ServiceImpl implements YysMonthlyProductionService { @Autowired private GeneraterSwapUtil generaterSwapUtil; @@ -47,246 +48,291 @@ public class YysMonthlyProductionServiceImpl extends ServiceImpl getList(YysMonthlyProductionPagination yysMonthlyProductionPagination){ - return getTypeList(yysMonthlyProductionPagination,yysMonthlyProductionPagination.getDataType()); + public List getList(YysMonthlyProductionPagination yysMonthlyProductionPagination) { +// QueryWrapper wrapper = new QueryWrapper<>(); +// if (ObjectUtil.isNotEmpty(yysMonthlyProductionPagination.getYears())) { +// wrapper.lambda().eq(YysMonthlyProductionEntity::getYears, yysMonthlyProductionPagination.getYears().toString()); +// } +// wrapper.lambda().isNull(YysMonthlyProductionEntity::getDeleteMark); +// wrapper.last("ORDER BY CAST(day AS UNSIGNED)"); +// Page page = new Page<>(yysMonthlyProductionPagination.getCurrentPage(), yysMonthlyProductionPagination.getPageSize()); +// IPage userIPage = this.page(page, wrapper); +// return yysMonthlyProductionPagination.setData(userIPage.getRecords(), userIPage.getTotal()); + return getTypeList(yysMonthlyProductionPagination, yysMonthlyProductionPagination.getDataType()); + } - /** 列表查询 */ + + /** + * 列表查询 + */ @Override - public List getTypeList(YysMonthlyProductionPagination yysMonthlyProductionPagination,String dataType){ - String userId=userProvider.get().getUserId(); - List AllIdList =new ArrayList(); - List> intersectionList =new ArrayList<>(); + public List getTypeList(YysMonthlyProductionPagination yysMonthlyProductionPagination, String dataType) { + String userId = userProvider.get().getUserId(); + List AllIdList = new ArrayList(); + List> intersectionList = new ArrayList<>(); boolean isPc = ServletUtil.getHeader("jnpf-origin").equals("pc"); String columnData = !isPc ? YysMonthlyProductionConstant.getAppColumnData() : YysMonthlyProductionConstant.getColumnData(); ColumnDataModel columnDataModel = JsonUtil.getJsonToBean(columnData, ColumnDataModel.class); String ruleJson = !isPc ? JsonUtil.getObjectToString(columnDataModel.getRuleListApp()) : JsonUtil.getObjectToString(columnDataModel.getRuleList()); - int total=0; - int yysMonthlyProductionNum =0; - QueryWrapper yysMonthlyProductionQueryWrapper=new QueryWrapper<>(); + int total = 0; + int yysMonthlyProductionNum = 0; + QueryWrapper yysMonthlyProductionQueryWrapper = new QueryWrapper<>(); List allSuperIDlist = new ArrayList<>(); - String superOp =""; - if (ObjectUtil.isNotEmpty(yysMonthlyProductionPagination.getSuperQueryJson())){ + String superOp = ""; + if (ObjectUtil.isNotEmpty(yysMonthlyProductionPagination.getSuperQueryJson())) { List allSuperList = new ArrayList<>(); - List> intersectionSuperList = new ArrayList<>(); + List> intersectionSuperList = new ArrayList<>(); String queryJson = yysMonthlyProductionPagination.getSuperQueryJson(); SuperJsonModel superJsonModel = JsonUtil.getJsonToBean(queryJson, SuperJsonModel.class); int superNum = 0; QueryWrapper yysMonthlyProductionSuperWrapper = new QueryWrapper<>(); - yysMonthlyProductionSuperWrapper = generaterSwapUtil.getCondition(new QueryModel(yysMonthlyProductionSuperWrapper,YysMonthlyProductionEntity.class,queryJson,"0")); + yysMonthlyProductionSuperWrapper = generaterSwapUtil.getCondition(new QueryModel(yysMonthlyProductionSuperWrapper, YysMonthlyProductionEntity.class, queryJson, "0")); int yysMonthlyProductionNum1 = yysMonthlyProductionSuperWrapper.getExpression().getNormal().size(); - if (yysMonthlyProductionNum1>0){ - List yysMonthlyProductionList =this.list(yysMonthlyProductionSuperWrapper).stream().map(YysMonthlyProductionEntity::getId).collect(Collectors.toList()); + if (yysMonthlyProductionNum1 > 0) { + List yysMonthlyProductionList = this.list(yysMonthlyProductionSuperWrapper).stream().map(YysMonthlyProductionEntity::getId).collect(Collectors.toList()); allSuperList.addAll(yysMonthlyProductionList); intersectionSuperList.add(yysMonthlyProductionList); superNum++; } superOp = superNum > 0 ? superJsonModel.getMatchLogic() : ""; //and or - if(superOp.equalsIgnoreCase("and")){ + if (superOp.equalsIgnoreCase("and")) { allSuperIDlist = generaterSwapUtil.getIntersection(intersectionSuperList); - }else{ + } else { allSuperIDlist = allSuperList; } } List allRuleIDlist = new ArrayList<>(); - String ruleOp =""; - if (ObjectUtil.isNotEmpty(ruleJson)){ + String ruleOp = ""; + if (ObjectUtil.isNotEmpty(ruleJson)) { List allRuleList = new ArrayList<>(); - List> intersectionRuleList = new ArrayList<>(); + List> intersectionRuleList = new ArrayList<>(); SuperJsonModel ruleJsonModel = JsonUtil.getJsonToBean(ruleJson, SuperJsonModel.class); int ruleNum = 0; QueryWrapper yysMonthlyProductionSuperWrapper = new QueryWrapper<>(); - yysMonthlyProductionSuperWrapper = generaterSwapUtil.getCondition(new QueryModel(yysMonthlyProductionSuperWrapper,YysMonthlyProductionEntity.class,ruleJson,"0")); + yysMonthlyProductionSuperWrapper = generaterSwapUtil.getCondition(new QueryModel(yysMonthlyProductionSuperWrapper, YysMonthlyProductionEntity.class, ruleJson, "0")); int yysMonthlyProductionNum1 = yysMonthlyProductionSuperWrapper.getExpression().getNormal().size(); - if (yysMonthlyProductionNum1>0){ - List yysMonthlyProductionList =this.list(yysMonthlyProductionSuperWrapper).stream().map(YysMonthlyProductionEntity::getId).collect(Collectors.toList()); + if (yysMonthlyProductionNum1 > 0) { + List yysMonthlyProductionList = this.list(yysMonthlyProductionSuperWrapper).stream().map(YysMonthlyProductionEntity::getId).collect(Collectors.toList()); allRuleList.addAll(yysMonthlyProductionList); intersectionRuleList.add(yysMonthlyProductionList); ruleNum++; } ruleOp = ruleNum > 0 ? ruleJsonModel.getMatchLogic() : ""; //and or - if(ruleOp.equalsIgnoreCase("and")){ + if (ruleOp.equalsIgnoreCase("and")) { allRuleIDlist = generaterSwapUtil.getIntersection(intersectionRuleList); - }else{ + } else { allRuleIDlist = allRuleList; } } - boolean pcPermission = false; - boolean appPermission = false; - if(isPc && pcPermission){ - if (!userProvider.get().getIsAdministrator()){ - Object yysMonthlyProductionObj=generaterSwapUtil.getAuthorizeCondition(new QueryModel(yysMonthlyProductionQueryWrapper,YysMonthlyProductionEntity.class,yysMonthlyProductionPagination.getMenuId(),"0")); - if (ObjectUtil.isEmpty(yysMonthlyProductionObj)){ - return new ArrayList<>(); - } else { - yysMonthlyProductionQueryWrapper = (QueryWrapper)yysMonthlyProductionObj; - if( yysMonthlyProductionQueryWrapper.getExpression().getNormal().size()>0){ - yysMonthlyProductionNum++; - } - } - } - } - if(!isPc && appPermission){ - if (!userProvider.get().getIsAdministrator()){ - Object yysMonthlyProductionObj=generaterSwapUtil.getAuthorizeCondition(new QueryModel(yysMonthlyProductionQueryWrapper,YysMonthlyProductionEntity.class,yysMonthlyProductionPagination.getMenuId(),"0")); - if (ObjectUtil.isEmpty(yysMonthlyProductionObj)){ - return new ArrayList<>(); - } else { - yysMonthlyProductionQueryWrapper = (QueryWrapper)yysMonthlyProductionObj; - if( yysMonthlyProductionQueryWrapper.getExpression().getNormal().size()>0){ - yysMonthlyProductionNum++; - } + boolean pcPermission = false; + boolean appPermission = false; + if (isPc && pcPermission) { + if (!userProvider.get().getIsAdministrator()) { + Object yysMonthlyProductionObj = generaterSwapUtil.getAuthorizeCondition(new QueryModel(yysMonthlyProductionQueryWrapper, YysMonthlyProductionEntity.class, yysMonthlyProductionPagination.getMenuId(), "0")); + if (ObjectUtil.isEmpty(yysMonthlyProductionObj)) { + return new ArrayList<>(); + } else { + yysMonthlyProductionQueryWrapper = (QueryWrapper) yysMonthlyProductionObj; + if (yysMonthlyProductionQueryWrapper.getExpression().getNormal().size() > 0) { + yysMonthlyProductionNum++; + } + } + } } + if (!isPc && appPermission) { + if (!userProvider.get().getIsAdministrator()) { + Object yysMonthlyProductionObj = generaterSwapUtil.getAuthorizeCondition(new QueryModel(yysMonthlyProductionQueryWrapper, YysMonthlyProductionEntity.class, yysMonthlyProductionPagination.getMenuId(), "0")); + if (ObjectUtil.isEmpty(yysMonthlyProductionObj)) { + return new ArrayList<>(); + } else { + yysMonthlyProductionQueryWrapper = (QueryWrapper) yysMonthlyProductionObj; + if (yysMonthlyProductionQueryWrapper.getExpression().getNormal().size() > 0) { + yysMonthlyProductionNum++; + } + } - } - } - if(isPc){ - if(ObjectUtil.isNotEmpty(yysMonthlyProductionPagination.getYears())){ - yysMonthlyProductionNum++; + } + } + if (isPc) { + if (ObjectUtil.isNotEmpty(yysMonthlyProductionPagination.getYears())) { + yysMonthlyProductionNum++; String value = yysMonthlyProductionPagination.getYears() instanceof List ? - JsonUtil.getObjectToString(yysMonthlyProductionPagination.getYears()) : - String.valueOf(yysMonthlyProductionPagination.getYears()); - yysMonthlyProductionQueryWrapper.lambda().eq(YysMonthlyProductionEntity::getYears,value); + JsonUtil.getObjectToString(yysMonthlyProductionPagination.getYears()) : + String.valueOf(yysMonthlyProductionPagination.getYears()); + yysMonthlyProductionQueryWrapper.lambda().eq(YysMonthlyProductionEntity::getYears, value); } - if(ObjectUtil.isNotEmpty(yysMonthlyProductionPagination.getProductId())){ - yysMonthlyProductionNum++; + if (ObjectUtil.isNotEmpty(yysMonthlyProductionPagination.getProductId())) { + yysMonthlyProductionNum++; String value = yysMonthlyProductionPagination.getProductId() instanceof List ? - JsonUtil.getObjectToString(yysMonthlyProductionPagination.getProductId()) : - String.valueOf(yysMonthlyProductionPagination.getProductId()); - yysMonthlyProductionQueryWrapper.lambda().like(YysMonthlyProductionEntity::getProductId,value); + JsonUtil.getObjectToString(yysMonthlyProductionPagination.getProductId()) : + String.valueOf(yysMonthlyProductionPagination.getProductId()); + yysMonthlyProductionQueryWrapper.lambda().like(YysMonthlyProductionEntity::getProductId, value); } } List intersection = generaterSwapUtil.getIntersection(intersectionList); - if (total>0){ - if (intersection.size()==0){ + if (total > 0) { + if (intersection.size() == 0) { intersection.add("jnpfNullList"); } yysMonthlyProductionQueryWrapper.lambda().in(YysMonthlyProductionEntity::getId, intersection); } - //是否有高级查询 - if (StringUtil.isNotEmpty(superOp)){ - if (allSuperIDlist.size()==0){ + //是否有高级查询 + if (StringUtil.isNotEmpty(superOp)) { + if (allSuperIDlist.size() == 0) { allSuperIDlist.add("jnpfNullList"); } List finalAllSuperIDlist = allSuperIDlist; - yysMonthlyProductionQueryWrapper.lambda().and(t->t.in(YysMonthlyProductionEntity::getId, finalAllSuperIDlist)); + yysMonthlyProductionQueryWrapper.lambda().and(t -> t.in(YysMonthlyProductionEntity::getId, finalAllSuperIDlist)); } - //是否有数据过滤查询 - if (StringUtil.isNotEmpty(ruleOp)){ - if (allRuleIDlist.size()==0){ + //是否有数据过滤查询 + if (StringUtil.isNotEmpty(ruleOp)) { + if (allRuleIDlist.size() == 0) { allRuleIDlist.add("jnpfNullList"); } List finalAllRuleIDlist = allRuleIDlist; - yysMonthlyProductionQueryWrapper.lambda().and(t->t.in(YysMonthlyProductionEntity::getId, finalAllRuleIDlist)); + yysMonthlyProductionQueryWrapper.lambda().and(t -> t.in(YysMonthlyProductionEntity::getId, finalAllRuleIDlist)); } //排序 - if(StringUtil.isEmpty(yysMonthlyProductionPagination.getSidx())){ + if (StringUtil.isEmpty(yysMonthlyProductionPagination.getSidx())) { yysMonthlyProductionQueryWrapper.lambda().orderByDesc(YysMonthlyProductionEntity::getId); - }else{ + } else { try { String sidx = yysMonthlyProductionPagination.getSidx(); - String[] strs= sidx.split("_name"); + String[] strs = sidx.split("_name"); YysMonthlyProductionEntity yysMonthlyProductionEntity = new YysMonthlyProductionEntity(); Field declaredField = yysMonthlyProductionEntity.getClass().getDeclaredField(strs[0]); declaredField.setAccessible(true); String value = declaredField.getAnnotation(TableField.class).value(); - yysMonthlyProductionQueryWrapper="asc".equals(yysMonthlyProductionPagination.getSort().toLowerCase())?yysMonthlyProductionQueryWrapper.orderByAsc(value):yysMonthlyProductionQueryWrapper.orderByDesc(value); + yysMonthlyProductionQueryWrapper = "asc".equals(yysMonthlyProductionPagination.getSort().toLowerCase()) ? yysMonthlyProductionQueryWrapper.orderByAsc(value) : yysMonthlyProductionQueryWrapper.orderByDesc(value); } catch (NoSuchFieldException e) { e.printStackTrace(); } } - if("0".equals(dataType)){ - if((total>0 && AllIdList.size()>0) || total==0){ - Page page=new Page<>(yysMonthlyProductionPagination.getCurrentPage(), yysMonthlyProductionPagination.getPageSize()); - IPage userIPage=this.page(page, yysMonthlyProductionQueryWrapper); - return yysMonthlyProductionPagination.setData(userIPage.getRecords(),userIPage.getTotal()); - }else{ + if ("0".equals(dataType)) { + if ((total > 0 && AllIdList.size() > 0) || total == 0) { + Page page = new Page<>(yysMonthlyProductionPagination.getCurrentPage(), yysMonthlyProductionPagination.getPageSize()); + IPage userIPage = this.page(page, yysMonthlyProductionQueryWrapper); + return yysMonthlyProductionPagination.setData(userIPage.getRecords(), userIPage.getTotal()); + } else { List list = new ArrayList(); return yysMonthlyProductionPagination.setData(list, list.size()); } - }else{ + } else { return this.list(yysMonthlyProductionQueryWrapper); } } + @Override - public YysMonthlyProductionEntity getInfo(String id){ - QueryWrapper queryWrapper=new QueryWrapper<>(); - queryWrapper.lambda().eq(YysMonthlyProductionEntity::getId,id); + public YysMonthlyProductionEntity getInfo(String id) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.lambda().eq(YysMonthlyProductionEntity::getId, id); return this.getOne(queryWrapper); } + @Override - public void create(YysMonthlyProductionEntity entity){ + public void create(YysMonthlyProductionEntity entity) { this.save(entity); } + @Override - public boolean update(String id, YysMonthlyProductionEntity entity){ + public boolean update(String id, YysMonthlyProductionEntity entity) { return this.updateById(entity); } + @Override - public void delete(YysMonthlyProductionEntity entity){ - if(entity!=null){ + public void delete(YysMonthlyProductionEntity entity) { + if (entity != null) { this.removeById(entity.getId()); } } - /** 验证表单唯一字段,正则,非空 i-0新增-1修改*/ + + /** + * 验证表单唯一字段,正则,非空 i-0新增-1修改 + */ @Override - public String checkForm(YysMonthlyProductionForm form,int i) { - boolean isUp =StringUtil.isNotEmpty(form.getId()) && !form.getId().equals("0"); - String id=""; + public String checkForm(YysMonthlyProductionForm form, int i) { + boolean isUp = StringUtil.isNotEmpty(form.getId()) && !form.getId().equals("0"); + String id = ""; String countRecover = ""; - if (isUp){ + if (isUp) { id = form.getId(); } //主表字段验证 - if(StringUtil.isEmpty(form.getYears())){ - return "年月不能为空"; - } - if(StringUtil.isEmpty(form.getProductId())){ - return "产品编码不能为空"; - } - if(StringUtil.isEmpty(form.getModel())){ - return "规格型号不能为空"; - } - if(StringUtil.isEmpty(form.getMeasurementUnit())){ - return "计量单位不能为空"; - } - if(StringUtil.isEmpty(form.getCurrentInventory())){ - return "当前库存不能为空"; - } + if (StringUtil.isEmpty(form.getYears())) { + return "年月不能为空"; + } + if (StringUtil.isEmpty(form.getProductId())) { + return "产品编码不能为空"; + } + if (StringUtil.isEmpty(form.getModel())) { + return "规格型号不能为空"; + } + if (StringUtil.isEmpty(form.getMeasurementUnit())) { + return "计量单位不能为空"; + } + if (StringUtil.isEmpty(form.getCurrentInventory())) { + return "当前库存不能为空"; + } return countRecover; } + /** - * 新增修改数据(事务回滚) - * @param id - * @param yysMonthlyProductionForm - * @return - */ + * 新增修改数据(事务回滚) + * + * @param id + * @param yysMonthlyProductionForm + * @return + */ @Override @Transactional - public void saveOrUpdate(YysMonthlyProductionForm yysMonthlyProductionForm,String id, boolean isSave) throws Exception{ - UserInfo userInfo=userProvider.get(); + public String saveOrUpdate(YysMonthlyProductionForm yysMonthlyProductionForm, String id, boolean isSave) { + UserInfo userInfo = userProvider.get(); + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(YysMonthlyProductionEntity.class); + UserEntity userEntity = generaterSwapUtil.getUser(userInfo.getUserId()); yysMonthlyProductionForm = JsonUtil.getJsonToBean( - generaterSwapUtil.swapDatetime(YysMonthlyProductionConstant.getFormData(),yysMonthlyProductionForm),YysMonthlyProductionForm.class); + generaterSwapUtil.swapDatetime(YysMonthlyProductionConstant.getFormData(), yysMonthlyProductionForm), YysMonthlyProductionForm.class); YysMonthlyProductionEntity entity = JsonUtil.getJsonToBean(yysMonthlyProductionForm, YysMonthlyProductionEntity.class); - if(isSave){ - String mainId = RandomUtil.uuId() ; + if (isSave) { + wrapper.eq(YysMonthlyProductionEntity::getYears, yysMonthlyProductionForm.getYears()); + wrapper.eq(YysMonthlyProductionEntity::getProductName, yysMonthlyProductionForm.getProductName()); + if (CollectionUtils.isNotEmpty(this.list(wrapper))) { + return "所选年月与产品已被创建"; + } + String mainId = RandomUtil.uuId(); + entity.setCreatorTime(DateUtil.getNowDate()); + entity.setCreatorUserId(userInfo.getUserId()); entity.setId(mainId); - }else{ + + } else { + + wrapper.ne(YysMonthlyProductionEntity::getYears, yysMonthlyProductionForm.getYears()); + wrapper.ne(YysMonthlyProductionEntity::getProductName, yysMonthlyProductionForm.getProductName()); + + if (CollectionUtils.isNotEmpty(this.list(wrapper))) { + return "所选年月与产品已被创建"; + } + entity.setLastModifyTime(DateUtil.getNowDate()); + entity.setLastModifyUserId(userInfo.getUserId()); + } + boolean result = this.saveOrUpdate(entity); + if (result) { + return "操作成功"; } - this.saveOrUpdate(entity); + return "操作失败"; } } diff --git a/jnpf-java-boot/jnpf-example/jnpf-example-controller/src/main/java/jnpf/controller/YysMonthlyProductionController.java b/jnpf-java-boot/jnpf-example/jnpf-example-controller/src/main/java/jnpf/controller/YysMonthlyProductionController.java index d955c4d..bee0689 100644 --- a/jnpf-java-boot/jnpf-example/jnpf-example-controller/src/main/java/jnpf/controller/YysMonthlyProductionController.java +++ b/jnpf-java-boot/jnpf-example/jnpf-example-controller/src/main/java/jnpf/controller/YysMonthlyProductionController.java @@ -117,12 +117,7 @@ public class YysMonthlyProductionController { if (StringUtil.isNotEmpty(b)){ return ActionResult.fail(b ); } - try{ - yysMonthlyProductionService.saveOrUpdate(yysMonthlyProductionForm, null ,true); - }catch(Exception e){ - return ActionResult.fail("新增数据失败"); - } - return ActionResult.success("创建成功"); + return ActionResult.success(yysMonthlyProductionService.saveOrUpdate(yysMonthlyProductionForm, null, true)); } /** * 导出Excel diff --git a/jnpf-java-boot/jnpf-web/src/views/yys/yysmonthlyproduction/form.vue b/jnpf-java-boot/jnpf-web/src/views/yys/yysmonthlyproduction/form.vue index 8ba6fc8..9c25622 100644 --- a/jnpf-java-boot/jnpf-web/src/views/yys/yysmonthlyproduction/form.vue +++ b/jnpf-java-boot/jnpf-web/src/views/yys/yysmonthlyproduction/form.vue @@ -346,6 +346,7 @@ export default { //初始化默认数据 initDefaultData() { this.dataForm.deliveryTime = new Date().getTime() + this.dataForm.years = new Date().getTime() }, // 表单提交