Commit b3a4c979 by liulianglang

初始化

parent 6235c767
......@@ -4,8 +4,8 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>xzxt.tjfx.report</groupId>
<artifactId>tjfx</artifactId>
<groupId>xzxt.qyxzpt.report</groupId>
<artifactId>qyxzpt</artifactId>
<packaging>jar</packaging>
<version>1.0</version>
......@@ -210,7 +210,7 @@
</dependencies>
<build>
<finalName>xzxt-tjfx-report</finalName>
<finalName>xzxt-qyxzpt-report</finalName>
<resources>
<!-- 打包包含xml文件-->
......
package org.springblade.founder.ztrxyj.controller;
import io.swagger.annotations.ApiOperation;
import org.springblade.founder.tjfx.entity.AjtjParam;
import org.springblade.founder.tjfx.entity.LianTj;
import org.springblade.founder.utils.EasyUIPage;
import org.springblade.founder.utils.R;
import org.springblade.founder.ztrxyj.entity.ZtryBksj;
import org.springblade.founder.ztrxyj.entity.Ztryyjxx;
import org.springblade.founder.ztrxyj.service.ztgjService;
import org.springblade.modules.system.entity.SysNewUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping("/ztgj")
public class gjcxController {
@Autowired
private ztgjService ztService;
@PostMapping("/getYjList")
public R getYjList(Ztryyjxx ztryyjxx){
try {
return R.ok().data(ztService.getYjList(ztryyjxx));
} catch (Exception e) {
e.printStackTrace();
return R.error(e.getMessage());
}
}
@PostMapping("/getListYjXqgj")
public R getListYjXqgj(Ztryyjxx ztryyjxx){
try {
return R.ok().data(ztService.getListYjXqgj(ztryyjxx));
} catch (Exception e) {
e.printStackTrace();
return R.error(e.getMessage());
}
}
@PostMapping("/getBkzpList")
public R getBkzpList(ZtryBksj ztryBksj){
try {
return R.ok().data(ztService.getBkzpList(ztryBksj));
} catch (Exception e) {
e.printStackTrace();
return R.error(e.getMessage());
}
}
@PostMapping("/deleteBkzp")
public R deleteBkzp(String certNo){
try {
return R.ok().data(ztService.deleteBkzp(certNo));
} catch (Exception e) {
e.printStackTrace();
return R.error(e.getMessage());
}
}
@PostMapping("/deleteYjjl")
public R deleteYjjl(String xxzjbh){
try {
return R.ok().data(ztService.deleteYjjl(xxzjbh));
} catch (Exception e) {
e.printStackTrace();
return R.error(e.getMessage());
}
}
@PostMapping("/selectUserNewList")
public R selectUserNewList(SysNewUser sysNewUser){
try {
EasyUIPage easyUIPage = new EasyUIPage();
easyUIPage.setPage(sysNewUser.getPage());
easyUIPage.setPagePara(sysNewUser.getLimit());
int begin = easyUIPage.getBegin();
int end = easyUIPage.getEnd();
sysNewUser.setBegin(begin);
sysNewUser.setEnd(end);
Map<String,Object> map = new HashMap<>();
List<SysNewUser> list = ztService.getUserNewList(sysNewUser);
if(list == null){
return R.error("无权限查看");
}else{
int count = ztService.getUserNewCount(sysNewUser);
map.put("rows",list);
map.put("total",count);
return R.ok().data(map);
}
} catch (Exception e) {
e.printStackTrace();
return R.error(e.getMessage());
}
}
@PostMapping("/insertUserQh")
@ResponseBody
@ApiOperation(value = "给用户分配区划", notes = "给用户分配区划")
public R insertUserQh(String userIds,String qdIds){
try {
ztService.insertUserQh(userIds,qdIds);
return R.ok();
} catch (Exception e) {
e.printStackTrace();
return R.error(e.getMessage());
}
}
}
package org.springblade.founder.ztrxyj.entity;
import lombok.Data;
import org.springblade.founder.utils.BaseModel;
@Data
public class SysUserLlyqh extends BaseModel {
private String id; //照片
private String userId;
private String qhId;
}
package org.springblade.founder.ztrxyj.entity;
import lombok.Data;
@Data
public class ZtryBksj {
private String imgFace; //照片
private String faceDBId; //700046010603000104
private String name; //姓名
private String certNo; //证件号码
private String operate;
private int page;
private int limit;
}
package org.springblade.founder.ztrxyj.entity;
import lombok.Data;
import java.util.Date;
@Data
public class ZtryYjYhcz {
/**
* 信息主键
*/
private String xxzjbh;
/**
* 信息主键
*/
private String glxxzjbh;
/**
* 信息登记人员_姓名
*/
private String xxdjryXm;
/**
* 信息登记人员_联系电话
*/
private String xxdjryLxdh;
/**
* 信息登记单位_公安机关名称
*/
private String xxdjdwGajgmc;
/**
* 信息登记人员_公民身份号码
*/
private String xxdjryGmsfhm;
/**
* 信息登记单位_公安机关机构代码
*/
private String xxdjdwGajgjgdm;
/**
* 登记时间
*/
private Date djsj;
/**
* 操作类型:1删除
*/
private String czlx;
}
package org.springblade.founder.ztrxyj.entity;
public class Ztryyjxx {
/**
* faceName : 周千雷
* faceUrl : http://74.10.30.180:10005/125,136dc5d5b1545f0
* score : 0.9903
* captureTime : 2022-03-30 15:57:16
* faceDbId : 700046010603000037
* faceCertNo : 460026200003123010
* alarmTime : 2022-03-30 15:57:21
* faceDbName : 省-前科人员库
* panoramaUrl : http://74.10.30.180:10005/14892,ffffb852c48c8330781a7825
* deviceId : 800046010603004299
* deviceName : 华盛夜都大厅
* captureUrl : http://74.10.30.180:10005/14856,ffffb852c48c83360ca07721
*/
private String faceName;
private String faceUrl;
private String score;
private String captureTime;
private String captureTimeKssj;
private String scrxm;
public String getScrxm() {
return scrxm;
}
public void setScrxm(String scrxm) {
this.scrxm = scrxm;
}
public String getScrdwmc() {
return scrdwmc;
}
public void setScrdwmc(String scrdwmc) {
this.scrdwmc = scrdwmc;
}
private String scrdwmc;
public String getCaptureTimeKssj() {
return captureTimeKssj;
}
public void setCaptureTimeKssj(String captureTimeKssj) {
this.captureTimeKssj = captureTimeKssj;
}
public String getCaptureTimeJssj() {
return captureTimeJssj;
}
public void setCaptureTimeJssj(String captureTimeJssj) {
this.captureTimeJssj = captureTimeJssj;
}
private String captureTimeJssj;
private String faceDbId;
private String faceCertNo;
private String alarmTime;
private String faceDbName;
private String panoramaUrl;
private String deviceId;
private String deviceName;
private String captureUrl;
public String getQhmc() {
return qhmc;
}
public void setQhmc(String qhmc) {
this.qhmc = qhmc;
}
private String qhmc;
public String getQhdm() {
return qhdm;
}
public void setQhdm(String qhdm) {
this.qhdm = qhdm;
}
private String qhdm;
public String getScbz() {
return scbz;
}
public void setScbz(String scbz) {
this.scbz = scbz;
}
private String scbz;
private int page;
public int getPage() {
return page;
}
public void setPage(int page) {
this.page = page;
}
public int getLimit() {
return limit;
}
public void setLimit(int limit) {
this.limit = limit;
}
private int limit;
public String getXxzjbh() {
return xxzjbh;
}
public void setXxzjbh(String xxzjbh) {
this.xxzjbh = xxzjbh;
}
private String xxzjbh;
public void setFaceName(String faceName) {
this.faceName = faceName;
}
public void setFaceUrl(String faceUrl) {
this.faceUrl = faceUrl;
}
public void setScore(String score) {
this.score = score;
}
public void setCaptureTime(String captureTime) {
this.captureTime = captureTime;
}
public void setFaceDbId(String faceDbId) {
this.faceDbId = faceDbId;
}
public void setFaceCertNo(String faceCertNo) {
this.faceCertNo = faceCertNo;
}
public void setAlarmTime(String alarmTime) {
this.alarmTime = alarmTime;
}
public void setFaceDbName(String faceDbName) {
this.faceDbName = faceDbName;
}
public void setPanoramaUrl(String panoramaUrl) {
this.panoramaUrl = panoramaUrl;
}
public void setDeviceId(String deviceId) {
this.deviceId = deviceId;
}
public void setDeviceName(String deviceName) {
this.deviceName = deviceName;
}
public void setCaptureUrl(String captureUrl) {
this.captureUrl = captureUrl;
}
public String getFaceName() {
return faceName;
}
public String getFaceUrl() {
return faceUrl;
}
public String getScore() {
return score;
}
public String getCaptureTime() {
return captureTime;
}
public String getFaceDbId() {
return faceDbId;
}
public String getFaceCertNo() {
return faceCertNo;
}
public String getAlarmTime() {
return alarmTime;
}
public String getFaceDbName() {
return faceDbName;
}
public String getPanoramaUrl() {
return panoramaUrl;
}
public String getDeviceId() {
return deviceId;
}
public String getDeviceName() {
return deviceName;
}
public String getCaptureUrl() {
return captureUrl;
}
}
package org.springblade.founder.ztrxyj.mapper;
import org.apache.ibatis.annotations.Mapper;
import org.springblade.founder.ztrxyj.entity.SysUserLlyqh;
import org.springblade.founder.ztrxyj.entity.ZtryBksj;
import org.springblade.founder.ztrxyj.entity.ZtryYjYhcz;
import org.springblade.founder.ztrxyj.entity.Ztryyjxx;
import org.springblade.modules.system.entity.SysNewUser;
import org.springblade.modules.system.entity.SysUserRolesNew;
import org.springframework.stereotype.Component;
import java.util.List;
@Mapper
@Component
public interface ztgjMapper {
List<Ztryyjxx> getListYjgj(Ztryyjxx ztryyjxx);
int getListYjgjCount(Ztryyjxx ztryyjxx);
List<Ztryyjxx> getListYjXqgj(Ztryyjxx ztryyjxx);
int getListYjXqgjCount(Ztryyjxx ztryyjxx);
List<ZtryBksj> getBkzpList(ZtryBksj ztryBksj);
int getBkzpListCount(ZtryBksj ztryBksj);
ZtryBksj getMaztryZp(String certNo);
int updatesftsZtzp(String certNo);
int insertYjYhcz(ZtryYjYhcz ztryYjYhcz);
int updateYjsc(String xxzjbh);
// 获取用户 个数
int getUserNewCount(SysNewUser sysNewUser)throws Exception;
// 获取用户 列表
List<SysNewUser> getUserNewList(SysNewUser sysNewUser)throws Exception;
List<String> getUserqh(String id);
void deleteUserqh(SysUserLlyqh sysUserLlyqh)throws Exception;
//给用户分配角色
int insertUserqh(SysUserLlyqh SysUserLlyqh )throws Exception;
}
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.springblade.founder.ztrxyj.mapper.ztgjMapper">
<insert id="insertYjYhcz">
insert into tb_maztry_yj_yhcz(xxzjbh,glxxzjbh, xxdjry_xm, xxdjry_lxdh, xxdjdw_gajgmc, xxdjry_gmsfhm, xxdjdw_gajgjgdm, djsj, czlx)
values (#{xxzjbh},#{glxxzjbh}, #{xxdjryXm}, #{xxdjryLxdh}, #{xxdjdwGajgmc}, #{xxdjryGmsfhm}, #{xxdjdwGajgjgdm}, now(), #{czlx})
</insert>
<insert id="insertUserqh">
insert into sys_user_llyqh(id,user_id, qh_id, xxsc_pdbz, xxdjdw_gajgjgdm, xxdjdw_gajgmc, xxdjry_xm, xxdjry_gmsfhm, xxdjry_lxdh, djsj, xxczdw_gajgjgdm, xxczdw_gajgmc, xxczry_xm, xxczry_gmsfhm, gxsj)
values (#{id},#{userId}, #{qhId},'0', #{xxdjdwGajgjgdm}, #{xxdjdwGajgmc}, #{xxdjryXm}, #{xxdjryGmsfhm}, #{xxdjryLxdh}, now(), #{xxczdwGajgjgdm}, #{xxczdwGajgmc}, #{xxczryXm}, #{xxczryGmsfhm}, now())
</insert>
<update id="updatesftsZtzp">
update tb_ry_maztryzp set sfts = '3' ,gxsj=now()
where identitycard=#{ certNo , jdbcType=VARCHAR }
</update>
<update id="updateYjsc">
update tb_maztry_yj set scbz='1',gxsj=now() where xxzjbh = #{xxzjbh}
</update>
<update id="deleteUserqh">
UPDATE sys_user_llyqh SET
gxsj = now(),
<if test="xxczdwGajgjgdm != null and xxczdwGajgjgdm != ''">
xxczdw_gajgjgdm = #{xxczdwGajgjgdm},
</if>
<if test="xxczdwGajgmc != null and xxczdwGajgmc != ''">
xxczdw_gajgmc = #{xxczdwGajgmc},
</if>
<if test="xxczryXm != null and xxczryXm != ''">
xxczry_xm = #{xxczryXm},
</if>
<if test="xxczryGmsfhm != null and xxczryGmsfhm != ''">
xxczry_gmsfhm = #{xxczryGmsfhm},
</if>
xxsc_pdbz = '1'
WHERE
user_id = #{ userId , jdbcType=VARCHAR }
</update>
<select id="getListYjgj" resultType="org.springblade.founder.ztrxyj.entity.Ztryyjxx">
select xxzjbh, faceName, faceUrl, score, captureTime,
faceDbId, faceCertNo, alarmTime, faceDbName, panoramaUrl, yj.deviceId, yj.deviceName,
(select dict.name from sys_dictitem dict
where dict.code=(select left(yd.gbCode,6) from tb_maztry_yj_device yd where yd.deviceId=yj.deviceId ) and dict.groupid = 'CODE_XZQH' ) qhmc,
captureUrl from tb_maztry_yj yj right join (
select idcard,zpsj from ( select
faceCertNo idcard, max(captureTime) zpsj
from tb_maztry_yj yj left join tb_maztry_yj_device sb on yj.deviceId=sb.deviceId
<where>
and scbz='0'
<if test="xxzjbh != null and xxzjbh != ''">
and xxzjbh = #{xxzjbh}
</if>
<if test="faceName != null and faceName != ''">
and faceName = #{faceName}
</if>
<if test="qhdm != null and qhdm != ''">
and left(sb.gbCode,6) like concat(#{qhdm},'%')
</if>
<if test="score != null and score != ''">
and score = #{score}
</if>
<if test="captureTime != null and captureTime != ''">
and captureTime = #{captureTime}
</if>
<if test="captureTimeKssj != null and captureTimeKssj != ''">
and captureTime <![CDATA[>=]]> DATE_FORMAT(#{captureTimeKssj,jdbcType=VARCHAR},'%Y-%m-%d %H:%i:%s')
</if>
<if test="captureTimeJssj != null and captureTimeJssj != ''">
and captureTime <![CDATA[<]]> DATE_FORMAT(#{captureTimeJssj,jdbcType=VARCHAR},'%Y-%m-%d %H:%i:%s')
</if>
<if test="faceDbId != null and faceDbId != ''">
and faceDbId = #{faceDbId}
</if>
<if test="faceCertNo != null and faceCertNo != ''">
and faceCertNo = #{faceCertNo}
</if>
<if test="alarmTime != null">
and alarmTime = #{alarmTime}
</if>
<if test="faceDbName != null and faceDbName != ''">
and faceDbName = #{faceDbName}
</if>
<if test="deviceId != null and deviceId != ''">
and deviceId = #{deviceId}
</if>
<if test="deviceName != null and deviceName != ''">
and deviceName = #{deviceName}
</if>
</where>
group by
faceCertNo ) abc left join tb_ry_maztryzp zp on zp.identitycard=abc.idcard where zp.sfts='1'
order
by abc.zpsj desc limit #{ page }, #{ limit }
) bb on yj.faceCertNo=bb.idcard and yj.captureTime=bb.zpsj
</select>
<select id="getListYjgjCount" resultType="java.lang.Integer">
select count(1) from ( select idcard,zpsj from ( select
faceCertNo idcard, max(captureTime) zpsj
from tb_maztry_yj yj left join tb_maztry_yj_device sb on yj.deviceId=sb.deviceId
<where>
and scbz='0'
<if test="xxzjbh != null and xxzjbh != ''">
and xxzjbh = #{xxzjbh}
</if>
<if test="faceName != null and faceName != ''">
and faceName = #{faceName}
</if>
<if test="qhdm != null and qhdm != ''">
and left(sb.gbCode,6) like concat(#{qhdm},'%')
</if>
<if test="score != null and score != ''">
and score = #{score}
</if>
<if test="captureTime != null and captureTime != ''">
and captureTime = #{captureTime}
</if>
<if test="captureTimeKssj != null and captureTimeKssj != ''">
and captureTime <![CDATA[>=]]> DATE_FORMAT(#{captureTimeKssj,jdbcType=VARCHAR},'%Y-%m-%d %H:%i:%s')
</if>
<if test="captureTimeJssj != null and captureTimeJssj != ''">
and captureTime <![CDATA[<]]> DATE_FORMAT(#{captureTimeJssj,jdbcType=VARCHAR},'%Y-%m-%d %H:%i:%s')
</if>
<if test="faceDbId != null and faceDbId != ''">
and faceDbId = #{faceDbId}
</if>
<if test="faceCertNo != null and faceCertNo != ''">
and faceCertNo = #{faceCertNo}
</if>
<if test="alarmTime != null">
and alarmTime = #{alarmTime}
</if>
<if test="faceDbName != null and faceDbName != ''">
and faceDbName = #{faceDbName}
</if>
<if test="deviceId != null and deviceId != ''">
and deviceId = #{deviceId}
</if>
<if test="deviceName != null and deviceName != ''">
and deviceName = #{deviceName}
</if>
</where>
group by
faceCertNo ) abc left join tb_ry_maztryzp zp on zp.identitycard=abc.idcard where zp.sfts='1'
) bb
</select>
<select id="getListYjXqgj" resultType="org.springblade.founder.ztrxyj.entity.Ztryyjxx">
select xxzjbh, faceName, faceUrl, score, captureTime,
faceDbId, faceCertNo, alarmTime, faceDbName, panoramaUrl, yj.deviceId, yj.deviceName, captureUrl,
(select cz.xxdjry_xm from tb_maztry_yj_yhcz cz where cz.glxxzjbh=yj.xxzjbh limit 1 ) scrxm,
(select cz.xxdjdw_gajgmc from tb_maztry_yj_yhcz cz where cz.glxxzjbh=yj.xxzjbh limit 1) scrdwmc,
(select dict.name from sys_dictitem dict where dict.code=left(sb.gbCode,6) and dict.groupid = 'CODE_XZQH' ) qhmc
from tb_maztry_yj yj left join tb_maztry_yj_device sb
on yj.deviceId=sb.deviceId
<where>
<if test="scbz != null and scbz != ''">
and scbz=#{scbz}
</if>
<if test="qhdm != null and qhdm != ''">
and left(sb.gbCode,6) like concat(#{qhdm},'%')
</if>
<if test="xxzjbh != null and xxzjbh != ''">
and xxzjbh = #{xxzjbh}
</if>
<if test="faceName != null and faceName != ''">
and faceName = #{faceName}
</if>
<if test="score != null and score != ''">
and score = #{score}
</if>
<if test="captureTime != null and captureTime != ''">
and captureTime = #{captureTime}
</if>
<if test="captureTimeKssj != null and captureTimeKssj != ''">
and captureTime <![CDATA[>=]]> DATE_FORMAT(#{captureTimeKssj,jdbcType=VARCHAR},'%Y-%m-%d %H:%i:%s')
</if>
<if test="captureTimeJssj != null and captureTimeJssj != ''">
and captureTime <![CDATA[<]]> DATE_FORMAT(#{captureTimeJssj,jdbcType=VARCHAR},'%Y-%m-%d %H:%i:%s')
</if>
<if test="faceDbId != null and faceDbId != ''">
and faceDbId = #{faceDbId}
</if>
<if test="faceCertNo != null and faceCertNo != ''">
and faceCertNo = #{faceCertNo}
</if>
<if test="alarmTime != null">
and alarmTime = #{alarmTime}
</if>
<if test="faceDbName != null and faceDbName != ''">
and faceDbName = #{faceDbName}
</if>
<if test="deviceId != null and deviceId != ''">
and deviceId = #{deviceId}
</if>
<if test="deviceName != null and deviceName != ''">
and deviceName = #{deviceName}
</if>
</where>
order by captureTime desc limit #{ page }, #{ limit }
</select>
<select id="getListYjXqgjCount" resultType="java.lang.Integer">
select count(1) from tb_maztry_yj yj left join tb_maztry_yj_device sb
on yj.deviceId=sb.deviceId
<where>
<if test="scbz != null and scbz != ''">
and scbz=#{scbz}
</if>
<if test="qhdm != null and qhdm != ''">
and left(sb.gbCode,6) like concat(#{qhdm},'%')
</if>
<if test="xxzjbh != null and xxzjbh != ''">
and xxzjbh = #{xxzjbh}
</if>
<if test="faceName != null and faceName != ''">
and faceName = #{faceName}
</if>
<if test="score != null and score != ''">
and score = #{score}
</if>
<if test="captureTime != null and captureTime != ''">
and captureTime = #{captureTime}
</if>
<if test="captureTimeKssj != null and captureTimeKssj != ''">
and captureTime <![CDATA[>=]]> DATE_FORMAT(#{captureTimeKssj,jdbcType=VARCHAR},'%Y-%m-%d %H:%i:%s')
</if>
<if test="captureTimeJssj != null and captureTimeJssj != ''">
and captureTime <![CDATA[<]]> DATE_FORMAT(#{captureTimeJssj,jdbcType=VARCHAR},'%Y-%m-%d %H:%i:%s')
</if>
<if test="faceDbId != null and faceDbId != ''">
and faceDbId = #{faceDbId}
</if>
<if test="faceCertNo != null and faceCertNo != ''">
and faceCertNo = #{faceCertNo}
</if>
<if test="alarmTime != null and alarmTime != ''">
and alarmTime = #{alarmTime}
</if>
<if test="faceDbName != null and faceDbName != ''">
and faceDbName = #{faceDbName}
</if>
<if test="deviceId != null and deviceId != ''">
and deviceId = #{deviceId}
</if>
<if test="deviceName != null and deviceName != ''">
and deviceName = #{deviceName}
</if>
</where>
</select>
<select id="getBkzpList" resultType="org.springblade.founder.ztrxyj.entity.ZtryBksj">
select ztry.xm as name,ztry.identitycard as certNo ,ztry.ckzp as imgFace from tb_ry_maztryzp ztry
where sfts='1'
<if test="certNo != null and certNo != ''">
and identitycard = #{certNo}
</if>
<if test="name != null and name != ''">
and xm = #{name}
</if>
limit #{ page }, #{ limit }
</select>
<select id="getBkzpListCount" resultType="java.lang.Integer">
select count(1) from tb_ry_maztryzp ztry
where sfts='1'
<if test="certNo != null and certNo != ''">
and identitycard = #{certNo}
</if>
<if test="name != null and name != ''">
and xm = #{name}
</if>
</select>
<select id="getMaztryZp" resultType="org.springblade.founder.ztrxyj.entity.ZtryBksj">
select ztry.xm as name,ztry.identitycard as certNo ,ztry.ckzp as imgFace from tb_ry_maztryzp ztry
where ztry.identitycard=#{certNo}
</select>
<select id="getUserNewList" resultType="org.springblade.modules.system.entity.SysNewUser">
SELECT
us.id as id,
(select name from sys_dictitem where groupid='QGCODE_UNIT' AND code=us.unitcode) as unitcode,
us.username as username,
us.password as password,
us.true_name as trueName,
us.open_flag as openFlag,
us.default_model as defaultModel,
us.remark as remark,
us.lrr as lrr,
us.lrsj as lrsj,
us.gxr as gxr,
us.gxsj as gxsj,
us.lrdwdm as lrdwdm,
us.lrdwmc as lrdwmc,
us.identitycard as identitycard,
(select name from sys_dictitem where groupid='CODE_XB' AND code=us.sex) as sex,
us.birthday as birthday,
us.telephone as telephone,
<!--(select name from sys_dictitem where groupid='CODE_UNIT' AND code=us.unitcode) as unitname,-->
(SELECT name FROM sys_dictitem_xz WHERE code = us.unitcode) as unitname,
us.scbz as scbz,
us.ip as ip,
us.grade as grade,
us.policemanid as policemanid,
(select (select name from sys_dictitem where groupid='CODE_XZQH' AND code=lqh.qh_id) as mc from sys_user_llyqh lqh where lqh.user_id=us.id AND lqh.xxsc_pdbz = '0' limit 1 ) qhmc
FROM sys_user us
LEFT JOIN sys_dictitem_xz xz ON us.unitcode = xz.code
<if test="roleId != null and roleId != ''">
RIGHT JOIN (
SELECT DISTINCT
ur.user_id id
FROM
sys_user_llyqh ur
WHERE
ur.qh_id = #{roleId}
AND ur.xxsc_pdbz = '0'
) a ON us.id = a.id
</if>
<include refid="user-where"/>
order by us.lrsj desc
limit #{begin}, #{end}
</select>
<select id="getUserNewCount" resultType="java.lang.Integer">
SELECT count(*)
FROM sys_user us
LEFT JOIN sys_dictitem_xz xz ON us.unitcode = xz.code
<if test="roleId != null and roleId != ''">
RIGHT JOIN (
SELECT DISTINCT
ur.user_id id
FROM
sys_user_llyqh ur
WHERE
ur.qh_id = #{roleId}
AND ur.xxsc_pdbz = '0'
) a ON us.id = a.id
</if>
<include refid="user-where"/>
</select>
<select id="getUserqh" resultType="java.lang.String">
SELECT
urole.qh_id
FROM sys_user_llyqh urole
where urole.xxsc_pdbz='0' and urole.user_id=#{ id , jdbcType=VARCHAR }
</select>
<sql id="user-where">
WHERE
us.scbz = '0'
and xz.${codeLevCol} = #{userUnitCode}
<if test="username != null and username != ''">
and us.username LIKE concat('%',#{username},'%')
</if>
<if test="trueName != null and trueName != ''">
and us.true_name LIKE concat('%',#{trueName},'%')
</if>
<if test="policemanid != null and policemanid != ''">
and us.policemanid = #{ policemanid , jdbcType=VARCHAR }
</if>
<if test="openFlag != null and openFlag != ''">
and us.open_flag = #{ openFlag, jdbcType=VARCHAR }
</if>
<if test="unitcode != null and unitcode != ''">
and us.unitcode = #{ unitcode, jdbcType=VARCHAR }
</if>
<if test="sfjg != null and sfjg != ''">
and ${sfzsjgsql}
</if>
</sql>
</mapper>
package org.springblade.founder.ztrxyj.service;
import org.springblade.founder.ztrxyj.entity.ZtryBksj;
import org.springblade.founder.ztrxyj.entity.Ztryyjxx;
import org.springblade.modules.system.entity.SysNewUser;
import java.util.List;
import java.util.Map;
public interface ztgjService {
Map<String, Object> getYjList(Ztryyjxx ztryyjxx);
Map<String, Object> getListYjXqgj(Ztryyjxx ztryyjxx);
Map<String, Object> getBkzpList(ZtryBksj ztryBksj);
Map<String, Object> deleteBkzp(String certNo);
Map<String, Object> deleteYjjl(String xxzjbh);
// 获取用户 列表
List<SysNewUser> getUserNewList(SysNewUser sysNewUser)throws Exception;
// 获取用户 个数
int getUserNewCount(SysNewUser sysNewUser)throws Exception;
//给用户分配角色
void insertUserQh(String userIds,String qdIds)throws Exception;
}
package org.springblade.founder.ztrxyj.service;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang.StringUtils;
import org.springblade.common.tool.HqXjDwCommon;
import org.springblade.core.secure.utils.SecureUtil;
import org.springblade.founder.tjfx.mapper.AjtjMapper;
import org.springblade.founder.utils.EasyUIPage;
import org.springblade.founder.utils.HttpClient;
import org.springblade.founder.utils.R;
import org.springblade.founder.ztrxyj.entity.SysUserLlyqh;
import org.springblade.founder.ztrxyj.entity.ZtryBksj;
import org.springblade.founder.ztrxyj.entity.ZtryYjYhcz;
import org.springblade.founder.ztrxyj.entity.Ztryyjxx;
import org.springblade.founder.ztrxyj.mapper.ztgjMapper;
import org.springblade.founder.ztrxyj.utils.TokenUtils;
import org.springblade.modules.system.entity.SysNewUser;
import org.springblade.modules.system.entity.SysUserRolesNew;
import org.springblade.modules.system.entity.XzxtUser;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@Service
public class ztgjServiceImpl implements ztgjService {
@Resource
private ztgjMapper ztgj;
@Resource
private AjtjMapper ajtjMapper;
@Value("${ssdw}")
private String ssdw;
@Override
public Map<String, Object> getYjList(Ztryyjxx ztryyjxx) {
Map<String, Object> rtMap = new HashMap<>();
EasyUIPage easyUIPage = new EasyUIPage();
easyUIPage.setPage(ztryyjxx.getPage());
easyUIPage.setPagePara(ztryyjxx.getLimit());
int begin = easyUIPage.getBegin();
int end = easyUIPage.getEnd();
ztryyjxx.setPage(begin);
ztryyjxx.setLimit(end);
XzxtUser user = SecureUtil.getUserXzxt();
List<String> qhs=ztgj.getUserqh(user.getTenantId());
String userQh="";
int qxlev=0;
int tjlev=0;
if(qhs!=null && qhs.size()>0){
userQh=qhs.get(0);
}
if(StringUtils.isEmpty(userQh)) {
rtMap.put("rows",new ArrayList<>());
rtMap.put("total",0);
return null;
}else {
String qxxzqh = userQh;
if (qxxzqh.endsWith("0000")) {
qxlev=1;
} else if (qxxzqh.endsWith("00")) {
qxlev=2;
}
}
if (StringUtils.isNotEmpty(ztryyjxx.getQhdm())) {
String zhfzxyrHjdzXzqhdm = ztryyjxx.getQhdm();
if (zhfzxyrHjdzXzqhdm.endsWith("0000")) {
zhfzxyrHjdzXzqhdm = zhfzxyrHjdzXzqhdm.substring(0, 2);
tjlev=1;
} else if (zhfzxyrHjdzXzqhdm.endsWith("00")) {
zhfzxyrHjdzXzqhdm = zhfzxyrHjdzXzqhdm.substring(0, 4);
tjlev=2;
}
if(qxlev==1){
ztryyjxx.setQhdm(zhfzxyrHjdzXzqhdm);
}else if(qxlev==0){
if(qxlev==0){
if(ztryyjxx.getQhdm().equals(userQh)){
ztryyjxx.setQhdm(zhfzxyrHjdzXzqhdm);
}else {
return null;
}
}
ztryyjxx.setQhdm(zhfzxyrHjdzXzqhdm);
}else if(qxlev==2){
if(qxlev>=tjlev){
if(userQh.equals(ztryyjxx.getQhdm().substring(0,4)+"00")){
ztryyjxx.setQhdm(zhfzxyrHjdzXzqhdm);
}else {
return null;
}
}else {
return null;
}
}
}else {
String zhfzxyrHjdzXzqhdm = userQh;
if (zhfzxyrHjdzXzqhdm.endsWith("0000")) {
zhfzxyrHjdzXzqhdm = zhfzxyrHjdzXzqhdm.substring(0, 2);
} else if (zhfzxyrHjdzXzqhdm.endsWith("00")) {
zhfzxyrHjdzXzqhdm = zhfzxyrHjdzXzqhdm.substring(0, 4);
}
ztryyjxx.setQhdm(zhfzxyrHjdzXzqhdm);
}
rtMap.put("rows",ztgj.getListYjgj(ztryyjxx));
rtMap.put("total",ztgj.getListYjgjCount(ztryyjxx));
return rtMap;
}
@Override
public Map<String, Object> getBkzpList(ZtryBksj ztryyjxx) {
Map<String, Object> rtMap = new HashMap<>();
EasyUIPage easyUIPage = new EasyUIPage();
easyUIPage.setPage(ztryyjxx.getPage());
easyUIPage.setPagePara(ztryyjxx.getLimit());
int begin = easyUIPage.getBegin();
int end = easyUIPage.getEnd();
ztryyjxx.setPage(begin);
ztryyjxx.setLimit(end);
List<ZtryBksj> list=ztgj.getBkzpList(ztryyjxx);
for(ZtryBksj xx:list){
if(xx.getImgFace().contains("base64,")) {
}else {
xx.setImgFace("data:image/jpg;base64,"+xx.getImgFace());
}
}
rtMap.put("rows",list);
rtMap.put("total",ztgj.getBkzpListCount(ztryyjxx));
return rtMap;
}
@Override
public Map<String, Object> deleteBkzp(String certNo) {
ZtryBksj sj=ztgj.getMaztryZp(certNo);
String url = "http://74.10.30.174:18093/govServerWeb/personFace/pictureToFaceDb";
String token="";
if(sj!=null) {
if(StringUtils.isEmpty(token)){
token= TokenUtils.getHnKyToken();
}
Map herders=new HashMap();
//设置请求的header参数
herders.put("Authorization",token);
herders.put("Content-Type","application/json");
//推送布控入库人像
// JSONObject params = new JSONObject();// 请求参数
// params.put("imgFace",imgFace);
// params.put("captureBeginTime"
// ,gxsjKssj);
// params.put("captureEndTime",gxsjJssj);
// params.put("","");
sj.setImgFace(sj.getImgFace().replaceAll("\\s*|\r|\n|\t",""));
// System.out.println(sj.getImgFace());
sj.setOperate("0");
sj.setFaceDBId("700046010603000104");
try {
String resultString = HttpClient.doPostJson(url, herders, JSONObject.toJSONString(sj));
System.out.println("bksjts==="+resultString);
JSONObject result=JSONObject.parseObject(resultString);
if(result.getInteger("code")==200){
ztgj.updatesftsZtzp(certNo);
XzxtUser user = SecureUtil.getUserXzxt();
ZtryYjYhcz yhcz=new ZtryYjYhcz();
yhcz.setXxzjbh(getOrderIdByUuid());
yhcz.setGlxxzjbh(certNo);
yhcz.setXxdjryXm(user.getRealname());
yhcz.setXxdjdwGajgjgdm(user.getUnitcode());
yhcz.setXxdjdwGajgmc(user.getUnitname());
yhcz.setXxdjryGmsfhm(user.getIdentitycard());
yhcz.setXxdjryLxdh(user.getPhone());
yhcz.setCzlx("2"); //1删除,2撤控
ztgj.insertYjYhcz(yhcz);
}else {
//推送未成功2,删除3,推送成功1
ztgj.updatesftsZtzp(certNo);
}
}catch (Exception e){
e.printStackTrace();
}
}
return null;
}
@Override
public Map<String, Object> deleteYjjl(String xxzjbh) {
XzxtUser user = SecureUtil.getUserXzxt();
ZtryYjYhcz yhcz=new ZtryYjYhcz();
yhcz.setXxzjbh(getOrderIdByUuid());
yhcz.setGlxxzjbh(xxzjbh);
yhcz.setXxdjryXm(user.getRealname());
yhcz.setXxdjdwGajgjgdm(user.getUnitcode());
yhcz.setXxdjdwGajgmc(user.getUnitname());
yhcz.setXxdjryGmsfhm(user.getIdentitycard());
yhcz.setXxdjryLxdh(user.getPhone());
yhcz.setCzlx("1"); //删除
ztgj.updateYjsc(xxzjbh);
ztgj.insertYjYhcz(yhcz);
return null;
}
// 用户的个数
@Override
public int getUserNewCount(SysNewUser sysNewUser) throws Exception {
return ztgj.getUserNewCount(sysNewUser);
}
// 用户的列表展示
@Override
public List<SysNewUser> getUserNewList(SysNewUser sysNewUser) throws Exception {
XzxtUser xzxtUser = SecureUtil.getUserXzxt();
String dwUnitCode = xzxtUser.getUnitcode(); //当前单位代码
String userGrade = xzxtUser.getGrade(); //用户等级
System.out.println("从系统中获取的用户等级" + userGrade);
String sfzsjgsql="";
String sfzsjgdwcode=sysNewUser.getUnitcode();
//加一个判断,如果有这个权限,表明可以看所有的用户
//------2023-03-17 去掉F010101和F010102菜单,用户信息管理菜单默认权限为本单位及以下 begin------
// int a = sysUserMapper.getCodeNum(xzxtUser.getId(), "F010101");
int a = 0;
//------2023-03-17 去掉F010101和F010102菜单,用户信息管理菜单默认权限为本单位及以下 end------
if(a > 0){
dwUnitCode = ssdw;
userGrade = "S";
}else{
int unitLev = Integer.valueOf(ajtjMapper.getTwoUnitLevel(dwUnitCode)).intValue(); //所属单位等级
if(unitLev == 1){ //如果所属单位是1,那么就是S
userGrade = "S";
System.out.println("判断所属单位等级是1");
}else if(unitLev == 2 && !"S".equals(userGrade)){ //如果所属单位是2,需要判断用户等级
userGrade = "D";
System.out.println("判断所属单位等级是2");
}else if(unitLev == 3 && !"S".equals(userGrade) && !"D".equals(userGrade)){
userGrade = "X";
System.out.println("判断所属单位等级是3");
}
System.out.println("经过判断后获取的用户等级" + userGrade);
if("S".equals(userGrade)){
dwUnitCode = ssdw;
System.out.println("ssdw是" + ssdw);
}else if("D".equals(userGrade)){
dwUnitCode = ajtjMapper.getDUnitcode(dwUnitCode);
System.out.println("如果判断是等于D" + dwUnitCode);
}
}
//加一个判断,如果查询条件的所属单位有值,需要判断当前登录用户是否有权限查看所选择单位的数据
if(StringUtils.isNotEmpty(sysNewUser.getUnitcode())){
int judgeValue = judgeDataAuthority(a, userGrade, dwUnitCode, sysNewUser.getUnitcode());
if(judgeValue < 0){
return null;
}else if(judgeValue > 0){
//需要判断包含下级是否选中
if(StringUtils.isEmpty(sysNewUser.getSfbhxj()) || "0".equals(sysNewUser.getSfbhxj())){
//没有选择,无权查看父级数据
return null;
}else{
//选择了,但是只能查看当前级别及其子集们的数据,所以去掉unitcode的值,选了跟没选一样
sysNewUser.setUnitcode(null);
}
}else{
//如果等于0,说明有权限查看选择单位的数据
if(StringUtils.isNotEmpty(sysNewUser.getSfbhxj()) && "1".equals(sysNewUser.getSfbhxj())){
dwUnitCode = sysNewUser.getUnitcode();
sysNewUser.setUnitcode(null); //去掉精确查询
}
//机关查询判断
if(StringUtils.isNotEmpty(sysNewUser.getSfbhxj()) && "3".equals(sysNewUser.getSfbhxj())) {
if(StringUtils.isNotEmpty(sfzsjgdwcode)){
if(sfzsjgdwcode.endsWith("0000000000")) {
sfzsjgsql=" us.unitcode like '"+sfzsjgdwcode.substring(0,4)+ "%'";
sysNewUser.setSfzsjgsql(sfzsjgsql);
sysNewUser.setSfjg("1");
dwUnitCode = sysNewUser.getUnitcode();
sysNewUser.setUnitcode(null); //去掉精确查询
}else if(sfzsjgdwcode.endsWith("00000000")){
sfzsjgsql=" us.unitcode like '"+sfzsjgdwcode.substring(0,6)+ "%'";
sysNewUser.setSfzsjgsql(sfzsjgsql);
sysNewUser.setSfjg("1");
dwUnitCode = sysNewUser.getUnitcode();
sysNewUser.setUnitcode(null); //去掉精确查询
}else{
dwUnitCode = sysNewUser.getUnitcode();
sysNewUser.setUnitcode(null); //去掉精确查询
}
}
}
}
}
String grade = ajtjMapper.getTwoUnitLevel(dwUnitCode); //单位所在级别
Map<String, String> mapDwLevCode = HqXjDwCommon.getMapDwLevCode(dwUnitCode, grade);
sysNewUser.setCodeLevCol(mapDwLevCode.get("codeLevCol"));
sysNewUser.setUserUnitCode(dwUnitCode);
List<SysNewUser> userNewList = ztgj.getUserNewList(sysNewUser);
return userNewList;
}
//判断当前用户是否有权限查询所选单位的数据
//返回值说明(-1:无权查看,0:可以查看所有数据、不需要额外判断,1:可以查看数据、但是说明所选单位的级别更高、需要另行判断)
private int judgeDataAuthority(int allAuthority, String grade, String userUnit, String chooseSsdw){
if(allAuthority > 0){ //如果有全部数据的权限,就可以看
return 0;
}else{
//如果没有,需要判断当前单位是否可以查看所选择单位的数据
//判断当前登录者是否是省级用户,有最高权限,可以查看数据
if("S".equals(grade)){
return 0;
}else{
//如果不是,则判断查询的所属单位等级与当前单位等级是否相等
int unitLev = Integer.valueOf(ajtjMapper.getTwoUnitLevel(userUnit)).intValue();
int chooseLev = Integer.valueOf(ajtjMapper.getTwoUnitLevel(chooseSsdw)).intValue();
int differenceValue = unitLev - chooseLev;
if(differenceValue < 0){
//小于0说明当前登录者所在单位的级别更高,查询当前查询单位是否是当前登录者所在的单位的下属
int a = ajtjMapper.queryChildOrNot(chooseSsdw, "CODE_LEV" + unitLev, userUnit);
if(a > 0){
//大于0,说明是当前登录单位的子集,可以查看其数据
return 0;
}else{
//否则,说明不是当前登录单位的子集,无权查看查询单位的数据
return -1;
}
}else if(differenceValue == 0){
//等于0说明当前登录者所在单位的级别与查询的级别相等,可以查看其数据
if(chooseSsdw.equals(userUnit)){
return 0;
}
//否则无权查看查询单位的数据
return -1;
}else{
//大于0说明查询单位的级别更高,需要判断当前登录单位是否为查询单位的子集
int a = ajtjMapper.queryChildOrNot(userUnit, "CODE_LEV" + chooseLev, chooseSsdw);
if(a > 0){
//如果大于0,说明是子集,但是只能查看当前单位起始的数据
return 1;
}else{
//否则,说明当前登录单位不是所选择单位的子集,无权查看查询单位的数据
return -1;
}
}
}
}
}
//给用户分配角色
@Override
public void insertUserQh(String userIds, String qdIds) throws Exception {
List<String> listStr = getListStr(userIds);
List<String> listStr1 = getListStr(qdIds);
SysUserLlyqh sysUserLl = new SysUserLlyqh();
XzxtUser xzxtUser = SecureUtil.getUserXzxt();
sysUserLl.setDjUser(xzxtUser);
// List<String> zhroles= roleMapper.getZhrolesId();
if(listStr!=null && listStr.size()>0){
if(listStr1!=null && listStr1.size()>0){
for(String userlist:listStr){
List<String> userRolesName = ztgj.getUserqh(userlist);
if(userRolesName!=null && userRolesName.size()>0){
SysUserLlyqh dslly=new SysUserLlyqh();
dslly.setUserId(userlist);
dslly.setUpUser(xzxtUser);
ztgj.deleteUserqh(dslly);
}
for(String rolelist: listStr1){
String jyxxzjbh = getOrderIdByUuid();//xxzjbh
sysUserLl.setId(jyxxzjbh);
sysUserLl.setUserId(userlist);
sysUserLl.setQhId(rolelist);
ztgj.insertUserqh(sysUserLl);
}
}
}
}
}
//逗号分隔的字符串转list
public static List<String> getListStr(String str) {
String[] strs = str.split(",");
return Arrays.asList(strs);
}
private static String getOrderIdByUuid() {
//最大支持1-9个集群机器部署
int machineId = 1;
int hashCodeV = UUID.randomUUID().toString().hashCode();
//有可能是负数
if (hashCodeV < 0) {
hashCodeV = -hashCodeV;
}
// 0 代表前面补充0
// 4 代表长度为4
// d 代表参数为正数型
return machineId + String.format("%015d", hashCodeV);
}
@Override
public Map<String, Object> getListYjXqgj(Ztryyjxx ztryyjxx) {
Map<String, Object> rtMap = new HashMap<>();
EasyUIPage easyUIPage = new EasyUIPage();
easyUIPage.setPage(ztryyjxx.getPage());
easyUIPage.setPagePara(ztryyjxx.getLimit());
int begin = easyUIPage.getBegin();
int end = easyUIPage.getEnd();
ztryyjxx.setPage(begin);
ztryyjxx.setLimit(end);
if (StringUtils.isNotEmpty(ztryyjxx.getQhdm())) {
String zhfzxyrHjdzXzqhdm = ztryyjxx.getQhdm();
if (zhfzxyrHjdzXzqhdm.endsWith("0000")) {
zhfzxyrHjdzXzqhdm = zhfzxyrHjdzXzqhdm.substring(0, 2);
} else if (zhfzxyrHjdzXzqhdm.endsWith("00")) {
zhfzxyrHjdzXzqhdm = zhfzxyrHjdzXzqhdm.substring(0, 4);
}
ztryyjxx.setQhdm(zhfzxyrHjdzXzqhdm);
}
rtMap.put("rows",ztgj.getListYjXqgj(ztryyjxx));
rtMap.put("total",ztgj.getListYjXqgjCount(ztryyjxx));
return rtMap;
}
}
package org.springblade.founder.ztrxyj.utils;
import cn.hutool.core.exceptions.ExceptionUtil;
import lombok.extern.slf4j.Slf4j;
import java.io.*;
import java.util.Properties;
@Slf4j
public class PropertieUtil {
/**
* 读取配置文件某属性绝对路径下的token
*/
public String readTokenValue(String key, String url) {
String value = "";
try {
Properties prop = new Properties();
// FileInputStream fileInputStream = new FileInputStream(url);
InputStream fileInputStream = this.getClass().getResourceAsStream("/token.properties");
prop.load(fileInputStream);
value = prop.getProperty(key);
fileInputStream.close();
} catch (Exception e) {
e.printStackTrace();
log.error(ExceptionUtil.getMessage(e));
}
return value;
}
/**
* 将值写入配置文件绝对路径下的token
*/
public void writeTokenProperties(String token_url, String parameterName, String parameterValue) throws Exception {
String filePath = token_url;
// 获取配置文件
Properties pps = new Properties();
// FileInputStream fileInputStream = new FileInputStream(filePath);
InputStream fileInputStream = this.getClass().getResourceAsStream("/token.properties");
InputStream in = new BufferedInputStream(fileInputStream);
InputStreamReader inputStreamReader = new InputStreamReader(in, "UTF-8");
pps.load(inputStreamReader);
inputStreamReader.close();
in.close();
fileInputStream.close();
//true表示追加打开,false表示每次都是清空重写
OutputStream out = new FileOutputStream(filePath);
// 设置配置名称和值
pps.setProperty(parameterName, parameterValue);
// comments 等于配置文件的注释
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(out, "UTF-8");
pps.store(outputStreamWriter, "Update " + parameterName + " name");
out.flush();
outputStreamWriter.close();
out.close();
}
}
package org.springblade.founder.ztrxyj.utils;
import org.apache.commons.codec.binary.Base64;
import java.security.*;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;
/**
* SHA1WithRSA-数字签名工具类
* Created by yangyang on 2022/04/27.
*/
public class RsaUtil {
//加密算法
public static final String SIGN_ALGORITHMS = "SHA1WithRSA";
//私钥
private static final String privateKey = "MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBANF/IIsbi9+v5V0VlXeDWp3LlWNXf1gQ3EYjbdj4qMJJoVaLUv2T6fsQq4MTGO6h0HaPQPb80g2VXXgtwOBAGhTN5ifi8VLkHp8h+sU3/hmR2q3eyUeUEaX8t53leWQiI462O23bysectI5lmqzkL/68LTzSpu8z308XSWOFdXKVAgMBAAECgYA7qjIxjCndDjKLvT7xZ8aiFD46qcvJ4BtsGmEJn2Ao3WGGzW1YbQ0BhTDjxseeBxXg/lGpRj3ownZ5aMZ616bVa8xFdI9agmElnM78RhUgJNtOelY4yB3vMQmdpYxhA6Zp+Z10DCvKyxiostqrLw/zdSr8ZkmRof1DUMml5FZzYQJBAPe8zQsHqXeGSjvAEpPpBX87Wzc7/T6tObuOokxOrWfPmZFO7qy2rsdOkmn8LghIhzvOognoT6DiBhO4UIgJAMkCQQDYe9Kfju7JhbhE0SRh+1hSRRV8+6vRmpTIxJpy+AN3Oc6oeiQ6UE7/ZxyeZ0pDgmBZGJDBHoX1rIYrsuMmgrVtAkEA0YwHO88tTwZuAABFNoshtS71xtCdMsi/TqAlM7pQ/sAgu0IyrDCRwc/6FF/UZ/lBOhtcAFlaEVFdpox+wbIr0QJBAM9BJHF7ruKiMbs4m2Nu9ay11Q+2BlYCb0US7Gb7SJ4hatdjMEHf1vGvrvd8Hd4p+MHzwcoRxeBhToaRmeSpqLUCQFFTCNRlE/0Qo8hKLJlu8NpN00/VznTp+llGsSelmpOJ3QVWWoFR4egxfkvS5k+lU3Xwwu4ljXh7gLxPRfTprgk=";
//公钥
private static final String publicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDRfyCLG4vfr+VdFZV3g1qdy5VjV39YENxGI23Y+KjCSaFWi1L9k+n7EKuDExjuodB2j0D2/NINlV14LcDgQBoUzeYn4vFS5B6fIfrFN/4Zkdqt3slHlBGl/Led5XlkIiOOtjtt28rHnLSOZZqs5C/+vC080qbvM99PF0ljhXVylQIDAQAB";
/**
* 使用私钥给入参签名
* @param param 签名的数据
* @return 返回入参签名16进制字符串
* */
public static String sign(String param) {
try {
//获取privatekey
byte[] privateKeyByte = new Base64().decode(privateKey);
KeyFactory keyfactory = KeyFactory.getInstance("RSA");
PKCS8EncodedKeySpec encoderule = new PKCS8EncodedKeySpec(privateKeyByte);
PrivateKey key = keyfactory.generatePrivate(encoderule);
//用私钥给入参加签
Signature sign = Signature.getInstance(SIGN_ALGORITHMS);
sign.initSign(key);
sign.update(param.getBytes());
byte[] signature = sign.sign();
//将签名的入参转换成16进制字符串
return Base64.encodeBase64String(signature);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/**
* 用公钥验证签名
* @param param 入参
* @param signature 使用私钥签名的入参字符串
* @param publicKey 公钥
* @return 返回验证结果
* */
// public static boolean verifyRes(String param,String signature,String publicKey){
// try {
// //获取公钥
// KeyFactory keyFactory=KeyFactory.getInstance("RSA");
// byte[] publicKeyByte= new Base64().decode(publicKey);
// X509EncodedKeySpec encodeRule=new X509EncodedKeySpec(publicKeyByte);
// PublicKey key= keyFactory.generatePublic(encodeRule);
//
// //用获取到的公钥对 入参中未加签参数param入参中的加签之后的参数signature进行验签
// Signature sign=Signature.getInstance(SIGN_ALGORITHMS);
// sign.initVerify(key);
// sign.update(param.getBytes());
//
// //将16进制码转成字符数组
// byte[] hexByte = Base64.decodeBase64(signature);
// //验证签名
// return sign.verify(hexByte);
//
// } catch (Exception e) {
// e.printStackTrace();
// }
// return false;
// }
/**
* byte数组转换成十六进制字符串
* @param bytes byte数组
* @return 返回十六进制字符串
*/
private static String bytesToHexStr(byte[] bytes) {
StringBuffer stringBuffer = new StringBuffer("");
for (int i = 0; i < bytes.length; ++i) {
stringBuffer.append(Integer.toHexString(0x0100 + (bytes[i] & 0x00FF)).substring(1).toUpperCase());
}
return stringBuffer.toString();
}
/**
* 十六进制字符串转成byte数组
* @param hexStr 十六进制字符串
* @return 返回byte数组
* */
private static byte[] hexStrToBytes(String hexStr) {
byte[] bytes = new byte[hexStr.length() / 2];
for (int i = 0; i < bytes.length; i++) {
bytes[i] = (byte) Integer.parseInt(hexStr.substring(2 * i, 2 * i + 2), 16);
}
return bytes;
}
public static void main(String[] args) {
String param = "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiI3NC4xMC4zMC4xNzQiLCJpc3MiOiJ0b2tlbi5idWlsZGVyIiwiaWF0IjoxNjUxMjIyOTcwfQ.WIbBf23zZ-KKpCbOX9z6qX0Tqzyanl_WBnvE8YWyle4.xingjdj";
String sign = sign(param);
System.out.println("签名后的参数>>>"+sign);
// System.out.println("验证结果>>>"+verifyRes(param,sign,publicKey));
}
}
package org.springblade.founder.ztrxyj.utils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.HttpStatus;
import org.apache.http.NameValuePair;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.springblade.common.tool.HttpUtil;
import org.springblade.founder.utils.HttpClient;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Component;
import org.springframework.util.ResourceUtils;
import org.springframework.util.StringUtils;
import java.util.*;
/**
* @ClassName: HttpClient
* @Auther: yangyang
* @Description: java类作用描述
* @CreateDate: 2022-04-28
* @Version: 1.0
*/
@Component
public class TokenUtils {
private static Log logger = LogFactory.getLog(HttpClient.class);
private static RequestConfig requestConfig = null;
private static String tokenPath="token.properties";
static{
// 设置请求和传输超时时间
//setConnectTimeout:设置连接超时时间,单位毫秒。
//setSocketTimeout:请求获取数据的超时时间,单位毫秒。 如果访问一个接口,多少时间内无法返回数据,就直接放弃此次调用。
//setConnectionRequestTimeout:设置从connect Manager获取Connection 超时时间,单位毫秒
requestConfig = RequestConfig.custom().setSocketTimeout(120000).setConnectTimeout(120000).build();
try{
// ClassPathResource classPathResource = new ClassPathResource("token.properties");
// tokenPath= classPathResource.getFile().getPath();
}catch (Exception e){
e.printStackTrace();
}
}
// 云天token
public static String getYtgsToken(){
PropertieUtil propertieUtil=new PropertieUtil();
String result_token = "";
try{
//1 先比较已有token是否过期
long nowtime = new Date().getTime();
//获取绝对路径下的token属性文件
String token= propertieUtil.readTokenValue("token",tokenPath);;
String expiration =propertieUtil.readTokenValue("expiration",tokenPath);
if(StringUtils.isEmpty(token) || StringUtils.isEmpty(expiration)){
result_token=readeWriteYtToken(nowtime);
}else{
//token值已过期
if(nowtime > Long.valueOf(expiration)){
result_token=readeWriteYtToken(nowtime);
}else{
result_token = token;
}
}
}catch (Exception e){
e.printStackTrace();
logger.info(e.getMessage());
}
return result_token;
}
//读和写云天的token值
public static String readeWriteYtToken(long nowtime){
PropertieUtil propertieUtil=new PropertieUtil();
String result_token="";
//2 如果过期先获取新的token值
String Authorization =propertieUtil.readTokenValue("Authorization",tokenPath);
String ContentType =propertieUtil.readTokenValue("Content-Type",tokenPath);
Map headerMap=new HashMap();
headerMap.put("Authorization",Authorization);
headerMap.put("Content-Type",ContentType);
String username =propertieUtil.readTokenValue("username",tokenPath);
String password =propertieUtil.readTokenValue("password",tokenPath);
String grant_type =propertieUtil.readTokenValue("grant_type",tokenPath);
String scope =propertieUtil.readTokenValue("scope",tokenPath);
String client_secret=propertieUtil.readTokenValue("client_secret",tokenPath);
String client_id =propertieUtil.readTokenValue("client_id",tokenPath);
JSONObject object = new JSONObject();
object.put("username", username);
object.put("password", password);
object.put("grant_type", grant_type);
object.put("scope", scope);
object.put("client_secret", client_secret);
object.put("client_id", client_id);
String token_url =propertieUtil.readTokenValue("token_url",tokenPath);
try {
String resultString = HttpClient.doPostJson(token_url,headerMap,JSONObject.toJSONString(object));
if (!StringUtils.isEmpty(resultString)) {
JSONObject result=JSONObject.parseObject(resultString);
result_token = result.getString("access_token");
String expires_in = result.getString("expires_in");//有效时间段 单位为秒
String result_expiration = nowtime+Integer.parseInt(expires_in)*1000+"";
//写入新的token值和本次token的过期时间
propertieUtil.writeTokenProperties(tokenPath, "token", result_token);
propertieUtil.writeTokenProperties(tokenPath, "expiration", result_expiration);
}
}catch (Exception e){
e.printStackTrace();
logger.info(e.getMessage());
}
return result_token;
}
/**
* 将参数拼接为?key1=a&key2=b形式提交
* @param url
* @param headers
* @param jsonParam
* @return
*/
public static String doPostUrlEncodedFormEntity(String url, Map<String, String> headers, String jsonParam){
String resultString = "";
HttpPost httpPost = new HttpPost(url);
try{
//给httpPost请求设置header
if(null!=headers&&headers.size()>0){
for(String key:headers.keySet()){
httpPost.addHeader(key,headers.get(key));
}
}
// 设置参数解决中文乱码
if (null != jsonParam){
List<NameValuePair> paramList=new ArrayList<>();
Map<String, String> paramMap=(Map<String, String>) JSON.parse(jsonParam);
paramMap.forEach((key,value) -> paramList.add(new BasicNameValuePair(key,value)));
//模拟表单
UrlEncodedFormEntity entity=new UrlEncodedFormEntity(paramList);
entity.setContentEncoding("UTF-8");
httpPost.setEntity(entity);
}
// 设置请求和传输超时时间
httpPost.setConfig(requestConfig);
//创建客户端连接请求
CloseableHttpClient httpClient = HttpClients.createDefault();
// 发送请求
CloseableHttpResponse result = httpClient.execute(httpPost);
System.out.println("StatusCode===="+result.getStatusLine().getStatusCode());
if (result.getStatusLine().getStatusCode() == HttpStatus.SC_OK){
// 读取服务器返回的json数据(然后解析)
resultString = EntityUtils.toString(result.getEntity(), "utf-8");
}
}catch (Exception e){
e.printStackTrace();
logger.info(e.getMessage());
}finally{
httpPost.releaseConnection();
}
return resultString;
}
// 海南凯亚token获取
public static String getHnKyToken(){
PropertieUtil propertieUtil=new PropertieUtil();
String result_token = "";
try{
//先比较已有token是否过期
long nowtime = new Date().getTime();
//获取绝对路径下的token属性文件
String token= propertieUtil.readTokenValue("tokenKy",tokenPath);;
String expiration =propertieUtil.readTokenValue("expirationKy",tokenPath);
System.out.println("tokenPath-----"+tokenPath);
System.out.println("expirationKy-----"+expiration);
if(StringUtils.isEmpty(token) || StringUtils.isEmpty(expiration)){
result_token=readeWriteHnKyToken(nowtime);
}else{
//token值已过期
if(nowtime > Long.valueOf(expiration)){
result_token=readeWriteHnKyToken(nowtime);
}else{
result_token = token;
}
}
}catch (Exception e){
e.printStackTrace();
logger.info(e.getMessage());
}
return result_token;
}
// 海南凯亚token获取
public static String getHnKyTokencc(String token){
PropertieUtil propertieUtil=new PropertieUtil();
String result_token = "";
try{
//先比较已有token是否过期
long nowtime = new Date().getTime();
//获取绝对路径下的token属性文件
// String token= propertieUtil.readTokenValue("tokenKy",tokenPath);;
String expiration =propertieUtil.readTokenValue("expirationKy",tokenPath);
System.out.println("tokenPath-----"+tokenPath);
System.out.println("expirationKy-----"+expiration);
if(StringUtils.isEmpty(token) || StringUtils.isEmpty(expiration)){
result_token=readeWriteHnKyToken(nowtime);
}else{
//token值已过期
if(nowtime > Long.valueOf(expiration)){
result_token=readeWriteHnKyToken(nowtime);
}else{
result_token = token;
}
}
}catch (Exception e){
e.printStackTrace();
logger.info(e.getMessage());
}
return result_token;
}
//读和写海南凯亚的token值
public static String readeWriteHnKyToken(long nowtime){
PropertieUtil propertieUtil=new PropertieUtil();
String result_token="";
//如果过期先获取新的token值
Map headerMap=new HashMap();
headerMap.put("login-channel","API");
String username =propertieUtil.readTokenValue("usernameKy",tokenPath);
String token_url =propertieUtil.readTokenValue("token_urlKy",tokenPath);
System.out.println("读写字段名1"+username);
String clientUid = getClientUid(token_url);// 随机码
System.out.println("随机码+"+clientUid);
String password =RsaUtil.sign(clientUid+"."+username);// 随机码+“.”+用户名 RSA私钥进行SHA1WithRSA数字签名
JSONObject object = new JSONObject();
object.put("username", username);
object.put("password", password);
object.put("clientUid", clientUid);
try {
String resultString = HttpClient.doPostJson(token_url+"/auth/login",headerMap,JSONObject.toJSONString(object));
if (!StringUtils.isEmpty(resultString)) {
JSONObject result=JSONObject.parseObject(resultString);
System.out.println("=====jjjj==="+result.toJSONString());
if(result.getInteger("code")==200){
JSONObject resultData=result.getJSONObject("data");
result_token = resultData.getString("authorization");
String expires_in = resultData.getString("expireTime");//有效时间段 单位为秒 1800秒
String result_expiration = nowtime+Integer.parseInt(expires_in)*1000+"";
//写入新的token值和本次token的过期时间
System.out.println("====="+result_token);
propertieUtil.writeTokenProperties(tokenPath, "tokenKy", result_token);
propertieUtil.writeTokenProperties(tokenPath, "expirationKy", result_expiration);
}else{
return result.getString("msg");
}
}
}catch (Exception e){
e.printStackTrace();
logger.info("获取token错误"+e.getMessage());
}
return result_token;
}
// 获取海南凯亚的clientUid
public static String getClientUid(String token_url){
JSONObject jsonObject = JSONObject.parseObject(HttpUtil.doGet(token_url+"/auth/getClientUid"));
return jsonObject.getString("clientUid");
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment