d513177abaa9c4b9da7fea0831ef7d4de32c1ae3.svn-base 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. package cn.com.goldenwater.dcproj.controller.general;
  2. import cn.com.goldenwater.core.web.BaseController;
  3. import cn.com.goldenwater.core.web.BaseResponse;
  4. import cn.com.goldenwater.dcproj.constValue.BisInspEnum;
  5. import cn.com.goldenwater.dcproj.constValue.CommonLabel;
  6. import cn.com.goldenwater.dcproj.param.TypeParam;
  7. import cn.com.goldenwater.dcproj.service.BisInspKeyRegisterService;
  8. import cn.com.goldenwater.dcproj.service.BisInspObjStrategy;
  9. import cn.com.goldenwater.dcproj.service.OlBisInspOrgService;
  10. import cn.com.goldenwater.dcproj.service.impl.system.BisInspObjFactory;
  11. import cn.com.goldenwater.dcproj.target.Authority;
  12. import cn.com.goldenwater.dcproj.utils.AdLevelUtil;
  13. import cn.com.goldenwater.dcproj.utils.DateUtils;
  14. import cn.com.goldenwater.target.CheckException;
  15. import cn.com.goldenwater.util.common.SqlUtils;
  16. import com.github.pagehelper.PageInfo;
  17. import io.swagger.annotations.Api;
  18. import io.swagger.annotations.ApiOperation;
  19. import org.apache.commons.lang3.StringUtils;
  20. import org.springframework.beans.factory.annotation.Autowired;
  21. import org.springframework.beans.factory.annotation.Value;
  22. import org.springframework.web.bind.annotation.RequestBody;
  23. import org.springframework.web.bind.annotation.RequestMapping;
  24. import org.springframework.web.bind.annotation.RequestMethod;
  25. import org.springframework.web.bind.annotation.RestController;
  26. import javax.servlet.http.HttpServletRequest;
  27. import javax.servlet.http.HttpServletResponse;
  28. import java.text.SimpleDateFormat;
  29. import java.util.Date;
  30. import java.util.Optional;
  31. @Api(value = "督查类型列表管理", tags = "list督查对象管理")
  32. @RestController
  33. @RequestMapping("/dc/insp/rsvrRgstr/list")
  34. public class RgstrController extends BaseController {
  35. @Value("${pagehelper.helperDialect}")
  36. private String sqlDialect ;
  37. @Autowired
  38. private BisInspObjFactory factory;
  39. @Autowired
  40. private BisInspKeyRegisterService bisInspKeyRegisterService;
  41. @Autowired
  42. private OlBisInspOrgService olBisInspOrgService;
  43. @ApiOperation(value = "根据记录人员id获取需要督查的172工程列表树形结构")
  44. @RequestMapping(value = "/tree", method = RequestMethod.POST)
  45. public BaseResponse tree(@RequestBody TypeParam typeParam) {
  46. typeParam.setPresId(getCurrentPersId());
  47. typeParam.setOrgId(getCurrentOrgId());
  48. typeParam.setProvince(olBisInspOrgService.getProvince(getCurrentOrgId()));
  49. typeParam.setNowTime(DateUtils.getToday("yyyy-MM-dd"));
  50. typeParam.setInIdsSql(SqlUtils.getinIdsSql(typeParam.getPresId(), typeParam.getProvince()));
  51. if (!StringUtils.isBlank(typeParam.getAdCodes())) {
  52. typeParam.setAdCodes(AdLevelUtil.getListAddvcd(typeParam.getAdCodes()));
  53. }
  54. BisInspEnum bisInspEnum = BisInspEnum.getEnumByKey(typeParam.getType());
  55. Optional.ofNullable(bisInspEnum).orElseThrow(() -> new CheckException("缺少督查项的KEY"));
  56. switch (bisInspEnum) {
  57. case EMPWTRUN:
  58. typeParam.setpType(BisInspEnum.EMPWTRUN.getValue());
  59. return buildSuccessResponse(bisInspKeyRegisterService.treeEmpwtrun(typeParam));
  60. case EMPWT:
  61. typeParam.setpType(BisInspEnum.EMPWT.getValue());
  62. return buildSuccessResponse(bisInspKeyRegisterService.treeEmpwt(typeParam));
  63. default:
  64. throw new CheckException("只能选择水利工程建设、水利工程运行!");
  65. }
  66. }
  67. @Authority
  68. @ApiOperation(value = "根据记录人员id获取需要督查水库(type=rsvr),农水(type=vill),水毁(type=rect)," +
  69. "172工程列表(type=empwt),地下水(type=grw),水闸(type=waga),稽察项目(type=pawp)persId人员id,plnaId批次id")
  70. @RequestMapping(value = "/type", method = RequestMethod.POST)
  71. public Object listType(@RequestBody TypeParam typeParam, HttpServletResponse response, HttpServletRequest request) {
  72. if (StringUtils.isBlank(typeParam.getpType()) && StringUtils.isBlank(typeParam.getType())) {
  73. throw new CheckException("缺少参数,type 或 pType");
  74. }
  75. typeParam.setPresId(getCurrentPersId());
  76. String adPr = AdLevelUtil.getAddvcd(olBisInspOrgService.getProvince(getCurrentOrgId()));
  77. if (StringUtils.isBlank(typeParam.getAdCode())) {
  78. typeParam.setAdCode(adPr);
  79. }
  80. if (StringUtils.isBlank(typeParam.getpType())) {
  81. for (BisInspEnum inspEnum : BisInspEnum.values()) {
  82. if (typeParam.getType().equals(inspEnum.getKey())) {
  83. typeParam.setpType(inspEnum.getValue());
  84. break;
  85. }
  86. }
  87. }
  88. if (StringUtils.isBlank(typeParam.getTabType())) {
  89. typeParam.setTabType(CommonLabel.TAB_TYPE);
  90. }
  91. String nowTime = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
  92. typeParam.setNowTime(nowTime);
  93. BisInspObjStrategy strategy = factory.createStrategy(typeParam.getpType());
  94. typeParam = setParam(typeParam, request);
  95. PageInfo pageInfo = strategy.findObjPageByType(typeParam, response);
  96. return buildSuccessResponse(pageInfo);
  97. }
  98. @Authority
  99. @ApiOperation(value = "【获取全部】根据记录人员id获取需要督查水库(type=rsvr),农水(type=vill),水毁(type=rect),172工程列表(type=empwt,pType=4建设,7运行),地下水(type=grw)水闸(type=waga),persId人员id,plnaId批次id")
  100. @RequestMapping(value = "/typeAll", method = RequestMethod.POST)
  101. public Object listTypeAll(@RequestBody TypeParam typeParam, HttpServletRequest request) {
  102. typeParam.setPresId(getCurrentPersId());
  103. BisInspEnum bisInspEnum = null;
  104. for (BisInspEnum inspEnum : BisInspEnum.values()) {
  105. if (StringUtils.isBlank(typeParam.getType())) {
  106. continue;
  107. }
  108. if (typeParam.getType().equals(inspEnum.getKey())) {
  109. bisInspEnum = inspEnum;
  110. break;
  111. }
  112. }
  113. if (bisInspEnum != null) {
  114. if (StringUtils.isBlank(typeParam.getpType())) {
  115. typeParam.setpType(bisInspEnum.getValue());
  116. }
  117. BisInspObjStrategy strategy = factory.createStrategy(bisInspEnum.getValue());
  118. if (strategy == null) {
  119. throw new CheckException("查询加载异常:" + bisInspEnum.getValue());
  120. }
  121. typeParam = setParam(typeParam, request);
  122. Object result = strategy.findObjListByType(typeParam);
  123. return buildSuccessResponse(result);
  124. }
  125. return buildFailResponse("无重要列表信息!!");
  126. }
  127. private TypeParam setParam(TypeParam typeParam, HttpServletRequest request) {
  128. if (StringUtils.isBlank(typeParam.getTabType())) {
  129. typeParam.setTabType(CommonLabel.TAB_TYPE);
  130. String source = request.getHeader("source");
  131. if (StringUtils.isNotBlank(source)) {
  132. typeParam.setTabType("0");
  133. }
  134. }
  135. String nowTime = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
  136. typeParam.setNowTime(nowTime);
  137. typeParam.setOrgId(getCurrentOrgId());
  138. typeParam.setProvince(olBisInspOrgService.getProvince(getCurrentOrgId()));
  139. typeParam.setPresId(getCurrentPersId());
  140. typeParam.setInIdsSql(SqlUtils.getinIdsSql(typeParam.getPresId(), typeParam.getProvince()));
  141. if (StringUtils.isNotBlank(typeParam.getRsName())) {
  142. typeParam.setName(typeParam.getRsName());
  143. }
  144. if (StringUtils.isNotBlank(typeParam.getAdCode())) {
  145. typeParam.setAdCode(typeParam.getAdCode().replace("00", ""));
  146. }
  147. if (StringUtils.isNotBlank(typeParam.getOrderBy()) && typeParam.getOrderBy().contains("SCHINESE_PINYIN_M")) {
  148. if("mysql".equals(sqlDialect)){
  149. typeParam.setOrderBy("CONVERT( nm USING gbk ) COLLATE gbk_chinese_ci ASC");
  150. }else{
  151. typeParam.setOrderBy("nlssort(nm,'NLS_SORT=SCHINESE_PINYIN_M')");
  152. }
  153. }
  154. if (StringUtils.isNotBlank(typeParam.getOrderBy()) && typeParam.getOrderBy().contains("#")) {
  155. if (typeParam.getOrderBy().startsWith("#")) {
  156. if("mysql".equals(sqlDialect)){
  157. typeParam.setOrderBy("CONVERT( nm USING gbk ) COLLATE gbk_chinese_ci ASC");
  158. }else{
  159. typeParam.setOrderBy("nlssort(nm,'NLS_SORT=SCHINESE_PINYIN_M')");
  160. }
  161. } else {
  162. String orderBy = typeParam.getOrderBy().replace("#", " ");
  163. typeParam.setOrderBy(orderBy);
  164. if("mysql".equals(sqlDialect) && typeParam.getOrderBy().contains("nlssort")){
  165. typeParam.setOrderBy(null);
  166. }
  167. }
  168. }
  169. return typeParam;
  170. }
  171. }