| | |
| | | import com.fzzy.igds.constant.RespCodeEnum; |
| | | import com.fzzy.igds.data.IgdsBaseParam; |
| | | import com.fzzy.igds.data.PageResponse; |
| | | import com.fzzy.igds.domain.PledgeContract; |
| | | import com.fzzy.igds.domain.PledgeContractDepot; |
| | | import com.fzzy.igds.domain.SnapReply; |
| | | import com.fzzy.igds.service.PledgeContractDepotService; |
| | | import com.fzzy.igds.service.PledgeContractService; |
| | | import com.fzzy.igds.service.SnapReplyService; |
| | | import com.google.code.kaptcha.Constants; |
| | | import com.ruoyi.common.core.domain.entity.SysUser; |
| | | import com.ruoyi.common.utils.ShiroUtils; |
| | | import com.ruoyi.system.service.ISysUserService; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Component |
| | | public class WeChatManager { |
| | | |
| | | @Autowired |
| | | @Resource |
| | | private WeChatUtil weChatUtil; |
| | | @Autowired |
| | | private ISysUserService sysUserService; |
| | | @Resource |
| | | private SnapReplyService snapReplyService; |
| | | |
| | | @Resource |
| | | private PledgeContractService pledgeContractService; |
| | | |
| | | @Resource |
| | | private PledgeContractDepotService pledgeContractDepotService; |
| | | |
| | | |
| | | public String getOpenid(String code) { |
| | |
| | | return new PageResponse(RespCodeEnum.CODE_0000.getCode(), "查询成功", user); |
| | | } |
| | | |
| | | //校验验证码 |
| | | public boolean validateResponse(HttpServletRequest request, String validateCode) { |
| | | // ① 从Session获取生成的验证码 |
| | | Object obj = ShiroUtils.getSession().getAttribute(Constants.KAPTCHA_SESSION_KEY); |
| | | String code = String.valueOf(obj != null ? obj : ""); |
| | | |
| | | // ② 立即清除Session中的验证码(防止重复使用) |
| | | request.getSession().removeAttribute(Constants.KAPTCHA_SESSION_KEY); |
| | | |
| | | // ③ 比对用户输入和正确答案(忽略大小写) |
| | | if (StringUtils.isEmpty(validateCode) || !validateCode.equalsIgnoreCase(code)) { |
| | | return false; |
| | | |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | //绑定openId |
| | | public PageResponse<String> bandOpenId(WeChatBaseParam param) { |
| | | public PageResponse<String> bandOpenId(HttpServletRequest httpRequest,WeChatBaseParam param) { |
| | | |
| | | //判断参数 |
| | | if (null == param || StringUtils.isEmpty(param.getOpenid())) { |
| | |
| | | return new PageResponse<String>(RespCodeEnum.CODE_1007.getCode(), "手机号为空,请填写"); |
| | | |
| | | } |
| | | // if (StringUtils.isEmpty(param.getMsgCode())) { |
| | | // return new PageResponse<String>(RespCodeEnum.CODE_1007.getCode(), "验证码不能为空"); |
| | | // |
| | | // } |
| | | // |
| | | // String code = (String) redisService.getCacheObject(WeChatConst.WX_MOBILE_CODE + param.getMobile()); |
| | | // if(StringUtils.isEmpty(code)){ |
| | | // res.put("code","1007"); |
| | | // res.put("msg","验证码已失效,请重新获取"); |
| | | // return res; |
| | | // } |
| | | // if(! code.equals(param.getMsgCode())){ |
| | | // res.put("code","1007"); |
| | | // res.put("msg","验证码错误"); |
| | | // return res; |
| | | // } |
| | | if (StringUtils.isEmpty(param.getMsgCode())) { |
| | | return new PageResponse<String>(RespCodeEnum.CODE_1007.getCode(), "验证码不能为空"); |
| | | |
| | | } |
| | | //验证码验证 |
| | | boolean validateResponse = validateResponse(httpRequest, param.getMsgCode()); |
| | | if (!validateResponse) { |
| | | return new PageResponse<String>(RespCodeEnum.CODE_1007.getCode(), "验证码错误"); |
| | | } |
| | | |
| | | //根据手机号查看用户是否是系统用户 |
| | | SysUser user = sysUserService.selectUserByPhoneNumber(param.getMobile()); |
| | |
| | | |
| | | // redisService.deleteObject(WeChatConst.WX_MOBILE_CODE + param.getMobile()); |
| | | |
| | | return new PageResponse<String>(RespCodeEnum.CODE_0000.getCode(), "请求成功"); |
| | | return new PageResponse<String>(RespCodeEnum.CODE_0000.getCode(), "绑定成功"); |
| | | |
| | | } |
| | | |
| | | |
| | | //解绑openId |
| | | public PageResponse<String> unBandOpenId(WeChatBaseParam param) { |
| | | public PageResponse<String> unBandOpenId(HttpServletRequest httpRequest,WeChatBaseParam param) { |
| | | |
| | | //判断参数 |
| | | if (null == param || StringUtils.isEmpty(param.getOpenid())) { |
| | |
| | | return new PageResponse<String>(RespCodeEnum.CODE_1007.getCode(), "验证码不能为空"); |
| | | |
| | | } |
| | | |
| | | // String code = (String) redisService.getCacheObject(WeChatConst.WX_MOBILE_CODE + param.getMobile()); |
| | | // if(StringUtils.isEmpty(code)){ |
| | | // res.put("code","1007"); |
| | | // res.put("msg","验证码已失效,请重新获取"); |
| | | // return res; |
| | | // |
| | | // } |
| | | // if(! code.equals(param.getMsgCode())){ |
| | | // res.put("code","1007"); |
| | | // res.put("msg","验证码错误"); |
| | | // return res; |
| | | // } |
| | | |
| | | //验证码验证 |
| | | boolean validateResponse = validateResponse(httpRequest, param.getMsgCode()); |
| | | if (!validateResponse) { |
| | | return new PageResponse<String>(RespCodeEnum.CODE_1007.getCode(), "验证码错误"); |
| | | } |
| | | //根据手机号查询用户是否已经绑定 |
| | | SysUser user = sysUserService.selectUserByPhoneNumber(param.getMobile()); |
| | | if (user == null || StringUtils.isEmpty(user.getPhonenumber())) { |
| | |
| | | |
| | | user.setOpenId(""); |
| | | sysUserService.updateUserInfo(user); |
| | | |
| | | // redisService.deleteObject(WeChatConst.WX_MOBILE_CODE + param.getMobile()); |
| | | |
| | | return new PageResponse<String>(RespCodeEnum.CODE_0000.getCode(), "请求成功"); |
| | | |
| | |
| | | return new PageResponse<Page<SnapReply>>(RespCodeEnum.CODE_1006.getCode(), "尚未绑定服务,请先绑定!"); |
| | | |
| | | } |
| | | //获取业务经理绑定的质押合同 |
| | | List<PledgeContract> dateByUser = pledgeContractService.getDateByUser(String.valueOf(user.getUserId())); |
| | | if (dateByUser == null || dateByUser.isEmpty()) { |
| | | //返回空数据 |
| | | return new PageResponse<Page<SnapReply>>(RespCodeEnum.CODE_0000.getCode(), "请求成功", new Page<>(param.getPageNo(), param.getPageSize())); |
| | | } |
| | | List<PledgeContractDepot> pledgeContractDepots = new ArrayList<>() ; |
| | | for (PledgeContract pledgeContract : dateByUser) { |
| | | String id = pledgeContract.getId(); |
| | | IgdsBaseParam depotPParam = new IgdsBaseParam(); |
| | | depotPParam.setParentId(id); |
| | | List<PledgeContractDepot> pledgeContractDepots1 = pledgeContractDepotService.listAll(depotPParam); |
| | | pledgeContractDepots.addAll(pledgeContractDepots1); |
| | | } |
| | | if(pledgeContractDepots.isEmpty()){ |
| | | //返回空数据 |
| | | return new PageResponse<Page<SnapReply>>(RespCodeEnum.CODE_0000.getCode(), "请求成功", new Page<>(param.getPageNo(), param.getPageSize())); |
| | | } |
| | | |
| | | // 获取pledgeContractDepots中去重后的库区IDList |
| | | List<String> deptIdList = pledgeContractDepots.stream().map(PledgeContractDepot::getPledgeDept).distinct().collect(Collectors.toList()); |
| | | |
| | | //分页拼接 |
| | | Page<SnapReply> page = new Page<>(param.getPageNo(), param.getPageSize()); |
| | | //查询参数组装 |
| | | IgdsBaseParam queryParam = new IgdsBaseParam(); |
| | | queryParam.setDeptId(String.valueOf(user.getDeptId())); |
| | | queryParam.setCompanyId(user.getCompanyId()); |
| | | queryParam.setKey(Constant.YN_N); |
| | | snapReplyService.listPage(page, queryParam); |
| | | snapReplyService.listPageByListDept(page, queryParam,deptIdList); |
| | | return new PageResponse<Page<SnapReply>>(RespCodeEnum.CODE_0000.getCode(), "请求成功", page); |
| | | } |
| | | |