diff --git a/src/main/java/com/qs/serve/modules/goods/common/GoodsSpuColumnUtil.java b/src/main/java/com/qs/serve/modules/goods/common/GoodsSpuColumnUtil.java new file mode 100644 index 00000000..0e6da582 --- /dev/null +++ b/src/main/java/com/qs/serve/modules/goods/common/GoodsSpuColumnUtil.java @@ -0,0 +1,29 @@ +package com.qs.serve.modules.goods.common; + +import com.qs.serve.common.util.StringUtils; + +import java.util.HashMap; +import java.util.Map; + +/** + * @author YenHex + * @since 2024/8/28 + */ +public class GoodsSpuColumnUtil { + + private static Map ORDER_SPU_COLUMN = new HashMap<>(); + + static { + ORDER_SPU_COLUMN.put("createTime","goods_spu.create_time"); + ORDER_SPU_COLUMN.put("updateTime","goods_spu.update_time"); + } + + + public static String getSpuColumn(String orderProp){ + if(!StringUtils.hasText(orderProp)){ + return null; + } + return ORDER_SPU_COLUMN.get(orderProp); + } + +} diff --git a/src/main/java/com/qs/serve/modules/goods/controller/GoodsSpuController.java b/src/main/java/com/qs/serve/modules/goods/controller/GoodsSpuController.java index 09e89917..86297ba3 100644 --- a/src/main/java/com/qs/serve/modules/goods/controller/GoodsSpuController.java +++ b/src/main/java/com/qs/serve/modules/goods/controller/GoodsSpuController.java @@ -90,16 +90,6 @@ public class GoodsSpuController { return R.ok(spuList); } - /** - * 翻页搜索 - * @return - */ - @GetMapping("/initSkuNum") - public R> initSkuNum(){ - goodsSpuService.initSkuNum(); - return R.ok(); - } - /** * 翻页搜索(组件接口) * @param param @@ -124,21 +114,6 @@ public class GoodsSpuController { return R.ok(result); } - - /** - * 更新spu下单状态 - * @param spuCode - * @param state - * @return - */ - @PutMapping("/orderState/{spuCode}/{state}") - public R updateOrderState(@PathVariable("spuCode")String spuCode, - @PathVariable("state") Integer state){ - boolean ok = goodsSpuService.update(new LambdaUpdateWrapper() - .eq(GoodsSpu::getSpuCode,spuCode).set(GoodsSpu::getOrderFlag,state)); - return R.isTrue(ok); - } - /** * spu下单查询 * @param param @@ -463,88 +438,6 @@ public class GoodsSpuController { return R.ok(goodsSpu); } - /** - * 商品上下架 - * @param spuId - * @param shelf - * @return - */ - @GetMapping("/shelf") - @SysLog(module = SystemModule.GOODS, title = "spu", biz = BizType.UPDATE) - @PreAuthorize("hasRole('goods:spu:update')") - public R updateById(Long spuId,Integer shelf){ - GoodsSpu goodsSpu = new GoodsSpu(); - goodsSpu.setId(spuId); - goodsSpu.setShelf(shelf); - goodsSpuService.updateById(goodsSpu); - return R.ok(); - } - - /** - * 删除 - * @param id - * @return - */ - @DeleteMapping("/deleteById/{id}") - @SysLog(module = SystemModule.GOODS, title = "spu", biz = BizType.DELETE) - @PreAuthorize("hasRole('goods:spu:delete')") - public R deleteById(@PathVariable("id") Long id){ - QueryWrapper lqw1 = new QueryWrapper<>(); - lqw1.in("target_type", TbsGoodsType.spu.name()); - lqw1.eq("target_id",id); - if(activityGoodsService.count(lqw1)>0){ - return R.error("活动含有当前商品,删除失败"); - } - if(budgetConditionService.count(lqw1)>0){ - return R.error("预算含有当前商品,删除失败"); - } - goodsSpuMapper.updateSpuCodeAndDelFlag(id,IdUtil.timeStampId()); - //删除商品规格 - LambdaQueryWrapper lqw = new LambdaQueryWrapper<>(); - lqw.eq(GoodsSpuSpec::getSpuId,id); - goodsSpuSpecService.remove(lqw); - //删除商品规格值 - LambdaQueryWrapper lqw2 = new LambdaQueryWrapper<>(); - lqw2.eq(GoodsSkuSpecValue::getSpuId,id); - goodsSkuSpecValueService.remove(lqw2); - //删除商品sku - LambdaQueryWrapper lqw3 = new LambdaQueryWrapper<>(); - lqw3.eq(GoodsSku::getSpuId,id); - goodsSkuService.remove(lqw3); - return R.ok(); - } - - /** - * 保存 口味品类SPU - * @param param - * @return - */ - @PostMapping("/saveTasteSpu") - @SysLog(module = SystemModule.GOODS, title = "spu", biz = BizType.INSERT) - @PreAuthorize("hasRole('goods:spu:insert')") - public R saveTasteSpu(@RequestBody @Valid GoodsSpuBo param){ - param.setId(null); - if(StringUtil.isNullOrEmpty(param.getCategoryId())){ - return R.error("参数缺少"); - } - return R.ok(goodsSpuService.editTasteSpu(param)); - } - - /** - * 编辑 口味品类SPU - * @param param - * @return - */ - @PostMapping("/updTasteSpu") - @SysLog(module = SystemModule.GOODS, title = "spu", biz = BizType.INSERT) - @PreAuthorize("hasRole('goods:spu:update')") - public R updTasteSpu(@RequestBody @Valid GoodsSpuBo param){ - if(param.getId()==null){ - return R.error(); - } - return R.ok(goodsSpuService.editTasteSpu(param)); - } - /** * 导出 * @param param @@ -573,174 +466,6 @@ public class GoodsSpuController { return R.ok(exportVoList); } - /** - * 导入 - * @param param - * @return - */ - @PostMapping("/importSpu") - @SysLog(module = SystemModule.GOODS, title = "import", biz = BizType.INSERT) - public R importSpu(@RequestBody @Valid GoodsSpuImportBo param){ - final String UPDATE = "2"; - final String DELETE = "3"; - final String SAVE = "1"; - final String NONE = "4"; - - //导入 - List spuCodes = new ArrayList<>(); - List cateCodes = new ArrayList<>(); - for (GoodsSpuImportBo.SpuItem item : param.getSpuList()) { - spuCodes.add(item.getSpuCode()); - //删除只需要spu编码 - if(StringUtils.hasText(item.getCategoryCode())&&!item.getOpt().equals(DELETE)){ - cateCodes.add(item.getCategoryCode()); - } - } - if(spuCodes.size()<1){ - return R.error("获取SKU编码失败"); - } - LambdaQueryWrapper spuLqw = new LambdaQueryWrapper<>(); - spuLqw.in(GoodsSpu::getSpuCode,spuCodes); - List spuList = goodsSpuService.list(spuLqw); - - List cateList = null; - if(cateCodes.size()>0){ - LambdaQueryWrapper cateLqw = new LambdaQueryWrapper<>(); - cateLqw.in(GoodsCategory::getCode,cateCodes); - cateLqw.eq(GoodsCategory::getLevel,3); - cateList = goodsCategoryService.list(cateLqw); - } - - boolean isError = false; - for (GoodsSpuImportBo.SpuItem item : param.getSpuList()) { - if(item.getOpt().equals(NONE)){ - continue; - } - spuCodes.add(item.getSpuCode()); - //更新或者保存,需要校验类目名称 - if(StringUtils.hasText(item.getCategoryCode())&&!item.getOpt().equals(DELETE)){ - if(cateList==null){ - isError = true; - item.setErrMsg("["+item.getCategoryCode()+"]类目不存在"); - }else { - String cateName = item.getCategoryCode(); - boolean existCate = cateList.stream().anyMatch(a->a.getCode().equals(cateName)); - if(!existCate){ - isError = true; - item.setErrMsg("["+item.getCategoryCode()+"]类目不存在"); - } - } - } - - - String spuCode = item.getSpuCode(); - boolean existSpu = spuList.stream().anyMatch(a->a.getSpuCode().equals(spuCode)); - - if(existSpu&&item.getOpt().equals(SAVE)){ - isError = true; - item.setErrMsg("SKU编码已存在"); - }else if(!existSpu && item.getOpt().equals(UPDATE)){ - isError = true; - item.setErrMsg("SKU编码不存在"); - } - long count = goodsSpuService.count(new LambdaQueryWrapper() - .eq(GoodsSpu::getName,item.getName()) - .ne(GoodsSpu::getSpuCode,spuCode) - ); - if(count>0){ - isError = true; - item.setErrMsg("SKU名称已存在"); - } - } - - if(isError){ - return R.ok(param,"数据错误"); - } - - List rmIds = new ArrayList<>(); - List spuUpdateList = new ArrayList<>(); - List spuSaveList = new ArrayList<>(); - - for (GoodsSpuImportBo.SpuItem spuItem : param.getSpuList()) { - - if(spuItem.getOpt().equals(SAVE)){ - GoodsSpu goodsSpu = new GoodsSpu(); - goodsSpu.setSpuCode(spuItem.getSpuCode()); - goodsSpu.setName(spuItem.getName()); - //修改类目 - this.toSetSpuCate(cateList, spuItem, goodsSpu); - goodsSpu.setShelf(spuItem.getShelf()); - goodsSpu.setCostFlag(spuItem.getCostFlag()); - goodsSpu.setOrderFlag(spuItem.getOrderFlag()); - goodsSpu.setSpuCunhuoFlag(spuItem.getSpuCunhuoFlag()); - spuSaveList.add(goodsSpu); - continue; - } - - for (GoodsSpu spu : spuList) { - if(spu.getSpuCode().equals(spuItem.getSpuCode())){ - if(spuItem.getOpt().equals(NONE)){ - continue; - } - //删除 - if(spuItem.getOpt().equals(DELETE)){ - rmIds.add(spu.getId()); - continue; - } - //更新start - if(StringUtils.hasText(spuItem.getName())){ - spu.setName(spuItem.getName()); - } - spu.setShelf(spuItem.getShelf()); - spu.setCostFlag(spuItem.getCostFlag()); - spu.setOrderFlag(spuItem.getOrderFlag()); - spu.setSpuCunhuoFlag(spuItem.getSpuCunhuoFlag()); - //修改类目 - this.toSetSpuCate(cateList, spuItem, spu); - //关联 - if(spuItem.getOpt().equals(UPDATE)){ - spuUpdateList.add(spu); - } - } - } - } - if(rmIds.size()>0){ - goodsSpuService.removeBatchByIds(rmIds); - } - if(spuUpdateList.size()>0){ - goodsSpuService.updateBatchById(spuUpdateList); - } - if(spuSaveList.size()>0){ - goodsSpuService.saveBatch(spuSaveList); - } - - return R.ok(); - } - - /** - * 修改类目 - * @param cateList - * @param spuItem - * @param spu - */ - private void toSetSpuCate(List cateList, GoodsSpuImportBo.SpuItem spuItem, GoodsSpu spu) { - if(cateList !=null){ - for (GoodsCategory category : cateList) { - if(category.getCode().equals(spuItem.getCategoryCode())){ - spu.setBookName(category.getBookName()); - spu.setBookBelong(category.getBookBelong()); - String[] cateIds = category.getLevelPath().split("_"); - if(cateIds.length==3){ - spu.setCategoryFirst(cateIds[0]); - spu.setCategorySecond(cateIds[1]); - spu.setCategoryThird(cateIds[2]); - spu.setCategoryLast(cateIds[2]); - } - } - } - } - } - /** * 封装通用的spu信息(客户特殊价,转换并关联开平产SKU) * @param supplierCode 客户编码 diff --git a/src/main/java/com/qs/serve/modules/goods/controller/GoodsSpuOptionController.java b/src/main/java/com/qs/serve/modules/goods/controller/GoodsSpuOptionController.java new file mode 100644 index 00000000..9adefb68 --- /dev/null +++ b/src/main/java/com/qs/serve/modules/goods/controller/GoodsSpuOptionController.java @@ -0,0 +1,357 @@ +package com.qs.serve.modules.goods.controller; + +import cn.hutool.core.collection.CollUtil; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; +import com.qs.serve.common.config.DevEnvironmentConfig; +import com.qs.serve.common.model.annotation.SysLog; +import com.qs.serve.common.model.dto.PageVo; +import com.qs.serve.common.model.dto.R; +import com.qs.serve.common.model.enums.BizType; +import com.qs.serve.common.model.enums.SystemModule; +import com.qs.serve.common.util.*; +import com.qs.serve.modules.bms.common.BookAccountUtil; +import com.qs.serve.modules.bms.entity.BmsSupplier; +import com.qs.serve.modules.bms.service.BmsSupplierService; +import com.qs.serve.modules.erp.mapper.ErpDispatchDataMapper; +import com.qs.serve.modules.goods.common.GoodsConst; +import com.qs.serve.modules.goods.entity.*; +import com.qs.serve.modules.goods.entity.bo.GoodsSpuBo; +import com.qs.serve.modules.goods.entity.bo.GoodsSpuImportBo; +import com.qs.serve.modules.goods.entity.dto.GoodsAccrIdsDto; +import com.qs.serve.modules.goods.entity.dto.GoodsRuleItemDTO; +import com.qs.serve.modules.goods.entity.dto.InventoryCusPrice; +import com.qs.serve.modules.goods.entity.so.GoodsHisOrderQuery; +import com.qs.serve.modules.goods.entity.vo.GoodsSpuExportVo; +import com.qs.serve.modules.goods.entity.vo.GoodsSpuVo; +import com.qs.serve.modules.goods.mapper.GoodsSkuMapper; +import com.qs.serve.modules.goods.mapper.GoodsSpuMapper; +import com.qs.serve.modules.goods.service.*; +import com.qs.serve.modules.oms.entity.dto.OmsSpuToSkuKey; +import com.qs.serve.modules.seeyon.service.impl.SeeYonRequestBaseService; +import com.qs.serve.modules.tbs.common.TbsGoodsType; +import com.qs.serve.modules.tbs.service.TbsActivityGoodsService; +import com.qs.serve.modules.tbs.service.TbsBudgetConditionService; +import io.netty.util.internal.StringUtil; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.*; + +import javax.validation.Valid; +import java.time.LocalDate; +import java.util.*; +import java.util.stream.Collectors; + +/** + * 商品 spu + * @author YenHex + * @since 2022-10-09 + */ +@Slf4j +@AllArgsConstructor +@RestController +@RequestMapping("goods/spu") +public class GoodsSpuOptionController { + + private GoodsSpuMapper goodsSpuMapper; + private GoodsSkuMapper goodsSkuMapper; + private GoodsRuleService goodsRuleService; + private GoodsSkuService goodsSkuService; + private GoodsSpuService goodsSpuService; + private GoodsSpuSpecService goodsSpuSpecService; + private GoodsSkuSpecValueService goodsSkuSpecValueService; + private GoodsCategoryRuleService goodsCategoryRuleService; + private TbsActivityGoodsService activityGoodsService; + private TbsBudgetConditionService budgetConditionService; + private BmsSupplierService bmsSupplierService; + private GoodsCategoryService goodsCategoryService; + private SeeYonRequestBaseService seeYonRequestBaseService; + private ErpDispatchDataMapper dispatchDataMapper; + private GoodsAccreditService goodsAccreditService; + private GoodsCustomerPriceService goodsCustomerPriceService; + + + + /** + * 商品上下架 + * @param spuId + * @param shelf + * @return + */ + @GetMapping("/shelf") + @SysLog(module = SystemModule.GOODS, title = "spu", biz = BizType.UPDATE) + @PreAuthorize("hasRole('goods:spu:update')") + public R updateById(Long spuId,Integer shelf){ + GoodsSpu goodsSpu = new GoodsSpu(); + goodsSpu.setId(spuId); + goodsSpu.setShelf(shelf); + goodsSpuService.updateById(goodsSpu); + return R.ok(); + } + + + /** + * 翻页搜索 + * @return + */ + @GetMapping("/initSkuNum") + public R> initSkuNum(){ + goodsSpuService.initSkuNum(); + return R.ok(); + } + + + /** + * 更新spu下单状态 + * @param spuCode + * @param state + * @return + */ + @PutMapping("/orderState/{spuCode}/{state}") + public R updateOrderState(@PathVariable("spuCode")String spuCode, + @PathVariable("state") Integer state){ + boolean ok = goodsSpuService.update(new LambdaUpdateWrapper() + .eq(GoodsSpu::getSpuCode,spuCode).set(GoodsSpu::getOrderFlag,state)); + return R.isTrue(ok); + } + + /** + * 删除 + * @param id + * @return + */ + @DeleteMapping("/deleteById/{id}") + @SysLog(module = SystemModule.GOODS, title = "spu", biz = BizType.DELETE) + @PreAuthorize("hasRole('goods:spu:delete')") + public R deleteById(@PathVariable("id") Long id){ + QueryWrapper lqw1 = new QueryWrapper<>(); + lqw1.in("target_type", TbsGoodsType.spu.name()); + lqw1.eq("target_id",id); + if(activityGoodsService.count(lqw1)>0){ + return R.error("活动含有当前商品,删除失败"); + } + if(budgetConditionService.count(lqw1)>0){ + return R.error("预算含有当前商品,删除失败"); + } + goodsSpuMapper.updateSpuCodeAndDelFlag(id,IdUtil.timeStampId()); + //删除商品规格 + LambdaQueryWrapper lqw = new LambdaQueryWrapper<>(); + lqw.eq(GoodsSpuSpec::getSpuId,id); + goodsSpuSpecService.remove(lqw); + //删除商品规格值 + LambdaQueryWrapper lqw2 = new LambdaQueryWrapper<>(); + lqw2.eq(GoodsSkuSpecValue::getSpuId,id); + goodsSkuSpecValueService.remove(lqw2); + //删除商品sku + LambdaQueryWrapper lqw3 = new LambdaQueryWrapper<>(); + lqw3.eq(GoodsSku::getSpuId,id); + goodsSkuService.remove(lqw3); + return R.ok(); + } + + /** + * 保存 口味品类SPU + * @param param + * @return + */ + @PostMapping("/saveTasteSpu") + @SysLog(module = SystemModule.GOODS, title = "spu", biz = BizType.INSERT) + @PreAuthorize("hasRole('goods:spu:insert')") + public R saveTasteSpu(@RequestBody @Valid GoodsSpuBo param){ + param.setId(null); + if(StringUtil.isNullOrEmpty(param.getCategoryId())){ + return R.error("参数缺少"); + } + return R.ok(goodsSpuService.editTasteSpu(param)); + } + + /** + * 编辑 口味品类SPU + * @param param + * @return + */ + @PostMapping("/updTasteSpu") + @SysLog(module = SystemModule.GOODS, title = "spu", biz = BizType.INSERT) + @PreAuthorize("hasRole('goods:spu:update')") + public R updTasteSpu(@RequestBody @Valid GoodsSpuBo param){ + if(param.getId()==null){ + return R.error(); + } + return R.ok(goodsSpuService.editTasteSpu(param)); + } + + /** + * 导入 + * @param param + * @return + */ + @PostMapping("/importSpu") + @SysLog(module = SystemModule.GOODS, title = "import", biz = BizType.INSERT) + public R importSpu(@RequestBody @Valid GoodsSpuImportBo param){ + final String UPDATE = "2"; + final String DELETE = "3"; + final String SAVE = "1"; + final String NONE = "4"; + + //导入 + List spuCodes = new ArrayList<>(); + List cateCodes = new ArrayList<>(); + for (GoodsSpuImportBo.SpuItem item : param.getSpuList()) { + spuCodes.add(item.getSpuCode()); + //删除只需要spu编码 + if(StringUtils.hasText(item.getCategoryCode())&&!item.getOpt().equals(DELETE)){ + cateCodes.add(item.getCategoryCode()); + } + } + if(spuCodes.size()<1){ + return R.error("获取SKU编码失败"); + } + LambdaQueryWrapper spuLqw = new LambdaQueryWrapper<>(); + spuLqw.in(GoodsSpu::getSpuCode,spuCodes); + List spuList = goodsSpuService.list(spuLqw); + + List cateList = null; + if(cateCodes.size()>0){ + LambdaQueryWrapper cateLqw = new LambdaQueryWrapper<>(); + cateLqw.in(GoodsCategory::getCode,cateCodes); + cateLqw.eq(GoodsCategory::getLevel,3); + cateList = goodsCategoryService.list(cateLqw); + } + + boolean isError = false; + for (GoodsSpuImportBo.SpuItem item : param.getSpuList()) { + if(item.getOpt().equals(NONE)){ + continue; + } + spuCodes.add(item.getSpuCode()); + //更新或者保存,需要校验类目名称 + if(StringUtils.hasText(item.getCategoryCode())&&!item.getOpt().equals(DELETE)){ + if(cateList==null){ + isError = true; + item.setErrMsg("["+item.getCategoryCode()+"]类目不存在"); + }else { + String cateName = item.getCategoryCode(); + boolean existCate = cateList.stream().anyMatch(a->a.getCode().equals(cateName)); + if(!existCate){ + isError = true; + item.setErrMsg("["+item.getCategoryCode()+"]类目不存在"); + } + } + } + + + String spuCode = item.getSpuCode(); + boolean existSpu = spuList.stream().anyMatch(a->a.getSpuCode().equals(spuCode)); + + if(existSpu&&item.getOpt().equals(SAVE)){ + isError = true; + item.setErrMsg("SKU编码已存在"); + }else if(!existSpu && item.getOpt().equals(UPDATE)){ + isError = true; + item.setErrMsg("SKU编码不存在"); + } + long count = goodsSpuService.count(new LambdaQueryWrapper() + .eq(GoodsSpu::getName,item.getName()) + .ne(GoodsSpu::getSpuCode,spuCode) + ); + if(count>0){ + isError = true; + item.setErrMsg("SKU名称已存在"); + } + } + + if(isError){ + return R.ok(param,"数据错误"); + } + + List rmIds = new ArrayList<>(); + List spuUpdateList = new ArrayList<>(); + List spuSaveList = new ArrayList<>(); + + for (GoodsSpuImportBo.SpuItem spuItem : param.getSpuList()) { + + if(spuItem.getOpt().equals(SAVE)){ + GoodsSpu goodsSpu = new GoodsSpu(); + goodsSpu.setSpuCode(spuItem.getSpuCode()); + goodsSpu.setName(spuItem.getName()); + //修改类目 + this.toSetSpuCate(cateList, spuItem, goodsSpu); + goodsSpu.setShelf(spuItem.getShelf()); + goodsSpu.setCostFlag(spuItem.getCostFlag()); + goodsSpu.setOrderFlag(spuItem.getOrderFlag()); + goodsSpu.setSpuCunhuoFlag(spuItem.getSpuCunhuoFlag()); + spuSaveList.add(goodsSpu); + continue; + } + + for (GoodsSpu spu : spuList) { + if(spu.getSpuCode().equals(spuItem.getSpuCode())){ + if(spuItem.getOpt().equals(NONE)){ + continue; + } + //删除 + if(spuItem.getOpt().equals(DELETE)){ + rmIds.add(spu.getId()); + continue; + } + //更新start + if(StringUtils.hasText(spuItem.getName())){ + spu.setName(spuItem.getName()); + } + spu.setShelf(spuItem.getShelf()); + spu.setCostFlag(spuItem.getCostFlag()); + spu.setOrderFlag(spuItem.getOrderFlag()); + spu.setSpuCunhuoFlag(spuItem.getSpuCunhuoFlag()); + //修改类目 + this.toSetSpuCate(cateList, spuItem, spu); + //关联 + if(spuItem.getOpt().equals(UPDATE)){ + spuUpdateList.add(spu); + } + } + } + } + if(rmIds.size()>0){ + goodsSpuService.removeBatchByIds(rmIds); + } + if(spuUpdateList.size()>0){ + goodsSpuService.updateBatchById(spuUpdateList); + } + if(spuSaveList.size()>0){ + goodsSpuService.saveBatch(spuSaveList); + } + + return R.ok(); + } + + /** + * 修改类目 + * @param cateList + * @param spuItem + * @param spu + */ + private void toSetSpuCate(List cateList, GoodsSpuImportBo.SpuItem spuItem, GoodsSpu spu) { + if(cateList !=null){ + for (GoodsCategory category : cateList) { + if(category.getCode().equals(spuItem.getCategoryCode())){ + spu.setBookName(category.getBookName()); + spu.setBookBelong(category.getBookBelong()); + String[] cateIds = category.getLevelPath().split("_"); + if(cateIds.length==3){ + spu.setCategoryFirst(cateIds[0]); + spu.setCategorySecond(cateIds[1]); + spu.setCategoryThird(cateIds[2]); + spu.setCategoryLast(cateIds[2]); + } + } + } + } + } + + +} + diff --git a/src/main/java/com/qs/serve/modules/goods/entity/GoodsSpu.java b/src/main/java/com/qs/serve/modules/goods/entity/GoodsSpu.java index 9929ae78..643e3cdb 100644 --- a/src/main/java/com/qs/serve/modules/goods/entity/GoodsSpu.java +++ b/src/main/java/com/qs/serve/modules/goods/entity/GoodsSpu.java @@ -253,6 +253,18 @@ public class GoodsSpu implements Serializable { @TableField(exist = false) private GoodsAccrIdsDto subAccInfo; + /** + * 排序方式 asc desc + */ + @TableField(exist = false) + private String orderType; + + /** + * 列名 + */ + @TableField(exist = false) + private String orderProp; + public List listCategoryIds(){ List list = new ArrayList<>(); list.add(this.getCategoryFirst()); diff --git a/src/main/java/com/qs/serve/modules/goods/entity/vo/GoodsSpuVo.java b/src/main/java/com/qs/serve/modules/goods/entity/vo/GoodsSpuVo.java index 73cd3f03..9e7b1a9e 100644 --- a/src/main/java/com/qs/serve/modules/goods/entity/vo/GoodsSpuVo.java +++ b/src/main/java/com/qs/serve/modules/goods/entity/vo/GoodsSpuVo.java @@ -67,4 +67,7 @@ public class GoodsSpuVo { /** 可投放费用标识 */ private Integer costFlag; + + /** 存货标识 */ + private Integer spuCunhuoFlag; } diff --git a/src/main/java/com/qs/serve/modules/goods/service/impl/GoodsSpuServiceImpl.java b/src/main/java/com/qs/serve/modules/goods/service/impl/GoodsSpuServiceImpl.java index 7f820e9e..ad3acbee 100644 --- a/src/main/java/com/qs/serve/modules/goods/service/impl/GoodsSpuServiceImpl.java +++ b/src/main/java/com/qs/serve/modules/goods/service/impl/GoodsSpuServiceImpl.java @@ -7,6 +7,7 @@ import com.qs.serve.common.model.dto.RowParam; import com.qs.serve.common.util.*; import com.qs.serve.modules.bms.entity.BmsFactory; import com.qs.serve.modules.bms.service.BmsFactoryService; +import com.qs.serve.modules.goods.common.GoodsSpuColumnUtil; import com.qs.serve.modules.goods.entity.*; import com.qs.serve.modules.goods.entity.bo.GoodsSpuBatchTasteBo; import com.qs.serve.modules.goods.entity.bo.GoodsSpuBo; @@ -48,8 +49,19 @@ public class GoodsSpuServiceImpl extends ServiceImpl im private BmsFactoryService bmsFactoryService; private ProjectApisProperties projectApisProperties; + + @Override public List selectSpuList(GoodsSpu goodsSpu) { + String orderType = PageUtil.getOrderType(); + String orderProp = GoodsSpuColumnUtil.getSpuColumn(goodsSpu.getOrderProp()); + if(orderProp==null||orderType==null){ + goodsSpu.setOrderType(null); + goodsSpu.setOrderProp(null); + }else { + goodsSpu.setOrderType(orderType); + goodsSpu.setOrderProp(orderProp); + } return baseMapper.selectSpuList(goodsSpu); } diff --git a/src/main/java/com/qs/serve/modules/tbs/service/impl/TbsCostApplyServiceImpl.java b/src/main/java/com/qs/serve/modules/tbs/service/impl/TbsCostApplyServiceImpl.java index c04f64db..7eddba45 100644 --- a/src/main/java/com/qs/serve/modules/tbs/service/impl/TbsCostApplyServiceImpl.java +++ b/src/main/java/com/qs/serve/modules/tbs/service/impl/TbsCostApplyServiceImpl.java @@ -167,12 +167,16 @@ public class TbsCostApplyServiceImpl extends ServiceImpl vtbLqw = new LambdaQueryWrapper<>(); vtbLqw.eq(VtbVerification::getCostApplyId,id); vtbLqw.and( diff --git a/src/main/java/com/qs/serve/modules/third/service/PortalOfCostApplication.java b/src/main/java/com/qs/serve/modules/third/service/PortalOfCostApplication.java index 98ae77cf..295bc20e 100644 --- a/src/main/java/com/qs/serve/modules/third/service/PortalOfCostApplication.java +++ b/src/main/java/com/qs/serve/modules/third/service/PortalOfCostApplication.java @@ -228,7 +228,7 @@ public class PortalOfCostApplication { invCodes = createBo.getGoodsList().stream() .map(ProcessGoodsItem::getInventoryCode).distinct().collect(Collectors.toList()); } - List skuList = this.initSkuListOfProcess(invCodes); + List skuList = this.initSkuListOfProcess(invCodes,true); skuList = this.filterRepSku(invCodes, skuList); //常用参数 final String GOODS_TYPE = "sku"; @@ -613,7 +613,9 @@ public class PortalOfCostApplication { if(invCodeList.size()<1){ Assert.throwEx("请选择存货提交"); } - List skuList = this.initSkuListOfProcess(invCodeList); + String costCode = createBo.getCostCode(); + String costTheme = createBo.getCostTheme(); + List skuList = this.initSkuListOfProcess(invCodeList,!costCode.contains("YX06")); //排除重复的sku skuList = this.filterRepSku(invCodeList, skuList); //常用参数 @@ -626,8 +628,6 @@ public class PortalOfCostApplication { String erpCode = createBo.getErpCode(); Long supplierId = Long.parseLong(supplier.getId()); BigDecimal totalAmount = createBo.getTotalAmount(); - String costCode = createBo.getCostCode(); - String costTheme = createBo.getCostTheme(); if(totalAmount.compareTo(BigDecimal.ZERO)==0){ Assert.throwEx("统计金额不能为0"); @@ -1311,14 +1311,15 @@ public class PortalOfCostApplication { /** * 创建流程中,初始化SKU列表 * @param invCodes + * @param filterEnable YX06赔款单,不需要过滤商品是否下架 * @return */ - private List initSkuListOfProcess(List invCodes) { + private List initSkuListOfProcess(List invCodes,boolean filterEnable) { List goodsSkus = null; if(CollectionUtil.isNotEmpty(invCodes)){ LambdaQueryWrapper skuLqw = new LambdaQueryWrapper<>(); skuLqw.in(GoodsSku::getSkuCode,invCodes); - skuLqw.eq(GoodsSku::getEnable,1); + skuLqw.eq(filterEnable,GoodsSku::getEnable,1); goodsSkus = goodsSkuService.list(skuLqw); if(invCodes.size()!=goodsSkus.size()){ List skuCodeNotExistList = new ArrayList<>(); diff --git a/src/main/java/com/qs/serve/modules/wx/common/conf/WxCpConfig.java b/src/main/java/com/qs/serve/modules/wx/common/conf/WxCpConfig.java index a9840792..edb0932d 100644 --- a/src/main/java/com/qs/serve/modules/wx/common/conf/WxCpConfig.java +++ b/src/main/java/com/qs/serve/modules/wx/common/conf/WxCpConfig.java @@ -8,41 +8,30 @@ import me.chanjar.weixin.cp.api.WxCpUserService; import me.chanjar.weixin.cp.api.impl.WxCpServiceImpl; import me.chanjar.weixin.cp.bean.WxCpOauth2UserInfo; import me.chanjar.weixin.cp.bean.WxCpUser; +import me.chanjar.weixin.cp.config.WxCpConfigStorage; import me.chanjar.weixin.cp.config.impl.WxCpDefaultConfigImpl; import org.springframework.context.annotation.Configuration; +import java.util.HashMap; +import java.util.Map; + /** * 企业微信配置 * @author YenHex * @since 2024/8/12 */ @Slf4j -@AllArgsConstructor -@Configuration(proxyBeanMethods = false) public class WxCpConfig { - private static WxCpService wxCpService; - //本公司KEY - private static Integer agentId = 1000008; - private static String secret = "tC2ENr_hs0on-OMfWMQ6ch3TL2ndcUDz1b34K-M7VGg"; - private static String corpId = "ww0e85370756611dc2"; -// //嘉士利KEY -// private static Integer agentId = 100000; -// private static String secret = "Q6ch3TL2ndcUDz1b34K-M7VGg"; -// private static String corpId = "ww0e85370756111111"; + private static Map secretMap = new HashMap<>(); + + static { + secretMap.put(1000008,"tC2ENr_hs0on-OMfWMQ6ch3TL2ndcUDz1b34K-M7VGg"); + secretMap.put(1000009,"uyyatorEYuaT_1Qm45sFQ-UAIVIViR095KI_SV94yrU"); + } - public WxCpService wxCpService(){ - if(wxCpService!=null){ - return wxCpService; - } - WxCpService service = new WxCpServiceImpl(); - WxCpDefaultConfigImpl config =new WxCpDefaultConfigImpl(); - config.setAgentId(agentId); - config.setCorpSecret(secret); - config.setCorpId(corpId); - // 挂载到静态类 - WxCpConfig.wxCpService = service; - return service; + public static String getSecret(Integer agentId){ + return secretMap.get(agentId); } } diff --git a/src/main/java/com/qs/serve/modules/wx/service/WxUserService.java b/src/main/java/com/qs/serve/modules/wx/service/WxUserService.java index 1ed40c84..6651a0f2 100644 --- a/src/main/java/com/qs/serve/modules/wx/service/WxUserService.java +++ b/src/main/java/com/qs/serve/modules/wx/service/WxUserService.java @@ -42,7 +42,10 @@ public interface WxUserService extends IService { * @param openId * @return */ + @Deprecated WxUser getByOpenId(String openId); + WxUser getByOpenId(String appId,String openId); + } diff --git a/src/main/java/com/qs/serve/modules/wx/service/impl/WxUserServiceImpl.java b/src/main/java/com/qs/serve/modules/wx/service/impl/WxUserServiceImpl.java index e1491989..2881db45 100644 --- a/src/main/java/com/qs/serve/modules/wx/service/impl/WxUserServiceImpl.java +++ b/src/main/java/com/qs/serve/modules/wx/service/impl/WxUserServiceImpl.java @@ -30,8 +30,15 @@ import me.chanjar.weixin.common.service.WxOAuth2Service; import me.chanjar.weixin.cp.api.WxCpOAuth2Service; import me.chanjar.weixin.cp.api.WxCpService; import me.chanjar.weixin.cp.api.WxCpUserService; +import me.chanjar.weixin.cp.api.impl.WxCpServiceImpl; import me.chanjar.weixin.cp.bean.WxCpOauth2UserInfo; import me.chanjar.weixin.cp.bean.WxCpUser; +import me.chanjar.weixin.cp.bean.WxCpUserDetail; +import me.chanjar.weixin.cp.config.WxCpTpConfigStorage; +import me.chanjar.weixin.cp.config.impl.WxCpDefaultConfigImpl; +import me.chanjar.weixin.cp.config.impl.WxCpTpDefaultConfigImpl; +import me.chanjar.weixin.cp.tp.service.WxCpTpService; +import me.chanjar.weixin.cp.tp.service.impl.WxCpTpServiceImpl; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.WxMpUserService; import me.chanjar.weixin.mp.bean.result.WxMpUser; @@ -59,9 +66,6 @@ public class WxUserServiceImpl extends ServiceImpl impleme @Autowired(required = false) private WxAppService wxAppService; - @Autowired(required = false) - private WxCpConfig wxCpConfig; - @Autowired private RedisService redisService; @@ -116,7 +120,8 @@ public class WxUserServiceImpl extends ServiceImpl impleme String wxUserId = redisService.getString(wxUserKey); String appId = AuthContextUtils.getAppId(); WxUser wxUser = this.getById(wxUserId); - if(updateSub&&!wxUser.getId().equals("1")){ + if(updateSub&&!wxUser.getId().equals("1") + &&(wxUser.getAppType().equals(1)||wxUser.getAppType().equals(2))){ try { WxMpService wxMpService = wxMpConfig.wxMpService().switchoverTo(appId); WxMpUser wxMpUser = wxMpService.getUserService().userInfo(wxUser.getOpenId(), GySysConst.LANG_ZH_CN); @@ -164,55 +169,73 @@ public class WxUserServiceImpl extends ServiceImpl impleme public WxUser login(WxLoginUser wxLoginUser, HttpServletRequest request){ String code = wxLoginUser.getCode(); String appId = AuthContextUtils.getAppId(); + String agentIdStr = request.getHeader("agentId"); WxApp wxApp = wxAppService.getById(appId); WxUser wxUser = null; if(wxApp.getAppType().equals(WxStatusConst.WxApp_AppType_3)){ - //企业微信登录 - WxCpService wxCpService = wxCpConfig.wxCpService(); + Integer agentId = Integer.parseInt(agentIdStr); + // 企业微信登录 + WxCpService wxCpService = new WxCpServiceImpl(); + WxCpDefaultConfigImpl config =new WxCpDefaultConfigImpl(); + config.setAgentId(agentId); + config.setCorpSecret(WxCpConfig.getSecret(agentId)); + config.setCorpId(wxApp.getId()); + wxCpService.setWxCpConfigStorage(config); + // 授权方式登录 WxCpOAuth2Service oauth2Service = wxCpService.getOauth2Service(); WxCpOauth2UserInfo cpOauth2UserInfo = null; + // 获取敏感信息 + WxCpUserDetail wxCpUserDetail = null; + WxCpUser wxCpUser = null; try { - cpOauth2UserInfo = oauth2Service.getUserInfo(code); - log.debug("UserTicket:{}",cpOauth2UserInfo.getUserTicket()); + cpOauth2UserInfo = oauth2Service.getUserInfo(agentId,code); + // 基础用户信息 WxCpUserService wxCpUserService = wxCpService.getUserService(); - WxCpUser wxCpUser = wxCpUserService.getById(cpOauth2UserInfo.getUserId()); - String openId = wxCpUser.getOpenUserId(); - wxUser = this.getByOpenId(openId); - if(wxUser == null){ - wxUser = new WxUser(); - wxUser.setAppId(wxApp.getId()); - wxUser.setAppType(wxApp.getAppType()); - wxUser.setNickName(wxCpUser.getName()); - wxUser.setEmpName(wxCpUser.getName()); - wxUser.setUnionId(wxCpUser.getUserId()); - wxUser.setHeadimgUrl(wxCpUser.getAvatar()); - wxUser.setOpenId(wxCpUser.getOpenUserId()); - } - //通过手机号绑定员工号 - if(StringUtils.hasText(wxCpUser.getMobile())){ - List sysUsers = sysUserMapper.selectList(new LambdaQueryWrapper() - .eq(SysUser::getMobile,wxCpUser.getMobile())); - if(sysUsers.size()>0){ - if(sysUsers.size()>1){ - log.error("企业微信登录,一个号码被多人使用:{}",wxCpUser.getMobile()); - } - SysUser sysUser = sysUsers.get(0); - wxUser.setSysUserId(sysUser.getId()); - wxUser.setSysUserCode(sysUser.getCode()); - wxUser.setEmpName(sysUser.getName()); - wxUser.setPhone(sysUser.getMobile()); - }else { - Assert.throwEx("CMS未收录该手机号["+wxCpUser.getMobile()+"]"); - } - } - if(wxUser.getId()==null){ - save(wxUser); - }else { - updateById(wxUser); - } + wxCpUser = wxCpUserService.getById(cpOauth2UserInfo.getUserId()); + // 获取敏感信息 + wxCpUserDetail = oauth2Service.getUserDetail(cpOauth2UserInfo.getUserTicket()); } catch (WxErrorException e) { log.error("企业微信登录失败:{}",e.getMessage()); } + if(wxCpUserDetail==null||wxCpUser==null){ + Assert.throwEx("企业微信登录失败"); + } + String userId = wxCpUserDetail.getUserId(); + wxUser = this.getByOpenId(appId,userId); + if(wxUser == null){ + wxUser = new WxUser(); + wxUser.setAppId(wxApp.getId()); + wxUser.setAppType(wxApp.getAppType()); + wxUser.setNickName(wxCpUser.getName()); + wxUser.setEmpName(wxCpUser.getName()); + wxUser.setUnionId(userId); + wxUser.setOpenId(userId); + wxUser.setHeadimgUrl(wxCpUserDetail.getAvatar()); + } + //通过手机号绑定员工号 + //if(StringUtils.hasText(wxCpUser.getMobile())){ + //List sysUsers = sysUserMapper.selectList(new LambdaQueryWrapper() + // .eq(SysUser::getMobile,wxCpUser.getMobile())); + List sysUsers = sysUserMapper.selectList(new LambdaQueryWrapper().eq(SysUser::getName,userId)); + if(sysUsers.size()>0){ + if(sysUsers.size()>1){ + //log.error("企业微信登录,一个号码被多人使用:{}",wxCpUser.getMobile()); + log.error("企业微信登录,员工号出现重复:{}",userId); + } + SysUser sysUser = sysUsers.get(0); + wxUser.setSysUserId(sysUser.getId()); + wxUser.setSysUserCode(sysUser.getCode()); + wxUser.setEmpName(sysUser.getName()); + wxUser.setPhone(sysUser.getMobile()); + }else { + //Assert.throwEx("CMS未收录该手机号["+wxCpUser.getMobile()+"]"); + Assert.throwEx("CMS未收录该员工号["+userId+"]"); + } + if(wxUser.getId()==null){ + save(wxUser); + }else { + updateById(wxUser); + } }else if(wxApp.getAppType().equals(WxStatusConst.WxApp_AppType_1)){ Assert.throwEx(HttpCode.DEV_ERR); }else if(wxApp.getAppType().equals(WxStatusConst.WxApp_AppType_2)){ @@ -223,7 +246,7 @@ public class WxUserServiceImpl extends ServiceImpl impleme log.debug("auth2AccessToken:{}",auth2AccessToken.getAccessToken()); WxOAuth2UserInfo auth2UserInfo = auth2Service.getUserInfo(auth2AccessToken, GySysConst.LANG_ZH_CN); WxMpUser wxMpUser = wxMpService.getUserService().userInfo(auth2UserInfo.getOpenid(), GySysConst.LANG_ZH_CN); - wxUser = this.getByOpenId(auth2UserInfo.getOpenid()); + wxUser = this.getByOpenId(appId,auth2UserInfo.getOpenid()); if(wxUser == null){ wxUser = new WxUser(); wxUser.setAppId(wxApp.getId()); @@ -265,5 +288,13 @@ public class WxUserServiceImpl extends ServiceImpl impleme wxUserLambdaQueryWrapper.eq(WxUser::getOpenId,openId); return getOne(wxUserLambdaQueryWrapper,false); } + + @Override + public WxUser getByOpenId(String appId, String openId) { + LambdaQueryWrapper wxUserLambdaQueryWrapper = new LambdaQueryWrapper<>(); + wxUserLambdaQueryWrapper.eq(WxUser::getOpenId,openId); + wxUserLambdaQueryWrapper.eq(WxUser::getAppId,appId); + return getOne(wxUserLambdaQueryWrapper,false); + } } diff --git a/src/main/resources/mapper/goods/GoodsSpuMapper.xml b/src/main/resources/mapper/goods/GoodsSpuMapper.xml index ebfaf198..d0ddb224 100644 --- a/src/main/resources/mapper/goods/GoodsSpuMapper.xml +++ b/src/main/resources/mapper/goods/GoodsSpuMapper.xml @@ -258,7 +258,10 @@ - order by `goods_spu`.`update_time` + + order by ${query.orderProp} ${query.orderType} + +