Commit ee846d56 by wxh

修改了BUG

parent e6d16cc0
......@@ -18,7 +18,8 @@
<druid.version>1.1.10</druid.version>
<java.version>1.8</java.version>
<fastjson.version>1.2.46</fastjson.version>
<shiro.version>1.4.0</shiro.version>
<jwt.version>0.7.0</jwt.version>
<spring-cloud.version>Greenwich.SR2</spring-cloud.version>
......@@ -75,7 +76,11 @@
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
......@@ -93,6 +98,31 @@
<version>4.0.0</version>
</dependency>
<!-- 用户权限 登录 鉴权框架 -->
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-core</artifactId>
<version>${shiro.version}</version>
</dependency>
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-spring</artifactId>
<version>${shiro.version}</version>
</dependency>
<!-- jwt java web token框架 -->
<dependency>
<groupId>com.auth0</groupId>
<artifactId>java-jwt</artifactId>
<version>3.4.0</version>
</dependency>
<!-- bcrypt 加密算法 -->
<dependency>
<groupId>de.svenkubiak</groupId>
<artifactId>jBCrypt</artifactId>
<version>0.4.1</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
......
package com.orhon.smartcampus.material.auth;
import static com.auth0.jwt.JWT.create;
import static com.auth0.jwt.JWT.decode;
import static com.auth0.jwt.JWT.require;
import java.util.Date;
import com.auth0.jwt.JWTVerifier;
import com.auth0.jwt.algorithms.Algorithm;
import com.auth0.jwt.exceptions.JWTDecodeException;
import com.auth0.jwt.interfaces.DecodedJWT;
public class JwtUtils {
private static final long EXPIRE_TIME = 5 * 60 * 1000;
/**
* 校验token是否正确
*
* @param token 密钥
* @param secret 用户的密码
* @return 是否正确
*/
public static boolean verify(String token, String username, String secret) {
try {
//根据密码生成JWT效验器
Algorithm algorithm = Algorithm.HMAC256(secret);
JWTVerifier verifier = require(algorithm)
.withClaim("username", username)
.build();
//效验TOKEN
DecodedJWT jwt = verifier.verify(token);
return true;
} catch (Exception exception) {
return false;
}
}
/**
* 获得token中的信息无需secret解密也能获得
*
* @return token中包含的用户名
*/
public static String getUsername(String token) {
try {
DecodedJWT jwt = decode(token);
return jwt.getClaim("username").asString();
} catch (JWTDecodeException e) {
return null;
}
}
public static Long getUserId(String token){
try{
DecodedJWT jwt = decode(token);
return jwt.getClaim("userid").asLong();
}catch (JWTDecodeException e){
return null;
}
}
public static String getUserType(String token){
try{
DecodedJWT jwt = decode(token);
return jwt.getClaim("user_type").asString();
}catch (JWTDecodeException e){
return null;
}
}
public static Long getSchoolId(String token){
try{
//token = token==null?"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzY2hvb2xfaWQiOjEsImV4cCI6MTU2ODkzMDYyMSwidXNlcmlkIjoxLCJ1c2VybmFtZSI6InRlYWNoZXIifQ.Rh2NncYkPkSaN1BImRwgQGPtbz2Pwb0EviUQTXtfykQ":token;
DecodedJWT jwt = decode(token);
return jwt.getClaim("school_id").asLong();
}catch (JWTDecodeException e){
return null;
}
}
/**
* 生成签名,5min后过期
*
* @param username 用户名
* @param secret 用户的密码
* @return 加密的token
*/
public static String sign(String username, String secret) {
Date date = new Date(System.currentTimeMillis() + EXPIRE_TIME);
Algorithm algorithm = Algorithm.HMAC256(secret);
// 附带username信息
return create()
.withClaim("username", username)
.withExpiresAt(date)
.sign(algorithm);
}
//sign的重载函数
public static String sign(String username, String secret , Date expireTime) {
Date date = expireTime;
Algorithm algorithm = Algorithm.HMAC256(secret);
// 附带username信息
return create()
.withClaim("username", username)
.withExpiresAt(date)
.sign(algorithm);
}
//sign的重载函数
public static String sign(String username, Long userId , Long schoolId , String secret , Date expireTime) {
Date date = expireTime;
Algorithm algorithm = Algorithm.HMAC256(secret);
// 附带username信息
return create()
.withClaim("username", username)
.withClaim("userid" , userId)
.withClaim("school_id" , schoolId)
.withExpiresAt(date)
.sign(algorithm);
}
//sign的重载函数
public static String sign(String username, Long userId , Long schoolId , String secret , Date expireTime, String userType) {
Date date = expireTime;
Algorithm algorithm = Algorithm.HMAC256(secret);
// 附带username信息
return create()
.withClaim("username", username)
.withClaim("userid" , userId)
.withClaim("school_id" , schoolId)
.withClaim("user_type" , userType)
.withExpiresAt(date)
.sign(algorithm);
}
}
package com.orhon.smartcampus.material.auth;
import java.security.MessageDigest;
import java.util.UUID;
public class TokenGenerator {
public static String generateValue() {
return generateValue(UUID.randomUUID().toString());
}
private static final char[] hexCode = "0123456789abcdef".toCharArray();
public static String toHexString(byte[] data) {
if(data == null) {
return null;
}
StringBuilder r = new StringBuilder(data.length*2);
for ( byte b : data) {
r.append(hexCode[(b >> 4) & 0xF]);
r.append(hexCode[(b & 0xF)]);
}
return r.toString();
}
public static String generateValue(String param) {
try {
MessageDigest algorithm = MessageDigest.getInstance("MD5");
algorithm.reset();
algorithm.update(param.getBytes());
byte[] messageDigest = algorithm.digest();
return toHexString(messageDigest);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}
package com.orhon.smartcampus.material.modules.base.user;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import java.util.Date;
@Setter
@Getter
@EqualsAndHashCode
@Entity
@Table(name = "user_token")
public class Token {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue
private Integer id;
private Long userid;
private String token;
private Date expire_time;
private Date update_time;
private String username;
}
\ No newline at end of file
package com.orhon.smartcampus.material.modules.base.user;
import com.orhon.smartcampus.material.basicComponents.baseDao.BaseDaoImpl;
import org.springframework.stereotype.Component;
import java.util.List;
@Component
public class TokenDao extends BaseDaoImpl<Token> {
public Token queryByUserId(Long userId){
Token token = new Token();
token.setUserid(userId);
List<Token> datas = this.getTemplate().findByExample(token);
if (datas != null && datas.size() > 0){
return datas.get(0);
}
return null;
}
}
package com.orhon.smartcampus.material.modules.base.user;
import com.orhon.smartcampus.material.auth.JwtUtils;
import com.orhon.smartcampus.material.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
@Service
public class TokenService {
//12小时后过期
private final static int EXPIRE = 3600 * 12;
@Autowired
private TokenDao tokenDao;
@Autowired
private HttpServletRequest request;
public String getSystemToken(){
String token = request.getHeader("token");
// String token = (String) SecurityUtils.getSubject().getPrincipal();
return token;
}
public R createJwtToken(String userName , Long userId, Long schoolId, String userType) throws Exception {
//当前时间
Date now = new Date();
//过期时间
Date expireTime = new Date(now.getTime() + EXPIRE * 1000);
String token_str = JwtUtils.sign(userName , userId , schoolId , "OrhonSmartCampusToken7893" , expireTime, userType);
Token token = tokenDao.queryByUserId(userId);
if (token == null){
Token t = new Token();
t.setUserid(userId);
t.setToken(token_str);
t.setExpire_time(expireTime);
t.setUsername(userName);
t.setUpdate_time(now);
tokenDao.save(t);
}
else{
//token = tokenDao.get(Token.class , userId);
token.setUserid(userId);
token.setUpdate_time(now);
token.setExpire_time(expireTime);
token.setUsername(userName);
token.setToken(token_str);
tokenDao.saveOrUpdate(token);
}
return R.ok().put("token" , token_str).put("expire" , expireTime);
}
}
......@@ -11,7 +11,7 @@ import java.util.Date;
@Getter
@EqualsAndHashCode
@Entity
@Table(name = "material_buildings", schema = "material", catalog = "")
@Table(name = "material_buildings", schema = "smartcloud", catalog = "")
public class Buildings {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
......
......@@ -11,7 +11,7 @@ import java.util.Date;
@Getter
@EqualsAndHashCode
@Entity
@Table(name = "material_floor", schema = "material", catalog = "")
@Table(name = "material_floor", schema = "smartcloud", catalog = "")
public class FloorEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
......
......@@ -11,7 +11,7 @@ import java.util.Date;
@Getter
@EqualsAndHashCode
@Entity
@Table(name = "material_classify", schema = "material", catalog = "")
@Table(name = "material_classify", schema = "smartcloud", catalog = "")
public class GoodsClassify {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
......
......@@ -11,7 +11,7 @@ import java.util.Date;
@Getter
@EqualsAndHashCode
@Entity
@Table(name = "material_goods", schema = "material", catalog = "")
@Table(name = "material_goods", schema = "smartcloud", catalog = "")
public class GoodsManage {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
......@@ -33,8 +33,8 @@ public class GoodsManage {
private Integer goods_stock;
@Column(name = "goods_note", nullable = false)
private String goods_note;
@Column(name = "good_status", nullable = false)
private Integer good_status;
@Column(name = "goods_status", nullable = false)
private Integer goods_status;
@Column(name = "add_id", nullable = false)
private String add_id;
@Column(name = "employ_time", nullable = false)
......
......@@ -11,7 +11,7 @@ import java.util.Date;
@Getter
@EqualsAndHashCode
@Entity
@Table(name = "material_floor", schema = "material", catalog = "")
@Table(name = "material_room", schema = "smartcloud", catalog = "")
public class RoomEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
......
......@@ -11,7 +11,7 @@ import java.util.Date;
@Getter
@EqualsAndHashCode
@Entity
@Table(name = "material_site", schema = "material", catalog = "")
@Table(name = "material_site", schema = "smartcloud", catalog = "")
public class RootEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
......@@ -21,7 +21,7 @@ public class RootEntity {
@Column(name = "site_name", nullable = false)
private String site_name;
@Column(name = "site_status", nullable = false)
private String site_status;
private Integer site_status;
@Column(name = "sort_order", nullable = false)
private Integer sort_order;
@Column(name = "school_id", nullable = false)
......
......@@ -11,7 +11,7 @@ import java.util.Date;
@Getter
@EqualsAndHashCode
@Entity
@Table(name = "material_unit", schema = "material", catalog = "")
@Table(name = "material_unit", schema = "smartcloud", catalog = "")
public class Unit {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
......@@ -23,8 +23,8 @@ public class Unit {
private String unit_name;
@Column(name = "unit_head", nullable = false)
private String unit_head;
@Column(name = "floor_status", nullable = false)
private String floor_status;
@Column(name = "unit_status", nullable = false)
private Integer unit_status;
@Column(name = "floor_start", nullable = false)
private Integer floor_start;
@Column(name = "floor_end", nullable = false)
......
......@@ -31,23 +31,25 @@ public class BuildingsListFetcher implements DataFetcher {
public Object get(DataFetchingEnvironment env) throws Exception {
// + schoolId
String hql = "from Buildings";
String hql = "from Buildings 1=1 ";
GQLPageParam page = EnvArgsMapper.MAPPER.fromArgs(env);
if (env.containsArgument("condition")) {
HashMap<String, Object> map = ObjectToMap.to(env.getArgument("condition"));
if (map.get("id") != null) {
hql += "and id " + Util.decide(map.get("id"));
hql += " and id " + Util.decide(map.get("id"));
}
if (map.get("buildings_name") != null) {
hql += "and buildings_name " + Util.decide(map.get("buildings_name"));
hql += " and buildings_name " + Util.decide("like_" +map.get("buildings_name"));
}
if (map.get("buildings_status") != null) {
hql += "and buildings_status " + Util.decide(map.get("buildings_status"));
hql += " and buildings_status " + Util.decide(map.get("buildings_status"));
}
}
hql += " ORDER BY created_at DESC ";
List<Buildings> list = buildingsDao.find(hql, null, page.getPage(), page.getLimit());
List<GQLBuildings> gqlGoodsClassifies = BuildingsMapper.MAPPER.toBuildingsList(list);
......
......@@ -28,23 +28,23 @@ public class GoodsClassifyListFetcher implements DataFetcher {
public Object get(DataFetchingEnvironment env) throws Exception {
// + schoolId
String hql = "from GoodsClassify";
String hql = "from GoodsClassify where 1=1 ";
GQLPageParam page = EnvArgsMapper.MAPPER.fromArgs(env);
if(env.containsArgument("condition")) {
HashMap<String,Object> map = ObjectToMap.to(env.getArgument("condition"));
if(map.get("id")!=null) {
hql += "and id " + Util.decide(map.get("id"));
hql += " and id " + Util.decide(map.get("id"));
}
if(map.get("classify_name")!=null) {
hql += "and classify_name " + Util.decide(map.get("classify_name"));
hql += " and classify_name " + Util.decide("like_" + map.get("classify_name"));
}
if(map.get("classify_status")!=null) {
hql += "and classify_status " + Util.decide(map.get("classify_status"));
hql += " and classify_status " + Util.decide(map.get("classify_status"));
}
}
hql += " ORDER BY created_at DESC ";
List<GoodsClassify> list = goodsClassifyDao.find(hql,null,page.getPage(),page.getLimit());
List<GQLGoodsClassify> gqlGoodsClassifies = GoodsClassifyMapper.MAPPER.toGoodsClassifyList(list);
......
......@@ -28,23 +28,23 @@ public class GoodsManageListFetcher implements DataFetcher {
public Object get(DataFetchingEnvironment env) throws Exception {
// + schoolId
String hql = "from GoodsManage";
String hql = "from GoodsManage 1=1 ";
GQLPageParam page = EnvArgsMapper.MAPPER.fromArgs(env);
if(env.containsArgument("condition")) {
HashMap<String,Object> map = ObjectToMap.to(env.getArgument("condition"));
if(map.get("id")!=null) {
hql += "and id " + Util.decide(map.get("id"));
hql += " and id " + Util.decide(map.get("id"));
}
if(map.get("goods_name")!=null) {
hql += "and goods_name " + Util.decide(map.get("goods_name"));
hql += " and goods_name " + Util.decide("like_" +map.get("goods_name"));
}
if(map.get("good_status")!=null) {
hql += "and good_status " + Util.decide(map.get("good_status"));
hql += " and good_status " + Util.decide(map.get("good_status"));
}
}
hql += " ORDER BY created_at DESC ";
List<GoodsManage> list = goodsManageDao.find(hql,null,page.getPage(),page.getLimit());
List<GQLGoodsManage> gqlGoodsClassifies = GoodsManageMapper.MAPPER.toGoodsManageList(list);
......
package com.orhon.smartcampus.material.modules.management.fetcher;
import com.orhon.smartcampus.material.modules.management.mutation.AddFloorMutation;
import com.orhon.smartcampus.material.modules.management.mutation.AddGoodsClassifyMutation;
import com.orhon.smartcampus.material.modules.management.mutation.AddRoomMutation;
import com.orhon.smartcampus.material.modules.management.mutation.AddRootSiteMutation;
import com.orhon.smartcampus.material.modules.management.mutation.*;
import graphql.schema.idl.RuntimeWiring;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
......@@ -24,9 +21,15 @@ public class MaterialFetchersLoader {
GoodsManageListFetcher goodsManageListFetcher;
@Autowired
AddGoodsManageMutation addGoodsManageMutation;
@Autowired
BuildingsListFetcher buildingsListFetcher;
@Autowired
AddBuildingsMutation addBuildingsMutation;
@Autowired
AddRootSiteMutation addRootSiteMutation;
@Autowired
......@@ -52,6 +55,12 @@ public class MaterialFetchersLoader {
@Autowired
SeleFloorListFetcher seleFloorListFetcher;
@Autowired
AddUnitMutation addUnitMutation;
@Autowired
UnitListFetcher unitListFetcher;
public void LoadFetchers(RuntimeWiring.Builder builder){
......@@ -65,14 +74,17 @@ public class MaterialFetchersLoader {
builder.type("Query" , t->t.dataFetcher("SeleRooms" , seleRoomListFetcher));
builder.type("Query" , t->t.dataFetcher("SeleFloor" , seleFloorOnceFetcher));
builder.type("Query" , t->t.dataFetcher("SeleFloors" , seleFloorListFetcher));
builder.type("Query" , t->t.dataFetcher("UnitList" , unitListFetcher));
builder.type("Mutation" , t->t.dataFetcher("addMaterialRoomAdds" , addRoomMutation));
builder.type("Mutation" , t->t.dataFetcher("addMaterialSiteAdds" , addRootSiteMutation));
builder.type("Mutation" , t->t.dataFetcher("addGoodsClassify" , addGoodsClassifyMutation));
builder.type("Mutation" , t->t.dataFetcher("addMaterialFloorAdds" , addFloorMutation));
builder.type("Mutation" , t->t.dataFetcher("addGoodsClassify" , addGoodsClassifyMutation));
builder.type("Mutation" , t->t.dataFetcher("addGoodsManage" , goodsManageListFetcher));
builder.type("Mutation" , t->t.dataFetcher("addBuildings" , buildingsListFetcher));
builder.type("Mutation" , t->t.dataFetcher("addGoodsManage" , addGoodsManageMutation));
builder.type("Mutation" , t->t.dataFetcher("addBuildings" , addBuildingsMutation));
builder.type("Mutation" , t->t.dataFetcher("addUnit" , addUnitMutation));
}
......
......@@ -31,23 +31,23 @@ public class SeleFloorListFetcher implements DataFetcher {
public Object get(DataFetchingEnvironment env) throws Exception {
// + schoolId
String hql = "from FloorEntity";
String hql = "from FloorEntity 1=1 ";
GQLPageParam page = EnvArgsMapper.MAPPER.fromArgs(env);
if(env.containsArgument("condition")) {
HashMap<String,Object> map = ObjectToMap.to(env.getArgument("condition"));
if(map.get("id")!=null) {
hql += "and id " + Util.decide(map.get("id"));
hql += " and id " + Util.decide(map.get("id"));
}
if(map.get("floor_name")!=null) {
hql += "and floor_name " + Util.decide(map.get("unit_id"));
hql += " and floor_name " + Util.decide("like_" +map.get("floor_name"));
}
if(map.get("floor_status")!=null) {
hql += "and floor_status " + Util.decide(map.get("floor_number"));
hql += " and floor_status " + Util.decide(map.get("floor_status"));
}
}
hql += " ORDER BY created_at DESC ";
List<FloorEntity> list = floorDao.find(hql,null,page.getPage(),page.getLimit());
......
......@@ -31,23 +31,23 @@ public class SeleRoomListFetcher implements DataFetcher {
public Object get(DataFetchingEnvironment env) throws Exception {
// + schoolId
String hql = "from RoomEntity";
String hql = "from RoomEntity 1=1 ";
GQLPageParam page = EnvArgsMapper.MAPPER.fromArgs(env);
if(env.containsArgument("condition")) {
HashMap<String,Object> map = ObjectToMap.to(env.getArgument("condition"));
if(map.get("id")!=null) {
hql += "and id " + Util.decide(map.get("id"));
hql += " and id " + Util.decide(map.get("id"));
}
if(map.get("room_name")!=null) {
hql += "and room_name " + Util.decide(map.get("unit_id"));
hql += " and room_name " + Util.decide("like_" +map.get("room_name"));
}
if(map.get("room_status")!=null) {
hql += "and room_status " + Util.decide(map.get("room_head"));
hql += " and room_status " + Util.decide(map.get("room_status"));
}
}
hql += " ORDER BY created_at DESC ";
List<RoomEntity> list = roomDao.find(hql,null,page.getPage(),page.getLimit());
List<RoomGqlModel> gqlGoodsClassifies = RoomMapper.MAPPER.toRoomList(list);
......
......@@ -32,23 +32,23 @@ public class SiteListFetcher implements DataFetcher {
public Object get(DataFetchingEnvironment env) throws Exception {
// + schoolId
String hql = "from RootEntity";
String hql = "from RootEntity 1=1 ";
GQLPageParam page = EnvArgsMapper.MAPPER.fromArgs(env);
if(env.containsArgument("condition")) {
HashMap<String,Object> map = ObjectToMap.to(env.getArgument("condition"));
if(map.get("id")!=null) {
hql += "and id " + Util.decide(map.get("id"));
hql += " and id " + Util.decide(map.get("id"));
}
if(map.get("site_name")!=null) {
hql += "and site_name " + Util.decide(map.get("site_name"));
hql += " and site_name " + Util.decide("like_" +map.get("site_name"));
}
if(map.get("site_status")!=null) {
hql += "and site_status " + Util.decide(map.get("site_status"));
hql += " and site_status " + Util.decide(map.get("site_status"));
}
}
hql += " ORDER BY created_at DESC ";
List<RootEntity> list = rootDao.find(hql,null,page.getPage(),page.getLimit());
// GQLGoodsClassify gqlGoodsClassify = null;
......
......@@ -27,23 +27,23 @@ public class UnitListFetcher implements DataFetcher {
public Object get(DataFetchingEnvironment env) throws Exception {
// + schoolId
String hql = "from Unit";
String hql = "from Unit 1=1 ";
GQLPageParam page = EnvArgsMapper.MAPPER.fromArgs(env);
if (env.containsArgument("condition")) {
HashMap<String, Object> map = ObjectToMap.to(env.getArgument("condition"));
if (map.get("id") != null) {
hql += "and id " + Util.decide(map.get("id"));
hql += " and id " + Util.decide(map.get("id"));
}
if (map.get("building_id") != null) {
hql += "and building_id " + Util.decide(map.get("building_id"));
hql += " and unit_name " + Util.decide("like_" +map.get("unit_name"));
}
if (map.get("floor_status") != null) {
hql += "and floor_status " + Util.decide(map.get("floor_status"));
hql += " and unit_status " + Util.decide(map.get("unit_status"));
}
}
hql += " ORDER BY created_at DESC ";
List<Unit> list = unitDao.find(hql, null, page.getPage(), page.getLimit());
List<GQLUnit> gqlGoodsClassifies = UnitMapper.MAPPER.toUnitList(list);
......
......@@ -14,7 +14,7 @@ public class GQLGoodsManageInput {
private String goods_number;
private Integer goods_stock;
private String goods_note;
private Integer good_status;
private Integer goods_status;
private String add_id;
private String employ_time;
private String employ_department;
......
......@@ -14,7 +14,7 @@ public class GQLRootInput {
private Long id;
private Integer parent_id;
private String site_name;
private String site_status;
private Integer site_status;
private Integer sort_order;
private String school_id;
private String add_id;
......
......@@ -9,7 +9,7 @@ public class GQLUnitInput {
private Integer building_id;
private String unit_name;
private String unit_head;
private String floor_status;
private Integer unit_status;
private Integer floor_start;
private Integer floor_end;
private String add_id;
......
......@@ -19,7 +19,7 @@ public class GQLGoodsManage {
private String goods_number;
private Integer goods_stock;
private String goods_note;
private Integer good_status;
private Integer goods_status;
private String add_id;
private String employ_time;
private String employ_department;
......
......@@ -9,7 +9,7 @@ public class GQLRootBeans {
private Long id;
private Integer parent_id;
private String site_name;
private String site_status;
private Integer site_status;
private Integer sort_order;
private String school_id;
private String add_id;
......
......@@ -10,7 +10,7 @@ public class GQLUnit {
private Integer building_id;
private String unit_name;
private String unit_head;
private String floor_status;
private Integer unit_status;
private Integer floor_start;
private Integer floor_end;
private String add_id;
......
......@@ -31,6 +31,6 @@ public interface RootBeanMapper {
// @Mapping(source = "updated_at" , target = "updated_at")
GQLRootBeans toRootsClassify(RootEntity entity);
@InheritConfiguration(name = "toGoodsClassify")
@InheritConfiguration(name = "toRootList")
List<GQLRootBeans> toRootList(List<RootEntity> entities);
}
......@@ -31,6 +31,6 @@ public interface UnitMapper {
// @Mapping(source = "updated_at" , target = "updated_at")
GQLGoodsClassify toGoodsClassify(GoodsClassify entity);
@InheritConfiguration(name = "toUnit")
@InheritConfiguration(name = "toUnitList")
List<GQLUnit> toUnitList(List<Unit> entities);
}
package com.orhon.smartcampus.material.modules.management.mutation;
import com.orhon.smartcampus.material.basicComponents.Result;
import com.orhon.smartcampus.material.modules.base.gqlModel.GQLPageParam;
import com.orhon.smartcampus.material.modules.base.mm.EnvArgsMapper;
import com.orhon.smartcampus.material.modules.base.user.TokenService;
import com.orhon.smartcampus.material.modules.management.dao.BuildingsDao;
import com.orhon.smartcampus.material.modules.management.dao.GoodsManageDao;
import com.orhon.smartcampus.material.modules.management.entity.Buildings;
import com.orhon.smartcampus.material.modules.management.entity.GoodsManage;
import com.orhon.smartcampus.material.modules.management.gqlInputModel.GQLBuildingsInput;
import com.orhon.smartcampus.material.modules.management.gqlInputModel.GQLGoodsManageInput;
import com.orhon.smartcampus.material.modules.management.inputMapper.BuildingsInputMapper;
import com.orhon.smartcampus.material.modules.management.inputMapper.GoodsManageInputMapper;
import com.orhon.smartcampus.material.auth.JwtUtils;
import com.orhon.smartcampus.material.utils.QuerCount;
import graphql.schema.DataFetcher;
import graphql.schema.DataFetchingEnvironment;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -23,6 +24,9 @@ public class AddBuildingsMutation implements DataFetcher {
@Autowired
BuildingsDao buildingsDao;
@Autowired
TokenService tokenService;
/**
* 楼层管理
* editor : ths
......@@ -30,7 +34,9 @@ public class AddBuildingsMutation implements DataFetcher {
@Override
public Object get(DataFetchingEnvironment environment) throws Exception {
//String token = (String) SecurityUtils.getSubject().getPrincipal();
String token = tokenService.getSystemToken();
Long schoolId = JwtUtils.getSchoolId(token);
Long userId = JwtUtils.getUserId(token);
GQLBuildingsInput input = BuildingsInputMapper.MAPPER.mapInput(environment.getArgument("inputData"));
......@@ -40,6 +46,11 @@ public class AddBuildingsMutation implements DataFetcher {
buildings = buildingsDao.get(Buildings.class, input.getId());
buildings.setUpdated_at(new Date());
} else {
String hql = "SELECT buildings_name FROM Buildings where buildings_name = " + "'" + input.getBuildings_name() + "'";
int size = buildingsDao.find(hql).size();
if (size > 0){
return Result.error("楼宇名称重复");
}
buildings = new Buildings();
buildings.setCreated_at(new Date());
}
......@@ -62,7 +73,7 @@ public class AddBuildingsMutation implements DataFetcher {
buildings.setBuildings_status(input.getBuildings_status());
}
if(input.getAdd_id() != null){
buildings.setAdd_id(input.getAdd_id());
buildings.setAdd_id(String.valueOf(userId));
}
try {
buildingsDao.saveOrUpdate(buildings);
......
package com.orhon.smartcampus.material.modules.management.mutation;
import com.orhon.smartcampus.material.auth.JwtUtils;
import com.orhon.smartcampus.material.basicComponents.Result;
import com.orhon.smartcampus.material.modules.base.user.TokenService;
import com.orhon.smartcampus.material.modules.management.dao.FloorDao;
import com.orhon.smartcampus.material.modules.management.dao.RoomDao;
import com.orhon.smartcampus.material.modules.management.entity.FloorEntity;
......@@ -23,6 +25,8 @@ public class AddFloorMutation implements DataFetcher {
@Autowired
FloorDao floorDao;
@Autowired
TokenService tokenService;
/**
* Room管理添加
* editor : ths
......@@ -30,16 +34,25 @@ public class AddFloorMutation implements DataFetcher {
@Override
public Object get(DataFetchingEnvironment environment) throws Exception {
//String token = (String) SecurityUtils.getSubject().getPrincipal();
String token = tokenService.getSystemToken();
Long schoolId = JwtUtils.getSchoolId(token);
Long userId = JwtUtils.getUserId(token);
GQLFloorInput input = FloomInputMapper.MAPPER.mapInput(environment.getArgument("inputData"));
FloorEntity roomEntity = null;
if (input.getId() != null) {
roomEntity = floorDao.get(FloorEntity.class, input.getId());
roomEntity.setUpdated_at(new Date());
} else {
String hql = "SELECT floor_name FROM FloorEntity where floor_name = " + "'" + input.getFloor_name() + "'";
int size = floorDao.find(hql).size();
if (size > 0){
return Result.error("楼层名称重复");
}
roomEntity = new FloorEntity();
roomEntity.setCreated_at(new Date());
}
......@@ -56,7 +69,7 @@ public class AddFloorMutation implements DataFetcher {
roomEntity.setFloor_status(input.getFloor_status());
}
if(input.getAdd_id() != null){
roomEntity.setAdd_id(input.getAdd_id());
roomEntity.setAdd_id(String.valueOf(userId));
}
try {
floorDao.saveOrUpdate(roomEntity);
......
package com.orhon.smartcampus.material.modules.management.mutation;
import com.alibaba.fastjson.JSON;
import com.orhon.smartcampus.material.auth.JwtUtils;
import com.orhon.smartcampus.material.basicComponents.Result;
import com.orhon.smartcampus.material.modules.base.user.TokenService;
import com.orhon.smartcampus.material.modules.management.dao.GoodsClassifyDao;
import com.orhon.smartcampus.material.modules.management.entity.GoodsClassify;
import com.orhon.smartcampus.material.modules.management.gqlInputModel.GQLFloorInput;
import com.orhon.smartcampus.material.modules.management.gqlInputModel.GQLGoodsClassifyInput;
import com.orhon.smartcampus.material.modules.management.inputMapper.FloomInputMapper;
import com.orhon.smartcampus.material.modules.management.inputMapper.GoodsClassifyInputMapper;
import graphql.schema.DataFetcher;
import graphql.schema.DataFetchingEnvironment;
......@@ -20,6 +24,8 @@ public class AddGoodsClassifyMutation implements DataFetcher {
@Autowired
GoodsClassifyDao goodsClassifyDao;
@Autowired
TokenService tokenService;
/**
* 楼层管理
* editor : ths
......@@ -27,16 +33,24 @@ public class AddGoodsClassifyMutation implements DataFetcher {
@Override
public Object get(DataFetchingEnvironment environment) throws Exception {
//String token = (String) SecurityUtils.getSubject().getPrincipal();
String token = tokenService.getSystemToken();
Long schoolId = JwtUtils.getSchoolId(token);
Long userId = JwtUtils.getUserId(token);
GQLGoodsClassifyInput input = GoodsClassifyInputMapper.MAPPER.mapInput(environment.getArgument("inputData"));
GoodsClassify goodsClassify = null;
if (input.getId() != null) {
goodsClassify = goodsClassifyDao.get(GoodsClassify.class, input.getId());
goodsClassify.setUpdated_at(new Date());
} else {
String hql = "SELECT classify_name FROM GoodsClassify where classify_name = " + "'" + input.getClassify_name() + "'";
int size = goodsClassifyDao.find(hql).size();
if (size > 0){
return Result.error("分类名称重复");
}
goodsClassify = new GoodsClassify();
goodsClassify.setCreated_at(new Date());
}
......@@ -53,10 +67,10 @@ public class AddGoodsClassifyMutation implements DataFetcher {
goodsClassify.setSort_order(input.getSort_order());
}
if(input.getSchool_id() != null){
goodsClassify.setSchool_id(input.getSchool_id());
goodsClassify.setSchool_id(String.valueOf(schoolId));
}
if(input.getAdd_id() != null){
goodsClassify.setAdd_id(JSON.toJSONString(input.getAdd_id()));
goodsClassify.setAdd_id(String.valueOf(userId));
}
try {
goodsClassifyDao.saveOrUpdate(goodsClassify);
......
package com.orhon.smartcampus.material.modules.management.mutation;
import com.alibaba.fastjson.JSON;
import com.orhon.smartcampus.material.auth.JwtUtils;
import com.orhon.smartcampus.material.basicComponents.Result;
import com.orhon.smartcampus.material.modules.base.user.TokenService;
import com.orhon.smartcampus.material.modules.management.dao.GoodsClassifyDao;
import com.orhon.smartcampus.material.modules.management.dao.GoodsManageDao;
import com.orhon.smartcampus.material.modules.management.entity.GoodsClassify;
......@@ -24,6 +26,8 @@ public class AddGoodsManageMutation implements DataFetcher {
@Autowired
GoodsManageDao goodsManageDao;
@Autowired
TokenService tokenService;
/**
* 楼层管理
* editor : ths
......@@ -31,16 +35,24 @@ public class AddGoodsManageMutation implements DataFetcher {
@Override
public Object get(DataFetchingEnvironment environment) throws Exception {
//String token = (String) SecurityUtils.getSubject().getPrincipal();
String token = tokenService.getSystemToken();
Long schoolId = JwtUtils.getSchoolId(token);
Long userId = JwtUtils.getUserId(token);
GQLGoodsManageInput input = GoodsManageInputMapper.MAPPER.mapInput(environment.getArgument("inputData"));
GoodsManage goodsManage = null;
if (input.getId() != null) {
goodsManage = goodsManageDao.get(GoodsManage.class, input.getId());
goodsManage.setUpdated_at(new Date());
} else {
String hql = "SELECT goods_name FROM GoodsManage where goods_name = " + "'" + input.getGoods_name() + "'";
int size = goodsManageDao.find(hql).size();
if (size > 0){
return Result.error("物品名称重复");
}
goodsManage = new GoodsManage();
goodsManage.setCreated_at(new Date());
}
......@@ -53,6 +65,9 @@ public class AddGoodsManageMutation implements DataFetcher {
if(input.getMain_image() != null){
goodsManage.setMain_image(input.getMain_image());
}
if(input.getSub_images() != null){
goodsManage.setSub_images(input.getSub_images());
}
if(input.getGoods_price() != null){
goodsManage.setGoods_price(input.getGoods_price());
}
......@@ -60,16 +75,16 @@ public class AddGoodsManageMutation implements DataFetcher {
goodsManage.setGoods_number(input.getGoods_number());
}
if(input.getGoods_stock() != null){
goodsManage.setGoods_price(input.getGoods_price());
goodsManage.setGoods_stock(input.getGoods_stock());
}
if(input.getGoods_note() != null){
goodsManage.setGoods_note(input.getGoods_note());
}
if(input.getGood_status() != null){
goodsManage.setGood_status(input.getGood_status());
if(input.getGoods_status() != null){
goodsManage.setGoods_status(input.getGoods_status());
}
if(input.getAdd_id() != null){
goodsManage.setAdd_id(input.getAdd_id());
goodsManage.setAdd_id(String.valueOf(userId));
}
if(input.getEmploy_time() != null){
goodsManage.setEmploy_time(input.getEmploy_time());
......
package com.orhon.smartcampus.material.modules.management.mutation;
import com.alibaba.fastjson.JSON;
import com.orhon.smartcampus.material.auth.JwtUtils;
import com.orhon.smartcampus.material.basicComponents.Result;
import com.orhon.smartcampus.material.modules.base.user.TokenService;
import com.orhon.smartcampus.material.modules.management.dao.GoodsClassifyDao;
import com.orhon.smartcampus.material.modules.management.dao.RoomDao;
import com.orhon.smartcampus.material.modules.management.entity.GoodsClassify;
......@@ -24,6 +26,8 @@ public class AddRoomMutation implements DataFetcher {
@Autowired
RoomDao roomDao;
@Autowired
TokenService tokenService;
/**
* Room管理添加
* editor : ths
......@@ -31,7 +35,9 @@ public class AddRoomMutation implements DataFetcher {
@Override
public Object get(DataFetchingEnvironment environment) throws Exception {
//String token = (String) SecurityUtils.getSubject().getPrincipal();
String token = tokenService.getSystemToken();
Long schoolId = JwtUtils.getSchoolId(token);
Long userId = JwtUtils.getUserId(token);
GQLRoomInput input = RoomInputMapper.MAPPER.mapInput(environment.getArgument("inputData"));
......@@ -41,6 +47,11 @@ public class AddRoomMutation implements DataFetcher {
roomEntity = roomDao.get(RoomEntity.class, input.getId());
roomEntity.setUpdated_at(new Date());
} else {
String hql = "SELECT room_name FROM RoomEntity where room_name = " + "'" + input.getRoom_name() + "'";
int size = roomDao.find(hql).size();
if (size > 0){
return Result.error("房间名称重复");
}
roomEntity = new RoomEntity();
roomEntity.setCreated_at(new Date());
}
......@@ -63,7 +74,7 @@ public class AddRoomMutation implements DataFetcher {
roomEntity.setRoom_status(input.getRoom_status());
}
if(input.getAdd_id() != null){
roomEntity.setAdd_id(input.getAdd_id());
roomEntity.setAdd_id(String.valueOf(userId));
}
try {
roomDao.saveOrUpdate(roomEntity);
......
package com.orhon.smartcampus.material.modules.management.mutation;
import com.alibaba.fastjson.JSON;
import com.orhon.smartcampus.material.auth.JwtUtils;
import com.orhon.smartcampus.material.basicComponents.Result;
import com.orhon.smartcampus.material.modules.base.user.TokenService;
import com.orhon.smartcampus.material.modules.management.dao.GoodsClassifyDao;
import com.orhon.smartcampus.material.modules.management.dao.RootDao;
import com.orhon.smartcampus.material.modules.management.entity.GoodsClassify;
import com.orhon.smartcampus.material.modules.management.entity.RootEntity;
import com.orhon.smartcampus.material.modules.management.gqlInputModel.GQLGoodsClassifyInput;
import com.orhon.smartcampus.material.modules.management.gqlInputModel.GQLRoomInput;
import com.orhon.smartcampus.material.modules.management.gqlInputModel.GQLRootInput;
import com.orhon.smartcampus.material.modules.management.gqlModel.GQLRootBeans;
import com.orhon.smartcampus.material.modules.management.inputMapper.GoodsClassifyInputMapper;
import com.orhon.smartcampus.material.modules.management.inputMapper.RoomInputMapper;
import com.orhon.smartcampus.material.modules.management.inputMapper.RootInputMapper;
import com.orhon.smartcampus.material.utils.ObjectToMap;
import com.orhon.smartcampus.material.utils.Util;
......@@ -29,6 +33,8 @@ public class AddRootSiteMutation implements DataFetcher {
@Autowired
RootDao rootDao;
@Autowired
TokenService tokenService;
/**
* 楼层管理
* editor : ths
......@@ -77,14 +83,25 @@ public class AddRootSiteMutation implements DataFetcher {
// } catch (Exception e) {
// return Result.error(500, "" + e);
// }
String token = tokenService.getSystemToken();
Long schoolId = JwtUtils.getSchoolId(token);
Long userId = JwtUtils.getUserId(token);
GQLRootBeans input = RootInputMapper.MAPPER.mapInput(environment.getArgument("inputData"));
RootEntity rootEntity = null;
if (input.getId() != null) {
rootEntity = rootDao.get(RootEntity.class, input.getId());
rootEntity.setUpdated_at(new Date());
} else {
String hql = "SELECT site_name FROM RootEntity where site_name = " + "'" + input.getSite_name() + "'";
int size = rootDao.find(hql).size();
if (size > 0){
return Result.error("场地分类名称重复");
}
rootEntity = new RootEntity();
rootEntity.setCreated_at(new Date());
}
......@@ -101,10 +118,10 @@ public class AddRootSiteMutation implements DataFetcher {
rootEntity.setSort_order(input.getSort_order());
}
if(input.getSchool_id() != null){
rootEntity.setSchool_id(input.getSchool_id());
rootEntity.setSchool_id(String.valueOf(schoolId));
}
if(input.getAdd_id() != null){
rootEntity.setAdd_id(JSON.toJSONString(input.getAdd_id()));
rootEntity.setAdd_id(String.valueOf(userId));
}
try {
rootDao.saveOrUpdate(rootEntity);
......
package com.orhon.smartcampus.material.modules.management.mutation;
import com.orhon.smartcampus.material.auth.JwtUtils;
import com.orhon.smartcampus.material.basicComponents.Result;
import com.orhon.smartcampus.material.modules.base.user.TokenService;
import com.orhon.smartcampus.material.modules.management.dao.BuildingsDao;
import com.orhon.smartcampus.material.modules.management.dao.UnitDao;
import com.orhon.smartcampus.material.modules.management.entity.Buildings;
......@@ -23,6 +25,8 @@ public class AddUnitMutation implements DataFetcher {
@Autowired
UnitDao unitDao;
@Autowired
TokenService tokenService;
/**
* 楼层管理
* editor : ths
......@@ -30,7 +34,9 @@ public class AddUnitMutation implements DataFetcher {
@Override
public Object get(DataFetchingEnvironment environment) throws Exception {
//String token = (String) SecurityUtils.getSubject().getPrincipal();
String token = tokenService.getSystemToken();
Long schoolId = JwtUtils.getSchoolId(token);
Long userId = JwtUtils.getUserId(token);
GQLUnitInput input = UnitInputMapper.MAPPER.mapInput(environment.getArgument("inputData"));
......@@ -40,17 +46,25 @@ public class AddUnitMutation implements DataFetcher {
unit = unitDao.get(Unit.class, input.getId());
unit.setUpdated_at(new Date());
} else {
String hql = "SELECT unit_name FROM Unit where unit_name = " + "'" + input.getUnit_name() + "'";
int size = unitDao.find(hql).size();
if (size > 0){
return Result.error("场地分类名称重复");
}
unit = new Unit();
unit.setCreated_at(new Date());
}
if(input.getBuilding_id() != null){
unit.setBuilding_id(input.getBuilding_id());
}
if(input.getUnit_head() != null){
unit.setUnit_head(input.getUnit_head());
}
if(input.getUnit_name() != null){
unit.setUnit_name(input.getUnit_name());
}
if(input.getFloor_status() != null){
unit.setFloor_status(input.getFloor_status());
if(input.getUnit_status() != null){
unit.setUnit_status(input.getUnit_status());
}
if(input.getFloor_start()!= null){
unit.setFloor_start(input.getFloor_start());
......@@ -59,7 +73,7 @@ public class AddUnitMutation implements DataFetcher {
unit.setFloor_end(input.getFloor_end());
}
if(input.getAdd_id() != null){
unit.setAdd_id(input.getAdd_id());
unit.setAdd_id(String.valueOf(userId));
}
try {
unitDao.saveOrUpdate(unit);
......
package com.orhon.smartcampus.material.utils;
import com.orhon.smartcampus.material.basicComponents.baseDao.BaseDao;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate4.HibernateCallback;
import org.springframework.orm.hibernate4.HibernateTemplate;
import java.util.Collection;
import java.util.List;
import java.util.Map;
public class QuerCount {
@Autowired
private HibernateTemplate hibernateTemplate;
public List CountSize(final String hql, final Map<String, Object> param, final int pageNo,
final int pageSize){
hibernateTemplate.execute(new HibernateCallback<List>() {
@Override
public List doInHibernate(Session session) throws HibernateException {
String shql = hql;
if (pageNo == 0 && pageSize!=0) {
String sql = "select count(e) ";
shql = sql + hql;
}
Query query = session.createQuery(shql);
if (param != null && param.size() > 0) {
for (String property : param.keySet()) {
if (param.get(property) instanceof List){
query.setParameterList(property, (Collection)param.get(property));
}else{
query.setParameter(property,
param.get(property));
}
}
}
List list = null;
if (pageNo != 0 && pageSize != 0) {
query.setFirstResult((pageNo - 1) * pageSize);
query.setMaxResults(pageSize);
}
try{
list = query.list();
}catch (HibernateException e) {
e.printStackTrace();
throw e;
}
return list;
}
});
return null;
}
}
package com.orhon.smartcampus.material.utils;
import java.util.HashMap;
import java.util.Map;
/**
* 返回数据
*
* @author bao
* @email
* @date 2019年06月26日 下午9:59:27
*/
public class R extends HashMap<String, Object> {
private static final long serialVersionUID = 1L;
public R() {
put("code", 200);
put("msg", "success");
}
public static R error() {
return error(500, "未知异常,请联系管理员");
}
public static R NoLogin() {
return error(501, "登陆信息过期,请您重新登陆");
}
public static R error(String msg) {
return error(500, msg);
}
public static R error(int code, String msg) {
R r = new R();
r.put("code", code);
r.put("msg", msg);
return r;
}
public static R ok(String msg) {
R r = new R();
r.put("msg", msg);
return r;
}
public static R ok(Map<String, Object> map) {
R r = new R();
r.putAll(map);
return r;
}
public static R ok() {
return new R();
}
public static R timeOut() {
R r = new R();
r.put("code", 10000);
r.put("msg", "修改超时");
return r;
}
public static R parameterIsNul() {
R r = new R();
r.put("code", 10001);
r.put("msg", "参数为空");
return r;
}
public static R Repeat() {
R r = new R();
r.put("msg", "重复提交");
return r;
}
public R put(String key, Object value) {
if(value==null) {
Object object = new Object();
super.put(key, object);
return this;
}
super.put(key, value);
return this;
}
}
......@@ -5,7 +5,7 @@ server:
uri-encoding: UTF-8
max-threads: 1000
min-spare-threads: 30
port: 8031
port: 8088
connection-timeout: 5000
spring:
......
......@@ -59,7 +59,7 @@ type GoodsManage {
"物品备注"
goods_note:String
"物品状态"
good_status:Int
goods_status:Int
"添加人"
add_id:String
"使用期限"
......@@ -80,7 +80,7 @@ input GoodsManageInput {
goods_number:String
goods_stock:Int
goods_note:String
good_status:Int
goods_status:Int
add_id:String
employ_time:String
employ_department:String
......@@ -148,7 +148,7 @@ type Unit {
"单元负责人"
unit_head:String
"单元状态"
unit_status:String
unit_status:Int
"楼层区间开始"
floor_start:Int
"楼层区间结束"
......@@ -164,7 +164,7 @@ input UnitInput {
building_id:Int
unit_name:String
unit_head:String
floor_status:String
unit_status:Int
floor_start:Int
floor_end:Int
add_id:String
......@@ -173,7 +173,7 @@ input UnitInput {
input UnitCondition {
id:Int
unit_name:String
buildings_status:Int
unit_status:Int
}
type UnitResponse {
......
......@@ -2,7 +2,7 @@ input MaterialSiteAdd{
id:Int
parent_id:Int
site_name:String
site_status:String
site_status:Int
sort_order:Int
school_id:String
add_id:String
......@@ -21,7 +21,7 @@ type MaterialSiteBean{
"场地名称"
site_name:String
"场地状态"
site_status:String
site_status:Int
"排序"
sort_order:Int
"学校ID"
......@@ -37,7 +37,7 @@ type MaterialSiteResultType{
id:Int
parent_id:Int
site_name:String
site_status:String
site_status:Int
sort_order:Int
school_id:String
add_id:String
......
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