ExpenseAccountController.java 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  1. package com.goafanti.expenseAccount.controller;
  2. import com.goafanti.common.bo.Result;
  3. import com.goafanti.common.constant.AFTConstants;
  4. import com.goafanti.common.constant.ErrorConstants;
  5. import com.goafanti.common.controller.CertifyApiController;
  6. import com.goafanti.common.model.ExpenseAccount;
  7. import com.goafanti.common.utils.ParamUtils;
  8. import com.goafanti.common.utils.excel.NewExcelUtil;
  9. import com.goafanti.core.shiro.token.TokenManager;
  10. import com.goafanti.expenseAccount.bo.*;
  11. import com.goafanti.expenseAccount.service.ExpenseAccountService;
  12. import com.goafanti.organization.bo.OrganizationListOut;
  13. import org.springframework.beans.factory.annotation.Autowired;
  14. import org.springframework.beans.factory.annotation.Value;
  15. import org.springframework.validation.BindingResult;
  16. import org.springframework.validation.annotation.Validated;
  17. import org.springframework.web.bind.annotation.RequestMapping;
  18. import org.springframework.web.bind.annotation.RequestMethod;
  19. import org.springframework.web.bind.annotation.RestController;
  20. import java.math.BigDecimal;
  21. import java.util.Arrays;
  22. import java.util.List;
  23. @RestController
  24. @RequestMapping("/api/admin/expenseAccount")
  25. public class ExpenseAccountController extends CertifyApiController {
  26. @Autowired
  27. private ExpenseAccountService expenseAccountService;
  28. @Value(value = "${upload.path}")
  29. private final String uploadPath = null;
  30. /**
  31. * 新增私有报销帐号
  32. */
  33. @RequestMapping(value = "/add",method = RequestMethod.POST)
  34. public Result add(@Validated InputExpenseAccount in , BindingResult bindingResult){
  35. Result res =new Result();
  36. if (bindingResult.hasErrors()) {
  37. String param=bindingResult.getFieldError().getField();
  38. res.getError().add(buildError(ParamUtils.getParamMsg(in,param),ParamUtils.getParamName(in,param)));
  39. return res;
  40. }
  41. in.setAid(TokenManager.getAdminId());
  42. res.setData(expenseAccountService.add(in));
  43. return res;
  44. }
  45. /**
  46. * 删除报销
  47. */
  48. @RequestMapping(value = "/delete",method = RequestMethod.POST)
  49. public Result delete(String id){
  50. Result res =new Result();
  51. res.setData(expenseAccountService.delete(id));
  52. return res;
  53. }
  54. /**
  55. * 新增私有报销帐号
  56. * @param in updateType=1时,作为修改类型。会删除所有子项
  57. */
  58. @RequestMapping(value = "/update",method = RequestMethod.POST)
  59. public Result update( InputExpenseAccount in ){
  60. Result res =new Result();
  61. in.setAid(TokenManager.getAdminId());
  62. //只修改状态
  63. if (in.getUpdateType()==1){
  64. res.setData(expenseAccountService.updateType(in));
  65. }else {
  66. //抵扣单借支单必须指定
  67. if (in.getType()==5){
  68. if (in.getDebitId()==null){
  69. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"抵扣单借支单"));
  70. return res;
  71. }
  72. }
  73. res.setData(expenseAccountService.update(in));
  74. }
  75. return res;
  76. }
  77. /**
  78. * 删除报销抵扣
  79. */
  80. @RequestMapping(value = "/updateDebitId",method = RequestMethod.POST)
  81. public Result updateDebitId( InputExpenseAccount in ){
  82. Result res =new Result();
  83. res.setData(expenseAccountService.updateDebitId(in));
  84. return res;
  85. }
  86. /**
  87. * 主报销列表
  88. */
  89. @RequestMapping(value = "/mainList",method = RequestMethod.GET)
  90. public Result mainList(ExpenseMainListInput in){
  91. Result res =new Result();
  92. return res.data(expenseAccountService.mainList(in));
  93. }
  94. /**
  95. * 报销列表,子报销列表
  96. */
  97. @RequestMapping(value = "/pageList",method = RequestMethod.GET)
  98. public Result pageList(InputPageListBo in ){
  99. Result res =new Result();
  100. res.setData(expenseAccountService.pageList(in));
  101. return res;
  102. }
  103. /**
  104. * 费用单列表导出
  105. */
  106. @RequestMapping(value = "/pageListExport",method = RequestMethod.GET)
  107. public Result pageListExport(InputPageListBo in ){
  108. Result res =new Result();
  109. in.setPageSize(999999);
  110. res.setData(expenseAccountService.pageListExport(in));
  111. return res;
  112. }
  113. /**
  114. * 报销详情列表
  115. */
  116. @RequestMapping(value = "/detailsList",method = RequestMethod.GET)
  117. public Result detailsList(InputDetailsListBo in ){
  118. Result res =new Result();
  119. res.setData(expenseAccountService.detailsList(in));
  120. return res;
  121. }
  122. /**
  123. * 费用详情列表导出
  124. */
  125. @RequestMapping(value = "/detailsListExport",method = RequestMethod.GET)
  126. public Result detailsListExport(InputDetailsListBo in ){
  127. Result res =new Result();
  128. in.setPageSize(999999);
  129. res.setData(expenseAccountService.detailsListExport(in));
  130. return res;
  131. }
  132. /**
  133. * 判断当前是否存在草稿
  134. */
  135. @RequestMapping(value = "/selectByPrid",method = RequestMethod.GET)
  136. public Result selectByPrid(InputExpenseAccount in ){
  137. Result res =new Result();
  138. res.setData(expenseAccountService.selectByPrid(in));
  139. return res;
  140. }
  141. /**
  142. * 报销列表
  143. */
  144. @RequestMapping(value = "/selectById",method = RequestMethod.GET)
  145. public Result selectById(Integer id ){
  146. Result res =new Result();
  147. res.setData(expenseAccountService.selectById(id));
  148. return res;
  149. }
  150. /**
  151. * 报销列表
  152. * @param checkNo 查询编号
  153. */
  154. @RequestMapping(value = "/selectByCheckNo",method = RequestMethod.GET)
  155. public Result selectByCheckNo(String checkNo ){
  156. Result res =new Result();
  157. res.setData(expenseAccountService.selectByCheckNo(checkNo));
  158. return res;
  159. }
  160. /**
  161. * 新增报销详情
  162. */
  163. @RequestMapping(value = "/details/add",method = RequestMethod.POST)
  164. public Result addDetails(@Validated InputExpenseAccountDetails in , BindingResult bindingResult){
  165. Result res =new Result();
  166. if (bindingResult.hasErrors()) {
  167. String param=bindingResult.getFieldError().getField();
  168. System.out.println(param);
  169. res.getError().add(buildError(ParamUtils.getParamMsg(in,param),ParamUtils.getParamName(in,param)));
  170. return res;
  171. }
  172. res.setData(expenseAccountService.addDetails(in));
  173. return res;
  174. }
  175. /**
  176. * 删除报销详情
  177. */
  178. @RequestMapping(value = "/details/delete",method = RequestMethod.GET)
  179. public Result deleteDetails(Integer id){
  180. Result res =new Result();
  181. res.setData(expenseAccountService.deleteDetails(id));
  182. return res;
  183. }
  184. /**
  185. * 报销详情
  186. */
  187. @RequestMapping(value = "/details/list",method = RequestMethod.GET)
  188. public Result detailsList(Integer eaid){
  189. Result res =new Result();
  190. res.setData(expenseAccountService.detailsList(eaid));
  191. return res;
  192. }
  193. @RequestMapping(value = "/log/list",method = RequestMethod.GET)
  194. public Result logList(Integer eaid){
  195. Result res =new Result();
  196. if (eaid==null){
  197. res.getError().add(buildErrorMessageParams(ErrorConstants.PARAM_EMPTY_ERROR,"报销编号"));
  198. return res;
  199. }
  200. res.setData(expenseAccountService.logList(eaid));
  201. return res;
  202. }
  203. /**
  204. * 报销审核
  205. */
  206. @RequestMapping(value = "/examine",method = RequestMethod.POST)
  207. public Result examine(InputExpenseAccount in,BindingResult bindingResult){
  208. Result res =new Result();
  209. if (bindingResult.hasErrors()) {
  210. String param=bindingResult.getFieldError().getField();
  211. res.getError().add(buildError(ParamUtils.getParamMsg(in,param),ParamUtils.getParamName(in,param)));
  212. return res;
  213. }
  214. res.setData(expenseAccountService.updateExamine(in));
  215. return res;
  216. }
  217. /**
  218. * 获取借支列表
  219. */
  220. @RequestMapping(value = "/selectDebitOrder",method = RequestMethod.GET)
  221. public Result selectDebitOrder(String depId,Integer id){
  222. Result res=new Result();
  223. if (depId==null){
  224. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"抵扣部门"));
  225. return res;
  226. }
  227. res.setData(expenseAccountService.selectDebitOrder(depId,id));
  228. return res;
  229. }
  230. /**
  231. * 获取后台统计数据
  232. */
  233. @RequestMapping(value = "/statistics",method = RequestMethod.GET)
  234. public Result statistics(String name,String depId,String startTime,String endTime) {
  235. Result res = new Result();
  236. String lander = null;
  237. if (TokenManager.hasRole(AFTConstants.FINANCE)) {
  238. lander = TokenManager.getAdminId();
  239. }
  240. res.setData(expenseAccountService.statistics(name, depId, startTime, endTime, lander));
  241. return res;
  242. }
  243. @RequestMapping(value = "/statistics/evict",method = RequestMethod.GET)
  244. public Result statisticsEvict(String name,String depId,String startTime,String endTime){
  245. Result res=new Result();
  246. expenseAccountService.statisticsEvict( name, depId, startTime, endTime);
  247. return res.data(1);
  248. }
  249. /**
  250. * 获取后台统计数据
  251. */
  252. @RequestMapping(value = "/statistics/export",method = RequestMethod.GET)
  253. public Result statisticsExport(String name,String depId,String startTime,String endTime) {
  254. String lander = null;
  255. if (TokenManager.hasRole(AFTConstants.FINANCE)) {
  256. lander = TokenManager.getAdminId();
  257. }
  258. List<OutExpenseAccountStatistics> list = expenseAccountService.statistics(name, depId, startTime, endTime, lander);
  259. NewExcelUtil<OutExpenseAccountStatistics> newExcelUtil = new NewExcelUtil<>(OutExpenseAccountStatistics.class);
  260. return newExcelUtil.exportExcel(list, "报销统计", uploadPath);
  261. }
  262. /**
  263. * 合并报销
  264. */
  265. @RequestMapping(value = "/merge",method = RequestMethod.GET)
  266. public Result merge(String ids){
  267. Result res =new Result();
  268. if (ids==null){
  269. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"合并编号"));
  270. return res;
  271. }
  272. String[] split = ids.split(",");
  273. List<String> list = Arrays.asList(split);
  274. List<ExpenseAccount> expenseAccounts = expenseAccountService.selectByIds(list);
  275. for (ExpenseAccount e : expenseAccounts) {
  276. if (e.getStatus()!=0){
  277. res.getError().add(buildError(String.format("[%s]编号已经发起,不能重复发起。",e.getId())));
  278. return res;
  279. }else if (e.getTotalAmount().compareTo(new BigDecimal(0))==0){
  280. res.getError().add(buildError(String.format("[%s]编号金额为0,请完善修改后发起。",e.getId())));
  281. return res;
  282. }
  283. }
  284. //预借支不允许和其他类型发起报销
  285. int i = expenseAccountService.selectCountByIdsAndType(list, 5);
  286. if (i>0){
  287. if (i!=expenseAccounts.size()+1){
  288. res.getError().add(buildError("不允许抵扣与其他类型报销合并发起。"));
  289. return res;
  290. }
  291. }
  292. return res.data(expenseAccountService.pushMerge(expenseAccounts));
  293. }
  294. /**
  295. * 主报销详情
  296. */
  297. @RequestMapping(value = "/mainExpense",method = RequestMethod.GET)
  298. public Result mainExpense(Integer id){
  299. Result res =new Result();
  300. if (id==null){
  301. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"合并编号"));
  302. return res;
  303. }
  304. return res.data(expenseAccountService.mainExpense(id));
  305. }
  306. /**
  307. * 修改主报销
  308. */
  309. @RequestMapping(value = "/updateMain",method = RequestMethod.POST)
  310. public Result updateMain( MainExpenseAccount in){
  311. Result res =new Result();
  312. if (in.getId()==null){
  313. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"编号"));
  314. return res;
  315. }
  316. if (in.getStatus()==1&&in.getEaaid()==null){
  317. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"报销账号"));
  318. return res;
  319. }
  320. return res.data(expenseAccountService.updateMain(in));
  321. }
  322. /**
  323. * 修改实报金额
  324. * @param type 类型 1报销与费用 2费用详细 去掉修改上级,只能修改费用
  325. * @param id 编号
  326. * @param amount 金额
  327. */
  328. @RequestMapping(value = "/updateRealAmount",method = RequestMethod.POST)
  329. public Result updateRealAmount(Integer type ,Integer id,BigDecimal amount){
  330. Result res =new Result();
  331. if (id==null){
  332. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"编号"));
  333. return res;
  334. }
  335. if (amount==null){
  336. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"金额"));
  337. return res;
  338. }
  339. return res.data(expenseAccountService.updateRealAmount( type , id, amount));
  340. }
  341. /**
  342. * 修改报销类型说明
  343. */
  344. @RequestMapping(value = "/updateTypeOther",method = RequestMethod.POST)
  345. public Result updateTypeOther(Integer id ,String typeOther,String remarks,String orderNo){
  346. Result res =new Result();
  347. if (id==null){
  348. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"编号"));
  349. return res;
  350. }
  351. return res.data(expenseAccountService.updateTypeOther( id, typeOther,remarks,orderNo));
  352. }
  353. /**
  354. * 修改报销详情类型说明
  355. */
  356. @RequestMapping(value = "/updateDetailsTypeOther",method = RequestMethod.POST)
  357. public Result updateDetailsTypeOther(Integer id , String typeOther){
  358. Result res =new Result();
  359. if (id==null){
  360. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"编号"));
  361. return res;
  362. }
  363. return res.data(expenseAccountService.updateDetailsTypeOther( id, typeOther));
  364. }
  365. /**
  366. * 主类分类说明
  367. */
  368. @RequestMapping(value = "/pushAll",method = RequestMethod.GET)
  369. public Result pushAll(){
  370. expenseAccountService.pushAll();
  371. return null;
  372. }
  373. /**
  374. * 获取报销部门设置
  375. */
  376. @RequestMapping(value = "/getDepDetails",method = RequestMethod.GET)
  377. public Result<OrganizationListOut> getDepDetails(Integer id){
  378. Result res= new Result();
  379. return res.data(expenseAccountService.getDepDetails(id));
  380. }
  381. }