1.4.4版本,新增模板消息通知、H5端商家管理发货修改及其列表时间显示修复

This commit is contained in:
hupeng
2019-12-13 19:23:56 +08:00
parent 2d89095296
commit a060e73e39
41 changed files with 1490 additions and 50 deletions

View File

@ -0,0 +1,61 @@
package co.yixiang.mp.controller;
import cn.hutool.core.util.StrUtil;
import co.yixiang.exception.BadRequestException;
import co.yixiang.mp.domain.YxWechatTemplate;
import co.yixiang.mp.service.YxWechatTemplateService;
import co.yixiang.mp.service.dto.YxWechatTemplateQueryCriteria;
import org.springframework.beans.factory.annotation.Autowired;
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.*;
/**
* @author xuwenbo
* @date 2019-12-10
*/
@Api(tags = "YxWechatTemplate管理")
@RestController
@RequestMapping("api")
public class YxWechatTemplateController {
@Autowired
private YxWechatTemplateService yxWechatTemplateService;
@ApiOperation(value = "查询YxWechatTemplate")
@GetMapping(value = "/yxWechatTemplate")
@PreAuthorize("hasAnyRole('ADMIN','YXWECHATTEMPLATE_ALL','YXWECHATTEMPLATE_SELECT')")
public ResponseEntity getYxWechatTemplates(YxWechatTemplateQueryCriteria criteria, Pageable pageable){
return new ResponseEntity(yxWechatTemplateService.queryAll(criteria,pageable),HttpStatus.OK);
}
@ApiOperation(value = "新增YxWechatTemplate")
@PostMapping(value = "/yxWechatTemplate")
@PreAuthorize("hasAnyRole('ADMIN','YXWECHATTEMPLATE_ALL','YXWECHATTEMPLATE_CREATE')")
public ResponseEntity create(@Validated @RequestBody YxWechatTemplate resources){
//if(StrUtil.isNotEmpty("22")) throw new BadRequestException("演示环境禁止操作");
return new ResponseEntity(yxWechatTemplateService.create(resources),HttpStatus.CREATED);
}
@ApiOperation(value = "修改YxWechatTemplate")
@PutMapping(value = "/yxWechatTemplate")
@PreAuthorize("hasAnyRole('ADMIN','YXWECHATTEMPLATE_ALL','YXWECHATTEMPLATE_EDIT')")
public ResponseEntity update(@Validated @RequestBody YxWechatTemplate resources){
//if(StrUtil.isNotEmpty("22")) throw new BadRequestException("演示环境禁止操作");
yxWechatTemplateService.update(resources);
return new ResponseEntity(HttpStatus.NO_CONTENT);
}
@ApiOperation(value = "删除YxWechatTemplate")
@DeleteMapping(value = "/yxWechatTemplate/{id}")
@PreAuthorize("hasAnyRole('ADMIN','YXWECHATTEMPLATE_ALL','YXWECHATTEMPLATE_DELETE')")
public ResponseEntity delete(@PathVariable Integer id){
//if(StrUtil.isNotEmpty("22")) throw new BadRequestException("演示环境禁止操作");
yxWechatTemplateService.delete(id);
return new ResponseEntity(HttpStatus.OK);
}
}

View File

@ -0,0 +1,51 @@
package co.yixiang.mp.domain;
import lombok.Data;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import javax.persistence.*;
import java.io.Serializable;
/**
* @author xuwenbo
* @date 2019-12-10
*/
@Entity
@Data
@Table(name="yx_wechat_template")
public class YxWechatTemplate implements Serializable {
// 模板id
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Integer id;
// 模板编号
@Column(name = "tempkey",nullable = false)
private String tempkey;
// 模板名
@Column(name = "name",nullable = false)
private String name;
// 回复内容
@Column(name = "content",nullable = false)
private String content;
// 模板ID
@Column(name = "tempid")
private String tempid;
// 添加时间
@Column(name = "add_time",nullable = false)
private String addTime;
// 状态
@Column(name = "status",nullable = false)
private Integer status;
public void copy(YxWechatTemplate source){
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
}
}

View File

@ -0,0 +1,13 @@
package co.yixiang.mp.repository;
import co.yixiang.mp.domain.YxWechatTemplate;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
/**
* @author xuwenbo
* @date 2019-12-10
*/
public interface YxWechatTemplateRepository extends JpaRepository<YxWechatTemplate, Integer>, JpaSpecificationExecutor {
YxWechatTemplate findByTempkey(String key);
}

View File

@ -0,0 +1,8 @@
package co.yixiang.mp.service;
import java.util.Map;
public interface WxMpTemplateMessageService {
String sendWxMpTemplateMessage(String openId, String templateId, String url, Map<String, String> map);
}

View File

@ -0,0 +1,68 @@
package co.yixiang.mp.service;
import co.yixiang.mp.domain.YxWechatTemplate;
import co.yixiang.mp.service.dto.YxWechatTemplateDTO;
import co.yixiang.mp.service.dto.YxWechatTemplateQueryCriteria;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Pageable;
import java.util.Map;
import java.util.List;
/**
* @author xuwenbo
* @date 2019-12-10
*/
//@CacheConfig(cacheNames = "yxWechatTemplate")
public interface YxWechatTemplateService {
YxWechatTemplate findByTempkey(String key);
/**
* 查询数据分页
* @param criteria
* @param pageable
* @return
*/
//@Cacheable
Map<String,Object> queryAll(YxWechatTemplateQueryCriteria criteria, Pageable pageable);
/**
* 查询所有数据不分页
* @param criteria
* @return
*/
//@Cacheable
List<YxWechatTemplateDTO> queryAll(YxWechatTemplateQueryCriteria criteria);
/**
* 根据ID查询
* @param id
* @return
*/
//@Cacheable(key = "#p0")
YxWechatTemplateDTO findById(Integer id);
/**
* 创建
* @param resources
* @return
*/
//@CacheEvict(allEntries = true)
YxWechatTemplateDTO create(YxWechatTemplate resources);
/**
* 编辑
* @param resources
*/
//@CacheEvict(allEntries = true)
void update(YxWechatTemplate resources);
/**
* 删除
* @param id
*/
//@CacheEvict(allEntries = true)
void delete(Integer id);
}

