BillRuleController.java 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. package jnpf.base.controller;
  2. import cn.dev33.satoken.annotation.SaCheckPermission;
  3. import cn.hutool.core.util.ObjectUtil;
  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 io.swagger.v3.oas.annotations.Operation;
  8. import jnpf.annotation.HandleLog;
  9. import jnpf.base.ActionResult;
  10. import jnpf.base.entity.DictionaryDataEntity;
  11. import jnpf.base.model.billrule.*;
  12. import jnpf.base.service.DictionaryDataService;
  13. import jnpf.base.vo.DownloadVO;
  14. import jnpf.base.vo.PageListVO;
  15. import jnpf.base.vo.PaginationVO;
  16. import jnpf.base.service.BillRuleService;
  17. import jnpf.base.entity.BillRuleEntity;
  18. import jnpf.config.ConfigValueUtil;
  19. import jnpf.constant.FileTypeConstant;
  20. import jnpf.constant.MsgCode;
  21. import jnpf.exception.DataException;
  22. import jnpf.permission.entity.UserEntity;
  23. import jnpf.permission.service.UserService;
  24. import jnpf.util.*;
  25. import jnpf.emnus.ModuleTypeEnum;
  26. import jnpf.util.DataFileExport;
  27. import org.springframework.beans.factory.annotation.Autowired;
  28. import org.springframework.http.MediaType;
  29. import org.springframework.web.bind.annotation.*;
  30. import org.springframework.web.multipart.MultipartFile;
  31. import jakarta.validation.Valid;
  32. import java.util.ArrayList;
  33. import java.util.List;
  34. /**
  35. * 单据规则
  36. *
  37. * @author JNPF开发平台组
  38. * @version V3.1.0
  39. * @copyright 引迈信息技术有限公司
  40. * @date 2019年9月27日 上午9:18
  41. */
  42. @Tag(name = "单据规则", description = "BillRule")
  43. @RestController
  44. @RequestMapping("/api/system/BillRule")
  45. public class BillRuleController extends SuperController<BillRuleService, BillRuleEntity> {
  46. @Autowired
  47. private DataFileExport fileExport;
  48. @Autowired
  49. private ConfigValueUtil configValueUtil;
  50. @Autowired
  51. private BillRuleService billRuleService;
  52. @Autowired
  53. private UserService userService;
  54. @Autowired
  55. private DictionaryDataService dictionaryDataService;
  56. /**
  57. * 列表
  58. *
  59. * @param pagination 分页参数
  60. * @return ignore
  61. */
  62. @HandleLog(moduleName = "单据规则", requestMethod = "查询")
  63. @Operation(summary = "获取单据规则列表(带分页)")
  64. @SaCheckPermission("templateCenter.billRule")
  65. @GetMapping
  66. public ActionResult<PageListVO<BillRuleListVO>> list(BillRulePagination pagination) {
  67. List<BillRuleEntity> list = billRuleService.getList(pagination);
  68. List<BillRuleListVO> listVO = new ArrayList<>();
  69. list.forEach(entity->{
  70. BillRuleListVO vo = JsonUtil.getJsonToBean(entity, BillRuleListVO.class);
  71. if(StringUtil.isNotEmpty(entity.getCategory())){
  72. DictionaryDataEntity dataEntity = dictionaryDataService.getInfo(entity.getCategory());
  73. vo.setCategory(dataEntity != null ? dataEntity.getFullName() : null);
  74. }
  75. UserEntity userEntity = userService.getInfo(entity.getCreatorUserId());
  76. if(userEntity != null){
  77. vo.setCreatorUser(userEntity.getRealName() + "/" + userEntity.getAccount());
  78. }
  79. listVO.add(vo);
  80. });
  81. PaginationVO paginationVO = JsonUtil.getJsonToBean(pagination, PaginationVO.class);
  82. return ActionResult.page(listVO, paginationVO);
  83. }
  84. /**
  85. * 列表
  86. *
  87. * @return ignore
  88. */
  89. @HandleLog(moduleName = "单据规则", requestMethod = "查询")
  90. @Operation(summary = "获取单据规则下拉框")
  91. @GetMapping("/Selector")
  92. public ActionResult selectList(BillRulePagination pagination) {
  93. List<BillRuleEntity> list = billRuleService.getListByCategory(pagination.getCategoryId(),pagination);
  94. List<BillRuleListVO> listVO = new ArrayList<>();
  95. list.forEach(entity->{
  96. BillRuleListVO vo = JsonUtil.getJsonToBean(entity, BillRuleListVO.class);
  97. if(StringUtil.isNotEmpty(entity.getCategory())){
  98. DictionaryDataEntity dataEntity = dictionaryDataService.getInfo(entity.getCategory());
  99. vo.setCategory(dataEntity != null ? dataEntity.getFullName() : null);
  100. }
  101. UserEntity userEntity = userService.getInfo(entity.getCreatorUserId());
  102. if(userEntity != null){
  103. vo.setCreatorUser(userEntity.getRealName() + "/" + userEntity.getAccount());
  104. }
  105. listVO.add(vo);
  106. });
  107. PaginationVO paginationVO = JsonUtil.getJsonToBean(pagination, PaginationVO.class);
  108. return ActionResult.page(listVO, paginationVO);
  109. }
  110. /**
  111. * 更新组织状态
  112. *
  113. * @param id 主键值
  114. * @return ignore
  115. */
  116. @HandleLog(moduleName = "单据规则", requestMethod = "修改")
  117. @Operation(summary = "更新单据规则状态")
  118. @Parameters({
  119. @Parameter(name = "id", description = "主键值", required = true)
  120. })
  121. @SaCheckPermission("templateCenter.billRule")
  122. @PutMapping("/{id}/Actions/State")
  123. public ActionResult update(@PathVariable("id") String id) {
  124. BillRuleEntity entity = billRuleService.getInfo(id);
  125. if (entity != null) {
  126. if ("1".equals(String.valueOf(entity.getEnabledMark()))) {
  127. entity.setEnabledMark(0);
  128. } else {
  129. entity.setEnabledMark(1);
  130. }
  131. billRuleService.update(entity.getId(), entity);
  132. return ActionResult.success(MsgCode.SU004.get());
  133. }
  134. return ActionResult.fail(MsgCode.FA002.get());
  135. }
  136. /**
  137. * 信息
  138. *
  139. * @param id 主键值
  140. * @return ignore
  141. */
  142. @HandleLog(moduleName = "单据规则", requestMethod = "查询")
  143. @Operation(summary = "获取单据规则信息")
  144. @Parameters({
  145. @Parameter(name = "id", description = "主键值", required = true)
  146. })
  147. @SaCheckPermission("templateCenter.billRule")
  148. @GetMapping("/{id}")
  149. public ActionResult<BillRuleInfoVO> info(@PathVariable("id") String id) throws DataException {
  150. BillRuleEntity entity = billRuleService.getInfo(id);
  151. BillRuleInfoVO vo = JsonUtilEx.getJsonToBeanEx(entity, BillRuleInfoVO.class);
  152. return ActionResult.success(vo);
  153. }
  154. /**
  155. * 获取单据流水号
  156. *
  157. * @param enCode 参数编码
  158. * @return ignore
  159. */
  160. @HandleLog(moduleName = "单据规则", requestMethod = "查询")
  161. @Operation(summary = "获取单据流水号(工作流调用)")
  162. @Parameters({
  163. @Parameter(name = "enCode", description = "参数编码", required = true)
  164. })
  165. @GetMapping("/BillNumber/{enCode}")
  166. public ActionResult getBillNumber(@PathVariable("enCode") String enCode) throws DataException {
  167. String data = billRuleService.getBillNumber(enCode, false);
  168. return ActionResult.success(MsgCode.SU019.get(), data);
  169. }
  170. /**
  171. * 新建
  172. *
  173. * @param billRuleCrForm 实体对象
  174. * @return ignore
  175. */
  176. @HandleLog(moduleName = "单据规则", requestMethod = "新增")
  177. @Operation(summary = "添加单据规则")
  178. @Parameters({
  179. @Parameter(name = "billRuleCrForm", description = "实体对象", required = true)
  180. })
  181. @SaCheckPermission("templateCenter.billRule")
  182. @PostMapping
  183. public ActionResult create(@RequestBody @Valid BillRuleCrForm billRuleCrForm) {
  184. BillRuleEntity entity = JsonUtil.getJsonToBean(billRuleCrForm, BillRuleEntity.class);
  185. if (billRuleService.isExistByFullName(entity.getFullName(), entity.getId())) {
  186. return ActionResult.fail(MsgCode.EXIST001.get());
  187. }
  188. if (billRuleService.isExistByEnCode(entity.getEnCode(), entity.getId())) {
  189. return ActionResult.fail(MsgCode.EXIST002.get());
  190. }
  191. billRuleService.create(entity);
  192. return ActionResult.success(MsgCode.SU001.get());
  193. }
  194. /**
  195. * 更新
  196. *
  197. * @param billRuleUpForm 实体对象
  198. * @param id 主键值
  199. * @return ignore
  200. */
  201. @HandleLog(moduleName = "单据规则", requestMethod = "修改")
  202. @Operation(summary = "修改单据规则")
  203. @Parameters({
  204. @Parameter(name = "id", description = "主键值", required = true),
  205. @Parameter(name = "billRuleUpForm", description = "实体对象", required = true)
  206. })
  207. @SaCheckPermission("templateCenter.billRule")
  208. @PutMapping("/{id}")
  209. public ActionResult update(@PathVariable("id") String id, @RequestBody BillRuleUpForm billRuleUpForm) {
  210. BillRuleEntity entity = JsonUtil.getJsonToBean(billRuleUpForm, BillRuleEntity.class);
  211. if (billRuleService.isExistByFullName(entity.getFullName(), id)) {
  212. return ActionResult.fail(MsgCode.EXIST001.get());
  213. }
  214. if (billRuleService.isExistByEnCode(entity.getEnCode(), id)) {
  215. return ActionResult.fail(MsgCode.EXIST002.get());
  216. }
  217. // 单据生成规则有改变则重新生成流水
  218. BillRuleEntity billRuleEntity = billRuleService.getInfo(id);
  219. if (entity.getType() == 1 && (
  220. (StringUtil.isNotEmpty(billRuleEntity.getPrefix()) && StringUtil.isNotEmpty(entity.getPrefix()) &&
  221. !ObjectUtil.equal(billRuleEntity.getPrefix().length(), entity.getPrefix().length())) ||
  222. (StringUtil.isNotEmpty(billRuleEntity.getSuffix()) && StringUtil.isNotEmpty(entity.getSuffix()) &&
  223. !ObjectUtil.equal(billRuleEntity.getSuffix().length(), entity.getSuffix().length())) ||
  224. !ObjectUtil.equal(billRuleEntity.getDigit(), entity.getDigit()) ||
  225. !ObjectUtil.equal(billRuleEntity.getDateFormat(), entity.getDateFormat())
  226. )
  227. ) {
  228. entity.setOutputNumber(null);
  229. entity.setThisNumber(null);
  230. }else {
  231. entity.setOutputNumber(billRuleEntity.getOutputNumber());
  232. entity.setThisNumber(billRuleEntity.getThisNumber());
  233. }
  234. boolean flag = billRuleService.update(id, entity);
  235. if (!flag) {
  236. return ActionResult.fail(MsgCode.FA002.get());
  237. }
  238. return ActionResult.success(MsgCode.SU004.get());
  239. }
  240. /**
  241. * 删除
  242. *
  243. * @param id 主键值
  244. * @return ignore
  245. */
  246. @HandleLog(moduleName = "单据规则", requestMethod = "删除")
  247. @Operation(summary = "删除单据规则")
  248. @Parameters({
  249. @Parameter(name = "id", description = "主键值", required = true)
  250. })
  251. @SaCheckPermission("templateCenter.billRule")
  252. @DeleteMapping("/{id}")
  253. public ActionResult delete(@PathVariable("id") String id) {
  254. BillRuleEntity entity = billRuleService.getInfo(id);
  255. if (entity != null) {
  256. if (!StringUtil.isEmpty(entity.getOutputNumber())) {
  257. return ActionResult.fail(MsgCode.SYS003.get());
  258. } else {
  259. billRuleService.delete(entity);
  260. return ActionResult.success(MsgCode.SU003.get());
  261. }
  262. }
  263. return ActionResult.fail(MsgCode.FA003.get());
  264. }
  265. /**
  266. * 导出单据规则
  267. *
  268. * @param id 打印模板id
  269. * @return ignore
  270. */
  271. @HandleLog(moduleName = "单据规则", requestMethod = "导出")
  272. @Operation(summary = "导出")
  273. @Parameters({
  274. @Parameter(name = "id", description = "主键值", required = true)
  275. })
  276. @SaCheckPermission("templateCenter.billRule")
  277. @GetMapping("/{id}/Actions/Export")
  278. public ActionResult<DownloadVO> export(@PathVariable String id) {
  279. BillRuleEntity entity = billRuleService.getInfo(id);
  280. //导出文件
  281. DownloadVO downloadVO = fileExport.exportFile(entity, FileTypeConstant.TEMPORARY, entity.getFullName(), ModuleTypeEnum.SYSTEM_BILLRULE.getTableName());
  282. return ActionResult.success(downloadVO);
  283. }
  284. /**
  285. * 导入单据规则
  286. *
  287. * @param multipartFile 备份json文件
  288. * @param type 0/1 跳过/追加
  289. * @return 执行结果标识
  290. */
  291. @HandleLog(moduleName = "单据规则", requestMethod = "导入")
  292. @Operation(summary = "导入")
  293. @SaCheckPermission("templateCenter.billRule")
  294. @PostMapping(value = "/Actions/Import", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
  295. public ActionResult importData(@RequestPart("file") MultipartFile multipartFile,
  296. @RequestParam("type") Integer type) throws DataException {
  297. //判断是否为.json结尾
  298. if (FileUtil.existsSuffix(multipartFile, ModuleTypeEnum.SYSTEM_BILLRULE.getTableName())) {
  299. return ActionResult.fail(MsgCode.IMP002.get());
  300. }
  301. try {
  302. String fileContent = FileUtil.getFileContent(multipartFile);
  303. BillRuleEntity entity = JsonUtil.getJsonToBean(fileContent, BillRuleEntity.class);
  304. return billRuleService.ImportData(entity, type);
  305. } catch (Exception e) {
  306. throw new DataException(MsgCode.IMP004.get());
  307. }
  308. }
  309. }