Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
cloud-fb
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
王衍超
cloud-fb
Commits
4de6e88b
Commit
4de6e88b
authored
Apr 13, 2021
by
shiwenbo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加数据字典通用查询接口
parent
63b08784
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
616 additions
and
0 deletions
+616
-0
DinasCommonConfiguration.java
...a/com/xyst/dinas/biz/config/DinasCommonConfiguration.java
+12
-0
SandDictController.java
.../main/java/com/xyst/dinas/biz/web/SandDictController.java
+302
-0
WarehouseDictController.java
.../java/com/xyst/dinas/biz/web/WarehouseDictController.java
+302
-0
No files found.
backend/xyst.dinas.biz/src/main/java/com/xyst/dinas/biz/config/DinasCommonConfiguration.java
View file @
4de6e88b
...
@@ -7,7 +7,9 @@ import com.xyst.dinas.biz.internal.dao.PlanningCycleDao;
...
@@ -7,7 +7,9 @@ import com.xyst.dinas.biz.internal.dao.PlanningCycleDao;
import
com.xyst.dinas.biz.internal.service.PlanningCycleServiceImpl
;
import
com.xyst.dinas.biz.internal.service.PlanningCycleServiceImpl
;
import
com.xyst.dinas.biz.service.PlanningCycleService
;
import
com.xyst.dinas.biz.service.PlanningCycleService
;
import
com.xyst.dinas.biz.web.DinasCommonController
;
import
com.xyst.dinas.biz.web.DinasCommonController
;
import
com.xyst.dinas.biz.web.SandDictController
;
import
com.xyst.dinas.biz.web.SandQueryController
;
import
com.xyst.dinas.biz.web.SandQueryController
;
import
com.xyst.dinas.biz.web.WarehouseDictController
;
import
com.xyst.dinas.biz.web.WarehouseQueryController
;
import
com.xyst.dinas.biz.web.WarehouseQueryController
;
@Configuration
@Configuration
...
@@ -28,6 +30,16 @@ public class DinasCommonConfiguration {
...
@@ -28,6 +30,16 @@ public class DinasCommonConfiguration {
return
new
SandQueryController
();
return
new
SandQueryController
();
}
}
@Bean
public
WarehouseDictController
warehouseDictController
()
{
return
new
WarehouseDictController
();
}
@Bean
public
SandDictController
sandDictController
()
{
return
new
SandDictController
();
}
/***************计划周期 ************/
/***************计划周期 ************/
@Bean
@Bean
...
...
backend/xyst.dinas.biz/src/main/java/com/xyst/dinas/biz/web/SandDictController.java
0 → 100644
View file @
4de6e88b
package
com
.
xyst
.
dinas
.
biz
.
web
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.UUID
;
import
javax.servlet.http.HttpServletResponse
;
import
org.json.JSONArray
;
import
org.json.JSONObject
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
com.beecode.amino.common.Convert
;
import
com.beecode.amino.core.Amino
;
import
com.beecode.bcp.dict.Dict
;
import
com.beecode.bcp.dict.DictAcions
;
import
com.beecode.bcp.dict.DictConstants
;
import
com.beecode.bcp.dict.DictExclude
;
import
com.beecode.bcp.dict.model.Page
;
import
com.beecode.bcp.dict.service.DictService
;
import
com.beecode.bcp.type.KObject
;
import
com.beecode.bcp.type.json.JSONObjectUtils
;
@RestController
@RequestMapping
(
value
=
"/sand/user/dict"
)
public
class
SandDictController
{
@Autowired
private
DictService
dictService
;
@RequestMapping
(
value
=
"/add"
,
method
=
RequestMethod
.
POST
)
public
String
insertData
(
@RequestBody
String
content
,
HttpServletResponse
response
)
throws
Exception
{
JSONObject
object
=
new
JSONObject
(
content
);
String
dictName
=
object
.
getString
(
"dictname"
);
String
dictValue
=
""
;
if
(
object
.
get
(
"dictvalue"
)
!=
null
)
{
dictValue
=
object
.
get
(
"dictvalue"
).
toString
();
}
Dict
dict
=
Amino
.
getApplicationMetadataContext
().
getBean
(
dictName
,
Dict
.
class
);
try
{
if
(
dictValue
==
""
)
{
throw
new
RuntimeException
();
}
KObject
kObject
=
JSONObjectUtils
.
toObject
(
dictValue
,
dict
.
getKClass
());
return
dictService
.
create
(
dict
,
kObject
).
toString
();
}
catch
(
Exception
e
)
{
response
.
sendError
(
500
,
e
.
getMessage
());
return
null
;
}
}
@RequestMapping
(
value
=
"/delete"
,
method
=
RequestMethod
.
POST
)
public
void
deleteData
(
@RequestBody
String
content
,
HttpServletResponse
response
)
throws
Exception
{
JSONObject
object
=
new
JSONObject
(
content
);
String
dictName
=
object
.
getString
(
"dictname"
);
String
dictValue
=
""
;
if
(
object
.
get
(
"dictvalue"
)
!=
null
)
{
dictValue
=
object
.
get
(
"dictvalue"
).
toString
();
}
Dict
dict
=
Amino
.
getApplicationMetadataContext
().
getBean
(
dictName
,
Dict
.
class
);
try
{
if
(
dictValue
==
""
)
{
throw
new
RuntimeException
();
}
dictService
.
remove
(
dict
,
JSONObjectUtils
.
toObject
(
dictValue
,
dict
.
getKClass
()));
}
catch
(
Exception
e
)
{
response
.
sendError
(
500
,
e
.
getMessage
());
}
}
@RequestMapping
(
value
=
"/delete/byId"
,
method
=
RequestMethod
.
POST
)
public
void
deleteDataById
(
@RequestBody
String
content
,
HttpServletResponse
response
)
throws
Exception
{
JSONObject
object
=
new
JSONObject
(
content
);
String
dictName
=
object
.
getString
(
"dictname"
);
String
id
=
object
.
getString
(
"id"
);
Dict
dict
=
Amino
.
getApplicationMetadataContext
().
getBean
(
dictName
,
Dict
.
class
);
try
{
dictService
.
removeDictById
(
dict
,
Convert
.
toUUID
(
id
));
}
catch
(
Exception
e
)
{
response
.
sendError
(
500
,
e
.
getMessage
());
}
}
@RequestMapping
(
value
=
"/delete/batch"
,
method
=
RequestMethod
.
POST
)
public
void
deleteDataBatch
(
@RequestBody
String
content
,
HttpServletResponse
response
)
throws
Exception
{
JSONObject
object
=
new
JSONObject
(
content
);
String
dictName
=
object
.
getString
(
"dictname"
);
JSONArray
ids
=
object
.
getJSONArray
(
"ids"
);
Dict
dict
=
Amino
.
getApplicationMetadataContext
().
getBean
(
dictName
,
Dict
.
class
);
for
(
int
i
=
0
;
i
<
ids
.
length
();
i
++)
{
try
{
dictService
.
removeDictById
(
dict
,
Convert
.
toUUID
(
ids
.
get
(
i
)));
}
catch
(
Exception
e
)
{
response
.
sendError
(
500
,
e
.
getMessage
());
}
}
}
@RequestMapping
(
value
=
"/update"
,
method
=
RequestMethod
.
POST
)
public
void
updateData
(
@RequestBody
String
content
,
HttpServletResponse
response
)
throws
Exception
{
JSONObject
object
=
new
JSONObject
(
content
);
String
dictName
=
object
.
getString
(
"dictname"
);
Dict
dict
=
Amino
.
getApplicationMetadataContext
().
getBean
(
dictName
,
Dict
.
class
);
JSONArray
dictItems
=
object
.
getJSONArray
(
"dictvalue"
);
try
{
for
(
int
i
=
0
;
i
<
dictItems
.
length
();
i
++)
{
KObject
kObject
=
JSONObjectUtils
.
toObject
(
dictItems
.
get
(
i
).
toString
(),
dict
.
getKClass
());
dictService
.
modify
(
dict
,
kObject
);
}
}
catch
(
Exception
e
)
{
response
.
sendError
(
500
,
e
.
getMessage
());
}
}
@RequestMapping
(
value
=
"/changeState"
,
method
=
RequestMethod
.
POST
)
public
void
changeState
(
@RequestBody
String
content
,
HttpServletResponse
response
)
throws
Exception
{
JSONObject
object
=
new
JSONObject
(
content
);
String
dictName
=
object
.
getString
(
"dictname"
);
Dict
dict
=
Amino
.
getApplicationMetadataContext
().
getBean
(
dictName
,
Dict
.
class
);
JSONArray
dictItems
=
object
.
getJSONArray
(
"dictvalue"
);
try
{
for
(
int
i
=
0
;
i
<
dictItems
.
length
();
i
++)
{
KObject
kObject
=
JSONObjectUtils
.
toObject
(
dictItems
.
get
(
i
).
toString
(),
dict
.
getKClass
());
dictService
.
modify
(
dict
,
kObject
);
}
}
catch
(
Exception
e
)
{
response
.
sendError
(
500
,
e
.
getMessage
());
}
}
@RequestMapping
(
value
=
"/listAll"
,
method
=
RequestMethod
.
GET
)
public
List
<
KObject
>
getListAllData
(
@RequestParam
(
name
=
"dictname"
,
required
=
true
)
String
dictname
,
DictExclude
dictExclude
)
throws
Exception
{
Dict
dict
=
Amino
.
getApplicationMetadataContext
().
getBean
(
dictname
,
Dict
.
class
);
List
<
KObject
>
allData
=
dictService
.
listAllWithExclude
(
dict
,
dictExclude
);
return
allData
;
}
@RequestMapping
(
value
=
"/roots"
,
method
=
RequestMethod
.
GET
)
public
List
<
KObject
>
getListRoots
(
@RequestParam
(
name
=
"dictname"
,
required
=
true
)
String
dictname
,
DictExclude
dictExclude
)
throws
Exception
{
Dict
dict
=
Amino
.
getApplicationMetadataContext
().
getBean
(
dictname
,
Dict
.
class
);
List
<
KObject
>
allData
=
dictService
.
listRootsWithExclude
(
dict
,
dictExclude
);
return
allData
;
}
@RequestMapping
(
value
=
"/criteria"
,
method
=
RequestMethod
.
GET
)
public
Page
getListByCriteria
(
@RequestParam
(
name
=
"dictname"
,
required
=
true
)
String
dictname
,
@RequestParam
(
name
=
"pageNo"
,
required
=
false
)
Integer
pageNo
,
@RequestParam
(
name
=
"pageSize"
,
required
=
false
)
Integer
pageSize
,
@RequestParam
(
name
=
"keyword"
,
required
=
false
)
String
keyword
,
@RequestParam
(
name
=
"isOrder"
,
required
=
false
)
Boolean
isOrder
,
@RequestParam
(
name
=
"fields"
,
required
=
false
)
String
fields
,
@RequestParam
(
name
=
"startFlag"
,
required
=
false
)
Boolean
startFlag
)
throws
Exception
{
String
[]
fieldArray
=
null
;
if
(
fields
!=
null
)
{
fieldArray
=
fields
.
split
(
","
);
}
Dict
dict
=
Amino
.
getApplicationMetadataContext
().
getBean
(
dictname
,
Dict
.
class
);
return
dictService
.
listDictByPage
(
dict
,
pageNo
,
pageSize
,
fieldArray
,
keyword
,
isOrder
,
startFlag
);
}
@RequestMapping
(
value
=
"/parents/{id}"
,
method
=
RequestMethod
.
GET
)
public
List
<
KObject
>
getParentLink
(
@PathVariable
(
"id"
)
UUID
id
,
@RequestParam
(
name
=
"dictname"
,
required
=
true
)
String
dictname
)
{
Dict
dict
=
Amino
.
getApplicationMetadataContext
().
getBean
(
dictname
,
Dict
.
class
);
KObject
childDict
=
dictService
.
getDictById
(
dict
,
id
);
if
(
childDict
==
null
||
childDict
.
isEmpty
())
{
return
null
;
}
if
(!
childDict
.
getBoolean
(
"startFlag"
))
{
//已停用
return
null
;
}
return
dictService
.
getParentLink
(
childDict
,
dict
);
}
@RequestMapping
(
value
=
"/byChild"
,
method
=
RequestMethod
.
POST
)
public
String
getDataByChild
(
@RequestBody
String
content
)
throws
Exception
{
JSONObject
object
=
new
JSONObject
(
content
);
String
dictName
=
object
.
getString
(
"dictname"
);
String
childId
=
object
.
getString
(
"childId"
);
Dict
dict
=
Amino
.
getApplicationMetadataContext
().
getBean
(
dictName
,
Dict
.
class
);
return
JSONObjectUtils
.
toJson
(
dictService
.
getDictById
(
dict
,
Convert
.
toUUID
(
childId
))).
toString
();
}
@RequestMapping
(
value
=
"/item/{id}"
,
method
=
RequestMethod
.
GET
)
public
String
getDataById
(
@PathVariable
(
"id"
)
UUID
id
,
@RequestParam
(
name
=
"dictname"
,
required
=
true
)
String
dictname
)
{
Dict
dict
=
Amino
.
getApplicationMetadataContext
().
getBean
(
dictname
,
Dict
.
class
);
return
JSONObjectUtils
.
toJson
(
dictService
.
getDictById
(
dict
,
Convert
.
toUUID
(
id
))).
toString
();
}
@RequestMapping
(
value
=
"/parentIds/{id}"
,
method
=
RequestMethod
.
GET
)
public
List
<
UUID
>
getTree
(
@PathVariable
(
"id"
)
UUID
id
,
@RequestParam
(
name
=
"dictname"
,
required
=
true
)
String
dictname
)
{
Dict
dict
=
Amino
.
getApplicationMetadataContext
().
getBean
(
dictname
,
Dict
.
class
);
KObject
kObject
=
dictService
.
getDictById
(
dict
,
Convert
.
toUUID
(
id
));
if
(!
kObject
.
getBoolean
(
"startFlag"
))
{
return
null
;
}
UUID
parentId
=
kObject
.
getUuid
(
"parentId"
);
List
<
UUID
>
list
=
new
ArrayList
<
UUID
>();
list
.
add
(
id
);
while
(!
parentId
.
toString
().
equalsIgnoreCase
(
DictConstants
.
DICT_ROOT_ID_STR
))
{
list
.
add
(
0
,
parentId
);
parentId
=
dictService
.
getDictById
(
dict
,
Convert
.
toUUID
(
parentId
)).
getUuid
(
"parentId"
);
}
return
list
;
}
@RequestMapping
(
value
=
"/item"
,
method
=
RequestMethod
.
GET
)
public
String
getDataByName
(
@RequestParam
(
"name"
)
String
name
,
@RequestParam
(
name
=
"dictname"
,
required
=
true
)
String
dictname
)
{
Dict
dict
=
Amino
.
getApplicationMetadataContext
().
getBean
(
dictname
,
Dict
.
class
);
return
JSONObjectUtils
.
toJson
(
dictService
.
getDictByName
(
dict
,
name
)).
toString
();
}
@RequestMapping
(
value
=
"/structure"
,
method
=
RequestMethod
.
GET
)
public
String
dictStructure
(
@RequestParam
(
name
=
"dictname"
,
required
=
true
)
String
dictname
)
throws
Exception
{
Dict
dict
=
Amino
.
getApplicationMetadataContext
().
getBean
(
dictname
,
Dict
.
class
);
if
(
dict
!=
null
)
{
return
dict
.
getStructure
();
}
else
{
throw
new
RuntimeException
(
"找不到对应的数据字典定义"
);
}
}
// @RequestMapping(value = "/codeRule", method = RequestMethod.POST)
// public String dictCodeRule(@RequestBody String content) throws Exception
// {
// JSONObject object = new JSONObject(content);
// String dictName = object.getString("dictname");
// Dict dict = Amino.getApplicationMetadataContext().getBean(dictName,
// Dict.class);
// if (dict != null && dict.getStructure().equalsIgnoreCase("codeTree")) {
// return dict.getCodeRule();
// } else {
// throw new RuntimeException("找不到对应的数据字典定义或尝试获取非级次树形数据字典的级次码");
// }
// }
@RequestMapping
(
value
=
"/dicts"
,
method
=
RequestMethod
.
GET
)
public
String
getDicts
()
throws
Exception
{
JSONArray
dicts
=
new
JSONArray
();
Map
<
String
,
Dict
>
map
=
Amino
.
getApplicationMetadataContext
().
getBeansOfType
(
Dict
.
class
);
for
(
String
key
:
map
.
keySet
())
{
JSONObject
object
=
new
JSONObject
();
Dict
dict
=
map
.
get
(
key
);
object
.
put
(
"name"
,
dict
.
getName
());
object
.
put
(
"title"
,
dict
.
getTitle
());
object
.
put
(
"type"
,
dict
.
getStructure
());
dicts
.
put
(
object
);
}
return
dicts
.
toString
();
}
@RequestMapping
(
value
=
"/count"
,
method
=
RequestMethod
.
GET
)
public
int
getCount
(
@RequestParam
(
name
=
"dictname"
,
required
=
true
)
String
dictname
)
throws
Exception
{
Dict
dict
=
Amino
.
getApplicationMetadataContext
().
getBean
(
dictname
,
Dict
.
class
);
return
dictService
.
getCount
(
dict
);
}
@RequestMapping
(
value
=
"/treenode/{rootId}"
,
method
=
RequestMethod
.
GET
)
public
String
getTreeByRoot
(
@PathVariable
(
"rootId"
)
UUID
rootId
,
@RequestParam
(
name
=
"dictname"
,
required
=
true
)
String
dictname
,
@RequestParam
(
name
=
"loaddisable"
,
required
=
true
,
defaultValue
=
"true"
)
boolean
loaddisable
)
{
Dict
dict
=
Amino
.
getApplicationMetadataContext
().
getBean
(
dictname
,
Dict
.
class
);
return
JSONObjectUtils
.
toJson
(
dictService
.
getTreeByRoot
(
dict
,
Convert
.
toUUID
(
rootId
),
loaddisable
)).
toString
();
}
@RequestMapping
(
value
=
"/action"
,
method
=
RequestMethod
.
POST
)
public
void
checkAction
(
@RequestBody
String
content
,
HttpServletResponse
response
)
throws
Exception
{
JSONObject
object
=
new
JSONObject
(
content
);
String
dictName
=
object
.
getString
(
"dictname"
);
String
action
=
object
.
getString
(
"action"
);
Dict
dict
=
Amino
.
getApplicationMetadataContext
().
getBean
(
dictName
,
Dict
.
class
);
Object
obj
=
object
.
get
(
"dictvalue"
);
String
dictvalue
=
""
;
if
(
obj
instanceof
String
)
{
dictvalue
=
(
String
)
obj
;
}
else
if
(
obj
instanceof
JSONObject
)
{
dictvalue
=
obj
.
toString
();
}
try
{
if
(
dictvalue
==
null
||
dictvalue
.
equalsIgnoreCase
(
""
))
{
dictService
.
checkAction
(
dict
,
null
,
DictAcions
.
valueOf
(
action
));
}
else
{
KObject
kObject
=
JSONObjectUtils
.
toObject
(
dictvalue
,
dict
.
getKClass
());
dictService
.
checkAction
(
dict
,
kObject
,
DictAcions
.
valueOf
(
action
));
}
}
catch
(
Exception
e
)
{
response
.
sendError
(
500
,
e
.
getMessage
());
}
}
}
backend/xyst.dinas.biz/src/main/java/com/xyst/dinas/biz/web/WarehouseDictController.java
0 → 100644
View file @
4de6e88b
package
com
.
xyst
.
dinas
.
biz
.
web
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.UUID
;
import
javax.servlet.http.HttpServletResponse
;
import
org.json.JSONArray
;
import
org.json.JSONObject
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
com.beecode.amino.common.Convert
;
import
com.beecode.amino.core.Amino
;
import
com.beecode.bcp.dict.Dict
;
import
com.beecode.bcp.dict.DictAcions
;
import
com.beecode.bcp.dict.DictConstants
;
import
com.beecode.bcp.dict.DictExclude
;
import
com.beecode.bcp.dict.model.Page
;
import
com.beecode.bcp.dict.service.DictService
;
import
com.beecode.bcp.type.KObject
;
import
com.beecode.bcp.type.json.JSONObjectUtils
;
@RestController
@RequestMapping
(
value
=
"/warehouse/api/dict"
)
public
class
WarehouseDictController
{
@Autowired
private
DictService
dictService
;
@RequestMapping
(
value
=
"/add"
,
method
=
RequestMethod
.
POST
)
public
String
insertData
(
@RequestBody
String
content
,
HttpServletResponse
response
)
throws
Exception
{
JSONObject
object
=
new
JSONObject
(
content
);
String
dictName
=
object
.
getString
(
"dictname"
);
String
dictValue
=
""
;
if
(
object
.
get
(
"dictvalue"
)
!=
null
)
{
dictValue
=
object
.
get
(
"dictvalue"
).
toString
();
}
Dict
dict
=
Amino
.
getApplicationMetadataContext
().
getBean
(
dictName
,
Dict
.
class
);
try
{
if
(
dictValue
==
""
)
{
throw
new
RuntimeException
();
}
KObject
kObject
=
JSONObjectUtils
.
toObject
(
dictValue
,
dict
.
getKClass
());
return
dictService
.
create
(
dict
,
kObject
).
toString
();
}
catch
(
Exception
e
)
{
response
.
sendError
(
500
,
e
.
getMessage
());
return
null
;
}
}
@RequestMapping
(
value
=
"/delete"
,
method
=
RequestMethod
.
POST
)
public
void
deleteData
(
@RequestBody
String
content
,
HttpServletResponse
response
)
throws
Exception
{
JSONObject
object
=
new
JSONObject
(
content
);
String
dictName
=
object
.
getString
(
"dictname"
);
String
dictValue
=
""
;
if
(
object
.
get
(
"dictvalue"
)
!=
null
)
{
dictValue
=
object
.
get
(
"dictvalue"
).
toString
();
}
Dict
dict
=
Amino
.
getApplicationMetadataContext
().
getBean
(
dictName
,
Dict
.
class
);
try
{
if
(
dictValue
==
""
)
{
throw
new
RuntimeException
();
}
dictService
.
remove
(
dict
,
JSONObjectUtils
.
toObject
(
dictValue
,
dict
.
getKClass
()));
}
catch
(
Exception
e
)
{
response
.
sendError
(
500
,
e
.
getMessage
());
}
}
@RequestMapping
(
value
=
"/delete/byId"
,
method
=
RequestMethod
.
POST
)
public
void
deleteDataById
(
@RequestBody
String
content
,
HttpServletResponse
response
)
throws
Exception
{
JSONObject
object
=
new
JSONObject
(
content
);
String
dictName
=
object
.
getString
(
"dictname"
);
String
id
=
object
.
getString
(
"id"
);
Dict
dict
=
Amino
.
getApplicationMetadataContext
().
getBean
(
dictName
,
Dict
.
class
);
try
{
dictService
.
removeDictById
(
dict
,
Convert
.
toUUID
(
id
));
}
catch
(
Exception
e
)
{
response
.
sendError
(
500
,
e
.
getMessage
());
}
}
@RequestMapping
(
value
=
"/delete/batch"
,
method
=
RequestMethod
.
POST
)
public
void
deleteDataBatch
(
@RequestBody
String
content
,
HttpServletResponse
response
)
throws
Exception
{
JSONObject
object
=
new
JSONObject
(
content
);
String
dictName
=
object
.
getString
(
"dictname"
);
JSONArray
ids
=
object
.
getJSONArray
(
"ids"
);
Dict
dict
=
Amino
.
getApplicationMetadataContext
().
getBean
(
dictName
,
Dict
.
class
);
for
(
int
i
=
0
;
i
<
ids
.
length
();
i
++)
{
try
{
dictService
.
removeDictById
(
dict
,
Convert
.
toUUID
(
ids
.
get
(
i
)));
}
catch
(
Exception
e
)
{
response
.
sendError
(
500
,
e
.
getMessage
());
}
}
}
@RequestMapping
(
value
=
"/update"
,
method
=
RequestMethod
.
POST
)
public
void
updateData
(
@RequestBody
String
content
,
HttpServletResponse
response
)
throws
Exception
{
JSONObject
object
=
new
JSONObject
(
content
);
String
dictName
=
object
.
getString
(
"dictname"
);
Dict
dict
=
Amino
.
getApplicationMetadataContext
().
getBean
(
dictName
,
Dict
.
class
);
JSONArray
dictItems
=
object
.
getJSONArray
(
"dictvalue"
);
try
{
for
(
int
i
=
0
;
i
<
dictItems
.
length
();
i
++)
{
KObject
kObject
=
JSONObjectUtils
.
toObject
(
dictItems
.
get
(
i
).
toString
(),
dict
.
getKClass
());
dictService
.
modify
(
dict
,
kObject
);
}
}
catch
(
Exception
e
)
{
response
.
sendError
(
500
,
e
.
getMessage
());
}
}
@RequestMapping
(
value
=
"/changeState"
,
method
=
RequestMethod
.
POST
)
public
void
changeState
(
@RequestBody
String
content
,
HttpServletResponse
response
)
throws
Exception
{
JSONObject
object
=
new
JSONObject
(
content
);
String
dictName
=
object
.
getString
(
"dictname"
);
Dict
dict
=
Amino
.
getApplicationMetadataContext
().
getBean
(
dictName
,
Dict
.
class
);
JSONArray
dictItems
=
object
.
getJSONArray
(
"dictvalue"
);
try
{
for
(
int
i
=
0
;
i
<
dictItems
.
length
();
i
++)
{
KObject
kObject
=
JSONObjectUtils
.
toObject
(
dictItems
.
get
(
i
).
toString
(),
dict
.
getKClass
());
dictService
.
modify
(
dict
,
kObject
);
}
}
catch
(
Exception
e
)
{
response
.
sendError
(
500
,
e
.
getMessage
());
}
}
@RequestMapping
(
value
=
"/listAll"
,
method
=
RequestMethod
.
GET
)
public
List
<
KObject
>
getListAllData
(
@RequestParam
(
name
=
"dictname"
,
required
=
true
)
String
dictname
,
DictExclude
dictExclude
)
throws
Exception
{
Dict
dict
=
Amino
.
getApplicationMetadataContext
().
getBean
(
dictname
,
Dict
.
class
);
List
<
KObject
>
allData
=
dictService
.
listAllWithExclude
(
dict
,
dictExclude
);
return
allData
;
}
@RequestMapping
(
value
=
"/roots"
,
method
=
RequestMethod
.
GET
)
public
List
<
KObject
>
getListRoots
(
@RequestParam
(
name
=
"dictname"
,
required
=
true
)
String
dictname
,
DictExclude
dictExclude
)
throws
Exception
{
Dict
dict
=
Amino
.
getApplicationMetadataContext
().
getBean
(
dictname
,
Dict
.
class
);
List
<
KObject
>
allData
=
dictService
.
listRootsWithExclude
(
dict
,
dictExclude
);
return
allData
;
}
@RequestMapping
(
value
=
"/criteria"
,
method
=
RequestMethod
.
GET
)
public
Page
getListByCriteria
(
@RequestParam
(
name
=
"dictname"
,
required
=
true
)
String
dictname
,
@RequestParam
(
name
=
"pageNo"
,
required
=
false
)
Integer
pageNo
,
@RequestParam
(
name
=
"pageSize"
,
required
=
false
)
Integer
pageSize
,
@RequestParam
(
name
=
"keyword"
,
required
=
false
)
String
keyword
,
@RequestParam
(
name
=
"isOrder"
,
required
=
false
)
Boolean
isOrder
,
@RequestParam
(
name
=
"fields"
,
required
=
false
)
String
fields
,
@RequestParam
(
name
=
"startFlag"
,
required
=
false
)
Boolean
startFlag
)
throws
Exception
{
String
[]
fieldArray
=
null
;
if
(
fields
!=
null
)
{
fieldArray
=
fields
.
split
(
","
);
}
Dict
dict
=
Amino
.
getApplicationMetadataContext
().
getBean
(
dictname
,
Dict
.
class
);
return
dictService
.
listDictByPage
(
dict
,
pageNo
,
pageSize
,
fieldArray
,
keyword
,
isOrder
,
startFlag
);
}
@RequestMapping
(
value
=
"/parents/{id}"
,
method
=
RequestMethod
.
GET
)
public
List
<
KObject
>
getParentLink
(
@PathVariable
(
"id"
)
UUID
id
,
@RequestParam
(
name
=
"dictname"
,
required
=
true
)
String
dictname
)
{
Dict
dict
=
Amino
.
getApplicationMetadataContext
().
getBean
(
dictname
,
Dict
.
class
);
KObject
childDict
=
dictService
.
getDictById
(
dict
,
id
);
if
(
childDict
==
null
||
childDict
.
isEmpty
())
{
return
null
;
}
if
(!
childDict
.
getBoolean
(
"startFlag"
))
{
//已停用
return
null
;
}
return
dictService
.
getParentLink
(
childDict
,
dict
);
}
@RequestMapping
(
value
=
"/byChild"
,
method
=
RequestMethod
.
POST
)
public
String
getDataByChild
(
@RequestBody
String
content
)
throws
Exception
{
JSONObject
object
=
new
JSONObject
(
content
);
String
dictName
=
object
.
getString
(
"dictname"
);
String
childId
=
object
.
getString
(
"childId"
);
Dict
dict
=
Amino
.
getApplicationMetadataContext
().
getBean
(
dictName
,
Dict
.
class
);
return
JSONObjectUtils
.
toJson
(
dictService
.
getDictById
(
dict
,
Convert
.
toUUID
(
childId
))).
toString
();
}
@RequestMapping
(
value
=
"/item/{id}"
,
method
=
RequestMethod
.
GET
)
public
String
getDataById
(
@PathVariable
(
"id"
)
UUID
id
,
@RequestParam
(
name
=
"dictname"
,
required
=
true
)
String
dictname
)
{
Dict
dict
=
Amino
.
getApplicationMetadataContext
().
getBean
(
dictname
,
Dict
.
class
);
return
JSONObjectUtils
.
toJson
(
dictService
.
getDictById
(
dict
,
Convert
.
toUUID
(
id
))).
toString
();
}
@RequestMapping
(
value
=
"/parentIds/{id}"
,
method
=
RequestMethod
.
GET
)
public
List
<
UUID
>
getTree
(
@PathVariable
(
"id"
)
UUID
id
,
@RequestParam
(
name
=
"dictname"
,
required
=
true
)
String
dictname
)
{
Dict
dict
=
Amino
.
getApplicationMetadataContext
().
getBean
(
dictname
,
Dict
.
class
);
KObject
kObject
=
dictService
.
getDictById
(
dict
,
Convert
.
toUUID
(
id
));
if
(!
kObject
.
getBoolean
(
"startFlag"
))
{
return
null
;
}
UUID
parentId
=
kObject
.
getUuid
(
"parentId"
);
List
<
UUID
>
list
=
new
ArrayList
<
UUID
>();
list
.
add
(
id
);
while
(!
parentId
.
toString
().
equalsIgnoreCase
(
DictConstants
.
DICT_ROOT_ID_STR
))
{
list
.
add
(
0
,
parentId
);
parentId
=
dictService
.
getDictById
(
dict
,
Convert
.
toUUID
(
parentId
)).
getUuid
(
"parentId"
);
}
return
list
;
}
@RequestMapping
(
value
=
"/item"
,
method
=
RequestMethod
.
GET
)
public
String
getDataByName
(
@RequestParam
(
"name"
)
String
name
,
@RequestParam
(
name
=
"dictname"
,
required
=
true
)
String
dictname
)
{
Dict
dict
=
Amino
.
getApplicationMetadataContext
().
getBean
(
dictname
,
Dict
.
class
);
return
JSONObjectUtils
.
toJson
(
dictService
.
getDictByName
(
dict
,
name
)).
toString
();
}
@RequestMapping
(
value
=
"/structure"
,
method
=
RequestMethod
.
GET
)
public
String
dictStructure
(
@RequestParam
(
name
=
"dictname"
,
required
=
true
)
String
dictname
)
throws
Exception
{
Dict
dict
=
Amino
.
getApplicationMetadataContext
().
getBean
(
dictname
,
Dict
.
class
);
if
(
dict
!=
null
)
{
return
dict
.
getStructure
();
}
else
{
throw
new
RuntimeException
(
"找不到对应的数据字典定义"
);
}
}
// @RequestMapping(value = "/codeRule", method = RequestMethod.POST)
// public String dictCodeRule(@RequestBody String content) throws Exception
// {
// JSONObject object = new JSONObject(content);
// String dictName = object.getString("dictname");
// Dict dict = Amino.getApplicationMetadataContext().getBean(dictName,
// Dict.class);
// if (dict != null && dict.getStructure().equalsIgnoreCase("codeTree")) {
// return dict.getCodeRule();
// } else {
// throw new RuntimeException("找不到对应的数据字典定义或尝试获取非级次树形数据字典的级次码");
// }
// }
@RequestMapping
(
value
=
"/dicts"
,
method
=
RequestMethod
.
GET
)
public
String
getDicts
()
throws
Exception
{
JSONArray
dicts
=
new
JSONArray
();
Map
<
String
,
Dict
>
map
=
Amino
.
getApplicationMetadataContext
().
getBeansOfType
(
Dict
.
class
);
for
(
String
key
:
map
.
keySet
())
{
JSONObject
object
=
new
JSONObject
();
Dict
dict
=
map
.
get
(
key
);
object
.
put
(
"name"
,
dict
.
getName
());
object
.
put
(
"title"
,
dict
.
getTitle
());
object
.
put
(
"type"
,
dict
.
getStructure
());
dicts
.
put
(
object
);
}
return
dicts
.
toString
();
}
@RequestMapping
(
value
=
"/count"
,
method
=
RequestMethod
.
GET
)
public
int
getCount
(
@RequestParam
(
name
=
"dictname"
,
required
=
true
)
String
dictname
)
throws
Exception
{
Dict
dict
=
Amino
.
getApplicationMetadataContext
().
getBean
(
dictname
,
Dict
.
class
);
return
dictService
.
getCount
(
dict
);
}
@RequestMapping
(
value
=
"/treenode/{rootId}"
,
method
=
RequestMethod
.
GET
)
public
String
getTreeByRoot
(
@PathVariable
(
"rootId"
)
UUID
rootId
,
@RequestParam
(
name
=
"dictname"
,
required
=
true
)
String
dictname
,
@RequestParam
(
name
=
"loaddisable"
,
required
=
true
,
defaultValue
=
"true"
)
boolean
loaddisable
)
{
Dict
dict
=
Amino
.
getApplicationMetadataContext
().
getBean
(
dictname
,
Dict
.
class
);
return
JSONObjectUtils
.
toJson
(
dictService
.
getTreeByRoot
(
dict
,
Convert
.
toUUID
(
rootId
),
loaddisable
)).
toString
();
}
@RequestMapping
(
value
=
"/action"
,
method
=
RequestMethod
.
POST
)
public
void
checkAction
(
@RequestBody
String
content
,
HttpServletResponse
response
)
throws
Exception
{
JSONObject
object
=
new
JSONObject
(
content
);
String
dictName
=
object
.
getString
(
"dictname"
);
String
action
=
object
.
getString
(
"action"
);
Dict
dict
=
Amino
.
getApplicationMetadataContext
().
getBean
(
dictName
,
Dict
.
class
);
Object
obj
=
object
.
get
(
"dictvalue"
);
String
dictvalue
=
""
;
if
(
obj
instanceof
String
)
{
dictvalue
=
(
String
)
obj
;
}
else
if
(
obj
instanceof
JSONObject
)
{
dictvalue
=
obj
.
toString
();
}
try
{
if
(
dictvalue
==
null
||
dictvalue
.
equalsIgnoreCase
(
""
))
{
dictService
.
checkAction
(
dict
,
null
,
DictAcions
.
valueOf
(
action
));
}
else
{
KObject
kObject
=
JSONObjectUtils
.
toObject
(
dictvalue
,
dict
.
getKClass
());
dictService
.
checkAction
(
dict
,
kObject
,
DictAcions
.
valueOf
(
action
));
}
}
catch
(
Exception
e
)
{
response
.
sendError
(
500
,
e
.
getMessage
());
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment