BusInitController.java 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796
  1. package com.bus.web;
  2. import java.awt.image.BufferedImage;
  3. import java.io.File;
  4. import java.io.FileOutputStream;
  5. import java.io.IOException;
  6. import java.io.OutputStream;
  7. import java.io.PrintWriter;
  8. import java.io.UnsupportedEncodingException;
  9. import java.text.ParseException;
  10. import java.text.SimpleDateFormat;
  11. //import java.time.Year;
  12. import java.util.ArrayList;
  13. import java.util.Calendar;
  14. import java.util.Collection;
  15. import java.util.Date;
  16. import java.util.HashMap;
  17. import java.util.List;
  18. import java.util.Map;
  19. import java.util.Properties;
  20. import java.util.Set;
  21. import javax.servlet.http.HttpServletRequest;
  22. import javax.servlet.http.HttpServletResponse;
  23. import com.base.service.IBaseOrgTypeService;
  24. import com.bus.model.*;
  25. import jxl.Workbook;
  26. import jxl.format.Alignment;
  27. import jxl.write.Label;
  28. import jxl.write.WritableCellFormat;
  29. import jxl.write.WritableSheet;
  30. import jxl.write.WritableWorkbook;
  31. import jxl.write.WriteException;
  32. import jxl.write.biff.RowsExceededException;
  33. import org.jbarcode.util.ImageUtil;
  34. import org.slf4j.Logger;
  35. import org.slf4j.LoggerFactory;
  36. import org.springframework.beans.factory.annotation.Autowired;
  37. import org.springframework.stereotype.Controller;
  38. import org.springframework.ui.Model;
  39. import org.springframework.ui.ModelMap;
  40. import org.springframework.web.bind.annotation.RequestMapping;
  41. import org.springframework.web.bind.annotation.ResponseBody;
  42. import org.springframework.web.multipart.MultipartFile;
  43. import org.springframework.web.multipart.MultipartHttpServletRequest;
  44. import com.StaticValues;
  45. import com.base.model.BaseOrgType;
  46. import com.base.model.BaseSection;
  47. import com.base.model.BaseStatus;
  48. import com.base.model.enumType.UserType;
  49. import com.base.service.IBaseStatusService;
  50. import com.bus.model.temp.BusOrgTemp;
  51. import com.bus.model.temp.BusPlanTempRowMap;
  52. import com.bus.model.temp.OrgTemp;
  53. import com.bus.model.temp.OrgTypeCountTemp;
  54. import com.bus.model.temp.ReplyPrintTemp;
  55. import com.bus.model.temp.unitCountYearRowMap;
  56. import com.bus.service.IBusAnnualPlanForWaterService;
  57. import com.bus.service.IBusCustomerMeterService;
  58. import com.bus.service.IBusMeterReadInfoService;
  59. import com.bus.service.IBusOrgService;
  60. import com.bus.service.IBusQuarterlyAssessmentService;
  61. import com.bus.service.IBusWaterAdjRecService;
  62. import com.core.dao.util.Updater;
  63. import com.core.util.FileUploadUtils;
  64. import com.core.util.JsonUtil;
  65. import com.core.web.BaseController;
  66. import com.core.web.security.ContextUtil;
  67. import com.data.model.ImportDataFile;
  68. import com.data.model.enumType.ImportStatus;
  69. import com.data.model.enumType.ImportType;
  70. import com.data.web.ImportDataFileController;
  71. import com.popedom.model.PopUser;
  72. import java.awt.image.BufferedImage;
  73. import java.io.FileOutputStream;
  74. import org.jbarcode.JBarcode;
  75. import org.jbarcode.encode.Code128Encoder;
  76. import org.jbarcode.encode.Code39Encoder;
  77. import org.jbarcode.encode.EAN13Encoder;
  78. import org.jbarcode.encode.InvalidAtributeException;
  79. import org.jbarcode.paint.BaseLineTextPainter;
  80. import org.jbarcode.paint.EAN13TextPainter;
  81. import org.jbarcode.paint.WideRatioCodedPainter;
  82. import org.jbarcode.paint.WidthCodedPainter;
  83. import org.jbarcode.util.ImageUtil;
  84. @Controller
  85. @RequestMapping("/busInit/")
  86. public class BusInitController extends BaseController {
  87. private static Logger log = LoggerFactory
  88. .getLogger(BusInitController.class);
  89. @Autowired
  90. private IBusOrgService busOrgService;
  91. @Autowired
  92. private IBaseOrgTypeService baseOrgTypeService;
  93. @Autowired
  94. private IBusMeterReadInfoService busMeterReadInfoService;
  95. @Autowired
  96. private IBusAnnualPlanForWaterService busAnnualPlanForWaterService;
  97. @Autowired
  98. private IBusQuarterlyAssessmentService busQuarterlyAssessmentService;
  99. @Autowired
  100. private IBusCustomerMeterService busCustomerMeterService;
  101. @Autowired
  102. private IBaseStatusService busStatusService;
  103. @Autowired
  104. private IBusWaterAdjRecService busWaterAdjRecService;
  105. private static String path;
  106. static {
  107. Properties p = new Properties();
  108. try {
  109. p.load(ImportDataFileController.class.getClassLoader().getResourceAsStream(
  110. "config.properties"));
  111. path = p.getProperty("upload_mdb");
  112. } catch (Exception e) {
  113. e.printStackTrace();
  114. }
  115. }
  116. /**
  117. * 进入年度初值化界面
  118. *
  119. * @return
  120. */
  121. @RequestMapping("busInitList.do")
  122. public String busInitList(Model model) {
  123. String year = busOrgService.getMatYearFromBusOrg();
  124. Map<String,List<Map<String,String>>> map = new HashMap<String,List<Map<String,String>>>();
  125. List<Map<String, String>> m = UserType.getList();
  126. map.put("list", m);
  127. model.addAttribute("year", year);
  128. model.addAttribute("isPlanUser", StaticValues.IS_PLAN);
  129. model.addAttribute("map", JsonUtil.getJSONSerializer().deepSerialize(map));
  130. return "bus/org-init-list";
  131. }
  132. /**
  133. * 获取要年度初化的信息列表
  134. *
  135. * @return
  136. */
  137. @RequestMapping("bugInitInfoList.do")
  138. @ResponseBody
  139. public String bugInitInfoList(int pageNo, int pageSize, String orgNumber,
  140. String orgName, String year, String busOrgCustomerNumber,
  141. String address, String busOrgMeterNumber, String isPlanUser,
  142. String userType, String orgNature, HttpServletRequest request) {
  143. String hql = "select b from BusOrg b where b.importStatus='normal'";
  144. if (null != orgNumber && !orgNumber.equals("")) {
  145. hql += " and b.orgNumber = "+ orgNumber;
  146. }
  147. if (null != orgName && !orgName.equals("")) {
  148. hql += " and b.orgName like '%" + orgName + "%'";
  149. }
  150. if (null != year && !year.equals("")) {
  151. hql += " and b.year like '%" + year + "%'";
  152. }
  153. if (null != busOrgCustomerNumber && !busOrgCustomerNumber.equals("")) {
  154. hql += " and b.orgId in(select bcm.org.orgId from BusCustomerMeter bcm where bcm.customerNumber="+busOrgCustomerNumber+")";
  155. }
  156. if (null != address && !address.equals("")) {
  157. hql += " and b.address like '%" + address + "%'";
  158. }
  159. if (null != busOrgMeterNumber && !busOrgMeterNumber.equals("")) {
  160. hql += " and b.orgId in(select bc.org.orgId from BusCustomerMeter bc where bc.meterNumber="+busOrgMeterNumber+")";
  161. }
  162. if (null != userType && !userType.equals("")) {
  163. hql += " and b.baseUserType = " + userType;
  164. }
  165. if (null != isPlanUser && !isPlanUser.equals("")) {
  166. hql += " and b.isPlanUser ='" + isPlanUser + "'";
  167. }
  168. if (null != orgNature && !orgNature.equals("")) {
  169. hql += " and b.orgNature like '%" + orgNature + "%'";
  170. }
  171. this.page = busOrgService.getPageByHql(hql, pageNo, pageSize);
  172. String result = this.getPageJosnResult();
  173. log.debug("#########################" + result);
  174. return result;
  175. }
  176. /**
  177. * 进入年度初值化时间选择区间界面
  178. *
  179. * @param orgIds
  180. * @param model
  181. * @return
  182. */
  183. @RequestMapping("gotoInitYearTimePage.do")
  184. public String gotoInitYearTimePage(String orgIds,String year, Model model) {
  185. model.addAttribute("ids", orgIds);
  186. if(!"".equals(year)&&year!=null){
  187. model.addAttribute("year", year);
  188. }
  189. return "bus/org-init-create";
  190. }
  191. /**
  192. * 年度计划初值化
  193. *
  194. * @param ids
  195. * @return
  196. * @throws ParseException
  197. */
  198. @RequestMapping("createYearWaterInfo.do")
  199. @ResponseBody
  200. public Object createYearWaterInfo(String ids, String startTime,
  201. String endTime,int initValue,String param) throws ParseException {
  202. startTime += "-01 00:00:00";
  203. endTime += "-01 00:00:00";
  204. String year = getCurrentYear();
  205. SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  206. try {
  207. if (ids.length() <= 0) {// 没有选择则所有生成年度计划初值化
  208. String[] strs1 = ids.split(",");
  209. for (String str : strs1) {
  210. Long orgId1 = Long.parseLong(str);
  211. BusOrg borg1 = busOrgService.get(orgId1);
  212. String name = borg1.getOrgNature();
  213. //取增长比例
  214. Float GR = baseOrgTypeService.getGrowthRatio(name);
  215. doInityearDate(f.parse(startTime), f.parse(endTime),year,GR);
  216. }
  217. } else {
  218. String[] strs = ids.split(",");
  219. for (String str : strs) {
  220. Long orgId = Long.parseLong(str);
  221. BusOrg busOrg = busOrgService.get(orgId);
  222. int orgNumber = busOrg.getOrgNumber();
  223. String y = busOrg.getYear();
  224. if(!y.equals(year)){ //不是新年的数据不初值化
  225. continue;
  226. }
  227. //批复过的不再初值化
  228. BusAnnualPlanForWater water = busAnnualPlanForWaterService.get(orgId);
  229. if(water != null){
  230. continue;
  231. }
  232. doDataInit(orgNumber,orgId, f.parse(startTime), f.parse(endTime));
  233. }
  234. }
  235. busQuarterlyAssessmentService.updateWaterPrice(param);
  236. return addJsonSuccessMsg("年度计划初值化成功");
  237. } catch (Exception e) {
  238. return addJsonErrorMsg("年度计划初值化失败,原因是:"+e.getMessage());
  239. }
  240. }
  241. /**
  242. * 循环实现年度初值化
  243. *
  244. * @param startTime
  245. * @param endTime
  246. * @param year
  247. */
  248. public void doInityearDate(Date startTime, Date endTime,String year,Float GR) {
  249. PopUser user = ContextUtil.getCurrentUser();
  250. String userName = user.getFullName();
  251. Long userId = user.getUserId();
  252. Date updateTime = new Date();
  253. // 年度计划初值化
  254. busOrgService.updateCountYearInitDate(userId,updateTime,userName,year,startTime,endTime,startTime,getAscOneMonth(startTime),getDescOneMonth(endTime),endTime,GR);
  255. //季度考核初值化
  256. for(int i=1;i<5;i++){
  257. busOrgService.updateInitbusQuarterlyAssessment(i, year, startTime, endTime, startTime, getAscOneMonth(startTime), getDescOneMonth(endTime), endTime,GR);
  258. }
  259. //月考核初值化
  260. //LHJ 2020-1-11
  261. for(int i=1;i<13;i++){
  262. busOrgService.updateInitbusMonthAssessment(i, year, startTime, endTime, startTime, getAscOneMonth(startTime), getDescOneMonth(endTime), endTime,GR);
  263. }
  264. //半年考核初值化
  265. //LHJ 2020-1-11
  266. for(int i=1;i<3;i++){
  267. busOrgService.updateInitbusHalfYearAssessment(i, year, startTime, endTime, startTime, getAscOneMonth(startTime), getDescOneMonth(endTime), endTime,GR);
  268. }
  269. }
  270. /**
  271. * 初值化过程计算
  272. *
  273. * @param orgId
  274. * @param startTime
  275. * @param endTime
  276. */
  277. private void doDataInit(int orgNumber,Long orgId, Date startTime, Date endTime) {
  278. //客户提出在年初始化的时候不再判断首月跟尾月是否有水,李周芳 2015-03-26
  279. // 不够12个月不做初值化,只判断首月跟尾月
  280. // List<BusMeterReadInfo> listS = busMeterReadInfoService.getStartOneMonthMeterInfo(orgNumber, startTime,getAscOneMonth(startTime));
  281. // if (null == listS) {
  282. // return;
  283. // }
  284. // List<BusMeterReadInfo> listE = busMeterReadInfoService.getStartOneMonthMeterInfo(orgNumber, getDescOneMonth(endTime),endTime);
  285. // if (null == listE) {
  286. // return;
  287. // }
  288. BusOrg borg1 = busOrgService.get(orgId);
  289. String name = borg1.getOrgNature();
  290. //取增长比例
  291. Float GR = baseOrgTypeService.getGrowthRatio(name);
  292. // 找到12个月区间总水量
  293. List<BusMeterReadInfo> listM = busMeterReadInfoService.getStartOneMonthMeterInfo(orgNumber, startTime, endTime);
  294. Float w = 0f;
  295. for (int i = 0; i < listM.size(); i++) {
  296. BusMeterReadInfo info = listM.get(i);
  297. w += info.getWater();
  298. }
  299. // 计划水量加上5%
  300. int planWater = (int) Math.round((1+(GR)/100) * w);
  301. int fs =Math.round(Float.valueOf(planWater) / 4);
  302. //月计划用水指标
  303. int ms = Math.round(Float.valueOf(planWater) / 12);
  304. //半年计划用水指标
  305. int hys = Math.round(Float.valueOf(planWater) / 2);
  306. //初值化年度计划表
  307. BusAnnualPlanForWater busAnnualPlanForWater = busAnnualPlanForWaterService.get(orgId);
  308. if (null == busAnnualPlanForWater) {
  309. BusOrg borg = busOrgService.get(orgId);
  310. BusAnnualPlanForWater busWater = new BusAnnualPlanForWater();
  311. busWater.setPriYearUseWater(w);
  312. busWater.setPlanOfWater((float)planWater);
  313. busWater.setReplyOfWater((float)planWater);
  314. busWater.setFirstQuarterPlan((float)fs);
  315. busWater.setFirstQuarterReply((float)fs);
  316. busWater.setSecondQuarterPlan((float)fs);
  317. busWater.setSecondQuarterReply((float)fs);
  318. busWater.setThirdQuarterPlan((float)fs);
  319. busWater.setThirdQuarterReply((float)fs);
  320. busWater.setFourthQuarterPlan((float)fs);
  321. busWater.setFourthQuarterReply((float)fs);
  322. busWater.setOperatorId(ContextUtil.getCurrentUserId());
  323. busWater.setUserName(ContextUtil.getCurrentUser().getFullName());
  324. busWater.setFillTime(new Date());
  325. busWater.setIsCancel(StaticValues.IS_PLAN); //默认考核yes
  326. busWater.setOrg(borg);
  327. busAnnualPlanForWaterService.save(busWater);
  328. //季度考核初值化
  329. for(int i=1;i<5;i++){
  330. BusQuarterlyAssessment bqa = new BusQuarterlyAssessment();
  331. bqa.setAssessmentQuarter(i);
  332. bqa.setWaterPlanningIndex((float)fs);
  333. bqa.setOrg(borg);
  334. bqa.setBank(borg.getBank());
  335. bqa.setBankAccount(borg.getBankAccount());
  336. busQuarterlyAssessmentService.save(bqa);
  337. }
  338. //月考核初值化
  339. for(int i=1;i<13;i++) {
  340. BusMonthAssessment bma = new BusMonthAssessment();
  341. bma.setAssessmentMonth(i);
  342. bma.setWaterPlanningIndex((float)ms);
  343. bma.setOrg(borg);
  344. bma.setBank(borg.getBank());
  345. bma.setBankAccount(borg.getBankAccount());
  346. }
  347. //半年考核初值化
  348. for(int i=1;i<3;i++) {
  349. BusYearhfAssessment bya = new BusYearhfAssessment();
  350. bya.setAssessmentYearhf(i);
  351. bya.setWaterPlanningIndex((float)hys);
  352. bya.setOrg(borg);
  353. bya.setBank(borg.getBank());
  354. bya.setBankAccount(borg.getBankAccount());
  355. }
  356. //年考核初值化
  357. }
  358. }
  359. /**
  360. * 进入年度用户信息初值化界面
  361. *
  362. * @return
  363. */
  364. @RequestMapping("userInitInfoList.do")
  365. public String userInitInfoList(Model model) {
  366. SimpleDateFormat format = new SimpleDateFormat("yyyy");
  367. Date d = new Date();
  368. Map<String,List<Map<String,String>>> map = new HashMap<String,List<Map<String,String>>>();
  369. List<Map<String, String>> m = UserType.getList();
  370. map.put("list", m);
  371. model.addAttribute("year", format.format(d));
  372. model.addAttribute("userType",JsonUtil.getJSONSerializer().deepSerialize(map));
  373. return "bus/user-init-list";
  374. }
  375. /**
  376. * 获取用户年度初值化列表
  377. *
  378. * @return
  379. */
  380. @RequestMapping("busUserInfoList.do")
  381. @ResponseBody
  382. public String busUserInfoList(int pageNo, int pageSize, String orgNumber,
  383. String orgName, String year, String busOrgCustomerNumber,
  384. String address, String busOrgMeterNumber, String isPlanUser,
  385. String userType, String orgNature, HttpServletRequest request) {
  386. String hql="select b from BusOrg b where b.importStatus='normal'";
  387. if(null != busOrgCustomerNumber && !busOrgCustomerNumber.equals("")){
  388. hql +=" and b.orgId in(select bcm.org.orgId from BusCustomerMeter bcm where bcm.customerNumber='"+busOrgCustomerNumber+"')";
  389. }
  390. if(null != busOrgMeterNumber && !busOrgMeterNumber.equals("")){
  391. hql +=" and b.orgId in(select bc.org.orgId from BusCustomerMeter bc where bc.meterNumber='"+busOrgMeterNumber+"')";
  392. }
  393. if (null != orgNumber && !orgNumber.equals("")) {
  394. hql += " and b.orgNumber = " + orgNumber;
  395. }
  396. if (null != orgName && !orgName.equals("")) {
  397. hql += " and b.orgName like '%" + orgName + "%'";
  398. }
  399. if (null != year && !year.equals("")) {
  400. hql += " and b.year = '" + year + "'";
  401. }
  402. if (null != address && !address.equals("")) {
  403. hql += " and b.address like '%" + address + "%'";
  404. }
  405. if (null != userType && !userType.equals("")) {
  406. hql += " and b.baseUserType =" + userType;
  407. }
  408. if (null != isPlanUser && !isPlanUser.equals("")) {
  409. hql += " and b.isPlanUser ='" + isPlanUser+"'";
  410. }
  411. if (null != orgNature && !orgNature.equals("")) {
  412. hql += " and b.orgNature like '%" + orgNature + "%'";
  413. }
  414. this.page = busOrgService.getPageByHql(hql, pageNo, pageSize);
  415. String result = this.getPageJosnResult();
  416. log.debug("#########################result" + result);
  417. return result;
  418. }
  419. /**
  420. * 进入生成新年度用户基本信息库界面
  421. *
  422. * @return
  423. */
  424. @RequestMapping("createUserInit.do")
  425. public String createBusUserInitInfo(String ids,Model model,String year) {
  426. model.addAttribute("ids", ids);
  427. model.addAttribute("year", year);
  428. return "bus/user-init-create";
  429. }
  430. /**
  431. * 初值化用户基本信息操作
  432. *
  433. * @param endTime
  434. * @param startTime
  435. * @return
  436. */
  437. @RequestMapping("editbusUserInitInfo.do")
  438. @ResponseBody
  439. public Object editbusUserInitInfo(String endTime, String startTime,String ids,int initValue,String year) {
  440. startTime += "-01 00:00:00";
  441. endTime += "-01 00:00:00";
  442. int sum=0;
  443. SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  444. try {
  445. Date startT = format.parse(startTime);
  446. Date endT = format.parse(endTime);
  447. if(ids.length()>0){
  448. String[] strs = ids.split(",");
  449. for(String s:strs){
  450. Long orgId = Long.parseLong(s);
  451. BusOrg busOrg = busOrgService.get(orgId);
  452. String name = busOrg.getOrgNature();
  453. //取增长比例
  454. Float GR = baseOrgTypeService.getGrowthRatio(name);
  455. //查询水量历史记录要用到单位编号
  456. int orgNumber = busOrg.getOrgNumber();
  457. if(!busOrg.getYear().equals(year)){ //只初值化最新数据,如果是去年的就不初值化了
  458. continue;
  459. }
  460. //批复过的单位不能再初值化
  461. // BusAnnualPlanForWater water = busAnnualPlanForWaterService.get(orgId);
  462. // if(water != null ){
  463. // continue;
  464. // }
  465. initStepBusOrg(year,orgNumber,orgId,startT,endT,GR);
  466. }
  467. }else{//没有选择默认初值化所有
  468. String a = format.format(getAscOneMonth(startT));
  469. String b = format.format(getDescOneMonth(endT));
  470. log.debug("%%%%%%%%%%%%%%%%%%%%%"+a+" "+b);
  471. busOrgService.updateYearneedInitDate(year, startT, endT, startT, getAscOneMonth(startT), getDescOneMonth(endT), endT);
  472. busOrgService.updateIsplanYear(year);
  473. busOrgService.updateCosMeter(year);
  474. String[] strs = ids.split(",");
  475. for (String str : strs) {
  476. Long orgId1 = Long.parseLong(str);
  477. BusOrg borg1 = busOrgService.get(orgId1);
  478. String name = borg1.getOrgNature();
  479. //取增长比例
  480. Float GR = baseOrgTypeService.getGrowthRatio(name);
  481. busOrgService.updateSetplanYear(year, startT, endT, startT, getAscOneMonth(startT), getDescOneMonth(endT), endT, GR);
  482. }
  483. }
  484. return addJsonSuccessMsg("用户信息初值化成功");
  485. } catch (ParseException e) {
  486. return addJsonErrorMsg("用户初值化信息失败,原因是:" + e.getMessage());
  487. }
  488. }
  489. /**
  490. * 单位中弹出处理合并后用户初始化页面
  491. * @param ids
  492. * @param model
  493. * @param year
  494. * @return
  495. */
  496. //@RequestMapping("createBusUserInitForOrg.do")
  497. //public String createBusUserInitForOrg(String ids,Model model,String year) {
  498. // model.addAttribute("ids", ids);
  499. // model.addAttribute("year", year);
  500. // return "bus/user-init-create-for-org";
  501. //}
  502. /**
  503. * 单位中处理合并后用户的初始化
  504. * @param endTime
  505. * @param startTime
  506. * @param ids
  507. * @param initValue
  508. * @param year
  509. * @return
  510. */
  511. //@RequestMapping("editBusUserInitInfoForOrg")
  512. //@ResponseBody
  513. //public Object editBusUserInitInfoForOrg(String endTime, String startTime,Long orgId,int initValue,String year) {
  514. // startTime += "-01 00:00:00";
  515. // endTime += "-01 00:00:00";
  516. // SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  517. // try {
  518. // Date startT = format.parse(startTime);
  519. // Date endT = format.parse(endTime);
  520. // BusOrg busOrg = busOrgService.get(orgId);
  521. // //查询水量历史记录要用到单位编号
  522. // int orgNumber = busOrg.getOrgNumber();
  523. // initStepBusOrg(year,orgNumber,orgId,startT,endT,initValue);
  524. // //查找初始化之后的单位是否为计划户
  525. // int nextyear = Integer.parseInt(year)+1;
  526. // String hql2 = " from BusOrg b where b.orgNumber=? and b.importStatus='normal' and b.year=?";
  527. // List<BusOrg> list1 = busOrgService.findByHql(hql2, orgNumber,(nextyear+"").trim());
  528. // BusOrg bo = list1.get(0);
  529. // Map<String, Object> map = new Hashtable<String,Object>();
  530. // map.put("status", "y");//成功标识
  531. // map.put("info", "用户信息初值化成功");//消息内容
  532. // if("yes".equals(bo.getIsPlanUser())){
  533. // map.put("isPlanUser", "y");
  534. // map.put("orgIds", bo.getOrgId());
  535. // map.put("year", bo.getYear());
  536. // }else{
  537. // map.put("isPlanUser", "n");
  538. // }
  539. // return map;
  540. // } catch (ParseException e) {
  541. // return addJsonErrorMsg("用户初值化信息失败,原因是:" + e.getMessage());
  542. // }
  543. //}
  544. /**
  545. * 用户初值化操作
  546. * @param orgId
  547. * @param startTime
  548. * @param endTime
  549. */
  550. private void initStepBusOrg(String year,int orgNumber,Long orgId,Date startTime,Date endTime,Float GR){
  551. int nextyear = Integer.parseInt(year)+1;
  552. //先初值化先
  553. String hql = " from BusOrg b where b.orgNumber=? and b.importStatus='normal' and b.year=?";
  554. List<BusOrg> list = busOrgService.findByHql(hql, orgNumber,(nextyear+"").trim());
  555. if(null == list || list.size()==0){
  556. busOrgService.initOneData(orgId, nextyear,StaticValues.NO_PLAN);
  557. }else{
  558. BusOrg bo = list.get(0);
  559. String h = " from BusAnnualPlanForWater w where w.id=?";
  560. List<BusAnnualPlanForWater> bw = busAnnualPlanForWaterService.findByHql(h, bo.getOrgId());
  561. if(null == bw || bw.size() == 0){
  562. bo.setIsPlanUser(StaticValues.NO_PLAN);
  563. Updater<BusOrg> updater = new Updater<BusOrg>(bo);
  564. busOrgService.updateByUpdater(updater);
  565. }
  566. }
  567. //客户提出在年初始化的时候不再判断首月跟尾月是否有水,李周芳 2015-03-26
  568. // 先判断是否12个月都有水,只判断首月跟尾月
  569. // List<BusMeterReadInfo> listS = busMeterReadInfoService.getStartOneMonthMeterInfo(orgNumber, startTime,getAscOneMonth(startTime));
  570. // if (null == listS) {
  571. // return;
  572. // }
  573. // List<BusMeterReadInfo> listE = busMeterReadInfoService.getStartOneMonthMeterInfo(orgNumber, getDescOneMonth(endTime),endTime);
  574. // if (null == listE) {
  575. // return;
  576. // }
  577. // 计算水量
  578. Float w = busMeterReadInfoService.getSumWaterByTime(orgNumber, startTime, endTime);
  579. // 根据水量判断是否计划户,超过12万吨为计划户
  580. if (w >= GR) {
  581. String hql2 = " from BusOrg b where b.orgNumber=? and b.importStatus='normal' and b.year=?";
  582. List<BusOrg> list1 = busOrgService.findByHql(hql2, orgNumber,(nextyear+"").trim());
  583. BusOrg bo = list1.get(0);
  584. bo.setIsPlanUser(StaticValues.IS_PLAN);
  585. Updater<BusOrg> updater = new Updater<BusOrg>(bo);
  586. busOrgService.updateByUpdater(updater);
  587. }
  588. }
  589. /**
  590. * 得到年份
  591. *
  592. * @return
  593. */
  594. private String getCurrentYear() {
  595. String year = busOrgService.getMatYearFromBusOrg();
  596. return year;
  597. }
  598. /**
  599. * 时间减一个月
  600. *
  601. * @param endTime
  602. * @return
  603. */
  604. private Date getDescOneMonth(Date endTime) {
  605. Calendar calendar = Calendar.getInstance();
  606. calendar.setTime(endTime);
  607. calendar.add(Calendar.MONTH, -1);
  608. return calendar.getTime();
  609. }
  610. /**
  611. * 时间加一个月
  612. *
  613. * @param startTime
  614. * @return
  615. */
  616. private Date getAscOneMonth(Date startTime) {
  617. Calendar calendar = Calendar.getInstance();
  618. calendar.setTime(startTime);
  619. calendar.add(Calendar.MONTH, 1);
  620. return calendar.getTime();
  621. }
  622. /**
  623. * 进入单位年度计划供水表列表界面
  624. * @return
  625. */
  626. @RequestMapping("unitYearPlanWater.do")
  627. public String unitYearPlanWater(Model model){
  628. Map<String,List<Map<String,String>>> map = new HashMap<String,List<Map<String,String>>>();
  629. List<Map<String, String>> m = UserType.getList();
  630. String year = getCurrentYear();
  631. map.put("list", m);
  632. model.addAttribute("year", year);
  633. model.addAttribute("map", JsonUtil.getJSONSerializer().deepSerialize(map));
  634. //载入状态颜色
  635. Map<String, List<Map<String, String>>> statusMap = new HashMap<String, List<Map<String, String>>>();
  636. statusMap.put("list", loadStatusSelectWithColor());
  637. String statusList = JsonUtil.getJSONSerializer().deepSerialize(statusMap);
  638. model.addAttribute("statusList", statusList);
  639. //载入状态名称
  640. Map<String, List<Map<String, String>>> nameMap = new HashMap<String, List<Map<String, String>>>();
  641. nameMap.put("list", loadStatusSelectWithName());
  642. String nameList = JsonUtil.getJSONSerializer().deepSerialize(nameMap);
  643. model.addAttribute("nameList", nameList);
  644. return "bus/org-plan-list";
  645. }
  646. /**
  647. * 列出单位年度计划供水表信息
  648. * @return
  649. * @throws ParseException
  650. */
  651. @RequestMapping("getYearPlanData.do")
  652. @ResponseBody
  653. public String getYearPlanData(int pageNo,int pageSize,String orgNumber,
  654. String orgName, String year, String busOrgCustomerNumber,
  655. String address, String busOrgMeterNumber, String priYearUseWater,
  656. String userType, String orgNature,String status,String org_name) throws ParseException{
  657. SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  658. //String sql = "select p.status_id,o.org_id,o.org_number,o.org_name,o.user_type,o.year,p.plan_of_water,p.replay_of_water,p.first_quarter_plan,p.second_quarter_plan,p.third_quarter_plan,p.fourth_quarter_plan,p.user_name,p.fill_time,p.remark,p.pri_year_usewater FROM `bus_annual_plan_for_water` as p left join bus_org o on p.org_id=o.org_id where p.is_cancel='yes'";
  659. String sql = "select p.status_id,o.org_id,o.org_number,o.org_name,o.user_type,o.year,p.plan_of_water,p.reply_of_water,p.first_quarter_reply,p.second_quarter_reply,p.third_quarter_reply,p.fourth_quarter_reply,p.user_name,p.fill_time,p.remark,p.pri_year_usewater ";
  660. sql +=",p.first_quarter_plan,p.second_quarter_plan,p.third_quarter_plan,p.fourth_quarter_plan,p.reply_of_increase FROM `bus_annual_plan_for_water` as p left join bus_org o on p.org_id=o.org_id where p.is_cancel='yes' ";
  661. if(null != busOrgCustomerNumber && !busOrgCustomerNumber.equals("")){
  662. sql +=" and o.org_id in (select bcm.org_id from bus_customer_meter as bcm where bcm.customer_Number = "+busOrgCustomerNumber+")";
  663. }
  664. if(null != busOrgMeterNumber && !busOrgMeterNumber.equals("")){
  665. sql +=" and o.org_id in (select bc.org_id from bus_customer_meter as bc where bc.meter_Number = "+busOrgMeterNumber+")";
  666. }
  667. if (null != orgNumber && !orgNumber.equals("")) {
  668. sql +=" and o.org_number="+orgNumber;
  669. }
  670. if (null != org_name && !org_name.equals("")) {
  671. sql +=" and LENGTH(o.org_name)<"+Integer.parseInt(org_name)+"";
  672. }
  673. if (null != orgName && !orgName.equals("")) {
  674. sql +=" and o.org_name like '%"+orgName+"%'";
  675. }
  676. if (null != orgNature && !orgNature.equals("")) {
  677. sql += " and b.orgNature like '%" + orgNature + "%'";
  678. }
  679. if (null != year && !year.equals("")) {
  680. sql +=" and o.year='"+year+"'";
  681. }
  682. if (null != address && !address.equals("")) {
  683. sql +=" and o.address like '%"+address+"%'";
  684. }
  685. if (null != userType && !userType.equals("")) {
  686. sql +=" and o.user_type="+userType;
  687. }
  688. if (null != status && !status.equals("")) {
  689. sql +=" and p.status_id="+status;
  690. }
  691. if (null != priYearUseWater && !priYearUseWater.equals("")) {
  692. try {
  693. Float p = Float.parseFloat(priYearUseWater);
  694. sql +=" and p.pri_year_usewater>='"+p+"'";
  695. } catch (Exception e) {
  696. log.debug("上一年用水量转化异常:"+e.getMessage());
  697. }
  698. }
  699. sql +=" order by o.year,o.org_number desc";
  700. this.page = busAnnualPlanForWaterService.getPageByJdbcTemplate(sql, pageNo, pageSize, new BusPlanTempRowMap());
  701. List<BusOrgTemp> list = (List<BusOrgTemp>)this.page.getResult();
  702. for(BusOrgTemp temp:list){
  703. int o = temp.getOrgNumber();
  704. int y = Integer.parseInt(temp.getYear());
  705. String s = y+"-01-01 00:00:00";
  706. String e = y+1+"-01-01 00:00:00";
  707. List<BusMeterReadInfo> listS = busMeterReadInfoService.getStartOneMonthMeterInfo(o, format.parse(s),format.parse(e));
  708. Float w=0f;
  709. if(null != listS){
  710. for(BusMeterReadInfo info:listS){
  711. w +=info.getWater();
  712. }
  713. }
  714. temp.setYearUseWater(w);
  715. }
  716. String result = this.getPageJosnResult();
  717. log.debug("####################################"+result);
  718. return result;
  719. }
  720. /**
  721. * 进入修改年度计划用水表界面
  722. * @param orgId
  723. * @param model
  724. * @return
  725. */
  726. @RequestMapping("createYearUnitNotice.do")
  727. public String createYearUnitNotice(Long orgId,Model model){
  728. BusOrg busOrg = busOrgService.get(orgId);
  729. BusAnnualPlanForWater plan = busAnnualPlanForWaterService.get(orgId);
  730. //BusWaterAdjRec adjplan1 = busWaterAdjRecService.findUniqueBy("orgId",orgId);
  731. //List<BusWaterAdjRec> adjplan=busWaterAdjRecService.findBy("orgId",orgId);
  732. String sql = "SELECT IFNULL(SUM(i.`water`),0) FROM `bus_meter_read_info` i WHERE i.`org_id`=?";
  733. Long useWate = busAnnualPlanForWaterService.getCountBySql(sql, orgId);
  734. Map<String,Collection<Map<String,String>>> map = new HashMap<String,Collection<Map<String,String>>>();
  735. map.put("list", loadStatusSelectWithName());
  736. String status = JsonUtil.getJSONSerializer().deepSerialize(map);
  737. model.addAttribute("status", status);
  738. if(plan.getBaseStatus()!=null){
  739. model.addAttribute("statusId", plan.getBaseStatus().getId());
  740. }
  741. model.addAttribute("busOrg", busOrg);
  742. model.addAttribute("plan", plan);
  743. model.addAttribute("useWate", useWate);
  744. //model.addAttribute("adjplan", adjplan);
  745. return "bus/org-plan-edit";
  746. }
  747. @RequestMapping("viewYearUnitNotice.do")
  748. public String viewYearUnitNotice(Long orgId,Model model){
  749. BusOrg busOrg = busOrgService.get(orgId);
  750. BusAnnualPlanForWater plan = busAnnualPlanForWaterService.get(orgId);
  751. String sql = "SELECT IFNULL(SUM(i.`water`),0) FROM `bus_meter_read_info` i WHERE i.`org_id`=?";
  752. Long useWate = busAnnualPlanForWaterService.getCountBySql(sql, orgId);
  753. Map<String,Collection<Map<String,String>>> map = new HashMap<String,Collection<Map<String,String>>>();
  754. map.put("list", loadStatusSelectWithName());
  755. String status = JsonUtil.getJSONSerializer().deepSerialize(map);
  756. model.addAttribute("status", status);
  757. if(plan.getBaseStatus()!=null){
  758. model.addAttribute("statusId", plan.getBaseStatus().getId());
  759. }
  760. model.addAttribute("busOrg", busOrg);
  761. model.addAttribute("plan", plan);
  762. model.addAttribute("useWate", useWate);
  763. return "bus/org-plan-view-page";
  764. }
  765. private List<Map<String, String>> loadStatusSelectWithColor(){
  766. List<Map<String,String>> statusList = new ArrayList<Map<String,String>>();
  767. Map<String,String> defaultMap = new HashMap<String,String>();
  768. defaultMap.put("key", "请选择...");
  769. defaultMap.put("value", "");
  770. statusList.add(defaultMap );
  771. List<BaseStatus> allOrgType = busStatusService.getAll();
  772. for(BaseStatus bs:allOrgType){
  773. Map<String,String> map = new HashMap<String,String>();
  774. map.put("key", bs.getStatusColor());
  775. map.put("value", bs.getId().toString());
  776. statusList.add(map);
  777. }
  778. return statusList;
  779. }
  780. private List<Map<String, String>> loadStatusSelectWithName(){
  781. List<Map<String,String>> statusList = new ArrayList<Map<String,String>>();
  782. Map<String,String> defaultMap = new HashMap<String,String>();
  783. defaultMap.put("key", "请选择...");
  784. defaultMap.put("value", "");
  785. statusList.add(defaultMap );
  786. List<BaseStatus> allOrgType = busStatusService.getAll();
  787. for(BaseStatus bs:allOrgType){
  788. Map<String,String> map = new HashMap<String,String>();
  789. map.put("key", bs.getStatusName());
  790. map.put("value", bs.getId().toString());
  791. statusList.add(map);
  792. }
  793. return statusList;
  794. }
  795. /**
  796. * 修改通知
  797. * @param plan
  798. * @return
  799. */
  800. @RequestMapping("editYearUnitNotice.do")
  801. @ResponseBody
  802. public Object editYearUnitNotice(BusAnnualPlanForWater plan,BusOrg busOrg,Long status){
  803. try {
  804. //修改年度计划表
  805. plan.setFillTime(new Date());
  806. plan.setOperatorId(ContextUtil.getCurrentUserId());
  807. plan.setUserName(ContextUtil.getCurrentUser().getFullName());
  808. if(status!=null){
  809. BaseStatus baseStatus = busStatusService.get(status);
  810. plan.setBaseStatus(baseStatus);
  811. }else{
  812. plan.setBaseStatus(null);
  813. }
  814. Long orgId = plan.getId();
  815. //取出原计划的数据,跟提交上来的数据做对比,只要修改过一个季度的 临时用水量,则更新到water_adj_rec表
  816. BusAnnualPlanForWater planwater = busAnnualPlanForWaterService.get(orgId);
  817. if(planwater.getFirstQuarterAdjust()!=plan.getFirstQuarterAdjust()||planwater.getSecondQuarterAdjust()!=plan.getSecondQuarterAdjust()||planwater.getThirdQuarterAdjust()!=plan.getThirdQuarterAdjust()||planwater.getFourthQuarterAdjust()!=plan.getFourthQuarterAdjust())
  818. {
  819. BusWaterAdjRec adjWater = new BusWaterAdjRec();
  820. adjWater.setOrgId(orgId);
  821. adjWater.setFirstQuarterAdjust(plan.getFirstQuarterAdjust());
  822. adjWater.setSecondQuarterAdjust(plan.getSecondQuarterAdjust());
  823. adjWater.setThirdQuarterAdjust(plan.getThirdQuarterAdjust());
  824. adjWater.setFourthQuarterAdjust(plan.getFourthQuarterAdjust());
  825. adjWater.setFillUser(ContextUtil.getCurrentUser().getFullName());
  826. adjWater.setFillTime(new Date());
  827. busWaterAdjRecService.save(adjWater);
  828. }
  829. //客户提出在录入的时候好核对修改邮寄地址,李周芳 2015-03-26
  830. if(busOrg.getOrgId()!=null){
  831. Updater<BusOrg> updater1 = new Updater<BusOrg>(busOrg);
  832. busOrgService.updateByUpdater(updater1);
  833. }
  834. //修改季度考核表
  835. String hql="select q from BusQuarterlyAssessment q where q.org.orgId=? order by q.assessmentQuarter";
  836. List<BusQuarterlyAssessment> list = busQuarterlyAssessmentService.findByHql(hql, orgId);
  837. for (int i = 0; i < list.size(); i++) {
  838. switch (i+1) {
  839. case 1:
  840. BusQuarterlyAssessment qa1 = list.get(i);
  841. if(plan.getFirstQuarterAdjust()!=null && plan.getFirstQuarterAdjust()!=0)
  842. {
  843. qa1.setWaterPlanningIndex(plan.getFirstQuarterAdjust());
  844. }
  845. else
  846. {
  847. qa1.setWaterPlanningIndex(plan.getFirstQuarterReply());
  848. }
  849. busQuarterlyAssessmentService.update(qa1);
  850. break;
  851. case 2:
  852. BusQuarterlyAssessment qa2 = list.get(i);
  853. if(plan.getSecondQuarterAdjust()!=null && plan.getSecondQuarterAdjust()!=0)
  854. {
  855. qa2.setWaterPlanningIndex(plan.getSecondQuarterAdjust());
  856. }
  857. else
  858. {
  859. qa2.setWaterPlanningIndex(plan.getSecondQuarterReply());
  860. }
  861. busQuarterlyAssessmentService.update(qa2);
  862. break;
  863. case 3:
  864. BusQuarterlyAssessment qa3 = list.get(i);
  865. if(plan.getThirdQuarterAdjust()!=null && plan.getThirdQuarterAdjust()!=0)
  866. {
  867. qa3.setWaterPlanningIndex(plan.getThirdQuarterAdjust());
  868. }
  869. else
  870. {
  871. qa3.setWaterPlanningIndex(plan.getThirdQuarterReply());
  872. }
  873. busQuarterlyAssessmentService.update(qa3);
  874. break;
  875. case 4:
  876. BusQuarterlyAssessment qa4 = list.get(i);
  877. if(plan.getFourthQuarterAdjust()!=null && plan.getFourthQuarterAdjust()!=0)
  878. {
  879. qa4.setWaterPlanningIndex(plan.getFourthQuarterAdjust());
  880. }
  881. else
  882. {
  883. qa4.setWaterPlanningIndex(plan.getFourthQuarterReply());
  884. }
  885. busQuarterlyAssessmentService.update(qa4);
  886. break;
  887. default:
  888. break;
  889. }
  890. }
  891. if(plan.getFirstQuarterAdjust()!=null && plan.getFirstQuarterAdjust()!=0)
  892. {
  893. //qa1.setWaterPlanningIndex(plan.getFirstQuarterAdjust());
  894. plan.setFirstQuarterReply(plan.getFirstQuarterAdjust());
  895. }
  896. if(plan.getSecondQuarterAdjust()!=null && plan.getSecondQuarterAdjust()!=0)
  897. {
  898. //qa2.setWaterPlanningIndex(plan.getSecondQuarterAdjust());
  899. plan.setSecondQuarterReply(plan.getSecondQuarterAdjust());
  900. }
  901. if(plan.getThirdQuarterAdjust()!=null && plan.getThirdQuarterAdjust()!=0)
  902. {
  903. //qa3.setWaterPlanningIndex(plan.getThirdQuarterAdjust());
  904. plan.setThirdQuarterReply(plan.getThirdQuarterAdjust());
  905. }
  906. if(plan.getFourthQuarterAdjust()!=null && plan.getFourthQuarterAdjust()!=0)
  907. {
  908. //qa4.setWaterPlanningIndex(plan.getFourthQuarterAdjust());
  909. plan.setFourthQuarterReply(plan.getFourthQuarterAdjust());
  910. }
  911. float flt = plan.getFirstQuarterReply()+plan.getSecondQuarterReply()+plan.getThirdQuarterReply()+plan.getFourthQuarterReply();
  912. plan.setReplyOfWater(flt);
  913. Updater<BusAnnualPlanForWater> updater = new Updater<BusAnnualPlanForWater>(plan);
  914. busAnnualPlanForWaterService.updateByUpdater(updater);
  915. return addJsonSuccessMsg("修改通知成功");
  916. } catch (Exception e) {
  917. return addJsonErrorMsg("修改通知失败,原因是:"+e.getMessage());
  918. }
  919. }
  920. /**
  921. * 水表信息数据
  922. * @param request
  923. * @return
  924. */
  925. @RequestMapping("AdjWaterList.do")
  926. @ResponseBody
  927. public String orgListPage(int pageNo, int pageSize,Long orgId, HttpServletRequest request) {
  928. this.page = busWaterAdjRecService.getAdjListPage(pageNo, pageSize,orgId);
  929. String result = this.getPageJosnResult();
  930. return result;
  931. }
  932. /**
  933. * 删除,即使就是取消考核
  934. * @param ids
  935. * @return
  936. */
  937. @RequestMapping("YearUnitNoticeCancel.do")
  938. @ResponseBody
  939. public Object YearUnitNoticeCancel(Long[] ids){
  940. try {
  941. for(Long id:ids){
  942. // BusAnnualPlanForWater busAnnualPlanForWater = busAnnualPlanForWaterService.get(id);
  943. // busAnnualPlanForWater.setIsCancel(StaticValues.NO_PLAN);
  944. // Updater<BusAnnualPlanForWater> updater = new Updater<BusAnnualPlanForWater>(busAnnualPlanForWater);
  945. // busAnnualPlanForWaterService.updateByUpdater(updater);
  946. //季度考核表如何处理取消考核,要删除掉
  947. String hql = "from BusQuarterlyAssessment b where b.org.orgId=?";
  948. List<BusQuarterlyAssessment> list = busQuarterlyAssessmentService.findByHql(hql, id);
  949. if(null != list && list.size()>0){
  950. for(BusQuarterlyAssessment b:list){
  951. busQuarterlyAssessmentService.remove(b);
  952. }
  953. }
  954. busAnnualPlanForWaterService.remove(id);
  955. }
  956. return addJsonSuccessMsg("操作成功");
  957. } catch (Exception e) {
  958. return addJsonErrorMsg("操作失败,原因是:"+e.getMessage());
  959. }
  960. }
  961. /**
  962. * 导出单位年度计划供水表
  963. * @param orgNumber
  964. * @param orgName
  965. * @param year
  966. * @param busOrgCustomerNumber
  967. * @param address
  968. * @param busOrgMeterNumber
  969. * @param priYearUseWater
  970. * @param userType
  971. * @throws UnsupportedEncodingException
  972. */
  973. @RequestMapping("unitWaterExportData.do")
  974. public void unitWaterExportData(String orgNumber,String orgName,String orgNature,String year,String busOrgCustomerNumber,String address,
  975. String busOrgMeterNumber,String priYearUseWater,String userType,String status,HttpServletResponse response,HttpServletRequest request) throws UnsupportedEncodingException{
  976. //request.setCharacterEncoding("UTF-8");
  977. String hql="select w from BusAnnualPlanForWater w join w.org o where w.isCancel='yes'";
  978. if(!orgNumber.equals("")){
  979. hql +=" and o.orgNumber="+orgNumber;
  980. }
  981. if(!orgName.equals("")){
  982. orgName = new String(orgName.getBytes("iso8859-1"),"UTF-8");
  983. hql +=" and o.orgName like '%"+orgName+"%'";
  984. }
  985. if(!orgNature.equals("")){
  986. orgNature = new String(orgNature.getBytes("iso8859-1"),"UTF-8");
  987. hql +=" and o.orgNature like '%"+orgNature+"%'";
  988. }
  989. if(!year.equals("")){
  990. hql +=" and o.year='"+year+"'";
  991. }else{
  992. year = getCurrentYear();
  993. hql +=" and o.year='"+year+"'";
  994. }
  995. if(!busOrgCustomerNumber.equals("")){
  996. hql +=" and o.orgId in (select bcm.org.orgId from BusCustomerMeter bcm where bcm.customerNumber="+busOrgCustomerNumber+")";
  997. }
  998. if(!address.equals("")){
  999. address = new String(address.getBytes("iso8859-1"),"UTF-8");
  1000. hql +=" and o.address like '%"+address+"%'";
  1001. }
  1002. if(!busOrgMeterNumber.equals("")){
  1003. hql +=" and o.orgId in (select bc.org.orgId from BusCustomerMeter bc where bc.meterNumber="+busOrgMeterNumber+")";
  1004. }
  1005. if(!userType.equals("")){
  1006. hql +=" and o.baseUserType='"+userType+"'";
  1007. }
  1008. if(!priYearUseWater.equals("")){
  1009. Float p = Float.parseFloat(priYearUseWater);
  1010. hql +=" and w.priYearUseWater>="+p;
  1011. }
  1012. if (null != status && !status.equals("")) {
  1013. hql +=" and w.baseStatus="+status;
  1014. }
  1015. hql +=" order by o.orgId";
  1016. writeExcel(response,hql,year);
  1017. }
  1018. private void writeExcel(HttpServletResponse response,String hql,String year){
  1019. String excelName = year+"单位年度计划供水表.xls";
  1020. response.setCharacterEncoding("UTF-8");
  1021. response.setContentType("application/octet-stream");
  1022. OutputStream os = null;
  1023. WritableWorkbook book= null;
  1024. WritableSheet sheet = null;
  1025. try {
  1026. os = response.getOutputStream();
  1027. String downName = new String(excelName.getBytes("gb2312"),"ISO8859-1");
  1028. response.setHeader("content-disposition", "attachment;filename="+downName);
  1029. //创建写入工作薄对象
  1030. book = Workbook.createWorkbook(os);
  1031. //创建一个sheet
  1032. sheet = book.createSheet("sheet1", 0);
  1033. //设置sheet每列宽度及第一行
  1034. createJxlSheet(sheet);
  1035. //往sheet里面添加内容
  1036. fillExcel(sheet,hql,1,500,1);
  1037. book.write();//写入到文件中
  1038. } catch (Exception e) {
  1039. // TODO: handle exception
  1040. }finally{
  1041. try {
  1042. if(null != book){
  1043. book.close();
  1044. }
  1045. if(null != os){
  1046. os.close();
  1047. }
  1048. } catch (Exception e2) {
  1049. }
  1050. }
  1051. }
  1052. private void createJxlSheet(WritableSheet sheet) {
  1053. try {
  1054. // 设置列宽 arg0:列号,arg2宽
  1055. sheet.setColumnView(0, 32);
  1056. sheet.setColumnView(1, 32);
  1057. sheet.setColumnView(2, 32);
  1058. sheet.setColumnView(3, 12);
  1059. sheet.setColumnView(4, 20);
  1060. sheet.setColumnView(5, 5);
  1061. sheet.setColumnView(6, 22);
  1062. sheet.setColumnView(7, 12);
  1063. sheet.setColumnView(8, 12);
  1064. sheet.setColumnView(9, 12);
  1065. sheet.setColumnView(10, 12);
  1066. sheet.setColumnView(11, 12);
  1067. sheet.setColumnView(12, 12);
  1068. // 设置第一行 Label(列号,行号,内容)
  1069. sheet.addCell(new Label(0, 0, "单位名称"));
  1070. sheet.addCell(new Label(1, 0, "单位地址"));
  1071. sheet.addCell(new Label(2, 0, "邮寄地址"));
  1072. sheet.addCell(new Label(3, 0, "邮编"));
  1073. sheet.addCell(new Label(4, 0, "水表户号"));
  1074. sheet.addCell(new Label(5, 0, "年度"));
  1075. sheet.addCell(new Label(6, 0, "上一年度实际用水量(m³)"));
  1076. sheet.addCell(new Label(7, 0, "一季度计划"));
  1077. sheet.addCell(new Label(8, 0, "二季度计划"));
  1078. sheet.addCell(new Label(9, 0, "三季度计划"));
  1079. sheet.addCell(new Label(10, 0, "四季度计划"));
  1080. sheet.addCell(new Label(11, 0, "全年计划"));
  1081. sheet.addCell(new Label(12, 0, "全年批复"));
  1082. sheet.addCell(new Label(13, 0, "是否居民用水"));
  1083. } catch (Exception e) {
  1084. // TODO: handle exception
  1085. }
  1086. }
  1087. private void fillExcel(WritableSheet sheet,String hql,int pageNo,int pageSize,int row){
  1088. try {
  1089. this.page = busAnnualPlanForWaterService.getPageByHql(hql, pageNo, pageSize);
  1090. //记录信息
  1091. List<BusAnnualPlanForWater> list = (List<BusAnnualPlanForWater>)this.page.getResult();
  1092. for(int i=0;i<list.size();i++){
  1093. BusAnnualPlanForWater plan = list.get(i);
  1094. sheet.addCell(new Label(0,row,plan.getOrgName()));//单位名称
  1095. sheet.addCell(new Label(1,row,plan.getOrgAddress()));//单位地址
  1096. sheet.addCell(new Label(2,row,plan.getEmailAddress()));//邮寄地址
  1097. sheet.addCell(new Label(3,row,plan.getPostCode()));//邮编
  1098. sheet.addCell(new Label(4,row,plan.getOrgMeterNumber()));//水表户号
  1099. sheet.addCell(new Label(5,row,plan.getYear()));//年度
  1100. sheet.addCell(new Label(6,row,Math.round(plan.getPriYearUseWater())+""));//上一年实际用水量
  1101. sheet.addCell(new Label(7,row,Math.round(plan.getFirstQuarterReply())+""));//一季度
  1102. sheet.addCell(new Label(8,row,Math.round(plan.getSecondQuarterReply())+""));//二季度
  1103. sheet.addCell(new Label(9,row,Math.round(plan.getThirdQuarterReply())+""));//三季度
  1104. sheet.addCell(new Label(10,row,Math.round(plan.getFourthQuarterReply())+""));//四季度
  1105. sheet.addCell(new Label(11,row,Math.round(plan.getPlanOfWater())+""));//全年
  1106. sheet.addCell(new Label(12,row,Math.round(plan.getReplyOfWater())+""));//全年
  1107. sheet.addCell(new Label(13,row,plan.getOrgType()));//用户类型
  1108. sheet.addCell(new Label(14,row,plan.getOrgNature()));//用水性质
  1109. row+=1;
  1110. }
  1111. if(this.page.hasNextPage()){
  1112. fillExcel(sheet,hql,pageNo+1,pageSize,row);
  1113. }
  1114. } catch (Exception e) {
  1115. // TODO: handle exception
  1116. }
  1117. }
  1118. /**
  1119. * 打印年度计划通知
  1120. * @param model
  1121. * @param ids
  1122. * @return
  1123. */
  1124. @RequestMapping("seasonPlanPrint.do")
  1125. public String seasonPlanPrint(String year,Model model,Long[] ids, HttpServletRequest request){
  1126. if(year.equals("")){
  1127. year = getCurrentYear();
  1128. }
  1129. List<ReplyPrintTemp> list = new ArrayList<ReplyPrintTemp>();
  1130. JBarcode localJBarcode = new JBarcode(EAN13Encoder.getInstance(), WidthCodedPainter.getInstance(), EAN13TextPainter.getInstance());
  1131. if(ids.length>0){
  1132. for(Long orgId:ids){
  1133. BusOrg org = busOrgService.get(orgId);
  1134. String name = org.getOrgName();
  1135. BusAnnualPlanForWater water = org.getBusAnnualPlanForWater();
  1136. Float reply = water.getReplyOfWater();
  1137. Set<BusCustomerMeter> meters = org.getBusCustomerMeters();
  1138. String meter="";
  1139. for(BusCustomerMeter m:meters){
  1140. int me = m.getMeterNumber();
  1141. if(meter.indexOf(me)<0){
  1142. if(meter.length()>0){
  1143. meter +=","+me;
  1144. }else{
  1145. meter += me;
  1146. }
  1147. }
  1148. }
  1149. Date nowdate = new Date();
  1150. ReplyPrintTemp temp = new ReplyPrintTemp(name,meter,water.getContacts(), water.getContactNo(),orgId.toString(), ContextUtil.getCurrentUser().getFullName());
  1151. list.add(temp);
  1152. BufferedImage localBufferedImage;
  1153. try {
  1154. localJBarcode.setEncoder(Code39Encoder.getInstance());
  1155. localJBarcode.setPainter(WideRatioCodedPainter.getInstance());
  1156. localJBarcode.setTextPainter(BaseLineTextPainter.getInstance());
  1157. localJBarcode.setShowCheckDigit(false);
  1158. localBufferedImage = localJBarcode.createBarcode( year+orgId.toString());
  1159. saveToPNG(localBufferedImage, orgId+".png",request);
  1160. } catch (InvalidAtributeException e) {
  1161. // TODO Auto-generated catch block
  1162. e.printStackTrace();
  1163. }
  1164. }
  1165. }
  1166. if(list!=null)
  1167. model.addAttribute("listLength", list.size());
  1168. SimpleDateFormat myFmt=new SimpleDateFormat("yyyy年MM月dd日");
  1169. Date now=new Date();
  1170. model.addAttribute("unit", list);
  1171. model.addAttribute("myFmt", myFmt.format(now));
  1172. return "bus/season-print";
  1173. }
  1174. /**
  1175. * 打印年度计划供水表预览
  1176. * @param model
  1177. * @return
  1178. */
  1179. @RequestMapping("unitYearPlanPrint.do")
  1180. public String unitYearPlanPrint(Model model){
  1181. String year = getCurrentYear();
  1182. String hql="select w from BusAnnualPlanForWater w join w.org o where w.isCancel='yes' and o.year=?";
  1183. List<BusAnnualPlanForWater> list = busAnnualPlanForWaterService.findByHql(hql, year);
  1184. model.addAttribute("plan", list);
  1185. return "bus/org-plan-view";
  1186. }
  1187. /**
  1188. * 打印通知预览
  1189. * @return
  1190. * @throws UnsupportedEncodingException
  1191. */
  1192. @RequestMapping("unitYearReplyPrint.do")
  1193. public String unitYearReplyPrint(String orgNumber,String orgName,String orgNature,String year,String busOrgCustomerNumber,
  1194. String address,String busOrgMeterNumber,String priYearUseWater,String userType,Model model,Long[] ids){
  1195. if(year.equals("")){
  1196. year = getCurrentYear();
  1197. }
  1198. List<ReplyPrintTemp> list = new ArrayList<ReplyPrintTemp>();
  1199. if(ids.length>0){
  1200. for(Long orgId:ids){
  1201. BusOrg org = busOrgService.get(orgId);
  1202. String name = org.getOrgName();
  1203. Set<BusCustomerMeter> meters = org.getBusCustomerMeters();
  1204. String meter="";
  1205. for(BusCustomerMeter m:meters){
  1206. int me = m.getMeterNumber();
  1207. if(meter.indexOf(me)<0){
  1208. if(meter.length()>0){
  1209. meter +=","+me;
  1210. }else{
  1211. meter +=me;
  1212. }
  1213. }
  1214. }
  1215. BusAnnualPlanForWater water= org.getBusAnnualPlanForWater();
  1216. Float one = water.getFirstQuarterReply();
  1217. Float two = water.getSecondQuarterReply();
  1218. Float three = water.getThirdQuarterReply();
  1219. Float fourth = water.getFourthQuarterReply();
  1220. Float reply = water.getReplyOfWater();
  1221. ReplyPrintTemp temp = new ReplyPrintTemp(name,one,two,three,fourth,meter,reply);
  1222. list.add(temp);
  1223. }
  1224. }else{
  1225. list = busOrgService.unitYearReplyPrin(orgNumber, orgName, year, busOrgCustomerNumber, address, busOrgMeterNumber, priYearUseWater, userType, orgNature);
  1226. }
  1227. model.addAttribute("unit", list);
  1228. model.addAttribute("year", year);
  1229. if(list!=null)
  1230. model.addAttribute("listLength", list.size());
  1231. //log.debug("#######################################################"+JsonUtil.getJSONSerializer().deepSerialize(list));
  1232. return "bus/org-reply-view";
  1233. }
  1234. static void saveToPNG(BufferedImage paramBufferedImage, String paramString, HttpServletRequest request)
  1235. {
  1236. saveToFile(paramBufferedImage, paramString, "png",request);
  1237. }
  1238. static void saveToFile(BufferedImage paramBufferedImage, String paramString1, String paramString2, HttpServletRequest request)
  1239. {
  1240. try
  1241. {
  1242. String path=request.getSession().getServletContext().getRealPath("/");
  1243. FileOutputStream localFileOutputStream = new FileOutputStream(path +"/pic/"+ paramString1);
  1244. ImageUtil.encodeAndWrite(paramBufferedImage, paramString2, localFileOutputStream, 96, 96);
  1245. localFileOutputStream.close();
  1246. }
  1247. catch (Exception localException)
  1248. {
  1249. localException.printStackTrace();
  1250. }
  1251. }
  1252. /**
  1253. * 打印封停预览
  1254. * @param orgNumber
  1255. * @param orgName
  1256. * @param year
  1257. * @param busOrgCustomerNumber
  1258. * @param address
  1259. * @param busOrgMeterNumber
  1260. * @param priYearUseWater
  1261. * @param userType
  1262. * @param model
  1263. * @return
  1264. * @throws UnsupportedEncodingException
  1265. */
  1266. @RequestMapping("unitYearEmailPrint.do")
  1267. public String unitYearEmailPrint(String orgNumber,String orgName,String orgNature,String year,String busOrgCustomerNumber,
  1268. String address,String busOrgMeterNumber,String priYearUseWater,String userType,Model model,Long[] ids) throws UnsupportedEncodingException{
  1269. List<OrgTemp> orgList = new ArrayList<OrgTemp>();
  1270. if(year.equals("")){
  1271. year = getCurrentYear();
  1272. }
  1273. if(ids.length>0){
  1274. for(Long orgId:ids){
  1275. BusOrg org = busOrgService.get(orgId);
  1276. String code = org.getCode();
  1277. String name = org.getOrgName();
  1278. String nature = org.getOrgNature();
  1279. String addr= org.getPostalAddress();
  1280. OrgTemp temp = new OrgTemp(code,name,addr);
  1281. orgList.add(temp);
  1282. }
  1283. }else{
  1284. orgList = busOrgService.emailPrintView(orgNumber, orgName, year, busOrgCustomerNumber, address, busOrgMeterNumber, priYearUseWater, userType, orgNature);
  1285. }
  1286. String result = JsonUtil.getJSONSerializer().deepSerialize(orgList);
  1287. log.debug("#####################################size:"+orgList.size()+" "+result);
  1288. model.addAttribute("orgList",result);
  1289. return "bus/org-email-view";
  1290. }
  1291. /**
  1292. * 打印年度计划通知
  1293. * @param orgNumber
  1294. * @param orgName
  1295. * @param year
  1296. * @param busOrgCustomerNumber
  1297. * @param address
  1298. * @param busOrgMeterNumber
  1299. * @param priYearUseWater
  1300. * @param userType
  1301. * @param model
  1302. * @param ids
  1303. * @return
  1304. */
  1305. @RequestMapping("yearPlanPrint.do")
  1306. public String yearPlanPrint(String orgNumber,String orgName,String orgNature,String year,String busOrgCustomerNumber,
  1307. String address,String busOrgMeterNumber,String priYearUseWater,String userType,Model model,Long[] ids){
  1308. if(year.equals("")){
  1309. year = getCurrentYear();
  1310. }
  1311. List<ReplyPrintTemp> list = new ArrayList<ReplyPrintTemp>();
  1312. if(ids.length>0){
  1313. for(Long orgId:ids){
  1314. BusOrg org = busOrgService.get(orgId);
  1315. String name = org.getOrgName();
  1316. BusAnnualPlanForWater water = org.getBusAnnualPlanForWater();
  1317. Float reply = water.getReplyOfWater();
  1318. Set<BusCustomerMeter> meters = org.getBusCustomerMeters();
  1319. String meter="";
  1320. for(BusCustomerMeter m:meters){
  1321. int me = m.getMeterNumber();
  1322. if(meter.indexOf(me)<0){
  1323. if(meter.length()>0){
  1324. meter +=","+me;
  1325. }else{
  1326. meter += me;
  1327. }
  1328. }
  1329. }
  1330. ReplyPrintTemp temp = new ReplyPrintTemp(name,reply,meter);
  1331. list.add(temp);
  1332. }
  1333. }else{
  1334. list = busOrgService.unitYearReplyPrin(orgNumber, orgName, year, busOrgCustomerNumber, address, busOrgMeterNumber, priYearUseWater, userType, orgNature);
  1335. }
  1336. if(list!=null)
  1337. model.addAttribute("listLength", list.size());
  1338. model.addAttribute("list", list);
  1339. return "bus/org-year-plan-notice-print";
  1340. }
  1341. /**
  1342. * 进入年度实际用水汇总页面
  1343. * @param model
  1344. * @return
  1345. */
  1346. @RequestMapping("countReplyWaterList.do")
  1347. public String countReplyWaterList(Model model){
  1348. String year = getCurrentYear();
  1349. Map<String,List<Map<String,String>>> map = new HashMap<String,List<Map<String,String>>>();
  1350. List<Map<String, String>> m = UserType.getList();
  1351. map.put("list", m);
  1352. model.addAttribute("year", year);
  1353. model.addAttribute("userType",JsonUtil.getJSONSerializer().deepSerialize(map));
  1354. return "bus/org-year-count";
  1355. }
  1356. /**
  1357. * 获取年度实际用水汇总信息
  1358. * @param pageNo
  1359. * @param pageSize
  1360. * @param orgNumber
  1361. * @param orgName
  1362. * @param year
  1363. * @param busOrgCustomerNumber
  1364. * @param address
  1365. * @param userType
  1366. * @return
  1367. * @throws ParseException
  1368. */
  1369. @RequestMapping("listCountReplyWater.do")
  1370. @ResponseBody
  1371. public String listCountReplyWater(int pageNo,int pageSize,String orgNumber,
  1372. String orgName,String orgNature, String year, String busOrgCustomerNumber,
  1373. String address,String userType) throws ParseException{
  1374. SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  1375. String sql = " SELECT b.`org_number`,b.`org_name`,b.`address`,b.`year`,w.plan_of_water,w.reply_of_water"
  1376. + " FROM `bus_org` b join `bus_annual_plan_for_water` w on b.org_id=w.org_id"
  1377. + " WHERE b.`import_status`='normal' and b.year='"+year+"' and w.is_cancel='yes'";
  1378. if(null !=orgNumber && !orgNumber.equals("")){
  1379. sql +=" and b.org_number="+orgNumber;
  1380. }
  1381. if(null !=orgName && !orgName.equals("")){
  1382. sql +=" and b.org_name like '%"+orgName+"%'";
  1383. }
  1384. if(null !=orgNature && !orgNature.equals("")){
  1385. sql +=" and b.org_name like '%"+orgNature+"%'";
  1386. }
  1387. if(null !=address && !address.equals("")){
  1388. sql +=" and b.address like '%"+address+"%'";
  1389. }
  1390. if(null !=userType && !userType.equals("")){
  1391. sql +=" and b.user_type ="+userType;
  1392. }
  1393. if(null !=busOrgCustomerNumber && !busOrgCustomerNumber.equals("")){
  1394. sql +=" and b.org_id in (select bcm.org_id from `bus_customer_meter` bcm where bcm.customer_Number="+busOrgCustomerNumber+")";
  1395. }
  1396. this.page = busOrgService.getPageByJdbcTemplate(sql, pageNo, pageSize, new unitCountYearRowMap());
  1397. List<BusOrgTemp> list = (List<BusOrgTemp>)this.page.getResult();
  1398. for(BusOrgTemp b:list){
  1399. int o = b.getOrgNumber();
  1400. int y = Integer.parseInt(b.getYear());
  1401. String s = y+"-01-01 00:00:00";
  1402. String e = y+1+"-01-01 00:00:00";
  1403. List<BusMeterReadInfo> listS = busMeterReadInfoService.getStartOneMonthMeterInfo(o, format.parse(s),format.parse(e));
  1404. Float w=0f;
  1405. if(null != listS){
  1406. for(BusMeterReadInfo info:listS){
  1407. w +=info.getWater();
  1408. }
  1409. }
  1410. b.setYearUseWater(w);
  1411. }
  1412. String result = this.getPageJosnResult();
  1413. log.debug("##################################:"+result);
  1414. return result;
  1415. }
  1416. /**
  1417. * 导出年度实际用水汇总
  1418. * @param orgNumber
  1419. * @param orgName
  1420. * @param year
  1421. * @param busOrgCustomerNumber
  1422. * @param address
  1423. * @param userType
  1424. * @throws UnsupportedEncodingException
  1425. * @throws ParseException
  1426. */
  1427. @RequestMapping("importYearCountUnitWater.do")
  1428. public void importYearCountUnitWater(String orgNumber,String orgName,String orgNature,String year,
  1429. String busOrgCustomerNumber,String address,String userType,HttpServletResponse response) throws UnsupportedEncodingException, ParseException{
  1430. SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  1431. int y =Integer.parseInt(year);
  1432. String fileName = y +"年度实际用水汇总.xls";
  1433. response.setCharacterEncoding("UTF-8");
  1434. response.setContentType("application/octet-stream");
  1435. OutputStream os = null;
  1436. WritableWorkbook book= null;
  1437. WritableSheet sheet = null;
  1438. try {
  1439. os = response.getOutputStream();
  1440. String downName = new String(fileName.getBytes("gb2312"),"ISO8859-1");
  1441. response.setHeader("content-disposition", "attachment;filename="+downName);
  1442. //创建写入工作薄对象
  1443. book = Workbook.createWorkbook(os);
  1444. //创建一个sheet
  1445. sheet = book.createSheet("sheet1", 0);
  1446. //样式
  1447. WritableCellFormat f = new WritableCellFormat();
  1448. f.setAlignment(Alignment.CENTRE);
  1449. //第一行
  1450. addFirstRowExcel(sheet,y,f);
  1451. //获取要导出的数据
  1452. List<BusOrgTemp> list = busOrgService.getPlanYearCountData(orgNumber, orgName, year, busOrgCustomerNumber, address, userType, orgNature);
  1453. int row =1;
  1454. if(list != null && list.size()>0){
  1455. for(int i=0;i<list.size();i++){
  1456. BusOrgTemp temp = list.get(i);
  1457. int o = temp.getOrgNumber();
  1458. Float replyWater = temp.getReplyOfWater();
  1459. Long orgType = temp.getOrgTypeId();
  1460. String type="";
  1461. if(orgType != null && orgType>0){
  1462. type +=orgType;
  1463. }
  1464. String s = y+"-01-01 00:00:00";
  1465. String e = y+1+"-01-01 00:00:00";
  1466. Float w=0f;
  1467. Float over = 0f;
  1468. List<BusMeterReadInfo> listS = busMeterReadInfoService.getStartOneMonthMeterInfo(o, format.parse(s),format.parse(e));
  1469. if(null != listS){
  1470. for(BusMeterReadInfo info:listS){
  1471. w +=info.getWater();
  1472. }
  1473. }
  1474. //节约水量
  1475. Float saveWater = replyWater-w;
  1476. //超用水量
  1477. if(replyWater<w){
  1478. over = w-replyWater;
  1479. }
  1480. if(i%23 == 0){
  1481. //设置行高
  1482. sheet.setRowView(row, 800);
  1483. //填充标题
  1484. sheet.addCell(new Label(1, row, "序号",f));
  1485. sheet.addCell(new Label(2,row,"单位名称",f));
  1486. sheet.addCell(new Label(3,row,"单位类别",f));
  1487. sheet.addCell(new Label(4,row,"计划批复水量",f));
  1488. sheet.addCell(new Label(5,row,"实际批复水量",f));
  1489. sheet.addCell(new Label(6,row,"实用水量",f));
  1490. sheet.addCell(new Label(7,row,"超用水量",f));
  1491. sheet.addCell(new Label(8,row,"节约水量",f));
  1492. row++;
  1493. //设置行高
  1494. sheet.setRowView(row, 800);
  1495. //填充内容
  1496. sheet.addCell(new Label(1, row,i+1+"",f));
  1497. sheet.addCell(new Label(2,row,temp.getOrgName(),f));
  1498. sheet.addCell(new Label(3,row,type,f));
  1499. sheet.addCell(new Label(4,row,temp.getPlanOfWater().toString(),f));
  1500. sheet.addCell(new Label(5,row,temp.getReplyOfWater().toString(),f));
  1501. sheet.addCell(new Label(6,row,w.toString(),f));
  1502. sheet.addCell(new Label(7,row,over.toString(),f));
  1503. sheet.addCell(new Label(8,row,saveWater.toString(),f));
  1504. row++;
  1505. }else{
  1506. //设置行高
  1507. sheet.setRowView(row, 800);
  1508. //填充内容
  1509. sheet.addCell(new Label(1, row,i+1+"",f));
  1510. sheet.addCell(new Label(2,row,temp.getOrgName(),f));
  1511. sheet.addCell(new Label(3,row,type,f));
  1512. sheet.addCell(new Label(4,row,temp.getPlanOfWater().toString(),f));
  1513. sheet.addCell(new Label(5,row,temp.getReplyOfWater().toString(),f));
  1514. sheet.addCell(new Label(6,row,w.toString(),f));
  1515. sheet.addCell(new Label(7,row,over.toString(),f));
  1516. sheet.addCell(new Label(8,row,saveWater.toString(),f));
  1517. row++;
  1518. }
  1519. }
  1520. }
  1521. book.write();//写入到文件中
  1522. } catch (IOException e) {
  1523. // TODO Auto-generated catch block
  1524. e.printStackTrace();
  1525. }catch (RowsExceededException e) {
  1526. // TODO Auto-generated catch block
  1527. e.printStackTrace();
  1528. } catch (WriteException e) {
  1529. // TODO Auto-generated catch block
  1530. e.printStackTrace();
  1531. }finally{
  1532. try {
  1533. if(null != book){
  1534. book.close();
  1535. }
  1536. if(null != os){
  1537. os.close();
  1538. }
  1539. } catch (Exception e2) {
  1540. }
  1541. }
  1542. }
  1543. private void addFirstRowExcel(WritableSheet sheet,int year,WritableCellFormat f){
  1544. try {
  1545. sheet.setColumnView(0, 10);
  1546. sheet.setColumnView(1, 5);
  1547. sheet.setColumnView(2, 15);
  1548. sheet.setColumnView(3, 15);
  1549. sheet.setColumnView(4, 10);
  1550. sheet.setColumnView(5, 10);
  1551. sheet.setColumnView(6, 10);
  1552. sheet.setColumnView(7, 10);
  1553. sheet.setColumnView(8, 10);
  1554. //设置行高
  1555. sheet.setRowView(0, 800);
  1556. //合并单元格,列开,行开,列结,行结
  1557. sheet.mergeCells(1, 0, 8, 0);
  1558. //添加内容
  1559. sheet.addCell(new Label(1, 0, year+"年度实际用水汇总", f));
  1560. } catch (Exception e) {
  1561. // TODO: handle exception
  1562. }
  1563. }
  1564. /**
  1565. * 进入单位类别用水汇总页面
  1566. * @param model
  1567. * @return
  1568. */
  1569. @RequestMapping("countWaterData.do")
  1570. public String countWaterData(Model model){
  1571. String year = getCurrentYear();
  1572. model.addAttribute("year", year);
  1573. return "bus/org-count-list";
  1574. }
  1575. /**
  1576. * 获取单位类别用水汇总数据
  1577. * @param year
  1578. * @return
  1579. */
  1580. @RequestMapping("listCountWaterData.do")
  1581. @ResponseBody
  1582. public String listCountWaterData(String year){
  1583. List<OrgTypeCountTemp> listo = new ArrayList<OrgTypeCountTemp>();
  1584. List<Object[]> list = busOrgService.listCountWaterData(year);
  1585. for(int i=0;i<list.size();i++){
  1586. Object[] obj = list.get(i);
  1587. OrgTypeCountTemp temp = new OrgTypeCountTemp();
  1588. String a = (String) obj[0];
  1589. Float b = (Float) obj[1];
  1590. Float c = (Float) obj[2];
  1591. Float overWater = c>b?c-b:0;
  1592. temp.setOrgType(a);
  1593. temp.setReply(b);
  1594. temp.setUseWater(c);
  1595. temp.setOverWater(overWater);
  1596. temp.setSaveWater(b-c);
  1597. listo.add(temp);
  1598. }
  1599. String result = JsonUtil.getJSONSerializer().deepSerialize(listo);
  1600. log.debug("###################"+list.size()+"###################result:"+result);
  1601. return result;
  1602. }
  1603. /**
  1604. * 导入单位年度信息
  1605. * @param model
  1606. * @return
  1607. */
  1608. @RequestMapping("importInfo.do")
  1609. public String importOrgInfo(ModelMap model){
  1610. return "bus/import-info";
  1611. }
  1612. /**
  1613. * 根据excel导入单位年度信息
  1614. * @param request
  1615. * @param model
  1616. * @return
  1617. * @throws IOException
  1618. */
  1619. @RequestMapping("importInfoData.do")
  1620. @ResponseBody
  1621. public void importOrgInfoData(HttpServletRequest request,HttpServletResponse response,final String year,ModelMap model) throws IOException{
  1622. MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
  1623. Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
  1624. response.setContentType("text/html;charset=utf-8");
  1625. PrintWriter print = response.getWriter();
  1626. for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
  1627. MultipartFile mf = entity.getValue();
  1628. // ImportDataFile idf = new ImportDataFile();
  1629. // idf.setFileName(mf.getOriginalFilename());
  1630. // idf.setFileSize(mf.getSize()/1024);
  1631. // idf.setUploadTime(new Date());
  1632. // idf.setCreater(ContextUtil.getCurrentUser());
  1633. // idf.setCreateTime(new Date());
  1634. // idf.setImportType(ImportType.org_info.name());
  1635. // idf.setYear(year);
  1636. try {
  1637. final Map<String,String> m = FileUploadUtils.uploadFile(mf,path);
  1638. // idf.setFilePath(m.get("file"));
  1639. // idf.setDataStatus(ImportStatus.in_import.name());
  1640. // idf.setStatusDescription("系统正在导入数据,请稍候...");
  1641. //final ImportDataFile idfTmp = importDataFileService.save(idf);
  1642. File uploadFilePath = new File(m.get("path"));
  1643. //判断文件是否已经上传完毕
  1644. if (uploadFilePath.exists() == true) {
  1645. // log.error("****执行单位基本信息导入,导入年份:"+year+",批次id"+idf.getImportId());
  1646. //启动一个线程导入数据
  1647. Thread t1 = new Thread(new Runnable(){
  1648. public void run(){
  1649. busAnnualPlanForWaterService.insertInfoData(path+m.get("file"), year);
  1650. }});
  1651. t1.start();
  1652. print.write("<script type='text/javascript'>alert('上传成功!');top.frmright.resetSearch();top.Dialog.close();</script>");
  1653. }
  1654. } catch (IOException e) {
  1655. print.write("<script type='text/javascript'>alert('上传失败!');</script>");
  1656. e.printStackTrace();
  1657. }
  1658. }
  1659. }
  1660. }