ExpenseAccountController.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  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. }
  66. // else if (in.getType()!=3&&in.getType()!=5){
  67. // if (in.getEaaid()==null){
  68. // res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"报销帐号"));
  69. // return res;
  70. // }
  71. // }
  72. res.setData(expenseAccountService.update(in));
  73. }
  74. return res;
  75. }
  76. /**
  77. * 报销列表,子报销列表
  78. * @param in
  79. * @return
  80. */
  81. @RequestMapping(value = "/pageList",method = RequestMethod.GET)
  82. public Result pageList(InputPageListBo in ){
  83. Result res =new Result();
  84. res.setData(expenseAccountService.pageList(in));
  85. return res;
  86. }
  87. /**
  88. * 主报销列表
  89. * @param in
  90. * @return
  91. */
  92. @RequestMapping(value = "/mainList",method = RequestMethod.GET)
  93. public Result mainList(ExpenseMainListInput in){
  94. Result res =new Result();
  95. return res.data(expenseAccountService.mainList(in));
  96. }
  97. /**
  98. * 报销详情列表
  99. * @return
  100. */
  101. @RequestMapping(value = "/detailsList",method = RequestMethod.GET)
  102. public Result detailsList(InputDetailsListBo in ){
  103. Result res =new Result();
  104. res.setData(expenseAccountService.detailsList(in));
  105. return res;
  106. }
  107. /**
  108. * 判断当前是否存在草稿
  109. * @param in
  110. * @return
  111. */
  112. @RequestMapping(value = "/selectByPrid",method = RequestMethod.GET)
  113. public Result selectByPrid(InputExpenseAccount in ){
  114. Result res =new Result();
  115. res.setData(expenseAccountService.selectByPrid(in));
  116. return res;
  117. }
  118. /**
  119. * 报销列表
  120. * @param id
  121. * @return
  122. */
  123. @RequestMapping(value = "/selectById",method = RequestMethod.GET)
  124. public Result selectById(Integer id ){
  125. Result res =new Result();
  126. res.setData(expenseAccountService.selectById(id));
  127. return res;
  128. }
  129. /**
  130. * 报销列表
  131. * @param checkNo
  132. * @return
  133. */
  134. @RequestMapping(value = "/selectByCheckNo",method = RequestMethod.GET)
  135. public Result selectByCheckNo(String checkNo ){
  136. Result res =new Result();
  137. res.setData(expenseAccountService.selectByCheckNo(checkNo));
  138. return res;
  139. }
  140. /**
  141. * 新增报销详情
  142. * @param in
  143. * @return
  144. */
  145. @RequestMapping(value = "/details/add",method = RequestMethod.POST)
  146. public Result addDetails(@Validated InputExpenseAccountDetails in , BindingResult bindingResult){
  147. Result res =new Result();
  148. if (bindingResult.hasErrors()) {
  149. String param=bindingResult.getFieldError().getField();
  150. System.out.println(param);
  151. res.getError().add(buildError(ParamUtils.getParamMsg(in,param),ParamUtils.getParamName(in,param)));
  152. return res;
  153. }
  154. res.setData(expenseAccountService.addDetails(in));
  155. return res;
  156. }
  157. /**
  158. * 删除报销详情
  159. * @param id
  160. * @return
  161. */
  162. @RequestMapping(value = "/details/delete",method = RequestMethod.GET)
  163. public Result deleteDetails(Integer id){
  164. Result res =new Result();
  165. res.setData(expenseAccountService.deleteDetails(id));
  166. return res;
  167. }
  168. /**
  169. * 删除报销详情
  170. * @param eaid
  171. * @return
  172. */
  173. @RequestMapping(value = "/details/list",method = RequestMethod.GET)
  174. public Result detailsList(Integer eaid){
  175. Result res =new Result();
  176. res.setData(expenseAccountService.detailsList(eaid));
  177. return res;
  178. }
  179. @RequestMapping(value = "/log/list",method = RequestMethod.GET)
  180. public Result logList(Integer eaid){
  181. Result res =new Result();
  182. if (eaid==null){
  183. res.getError().add(buildErrorMessageParams(ErrorConstants.PARAM_EMPTY_ERROR,"报销编号"));
  184. return res;
  185. }
  186. res.setData(expenseAccountService.logList(eaid));
  187. return res;
  188. }
  189. /**
  190. * 报销审核
  191. * @param in
  192. * @param bindingResult
  193. * @return
  194. */
  195. @RequestMapping(value = "/examine",method = RequestMethod.POST)
  196. public Result examine(InputExpenseAccount in,BindingResult bindingResult){
  197. Result res =new Result();
  198. if (bindingResult.hasErrors()) {
  199. String param=bindingResult.getFieldError().getField();
  200. res.getError().add(buildError(ParamUtils.getParamMsg(in,param),ParamUtils.getParamName(in,param)));
  201. return res;
  202. }
  203. res.setData(expenseAccountService.updateExamine(in));
  204. return res;
  205. }
  206. /**
  207. * 获取借支列表
  208. * @return
  209. */
  210. @RequestMapping(value = "/selectDebitOrder",method = RequestMethod.GET)
  211. public Result selectDebitOrder(String depId,Integer id){
  212. Result res=new Result();
  213. if (depId==null){
  214. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"抵扣部门"));
  215. return res;
  216. }
  217. res.setData(expenseAccountService.selectDebitOrder(depId,id));
  218. return res;
  219. }
  220. /**
  221. * 获取后台统计数据
  222. * @return
  223. */
  224. @RequestMapping(value = "/statistics",method = RequestMethod.GET)
  225. public Result statistics(String name,String depId,String startTime,String endTime){
  226. Result res=new Result();
  227. res.setData(expenseAccountService.statistics( name, depId, startTime, endTime));
  228. return res;
  229. }
  230. @RequestMapping(value = "/statistics/evict",method = RequestMethod.GET)
  231. public Result statisticsEvict(String name,String depId,String startTime,String endTime){
  232. Result res=new Result();
  233. expenseAccountService.statisticsEvict( name, depId, startTime, endTime);
  234. return res.data(1);
  235. }
  236. /**
  237. * 获取后台统计数据
  238. * @return
  239. */
  240. @RequestMapping(value = "/statistics/export",method = RequestMethod.GET)
  241. public Result statisticsExport(String name,String depId,String startTime,String endTime){
  242. List<OutExpenseAccountStatistics> list = expenseAccountService.statistics( name, depId, startTime, endTime);
  243. NewExcelUtil<OutExpenseAccountStatistics> newExcelUtil=new NewExcelUtil<>(OutExpenseAccountStatistics.class);
  244. return newExcelUtil.exportExcel(list,"报销统计",uploadPath);
  245. }
  246. /**
  247. * 合并报销
  248. * @param ids
  249. * @return
  250. */
  251. @RequestMapping(value = "/merge",method = RequestMethod.GET)
  252. public Result merge(String ids){
  253. Result res =new Result();
  254. if (ids==null){
  255. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"合并编号"));
  256. return res;
  257. }
  258. String[] split = ids.split(",");
  259. List<String> list = Arrays.asList(split);
  260. List<ExpenseAccount> expenseAccounts = expenseAccountService.selectByIds(list);
  261. for (ExpenseAccount e : expenseAccounts) {
  262. if (e.getStatus()!=0){
  263. res.getError().add(buildError(String.format("[%s]编号已经发起,不能重复发起。",e.getId())));
  264. return res;
  265. }else if (e.getTotalAmount().compareTo(new BigDecimal(0))==0){
  266. res.getError().add(buildError(String.format("[%s]编号金额为0,请完善修改后发起。",e.getId())));
  267. return res;
  268. }
  269. }
  270. //预借支不允许和其他类型发起报销
  271. int i = expenseAccountService.selectCountByIdsAndType(list, 5);
  272. if (i>0){
  273. if (i!=expenseAccounts.size()+1){
  274. res.getError().add(buildError("不允许抵扣与其他类型报销合并发起。"));
  275. return res;
  276. }
  277. }
  278. return res.data(expenseAccountService.pushMerge(expenseAccounts));
  279. }
  280. /**
  281. * 主报销详情
  282. * @param id
  283. * @return
  284. */
  285. @RequestMapping(value = "/mainExpense",method = RequestMethod.GET)
  286. public Result mainExpense(Integer id){
  287. Result res =new Result();
  288. if (id==null){
  289. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"合并编号"));
  290. return res;
  291. }
  292. return res.data(expenseAccountService.mainExpense(id));
  293. }
  294. /**
  295. * 修改主报销
  296. * @param in
  297. * @return
  298. */
  299. @RequestMapping(value = "/updateMain",method = RequestMethod.POST)
  300. public Result updateMain(MainExpenseAccount in){
  301. Result res =new Result();
  302. if (in.getId()==null){
  303. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"编号"));
  304. return res;
  305. }
  306. return res.data(expenseAccountService.updateMain(in));
  307. }
  308. /**
  309. * 修改实报金额
  310. * @param type 类型 1报销与费用 2费用详细
  311. * @param id 编号
  312. * @param amount 金额
  313. * @return
  314. */
  315. @RequestMapping(value = "/updateRealAmount",method = RequestMethod.POST)
  316. public Result updateRealAmount(Integer type ,Integer id,BigDecimal amount){
  317. Result res =new Result();
  318. if (id==null){
  319. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"编号"));
  320. return res;
  321. }
  322. if (type==null){
  323. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"分类"));
  324. return res;
  325. }
  326. if (amount==null){
  327. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"金额"));
  328. return res;
  329. }
  330. return res.data(expenseAccountService.updateRealAmount( type , id, amount));
  331. }
  332. }