ExpenseAccountController.java 12 KB

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