PlanYearsController.java 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. package com.ozs.web.controller.plan;
  2. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  3. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  4. import com.ozs.common.annotation.Log;
  5. import com.ozs.common.constant.Constants;
  6. import com.ozs.common.constant.ModularConstans;
  7. import com.ozs.common.core.controller.BaseController;
  8. import com.ozs.common.core.domain.AjaxResult;
  9. import com.ozs.common.core.domain.entity.SysDept;
  10. import com.ozs.common.core.domain.entity.SysRole;
  11. import com.ozs.common.core.domain.model.LoginUser;
  12. import com.ozs.common.enums.BusinessType;
  13. import com.ozs.common.enums.DataIsDelete;
  14. import com.ozs.common.utils.PageUtils;
  15. import com.ozs.common.utils.file.FileUtils;
  16. import com.ozs.common.utils.poi.ExcelUtil;
  17. import com.ozs.framework.web.service.TokenService;
  18. import com.ozs.plan.doman.PlanYears;
  19. import com.ozs.plan.doman.vo.requestVo.PlanYearsStandardVo;
  20. import com.ozs.plan.doman.vo.responseVo.PlanYearsResponseVo;
  21. import com.ozs.plan.service.PlanYearsService;
  22. import com.ozs.plan.service.impl.PlanYearsServiceImpl;
  23. import com.ozs.system.service.ISysDeptService;
  24. import io.swagger.annotations.Api;
  25. import io.swagger.annotations.ApiOperation;
  26. import lombok.extern.slf4j.Slf4j;
  27. import org.springframework.beans.factory.annotation.Autowired;
  28. import org.springframework.http.MediaType;
  29. import org.springframework.security.access.prepost.PreAuthorize;
  30. import org.springframework.util.ObjectUtils;
  31. import org.springframework.web.bind.annotation.GetMapping;
  32. import org.springframework.web.bind.annotation.PostMapping;
  33. import org.springframework.web.bind.annotation.RequestBody;
  34. import org.springframework.web.bind.annotation.RequestMapping;
  35. import org.springframework.web.bind.annotation.RestController;
  36. import org.springframework.web.multipart.MultipartFile;
  37. import javax.servlet.http.HttpServletRequest;
  38. import javax.servlet.http.HttpServletResponse;
  39. import java.io.InputStream;
  40. import java.text.SimpleDateFormat;
  41. import java.util.ArrayList;
  42. import java.util.Date;
  43. import java.util.List;
  44. import java.util.stream.Collectors;
  45. /**
  46. * 年度计划信息控制层
  47. *
  48. * @author buzhanyi
  49. */
  50. @Api(tags = "年度计划")
  51. @Slf4j
  52. @RestController
  53. @RequestMapping("/plan/planYears")
  54. public class PlanYearsController extends BaseController {
  55. @Autowired
  56. private PlanYearsService planYearsService;
  57. @Autowired
  58. private TokenService tokenService;
  59. @Autowired
  60. private ISysDeptService iSysDeptService;
  61. @Autowired
  62. private PlanYearsServiceImpl planYearsServiceImpl;
  63. @ApiOperation(value = "查询年度计划")
  64. @PostMapping("/list")
  65. @PreAuthorize("@ss.hasPermi('plan:planYears:list')")
  66. @Log(title = ModularConstans.planYear, businessType = BusinessType.QUERY)
  67. public AjaxResult list(@RequestBody PlanYearsStandardVo vo, HttpServletRequest request) {
  68. List<PlanYearsResponseVo> planYearsList = new ArrayList<>();
  69. try {
  70. LambdaQueryWrapper<PlanYears> lw = new LambdaQueryWrapper<PlanYears>();
  71. if (!ObjectUtils.isEmpty(vo.getProjectName())) {
  72. lw.like(PlanYears::getProjectName, vo.getProjectName());
  73. }
  74. if (!ObjectUtils.isEmpty(vo.getPurchaseServices())) {
  75. lw.eq(PlanYears::getPurchaseServices, vo.getPurchaseServices());
  76. }
  77. if (!ObjectUtils.isEmpty(vo.getIsExcess())) {
  78. lw.eq(PlanYears::getIsExcess, vo.getIsExcess());
  79. }
  80. if (!ObjectUtils.isEmpty(vo.getProjectStatus())) {
  81. lw.eq(PlanYears::getProjectStatus, vo.getProjectStatus());
  82. }
  83. if (!ObjectUtils.isEmpty(vo.getBeginTime())) {
  84. lw.ge(PlanYears::getPlanDemandSubTime, vo.getBeginTime());
  85. }
  86. if (!ObjectUtils.isEmpty(vo.getEndTime())) {
  87. SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
  88. SimpleDateFormat dateFormatT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS");
  89. Date parse = dateFormatT.parse(dateFormat.format(vo.getEndTime()) + " 23:59:59:999");
  90. lw.le(PlanYears::getPlanDemandSubTime, parse);
  91. }
  92. lw.eq(PlanYears::getDelFlay, DataIsDelete.DataNOTDelete.getCode());
  93. lw.orderBy(true, false, PlanYears::getCreateTime);
  94. List<PlanYears> planYears = planYearsService.list(lw);
  95. planYearsList = planYearsServiceImpl.changeTo(planYears);
  96. } catch (Exception e) {
  97. e.printStackTrace();
  98. }
  99. Page pages = PageUtils.getPages(vo.getPageNum().intValue(), vo.getPageSize().intValue(), planYearsList);
  100. return AjaxResult.success(pages);
  101. }
  102. @ApiOperation(value = "审核单位查询年度计划")
  103. @PostMapping("/examineList")
  104. @PreAuthorize("@ss.hasPermi('plan:planYears:examineList')")
  105. @Log(title = ModularConstans.planYear, businessType = BusinessType.QUERY)
  106. public AjaxResult examineList(@RequestBody PlanYearsStandardVo vo, HttpServletRequest request) {
  107. List<PlanYearsResponseVo> planYearsList = new ArrayList<>();
  108. try {
  109. LoginUser loginUser = tokenService.getLoginUser(request);
  110. vo.setPurchaseDeptId(String.valueOf(loginUser.getDeptId()));
  111. vo.setCreated(String.valueOf(loginUser.getUserId()));
  112. List<PlanYears> planYears = planYearsService.queryPage(vo);
  113. if (!ObjectUtils.isEmpty(planYears) && !ObjectUtils.isEmpty(planYears.size())) {
  114. planYearsList = planYearsServiceImpl.changeTo(planYears);
  115. }
  116. } catch (Exception e) {
  117. e.printStackTrace();
  118. }
  119. Page pages = PageUtils.getPages(vo.getPageNum().intValue(), vo.getPageSize().intValue(), planYearsList);
  120. return AjaxResult.success(pages);
  121. }
  122. @ApiOperation(value = "导出年度计划数据")
  123. @PostMapping("/exportPlan")
  124. @PreAuthorize("@ss.hasPermi('plan:planYears:exportPlan')")
  125. @Log(title = ModularConstans.planYear, businessType = BusinessType.EXPORT)
  126. public void exportPlan(HttpServletResponse response, @RequestBody PlanYearsStandardVo yearsStandardVo, HttpServletRequest request) throws Exception {
  127. LoginUser loginUser = tokenService.getLoginUser(request);
  128. List<PlanYearsResponseVo> list = planYearsService.selectPlanYearsListEXP(yearsStandardVo, loginUser);
  129. ExcelUtil<PlanYearsResponseVo> util = new ExcelUtil<>(PlanYearsResponseVo.class);
  130. util.exportExcel(response, list, "年度计划数据");
  131. }
  132. @ApiOperation(value = "导出年度计划数据(审核单位)")
  133. @PreAuthorize("@ss.hasPermi('plan:planYears:exportPlanExamine')")
  134. @PostMapping("/exportPlanExamine")
  135. @Log(title = ModularConstans.planYear, businessType = BusinessType.EXPORT)
  136. public void exportPlanExamine(HttpServletResponse response, @RequestBody PlanYearsStandardVo yearsStandardVo, HttpServletRequest request) throws Exception {
  137. LoginUser loginUser = tokenService.getLoginUser(request);
  138. List<PlanYearsResponseVo> list = planYearsService.selectPlanYearsExamineListEXP(yearsStandardVo, loginUser);
  139. ExcelUtil<PlanYearsResponseVo> util = new ExcelUtil<>(PlanYearsResponseVo.class);
  140. util.exportExcel(response, list, "年度计划数据(审核单位)");
  141. }
  142. @ApiOperation(value = "创建年度计划")
  143. @PostMapping("/add")
  144. @PreAuthorize("@ss.hasPermi('plan:planYears:add')")
  145. @Log(title = ModularConstans.planYear, businessType = BusinessType.INSERT)
  146. public AjaxResult add(@RequestBody PlanYearsStandardVo yearsStandardVo, HttpServletRequest request) {
  147. //获取采购单位-
  148. LoginUser loginUser = tokenService.getLoginUser(request);
  149. yearsStandardVo.setPurchaseDeptId(String.valueOf(loginUser.getDeptId()));
  150. yearsStandardVo.setCreated(String.valueOf(loginUser.getUserId()));
  151. return planYearsService.insertPlanYears(yearsStandardVo);
  152. }
  153. @ApiOperation(value = "修改年度计划")
  154. @PostMapping("/update")
  155. @PreAuthorize("@ss.hasPermi('plan:planYears:update')")
  156. @Log(title = ModularConstans.planYear, businessType = BusinessType.UPDATE)
  157. public AjaxResult update(@RequestBody PlanYearsStandardVo yearsStandardVo, HttpServletRequest request) {
  158. LoginUser loginUser = tokenService.getLoginUser(request);
  159. yearsStandardVo.setPurchaseDeptId(String.valueOf(loginUser.getDeptId()));
  160. yearsStandardVo.setUpdated(String.valueOf(loginUser.getUserId()));
  161. return planYearsService.update(yearsStandardVo);
  162. }
  163. @ApiOperation(value = "提交年度计划")
  164. @PostMapping("/commit")
  165. @PreAuthorize("@ss.hasPermi('plan:planYears:commit')")
  166. @Log(title = ModularConstans.planYear, businessType = BusinessType.UPDATE)
  167. public AjaxResult commit(@RequestBody PlanYearsStandardVo yearsStandardVo) {
  168. return planYearsService.commit(yearsStandardVo);
  169. }
  170. @ApiOperation(value = "删除年度计划")
  171. @PostMapping("/delete")
  172. @PreAuthorize("@ss.hasPermi('plan:planYears:delete')")
  173. @Log(title = ModularConstans.planYear, businessType = BusinessType.DELETE)
  174. public AjaxResult delete(@RequestBody PlanYearsStandardVo yearsStandardVo) {
  175. return planYearsService.deletePlanYearsById(yearsStandardVo.getPlanYearId());
  176. }
  177. @ApiOperation(value = "根据id获取年度计划信息")
  178. @PostMapping("/view")
  179. // @PreAuthorize("@ss.hasPermi('plan:planYears:view')") 首页调用的接口不需要权限
  180. @Log(title = ModularConstans.planYear, businessType = BusinessType.QUERY)
  181. public AjaxResult view(@RequestBody PlanYearsStandardVo yearsStandardVo) {
  182. return planYearsService.view(yearsStandardVo);
  183. }
  184. @ApiOperation(value = "审核年度计划通过")
  185. @PostMapping("/reviewTo")
  186. @Log(title = ModularConstans.planYear, businessType = BusinessType.UPDATE)
  187. @PreAuthorize("@ss.hasPermi('plan:planYears:reviewTo')")
  188. public AjaxResult reviewTo(@RequestBody PlanYearsStandardVo yearsStandardVo, HttpServletRequest request) {
  189. LoginUser loginUser = tokenService.getLoginUser(request);
  190. yearsStandardVo.setUpdated(String.valueOf(loginUser.getUserId()));
  191. return planYearsService.reviewTo(yearsStandardVo);
  192. }
  193. @ApiOperation(value = "审核年度计划退回")
  194. @PostMapping("/reviewReturn")
  195. @PreAuthorize("@ss.hasPermi('plan:planYears:reviewReturn')")
  196. @Log(title = ModularConstans.planYear, businessType = BusinessType.UPDATE)
  197. public AjaxResult reviewReturn(@RequestBody PlanYearsStandardVo yearsStandardVo, HttpServletRequest request) {
  198. LoginUser loginUser = tokenService.getLoginUser(request);
  199. yearsStandardVo.setUpdated(String.valueOf(loginUser.getUserId()));
  200. return planYearsService.reviewReturn(yearsStandardVo);
  201. }
  202. @ApiOperation(value = "申请修改年度计划")
  203. @PostMapping("/appUpdate")
  204. @PreAuthorize("@ss.hasPermi('plan:planYears:appUpdate')")
  205. @Log(title = ModularConstans.planYear, businessType = BusinessType.UPDATE)
  206. public AjaxResult appUpdate(@RequestBody PlanYearsStandardVo yearsStandardVo) {
  207. return planYearsService.appUpdate(yearsStandardVo);
  208. }
  209. @ApiOperation(value = "发函催告")
  210. @PostMapping("/sendLetter")
  211. @PreAuthorize("@ss.hasPermi('plan:planYears:sendLetter')")
  212. @Log(title = ModularConstans.planYear, businessType = BusinessType.UPDATE)
  213. public AjaxResult sendLetter(@RequestBody PlanYearsStandardVo yearsStandardVo) {
  214. return planYearsService.sendLetter(yearsStandardVo);
  215. }
  216. @ApiOperation(value = "上传计划关联文件后保存文件信息")
  217. @PostMapping("/upLoadPlanFile")
  218. @PreAuthorize("@ss.hasPermi('plan:planYears:upLoadPlanFile')")
  219. @Log(title = ModularConstans.planYear, businessType = BusinessType.OTHER)
  220. public AjaxResult upLoadPlanFile(@RequestBody PlanYearsStandardVo yearsStandardVo) {
  221. return planYearsService.upLoadPlanFile(yearsStandardVo);
  222. }
  223. //
  224. //@ApiOperation(value = "下载计划关联文件")
  225. //@PostMapping("/downLoadPlanFile")
  226. //public AjaxResult downLoadPlanFile(@RequestBody PlanYearsStandardVo yearsStandardVo) {
  227. // return planYearsService.downLoadPlanFile(yearsStandardVo);
  228. @ApiOperation(value = "导入年度计划数据")
  229. @PostMapping("/importData")
  230. @PreAuthorize("@ss.hasPermi('plan:planYears:importData')")
  231. @Log(title = ModularConstans.planYear, businessType = BusinessType.INSERT)
  232. public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception {
  233. ExcelUtil<PlanYearsStandardVo> util = new ExcelUtil<>(PlanYearsStandardVo.class);
  234. List<PlanYearsStandardVo> planYears = util.importExcel(file.getInputStream());
  235. //获取采购单位-
  236. LoginUser loginUser = getLoginUser();
  237. String message = planYearsService.importPlanYears(planYears, updateSupport, loginUser);
  238. return success(message);
  239. }
  240. @ApiOperation(value = "系统首页计划管理")
  241. @GetMapping("/planYearsTotal")
  242. @PreAuthorize("@ss.hasPermi('plan:planYears:planYearsTotal')")
  243. @Log(title = ModularConstans.planYear, businessType = BusinessType.QUERY)
  244. public AjaxResult planYearsTotal() {
  245. return success(planYearsService.count());
  246. }
  247. @ApiOperation("模板下载")
  248. @GetMapping("/downloaExcel")
  249. public void downloadZip(HttpServletResponse response) {
  250. try {
  251. InputStream resourceAsStream = this.getClass().getResourceAsStream("/template/planYears.xlsx");
  252. response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
  253. FileUtils.setAttachmentResponseHeader(response, "年度计划导入模板.xlsx");
  254. FileUtils.writeBytesByInput(resourceAsStream, response.getOutputStream());
  255. } catch (Exception e) {
  256. log.error("下载文件失败", e);
  257. }
  258. }
  259. }