|
@@ -6,7 +6,12 @@ import com.jpsoft.railroad.modules.common.dto.Sort;
|
|
|
import com.jpsoft.railroad.modules.common.dto.MessageResult;
|
|
|
import com.jpsoft.railroad.modules.base.entity.OaFileInfo;
|
|
|
import com.jpsoft.railroad.modules.base.service.OaFileInfoService;
|
|
|
+import com.jpsoft.railroad.modules.sys.entity.User;
|
|
|
+import com.jpsoft.railroad.modules.sys.service.UserService;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
+import net.sf.json.JSONArray;
|
|
|
+import net.sf.json.JSONObject;
|
|
|
+import org.apache.commons.collections.map.HashedMap;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
@@ -24,11 +29,14 @@ public class OaFileInfoController {
|
|
|
|
|
|
@Autowired
|
|
|
private OaFileInfoService oaFileInfoService;
|
|
|
-
|
|
|
-
|
|
|
- @ApiOperation(value="创建空记录")
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private UserService userService;
|
|
|
+
|
|
|
+
|
|
|
+ @ApiOperation(value = "创建空记录")
|
|
|
@GetMapping("create")
|
|
|
- public MessageResult<OaFileInfo> create(){
|
|
|
+ public MessageResult<OaFileInfo> create() {
|
|
|
MessageResult<OaFileInfo> msgResult = new MessageResult<>();
|
|
|
|
|
|
OaFileInfo oaFileInfo = new OaFileInfo();
|
|
@@ -39,17 +47,33 @@ public class OaFileInfoController {
|
|
|
return msgResult;
|
|
|
}
|
|
|
|
|
|
- @ApiOperation(value="添加信息")
|
|
|
+ @ApiOperation(value = "添加信息")
|
|
|
@PostMapping("add")
|
|
|
- public MessageResult<OaFileInfo> add(@RequestBody OaFileInfo oaFileInfo,@RequestAttribute String subject){
|
|
|
+ public MessageResult<OaFileInfo> add(@RequestBody OaFileInfo oaFileInfo, @RequestAttribute String subject) {
|
|
|
MessageResult<OaFileInfo> msgResult = new MessageResult<>();
|
|
|
|
|
|
try {
|
|
|
oaFileInfo.setId(UUID.randomUUID().toString());
|
|
|
- oaFileInfo.setDelFlag(false);
|
|
|
+ oaFileInfo.setDelFlag(false);
|
|
|
oaFileInfo.setCreateBy(subject);
|
|
|
oaFileInfo.setCreateTime(new Date());
|
|
|
|
|
|
+ JSONArray jsonArray = new JSONArray();
|
|
|
+
|
|
|
+ if (oaFileInfo.getUrlList() != null) {
|
|
|
+ for (Map<String, String> map : oaFileInfo.getUrlList()) {
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.put("name", map.get("name"));
|
|
|
+ jsonObject.put("url", map.get("url"));
|
|
|
+ jsonArray.add(jsonObject);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (jsonArray.size() > 0) {
|
|
|
+ oaFileInfo.setUrl(jsonArray.toString());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
int affectCount = oaFileInfoService.insert(oaFileInfo);
|
|
|
|
|
|
if (affectCount > 0) {
|
|
@@ -59,9 +83,8 @@ public class OaFileInfoController {
|
|
|
msgResult.setResult(false);
|
|
|
msgResult.setMessage("数据库添加失败");
|
|
|
}
|
|
|
- }
|
|
|
- catch(Exception ex){
|
|
|
- logger.error(ex.getMessage(),ex);
|
|
|
+ } catch (Exception ex) {
|
|
|
+ logger.error(ex.getMessage(), ex);
|
|
|
|
|
|
msgResult.setResult(false);
|
|
|
msgResult.setMessage(ex.getMessage());
|
|
@@ -70,24 +93,46 @@ public class OaFileInfoController {
|
|
|
return msgResult;
|
|
|
}
|
|
|
|
|
|
- @ApiOperation(value="获取信息")
|
|
|
+ @ApiOperation(value = "获取信息")
|
|
|
@GetMapping("edit/{id}")
|
|
|
- public MessageResult<OaFileInfo> edit(@PathVariable("id") String id){
|
|
|
+ public MessageResult<OaFileInfo> edit(@PathVariable("id") String id) {
|
|
|
MessageResult<OaFileInfo> msgResult = new MessageResult<>();
|
|
|
|
|
|
try {
|
|
|
OaFileInfo oaFileInfo = oaFileInfoService.get(id);
|
|
|
|
|
|
if (oaFileInfo != null) {
|
|
|
+ String url = oaFileInfo.getUrl();
|
|
|
+
|
|
|
+ List<Map> annexFileList = new ArrayList<>();
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(url)) {
|
|
|
+
|
|
|
+ JSONArray jsonArray = JSONArray.fromObject(url);
|
|
|
+
|
|
|
+ for (Object object : jsonArray) {
|
|
|
+ Map map = new HashedMap();
|
|
|
+ JSONObject jsonObject = JSONObject.fromObject(object);
|
|
|
+ String fileName = jsonObject.get("name").toString();
|
|
|
+ String urlAddress = jsonObject.get("url").toString();
|
|
|
+ map.put("fileName", fileName);
|
|
|
+ map.put("url", urlAddress);
|
|
|
+ map.put("name", fileName);
|
|
|
+ annexFileList.add(map);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ oaFileInfo.setUrlList(annexFileList);
|
|
|
+
|
|
|
+
|
|
|
msgResult.setResult(true);
|
|
|
msgResult.setData(oaFileInfo);
|
|
|
} else {
|
|
|
msgResult.setResult(false);
|
|
|
msgResult.setMessage("数据库不存在该记录!");
|
|
|
}
|
|
|
- }
|
|
|
- catch(Exception ex){
|
|
|
- logger.error(ex.getMessage(),ex);
|
|
|
+ } catch (Exception ex) {
|
|
|
+ logger.error(ex.getMessage(), ex);
|
|
|
|
|
|
msgResult.setResult(false);
|
|
|
msgResult.setMessage(ex.getMessage());
|
|
@@ -96,15 +141,31 @@ public class OaFileInfoController {
|
|
|
return msgResult;
|
|
|
}
|
|
|
|
|
|
- @ApiOperation(value="更新用户")
|
|
|
+ @ApiOperation(value = "更新用户")
|
|
|
@PostMapping("update")
|
|
|
- public MessageResult<OaFileInfo> update(@RequestBody OaFileInfo oaFileInfo,@RequestAttribute String subject){
|
|
|
+ public MessageResult<OaFileInfo> update(@RequestBody OaFileInfo oaFileInfo, @RequestAttribute String subject) {
|
|
|
MessageResult<OaFileInfo> msgResult = new MessageResult<>();
|
|
|
|
|
|
try {
|
|
|
- oaFileInfo.setUpdateBy(subject);
|
|
|
+ oaFileInfo.setUpdateBy(subject);
|
|
|
oaFileInfo.setUpdateTime(new Date());
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+ JSONArray jsonArray = new JSONArray();
|
|
|
+
|
|
|
+ if (oaFileInfo.getUrlList() != null) {
|
|
|
+ for (Map<String, String> map : oaFileInfo.getUrlList()) {
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.put("name", map.get("name"));
|
|
|
+ jsonObject.put("url", map.get("url"));
|
|
|
+ jsonArray.add(jsonObject);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (jsonArray.size() > 0) {
|
|
|
+ oaFileInfo.setUrl(jsonArray.toString());
|
|
|
+ }
|
|
|
+
|
|
|
int affectCount = oaFileInfoService.update(oaFileInfo);
|
|
|
|
|
|
if (affectCount > 0) {
|
|
@@ -114,9 +175,8 @@ public class OaFileInfoController {
|
|
|
msgResult.setResult(false);
|
|
|
msgResult.setMessage("数据库更新失败");
|
|
|
}
|
|
|
- }
|
|
|
- catch(Exception ex){
|
|
|
- logger.error(ex.getMessage(),ex);
|
|
|
+ } catch (Exception ex) {
|
|
|
+ logger.error(ex.getMessage(), ex);
|
|
|
|
|
|
msgResult.setResult(false);
|
|
|
msgResult.setMessage(ex.getMessage());
|
|
@@ -125,19 +185,19 @@ public class OaFileInfoController {
|
|
|
return msgResult;
|
|
|
}
|
|
|
|
|
|
- @ApiOperation(value="删除用户")
|
|
|
+ @ApiOperation(value = "删除用户")
|
|
|
@PostMapping("delete/{id}")
|
|
|
- public MessageResult<OaFileInfo> delete(@PathVariable("id") String id,@RequestAttribute String subject){
|
|
|
+ public MessageResult<OaFileInfo> delete(@PathVariable("id") String id, @RequestAttribute String subject) {
|
|
|
MessageResult<OaFileInfo> msgResult = new MessageResult<>();
|
|
|
|
|
|
try {
|
|
|
-
|
|
|
- OaFileInfo oaFileInfo = oaFileInfoService.get(id);
|
|
|
+
|
|
|
+ OaFileInfo oaFileInfo = oaFileInfoService.get(id);
|
|
|
oaFileInfo.setDelFlag(true);
|
|
|
oaFileInfo.setUpdateBy(subject);
|
|
|
oaFileInfo.setUpdateTime(new Date());
|
|
|
-
|
|
|
- int affectCount = oaFileInfoService.update(oaFileInfo);
|
|
|
+
|
|
|
+ int affectCount = oaFileInfoService.update(oaFileInfo);
|
|
|
|
|
|
if (affectCount > 0) {
|
|
|
msgResult.setResult(true);
|
|
@@ -145,9 +205,8 @@ public class OaFileInfoController {
|
|
|
msgResult.setResult(false);
|
|
|
msgResult.setMessage("数据库删除失败");
|
|
|
}
|
|
|
- }
|
|
|
- catch(Exception ex){
|
|
|
- logger.error(ex.getMessage(),ex);
|
|
|
+ } catch (Exception ex) {
|
|
|
+ logger.error(ex.getMessage(), ex);
|
|
|
|
|
|
msgResult.setResult(false);
|
|
|
msgResult.setMessage(ex.getMessage());
|
|
@@ -157,9 +216,9 @@ public class OaFileInfoController {
|
|
|
}
|
|
|
|
|
|
|
|
|
- @ApiOperation(value="批量删除")
|
|
|
+ @ApiOperation(value = "批量删除")
|
|
|
@PostMapping("batchDelete")
|
|
|
- public MessageResult<Integer> batchDelete(@RequestBody List<String> idList,@RequestAttribute String subject){
|
|
|
+ public MessageResult<Integer> batchDelete(@RequestBody List<String> idList, @RequestAttribute String subject) {
|
|
|
MessageResult<Integer> msgResult = new MessageResult<>();
|
|
|
|
|
|
try {
|
|
@@ -181,9 +240,8 @@ public class OaFileInfoController {
|
|
|
msgResult.setResult(false);
|
|
|
msgResult.setMessage("删除失败");
|
|
|
}
|
|
|
- }
|
|
|
- catch(Exception ex){
|
|
|
- logger.error(ex.getMessage(),ex);
|
|
|
+ } catch (Exception ex) {
|
|
|
+ logger.error(ex.getMessage(), ex);
|
|
|
|
|
|
msgResult.setResult(false);
|
|
|
msgResult.setMessage(ex.getMessage());
|
|
@@ -192,31 +250,55 @@ public class OaFileInfoController {
|
|
|
return msgResult;
|
|
|
}
|
|
|
|
|
|
- @ApiOperation(value="列表")
|
|
|
- @RequestMapping(value = "pageList",method = RequestMethod.POST)
|
|
|
+ @ApiOperation(value = "列表")
|
|
|
+ @RequestMapping(value = "pageList", method = RequestMethod.POST)
|
|
|
public MessageResult<Map> pageList(
|
|
|
- String id,
|
|
|
- @RequestParam(value="pageIndex",defaultValue="1") int pageIndex,
|
|
|
- @RequestParam(value="pageSize",defaultValue="20") int pageSize,
|
|
|
- HttpServletRequest request){
|
|
|
- String subject = (String)request.getAttribute("subject");
|
|
|
+ String name,
|
|
|
+ @RequestParam(value = "pageIndex", defaultValue = "1") int pageIndex,
|
|
|
+ @RequestParam(value = "pageSize", defaultValue = "20") int pageSize,
|
|
|
+ HttpServletRequest request) {
|
|
|
+ String subject = (String) request.getAttribute("subject");
|
|
|
|
|
|
//当前用户ID
|
|
|
System.out.println(subject);
|
|
|
|
|
|
MessageResult<Map> msgResult = new MessageResult<>();
|
|
|
|
|
|
- Map<String,Object> searchParams = new HashMap<>();
|
|
|
+ Map<String, Object> searchParams = new HashMap<>();
|
|
|
|
|
|
List<Sort> sortList = new ArrayList<>();
|
|
|
- sortList.add(new Sort("create_time","desc"));
|
|
|
+ sortList.add(new Sort("create_time", "desc"));
|
|
|
|
|
|
- if (StringUtils.isNotEmpty(id)) {
|
|
|
- searchParams.put("id","%" + id + "%");
|
|
|
+ if (StringUtils.isNotEmpty(name)) {
|
|
|
+ searchParams.put("name", "%" + name + "%");
|
|
|
}
|
|
|
|
|
|
|
|
|
- Page<OaFileInfo> page = oaFileInfoService.pageSearch(searchParams,pageIndex,pageSize,true,sortList);
|
|
|
+ Page<OaFileInfo> page = oaFileInfoService.pageSearch(searchParams, pageIndex, pageSize, true, sortList);
|
|
|
+
|
|
|
+ for (OaFileInfo oaFileInfo : page) {
|
|
|
+ String createBy = oaFileInfo.getCreateBy();
|
|
|
+
|
|
|
+ User user = userService.get(createBy);
|
|
|
+
|
|
|
+ if (user != null) {
|
|
|
+ oaFileInfo.setCreateByN(user.getRealName());
|
|
|
+ }
|
|
|
+
|
|
|
+ String url = oaFileInfo.getUrl();
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(url)) {
|
|
|
+ JSONArray jsonArray = JSONArray.fromObject(url);
|
|
|
+ if (jsonArray.size() > 0) {
|
|
|
+ JSONObject jsonObject = JSONObject.fromObject(jsonArray.get(0));
|
|
|
+ String tempAddress = jsonObject.getString("url");
|
|
|
+ String urlName = jsonObject.getString("name");
|
|
|
+ oaFileInfo.setUrl(tempAddress);
|
|
|
+ oaFileInfo.setUrlName(urlName);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
|
|
|
msgResult.setResult(true);
|