ExpenseAccountController.java 15 KB

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