TableExampleController.java 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  1. package jnpf.controller;
  2. import cn.dev33.satoken.annotation.SaCheckPermission;
  3. import io.swagger.v3.oas.annotations.Operation;
  4. import io.swagger.v3.oas.annotations.Parameter;
  5. import io.swagger.v3.oas.annotations.Parameters;
  6. import io.swagger.v3.oas.annotations.tags.Tag;
  7. import jnpf.base.ActionResult;
  8. import jnpf.base.Page;
  9. import jnpf.base.UserInfo;
  10. import jnpf.base.controller.SuperController;
  11. import io.swagger.v3.oas.annotations.Parameter;
  12. import io.swagger.v3.oas.annotations.Parameters;
  13. import io.swagger.v3.oas.annotations.Operation;
  14. import jnpf.constant.MsgCode;
  15. import jnpf.permission.entity.UserEntity;
  16. import jnpf.permission.service.UserService;
  17. import jnpf.util.JsonUtilEx;
  18. import jnpf.base.ActionResult;
  19. import jnpf.base.vo.PageListVO;
  20. import jnpf.base.vo.PaginationVO;
  21. import jnpf.base.UserInfo;
  22. import jnpf.base.service.DictionaryDataService;
  23. import jnpf.base.service.ProvinceService;
  24. import jnpf.base.vo.ListVO;
  25. import jnpf.entity.TableExampleEntity;
  26. import jnpf.base.entity.DictionaryDataEntity;
  27. import jnpf.base.entity.ProvinceEntity;
  28. import jnpf.exception.DataException;
  29. import jnpf.model.tableexample.*;
  30. import jnpf.model.tableexample.postil.PostilInfoVO;
  31. import jnpf.model.tableexample.postil.PostilModel;
  32. import jnpf.model.tableexample.postil.PostilSendForm;
  33. import jnpf.service.TableExampleService;
  34. import jnpf.util.DateUtil;
  35. import jnpf.util.JsonUtil;
  36. import jnpf.util.StringUtil;
  37. import jnpf.util.UserProvider;
  38. import jnpf.util.treeutil.SumTree;
  39. import jnpf.util.treeutil.TreeDotUtils;
  40. import jnpf.util.type.StringNumber;
  41. import org.apache.commons.lang3.StringUtils;
  42. import org.springframework.beans.factory.annotation.Autowired;
  43. import org.springframework.web.bind.annotation.*;
  44. import jakarta.validation.Valid;
  45. import java.math.BigDecimal;
  46. import java.util.ArrayList;
  47. import java.util.List;
  48. import java.util.stream.Collectors;
  49. /**
  50. * 表格示例数据
  51. *
  52. * @author JNPF开发平台组
  53. * @version V3.1.0
  54. * @copyright 引迈信息技术有限公司(https://www.jnpfsoft.com)
  55. * @date 2019年9月26日 上午9:18
  56. */
  57. @Tag(name = "表格示例数据", description = "TableExample")
  58. @RestController
  59. @RequestMapping("/api/extend/TableExample")
  60. public class TableExampleController extends SuperController<TableExampleService, TableExampleEntity> {
  61. @Autowired
  62. private TableExampleService tableExampleService;
  63. @Autowired
  64. private ProvinceService provinceService;
  65. @Autowired
  66. private DictionaryDataService dictionaryDataService;
  67. @Autowired
  68. private UserService userService;
  69. /**
  70. * 列表
  71. *
  72. * @param paginationTableExample 分页模型
  73. * @return
  74. */
  75. @Operation(summary = "获取表格数据列表")
  76. @GetMapping
  77. @SaCheckPermission("extend.tableDemo.commonTable")
  78. public ActionResult<PageListVO<TableExampleListVO>> list(PaginationTableExample paginationTableExample) {
  79. List<TableExampleEntity> data = tableExampleService.getList(paginationTableExample);
  80. List<TableExampleListVO> list = JsonUtil.getJsonToList(data, TableExampleListVO.class);
  81. List<String> userId = list.stream().map(t -> t.getRegistrant()).collect(Collectors.toList());
  82. List<UserEntity> userList = userService.getUserName(userId);
  83. for (TableExampleListVO tableExampleListVO : list) {
  84. UserEntity user = userList.stream().filter(t -> t.getId().equals(tableExampleListVO.getRegistrant())).findFirst().orElse(null);
  85. tableExampleListVO.setRegistrant(user != null ? user.getRealName() + "/" + user.getAccount() : "");
  86. }
  87. PaginationVO paginationVO = JsonUtil.getJsonToBean(paginationTableExample, PaginationVO.class);
  88. return ActionResult.page(list, paginationVO);
  89. }
  90. /**
  91. * 列表(树形表格)
  92. *
  93. * @param typeId 主键
  94. * @param paginationTableExample 查询模型
  95. * @return
  96. */
  97. @Operation(summary = "(树形表格)")
  98. @GetMapping("/ControlSample/{typeId}")
  99. @Parameters({
  100. @Parameter(name = "typeId", description = "主键", required = true),
  101. })
  102. @SaCheckPermission("extend.tableDemo.tableTree")
  103. public ActionResult<PageListVO<TableExampleListVO>> list(@PathVariable("typeId") String typeId, PaginationTableExample paginationTableExample) {
  104. List<TableExampleEntity> data = tableExampleService.getList(typeId, paginationTableExample);
  105. List<TableExampleListVO> list = JsonUtil.getJsonToList(data, TableExampleListVO.class);
  106. List<String> userId = list.stream().map(t -> t.getRegistrant()).collect(Collectors.toList());
  107. List<UserEntity> userList = userService.getUserName(userId);
  108. for (TableExampleListVO tableExampleListVO : list) {
  109. UserEntity user = userList.stream().filter(t -> t.getId().equals(tableExampleListVO.getRegistrant())).findFirst().orElse(null);
  110. tableExampleListVO.setRegistrant(user != null ? user.getRealName() + "/" + user.getAccount() : "");
  111. }
  112. PaginationVO paginationVO = JsonUtil.getJsonToBean(paginationTableExample, PaginationVO.class);
  113. return ActionResult.page(list, paginationVO);
  114. }
  115. /**
  116. * 列表
  117. *
  118. * @return
  119. */
  120. @Operation(summary = "获取表格分组列表")
  121. @GetMapping("/All")
  122. @SaCheckPermission("extend.tableDemo.groupingTable")
  123. public ActionResult<ListVO<TableExampleListAllVO>> listAll() {
  124. List<TableExampleEntity> data = tableExampleService.getList();
  125. List<TableExampleListAllVO> list = JsonUtil.getJsonToList(data, TableExampleListAllVO.class);
  126. List<String> userId = list.stream().map(t -> t.getRegistrant()).collect(Collectors.toList());
  127. List<UserEntity> userList = userService.getUserName(userId);
  128. for (TableExampleListAllVO tableExampleListVO : list) {
  129. UserEntity user = userList.stream().filter(t -> t.getId().equals(tableExampleListVO.getRegistrant())).findFirst().orElse(null);
  130. tableExampleListVO.setRegistrant(user != null ? user.getRealName() + "/" + user.getAccount() : "");
  131. }
  132. ListVO<TableExampleListAllVO> vo = new ListVO<>();
  133. vo.setList(list);
  134. return ActionResult.success(vo);
  135. }
  136. /**
  137. * 列表
  138. *
  139. * @param page 查询模型
  140. * @return
  141. */
  142. @Operation(summary = "获取延伸扩展列表(行政区划)")
  143. @GetMapping("/IndustryList")
  144. @SaCheckPermission("extend.tableDemo.extension")
  145. public ActionResult<ListVO<TableExampleIndustryListVO>> industryList(Page page) {
  146. String keyword = page.getKeyword();
  147. List<ProvinceEntity> data = provinceService.getList("-1");
  148. if (!StringUtil.isEmpty(keyword)) {
  149. data = data.stream().filter(t -> t.getFullName().contains(keyword)).collect(Collectors.toList());
  150. }
  151. List<TableExampleIndustryListVO> listVos = JsonUtil.getJsonToList(data, TableExampleIndustryListVO.class);
  152. ListVO<TableExampleIndustryListVO> vo = new ListVO<>();
  153. vo.setList(listVos);
  154. return ActionResult.success(vo);
  155. }
  156. /**
  157. * 列表
  158. *
  159. * @param id 主键值
  160. * @return
  161. */
  162. @Operation(summary = "获取城市信息列表(获取延伸扩展列表(行政区划))")
  163. @GetMapping("/CityList/{id}")
  164. @Parameters({
  165. @Parameter(name = "id", description = "主键", required = true),
  166. })
  167. @SaCheckPermission("extend.tableDemo.extension")
  168. public ActionResult<ListVO<TableExampleCityListVO>> cityList(@PathVariable("id") String id) {
  169. List<ProvinceEntity> data = provinceService.getList(id);
  170. List<TableExampleCityListVO> listVos = JsonUtil.getJsonToList(data, TableExampleCityListVO.class);
  171. ListVO<TableExampleCityListVO> vo = new ListVO<>();
  172. vo.setList(listVos);
  173. return ActionResult.success(vo);
  174. }
  175. /**
  176. * 列表(表格树形)
  177. *
  178. * @param isTree 类型
  179. * @return
  180. */
  181. @Operation(summary = "表格树形")
  182. @GetMapping("/ControlSample/TreeList")
  183. @Parameters({
  184. @Parameter(name = "isTree", description = "类型"),
  185. })
  186. @SaCheckPermission("extend.tableDemo.tableTree")
  187. public ActionResult<ListVO<TableExampleTreeModel>> treeList(@RequestParam("isTree")String isTree) {
  188. List<DictionaryDataEntity> data = dictionaryDataService.getList("d59a3cf65f9847dbb08be449e3feae16");
  189. List<TableExampleTreeModel> treeList = new ArrayList<>();
  190. for (DictionaryDataEntity entity : data) {
  191. TableExampleTreeModel treeModel = new TableExampleTreeModel();
  192. treeModel.setId(entity.getId());
  193. treeModel.setText(entity.getFullName());
  194. treeModel.setParentId(entity.getParentId());
  195. treeModel.setLoaded(true);
  196. treeModel.setExpanded(true);
  197. treeModel.setHt(JsonUtil.entityToMap(entity));
  198. treeList.add(treeModel);
  199. }
  200. if (isTree != null && StringNumber.ONE.equals(isTree)) {
  201. List<SumTree<TableExampleTreeModel>> trees = TreeDotUtils.convertListToTreeDot(treeList);
  202. List<TableExampleTreeModel> listVO = JsonUtil.getJsonToList(trees, TableExampleTreeModel.class);
  203. ListVO vo = new ListVO();
  204. vo.setList(listVO);
  205. return ActionResult.success(vo);
  206. }
  207. ListVO vo = new ListVO();
  208. vo.setList(treeList);
  209. return ActionResult.success(vo);
  210. }
  211. /**
  212. * 信息
  213. *
  214. * @param id 主键
  215. * @return
  216. */
  217. @Operation(summary = "获取普通表格示例信息")
  218. @GetMapping("/{id}")
  219. @Parameters({
  220. @Parameter(name = "id", description = "主键", required = true),
  221. })
  222. @SaCheckPermission("extend.tableDemo.extension")
  223. public ActionResult<TableExampleInfoVO> info(@PathVariable("id") String id) throws DataException {
  224. TableExampleEntity entity = tableExampleService.getInfo(id);
  225. TableExampleInfoVO vo = JsonUtil.getJsonToBeanEx(entity, TableExampleInfoVO.class);
  226. return ActionResult.success(vo);
  227. }
  228. /**
  229. * 删除
  230. *
  231. * @param id 主键
  232. * @return
  233. */
  234. @Operation(summary = "删除项目")
  235. @DeleteMapping("/{id}")
  236. @Parameters({
  237. @Parameter(name = "id", description = "主键", required = true),
  238. })
  239. @SaCheckPermission("extend.tableDemo.extension")
  240. public ActionResult delete(@PathVariable("id") String id) {
  241. TableExampleEntity entity = tableExampleService.getInfo(id);
  242. if (entity != null) {
  243. tableExampleService.delete(entity);
  244. return ActionResult.success(MsgCode.SU003.get());
  245. }
  246. return ActionResult.fail(MsgCode.FA003.get());
  247. }
  248. /**
  249. * 创建
  250. *
  251. * @param tableExampleCrForm 项目模型
  252. * @return
  253. */
  254. @Operation(summary = "新建项目")
  255. @PostMapping
  256. @Parameters({
  257. @Parameter(name = "tableExampleCrForm", description = "项目模型",required = true),
  258. })
  259. @SaCheckPermission("extend.tableDemo.extension")
  260. public ActionResult create(@RequestBody @Valid TableExampleCrForm tableExampleCrForm) {
  261. TableExampleEntity entity = JsonUtil.getJsonToBean(tableExampleCrForm, TableExampleEntity.class);
  262. entity.setCostAmount(entity.getCostAmount() == null ? new BigDecimal("0") : entity.getCostAmount());
  263. entity.setTunesAmount(entity.getTunesAmount() == null ? new BigDecimal("0") : entity.getTunesAmount());
  264. entity.setProjectedIncome(entity.getProjectedIncome() == null ? new BigDecimal("0") : entity.getProjectedIncome());
  265. entity.setSign("0000000");
  266. tableExampleService.create(entity);
  267. return ActionResult.success(MsgCode.SU001.get());
  268. }
  269. /**
  270. * 更新
  271. *
  272. * @param id 主键
  273. * @param tableExampleUpForm 项目模型
  274. * @return
  275. */
  276. @Operation(summary = "更新项目")
  277. @PutMapping("/{id}")
  278. @Parameters({
  279. @Parameter(name = "tableExampleUpForm", description = "项目模型",required = true),
  280. @Parameter(name = "id", description = "主键", required = true),
  281. })
  282. @SaCheckPermission("extend.tableDemo.postilTable")
  283. public ActionResult update(@PathVariable("id") String id, @RequestBody @Valid TableExampleUpForm tableExampleUpForm) {
  284. TableExampleEntity entity = JsonUtil.getJsonToBean(tableExampleUpForm, TableExampleEntity.class);
  285. entity.setCostAmount(entity.getCostAmount() == null ? new BigDecimal("0") : entity.getCostAmount());
  286. entity.setTunesAmount(entity.getTunesAmount() == null ? new BigDecimal("0") : entity.getTunesAmount());
  287. entity.setProjectedIncome(entity.getProjectedIncome() == null ? new BigDecimal("0") : entity.getProjectedIncome());
  288. boolean flag = tableExampleService.update(id, entity);
  289. if (flag == false) {
  290. return ActionResult.fail(MsgCode.FA002.get());
  291. }
  292. return ActionResult.success(MsgCode.SU004.get());
  293. }
  294. /**
  295. * 更新标签
  296. *
  297. * @param id 主键
  298. * @param tableExampleSignUpForm 项目模型
  299. * @return
  300. */
  301. @Operation(summary = "更新标记")
  302. @PutMapping("/UpdateSign/{id}")
  303. @Parameters({
  304. @Parameter(name = "tableExampleSignUpForm", description = "项目模型",required = true),
  305. @Parameter(name = "id", description = "主键", required = true),
  306. })
  307. @SaCheckPermission("extend.tableDemo.postilTable")
  308. public ActionResult updateSign(@PathVariable("id") String id, @RequestBody @Valid TableExampleSignUpForm tableExampleSignUpForm) {
  309. TableExampleEntity entity = JsonUtil.getJsonToBean(tableExampleSignUpForm, TableExampleEntity.class);
  310. TableExampleEntity tableExampleEntity = tableExampleService.getInfo(id);
  311. if (tableExampleEntity == null) {
  312. return ActionResult.success(MsgCode.FA002.get());
  313. }
  314. tableExampleEntity.setSign(entity.getSign());
  315. tableExampleService.update(id, entity);
  316. return ActionResult.success(MsgCode.SU004.get());
  317. }
  318. /**
  319. * 行编辑
  320. *
  321. * @param tableExampleRowUpForm 项目模型
  322. * @param id 主键
  323. * @return
  324. */
  325. @Operation(summary = "行编辑")
  326. @PutMapping("/{id}/Actions/RowsEdit")
  327. @Parameters({
  328. @Parameter(name = "tableExampleRowUpForm", description = "项目模型",required = true),
  329. @Parameter(name = "id", description = "主键", required = true),
  330. })
  331. @SaCheckPermission("extend.tableDemo.redactTable")
  332. public ActionResult rowEditing(@PathVariable("id") String id, @RequestBody @Valid TableExampleRowUpForm tableExampleRowUpForm) {
  333. TableExampleEntity entity = JsonUtil.getJsonToBean(tableExampleRowUpForm, TableExampleEntity.class);
  334. entity.setCostAmount(entity.getCostAmount() == null ? new BigDecimal("0") : entity.getCostAmount());
  335. entity.setTunesAmount(entity.getTunesAmount() == null ? new BigDecimal("0") : entity.getTunesAmount());
  336. entity.setProjectedIncome(entity.getProjectedIncome() == null ? new BigDecimal("0") : entity.getProjectedIncome());
  337. entity.setId(id);
  338. boolean falg = tableExampleService.rowEditing(entity);
  339. if (falg == false) {
  340. return ActionResult.fail(MsgCode.FA002.get());
  341. }
  342. return ActionResult.success(MsgCode.SU004.get());
  343. }
  344. /**
  345. * 发送
  346. *
  347. * @param postilSendForm 项目模型
  348. * @param id 主键
  349. * @return
  350. */
  351. @Operation(summary = "发送批注")
  352. @PostMapping("/{id}/Postil")
  353. @Parameters({
  354. @Parameter(name = "postilSendForm", description = "项目模型",required = true),
  355. @Parameter(name = "id", description = "主键", required = true),
  356. })
  357. @SaCheckPermission("extend.tableDemo.postilTable")
  358. public ActionResult sendPostil(@PathVariable("id") String id, @RequestBody PostilSendForm postilSendForm) {
  359. TableExampleEntity tableExampleEntity = tableExampleService.getInfo(id);
  360. if (tableExampleEntity == null) {
  361. return ActionResult.success(MsgCode.FA005.get());
  362. }
  363. UserInfo userInfo = UserProvider.getUser();
  364. PostilModel model = new PostilModel();
  365. model.setCreatorTime(DateUtil.getNow("+8"));
  366. model.setText(postilSendForm.getText());
  367. model.setUserId(userInfo != null ? userInfo.getUserName() + "/" + userInfo.getUserAccount() : "");
  368. List<PostilModel> list = new ArrayList<>();
  369. list.add(model);
  370. if (!StringUtil.isEmpty(tableExampleEntity.getPostilJson())) {
  371. list.addAll(JsonUtil.getJsonToList(tableExampleEntity.getPostilJson(), PostilModel.class));
  372. }
  373. String postilJson = JsonUtil.getObjectToString(list);
  374. tableExampleEntity.setPostilJson(postilJson);
  375. tableExampleEntity.setPostilCount(list.size());
  376. tableExampleService.update(id, tableExampleEntity);
  377. return ActionResult.success(MsgCode.SU012.get());
  378. }
  379. /**
  380. * 发送
  381. *
  382. * @param id 主键值
  383. * @return
  384. */
  385. @Operation(summary = "获取批注")
  386. @Parameters({
  387. @Parameter(name = "id", description = "主键", required = true),
  388. })
  389. @GetMapping("/{id}/Actions/Postil")
  390. @SaCheckPermission("extend.tableDemo.postilTable")
  391. public ActionResult<PostilInfoVO> getPostil(@PathVariable("id") String id) {
  392. TableExampleEntity tableExampleEntity = tableExampleService.getInfo(id);
  393. if (tableExampleEntity == null) {
  394. return ActionResult.success(MsgCode.FA012.get());
  395. }
  396. PostilInfoVO vo = new PostilInfoVO();
  397. vo.setPostilJson(tableExampleEntity.getPostilJson());
  398. return ActionResult.success(vo);
  399. }
  400. /**
  401. * 删除批注
  402. *
  403. * @param id 主键值
  404. * @param index 行数
  405. * @return
  406. */
  407. @Operation(summary = "删除批注")
  408. @DeleteMapping("/{id}/Postil/{index}")
  409. @Parameters({
  410. @Parameter(name = "id", description = "主键", required = true),
  411. @Parameter(name = "index", description = "行数", required = true),
  412. })
  413. @SaCheckPermission("extend.tableDemo.postilTable")
  414. public ActionResult deletePostil(@PathVariable("id") String id, @PathVariable("index") int index) {
  415. TableExampleEntity tableExampleEntity = tableExampleService.getInfo(id);
  416. if (tableExampleEntity == null) {
  417. return ActionResult.success(MsgCode.FA003.get());
  418. }
  419. List<PostilModel> list = JsonUtil.getJsonToList(tableExampleEntity.getPostilJson(), PostilModel.class);
  420. list.remove(index);
  421. String postilJson = JsonUtil.getObjectToString(list);
  422. tableExampleEntity.setPostilJson(postilJson);
  423. tableExampleEntity.setPostilCount((list.size()));
  424. tableExampleService.update(id, tableExampleEntity);
  425. return ActionResult.success(MsgCode.SU003.get());
  426. }
  427. }