065bc296c2c450f4f5ff6b37e775d4da384982c4.svn-base 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. package cn.com.goldenwater.dcproj.utils;
  2. import cn.com.goldenwater.dcproj.enums.GrwSttpEnum;
  3. import cn.com.goldenwater.dcproj.enums.NormalEnum;
  4. import cn.com.goldenwater.dcproj.model.BisInspGrw;
  5. import com.alibaba.fastjson.JSONObject;
  6. import org.apache.commons.lang3.StringUtils;
  7. import org.apache.commons.lang3.math.NumberUtils;
  8. /**
  9. * 地下水监测站督查评分规则
  10. */
  11. public class GrwScoreRule {
  12. private final int flagSign = 10; //是否有标志牌
  13. private final int flagMark = 5;//是否有水准点
  14. private final int flagExact = 5;//基本信息是否准确(
  15. private final int flagSafeguard = 5;//有无简易保护措施
  16. private final int flagTool = 5;//是否配备检测工具
  17. private final int flagTrain = 5;//委托观测人员是否经过培训
  18. private final int repeatability = 2;//现场比测精度误差(cm) 临界值
  19. private final Long repeatabilityScore = 40L;//现场比测精度误差得分
  20. private final int[] percentage = {80, 90, 95};//单站月统计到报率(%)
  21. private final Long toolProfScore = 10L;//观测人员操作规范、熟练
  22. private final Long[] percentageScore = {0L, 5L, 10L, 15L}; //单站月统计到报率得分
  23. private final Long toolTsoScore = 5L;//测具是否符合有关技术要求
  24. private final Long wellProtScore = 5L;//保护筒外管是否完好无损
  25. private final Long handScore = 15L;//人工监测数据报送是否及时
  26. private final String ruleStr = "{\n" +
  27. "\t\"data\": {\n" +
  28. "\t\t\"essentialInfo\": [{\n" +
  29. "\t\t\t\"key\": \"0\",\n" +
  30. "\t\t\t\"value\": \"0\"\n" +
  31. "\t\t}, {\n" +
  32. "\t\t\t\"key\": \"1\",\n" +
  33. "\t\t\t\"value\": \"5\"\n" +
  34. "\t\t}],\n" +
  35. "\t\t\"protectfacility\": [{\n" +
  36. "\t\t\t\"key\": \"0\",\n" +
  37. "\t\t\t\"value\": \"0\"\n" +
  38. "\t\t}, {\n" +
  39. "\t\t\t\"key\": \"1\",\n" +
  40. "\t\t\t\"value\": \"5\"\n" +
  41. "\t\t}],\n" +
  42. "\t\t\"detectionTool\": [{\n" +
  43. "\t\t\t\"key\": \"0\",\n" +
  44. "\t\t\t\"value\": \"0\"\n" +
  45. "\t\t}, {\n" +
  46. "\t\t\t\"key\": \"1\",\n" +
  47. "\t\t\t\"value\": \"0\"\n" +
  48. "\t\t}],\n" +
  49. "\t\t\"cylinderoutertube\": [{\n" +
  50. "\t\t\t\"key\": \"scoring\",\n" +
  51. "\t\t\t\"value\": \"[0,5]\"\n" +
  52. "\t\t}],\n" +
  53. "\t\t\"fieldcomparisontest\": [{\n" +
  54. "\t\t\t\"key\": \"[0,2]\",\n" +
  55. "\t\t\t\"value\": \"40\"\n" +
  56. "\t\t}, {\n" +
  57. "\t\t\t\"key\": \"(2,100]\",\n" +
  58. "\t\t\t\"value\": \"0\"\n" +
  59. "\t\t}],\n" +
  60. "\t\t\"monthlySingleStation\": [{\n" +
  61. "\t\t\t\"key\": \"[0,80)\",\n" +
  62. "\t\t\t\"value\": \"0\"\n" +
  63. "\t\t}, {\n" +
  64. "\t\t\t\"key\": \"[80,90)\",\n" +
  65. "\t\t\t\"value\": \"5\"\n" +
  66. "\t\t}, {\n" +
  67. "\t\t\t\"key\": \"[90,95)\",\n" +
  68. "\t\t\t\"value\": \"10\"\n" +
  69. "\t\t}, {\n" +
  70. "\t\t\t\"key\": \"[95,100]\",\n" +
  71. "\t\t\t\"value\": \"15\"\n" +
  72. "\t\t}],\n" +
  73. "\t\t\"techrequire\": [{\n" +
  74. "\t\t\t\"key\": \"scoring\",\n" +
  75. "\t\t\t\"value\": \"[0,5]\"\n" +
  76. "\t\t}],\n" +
  77. "\t\t\"standproficiency\": [{\n" +
  78. "\t\t\t\"key\": \"scoring\",\n" +
  79. "\t\t\t\"value\": \"[0,10]\"\n" +
  80. "\t\t}],\n" +
  81. "\t\t\"manualmonitorReport\": [{\n" +
  82. "\t\t\t\"key\": \"scoring\",\n" +
  83. "\t\t\t\"value\": \"[0,15]\"\n" +
  84. "\t\t}],\n" +
  85. "\t\t\"benchmark\": [{\n" +
  86. "\t\t\t\"key\": \"0\",\n" +
  87. "\t\t\t\"value\": \"0\"\n" +
  88. "\t\t}, {\n" +
  89. "\t\t\t\"key\": \"1\",\n" +
  90. "\t\t\t\"value\": \"5\"\n" +
  91. "\t\t}],\n" +
  92. "\t\t\"signBoard\": [{\n" +
  93. "\t\t\t\"key\": \"0\",\n" +
  94. "\t\t\t\"value\": \"0\"\n" +
  95. "\t\t}, {\n" +
  96. "\t\t\t\"key\": \"1\",\n" +
  97. "\t\t\t\"value\": \"10\"\n" +
  98. "\t\t}],\n" +
  99. "\t\t\"train\": [{\n" +
  100. "\t\t\t\"key\": \"0\",\n" +
  101. "\t\t\t\"value\": \"0\"\n" +
  102. "\t\t}, {\n" +
  103. "\t\t\t\"key\": \"1\",\n" +
  104. "\t\t\t\"value\": \"5\"\n" +
  105. "\t\t}]\n" +
  106. "\t}\n" +
  107. "}\n";
  108. public JSONObject getRuleJson() {
  109. JSONObject rule = new JSONObject();
  110. rule = JSONObject.parseObject(this.ruleStr);
  111. return rule;
  112. }
  113. /**
  114. * 计算监测数据质量和到报率小计得分
  115. *
  116. * @param bisInspGrw
  117. * @return
  118. * @throws Exception
  119. */
  120. public static Long calDataQuality(BisInspGrw bisInspGrw) throws Exception {
  121. Long score = 0L;
  122. if (bisInspGrw.getRepeatabilityScore() != null) {//现场比测经度误差
  123. score += bisInspGrw.getRepeatabilityScore();
  124. }
  125. if (GrwSttpEnum.PROVHAND.getValue().equals(bisInspGrw.getSttp()) || GrwSttpEnum.PROV.getValue().equals(bisInspGrw.getSttp())) {
  126. if (bisInspGrw.getHandScore() != null) {//人工监测数据报送是否及时
  127. score += bisInspGrw.getHandScore();
  128. }
  129. } else if (GrwSttpEnum.NATIONAL.getValue().equals(bisInspGrw.getSttp()) || GrwSttpEnum.PROVAUTO.getValue().equals(bisInspGrw.getSttp())) {
  130. if (bisInspGrw.getPercentageScore() != null) {//单站月统计到报率
  131. score += bisInspGrw.getPercentageScore();
  132. }
  133. } else {
  134. throw new Exception("测站类型错误:" + bisInspGrw.getSttp());
  135. }
  136. return score;
  137. }
  138. /**
  139. * 计算测站维护管理信息小计得分
  140. *
  141. * @param bisInspGrw
  142. * @return
  143. * @throws Exception
  144. */
  145. public static Long calMainTainScore(BisInspGrw bisInspGrw) throws Exception {
  146. Long score = 0L;
  147. if (NormalEnum.YES.getValue().equals(bisInspGrw.getFlagSign()) && bisInspGrw.getSignScore() != null) {//是否有标志牌
  148. score += bisInspGrw.getSignScore();
  149. }
  150. if (NormalEnum.YES.getValue().equals(bisInspGrw.getFlagExact()) && bisInspGrw.getExactScore() != null) {//基本信息是否准确
  151. score += bisInspGrw.getExactScore();
  152. }
  153. if (NormalEnum.YES.getValue().equals(bisInspGrw.getFlagSafeguard()) && bisInspGrw.getSafeguardScore() != null) {//有无简易保护措施
  154. score += bisInspGrw.getSafeguardScore();
  155. }
  156. if (GrwSttpEnum.PROVHAND.getValue().equals(bisInspGrw.getSttp()) || GrwSttpEnum.PROV.getValue().equals(bisInspGrw.getSttp())) {
  157. if (NormalEnum.YES.getValue().equals(bisInspGrw.getFlagTool())) {//是否配备检测工具
  158. if (bisInspGrw.getToolScore() != null) {//是否配备检测工具得分
  159. score += bisInspGrw.getToolScore();
  160. }
  161. if (bisInspGrw.getToolTsoScore() != null) {//测具是否符合有关技术要求
  162. score += bisInspGrw.getToolTsoScore();
  163. }
  164. }
  165. if (NormalEnum.YES.getValue().equals(bisInspGrw.getFlagTrain())) {//委托观测人员是否经过培训
  166. if (bisInspGrw.getTrainScore() != null) {
  167. score += bisInspGrw.getTrainScore();
  168. }
  169. }
  170. if (bisInspGrw.getToolProfScore() != null) {//测量人员操作规范、熟练
  171. score += bisInspGrw.getToolProfScore();
  172. }
  173. } else if (GrwSttpEnum.NATIONAL.getValue().equals(bisInspGrw.getSttp()) || GrwSttpEnum.PROVAUTO.getValue().equals(bisInspGrw.getSttp())) {
  174. if (NormalEnum.YES.getValue().equals(bisInspGrw.getFlagMark()) && bisInspGrw.getMarkScore() != null) {//是否有水准点
  175. score += bisInspGrw.getMarkScore();
  176. }
  177. if (NormalEnum.YES.getValue().equals(bisInspGrw.getFlagTool())) {//是否配备检测工具
  178. if (bisInspGrw.getToolTsoScore() != null) {//测具是否符合有关技术要求
  179. score += bisInspGrw.getToolTsoScore();
  180. }
  181. if (bisInspGrw.getToolProfScore() != null) {//测量人员操作规范、熟练
  182. score += bisInspGrw.getToolProfScore();
  183. }
  184. }
  185. if (bisInspGrw.getWellProtScore() != null) {//保护筒外管是否完好无损
  186. score += bisInspGrw.getWellProtScore();
  187. }
  188. } else {
  189. throw new Exception("测站类型错误:" + bisInspGrw.getSttp());
  190. }
  191. return score;
  192. }
  193. /**
  194. * 根据数据库中数据相加计算总得分
  195. *
  196. * @param bisInspGrw
  197. * @return
  198. * @throws Exception
  199. */
  200. public static Long calTotalScore(BisInspGrw bisInspGrw) throws Exception {
  201. Long score = 0L;
  202. score = calMainTainScore(bisInspGrw);
  203. score += calDataQuality(bisInspGrw);
  204. bisInspGrw.setAllScore(score);
  205. return score;
  206. }
  207. /**
  208. * 根据规则实时计算总分
  209. *
  210. * @param p
  211. * @return
  212. * @throws Exception
  213. */
  214. public Long CalScoreByRule(BisInspGrw p) throws Exception {
  215. Long score = 0L;
  216. if (StringUtils.isNotBlank(p.getFlagSign())) {//是否有标志牌
  217. Long signScore = NumberUtils.toLong(p.getFlagSign()) * flagSign;
  218. p.setSignScore(signScore);
  219. score += signScore;
  220. }
  221. if (StringUtils.isNotBlank(p.getFlagMark())) {//是否有水准点
  222. Long markScore = NumberUtils.toLong(p.getFlagMark()) * flagMark;
  223. p.setMarkScore(markScore);
  224. score += markScore;
  225. }
  226. if (StringUtils.isNotBlank(p.getFlagExact())) {//基本信息是否准确
  227. Long exactScore = NumberUtils.toLong(p.getFlagExact()) * flagExact;
  228. p.setExactScore(exactScore);
  229. score += exactScore;
  230. }
  231. if (StringUtils.isNotBlank(p.getFlagSafeguard())) {//有无简易保护措施
  232. Long safeguardScore = NumberUtils.toLong(p.getFlagSafeguard()) * flagSafeguard;
  233. p.setSafeguardScore(safeguardScore);
  234. score += safeguardScore;
  235. }
  236. if (GrwSttpEnum.PROVHAND.getValue().equals(p.getSttp()) && StringUtils.isNotBlank(p.getFlagTool())) {//是否配备检测工具
  237. Long toolScore = NumberUtils.toLong(p.getFlagTool()) * flagTool;
  238. p.setToolScore(toolScore);
  239. score += toolScore;
  240. }
  241. if (p.getToolTsoScore() != null) {//测具是否符合有关技术要求 5分
  242. if (p.getToolTsoScore() >= 0 && p.getToolTsoScore() <= toolTsoScore) {
  243. score += p.getToolTsoScore();
  244. } else {
  245. throw new Exception("测具是否符合有关技术要求得分范围为[0," + toolTsoScore + "]");
  246. }
  247. }
  248. if (p.getToolProfScore() != null) {//测量人员操作规范、熟练 10分
  249. if (p.getToolProfScore() >= 0 && p.getToolProfScore() <= toolProfScore) {
  250. score += p.getToolProfScore();
  251. } else {
  252. throw new Exception("测量人员操作规范、熟练得分范围为[0," + toolProfScore + "]");
  253. }
  254. }
  255. if (StringUtils.isNotBlank(p.getFlagTrain())) {//委托观测人员是否经过培训
  256. Long trainScore = NumberUtils.toLong(p.getFlagTrain()) * flagTrain;
  257. p.setTrainScore(trainScore);
  258. score += trainScore;
  259. }
  260. if (p.getWellProtScore() != null) {//保护筒外管是否完好无损
  261. if (p.getWellProtScore() >= 0 && p.getWellProtScore() <= wellProtScore) {
  262. score += p.getWellProtScore();
  263. } else {
  264. throw new Exception("保护筒外管是否完好无损得分范围为[0," + wellProtScore + "]");
  265. }
  266. }
  267. if (p.getRepeatability() != null && p.getRepeatability() <= repeatability) { //现场比测精度误差
  268. p.setRepeatabilityScore(repeatabilityScore);
  269. score += repeatabilityScore;
  270. }
  271. if (p.getPercentage() != null) { //单站月统计到报率(%)
  272. if (p.getPercentage() < percentage[0]) {
  273. score += percentageScore[0];
  274. p.setRepeatabilityScore(percentageScore[0]);
  275. } else if (p.getPercentage() >= percentage[percentage.length - 1]) {
  276. score += percentageScore[percentage.length - 1];
  277. p.setRepeatabilityScore(percentageScore[percentage.length - 1]);
  278. } else {
  279. for (int i = 0; i < percentage.length - 1; i++) {
  280. if (p.getPercentage() >= percentage[i] && p.getPercentage() < percentage[i + 1]) {
  281. p.setRepeatabilityScore(percentageScore[i + 1]);
  282. score += percentageScore[i + 1];
  283. break;
  284. }
  285. }
  286. }
  287. }
  288. if (GrwSttpEnum.PROVHAND.getValue().equals(p.getSttp()) && p.getHandScore() != null) {
  289. if (p.getHandScore() >= 0 && p.getHandScore() <= handScore) {
  290. score += p.getHandScore();
  291. } else {
  292. throw new Exception("人工监测数据报送是否及时得分范围为[0," + handScore + "]");
  293. }
  294. }
  295. return score;
  296. }
  297. public String getRuleStr() {
  298. return ruleStr;
  299. }
  300. public int getFlagSign() {
  301. return flagSign;
  302. }
  303. public int getFlagMark() {
  304. return flagMark;
  305. }
  306. public int getFlagExact() {
  307. return flagExact;
  308. }
  309. public int getFlagSafeguard() {
  310. return flagSafeguard;
  311. }
  312. public int getFlagTool() {
  313. return flagTool;
  314. }
  315. public int getFlagTrain() {
  316. return flagTrain;
  317. }
  318. public int getRepeatability() {
  319. return repeatability;
  320. }
  321. public Long getRepeatabilityScore() {
  322. return repeatabilityScore;
  323. }
  324. public int[] getPercentage() {
  325. return percentage;
  326. }
  327. public Long[] getPercentageScore() {
  328. return percentageScore;
  329. }
  330. public Long getToolTsoScore() {
  331. return toolTsoScore;
  332. }
  333. public Long getToolProfScore() {
  334. return toolProfScore;
  335. }
  336. public Long getWellProtScore() {
  337. return wellProtScore;
  338. }
  339. public Long getHandScore() {
  340. return handScore;
  341. }
  342. }