View File

@ -0,0 +1,34 @@
package co.yixiang.mp.service.dto;
import lombok.Data;
import java.io.Serializable;
/**
* @author xuwenbo
* @date 2019-12-10
*/
@Data
public class YxWechatTemplateDTO implements Serializable {
// 模板id
private Integer id;
// 模板编号
private String tempkey;
// 模板名
private String name;
// 回复内容
private String content;
// 模板ID
private String tempid;
// 添加时间
private String addTime;
// 状态
private Integer status;
}

View File

@ -0,0 +1,12 @@
package co.yixiang.mp.service.dto;
import lombok.Data;
import co.yixiang.annotation.Query;
/**
* @author xuwenbo
* @date 2019-12-10
*/
@Data
public class YxWechatTemplateQueryCriteria{
}

View File

@ -0,0 +1,35 @@
package co.yixiang.mp.service.impl;
import co.yixiang.mp.service.WxMpTemplateMessageService;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.template.WxMpTemplateData;
import me.chanjar.weixin.mp.bean.template.WxMpTemplateMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Map;
@Component
public class WxMpTemplateMessageServiceImpl implements WxMpTemplateMessageService {
@Autowired
private WxMpService wxMpService;
@Override
public String sendWxMpTemplateMessage(String openId, String templateId, String url, Map<String,String> map){
WxMpTemplateMessage templateMessage = WxMpTemplateMessage.builder()
.toUser(openId)
.templateId(templateId)
.url(url)
.build();
map.forEach( (k,v)-> { templateMessage.addData(new WxMpTemplateData(k, v, "#000000"));} );
String msgId = null;
try {
msgId = wxMpService.getTemplateMsgService().sendTemplateMsg(templateMessage);
} catch (WxErrorException e) {
e.printStackTrace();
}
return msgId;
}
}

View File

@ -0,0 +1,80 @@
package co.yixiang.mp.service.impl;
import co.yixiang.mp.domain.YxWechatTemplate;
import co.yixiang.utils.ValidationUtil;
import co.yixiang.mp.repository.YxWechatTemplateRepository;
import co.yixiang.mp.service.YxWechatTemplateService;
import co.yixiang.mp.service.dto.YxWechatTemplateDTO;
import co.yixiang.mp.service.dto.YxWechatTemplateQueryCriteria;
import co.yixiang.mp.service.mapper.YxWechatTemplateMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.util.Optional;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import co.yixiang.utils.PageUtil;
import co.yixiang.utils.QueryHelp;
import java.util.List;
import java.util.Map;
/**
* @author xuwenbo
* @date 2019-12-10
*/
@Service
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class YxWechatTemplateServiceImpl implements YxWechatTemplateService {
@Autowired
private YxWechatTemplateRepository yxWechatTemplateRepository;
@Autowired
private YxWechatTemplateMapper yxWechatTemplateMapper;
@Override
public YxWechatTemplate findByTempkey(String key) {
return yxWechatTemplateRepository.findByTempkey(key);
}
@Override
public Map<String,Object> queryAll(YxWechatTemplateQueryCriteria criteria, Pageable pageable){
Page<YxWechatTemplate> page = yxWechatTemplateRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
return PageUtil.toPage(page.map(yxWechatTemplateMapper::toDto));
}
@Override
public List<YxWechatTemplateDTO> queryAll(YxWechatTemplateQueryCriteria criteria){
return yxWechatTemplateMapper.toDto(yxWechatTemplateRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
}
@Override
public YxWechatTemplateDTO findById(Integer id) {
Optional<YxWechatTemplate> yxWechatTemplate = yxWechatTemplateRepository.findById(id);
ValidationUtil.isNull(yxWechatTemplate,"YxWechatTemplate","id",id);
return yxWechatTemplateMapper.toDto(yxWechatTemplate.get());
}
@Override
@Transactional(rollbackFor = Exception.class)
public YxWechatTemplateDTO create(YxWechatTemplate resources) {
return yxWechatTemplateMapper.toDto(yxWechatTemplateRepository.save(resources));
}
@Override
@Transactional(rollbackFor = Exception.class)
public void update(YxWechatTemplate resources) {
Optional<YxWechatTemplate> optionalYxWechatTemplate = yxWechatTemplateRepository.findById(resources.getId());
ValidationUtil.isNull( optionalYxWechatTemplate,"YxWechatTemplate","id",resources.getId());
YxWechatTemplate yxWechatTemplate = optionalYxWechatTemplate.get();
yxWechatTemplate.copy(resources);
yxWechatTemplateRepository.save(yxWechatTemplate);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void delete(Integer id) {
yxWechatTemplateRepository.deleteById(id);
}
}

View File

@ -0,0 +1,16 @@
package co.yixiang.mp.service.mapper;
import co.yixiang.mapper.EntityMapper;
import co.yixiang.mp.domain.YxWechatTemplate;
import co.yixiang.mp.service.dto.YxWechatTemplateDTO;
import org.mapstruct.Mapper;
import org.mapstruct.ReportingPolicy;
/**
* @author xuwenbo
* @date 2019-12-10
*/
@Mapper(componentModel = "spring",uses = {},unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface YxWechatTemplateMapper extends EntityMapper<YxWechatTemplateDTO, YxWechatTemplate> {
}