|
|
@ -9,17 +9,23 @@ import com.qs.serve.common.model.enums.SystemModule; |
|
|
|
import com.qs.serve.common.util.PageUtil; |
|
|
|
import com.qs.serve.common.util.CopierUtil; |
|
|
|
import com.qs.serve.common.util.StringUtils; |
|
|
|
import com.qs.serve.modules.wx.entity.*; |
|
|
|
import com.qs.serve.modules.wx.entity.dto.sms.WxSmsNewForm; |
|
|
|
import com.qs.serve.modules.wx.entity.vo.WxPushResultVo; |
|
|
|
import com.qs.serve.modules.wx.service.*; |
|
|
|
import lombok.AllArgsConstructor; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import me.chanjar.weixin.mp.api.WxMpService; |
|
|
|
import org.springframework.security.access.prepost.PreAuthorize; |
|
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
|
|
|
|
import com.qs.serve.modules.wx.entity.bo.WxFormPushBo; |
|
|
|
import com.qs.serve.modules.wx.entity.WxFormPush; |
|
|
|
import com.qs.serve.modules.wx.service.WxFormPushService; |
|
|
|
|
|
|
|
import javax.validation.Valid; |
|
|
|
import java.time.LocalDateTime; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.List; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
/** |
|
|
|
* 微信 表单推送 |
|
|
@ -33,6 +39,12 @@ import java.util.List; |
|
|
|
public class WxFormPushController { |
|
|
|
|
|
|
|
private WxFormPushService wxFormPushService; |
|
|
|
private WxFormPushUserService wxFormPushUserService; |
|
|
|
private WxFormPushTypeService wxFormPushTypeService; |
|
|
|
private WxUserService wxUserService; |
|
|
|
private WxPushService wxPushService; |
|
|
|
private WxAppService wxAppService; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 列表 |
|
|
@ -40,7 +52,7 @@ public class WxFormPushController { |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
//@GetMapping("/list")
|
|
|
|
@PreAuthorize("hasRole('wx:formPush:query')") |
|
|
|
// @PreAuthorize("hasRole('wx:formPush:query')")
|
|
|
|
public R<List<WxFormPush>> getList(WxFormPush param){ |
|
|
|
LambdaQueryWrapper<WxFormPush> lqw = new LambdaQueryWrapper<>(param); |
|
|
|
PageUtil.startPage(); |
|
|
@ -70,6 +82,12 @@ public class WxFormPushController { |
|
|
|
@SysLog(module = SystemModule.Verification, title = "表单推送", biz = BizType.QUERY) |
|
|
|
public R<WxFormPush> getById(@PathVariable("id") String id){ |
|
|
|
WxFormPush wxFormPush = wxFormPushService.getById(id); |
|
|
|
|
|
|
|
LambdaQueryWrapper<WxFormPushUser> userlqw = new LambdaQueryWrapper<>(); |
|
|
|
userlqw.eq(WxFormPushUser::getFormPushId,wxFormPush.getId()); |
|
|
|
List<WxFormPushUser> list = wxFormPushUserService.list(userlqw); |
|
|
|
wxFormPush.setWxFormPushUserList(list); |
|
|
|
|
|
|
|
return R.ok(wxFormPush); |
|
|
|
} |
|
|
|
|
|
|
@ -80,15 +98,77 @@ public class WxFormPushController { |
|
|
|
* @param param |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@PostMapping("/updateById") |
|
|
|
// @PostMapping("/updateById")
|
|
|
|
@SysLog(module = SystemModule.Verification, title = "表单推送", biz = BizType.UPDATE) |
|
|
|
@PreAuthorize("hasRole('wx:formPush:update')") |
|
|
|
// @PreAuthorize("hasRole('wx:formPush:update')")
|
|
|
|
public R<?> updateById(@RequestBody @Valid WxFormPushBo param){ |
|
|
|
WxFormPush entity = CopierUtil.copy(param,new WxFormPush()); |
|
|
|
boolean result = wxFormPushService.updateById(entity); |
|
|
|
return R.isTrue(result); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 发布 |
|
|
|
* @param param |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@PostMapping("/publishById") |
|
|
|
@SysLog(module = SystemModule.Verification, title = "表单推送发布", biz = BizType.UPDATE) |
|
|
|
// @PreAuthorize("hasRole('wx:formPush:update')")
|
|
|
|
public R<?> publishById(@RequestBody WxFormPushBo param){ |
|
|
|
String id = param.getId(); |
|
|
|
WxFormPush entity = wxFormPushService.getById(id); |
|
|
|
if(entity.getId().equals("1")){ |
|
|
|
return R.error("已发布的消息不能再次发布"); |
|
|
|
} |
|
|
|
entity.setStatus("1"); |
|
|
|
boolean result = wxFormPushService.updateById(entity); |
|
|
|
|
|
|
|
LambdaQueryWrapper<WxFormPushUser> userlqw = new LambdaQueryWrapper<>(); |
|
|
|
userlqw.eq(WxFormPushUser::getFormPushId,entity.getId()); |
|
|
|
List<WxFormPushUser> list = wxFormPushUserService.list(userlqw); |
|
|
|
|
|
|
|
List<String> userCodes = list.stream().map(a->a.getUserCode()).collect(Collectors.toList()); |
|
|
|
WxApp app = wxAppService.getOne(new LambdaQueryWrapper<>(),false); |
|
|
|
LambdaQueryWrapper<WxUser> lqw = new LambdaQueryWrapper<>(); |
|
|
|
lqw.eq(WxUser::getAppId,app.getId()); |
|
|
|
lqw.in(WxUser::getSysUserCode,userCodes); |
|
|
|
List<WxUser> wxUserList = wxUserService.list(lqw); |
|
|
|
for (WxUser wxUser : wxUserList) { |
|
|
|
if (wxUser.getOpenId().equals("0")) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
WxSmsNewForm wxSmsNewForm = new WxSmsNewForm(); |
|
|
|
wxSmsNewForm.setTitle(entity.getTitle()); |
|
|
|
wxSmsNewForm.setUserName(wxUser.getEmpName()); |
|
|
|
wxSmsNewForm.setBizType(entity.getBusinessType() == null ? "通知" : entity.getBusinessType()); |
|
|
|
wxSmsNewForm.setBitTime(LocalDateTime.now().toString().replace("T", " ")); |
|
|
|
wxSmsNewForm.setRemark(entity.getRemark()); |
|
|
|
wxPushService.sendWxMsg(wxUser, "表单通知", wxSmsNewForm, true, entity.getId()); |
|
|
|
|
|
|
|
} |
|
|
|
return R.isTrue(result); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 撤消 |
|
|
|
* @param param |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@PostMapping("/unPublishById") |
|
|
|
@SysLog(module = SystemModule.Verification, title = "撤消表单推送", biz = BizType.UPDATE) |
|
|
|
// @PreAuthorize("hasRole('wx:formPush:update')")
|
|
|
|
public R<?> unPublishById(@RequestBody WxFormPushBo param){ |
|
|
|
String id = param.getId(); |
|
|
|
WxFormPush entity = wxFormPushService.getById(id); |
|
|
|
entity.setStatus("0"); |
|
|
|
boolean result = wxFormPushService.updateById(entity); |
|
|
|
LambdaQueryWrapper<WxFormPushUser> dellqw = new LambdaQueryWrapper<>(); |
|
|
|
dellqw.eq(WxFormPushUser::getFormPushId,entity.getId()); |
|
|
|
wxFormPushUserService.remove(dellqw); |
|
|
|
return R.isTrue(result); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 新增 |
|
|
|
* @param param |
|
|
@ -96,10 +176,73 @@ public class WxFormPushController { |
|
|
|
*/ |
|
|
|
@PostMapping("/save") |
|
|
|
@SysLog(module = SystemModule.Verification, title = "表单推送", biz = BizType.INSERT) |
|
|
|
@PreAuthorize("hasRole('wx:formPush:insert')") |
|
|
|
// @PreAuthorize("hasRole('wx:formPush:insert')")
|
|
|
|
public R<?> save(@RequestBody @Valid WxFormPushBo param){ |
|
|
|
WxFormPush entity = CopierUtil.copy(param,new WxFormPush()); |
|
|
|
boolean result = wxFormPushService.save(entity); |
|
|
|
WxFormPushType pushType = null; |
|
|
|
if(param.getTypeId()!=null){ |
|
|
|
pushType = wxFormPushTypeService.getById(param.getTypeId()); |
|
|
|
entity.setTypeCode(pushType.getCode()); |
|
|
|
entity.setTypeName(pushType.getTitle()); |
|
|
|
}else{ |
|
|
|
return R.error("分类不存在"); |
|
|
|
} |
|
|
|
|
|
|
|
boolean result; |
|
|
|
if(null==entity.getId()) { |
|
|
|
result = wxFormPushService.save(entity); |
|
|
|
}else{ |
|
|
|
WxFormPush ori_entity = wxFormPushService.getById(entity.getId()); |
|
|
|
if(ori_entity.getStatus().equals("1")){ |
|
|
|
return R.error("已发布的消息不能更新"); |
|
|
|
} |
|
|
|
result = wxFormPushService.updateById(entity); |
|
|
|
} |
|
|
|
//保存推送人员
|
|
|
|
|
|
|
|
List<String> userIds = param.getUserIds().stream().distinct().collect(Collectors.toList()); |
|
|
|
LambdaQueryWrapper<WxUser> lqw = new LambdaQueryWrapper<>(); |
|
|
|
WxApp app = wxAppService.getOne(new LambdaQueryWrapper<>(),false); |
|
|
|
lqw.eq(WxUser::getAppId,app.getId()); |
|
|
|
lqw.in(WxUser::getSysUserId,userIds); |
|
|
|
List<WxUser> wxUserList = wxUserService.list(lqw); |
|
|
|
List<WxFormPushUser> pushUserList = new ArrayList<>(); |
|
|
|
for (WxUser wxUser : wxUserList) { |
|
|
|
if(wxUser.getOpenId().equals("0")){ |
|
|
|
continue; |
|
|
|
} |
|
|
|
WxSmsNewForm wxSmsNewForm = new WxSmsNewForm(); |
|
|
|
wxSmsNewForm.setTitle(param.getTitle()); |
|
|
|
wxSmsNewForm.setUserName(wxUser.getEmpName()); |
|
|
|
wxSmsNewForm.setBizType(param.getBusinessType()==null?"通知":param.getBusinessType()); |
|
|
|
wxSmsNewForm.setBitTime(LocalDateTime.now().toString().replace("T"," ")); |
|
|
|
wxSmsNewForm.setRemark(param.getRemark()); |
|
|
|
if(param.getStatus().equals("1")) { |
|
|
|
wxPushService.sendWxMsg(wxUser, "表单通知", wxSmsNewForm, true, entity.getId()); |
|
|
|
} |
|
|
|
WxFormPushUser pushUser = new WxFormPushUser(); |
|
|
|
pushUser.setFormPushId(entity.getId()); |
|
|
|
pushUser.setFormTitle(entity.getTitle()); |
|
|
|
pushUser.setUserId(wxUser.getSysUserId()); |
|
|
|
pushUser.setUserCode(wxUser.getSysUserCode()); |
|
|
|
pushUser.setUserName(wxUser.getEmpName()); |
|
|
|
if(pushType!=null){ |
|
|
|
pushUser.setTypeId(pushType.getId()); |
|
|
|
pushUser.setTypeCode(pushType.getCode()); |
|
|
|
pushUser.setTypeName(pushType.getTitle()); |
|
|
|
} |
|
|
|
pushUserList.add(pushUser); |
|
|
|
} |
|
|
|
pushUserList = pushUserList.stream().distinct().collect(Collectors.toList()); |
|
|
|
if(null==entity.getId()) { |
|
|
|
wxFormPushUserService.saveBatch(pushUserList); |
|
|
|
}else{ |
|
|
|
LambdaQueryWrapper<WxFormPushUser> dellqw = new LambdaQueryWrapper<>(); |
|
|
|
dellqw.eq(WxFormPushUser::getFormPushId,entity.getId()); |
|
|
|
wxFormPushUserService.remove(dellqw); |
|
|
|
wxFormPushUserService.saveBatch(pushUserList); |
|
|
|
} |
|
|
|
|
|
|
|
return R.isTrue(result); |
|
|
|
} |
|
|
|
|
|
|
|