PlanQuarterController.java 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  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.poi.ExcelUtil;
  16. import com.ozs.framework.web.service.TokenService;
  17. import com.ozs.plan.doman.PlanQuarter;
  18. import com.ozs.plan.doman.vo.requestVo.PlanQuarterStandardVo;
  19. import com.ozs.plan.doman.vo.responseVo.PlanQuarterResponseVo;
  20. import com.ozs.plan.service.PlanQuarterService;
  21. import com.ozs.plan.service.impl.PlanQuarterServiceImpl;
  22. import com.ozs.system.service.ISysDeptService;
  23. import io.swagger.annotations.Api;
  24. import io.swagger.annotations.ApiOperation;
  25. import org.springframework.beans.factory.annotation.Autowired;
  26. import org.springframework.util.ObjectUtils;
  27. import org.springframework.web.bind.annotation.PostMapping;
  28. import org.springframework.web.bind.annotation.RequestBody;
  29. import org.springframework.web.bind.annotation.RequestMapping;
  30. import org.springframework.web.bind.annotation.RestController;
  31. import org.springframework.web.multipart.MultipartFile;
  32. import javax.servlet.http.HttpServletRequest;
  33. import javax.servlet.http.HttpServletResponse;
  34. import java.util.ArrayList;
  35. import java.util.List;
  36. import java.util.stream.Collectors;
  37. /**
  38. * 季度计划信息控制层
  39. *
  40. * @author buzhanyi
  41. */
  42. @Api(tags = "季度计划")
  43. @RestController
  44. @RequestMapping("/plan/quarter")
  45. public class PlanQuarterController extends BaseController {
  46. @Autowired
  47. private PlanQuarterService quarterService;
  48. @Autowired
  49. private PlanQuarterServiceImpl quarterServiceImpl;
  50. @Autowired
  51. private TokenService tokenService;
  52. @Autowired
  53. private ISysDeptService iSysDeptService;
  54. @ApiOperation(value = "查询季度计划")
  55. @PostMapping("/list")
  56. @Log(title = ModularConstans.planQuarter, businessType = BusinessType.QUERY)
  57. public AjaxResult list(@RequestBody PlanQuarterStandardVo vo, HttpServletRequest request) {
  58. List<PlanQuarterResponseVo> planQuarterList = new ArrayList<>();
  59. try {
  60. LambdaQueryWrapper<PlanQuarter> lw = new LambdaQueryWrapper<>();
  61. if (!ObjectUtils.isEmpty(vo.getProjectName())) {
  62. lw.like(PlanQuarter::getProjectName, vo.getProjectName());
  63. }
  64. if (!ObjectUtils.isEmpty(vo.getPurchaseServices())) {
  65. lw.eq(PlanQuarter::getPurchaseServices, vo.getPurchaseServices());
  66. }
  67. if (!ObjectUtils.isEmpty(vo.getIsExcess())) {
  68. lw.eq(PlanQuarter::getIsExcess, vo.getIsExcess());
  69. }
  70. if (!ObjectUtils.isEmpty(vo.getProjectStatus())) {
  71. lw.eq(PlanQuarter::getProjectStatus, vo.getProjectStatus());
  72. } else {
  73. lw.in(PlanQuarter::getProjectStatus, "1,3");
  74. }
  75. if (!ObjectUtils.isEmpty(vo.getBeginTime())) {
  76. lw.ge(PlanQuarter::getPlanDemandSubTime, vo.getBeginTime());
  77. }
  78. if (!ObjectUtils.isEmpty(vo.getEndTime())) {
  79. lw.le(PlanQuarter::getPlanDemandSubTime, vo.getEndTime());
  80. }
  81. lw.eq(PlanQuarter::getDelFlay, DataIsDelete.DataNOTDelete);
  82. LoginUser loginUser = tokenService.getLoginUser(request);
  83. // 添加数据权限
  84. List<String> roleKeys = loginUser.getUser().getRoles().stream().map(SysRole::getRoleKey).collect(Collectors.toList());
  85. if (roleKeys.contains(Constants.DEMAND_UNIT)) {
  86. // 需求单位
  87. /*(purchase_dept_id = 当前用户deptID) */
  88. lw.eq(PlanQuarter::getPurchaseDeptId, loginUser.getDeptId());
  89. } else if (roleKeys.contains(Constants.PURCHASING_MANAGEMENT)
  90. || roleKeys.contains(Constants.PURCHASE_SERVICES)) {
  91. // 采购管理部门 或 采购办
  92. /* (purchase_dept_id = 当前用户deptID AND is_excess = 0)
  93. OR
  94. (purchase_dept_id IN (当前用户 子deptId 集合) and AND is_excess = 1)
  95. */
  96. SysDept sysDept = new SysDept();
  97. sysDept.setParentId(loginUser.getDeptId());
  98. sysDept.setStatus("0");
  99. List<Long> childDeptIds = iSysDeptService.selectDeptList(sysDept)
  100. .stream()
  101. .map(SysDept::getDeptId)
  102. .collect(Collectors.toList());
  103. if (ObjectUtils.isEmpty(childDeptIds)) {
  104. lw.and((wrapper) -> {
  105. wrapper.eq(PlanQuarter::getIsExcess, 0);
  106. wrapper.eq(PlanQuarter::getPurchaseDeptId, loginUser.getDeptId());
  107. });
  108. } else {
  109. lw.and((wrapper) -> {
  110. wrapper.eq(PlanQuarter::getIsExcess, 0);
  111. wrapper.eq(PlanQuarter::getPurchaseDeptId, loginUser.getDeptId());
  112. })
  113. .or((wrapper) -> {
  114. wrapper.eq(PlanQuarter::getIsExcess, 1);
  115. wrapper.in(PlanQuarter::getPurchaseDeptId, childDeptIds);
  116. });
  117. }
  118. }
  119. List<PlanQuarter> list = quarterService.list(lw);
  120. planQuarterList = quarterServiceImpl.changeTo(list);
  121. } catch (Exception e) {
  122. e.printStackTrace();
  123. }
  124. Page pages = PageUtils.getPages(vo.getPageNum().intValue(), vo.getPageSize().intValue(), planQuarterList);
  125. return AjaxResult.success(pages);
  126. }
  127. @ApiOperation(value = "审核单位查询季度计划")
  128. @PostMapping("/examineList")
  129. @Log(title = ModularConstans.planQuarter, businessType = BusinessType.QUERY)
  130. public AjaxResult examineList(@RequestBody PlanQuarterStandardVo vo, HttpServletRequest request) {
  131. List<PlanQuarterResponseVo> planQuarterList = new ArrayList<>();
  132. try {
  133. LambdaQueryWrapper<PlanQuarter> lw = new LambdaQueryWrapper<>();
  134. if (!ObjectUtils.isEmpty(vo.getProjectName())) {
  135. lw.like(PlanQuarter::getProjectName, vo.getProjectName());
  136. }
  137. if (!ObjectUtils.isEmpty(vo.getPurchaseServices())) {
  138. lw.eq(PlanQuarter::getPurchaseServices, vo.getPurchaseServices());
  139. }
  140. if (!ObjectUtils.isEmpty(vo.getIsExcess())) {
  141. lw.eq(PlanQuarter::getIsExcess, vo.getIsExcess());
  142. }
  143. if (!ObjectUtils.isEmpty(vo.getProjectStatus())) {
  144. lw.eq(PlanQuarter::getProjectStatus, vo.getProjectStatus());
  145. }
  146. if (!ObjectUtils.isEmpty(vo.getBeginTime())) {
  147. lw.ge(PlanQuarter::getPlanDemandSubTime, vo.getBeginTime());
  148. }
  149. if (!ObjectUtils.isEmpty(vo.getEndTime())) {
  150. lw.le(PlanQuarter::getPlanDemandSubTime, vo.getEndTime());
  151. }
  152. lw.eq(PlanQuarter::getDelFlay, DataIsDelete.DataNOTDelete);
  153. LoginUser loginUser = tokenService.getLoginUser(request);
  154. // 添加数据权限
  155. List<String> roleKeys = loginUser.getUser().getRoles().stream().map(SysRole::getRoleKey).collect(Collectors.toList());
  156. if (roleKeys.contains(Constants.DEMAND_UNIT)) {
  157. // 需求单位
  158. /*(purchase_dept_id = 当前用户deptID) */
  159. lw.eq(PlanQuarter::getPurchaseDeptId, loginUser.getDeptId());
  160. } else if (roleKeys.contains(Constants.PURCHASING_MANAGEMENT)
  161. || roleKeys.contains(Constants.PURCHASE_SERVICES)) {
  162. // 采购管理部门 或 采购办
  163. /* (purchase_dept_id = 当前用户deptID AND is_excess = 0)
  164. OR
  165. (purchase_dept_id IN (当前用户 子deptId 集合) and AND is_excess = 1)
  166. */
  167. SysDept sysDept = new SysDept();
  168. sysDept.setParentId(loginUser.getDeptId());
  169. sysDept.setStatus("0");
  170. List<Long> childDeptIds = iSysDeptService.selectDeptList(sysDept)
  171. .stream()
  172. .map(SysDept::getDeptId)
  173. .collect(Collectors.toList());
  174. if (ObjectUtils.isEmpty(childDeptIds)) {
  175. lw.and((wrapper) -> {
  176. wrapper.eq(PlanQuarter::getIsExcess, 0);
  177. wrapper.eq(PlanQuarter::getPurchaseDeptId, loginUser.getDeptId());
  178. });
  179. } else {
  180. lw.and((wrapper) -> {
  181. wrapper.eq(PlanQuarter::getIsExcess, 0);
  182. wrapper.eq(PlanQuarter::getPurchaseDeptId, loginUser.getDeptId());
  183. })
  184. .or((wrapper) -> {
  185. wrapper.eq(PlanQuarter::getIsExcess, 1);
  186. wrapper.in(PlanQuarter::getPurchaseDeptId, childDeptIds);
  187. });
  188. }
  189. }
  190. List<PlanQuarter> list = quarterService.list(lw);
  191. planQuarterList = quarterServiceImpl.changeTo(list);
  192. } catch (Exception e) {
  193. e.printStackTrace();
  194. }
  195. Page pages = PageUtils.getPages(vo.getPageNum().intValue(), vo.getPageSize().intValue(), planQuarterList);
  196. return AjaxResult.success(pages);
  197. }
  198. @ApiOperation(value = "导出季度计划数据")
  199. @Log(title = ModularConstans.planQuarter, businessType = BusinessType.EXPORT)
  200. @PostMapping("/exportPlan")
  201. public void exportPlan(HttpServletResponse response, @RequestBody PlanQuarterStandardVo quarterStandardVo) throws Exception {
  202. List<PlanQuarterResponseVo> list = quarterService.selectPlanQuarterListEXP(quarterStandardVo);
  203. ExcelUtil<PlanQuarterResponseVo> util = new ExcelUtil<>(PlanQuarterResponseVo.class);
  204. util.exportExcel(response, list, "季度计划数据");
  205. }
  206. @ApiOperation(value = "导出季度计划数据(审核单位)")
  207. @PostMapping("/exportPlanExamine")
  208. @Log(title = ModularConstans.planQuarter, businessType = BusinessType.EXPORT)
  209. public void exportPlanExamine(HttpServletResponse response, @RequestBody PlanQuarterStandardVo quarterStandardVo) throws Exception {
  210. List<PlanQuarterResponseVo> list = quarterService.selectPlanQuarterExamineListEXP(quarterStandardVo);
  211. ExcelUtil<PlanQuarterResponseVo> util = new ExcelUtil<>(PlanQuarterResponseVo.class);
  212. util.exportExcel(response, list, "季度计划数据(审核单位)");
  213. }
  214. @ApiOperation(value = "创建季度计划")
  215. @PostMapping("/add")
  216. @Log(title = ModularConstans.planQuarter, businessType = BusinessType.INSERT)
  217. public AjaxResult add(@RequestBody PlanQuarterStandardVo quarterStandardVo, HttpServletRequest request) {
  218. //获取采购单位-
  219. LoginUser loginUser = tokenService.getLoginUser(request);
  220. quarterStandardVo.setPurchaseDeptId(String.valueOf(loginUser.getDeptId()));
  221. quarterStandardVo.setCreated(String.valueOf(loginUser.getUserId()));
  222. return quarterService.insertPlanQuarter(quarterStandardVo);
  223. }
  224. @ApiOperation(value = "修改季度计划")
  225. @PostMapping("/update")
  226. @Log(title = ModularConstans.planQuarter, businessType = BusinessType.UPDATE)
  227. public AjaxResult update(@RequestBody PlanQuarterStandardVo quarterStandardVo, HttpServletRequest request) {
  228. LoginUser loginUser = tokenService.getLoginUser(request);
  229. quarterStandardVo.setUpdated(String.valueOf(loginUser.getUserId()));
  230. return quarterService.update(quarterStandardVo);
  231. }
  232. @ApiOperation(value = "提交季度计划")
  233. @PostMapping("/commit")
  234. @Log(title = ModularConstans.planQuarter, businessType = BusinessType.UPDATE)
  235. public AjaxResult commit(@RequestBody PlanQuarterStandardVo quarterStandardVo) {
  236. return quarterService.commit(quarterStandardVo);
  237. }
  238. @ApiOperation(value = "删除季度计划")
  239. @PostMapping("/delete")
  240. @Log(title = ModularConstans.planQuarter, businessType = BusinessType.DELETE)
  241. public AjaxResult delete(@RequestBody PlanQuarterStandardVo quarterStandardVo) {
  242. return quarterService.deletePlanQuarterById(quarterStandardVo.getPlanPracticalId());
  243. }
  244. @ApiOperation(value = "根据id获取季度计划信息")
  245. @PostMapping("/view")
  246. @Log(title = ModularConstans.planQuarter, businessType = BusinessType.QUERY)
  247. public AjaxResult view(@RequestBody PlanQuarterStandardVo quarterStandardVo) {
  248. return quarterService.view(quarterStandardVo);
  249. }
  250. @ApiOperation(value = "审核季度计划通过")
  251. @PostMapping("/reviewTo")
  252. @Log(title = ModularConstans.planQuarter, businessType = BusinessType.UPDATE)
  253. public AjaxResult reviewTo(@RequestBody PlanQuarterStandardVo quarterStandardVo, HttpServletRequest request) {
  254. LoginUser loginUser = tokenService.getLoginUser(request);
  255. quarterStandardVo.setUpdated(String.valueOf(loginUser.getUserId()));
  256. return quarterService.reviewTo(quarterStandardVo);
  257. }
  258. @ApiOperation(value = "审核季度计划退回")
  259. @PostMapping("/reviewReturn")
  260. @Log(title = ModularConstans.planQuarter, businessType = BusinessType.UPDATE)
  261. public AjaxResult reviewReturn(@RequestBody PlanQuarterStandardVo quarterStandardVo, HttpServletRequest request) {
  262. LoginUser loginUser = tokenService.getLoginUser(request);
  263. quarterStandardVo.setUpdated(String.valueOf(loginUser.getUserId()));
  264. return quarterService.reviewReturn(quarterStandardVo);
  265. }
  266. @ApiOperation(value = "申请修改季度计划")
  267. @PostMapping("/appUpdate")
  268. @Log(title = ModularConstans.planQuarter, businessType = BusinessType.UPDATE)
  269. public AjaxResult appUpdate(@RequestBody PlanQuarterStandardVo quarterStandardVo) {
  270. return quarterService.appUpdate(quarterStandardVo);
  271. }
  272. @ApiOperation(value = "发函催告")
  273. @PostMapping("/sendLetter")
  274. @Log(title = ModularConstans.planQuarter, businessType = BusinessType.UPDATE)
  275. public AjaxResult sendLetter(@RequestBody PlanQuarterStandardVo quarterStandardVo) {
  276. return quarterService.sendLetter(quarterStandardVo);
  277. }
  278. @ApiOperation(value = "上传计划关联文件后保存文件信息")
  279. @PostMapping("/upLoadPlanFile")
  280. @Log(title = ModularConstans.planQuarter, businessType = BusinessType.OTHER)
  281. public AjaxResult upLoadPlanFile(@RequestBody PlanQuarterStandardVo quarterStandardVo) {
  282. return quarterService.upLoadPlanFile(quarterStandardVo);
  283. }
  284. //
  285. //@ApiOperation(value = "下载计划关联文件")
  286. //@PostMapping("/downLoadPlanFile")
  287. //public AjaxResult downLoadPlanFile(@RequestBody PlanQuarterStandardVo quarterStandardVo) {
  288. // return quarterService.downLoadPlanFile(quarterStandardVo);
  289. //}
  290. @ApiOperation(value = "导入季度计划数据")
  291. @PostMapping("/importData")
  292. @Log(title = ModularConstans.planQuarter, businessType = BusinessType.INSERT)
  293. public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception {
  294. ExcelUtil<PlanQuarterStandardVo> util = new ExcelUtil<>(PlanQuarterStandardVo.class);
  295. List<PlanQuarterStandardVo> quarter = util.importExcel(file.getInputStream());
  296. //获取采购单位-
  297. LoginUser loginUser = getLoginUser();
  298. String message = quarterService.importPlanQuarter(quarter, updateSupport, loginUser);
  299. return success(message);
  300. }
  301. }