yshop3.0-RC2版本
This commit is contained in:
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>yshop</artifactId>
|
||||
<groupId>co.yixiang</groupId>
|
||||
<version>3.0-alpha</version>
|
||||
<version>3.0-RC2</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@ -20,7 +20,7 @@
|
||||
<dependency>
|
||||
<groupId>co.yixiang</groupId>
|
||||
<artifactId>yshop-weixin</artifactId>
|
||||
<version>3.0-alpha</version>
|
||||
<version>3.0-RC2</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
@ -5,6 +5,9 @@
|
||||
*/
|
||||
package co.yixiang.modules.activity.rest;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import co.yixiang.api.YshopException;
|
||||
import co.yixiang.enums.CouponEnum;
|
||||
import co.yixiang.logging.aop.log.Log;
|
||||
import co.yixiang.modules.activity.domain.YxStoreCoupon;
|
||||
import co.yixiang.modules.activity.service.YxStoreCouponService;
|
||||
@ -55,6 +58,13 @@ public class StoreCouponController {
|
||||
@PostMapping(value = "/yxStoreCoupon")
|
||||
@PreAuthorize("@el.check('admin','YXSTORECOUPON_ALL','YXSTORECOUPON_CREATE')")
|
||||
public ResponseEntity create(@Validated @RequestBody YxStoreCoupon resources){
|
||||
if(CouponEnum.TYPE_1.getValue().equals(resources.getType())
|
||||
&& StrUtil.isEmpty(resources.getProductId())){
|
||||
throw new YshopException("请选择商品");
|
||||
}
|
||||
if(resources.getCouponPrice().compareTo(resources.getUseMinPrice()) >= 0) {
|
||||
throw new YshopException("优惠券金额不能高于最低消费金额");
|
||||
}
|
||||
return new ResponseEntity<>(yxStoreCouponService.save(resources),HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
@ -63,6 +73,13 @@ public class StoreCouponController {
|
||||
@PutMapping(value = "/yxStoreCoupon")
|
||||
@PreAuthorize("@el.check('admin','YXSTORECOUPON_ALL','YXSTORECOUPON_EDIT')")
|
||||
public ResponseEntity update(@Validated @RequestBody YxStoreCoupon resources){
|
||||
if(CouponEnum.TYPE_1.getValue().equals(resources.getType())
|
||||
&& StrUtil.isEmpty(resources.getProductId())){
|
||||
throw new YshopException("请选择商品");
|
||||
}
|
||||
if(resources.getCouponPrice().compareTo(resources.getUseMinPrice()) >= 0) {
|
||||
throw new YshopException("优惠券金额不能高于最低消费金额");
|
||||
}
|
||||
yxStoreCouponService.saveOrUpdate(resources);
|
||||
return new ResponseEntity(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
@ -9,6 +9,8 @@
|
||||
package co.yixiang.modules.aop;
|
||||
|
||||
|
||||
import co.yixiang.api.BusinessException;
|
||||
import co.yixiang.api.YshopException;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
@ -37,7 +39,7 @@ public class ForbidSubmitAspect {
|
||||
public Object around(ProceedingJoinPoint pjp, ForbidSubmit forbidSubmit) throws Throwable {
|
||||
|
||||
//用于拦截演示环境一些禁止操作
|
||||
//throw new BusinessException("演示环境禁止操作");
|
||||
//throw new YshopException("演示环境禁止操作");
|
||||
return pjp.proceed();
|
||||
|
||||
|
||||
|
@ -18,6 +18,8 @@ import co.yixiang.modules.category.domain.YxStoreCategory;
|
||||
import co.yixiang.modules.category.service.YxStoreCategoryService;
|
||||
import co.yixiang.modules.category.service.dto.YxStoreCategoryDto;
|
||||
import co.yixiang.modules.category.service.dto.YxStoreCategoryQueryCriteria;
|
||||
import co.yixiang.modules.product.domain.YxStoreProduct;
|
||||
import co.yixiang.modules.product.service.YxStoreProductService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
@ -43,10 +45,13 @@ public class StoreCategoryController {
|
||||
|
||||
|
||||
private final YxStoreCategoryService yxStoreCategoryService;
|
||||
private final YxStoreProductService yxStoreProductService;
|
||||
|
||||
|
||||
public StoreCategoryController(YxStoreCategoryService yxStoreCategoryService) {
|
||||
public StoreCategoryController(YxStoreCategoryService yxStoreCategoryService,
|
||||
YxStoreProductService yxStoreProductService) {
|
||||
this.yxStoreCategoryService = yxStoreCategoryService;
|
||||
this.yxStoreProductService = yxStoreProductService;
|
||||
}
|
||||
|
||||
@Log("导出数据")
|
||||
@ -116,8 +121,27 @@ public class StoreCategoryController {
|
||||
public ResponseEntity delete(@PathVariable String id){
|
||||
String[] ids = id.split(",");
|
||||
for (String newId: ids) {
|
||||
this.delCheck(Integer.valueOf(newId));
|
||||
yxStoreCategoryService.removeById(Integer.valueOf(newId));
|
||||
}
|
||||
return new ResponseEntity(HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 检测删除分类
|
||||
* @param id 分类id
|
||||
*/
|
||||
private void delCheck(Integer id){
|
||||
int count = yxStoreCategoryService.lambdaQuery()
|
||||
.eq(YxStoreCategory::getPid,id)
|
||||
.count();
|
||||
if(count > 0) throw new YshopException("请先删除子分类");
|
||||
|
||||
int countP = yxStoreProductService.lambdaQuery()
|
||||
.eq(YxStoreProduct::getCateId,id)
|
||||
.count();
|
||||
|
||||
if(countP > 0) throw new YshopException("当前分类下有商品不可删除");
|
||||
}
|
||||
}
|
||||
|
@ -155,7 +155,7 @@ public class StoreOrderController {
|
||||
@PostMapping(value = "/yxStoreOrder/refund")
|
||||
@PreAuthorize("@el.check('admin','YXSTOREORDER_ALL','YXSTOREORDER_EDIT')")
|
||||
public ResponseEntity refund(@Validated @RequestBody YxStoreOrder resources) {
|
||||
yxStoreOrderService.orderRefund(resources.getOrderId(),resources.getPayPrice().doubleValue(),
|
||||
yxStoreOrderService.orderRefund(resources.getOrderId(),resources.getPayPrice(),
|
||||
ShopCommonEnum.AGREE_1.getValue());
|
||||
return new ResponseEntity(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
@ -8,17 +8,33 @@
|
||||
*/
|
||||
package co.yixiang.modules.product.rest;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import co.yixiang.constant.ShopConstants;
|
||||
import co.yixiang.enums.ShopCommonEnum;
|
||||
import co.yixiang.enums.SpecTypeEnum;
|
||||
import co.yixiang.logging.aop.log.Log;
|
||||
import co.yixiang.modules.aop.ForbidSubmit;
|
||||
import co.yixiang.modules.category.domain.YxStoreCategory;
|
||||
import co.yixiang.modules.category.service.YxStoreCategoryService;
|
||||
import co.yixiang.modules.product.domain.YxStoreProduct;
|
||||
import co.yixiang.modules.product.domain.YxStoreProductAttrResult;
|
||||
import co.yixiang.modules.product.service.YxStoreProductAttrResultService;
|
||||
import co.yixiang.modules.product.service.YxStoreProductReplyService;
|
||||
import co.yixiang.modules.product.service.YxStoreProductRuleService;
|
||||
import co.yixiang.modules.product.service.YxStoreProductService;
|
||||
import co.yixiang.modules.product.service.dto.ProductDto;
|
||||
import co.yixiang.modules.product.service.dto.ProductFormatDto;
|
||||
import co.yixiang.modules.product.service.dto.StoreProductDto;
|
||||
import co.yixiang.modules.product.service.dto.YxStoreProductQueryCriteria;
|
||||
import co.yixiang.modules.template.domain.YxShippingTemplates;
|
||||
import co.yixiang.modules.template.service.YxShippingTemplatesService;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.http.HttpStatus;
|
||||
@ -27,6 +43,8 @@ import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author hupeng
|
||||
* @date 2019-10-04
|
||||
@ -36,10 +54,24 @@ import org.springframework.web.bind.annotation.*;
|
||||
@RequestMapping("api")
|
||||
public class StoreProductController {
|
||||
|
||||
private final YxStoreProductService yxStoreProductService;
|
||||
private static List<Map<String,Object>> cateList = new ArrayList<>();
|
||||
|
||||
public StoreProductController(YxStoreProductService yxStoreProductService) {
|
||||
private final YxStoreProductService yxStoreProductService;
|
||||
private final YxStoreCategoryService yxStoreCategoryService;
|
||||
private final YxShippingTemplatesService yxShippingTemplatesService;
|
||||
private final YxStoreProductRuleService yxStoreProductRuleService;
|
||||
private final YxStoreProductAttrResultService yxStoreProductAttrResultService;
|
||||
|
||||
public StoreProductController(YxStoreProductService yxStoreProductService,
|
||||
YxStoreCategoryService yxStoreCategoryService,
|
||||
YxShippingTemplatesService yxShippingTemplatesService,
|
||||
YxStoreProductRuleService yxStoreProductRuleService,
|
||||
YxStoreProductAttrResultService yxStoreProductAttrResultService) {
|
||||
this.yxStoreProductService = yxStoreProductService;
|
||||
this.yxStoreCategoryService = yxStoreCategoryService;
|
||||
this.yxShippingTemplatesService = yxShippingTemplatesService;
|
||||
this.yxStoreProductRuleService = yxStoreProductRuleService;
|
||||
this.yxStoreProductAttrResultService = yxStoreProductAttrResultService;
|
||||
}
|
||||
|
||||
@Log("查询商品")
|
||||
@ -51,25 +83,16 @@ public class StoreProductController {
|
||||
}
|
||||
|
||||
@ForbidSubmit
|
||||
@Log("新增商品")
|
||||
@ApiOperation(value = "新增商品")
|
||||
@Log("新增/修改商品")
|
||||
@ApiOperation(value = "新增/修改商品")
|
||||
@CacheEvict(cacheNames = ShopConstants.YSHOP_REDIS_INDEX_KEY,allEntries = true)
|
||||
@PostMapping(value = "/yxStoreProduct")
|
||||
@PostMapping(value = "/yxStoreProduct/addOrSave")
|
||||
@PreAuthorize("@el.check('admin','YXSTOREPRODUCT_ALL','YXSTOREPRODUCT_CREATE')")
|
||||
public ResponseEntity create(@Validated @RequestBody YxStoreProduct resources){
|
||||
return new ResponseEntity<>(yxStoreProductService.saveProduct(resources),HttpStatus.CREATED);
|
||||
public ResponseEntity create(@Validated @RequestBody StoreProductDto storeProductDto){
|
||||
yxStoreProductService.insertAndEditYxStoreProduct(storeProductDto);
|
||||
return new ResponseEntity<>(HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
@ForbidSubmit
|
||||
@Log("修改商品")
|
||||
@ApiOperation(value = "修改商品")
|
||||
@CacheEvict(cacheNames = ShopConstants.YSHOP_REDIS_INDEX_KEY,allEntries = true)
|
||||
@PutMapping(value = "/yxStoreProduct")
|
||||
@PreAuthorize("@el.check('admin','YXSTOREPRODUCT_ALL','YXSTOREPRODUCT_EDIT')")
|
||||
public ResponseEntity update(@Validated @RequestBody YxStoreProduct resources){
|
||||
yxStoreProductService.updateProduct(resources);
|
||||
return new ResponseEntity(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
||||
@ForbidSubmit
|
||||
@Log("删除商品")
|
||||
@ -82,15 +105,7 @@ public class StoreProductController {
|
||||
return new ResponseEntity(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "恢复数据")
|
||||
@Deprecated
|
||||
@CacheEvict(cacheNames = ShopConstants.YSHOP_REDIS_INDEX_KEY,allEntries = true)
|
||||
@DeleteMapping(value = "/yxStoreProduct/recovery/{id}")
|
||||
@PreAuthorize("@el.check('admin','YXSTOREPRODUCT_ALL','YXSTOREPRODUCT_DELETE')")
|
||||
public ResponseEntity recovery(@PathVariable Integer id){
|
||||
// yxStoreProductService.recovery(id);
|
||||
return new ResponseEntity(HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation(value = "商品上架/下架")
|
||||
@CacheEvict(cacheNames = ShopConstants.YSHOP_REDIS_INDEX_KEY,allEntries = true)
|
||||
@ -105,37 +120,117 @@ public class StoreProductController {
|
||||
@ApiOperation(value = "生成属性")
|
||||
@PostMapping(value = "/yxStoreProduct/isFormatAttr/{id}")
|
||||
public ResponseEntity isFormatAttr(@PathVariable Long id,@RequestBody String jsonStr){
|
||||
return new ResponseEntity<>(yxStoreProductService.isFormatAttr(id,jsonStr),HttpStatus.OK);
|
||||
return new ResponseEntity<>(yxStoreProductService.getFormatAttr(id,jsonStr),HttpStatus.OK);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "设置保存属性")
|
||||
@CacheEvict(cacheNames = ShopConstants.YSHOP_REDIS_INDEX_KEY,allEntries = true)
|
||||
@PostMapping(value = "/yxStoreProduct/setAttr/{id}")
|
||||
public ResponseEntity setAttr(@PathVariable Long id,@RequestBody String jsonStr){
|
||||
yxStoreProductService.createProductAttr(id,jsonStr);
|
||||
return new ResponseEntity(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "清除属性")
|
||||
@CacheEvict(cacheNames = ShopConstants.YSHOP_REDIS_INDEX_KEY,allEntries = true)
|
||||
@PostMapping(value = "/yxStoreProduct/clearAttr/{id}")
|
||||
public ResponseEntity clearAttr(@PathVariable Long id){
|
||||
yxStoreProductService.clearProductAttr(id,true);
|
||||
return new ResponseEntity(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "获取属性")
|
||||
@GetMapping(value = "/yxStoreProduct/attr/{id}")
|
||||
public ResponseEntity attr(@PathVariable Long id){
|
||||
String str = yxStoreProductService.getStoreProductAttrResult(id);
|
||||
if(StrUtil.isEmpty(str)){
|
||||
return new ResponseEntity(HttpStatus.OK);
|
||||
@ApiOperation(value = "获取商品信息")
|
||||
@GetMapping(value = "/yxStoreProduct/info/{id}")
|
||||
public ResponseEntity info(@PathVariable Long id){
|
||||
Map<String,Object> map = new LinkedHashMap<>(3);
|
||||
|
||||
//运费模板
|
||||
List<YxShippingTemplates> shippingTemplatesList = yxShippingTemplatesService.list();
|
||||
map.put("tempList", shippingTemplatesList);
|
||||
|
||||
//商品分类
|
||||
List<YxStoreCategory> storeCategories = yxStoreCategoryService.lambdaQuery()
|
||||
.eq(YxStoreCategory::getIsShow, ShopCommonEnum.SHOW_1.getValue())
|
||||
.list();
|
||||
map.put("cateList", this.makeCate(storeCategories,0,1));
|
||||
|
||||
//商品规格
|
||||
map.put("ruleList",yxStoreProductRuleService.list());
|
||||
|
||||
|
||||
if(id == 0){
|
||||
return new ResponseEntity<>(map,HttpStatus.OK);
|
||||
}
|
||||
JSONObject jsonObject = JSON.parseObject(str);
|
||||
|
||||
return new ResponseEntity<>(jsonObject,HttpStatus.OK);
|
||||
//处理商品详情
|
||||
YxStoreProduct yxStoreProduct = yxStoreProductService.getById(id);
|
||||
ProductDto productDto = new ProductDto();
|
||||
BeanUtil.copyProperties(yxStoreProduct,productDto,"sliderImage");
|
||||
productDto.setSliderImage(Arrays.asList(yxStoreProduct.getSliderImage().split(",")));
|
||||
YxStoreProductAttrResult storeProductAttrResult = yxStoreProductAttrResultService
|
||||
.getOne(Wrappers.<YxStoreProductAttrResult>lambdaQuery()
|
||||
.eq(YxStoreProductAttrResult::getProductId,id).last("limit 1"));
|
||||
JSONObject result = JSON.parseObject(storeProductAttrResult.getResult());
|
||||
|
||||
if(SpecTypeEnum.TYPE_1.getValue().equals(yxStoreProduct.getSpecType())){
|
||||
productDto.setAttr(new ProductFormatDto());
|
||||
productDto.setAttrs(result.getObject("value",ArrayList.class));
|
||||
productDto.setItems(result.getObject("attr",ArrayList.class));
|
||||
}else{
|
||||
Map<String,Object> mapAttr = (Map<String,Object>)result.getObject("value",ArrayList.class).get(0);
|
||||
ProductFormatDto productFormatDto = ProductFormatDto.builder()
|
||||
.pic(mapAttr.get("pic").toString())
|
||||
.price(Double.valueOf(mapAttr.get("price").toString()))
|
||||
.cost(Double.valueOf(mapAttr.get("cost").toString()))
|
||||
.otPrice(Double.valueOf(mapAttr.get("ot_price").toString()))
|
||||
.stock(Integer.valueOf(mapAttr.get("stock").toString()))
|
||||
.barCode(mapAttr.get("bar_code").toString())
|
||||
.weight(Double.valueOf(mapAttr.get("weight").toString()))
|
||||
.volume(Double.valueOf(mapAttr.get("volume").toString()))
|
||||
.brokerage(Double.valueOf(mapAttr.get("brokerage").toString()))
|
||||
.brokerageTwo(Double.valueOf(mapAttr.get("brokerage_two").toString()))
|
||||
.build();
|
||||
productDto.setAttr(productFormatDto);
|
||||
}
|
||||
|
||||
|
||||
map.put("productInfo",productDto);
|
||||
|
||||
return new ResponseEntity<>(map,HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 分类递归
|
||||
* @param data 分类列表
|
||||
* @param pid 附件id
|
||||
* @param level d等级
|
||||
* @return list
|
||||
*/
|
||||
private List<Map<String,Object>> makeCate(List<YxStoreCategory> data, int pid, int level)
|
||||
{
|
||||
String html = "|-----";
|
||||
String newHtml = "";
|
||||
|
||||
|
||||
if(cateList.size() == data.size()){
|
||||
return cateList;
|
||||
}
|
||||
|
||||
for (int i = 0; i < data.size(); i++) {
|
||||
YxStoreCategory storeCategory = data.get(i);
|
||||
int catePid = storeCategory.getPid();
|
||||
Map<String,Object> map = new HashMap<>();
|
||||
if(catePid == pid){
|
||||
newHtml = String.join("", Collections.nCopies(level,html));
|
||||
map.put("value",storeCategory.getId());
|
||||
map.put("label",newHtml + storeCategory.getCateName());
|
||||
if(storeCategory.getPid() == 0){
|
||||
map.put("disabled",0);
|
||||
}else{
|
||||
map.put("disabled",1);
|
||||
}
|
||||
cateList.add(map);
|
||||
data.remove(i);
|
||||
|
||||
i--;
|
||||
this.makeCate(data,storeCategory.getId(),level + 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return cateList;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -8,6 +8,7 @@
|
||||
*/
|
||||
package co.yixiang.modules.product.rest;
|
||||
|
||||
import co.yixiang.enums.ShopCommonEnum;
|
||||
import co.yixiang.logging.aop.log.Log;
|
||||
import co.yixiang.modules.aop.ForbidSubmit;
|
||||
import co.yixiang.modules.product.domain.YxStoreProductReply;
|
||||
@ -28,6 +29,8 @@ import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author hupeng
|
||||
* @date 2019-11-03
|
||||
@ -59,7 +62,9 @@ public class StoreProductReplyController {
|
||||
@PutMapping(value = "/yxStoreProductReply")
|
||||
@PreAuthorize("@el.check('admin','YXSTOREPRODUCTREPLY_ALL','YXSTOREPRODUCTREPLY_EDIT')")
|
||||
public ResponseEntity update(@Validated @RequestBody YxStoreProductReply resources){
|
||||
yxStoreProductReplyService.save(resources);
|
||||
resources.setMerchantReplyTime(new Date());
|
||||
resources.setIsReply(ShopCommonEnum.REPLY_1.getValue());
|
||||
yxStoreProductReplyService.updateById(resources);
|
||||
return new ResponseEntity(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
||||
|
@ -7,8 +7,10 @@
|
||||
* 一经发现盗用、分享等行为,将追究法律责任,后果自负
|
||||
*/
|
||||
package co.yixiang.modules.product.rest;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import co.yixiang.dozer.service.IGenerator;
|
||||
import co.yixiang.modules.aop.ForbidSubmit;
|
||||
import co.yixiang.modules.product.domain.YxStoreProductRule;
|
||||
import co.yixiang.modules.product.service.YxStoreProductRuleService;
|
||||
import co.yixiang.modules.product.service.dto.YxStoreProductRuleDto;
|
||||
@ -56,31 +58,30 @@ public class StoreProductRuleController {
|
||||
return new ResponseEntity<>(yxStoreProductRuleService.queryAll(criteria,pageable),HttpStatus.OK);
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
@Log("新增sku规则")
|
||||
@ApiOperation("新增sku规则")
|
||||
|
||||
@PostMapping("/save/{id}")
|
||||
@Log("新增/修改sku规则")
|
||||
@ApiOperation("新增/修改sku规则")
|
||||
@PreAuthorize("@el.check('admin','yxStoreProductRule:add')")
|
||||
public ResponseEntity<Object> create(@Validated @RequestBody YxStoreProductRule resources){
|
||||
return new ResponseEntity<>(yxStoreProductRuleService.save(resources),HttpStatus.CREATED);
|
||||
public ResponseEntity<Object> create(@Validated @RequestBody YxStoreProductRule resources,@PathVariable Integer id){
|
||||
if(id != null && id > 0){
|
||||
resources.setId(id);
|
||||
yxStoreProductRuleService.updateById(resources);
|
||||
}else{
|
||||
yxStoreProductRuleService.save(resources);
|
||||
}
|
||||
|
||||
return new ResponseEntity<>(HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
@PutMapping
|
||||
@Log("修改sku规则")
|
||||
@ApiOperation("修改sku规则")
|
||||
@PreAuthorize("@el.check('admin','yxStoreProductRule:edit')")
|
||||
public ResponseEntity<Object> update(@Validated @RequestBody YxStoreProductRule resources){
|
||||
yxStoreProductRuleService.updateById(resources);
|
||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
||||
@ForbidSubmit
|
||||
@Log("删除sku规则")
|
||||
@ApiOperation("删除sku规则")
|
||||
@PreAuthorize("@el.check('admin','yxStoreProductRule:del')")
|
||||
@DeleteMapping
|
||||
public ResponseEntity<Object> deleteAll(@RequestBody Integer[] ids) {
|
||||
Arrays.asList(ids).forEach(id->{
|
||||
yxStoreProductRuleService.removeById(id);
|
||||
});
|
||||
yxStoreProductRuleService.removeByIds(new ArrayList<>(Arrays.asList(ids)));
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,148 @@
|
||||
package co.yixiang.modules.services;
|
||||
|
||||
import cn.hutool.core.util.ReUtil;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import co.yixiang.exception.ErrorRequestException;
|
||||
import co.yixiang.modules.wechat.service.dto.YxArticleDto;
|
||||
import co.yixiang.mp.config.WxMpConfiguration;
|
||||
import co.yixiang.mp.utils.URLUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import me.chanjar.weixin.common.api.WxConsts;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.mp.api.WxMpService;
|
||||
import me.chanjar.weixin.mp.bean.WxMpMassTagMessage;
|
||||
import me.chanjar.weixin.mp.bean.material.WxMediaImgUploadResult;
|
||||
import me.chanjar.weixin.mp.bean.material.WxMpMaterial;
|
||||
import me.chanjar.weixin.mp.bean.material.WxMpMaterialNews;
|
||||
import me.chanjar.weixin.mp.bean.material.WxMpMaterialUploadResult;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpMassSendResult;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @ClassName WechatArticleService
|
||||
* @Author hupeng <610796224@qq.com>
|
||||
* @Date 2020/7/2
|
||||
**/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class WechatArticleService {
|
||||
|
||||
@Value("${file.path}")
|
||||
private String uploadDirStr;
|
||||
|
||||
/**
|
||||
* 发布微信图文
|
||||
* @param wxNewsArticleItem YxArticleDto
|
||||
* @throws WxErrorException
|
||||
*/
|
||||
public void publish(YxArticleDto wxNewsArticleItem) throws WxErrorException {
|
||||
WxMpService wxMpService = WxMpConfiguration.getWxMpService();
|
||||
|
||||
WxMpMaterialNews wxMpMaterialNews = new WxMpMaterialNews();
|
||||
|
||||
|
||||
WxMpMaterialNews.WxMpMaterialNewsArticle article = new WxMpMaterialNews.WxMpMaterialNewsArticle();
|
||||
|
||||
WxMpMaterialUploadResult wxMpMaterialUploadResult = uploadPhotoToWx( wxMpService,
|
||||
wxNewsArticleItem.getImageInput() );
|
||||
wxNewsArticleItem.setThumbMediaId( wxMpMaterialUploadResult.getMediaId() );
|
||||
|
||||
article.setAuthor( wxNewsArticleItem.getAuthor() );
|
||||
|
||||
|
||||
//处理content
|
||||
String content = processContent(wxMpService, wxNewsArticleItem.getContent());
|
||||
System.out.println(content);
|
||||
article.setContent( content );
|
||||
article.setContentSourceUrl( wxNewsArticleItem.getUrl() );
|
||||
article.setDigest( wxNewsArticleItem.getSynopsis() );
|
||||
article.setShowCoverPic( true );
|
||||
article.setThumbMediaId( wxNewsArticleItem.getThumbMediaId() );
|
||||
article.setTitle( wxNewsArticleItem.getTitle() );
|
||||
//TODO 暂时注释掉,测试号没有留言权限
|
||||
//article.setNeedOpenComment( wxNewsArticleItem );
|
||||
//article.setOnlyFansCanComment( wxNewsArticleItem );
|
||||
wxMpMaterialNews.addArticle( article );
|
||||
|
||||
log.info( "wxMpMaterialNews : {}", JSONUtil.toJsonStr( wxMpMaterialNews ) );
|
||||
|
||||
WxMpMaterialUploadResult wxMpMaterialUploadResult1 = wxMpService.getMaterialService()
|
||||
.materialNewsUpload( wxMpMaterialNews );
|
||||
|
||||
//推送开始
|
||||
WxMpMassTagMessage massMessage = new WxMpMassTagMessage();
|
||||
massMessage.setMsgType(WxConsts.MassMsgType.MPNEWS);
|
||||
massMessage.setMediaId(wxMpMaterialUploadResult1.getMediaId());
|
||||
massMessage.setSendAll(true);
|
||||
|
||||
WxMpMassSendResult massResult = wxMpService.getMassMessageService()
|
||||
.massGroupMessageSend(massMessage);
|
||||
if(!massResult.getErrorCode().equals("0")) {
|
||||
log.info("error:"+massResult.getErrorMsg());
|
||||
throw new ErrorRequestException("发送失败");
|
||||
}
|
||||
|
||||
log.info( "massResult : {}", JSONUtil.toJsonStr( massResult ) );
|
||||
|
||||
log.info( "wxMpMaterialUploadResult : {}", JSONUtil.toJsonStr( wxMpMaterialUploadResult1 ) );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 上传素材
|
||||
* @param wxMpService WxMpService
|
||||
* @param picPath 图片路径
|
||||
* @return WxMpMaterialUploadResult
|
||||
* @throws WxErrorException
|
||||
*/
|
||||
private WxMpMaterialUploadResult uploadPhotoToWx(WxMpService wxMpService, String picPath) throws WxErrorException {
|
||||
WxMpMaterial wxMpMaterial = new WxMpMaterial();
|
||||
|
||||
String filename = String.valueOf( (int)System.currentTimeMillis() ) + ".png";
|
||||
String downloadPath = uploadDirStr + filename;
|
||||
long size = HttpUtil.downloadFile(picPath, cn.hutool.core.io.FileUtil.file(downloadPath));
|
||||
picPath = downloadPath;
|
||||
File picFile = new File( picPath );
|
||||
wxMpMaterial.setFile( picFile );
|
||||
wxMpMaterial.setName( picFile.getName() );
|
||||
log.info( "picFile name : {}", picFile.getName() );
|
||||
WxMpMaterialUploadResult wxMpMaterialUploadResult = wxMpService.getMaterialService().materialFileUpload( WxConsts.MediaFileType.IMAGE, wxMpMaterial );
|
||||
log.info( "wxMpMaterialUploadResult : {}", JSONUtil.toJsonStr( wxMpMaterialUploadResult ) );
|
||||
return wxMpMaterialUploadResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理内容
|
||||
* @param wxMpService WxMpService
|
||||
* @param content 内容
|
||||
* @return String
|
||||
* @throws WxErrorException
|
||||
*/
|
||||
private String processContent(WxMpService wxMpService,String content) throws WxErrorException {
|
||||
if(StringUtils.isBlank( content )){
|
||||
return content;
|
||||
}
|
||||
String imgReg = "<img[^>]+src\\s*=\\s*['\"]([^'\"]+)['\"][^>]*>";
|
||||
List<String> imgList = ReUtil.findAllGroup1( imgReg,content);
|
||||
for (int j = 0; j < imgList.size(); j++) {
|
||||
String imgSrc = imgList.get( j );
|
||||
String filepath = URLUtils.getParam( imgSrc,"filepath" );
|
||||
|
||||
if(StringUtils.isBlank( filepath )){//网络图片URL,需下载到本地
|
||||
String filename = System.currentTimeMillis() + ".png";
|
||||
String downloadPath = uploadDirStr + filename;
|
||||
long size = HttpUtil.downloadFile(imgSrc, cn.hutool.core.io.FileUtil.file(downloadPath));
|
||||
filepath = downloadPath;
|
||||
}
|
||||
WxMediaImgUploadResult wxMediaImgUploadResult = wxMpService.getMaterialService().mediaImgUpload( new File(filepath) );
|
||||
content = StringUtils.replace( content,imgList.get( j ),wxMediaImgUploadResult.getUrl());
|
||||
}
|
||||
return content;
|
||||
}
|
||||
}
|
@ -10,6 +10,7 @@ package co.yixiang.modules.shop.rest;
|
||||
|
||||
|
||||
import co.yixiang.logging.aop.log.Log;
|
||||
import co.yixiang.modules.aop.ForbidSubmit;
|
||||
import co.yixiang.modules.shop.domain.YxMaterial;
|
||||
import co.yixiang.modules.shop.service.YxMaterialService;
|
||||
import co.yixiang.modules.shop.service.dto.YxMaterialQueryCriteria;
|
||||
@ -69,6 +70,7 @@ public class MaterialController {
|
||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
||||
@ForbidSubmit
|
||||
@Log("删除素材管理")
|
||||
@ApiOperation("删除素材管理")
|
||||
@DeleteMapping(value = "/{id}")
|
||||
|
@ -9,6 +9,7 @@
|
||||
package co.yixiang.modules.shop.rest;
|
||||
|
||||
import co.yixiang.logging.aop.log.Log;
|
||||
import co.yixiang.modules.aop.ForbidSubmit;
|
||||
import co.yixiang.modules.shop.domain.YxMaterialGroup;
|
||||
import co.yixiang.modules.shop.service.YxMaterialGroupService;
|
||||
import co.yixiang.modules.shop.service.dto.YxMaterialGroupQueryCriteria;
|
||||
@ -58,6 +59,7 @@ public class MaterialGroupController {
|
||||
return new ResponseEntity<>(yxMaterialGroupService.save(resources),HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
@ForbidSubmit
|
||||
@PutMapping
|
||||
@Log("修改素材分组")
|
||||
@ApiOperation("修改素材分组")
|
||||
@ -66,6 +68,7 @@ public class MaterialGroupController {
|
||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
||||
@ForbidSubmit
|
||||
@Log("删除素材分组")
|
||||
@ApiOperation("删除素材分组")
|
||||
@DeleteMapping(value = "/{id}")
|
||||
|
@ -0,0 +1,114 @@
|
||||
/**
|
||||
* Copyright (C) 2018-2020
|
||||
* All rights reserved, Designed By www.yixiang.co
|
||||
* 注意:
|
||||
* 本软件为www.yixiang.co开发研制,未经购买不得使用
|
||||
* 购买后可获得全部源代码(禁止转卖、分享、上传到码云、github等开源平台)
|
||||
* 一经发现盗用、分享等行为,将追究法律责任,后果自负
|
||||
*/
|
||||
package co.yixiang.modules.template.rest;
|
||||
import java.util.Arrays;
|
||||
|
||||
import co.yixiang.constant.ShopConstants;
|
||||
import co.yixiang.dozer.service.IGenerator;
|
||||
import co.yixiang.modules.aop.ForbidSubmit;
|
||||
import co.yixiang.modules.template.domain.YxShippingTemplates;
|
||||
import co.yixiang.modules.template.domain.YxSystemCity;
|
||||
import co.yixiang.modules.template.service.YxShippingTemplatesService;
|
||||
import co.yixiang.modules.template.service.YxSystemCityService;
|
||||
import co.yixiang.modules.template.service.dto.ShippingTemplatesDto;
|
||||
import co.yixiang.modules.template.service.dto.YxShippingTemplatesDto;
|
||||
import co.yixiang.modules.template.service.dto.YxShippingTemplatesQueryCriteria;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import lombok.AllArgsConstructor;
|
||||
import co.yixiang.logging.aop.log.Log;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import io.swagger.annotations.*;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* @author hupeng
|
||||
* @date 2020-06-29
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@Api(tags = "运费模板管理")
|
||||
@RestController
|
||||
@RequestMapping("/api/yxShippingTemplates")
|
||||
public class ShippingTemplatesController {
|
||||
|
||||
private final YxShippingTemplatesService yxShippingTemplatesService;
|
||||
private final YxSystemCityService yxSystemCityService;
|
||||
private final IGenerator generator;
|
||||
|
||||
|
||||
@Log("导出数据")
|
||||
@ApiOperation("导出数据")
|
||||
@GetMapping(value = "/download")
|
||||
@PreAuthorize("@el.check('admin','yxShippingTemplates:list')")
|
||||
public void download(HttpServletResponse response, YxShippingTemplatesQueryCriteria criteria) throws IOException {
|
||||
yxShippingTemplatesService.download(generator.convert(yxShippingTemplatesService.queryAll(criteria), YxShippingTemplatesDto.class), response);
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
@Log("查询运费模板")
|
||||
@ApiOperation("查询运费模板")
|
||||
@PreAuthorize("@el.check('admin','yxShippingTemplates:list')")
|
||||
public ResponseEntity<Object> getYxShippingTemplatess(YxShippingTemplatesQueryCriteria criteria, Pageable pageable){
|
||||
return new ResponseEntity<>(yxShippingTemplatesService.queryAll(criteria,pageable),HttpStatus.OK);
|
||||
}
|
||||
|
||||
@ForbidSubmit
|
||||
@PostMapping("/save/{id}")
|
||||
@Log("新增/保存运费模板")
|
||||
@ApiOperation("新增/保存运费模板")
|
||||
@PreAuthorize("@el.check('admin','yxShippingTemplates:add')")
|
||||
public ResponseEntity<Object> create(@PathVariable Integer id,
|
||||
@Validated @RequestBody ShippingTemplatesDto shippingTemplatesDto){
|
||||
yxShippingTemplatesService.addAndUpdate(id,shippingTemplatesDto);
|
||||
return new ResponseEntity<>(HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
|
||||
@ForbidSubmit
|
||||
@Log("删除运费模板")
|
||||
@ApiOperation("删除运费模板")
|
||||
@PreAuthorize("@el.check('admin','yxShippingTemplates:del')")
|
||||
@DeleteMapping
|
||||
public ResponseEntity<Object> deleteAll(@RequestBody Integer[] ids) {
|
||||
Arrays.asList(ids).forEach(id->{
|
||||
yxShippingTemplatesService.removeById(id);
|
||||
});
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取城市列表
|
||||
*/
|
||||
@Cacheable(cacheNames = ShopConstants.YSHOP_REDIS_SYS_CITY_KEY)
|
||||
@GetMapping("/citys")
|
||||
public ResponseEntity<Object> cityList()
|
||||
{
|
||||
List<YxSystemCity> cityList = yxSystemCityService.list(Wrappers.<YxSystemCity>lambdaQuery()
|
||||
.eq(YxSystemCity::getParentId,0));
|
||||
|
||||
for (YxSystemCity systemCity : cityList){
|
||||
List<YxSystemCity> children = yxSystemCityService.list(Wrappers
|
||||
.<YxSystemCity>lambdaQuery()
|
||||
.eq(YxSystemCity::getParentId,systemCity.getCityId()));
|
||||
|
||||
systemCity.setChildren(children);
|
||||
}
|
||||
|
||||
return new ResponseEntity<>(cityList,HttpStatus.OK);
|
||||
}
|
||||
|
||||
}
|
@ -40,6 +40,15 @@ public class MemberController {
|
||||
this.yxUserService = yxUserService;
|
||||
}
|
||||
|
||||
@Log("查看下级")
|
||||
@ApiOperation(value = "查看下级")
|
||||
@PostMapping(value = "/yxUser/spread")
|
||||
@PreAuthorize("@el.check('admin','YXUSER_ALL','YXUSER_EDIT')")
|
||||
public ResponseEntity getSpread(@RequestBody YxUserQueryCriteria criteria){
|
||||
return new ResponseEntity<>(yxUserService.querySpread(criteria.getUid(),criteria.getGrade()),
|
||||
HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Log("查询用户")
|
||||
@ApiOperation(value = "查询用户")
|
||||
@GetMapping(value = "/yxUser")
|
||||
|
@ -7,6 +7,7 @@ package co.yixiang.modules.wechat.rest;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import co.yixiang.modules.aop.ForbidSubmit;
|
||||
import co.yixiang.modules.services.WechatArticleService;
|
||||
import co.yixiang.modules.wechat.domain.YxArticle;
|
||||
import co.yixiang.modules.wechat.service.YxArticleService;
|
||||
import co.yixiang.modules.wechat.service.dto.YxArticleDto;
|
||||
@ -40,9 +41,18 @@ import java.util.Date;
|
||||
public class WechatArticleController {
|
||||
|
||||
private final YxArticleService yxArticleService;
|
||||
private final WechatArticleService wechatArticleService;
|
||||
|
||||
public WechatArticleController(YxArticleService yxArticleService) {
|
||||
public WechatArticleController(YxArticleService yxArticleService,WechatArticleService wechatArticleService) {
|
||||
this.yxArticleService = yxArticleService;
|
||||
this.wechatArticleService = wechatArticleService;
|
||||
}
|
||||
|
||||
@ApiOperation(value = "查询单条信息")
|
||||
@GetMapping(value = "/yxArticle/info/{id}")
|
||||
@PreAuthorize("@el.check('admin','YXARTICLE_ALL','YXARTICLE_GET')")
|
||||
public ResponseEntity getInfo(@PathVariable Integer id){
|
||||
return new ResponseEntity<>(yxArticleService.getById(id),HttpStatus.OK);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "查询")
|
||||
@ -86,7 +96,7 @@ public class WechatArticleController {
|
||||
YxArticleDto yxArticleDTO= new YxArticleDto();
|
||||
YxArticle yxArticle = yxArticleService.getById(id);
|
||||
BeanUtils.copyProperties(yxArticle,yxArticleDTO);
|
||||
yxArticleService.uploadNews(yxArticleDTO);
|
||||
wechatArticleService.publish(yxArticleDTO);
|
||||
return new ResponseEntity(HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@ package co.yixiang.modules.wechat.rest;
|
||||
|
||||
import co.yixiang.dozer.service.IGenerator;
|
||||
|
||||
import co.yixiang.modules.aop.ForbidSubmit;
|
||||
import co.yixiang.modules.wechat.domain.YxWechatTemplate;
|
||||
import co.yixiang.modules.wechat.service.YxWechatTemplateService;
|
||||
import co.yixiang.modules.wechat.service.dto.YxWechatTemplateDto;
|
||||
@ -19,13 +20,7 @@ import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
@ -60,6 +55,7 @@ public class WechatTemplateController {
|
||||
return new ResponseEntity<>(yxWechatTemplateService.queryAll(criteria,pageable),HttpStatus.OK);
|
||||
}
|
||||
|
||||
@ForbidSubmit
|
||||
@PostMapping
|
||||
@ApiOperation("新增微信模板消息")
|
||||
@PreAuthorize("@el.check('admin','yxWechatTemplate:add')")
|
||||
@ -67,6 +63,7 @@ public class WechatTemplateController {
|
||||
return new ResponseEntity<>(yxWechatTemplateService.save(resources),HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
@ForbidSubmit
|
||||
@PutMapping
|
||||
@ApiOperation("修改微信模板消息")
|
||||
@PreAuthorize("@el.check('admin','yxWechatTemplate:edit')")
|
||||
@ -75,13 +72,12 @@ public class WechatTemplateController {
|
||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
||||
@ForbidSubmit
|
||||
@ApiOperation("删除微信模板消息")
|
||||
@PreAuthorize("@el.check('admin','yxWechatTemplate:del')")
|
||||
@DeleteMapping
|
||||
public ResponseEntity<Object> deleteAll(@RequestBody Integer[] ids) {
|
||||
Arrays.asList(ids).forEach(id->{
|
||||
yxWechatTemplateService.removeById(id);
|
||||
});
|
||||
@DeleteMapping("/{id}")
|
||||
public ResponseEntity<Object> deleteAll(@PathVariable Integer id) {
|
||||
yxWechatTemplateService.removeById(id);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user