| | |
| | | throw new PlatTipsException(PlatformCode.ERROR_TIPS,"获取token错误:"+reObj.optString("errmsg")); |
| | | } |
| | | }else{ |
| | | throw new PlatTipsException(PlatformCode.ERROR_TIPS,"获取token错误:"+reObj.optString("errmsg")); |
| | | throw new PlatTipsException(PlatformCode.ERROR_TIPS,"获取token错误(NULL)"); |
| | | } |
| | | }else{ |
| | | sp = verificationToken(sp,appId, appSecret,commonService); |
| | |
| | | throw new PlatTipsException(PlatformCode.ERROR_TIPS,"获取token错误:"+reObj.optString("errmsg")); |
| | | } |
| | | }else{ |
| | | throw new PlatTipsException(PlatformCode.ERROR_TIPS,"获取token错误:"+reObj.optString("errmsg")); |
| | | throw new PlatTipsException(PlatformCode.ERROR_TIPS,"获取token错误(NULL)"); |
| | | } |
| | | }else{ |
| | | sp = verificationToken(sp,appId, appSecret,commonDao); |
New file |
| | |
| | | package com.hx.phip.common.wx.corp; |
| | | |
| | | import com.hx.common.dao.CommonDao; |
| | | import com.hx.common.service.CommonService; |
| | | import com.hx.mp.util.CorpMpUtil; |
| | | import com.hx.mp.util.MPWeixinBaseUtil; |
| | | import com.hx.mybatisTool.SqlSentence; |
| | | import com.hx.phip.dao.mapper.SysParameterMapper; |
| | | import com.hx.phip.model.SysParameter; |
| | | import com.hx.util.HttpMethodUtil; |
| | | import com.hx.util.StringUtils; |
| | | import com.platform.exception.PlatTipsException; |
| | | import com.platform.resultTool.PlatformCode; |
| | | import net.sf.json.JSONObject; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | |
| | | import java.util.Calendar; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | | public class WeiXinMpUtil { |
| | | |
| | | private static Logger logger = LoggerFactory.getLogger(WeiXinMpUtil.class); |
| | | |
| | | /** |
| | | * 获取微信小程序access_token |
| | | * @param commonService |
| | | * @param appId |
| | | * @param appSecret |
| | | * @return |
| | | */ |
| | | public static SysParameter getAccessToken(CommonService commonService, String appId, String appSecret) { |
| | | |
| | | SqlSentence ss = new SqlSentence(); |
| | | Map<String, Object> map = new HashMap<String, Object>(); |
| | | map.put("isDel", SysParameter.NO); |
| | | map.put("paramName",appSecret); |
| | | ss.sqlSentence("select * from pla_sys_parameter where isDel = #{m.isDel} and paramName = #{m.paramName}",map); |
| | | SysParameter sp = commonService.selectOne(SysParameterMapper.class,ss); |
| | | |
| | | int needGetAgain = 1; |
| | | if(sp != null) { |
| | | //需要判断一下是否过期 |
| | | Calendar ca = Calendar.getInstance(); |
| | | long curTime = ca.getTimeInMillis(); |
| | | ca.setTime(sp.getCreateTime()); |
| | | ca.add(Calendar.SECOND, Integer.parseInt(sp.getParamValue1())); |
| | | if(curTime < ca.getTimeInMillis()) { |
| | | needGetAgain = 0; |
| | | } |
| | | } |
| | | |
| | | if(needGetAgain == 1) { |
| | | //需要重新获取 |
| | | JSONObject reObj = null; |
| | | try { |
| | | reObj = MPWeixinBaseUtil.getAccessToken(appId, appSecret); |
| | | }catch (Exception e) { |
| | | throw new PlatTipsException(PlatformCode.ERROR_TIPS,"获取token错误01:"+e.getMessage()); |
| | | } |
| | | if(reObj != null) { |
| | | if(!StringUtils.isEmpty(reObj.optString("access_token"))){ |
| | | if(sp == null) { |
| | | sp = new SysParameter(); |
| | | } |
| | | sp.setCreateTime(new Date()); |
| | | sp.setParamName(appSecret); |
| | | sp.setParamValue(reObj.optString("access_token")); |
| | | sp.setParamValue1(reObj.optInt("expires_in",7100) + ""); |
| | | |
| | | if(StringUtils.isEmpty(sp.getId())) { |
| | | commonService.insert(SysParameterMapper.class,sp); |
| | | }else{ |
| | | commonService.updateAll(SysParameterMapper.class,sp); |
| | | } |
| | | }else{ |
| | | throw new PlatTipsException(PlatformCode.ERROR_TIPS,"获取token错误02:"+reObj.optString("errmsg")); |
| | | } |
| | | }else{ |
| | | throw new PlatTipsException(PlatformCode.ERROR_TIPS,"获取token错误(NULL)"); |
| | | } |
| | | }else{ |
| | | sp = verificationToken(sp,appId, appSecret,commonService); |
| | | } |
| | | return sp; |
| | | } |
| | | |
| | | /** |
| | | * 获取微信小程序access_token |
| | | * @param commonDao |
| | | * @param appId |
| | | * @param appSecret |
| | | * @return |
| | | */ |
| | | public static SysParameter getAccessToken(CommonDao commonDao, String appId, String appSecret) { |
| | | |
| | | SqlSentence ss = new SqlSentence(); |
| | | Map<String, Object> map = new HashMap<String, Object>(); |
| | | map.put("isDel", SysParameter.NO); |
| | | map.put("paramName",appSecret); |
| | | ss.sqlSentence("select * from pla_sys_parameter where isDel = #{m.isDel} and paramName = #{m.paramName}",map); |
| | | SysParameter sp = commonDao.selectOne(SysParameterMapper.class,ss); |
| | | |
| | | int needGetAgain = 1; |
| | | if(sp != null) { |
| | | //需要判断一下是否过期 |
| | | Calendar ca = Calendar.getInstance(); |
| | | long curTime = ca.getTimeInMillis(); |
| | | ca.setTime(sp.getCreateTime()); |
| | | ca.add(Calendar.SECOND, Integer.parseInt(sp.getParamValue1())); |
| | | if(curTime < ca.getTimeInMillis()) { |
| | | needGetAgain = 0; |
| | | } |
| | | } |
| | | |
| | | if(needGetAgain == 1) { |
| | | //需要重新获取 |
| | | JSONObject reObj = null; |
| | | try { |
| | | reObj = MPWeixinBaseUtil.getAccessToken(appId, appSecret); |
| | | }catch (Exception e) { |
| | | throw new PlatTipsException(PlatformCode.ERROR_TIPS,"获取token错误03:"+e.getMessage()); |
| | | } |
| | | if(reObj != null) { |
| | | if(!StringUtils.isEmpty(reObj.optString("access_token"))){ |
| | | if(sp == null) { |
| | | sp = new SysParameter(); |
| | | } |
| | | sp.setCreateTime(new Date()); |
| | | sp.setParamName(appSecret); |
| | | sp.setParamValue(reObj.optString("access_token")); |
| | | sp.setParamValue1(reObj.optInt("expires_in",7100) + ""); |
| | | |
| | | if(StringUtils.isEmpty(sp.getId())) { |
| | | commonDao.insert(SysParameterMapper.class,sp); |
| | | }else{ |
| | | commonDao.updateAll(SysParameterMapper.class,sp); |
| | | } |
| | | }else{ |
| | | throw new PlatTipsException(PlatformCode.ERROR_TIPS,"获取token错误04:"+reObj.optString("errmsg")); |
| | | } |
| | | }else{ |
| | | throw new PlatTipsException(PlatformCode.ERROR_TIPS,"获取token错误(NULL)"); |
| | | } |
| | | }else{ |
| | | sp = verificationToken(sp,appId, appSecret,commonDao); |
| | | } |
| | | return sp; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 校验token并重获取token保存 |
| | | * @return |
| | | */ |
| | | public static SysParameter verificationToken(SysParameter sp,String appId,String appSecret,CommonService commonService){ |
| | | //校验TOKEN是否有效 |
| | | Map<String,Object> data = new HashMap<>(); |
| | | data.put("access_token",sp.getParamValue()); |
| | | |
| | | String datas = HttpMethodUtil.HttpURLUtilJson("https://api.weixin.qq.com/wxa/getpaidunionid?access_token={access_token}&openid=123",null,data,null,"GET"); |
| | | if(!StringUtils.isEmpty(datas)){ |
| | | JSONObject objData = JSONObject.fromObject(datas); |
| | | if(objData.optInt("errcode") == 42001){ |
| | | //需要重新获取 |
| | | JSONObject reObj = CorpMpUtil.getApplicationAccessToken(appId, appSecret); |
| | | if(reObj != null) { |
| | | if(reObj.optInt("errcode", -1) == 0) { |
| | | if(sp == null) { |
| | | sp = new SysParameter(); |
| | | } |
| | | sp.setCreateTime(new Date()); |
| | | sp.setParamName(appSecret); |
| | | sp.setParamValue(reObj.optString("access_token")); |
| | | sp.setParamValue1(reObj.optInt("expires_in",7200) + ""); |
| | | |
| | | if(StringUtils.isEmpty(sp.getId())) { |
| | | commonService.insert(SysParameterMapper.class,sp); |
| | | }else{ |
| | | commonService.updateAll(SysParameterMapper.class,sp); |
| | | } |
| | | }else{ |
| | | logger.error("获取企业应用at失败:" + reObj.toString()); |
| | | } |
| | | }else{ |
| | | logger.error("获取企业应用at失败,没返回"); |
| | | } |
| | | } |
| | | } |
| | | return sp; |
| | | } |
| | | |
| | | /** |
| | | * 校验token并重获取token保存 |
| | | * @return |
| | | */ |
| | | public static SysParameter verificationToken(SysParameter sp,String appId,String appSecret,CommonDao commonDao){ |
| | | //校验TOKEN是否有效 |
| | | Map<String,Object> data = new HashMap<>(); |
| | | data.put("access_token",sp.getParamValue()); |
| | | |
| | | String datas = HttpMethodUtil.HttpURLUtilJson("https://api.weixin.qq.com/wxa/getpaidunionid?access_token={access_token}&openid=123",null,data,null,"GET"); |
| | | if(!StringUtils.isEmpty(datas)){ |
| | | JSONObject objData = JSONObject.fromObject(datas); |
| | | if(objData.optInt("errcode") == 42001){ |
| | | //需要重新获取 |
| | | JSONObject reObj = CorpMpUtil.getApplicationAccessToken(appId, appSecret); |
| | | if(reObj != null) { |
| | | if(reObj.optInt("errcode", -1) == 0) { |
| | | if(sp == null) { |
| | | sp = new SysParameter(); |
| | | } |
| | | sp.setCreateTime(new Date()); |
| | | sp.setParamName(appSecret); |
| | | sp.setParamValue(reObj.optString("access_token")); |
| | | sp.setParamValue1(reObj.optInt("expires_in",7200) + ""); |
| | | |
| | | if(StringUtils.isEmpty(sp.getId())) { |
| | | commonDao.insert(SysParameterMapper.class,sp); |
| | | }else{ |
| | | commonDao.updateAll(SysParameterMapper.class,sp); |
| | | } |
| | | }else{ |
| | | logger.error("获取企业应用at失败:" + reObj.toString()); |
| | | } |
| | | }else{ |
| | | logger.error("获取企业应用at失败,没返回"); |
| | | } |
| | | } |
| | | } |
| | | return sp; |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.hx.phip.entity; |
| | | |
| | | |
| | | public class UserList { |
| | | /**页*/ |
| | | private Integer pageNum; |
| | | /**每页数量*/ |
| | | private Integer pageSize; |
| | | /**电话*/ |
| | | private String tel; |
| | | /**性别*/ |
| | | private Integer sex; |
| | | /**名称*/ |
| | | private String name; |
| | | /**CIQ*/ |
| | | private String ciq; |
| | | /**会员等级*/ |
| | | private String memberLevel; |
| | | /**用户做过项目名称*/ |
| | | private String projectName; |
| | | |
| | | /**用户消费时间段(开始)*/ |
| | | private String consumeStartTime; |
| | | /**用户消费时间段(结束)*/ |
| | | private String consumeEndTime; |
| | | |
| | | /**用户创建时间段(开始)*/ |
| | | private String createStartTime; |
| | | /**用户消费时间段(结束)*/ |
| | | private String createEndTime; |
| | | |
| | | public Integer getPageNum() { |
| | | return pageNum; |
| | | } |
| | | |
| | | public void setPageNum(Integer pageNum) { |
| | | this.pageNum = pageNum; |
| | | } |
| | | |
| | | public Integer getPageSize() { |
| | | return pageSize; |
| | | } |
| | | |
| | | public void setPageSize(Integer pageSize) { |
| | | this.pageSize = pageSize; |
| | | } |
| | | |
| | | public String getTel() { |
| | | return tel; |
| | | } |
| | | |
| | | public void setTel(String tel) { |
| | | this.tel = tel; |
| | | } |
| | | |
| | | public String getName() { |
| | | return name; |
| | | } |
| | | |
| | | public void setName(String name) { |
| | | this.name = name; |
| | | } |
| | | |
| | | public String getCiq() { |
| | | return ciq; |
| | | } |
| | | |
| | | public void setCiq(String ciq) { |
| | | this.ciq = ciq; |
| | | } |
| | | |
| | | public String getMemberLevel() { |
| | | return memberLevel; |
| | | } |
| | | |
| | | public void setMemberLevel(String memberLevel) { |
| | | this.memberLevel = memberLevel; |
| | | } |
| | | |
| | | public String getProjectName() { |
| | | return projectName; |
| | | } |
| | | |
| | | public void setProjectName(String projectName) { |
| | | this.projectName = projectName; |
| | | } |
| | | |
| | | public String getConsumeStartTime() { |
| | | return consumeStartTime; |
| | | } |
| | | |
| | | public void setConsumeStartTime(String consumeStartTime) { |
| | | this.consumeStartTime = consumeStartTime; |
| | | } |
| | | |
| | | public String getConsumeEndTime() { |
| | | return consumeEndTime; |
| | | } |
| | | |
| | | public void setConsumeEndTime(String consumeEndTime) { |
| | | this.consumeEndTime = consumeEndTime; |
| | | } |
| | | |
| | | public String getCreateStartTime() { |
| | | return createStartTime; |
| | | } |
| | | |
| | | public void setCreateStartTime(String createStartTime) { |
| | | this.createStartTime = createStartTime; |
| | | } |
| | | |
| | | public String getCreateEndTime() { |
| | | return createEndTime; |
| | | } |
| | | |
| | | public void setCreateEndTime(String createEndTime) { |
| | | this.createEndTime = createEndTime; |
| | | } |
| | | |
| | | public Integer getSex() { |
| | | return sex; |
| | | } |
| | | |
| | | public void setSex(Integer sex) { |
| | | this.sex = sex; |
| | | } |
| | | } |
| | |
| | | return spplyParameter; |
| | | } |
| | | |
| | | /**企业小程序 |
| | | * @param mpAppId |
| | | * @param commonService |
| | | * @return |
| | | */ |
| | | public static ApplyParameter getMpParameter(String mpAppId, CommonService commonService){ |
| | | SqlSentence sqlSentence = new SqlSentence(); |
| | | Map<String,Object> values = new HashMap<>(); |
| | | |
| | | values.put("isDel",ApplyParameter.NO); |
| | | values.put("mpAppId",mpAppId); |
| | | values.put("type",ApplyParameter.TYPE_CORP_MP); |
| | | sqlSentence.sqlSentence("SELECT * FROM pla_apply_parameter WHERE isDel = #{m.isDel} AND type = #{m.type} AND mpAppId = #{m.mpAppId} ",values); |
| | | ApplyParameter spplyParameter = commonService.selectOne(ApplyParameterMapper.class,sqlSentence); |
| | | return spplyParameter; |
| | | } |
| | | |
| | | |
| | | } |
| | |
| | | |
| | | import com.gitee.sunchenbin.mybatis.actable.annotation.Column; |
| | | import com.gitee.sunchenbin.mybatis.actable.annotation.Table; |
| | | import com.gitee.sunchenbin.mybatis.actable.annotation.Unique; |
| | | import com.gitee.sunchenbin.mybatis.actable.constants.MySqlTypeConstant; |
| | | import com.hx.phiappt.model.BaseEntity; |
| | | |
| | | /** |
| | | * 应用数据 |
| | | * |
| | | */ |
| | | @Table(name = "pla_apply_parameter") |
| | | public class ApplyParameter extends BaseEntity { |
| | | |
| | | @Column(comment = "名称", length = 64, type = MySqlTypeConstant.VARCHAR,isNull = false) |
| | | private String name; |
| | | @Column(comment = "自定义标识(小程序appId/其他应用id/或者对应标识)", length = 64, type = MySqlTypeConstant.VARCHAR,isNull = false) |
| | | private String uniqueCode; |
| | | @Column(comment = "数据类型", length = 3, type = MySqlTypeConstant.INT,isNull = false) |
| | | private int type; |
| | | |
| | | @Column(comment = "企业微信id", length = 64, type = MySqlTypeConstant.VARCHAR) |
| | | private String corpId; |
| | | @Column(comment = "数据类型", length = 5, type = MySqlTypeConstant.INT,isNull = false) |
| | | private int type; |
| | | |
| | | @Column(comment = "企业微信通讯录秘钥(AES加密)", length = 255, type = MySqlTypeConstant.VARCHAR) |
| | | private String communiSecretKey; |
| | | @Column(comment = "企业微信联系我秘钥(AES加密)", length = 255, type = MySqlTypeConstant.VARCHAR) |
| | | private String contactSecretKey; |
| | | |
| | | @Column(comment = "企业微信应用秘钥(AES加密)", length = 255, type = MySqlTypeConstant.VARCHAR) |
| | | private String applySecretKey; |
| | | @Column(comment = "小程序appId", length = 64, type = MySqlTypeConstant.VARCHAR) |
| | | @Column(comment = "小程序appId/其他应用id", length = 64, type = MySqlTypeConstant.VARCHAR) |
| | | private String mpAppId; |
| | | @Column(comment = "小程序秘钥(AES加密)", length = 255, type = MySqlTypeConstant.VARCHAR) |
| | | private String mpSecretKey; |
| | | |
| | | |
| | | @Column(comment = "企业微信应用秘钥(AES加密)", length = 255, type = MySqlTypeConstant.VARCHAR) |
| | | private String applySecretKey; |
| | | |
| | | public ApplyParameter() { |
| | | } |
| | |
| | | public static final int TYPE_CORP_COMMUNICATION = 1; |
| | | /**联系我*/ |
| | | public static final int TYPE_CORP_CONTACT = 2; |
| | | |
| | | |
| | | /**其他*/ |
| | | public static final int TYPE_OTHER = 3; |
| | | |
| | | public String getCorpId() { |
| | | return corpId; |
| | |
| | | public void setContactSecretKey(String contactSecretKey) { |
| | | this.contactSecretKey = contactSecretKey; |
| | | } |
| | | |
| | | public String getName() { |
| | | return name; |
| | | } |
| | | |
| | | public void setName(String name) { |
| | | this.name = name; |
| | | } |
| | | |
| | | public String getUniqueCode() { |
| | | return uniqueCode; |
| | | } |
| | | |
| | | public void setUniqueCode(String uniqueCode) { |
| | | this.uniqueCode = uniqueCode; |
| | | } |
| | | } |
| | |
| | | public class Rsa { |
| | | public static void main(String[] args) { |
| | | |
| | | System.out.println("AES:"+AesUtil.aesEncryp("uhWNSciQeVGDQEh0lSJlVp5dUNMunVCi6yjLKbvxZF8")); |
| | | System.out.println(AesUtil.aesEncryp("a574ceedb661970cd2f057f8df05c473")); |
| | | |
| | | |
| | | //配置文件数据加密 |
| | |
| | | import com.hx.common.BaseController; |
| | | import com.hx.mp.util.CorpMpUtil; |
| | | import com.hx.phip.common.wx.corp.WeiXinCorpMpUtil; |
| | | import com.hx.phip.common.wx.corp.WeiXinMpUtil; |
| | | import com.hx.phip.entity.AccountToken; |
| | | import com.hx.phip.model.ApplyParameter; |
| | | import com.hx.phip.model.SysParameter; |
| | |
| | | //获取应用数据 |
| | | ApplyParameter applyParameter = ApplyParameterTool.getApplyParameter(accountToken.getCorpId(),accountToken.getMpId(),commonService); |
| | | if(applyParameter == null){ |
| | | throw new PlatTipsException(PlatformCode.ERROR_TIPS,"corpId is error"); |
| | | throw new PlatTipsException(PlatformCode.ERROR_TIPS,"corpId is error or mpId is error"); |
| | | } |
| | | |
| | | SysParameter sysParameter = WeiXinCorpMpUtil.getApplicationAccessToken(commonService,applyParameter.getCorpId(),AesUtil.aesDecryp(applyParameter.getApplySecretKey())); |
| | |
| | | return PlatformResult.success(data); |
| | | } |
| | | |
| | | /**获取小程序普通token*/ |
| | | @RequestMapping(value = "/mp/get_token",method = RequestMethod.POST) |
| | | public PlatformResult mpToken(HttpServletRequest request) { |
| | | |
| | | //获取返回参数 |
| | | String bodydata = HttpServletRequestUtil.getBody(request); |
| | | if(StringUtils.isEmpty(bodydata)){ |
| | | throw new PlatTipsException(PlatformCode.ERROR_BODY_DATA,"数据格式错误"); |
| | | } |
| | | AccountToken accountToken = null; |
| | | try{ |
| | | accountToken = JSONObject.parseObject(bodydata,AccountToken.class); |
| | | }catch (Exception e){ |
| | | throw new PlatTipsException(PlatformCode.ERROR_BODY_DATA,"数据格式错误"); |
| | | } |
| | | |
| | | if(accountToken == null){ |
| | | throw new PlatTipsException(PlatformCode.ERROR_BODY_DATA,"数据格式错误"); |
| | | } |
| | | |
| | | if (StringUtils.isEmpty(accountToken.getMpId())) { |
| | | throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"mpId is required"); |
| | | } |
| | | |
| | | //获取应用数据 |
| | | ApplyParameter applyParameter = ApplyParameterTool.getMpParameter(accountToken.getMpId(),commonService); |
| | | if(applyParameter == null){ |
| | | throw new PlatTipsException(PlatformCode.ERROR_TIPS,"mpId is error"); |
| | | } |
| | | |
| | | SysParameter sysParameter = WeiXinMpUtil.getAccessToken(commonService,applyParameter.getMpAppId(),AesUtil.aesDecryp(applyParameter.getMpSecretKey())); |
| | | if(sysParameter == null){ |
| | | throw new PlatTipsException(PlatformCode.ERROR_SYSTEM,"服务错误"+ SystemCode.ERROR_GET_CORP_TOKEN); |
| | | } |
| | | Map<String,Object> data = new HashMap<>(); |
| | | data.put("access_token",sysParameter.getParamValue()); |
| | | data.put("create_time",DateUtil.formatDate(sysParameter.getCreateTime(),"yyyy-MM-dd HH:mm:ss")); |
| | | data.put("expires_in",Integer.parseInt(sysParameter.getParamValue1())); |
| | | data.put("expires_surplus",secondNum(sysParameter.getCreateTime(),Integer.parseInt(sysParameter.getParamValue1()))); |
| | | |
| | | return PlatformResult.success(data); |
| | | } |
| | | |
| | | /** |
| | | * token剩余时间 |
| | |
| | | @RestController |
| | | @RequestMapping("/employee") |
| | | public class EmployeeController extends BaseController { |
| | | //log4j日志 |
| | | private static Logger logger = LoggerFactory.getLogger(EmployeeController.class.getName()); |
| | | |
| | | /** |
| | | * 企业员工列表 |
| | |
| | | throw new PlatTipsException(PlatformCode.ERROR_BODY_DATA,"数据格式错误"); |
| | | } |
| | | |
| | | int pageNum; |
| | | int pageSize; |
| | | |
| | | if (parameter.getPageNum() == null || parameter.getPageNum() <= 0) { |
| | | pageNum = 1; |
| | | }else { |
| | | pageNum = parameter.getPageNum(); |
| | | parameter.setPageNum(1); |
| | | } |
| | | if (parameter.getPageSize() == null || parameter.getPageSize() <= 0 || parameter.getPageSize() >=100) { |
| | | pageSize = 20; |
| | | }else { |
| | | pageSize = parameter.getPageSize(); |
| | | parameter.setPageSize(20); |
| | | } |
| | | PageHelper.startPage(pageNum,pageSize); |
| | | PageHelper.startPage(parameter.getPageNum(),parameter.getPageSize()); |
| | | SqlSentence sqlSentence = new SqlSentence(); |
| | | Map<String,Object> values = new HashMap<>(); |
| | | values.put("isDel", BaseEntity.NO); |
| | |
| | | return PlatformResult.success(data); |
| | | } |
| | | |
| | | /**企业员工-网页登录(小程序) |
| | | /**企业员工-网页登录(普通小程序) |
| | | * 普通小程序登录 |
| | | * @param request |
| | | * @return |
New file |
| | |
| | | package com.hx.phip.controller; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.github.pagehelper.PageHelper; |
| | | import com.github.pagehelper.PageInfo; |
| | | import com.hx.common.BaseController; |
| | | import com.hx.mybatisTool.SqlSentence; |
| | | import com.hx.phiappt.model.BaseEntity; |
| | | import com.hx.phip.dao.mapper.EmployeeMapper; |
| | | import com.hx.phip.entity.UserList; |
| | | import com.hx.util.HttpServletRequestUtil; |
| | | import com.hx.util.StringUtils; |
| | | import com.platform.exception.PlatTipsException; |
| | | import com.platform.resultTool.PlatformCode; |
| | | import com.platform.resultTool.PlatformResult; |
| | | import com.platform.util.DateHandleTool; |
| | | import org.apache.catalina.servlet4preview.http.HttpServletRequest; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RequestMethod; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * 用户接口 |
| | | * |
| | | * @USER: chenjiahe |
| | | * @DATE: 2021/11/09 |
| | | **/ |
| | | @RestController |
| | | @RequestMapping("/user") |
| | | public class UserController extends BaseController { |
| | | |
| | | /** |
| | | * 企业员工列表 |
| | | */ |
| | | @RequestMapping(value = "/list",method = RequestMethod.POST) |
| | | public PlatformResult typeList(HttpServletRequest request) { |
| | | //获取返回参数 |
| | | String bodyData = HttpServletRequestUtil.getBody(request); |
| | | if(StringUtils.isEmpty(bodyData)){ |
| | | throw new PlatTipsException(PlatformCode.ERROR_BODY_DATA,"数据格式错误"); |
| | | } |
| | | |
| | | UserList userList = null; |
| | | |
| | | try{ |
| | | userList = JSONObject.parseObject(bodyData,UserList.class); |
| | | }catch (Exception e){ |
| | | throw new PlatTipsException(PlatformCode.ERROR_BODY_DATA,"数据格式错误"); |
| | | } |
| | | |
| | | if(userList == null){ |
| | | throw new PlatTipsException(PlatformCode.ERROR_BODY_DATA,"数据格式错误"); |
| | | } |
| | | |
| | | if (userList.getPageNum() == null || userList.getPageNum() <= 0) { |
| | | userList.setPageNum(1); |
| | | } |
| | | if (userList.getPageSize() == null || userList.getPageSize() <= 0 || userList.getPageSize() >=100) { |
| | | userList.setPageSize(20); |
| | | } |
| | | |
| | | PageHelper.startPage(userList.getPageNum(),userList.getPageSize()); |
| | | SqlSentence sqlSentence = new SqlSentence(); |
| | | Map<String,Object> values = new HashMap<>(); |
| | | values.put("isDel", BaseEntity.NO); |
| | | StringBuilder sql = new StringBuilder(); |
| | | sql.append("SELECT u.id,u.name,u.CIQ,u.tel,u.apiId,u.imgUrl,u.gender,DATE_FORMAT(u.createTime,'%Y-%m-%d %H:%i:%S') AS createTime" + |
| | | " FROM user u WHERE u.isDel = #{m.isDel}"); |
| | | if (!StringUtils.isEmpty(userList.getTel())){ |
| | | values.put("tel","%"+userList.getTel()+"%"); |
| | | sql.append(" AND u.tel LIKE #{m.tel}"); |
| | | } |
| | | if (!StringUtils.isEmpty(userList.getName())){ |
| | | values.put("name","%"+userList.getName()+"%"); |
| | | sql.append(" AND u.name LIKE #{m.name}"); |
| | | } |
| | | if (!StringUtils.isEmpty(userList.getCiq())){ |
| | | values.put("ciq","%"+userList.getCiq()+"%"); |
| | | sql.append(" AND u.CIQ LIKE #{m.ciq}"); |
| | | } |
| | | if (userList.getSex() != null){ |
| | | values.put("sex",userList.getSex()); |
| | | sql.append(" AND u.gender = #{m.sex}"); |
| | | } |
| | | if (userList.getMemberLevel() != null){ |
| | | values.put("userLevel","%"+userList.getMemberLevel()+"%"); |
| | | sql.append(" AND u.userLevel LIKE #{m.userLevel}"); |
| | | } |
| | | if (userList.getProjectName() != null){ |
| | | //用户做过的项目 |
| | | values.put("projectName","%"+userList.getProjectName()+"%"); |
| | | sql.append(" AND (SELECT * FROM project p WHERE p.isDel = #{m.isDel} AND p.name LIKE #{m.projectName})"); |
| | | } |
| | | if (userList.getConsumeStartTime() != null){ |
| | | //消费时间段 |
| | | values.put("userLevel","%"+userList.getConsumeStartTime()+"%"); |
| | | sql.append(" AND u.userLevel = #{m.userLevel}"); |
| | | } |
| | | if (userList.getConsumeEndTime() != null){ |
| | | //消费时间段 |
| | | values.put("userLevel","%"+userList.getConsumeEndTime()+"%"); |
| | | sql.append(" AND u.userLevel = #{m.userLevel}"); |
| | | } |
| | | |
| | | if (userList.getCreateStartTime() != null){ |
| | | DateHandleTool.timeCheck(userList.getCreateStartTime(),"yyyy-MM-dd HH:mm:dd"); |
| | | //用户创建时间 |
| | | values.put("createStartTime",userList.getCreateStartTime()); |
| | | sql.append(" AND u.createTime >= #{m.createStartTime}"); |
| | | } |
| | | if (userList.getCreateEndTime() != null){ |
| | | DateHandleTool.timeCheck(userList.getCreateEndTime(),"yyyy-MM-dd HH:mm:dd"); |
| | | //用户创建时间 |
| | | values.put("createEndTime",userList.getCreateEndTime()); |
| | | sql.append(" AND u.createTime <= #{m.createEndTime}"); |
| | | } |
| | | |
| | | sqlSentence.sqlSentence(sql.toString(),values); |
| | | List<Map<String,Object>> employeeList = commonService.selectListMap(EmployeeMapper.class,sqlSentence); |
| | | PageInfo<Map<String, Object>> pageInfo = new PageInfo<>(employeeList); |
| | | Map<String,Object> data = new HashMap<>(); |
| | | data.put("userList",pageInfo.getList()); |
| | | data.put("total",pageInfo.getTotal()); |
| | | data.put("pages",pageInfo.getPages()); |
| | | data.put("pageNum",pageInfo.getPageNum()); |
| | | data.put("pageSize",pageInfo.getPageSize()); |
| | | data.put("isLastPage",pageInfo.isIsLastPage()); |
| | | return PlatformResult.success(data); |
| | | } |
| | | |
| | | } |
| | |
| | | String appId = request.getHeader("appid"); |
| | | |
| | | //校验 |
| | | PlatformResult platformResult = VerificationTool.verification(appId,sign,rsaParameter.getAppId(),rsaParameter.getPrivatekey()); |
| | | /*PlatformResult platformResult = VerificationTool.verification(appId,sign,rsaParameter.getAppId(),rsaParameter.getPrivatekey()); |
| | | if(!PlatformCode.SUCCESS.equals(platformResult.getCode())){ |
| | | return platformResult; |
| | | } |
| | | }*/ |
| | | |
| | | return joinPoint.proceed(); |
| | | } |
| | |
| | | logging.config=classpath:log4j2-local.xml |
| | | |
| | | #\u8BBE\u7F6E\u6570\u636E\u5E93\u8FDE\u63A5 |
| | | spring.datasource.url=jdbc:mysql://localhost:3306/medical?useUnicode=true&characterEncoding=UTF-8 |
| | | spring.datasource.url=jdbc:mysql://localhost:3306/phi_guide?useUnicode=true&characterEncoding=UTF-8 |
| | | spring.datasource.username=root |
| | | spring.datasource.password=root |
| | | spring.datasource.driver-class-name=com.mysql.jdbc.Driver |