ContractPaymentController.java 53 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271
  1. package cn.com.lzt.contractpayment.controller;
  2. import cn.com.lzt.budget.data.util.BudgetConstant;
  3. import cn.com.lzt.budget.writeback.service.BudgetWriteBackServiceI;
  4. import cn.com.lzt.common.controller.BaseLztController;
  5. import cn.com.lzt.common.service.TSysFileServiceI;
  6. import cn.com.lzt.common.util.DictUtil;
  7. import cn.com.lzt.common.util.LztUtil;
  8. import cn.com.lzt.common.view.JsonDataModelAndView;
  9. import cn.com.lzt.contract.entity.ContractEntity;
  10. import cn.com.lzt.contractinvoice.entity.ContractInvoiceEntity;
  11. import cn.com.lzt.contractp.entity.ContractPEntity;
  12. import cn.com.lzt.contractpayment.dao.ContractPaymentDao;
  13. import cn.com.lzt.contractpayment.dto.ContractPaymentDto;
  14. import cn.com.lzt.contractpayment.entity.ContractPaymentEntity;
  15. import cn.com.lzt.contractpayment.page.ContractPaymentPage;
  16. import cn.com.lzt.contractpayment.service.ContractPaymentServiceI;
  17. import cn.com.lzt.maintainbill.entity.MaintainBillEntity;
  18. import cn.com.lzt.maintainbill.service.MaintainBillServiceI;
  19. import cn.com.lzt.project.entity.ProjectEntity;
  20. import cn.com.lzt.project.service.ProjectServiceI;
  21. import cn.com.lzt.relatedunits.entity.RelatedUnitsEntity;
  22. import cn.com.lzt.tools.DecimalUtils;
  23. import cn.com.lzt.tools.OrderNumTools;
  24. import cn.com.lzt.useractiviti.data.util.ActivitiPdfExport;
  25. import cn.com.lzt.workflow.service.WorkflowServiceI;
  26. import com.xcgl.utils.XcglDateUtils;
  27. import com.xcgl.weixin.entity.WXAjaxJson;
  28. import com.xcgl.weixin.service.WXServiceI;
  29. import org.apache.commons.lang.xwork.StringUtils;
  30. import org.apache.log4j.Logger;
  31. import org.apache.poi.ss.usermodel.Workbook;
  32. import org.jeecgframework.core.beanvalidator.BeanValidators;
  33. import org.jeecgframework.core.common.exception.BusinessException;
  34. import org.jeecgframework.core.common.hibernate.qbc.CriteriaQuery;
  35. import org.jeecgframework.core.common.model.json.AjaxJson;
  36. import org.jeecgframework.core.common.model.json.DataGrid;
  37. import org.jeecgframework.core.constant.Globals;
  38. import org.jeecgframework.core.util.*;
  39. import org.jeecgframework.poi.excel.ExcelExportUtil;
  40. import org.jeecgframework.poi.excel.ExcelImportUtil;
  41. import org.jeecgframework.poi.excel.entity.ExportParams;
  42. import org.jeecgframework.poi.excel.entity.ImportParams;
  43. import org.jeecgframework.poi.excel.entity.vo.NormalExcelConstants;
  44. import org.jeecgframework.tag.core.easyui.TagUtil;
  45. import org.jeecgframework.tag.vo.datatable.SortDirection;
  46. import org.jeecgframework.web.system.pojo.base.TSDepart;
  47. import org.jeecgframework.web.system.pojo.base.TSUser;
  48. import org.jeecgframework.web.system.service.SystemService;
  49. import org.springframework.beans.factory.annotation.Autowired;
  50. import org.springframework.http.HttpHeaders;
  51. import org.springframework.http.HttpStatus;
  52. import org.springframework.http.MediaType;
  53. import org.springframework.http.ResponseEntity;
  54. import org.springframework.stereotype.Controller;
  55. import org.springframework.ui.ModelMap;
  56. import org.springframework.web.bind.annotation.*;
  57. import org.springframework.web.multipart.MultipartFile;
  58. import org.springframework.web.multipart.MultipartHttpServletRequest;
  59. import org.springframework.web.servlet.ModelAndView;
  60. import org.springframework.web.util.UriComponentsBuilder;
  61. import javax.servlet.ServletOutputStream;
  62. import javax.servlet.http.HttpServletRequest;
  63. import javax.servlet.http.HttpServletResponse;
  64. import javax.validation.ConstraintViolation;
  65. import javax.validation.Validator;
  66. import java.io.IOException;
  67. import java.math.BigDecimal;
  68. import java.net.URI;
  69. import java.text.DecimalFormat;
  70. import java.text.ParseException;
  71. import java.text.SimpleDateFormat;
  72. import java.util.*;
  73. import java.util.Map.Entry;
  74. import java.util.zip.ZipEntry;
  75. import java.util.zip.ZipOutputStream;
  76. /**
  77. * @Title: Controller
  78. * @Description: 合同支付申请
  79. * @author onlineGenerator
  80. * @date 2019-03-26 16:36:02
  81. * @version V1.0
  82. *
  83. */
  84. @Controller
  85. @RequestMapping("/contractPaymentController")
  86. public class ContractPaymentController extends BaseLztController {
  87. /**
  88. * Logger for this class
  89. */
  90. private static final Logger logger = Logger.getLogger(ContractPaymentController.class);
  91. @Autowired
  92. private ContractPaymentServiceI contractPaymentService;
  93. @Autowired
  94. private SystemService systemService;
  95. @Autowired
  96. private Validator validator;
  97. @Autowired
  98. private ContractPaymentDao paydao;
  99. @Autowired
  100. private WorkflowServiceI workflowService;
  101. @Autowired
  102. private WXServiceI wXServiceI;
  103. @Autowired
  104. private ProjectServiceI projectServiceI;
  105. @Autowired
  106. private MaintainBillServiceI maintainService;
  107. @Autowired
  108. private TSysFileServiceI tSysFileService;
  109. @Autowired
  110. private BudgetWriteBackServiceI budgetWriteBackService;
  111. /**
  112. * 合同支付申请列表 页面跳转
  113. *
  114. * @return
  115. */
  116. @RequestMapping(params = "applylist")
  117. public ModelAndView applylist(HttpServletRequest request) {
  118. return new ModelAndView("cn/com/lzt/contractpayment/contractPaymentApplyList");
  119. }
  120. @RequestMapping(params = "datagrid4Apply")
  121. public void datagrid4Apply(ContractPaymentEntity contractPayment,HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
  122. CriteriaQuery cq = new CriteriaQuery(ContractPaymentEntity.class, dataGrid);
  123. String code = request.getParameter("code");
  124. contractPayment.setContractname(null);
  125. String projectName = request.getParameter("projectName");
  126. String partnerName =request.getParameter("partnerName");
  127. if(StringUtils.isNotEmpty(projectName)) {
  128. String sql = "select id from t_b_project where name like '%"+projectName+"%'";
  129. List<String> projectIDList = systemService.findListbySql(sql);
  130. cq.in("projectid", projectIDList.toArray());
  131. contractPayment.setProjectName(null);
  132. }
  133. if(StringUtils.isNotEmpty(partnerName)) {
  134. String sql = "select id from t_b_related_units where unit_name like '%"+partnerName+"%'";
  135. List<String> partnerIDList = systemService.findListbySql(sql);
  136. cq.in("partnerid", partnerIDList.toArray());
  137. contractPayment.setPartnerName(null);
  138. }
  139. //查询条件组装器
  140. if(StringUtils.isNotBlank(code)){
  141. //模糊查询
  142. cq.like("code", "%"+code+"%");
  143. contractPayment.setCode(null);
  144. }
  145. cq.addOrder("createDate", SortDirection.desc);
  146. //增加权限处理
  147. TSUser user = ResourceUtil.getSessionUser();
  148. String roleSql = "select rolecode from t_s_role where id in (select roleid from t_s_role_user where userid = ?)";
  149. List<Map<String, Object>> roleMapList = systemService.findForJdbc(roleSql, user.getId());
  150. String roles = "";
  151. if(roleMapList != null && roleMapList.size()>0) {
  152. for (Map<String, Object> roleMap :roleMapList) {
  153. roles += (roleMap.get("rolecode").toString()+",");
  154. }
  155. }
  156. if(roles.indexOf("admin") == -1
  157. && (roles.indexOf("P_XMNQ,") > -1 //项目内勤
  158. || roles.indexOf("P_XMJL,") > -1)/*项目经理*/) {
  159. contractPayment.setCreateBy(user.getUserName());
  160. }
  161. //查询条件组装器
  162. org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, contractPayment);
  163. cq.add();
  164. this.contractPaymentService.getDataGridReturn(cq, true);
  165. TagUtil.datagrid(response, dataGrid);
  166. }
  167. @RequestMapping(params = "paylist")
  168. public ModelAndView paylist(ContractPaymentEntity contractPayment,HttpServletRequest request) {
  169. request.setAttribute("contractPayment", contractPayment);
  170. return new ModelAndView("cn/com/lzt/contractpayment/contractPaymentList");
  171. }
  172. @RequestMapping(params = "payOverlookList")
  173. public ModelAndView payOverlooklist(HttpServletRequest request) {
  174. return new ModelAndView("cn/com/lzt/contractpayment/contractPaymentOverlook");
  175. }
  176. @RequestMapping(params = "datagrid4Pay")
  177. public void datagrid4pay(ContractPaymentEntity contractPayment,HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
  178. CriteriaQuery cq = new CriteriaQuery(ContractPaymentEntity.class, dataGrid);
  179. String projectName = request.getParameter("projectName");
  180. String partnerName =request.getParameter("partnerName");
  181. if(StringUtils.isNotEmpty(projectName)) {
  182. String sql = "select id from t_b_project where name like '%"+projectName+"%'";
  183. List<String> projectIDList = systemService.findListbySql(sql);
  184. cq.in("projectid", projectIDList.toArray());
  185. contractPayment.setProjectName(null);
  186. }
  187. if(StringUtils.isNotEmpty(partnerName)) {
  188. String sql = "select id from t_b_related_units where unit_name like '%"+partnerName+"%'";
  189. List<String> partnerIDList = systemService.findListbySql(sql);
  190. cq.in("partnerid", partnerIDList.toArray());
  191. contractPayment.setPartnerName(null);
  192. }
  193. contractPayment.setBpmStatus(Globals.BPM_STATUS_FINISHED.toString());
  194. //查询条件组装器
  195. org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, contractPayment);
  196. try{
  197. //自定义追加查询条件
  198. //增加权限处理
  199. TSUser user = ResourceUtil.getSessionUser();
  200. String roleSql = "select rolecode from t_s_role where id in (select roleid from t_s_role_user where userid = ?)";
  201. List<Map<String, Object>> roleMapList = systemService.findForJdbc(roleSql, user.getId());
  202. String roles = "";
  203. if(roleMapList != null && roleMapList.size()>0) {
  204. for (Map<String, Object> roleMap :roleMapList) {
  205. roles += (roleMap.get("rolecode").toString()+",");
  206. }
  207. }
  208. if(roles.indexOf("admin") == -1 && roles.indexOf("A_") == -1
  209. && (roles.indexOf("P_XMNQ,") > -1 //项目内勤
  210. || roles.indexOf("P_XMJL,") > -1)/*项目经理*/) {
  211. // 所属项目及兼职项目id
  212. List<String> projectList = projectServiceI.getProjectsByUserid(user.getId());
  213. cq.in("projectid", projectList.toArray());
  214. }
  215. }catch (Exception e) {
  216. throw new BusinessException(e.getMessage());
  217. }
  218. cq.add();
  219. this.contractPaymentService.getDataGridReturn(cq, true);
  220. TagUtil.datagrid(response, dataGrid);
  221. }
  222. /**
  223. * easyui AJAX请求数据
  224. *
  225. * @param request
  226. * @param response
  227. * @param dataGrid
  228. */
  229. @RequestMapping(params = "datagrid")
  230. public void datagrid(ContractPaymentEntity contractPayment,HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
  231. CriteriaQuery cq = new CriteriaQuery(ContractPaymentEntity.class, dataGrid);
  232. //查询条件组装器
  233. org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, contractPayment);
  234. try{
  235. //自定义追加查询条件
  236. String contractid = request.getParameter("contractid");
  237. if(StringUtil.isNotEmpty(contractid)) {
  238. cq.eq("contractid", contractid);
  239. cq.eq("paystatus", Globals.PAY_STATUS_YES);
  240. }
  241. }catch (Exception e) {
  242. throw new BusinessException(e.getMessage());
  243. }
  244. cq.add();
  245. this.contractPaymentService.getDataGridReturn(cq, true);
  246. dataGrid.setFooter("applypayamount:支付合计:,paymentamount");
  247. TagUtil.datagrid(response, dataGrid);
  248. }
  249. /**
  250. * 删除合同支付申请
  251. *
  252. * @return
  253. */
  254. @RequestMapping(params = "doDel")
  255. @ResponseBody
  256. public AjaxJson doDel(ContractPaymentEntity contractPayment, HttpServletRequest request) {
  257. AjaxJson j = new AjaxJson();
  258. contractPayment = systemService.getEntity(ContractPaymentEntity.class, contractPayment.getId());
  259. String message = "合同支付申请删除成功";
  260. try{
  261. maintainService.updatePaymentInfo(null, contractPayment.getId());
  262. contractPaymentService.delMain(contractPayment);
  263. systemService.addLog(message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO);
  264. }catch(Exception e){
  265. e.printStackTrace();
  266. message = "合同支付申请删除失败";
  267. throw new BusinessException(e.getMessage());
  268. }
  269. j.setMsg(message);
  270. return j;
  271. }
  272. /**
  273. * 批量删除合同支付申请
  274. *
  275. * @return
  276. */
  277. @RequestMapping(params = "doBatchDel")
  278. @ResponseBody
  279. public AjaxJson doBatchDel(String ids,HttpServletRequest request){
  280. AjaxJson j = new AjaxJson();
  281. String message = "合同支付申请删除成功";
  282. try{
  283. for(String id:ids.split(",")){
  284. ContractPaymentEntity contractPayment = systemService.getEntity(ContractPaymentEntity.class,
  285. id
  286. );
  287. contractPaymentService.delMain(contractPayment);
  288. systemService.addLog(message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO);
  289. }
  290. }catch(Exception e){
  291. e.printStackTrace();
  292. message = "合同支付申请删除失败";
  293. throw new BusinessException(e.getMessage());
  294. }
  295. j.setMsg(message);
  296. return j;
  297. }
  298. /**
  299. * 添加合同支付申请
  300. *
  301. * @return
  302. */
  303. @RequestMapping(params = "doAdd")
  304. @ResponseBody
  305. public AjaxJson doAdd(ContractPaymentEntity contractPayment,ContractPaymentPage contractPaymentPage, HttpServletRequest request) {
  306. List<ContractInvoiceEntity> contractInvoiceList = contractPaymentPage.getContractInvoiceList();
  307. AjaxJson j = new AjaxJson();
  308. String message = "添加成功";
  309. try{
  310. /*double payAmount = contractPayment.getApplypayamount();
  311. double totalAmount = contractPayment.getTotalamount();
  312. String contractId = contractPayment.getContractid();
  313. String sql = "select sum(applypayamount) from t_b_contract_payment where contractid=? ";
  314. List<Double> list = systemService.findListbySql(sql,contractId);
  315. if(!list.isEmpty()){
  316. Double hasPayAmount = list.get(0);
  317. if(hasPayAmount==null) hasPayAmount=0d;
  318. if(hasPayAmount+payAmount>totalAmount){
  319. j.setMsg("已经申请支付金额超过合同金额");
  320. j.setSuccess(false);
  321. return j;
  322. }
  323. }*/
  324. //默认支付金额=申请金额
  325. contractPayment.setPaymentamount(contractPayment.getApplypayamount());
  326. String maintainIds = contractPayment.getMaintainids();
  327. contractPaymentService.addMain(contractPayment, contractInvoiceList);
  328. tSysFileService.updateBusiId(contractPayment.getAttachment(), contractPayment.getId());
  329. maintainService.updatePaymentInfo(maintainIds, contractPayment.getId());
  330. systemService.addLog(message, Globals.Log_Type_INSERT, Globals.Log_Leavel_INFO);
  331. }catch(Exception e){
  332. e.printStackTrace();
  333. message = "合同支付申请添加失败";
  334. throw new BusinessException(e.getMessage());
  335. }
  336. j.setMsg(message);
  337. return j;
  338. }
  339. /**
  340. * 更新合同支付申请
  341. *
  342. * @return
  343. */
  344. @RequestMapping(params = "doUpdate")
  345. @ResponseBody
  346. public AjaxJson doUpdate(ContractPaymentEntity contractPayment,ContractPaymentPage contractPaymentPage, HttpServletRequest request) {
  347. List<ContractInvoiceEntity> contractInvoiceList = contractPaymentPage.getContractInvoiceList();
  348. AjaxJson j = new AjaxJson();
  349. String message = "更新成功";
  350. try{
  351. //默认支付金额=申请金额
  352. contractPayment.setPaymentamount(contractPayment.getApplypayamount());
  353. contractPaymentService.updateMain(contractPayment, contractInvoiceList);
  354. systemService.addLog(message, Globals.Log_Type_UPDATE, Globals.Log_Leavel_INFO);
  355. }catch(Exception e){
  356. e.printStackTrace();
  357. message = "更新合同支付申请失败";
  358. throw new BusinessException(e.getMessage());
  359. }
  360. j.setMsg(message);
  361. return j;
  362. }
  363. /**
  364. * 合同支付申请新增页面跳转
  365. *
  366. * @return
  367. */
  368. @RequestMapping(params = "goAdd")
  369. public ModelAndView goAdd(ContractPaymentEntity contractPayment, HttpServletRequest req) {
  370. String contractid = req.getParameter("cid");
  371. String contractType = req.getParameter("contractType");
  372. String maintainids = req.getParameter("maintainids");
  373. if(StringUtil.isNotEmpty(contractid)) {
  374. contractPayment.setApplyerid(ResourceUtil.getSessionUser().getId());
  375. contractPayment.setContractid(contractid);
  376. switch (contractType) {
  377. case "service":
  378. ContractEntity contract = systemService.getEntity(ContractEntity.class, contractid);
  379. contractPayment.setContractStartEnd(DateUtils.formatDate(contract.getStartdate(),"yyyy.MM.dd") +"~" +
  380. DateUtils.formatDate( contract.getEnddate(),"yyyy.MM.dd"));
  381. contractPayment.setProjectid(contract.getProjectid());
  382. contractPayment.setPartnerid(contract.getPartnerid());
  383. contractPayment.setTotalamount(contract.getTotalamount());
  384. //设置付款至数据
  385. contractPayment.setPayedPeriodEnd(getPayto(contractPayment.getContractid()));
  386. if(contract.getPaytype().equals("Onetime")) {
  387. contractPayment.setPeriodBegin(DateUtils.date_sdf.format(contract.getStartdate()));
  388. contractPayment.setPeriodEnd(DateUtils.date_sdf.format(contract.getEnddate()));
  389. }else if(contract.getPaytype().equals("Quarterly")) {
  390. String hql = " from ContractPaymentEntity where contractid =? order by createDate desc";
  391. List<ContractPaymentEntity> paymentHis = systemService.findHql(hql, contractid);
  392. if(paymentHis.size() == 0) {
  393. contractPayment.setPeriodBegin(DateUtils.date_sdf.format(contract.getStartdate()));
  394. contractPayment.setPeriodEnd(XcglDateUtils.addDateMonth(contract.getStartdate(), 3, DateUtils.date_sdf));
  395. }else {
  396. String begin = paymentHis.get(0).getPeriodEnd();
  397. contractPayment.setPeriodBegin(XcglDateUtils.addDateDay(begin, 1, DateUtils.date_sdf));
  398. try {
  399. String end = XcglDateUtils.addDateMonth(DateUtils.date_sdf.parse(begin), 3, DateUtils.date_sdf) ;
  400. if(DateUtils.date_sdf.format(contract.getEnddate()).compareTo(end) < 0) {
  401. contractPayment.setPeriodEnd(DateUtils.date_sdf.format(contract.getEnddate()));
  402. }else {
  403. contractPayment.setPeriodEnd(end);
  404. }
  405. }catch (Exception e) {
  406. logger.error(e.getMessage());
  407. }
  408. }
  409. }
  410. if(StringUtils.isNotEmpty(maintainids)) {
  411. setMaintainInfo(contractPayment,maintainids);
  412. }
  413. break;
  414. case "purchase":
  415. ContractPEntity contractp = systemService.getEntity(ContractPEntity.class, contractid);
  416. contractPayment.setProjectid(contractp.getProjectid());
  417. contractPayment.setPartnerid(contractp.getPartnerid());
  418. contractPayment.setTotalamount(contractp.getTotalamount());
  419. break;
  420. default:
  421. break;
  422. }
  423. //按照编码规则设置默认编码
  424. contractPayment.setCode(OrderNumTools.generateNextBillCode(getMaxLocalCode(),Globals.CODE_PREFIX_PAYAPPLY));
  425. //设置支付状态
  426. contractPayment.setPaystatus(Globals.PAY_STATUS_NO);
  427. //默认外包合同,如果传入参数,则设置为传入值
  428. contractPayment.setBilltype(StringUtils.isEmpty(contractType)?"service":contractType);
  429. req.setAttribute("contractPaymentPage", contractPayment);
  430. }
  431. return new ModelAndView("cn/com/lzt/contractpayment/contractPayment-add");
  432. }
  433. /**设置评价
  434. *
  435. * @param payment
  436. * @param maintainids
  437. */
  438. private void setMaintainInfo(ContractPaymentEntity payment,String maintainids) {
  439. payment.setMaintainids(maintainids);
  440. maintainids = maintainids.replaceAll(",", "','");
  441. maintainids = "'"+maintainids + "'";
  442. //取最低分评价,分数为平均值
  443. String sql = "select floor(temp1.score) as score,temp2.valuate as valuete \n" +
  444. " from \n" +
  445. " (select AVG(score) score ,projectid from t_b_maintain_bill where id in ("+maintainids+") group by projectid) temp1\n" +
  446. " left join \n" +
  447. " (select valuate,projectid \n" +
  448. " from t_b_maintain_bill \n" +
  449. " where id in ("+maintainids+")\n" +
  450. " and score = (select min(score) from t_b_maintain_bill where id in ("+maintainids+") group by projectid)) \n" +
  451. " temp2 on temp1.projectid = temp2.projectid";
  452. List<Map<String,Object>> infoList = systemService.findForJdbc(sql);
  453. if(infoList.size() > 0) {
  454. payment.setSupplierscore(((Long)infoList.get(0).get("score")).intValue());
  455. payment.setSupplierevaluate(infoList.get(0).get("valuete").toString());
  456. }
  457. }
  458. /**
  459. * 合同支付申请编辑页面跳转
  460. *
  461. * @return
  462. */
  463. @RequestMapping(params = "goUpdate")
  464. public ModelAndView goUpdate(ContractPaymentEntity contractPayment, HttpServletRequest req) {
  465. if (StringUtil.isNotEmpty(contractPayment.getId())) {
  466. contractPayment = contractPaymentService.getEntity(ContractPaymentEntity.class, contractPayment.getId());
  467. if(StringUtil.isNotEmpty(contractPayment.getProjectid())) {
  468. contractPayment.setProjectName(((ProjectEntity)systemService.getEntity(ProjectEntity.class, contractPayment.getProjectid())).getName());
  469. }
  470. if(StringUtil.isNotEmpty(contractPayment.getPartnerid())) {
  471. contractPayment.setPartnerName(((RelatedUnitsEntity)systemService.getEntity(RelatedUnitsEntity.class, contractPayment.getPartnerid())).getUnitName());
  472. }
  473. contractPayment.setPayedPeriodEnd(getPayto(contractPayment.getContractid()));
  474. ContractEntity contract = systemService.getEntity(ContractEntity.class, contractPayment.getContractid());
  475. contractPayment.setContractStartEnd(DateUtils.formatDate(contract.getStartdate(),"yyyy.MM.dd") +"~" +
  476. DateUtils.formatDate( contract.getEnddate(),"yyyy.MM.dd"));
  477. req.setAttribute("contractPaymentPage", contractPayment);
  478. }
  479. return new ModelAndView("cn/com/lzt/contractpayment/contractPayment-update");
  480. }
  481. private String getPayto(String contractid) {
  482. String payto = "--";
  483. String maxPeriodendSql = "select max(periodend) as payedperiodend from t_b_contract_payment where contractid = '"+contractid+"' and paystatus = '1' ";
  484. List<String> periodList = systemService.findListbySql(maxPeriodendSql);
  485. if(periodList.get(0) != null) {
  486. payto = periodList.get(0);
  487. }
  488. return payto;
  489. }
  490. @RequestMapping(params = "goUpdateMobile")
  491. public ModelAndView goUpdateMobile(ContractPaymentEntity contractPayment, HttpServletRequest req) {
  492. if (StringUtil.isNotEmpty(contractPayment.getId())) {
  493. contractPayment = contractPaymentService.getEntity(ContractPaymentEntity.class, contractPayment.getId());
  494. if(StringUtil.isNotEmpty(contractPayment.getProjectid())) {
  495. contractPayment.setProjectName(((ProjectEntity)systemService.getEntity(ProjectEntity.class, contractPayment.getProjectid())).getAbbreviation());
  496. }
  497. if(StringUtil.isNotEmpty(contractPayment.getPartnerid())) {
  498. contractPayment.setPartnerName(((RelatedUnitsEntity)systemService.getEntity(RelatedUnitsEntity.class, contractPayment.getPartnerid())).getUnitName());
  499. }
  500. //设置合同中的信息
  501. if(contractPayment.getBilltype().equals("service")) {
  502. ContractEntity contract = systemService.getEntity(ContractEntity.class, contractPayment.getContractid());
  503. contractPayment.setContractname(contract.getName());
  504. contractPayment.setTotalpayment(contract.getTotalpayment());
  505. }else if (contractPayment.getBilltype().equals("purchase")) {
  506. ContractPEntity contract = systemService.getEntity(ContractPEntity.class, contractPayment.getContractid());
  507. contractPayment.setContractname(contract.getName());
  508. contractPayment.setTotalpayment(contract.getTotalpayment());
  509. }
  510. String paytype = DictUtil.formatToTypeName(contractPayment.getPaytype(), "paytype");
  511. req.setAttribute("paytype", paytype);
  512. req.setAttribute("entity", contractPayment);
  513. }
  514. Map<String, Object> data = LztUtil.copyReqAttributes(new String[]{
  515. "paytype", "entity"});
  516. return new JsonDataModelAndView(WXAjaxJson.success(data));
  517. }
  518. @RequestMapping(params = "goView")
  519. public ModelAndView goView(ContractPaymentEntity contractPayment, HttpServletRequest request) {
  520. String taskId = request.getParameter("taskId");
  521. //【我发起的流程】-【详情】中查看业务数据时,只看单据信息,不预览审批流程
  522. if(StringUtils.isEmpty(taskId)) {
  523. contractPayment = contractPaymentService.getEntity(ContractPaymentEntity.class, contractPayment.getId());
  524. if(StringUtil.isNotEmpty(contractPayment.getProjectid())) {
  525. contractPayment.setProjectName(((ProjectEntity)systemService.getEntity(ProjectEntity.class, contractPayment.getProjectid())).getName());
  526. }
  527. if(StringUtil.isNotEmpty(contractPayment.getPartnerid())) {
  528. contractPayment.setPartnerName(((RelatedUnitsEntity)systemService.getEntity(RelatedUnitsEntity.class, contractPayment.getPartnerid())).getUnitName());
  529. }
  530. request.setAttribute("contractPaymentPage", contractPayment);
  531. request.setAttribute("viewFlag", 1);
  532. return new ModelAndView("cn/com/lzt/contractpayment/contractPayment-update");
  533. }
  534. if(StringUtils.isNotEmpty(request.getParameter("flag"))){
  535. //驳回重填表单
  536. request.setAttribute("url", "contractPaymentController.do?goUpdate&id="+workflowService.getBpmDataId(taskId));
  537. }else {
  538. request.setAttribute("url", "contractPaymentController.do?goUpdate&load=detail&audit=1&id="+workflowService.getBpmDataId(taskId));
  539. }
  540. Map<String, Object> taskDetails = workflowService.getTaskDetails(taskId);
  541. request.setAttribute("busititle", "付款申请详细信息");
  542. request.setAttribute("id", workflowService.getBpmDataId(taskId));
  543. request.setAttribute("bpmLogList", taskDetails.get("bpmLogList"));
  544. request.setAttribute("taskId", taskDetails.get("taskId"));
  545. request.setAttribute("taskName", taskDetails.get("taskName"));
  546. request.setAttribute("task", taskDetails.get("task"));
  547. request.setAttribute("transitionList", taskDetails.get("transitionList"));
  548. request.setAttribute("nextCodeCount", taskDetails.get("nextCodeCount"));
  549. request.setAttribute("bpmLogListCount", taskDetails.get("bpmLogListCount"));
  550. request.setAttribute("bpmLogNewList", taskDetails.get("bpmLogNewList"));
  551. request.setAttribute("bpmLogNewListCount", taskDetails.get("bpmLogNewListCount"));
  552. request.setAttribute("histListNode", taskDetails.get("histListNode"));
  553. request.setAttribute("histListSize", taskDetails.get("histListSize"));
  554. request.setAttribute("turnbackTaskId", taskDetails.get("turnbackTaskId"));
  555. request.setAttribute("height", "800px");
  556. return new ModelAndView("cn/com/lzt/workflow/task-option");
  557. }
  558. /**
  559. * 加载明细列表[发票明细]
  560. *
  561. * @return
  562. */
  563. @RequestMapping(params = "contractInvoiceList")
  564. public ModelAndView contractInvoiceList(ContractPaymentEntity contractPayment, HttpServletRequest req) {
  565. //===================================================================================
  566. //获取参数
  567. Object id0 = contractPayment.getId();
  568. //===================================================================================
  569. //查询-发票明细
  570. String hql0 = "from ContractInvoiceEntity where 1 = 1 AND pAYMENTID =? ";
  571. try{
  572. List<ContractInvoiceEntity> contractInvoiceEntityList = systemService.findHql(hql0,id0);
  573. req.setAttribute("contractInvoiceList", contractInvoiceEntityList);
  574. }catch(Exception e){
  575. logger.info(e.getMessage());
  576. }
  577. return new ModelAndView("cn/com/lzt/contractinvoice/contractInvoiceList");
  578. }
  579. @RequestMapping(params = "contractInvoiceListReadonly")
  580. public ModelAndView contractInvoiceListReadonly( HttpServletRequest req) {
  581. String contractid = req.getParameter("contractid");
  582. ModelAndView mv = new ModelAndView("cn/com/lzt/contractinvoice/contractInvoiceListReadonly");
  583. req.setAttribute("contractid", contractid);
  584. return mv;
  585. }
  586. @RequestMapping(params = "invoiceDatagrid")
  587. public void invoiceDatagrid(ContractInvoiceEntity contractInvoice,HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
  588. CriteriaQuery cq = new CriteriaQuery(ContractInvoiceEntity.class, dataGrid);
  589. //查询条件组装器
  590. org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, contractInvoice);
  591. cq.add();
  592. this.contractPaymentService.getDataGridReturn(cq, true);
  593. if (StringUtils.isNotEmpty(contractInvoice.getContractid())) {
  594. List<ContractInvoiceEntity> resualtlist = dataGrid.getResults();
  595. Double sum = 0.0;
  596. if (resualtlist.size() != 0) {
  597. for (ContractInvoiceEntity aa : resualtlist) {
  598. sum = sum + Double.valueOf(aa.getInvoiceamount());
  599. }
  600. }
  601. // 格式化为小数点2位数
  602. DecimalFormat df = new DecimalFormat("#.00");
  603. String total_salary = df.format(sum);
  604. dataGrid.setFooter("invoiceamount:合计:"+total_salary);
  605. }
  606. TagUtil.datagrid(response, dataGrid);
  607. }
  608. @RequestMapping(params = "contractPaymentListReadonly")
  609. public ModelAndView contractPaymentListReadonly( HttpServletRequest req) {
  610. String contractid = req.getParameter("contractid");
  611. ModelAndView mv = new ModelAndView("cn/com/lzt/contractpayment/contractPaymentListReadonly");
  612. req.setAttribute("contractid", contractid);
  613. return mv;
  614. }
  615. /**
  616. * 导出excel
  617. *
  618. * @param request
  619. * @param response
  620. */
  621. @RequestMapping(params = "exportXls")
  622. public String exportXls(ContractPaymentEntity contractPayment,HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid,ModelMap map) {
  623. CriteriaQuery cq = new CriteriaQuery(ContractPaymentEntity.class, dataGrid);
  624. contractPayment.setBpmStatus(Globals.BPM_STATUS_FINISHED.toString());
  625. cq.addOrder("createDate", SortDirection.desc);
  626. cq.add();
  627. //查询条件组装器
  628. org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, contractPayment);
  629. List<ContractPaymentEntity> list=this.contractPaymentService.getListByCriteriaQuery(cq, false);
  630. // List<ContractPaymentPage> pageList=new ArrayList<ContractPaymentPage>();
  631. // if(list!=null&&list.size()>0){
  632. // for(ContractPaymentEntity entity:list){
  633. // try{
  634. // ContractPaymentPage page=new ContractPaymentPage();
  635. // MyBeanUtils.copyBeanNotNull2Bean(entity,page);
  636. // Object id0 = entity.getId();
  637. // String hql0 = "from ContractInvoiceEntity where 1 = 1 AND pAYMENTID = ? ";
  638. // List<ContractInvoiceEntity> contractInvoiceEntityList = systemService.findHql(hql0,id0);
  639. // page.setContractInvoiceList(contractInvoiceEntityList);
  640. // pageList.add(page);
  641. // }catch(Exception e){
  642. // logger.info(e.getMessage());
  643. // }
  644. // }
  645. // }
  646. map.put(NormalExcelConstants.FILE_NAME,"合同支付申请"+DateUtils.yyyymmddhhmmss.format(new Date()));
  647. map.put(NormalExcelConstants.CLASS,ContractPaymentEntity.class);
  648. map.put(NormalExcelConstants.PARAMS,new ExportParams("合同支付列表", "导出人:"+ResourceUtil.getSessionUser().getRealName(),
  649. "导出信息"));
  650. map.put(NormalExcelConstants.DATA_LIST,list);
  651. return NormalExcelConstants.JEECG_EXCEL_VIEW;
  652. }
  653. /**
  654. * 通过excel导入数据
  655. * @param request
  656. * @param
  657. * @return
  658. */
  659. @RequestMapping(params = "importExcel", method = RequestMethod.POST)
  660. @ResponseBody
  661. public AjaxJson importExcel(HttpServletRequest request, HttpServletResponse response) {
  662. AjaxJson j = new AjaxJson();
  663. MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
  664. Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
  665. for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
  666. MultipartFile file = entity.getValue();// 获取上传文件对象
  667. ImportParams params = new ImportParams();
  668. params.setTitleRows(2);
  669. params.setHeadRows(2);
  670. params.setNeedSave(true);
  671. try {
  672. List<ContractPaymentPage> list = ExcelImportUtil.importExcel(file.getInputStream(), ContractPaymentPage.class, params);
  673. ContractPaymentEntity entity1=null;
  674. for (ContractPaymentPage page : list) {
  675. entity1=new ContractPaymentEntity();
  676. MyBeanUtils.copyBeanNotNull2Bean(page,entity1);
  677. contractPaymentService.addMain(entity1, page.getContractInvoiceList());
  678. }
  679. j.setMsg("文件导入成功!");
  680. } catch (Exception e) {
  681. j.setMsg("文件导入失败!");
  682. logger.error(ExceptionUtil.getExceptionMessage(e));
  683. }finally{
  684. try {
  685. file.getInputStream().close();
  686. } catch (IOException e) {
  687. e.printStackTrace();
  688. }
  689. }
  690. }
  691. return j;
  692. }
  693. /**
  694. * 导出excel 使模板
  695. */
  696. @RequestMapping(params = "exportXlsByT")
  697. public String exportXlsByT(ModelMap map) {
  698. map.put(NormalExcelConstants.FILE_NAME,"合同支付申请");
  699. map.put(NormalExcelConstants.CLASS,ContractPaymentPage.class);
  700. map.put(NormalExcelConstants.PARAMS,new ExportParams("合同支付申请列表", "导出人:"+ ResourceUtil.getSessionUser().getRealName(),
  701. "导出信息"));
  702. map.put(NormalExcelConstants.DATA_LIST,new ArrayList());
  703. return NormalExcelConstants.JEECG_EXCEL_VIEW;
  704. }
  705. /**
  706. * 导入功能跳转
  707. *
  708. * @return
  709. */
  710. @RequestMapping(params = "upload")
  711. public ModelAndView upload(HttpServletRequest req) {
  712. req.setAttribute("controller_name", "contractPaymentController");
  713. return new ModelAndView("common/upload/pub_excel_upload");
  714. }
  715. @RequestMapping(method = RequestMethod.GET)
  716. @ResponseBody
  717. public List<ContractPaymentEntity> list() {
  718. List<ContractPaymentEntity> listContractPayments=contractPaymentService.getList(ContractPaymentEntity.class);
  719. return listContractPayments;
  720. }
  721. @RequestMapping(value = "/{id}", method = RequestMethod.GET)
  722. @ResponseBody
  723. public ResponseEntity<?> get(@PathVariable("id") String id) {
  724. ContractPaymentEntity task = contractPaymentService.get(ContractPaymentEntity.class, id);
  725. if (task == null) {
  726. return new ResponseEntity(HttpStatus.NOT_FOUND);
  727. }
  728. return new ResponseEntity(task, HttpStatus.OK);
  729. }
  730. @RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
  731. @ResponseBody
  732. public ResponseEntity<?> create(@RequestBody ContractPaymentPage contractPaymentPage, UriComponentsBuilder uriBuilder) {
  733. //调用JSR303 Bean Validator进行校验,如果出错返回含400错误码及json格式的错误信息.
  734. Set<ConstraintViolation<ContractPaymentPage>> failures = validator.validate(contractPaymentPage);
  735. if (!failures.isEmpty()) {
  736. return new ResponseEntity(BeanValidators.extractPropertyAndMessage(failures), HttpStatus.BAD_REQUEST);
  737. }
  738. //保存
  739. List<ContractInvoiceEntity> contractInvoiceList = contractPaymentPage.getContractInvoiceList();
  740. ContractPaymentEntity contractPayment = new ContractPaymentEntity();
  741. try{
  742. MyBeanUtils.copyBeanNotNull2Bean(contractPayment,contractPaymentPage);
  743. }catch(Exception e){
  744. logger.info(e.getMessage());
  745. }
  746. contractPaymentService.addMain(contractPayment, contractInvoiceList);
  747. //按照Restful风格约定,创建指向新任务的url, 也可以直接返回id或对象.
  748. String id = contractPaymentPage.getId();
  749. URI uri = uriBuilder.path("/rest/contractPaymentController/" + id).build().toUri();
  750. HttpHeaders headers = new HttpHeaders();
  751. headers.setLocation(uri);
  752. return new ResponseEntity(headers, HttpStatus.CREATED);
  753. }
  754. @RequestMapping(value = "/{id}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE)
  755. public ResponseEntity<?> update(@RequestBody ContractPaymentPage contractPaymentPage) {
  756. //调用JSR303 Bean Validator进行校验,如果出错返回含400错误码及json格式的错误信息.
  757. Set<ConstraintViolation<ContractPaymentPage>> failures = validator.validate(contractPaymentPage);
  758. if (!failures.isEmpty()) {
  759. return new ResponseEntity(BeanValidators.extractPropertyAndMessage(failures), HttpStatus.BAD_REQUEST);
  760. }
  761. //保存
  762. List<ContractInvoiceEntity> contractInvoiceList = contractPaymentPage.getContractInvoiceList();
  763. ContractPaymentEntity contractPayment = new ContractPaymentEntity();
  764. try{
  765. MyBeanUtils.copyBeanNotNull2Bean(contractPayment,contractPaymentPage);
  766. }catch(Exception e){
  767. logger.info(e.getMessage());
  768. }
  769. contractPaymentService.updateMain(contractPayment, contractInvoiceList);
  770. //按Restful约定,返回204状态码, 无内容. 也可以返回200状态码.
  771. return new ResponseEntity(HttpStatus.NO_CONTENT);
  772. }
  773. @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
  774. @ResponseStatus(HttpStatus.NO_CONTENT)
  775. public void delete(@PathVariable("id") String id) {
  776. ContractPaymentEntity contractPayment = contractPaymentService.get(ContractPaymentEntity.class, id);
  777. contractPaymentService.delMain(contractPayment);
  778. }
  779. private String getMaxLocalCode(){
  780. StringBuilder sb = new StringBuilder();
  781. sb.append("SELECT code FROM t_b_contract_payment ");
  782. sb.append(" where left(create_date,10) = '"+ DateUtils.date_sdf.format(new Date())+"' ");
  783. sb.append(" ORDER BY code DESC");
  784. List<Map<String, Object>> objMapList = systemService.findForJdbc(sb.toString(), 1, 1);
  785. String returnCode = null;
  786. if(objMapList!=null && objMapList.size()>0){
  787. returnCode = (String)objMapList.get(0).get("code");
  788. }
  789. return returnCode;
  790. }
  791. @RequestMapping(params = "exportXlsOfPay")
  792. public synchronized void exportXlsOfPay(String payapplyIDs, HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid,ModelMap map) {
  793. List<ContractPaymentDto> dtolist = new ArrayList<ContractPaymentDto>();
  794. if(payapplyIDs != null) {
  795. String[] splits = payapplyIDs.split(",");
  796. ArrayList<String> applyIDs = new ArrayList<String>();
  797. if(splits.length > 0) {
  798. for(String id :splits) {
  799. applyIDs.add(id);
  800. }
  801. // minidao
  802. dtolist = paydao.getPayFromApplyByApplyIDs(applyIDs);
  803. }
  804. }
  805. if(dtolist.isEmpty()) {
  806. try {
  807. response.sendRedirect(request.getContextPath()+"/contractPaymentController.do?paylist");
  808. } catch (IOException e) {
  809. e.printStackTrace();
  810. }
  811. return;
  812. }
  813. List<String> idList = new ArrayList<>();
  814. for(ContractPaymentDto dto :dtolist){
  815. idList.add(dto.getId());
  816. }
  817. payapplyIDs = StringUtils.join(idList,",");
  818. budgetWriteBack(payapplyIDs,Globals.PAY_STATUS_YES);
  819. List<Workbook> workbooklist = getWorkboodsByPayApplyIDs(dtolist, map);
  820. if(workbooklist == null || workbooklist.size() == 0 || workbooklist.get(0)==null) {
  821. return;
  822. }
  823. ServletOutputStream out = null;
  824. ZipOutputStream zipOutputStream = null;
  825. String timenow = "";
  826. SimpleDateFormat formater = new SimpleDateFormat("yyMMddHHmmss_sss");
  827. try {
  828. timenow = formater.format(new Date());
  829. } catch (Exception e) {
  830. }
  831. try {
  832. out=response.getOutputStream();
  833. String codedFileName = "合同支付清单_"+timenow+".zip";
  834. if (isIE(request)) {
  835. codedFileName = java.net.URLEncoder.encode(codedFileName, "UTF8");
  836. } else {
  837. codedFileName = new String(codedFileName.getBytes("UTF-8"), "ISO-8859-1");
  838. }
  839. zipOutputStream= new ZipOutputStream(out);
  840. response.setContentType("application/octet-stream ");
  841. response.setHeader("Connection", "close"); // 表示不能用浏览器直接打开
  842. response.setHeader("Accept-Ranges", "bytes");// 告诉客户端允许断点续传多线程连接下载
  843. response.setHeader("Content-Disposition",
  844. "attachment;filename=" + codedFileName);
  845. response.setCharacterEncoding("UTF-8");
  846. for(Workbook book : workbooklist) {
  847. ZipEntry entry = new ZipEntry(book.getSheetName(0) + ".xls");
  848. zipOutputStream.putNextEntry(entry);
  849. book.write(zipOutputStream);
  850. }
  851. zipOutputStream.flush();
  852. updateApplyStatus(payapplyIDs,Globals.PAY_STATUS_YES);
  853. updateContract(payapplyIDs,Globals.PAY_STATUS_YES);
  854. sendWXmsgToRelatedPerson(payapplyIDs);
  855. } catch (IOException e) {
  856. org.jeecgframework.core.util.LogUtil.error(e.getMessage());
  857. }finally {
  858. if(zipOutputStream != null) {
  859. try {
  860. zipOutputStream.close();
  861. } catch (IOException e) {
  862. org.jeecgframework.core.util.LogUtil.error(e.getMessage());
  863. }
  864. }
  865. }
  866. }
  867. private void budgetWriteBack(String payapplyIDs, String yes) {
  868. String[] idArray = payapplyIDs.split(",");
  869. for(String id :idArray){
  870. ContractPaymentEntity paymentEntity = systemService.getEntity(ContractPaymentEntity.class, id);
  871. String budgetMonth = paymentEntity.getBudgetMonth();
  872. String contractId = paymentEntity.getContractid();
  873. BigDecimal value = new BigDecimal(paymentEntity.getApplypayamount());
  874. ContractEntity contractEntity = systemService.getEntity(ContractEntity.class, contractId);
  875. String measureId = contractEntity.getBudgetMeasureId();
  876. String projectid = contractEntity.getProjectid();
  877. String departId=null;
  878. String findProjectDepartHql = "from TSDepart where projectid=? and length(orgCode)=6";
  879. List<TSDepart> list = systemService.findHql(findProjectDepartHql,projectid);
  880. if(!list.isEmpty()){
  881. departId =list.get(0).getId();
  882. }
  883. if(StringUtils.equals(yes,Globals.PAY_STATUS_NO )){
  884. value = value.negate();
  885. }
  886. budgetWriteBackService.writeBack(BudgetConstant.BusType.contract_payment, "contract_payment", departId, measureId,null, value,budgetMonth , "t_b_contract_payment", id);
  887. }
  888. // budgetWriteBackService
  889. }
  890. /**
  891. * 变更付款状态,支付操作员,支付日期
  892. *
  893. * */
  894. private void updateApplyStatus(String ids,String newStatus) {
  895. StringBuffer strIDs= new StringBuffer();
  896. String[] splits = null;
  897. if(ids != null) {
  898. splits = ids.split(",");
  899. if(splits.length > 0) {
  900. for(int i = 0;i < splits.length;i++) {
  901. if(i == 0)
  902. strIDs.append("'"+splits[i]+"'");
  903. else
  904. strIDs.append(",").append("'"+splits[i]+"'");
  905. }
  906. }
  907. }
  908. if(strIDs.length()>0) {
  909. String updateSql = "";
  910. if(newStatus.equals(Globals.PAY_STATUS_NO))
  911. updateSql = "update t_b_contract_payment set paystatus='"+newStatus+"' ,payOperator= null,paydate=null,c2cpayment=null,c2npayment=null,c2lpayment=null where id in ("+strIDs.toString()+")";
  912. else
  913. updateSql = "update t_b_contract_payment set paystatus='"+newStatus+"' ,"
  914. + "paydate ='"+DateUtils.datetimeFormat.format(new Date())+"' ,"
  915. + "payOperator = '"+ResourceUtil.getSessionUser().getId()+"' "
  916. // + "paymentamount = applypayamount"
  917. + " where id in ("+strIDs.toString()+")";
  918. systemService.executeSql(updateSql);
  919. //增加:拆分跨年度的付款金额
  920. try {
  921. if(newStatus.equals(Globals.PAY_STATUS_YES) && splits != null){
  922. for(String id:splits) {
  923. ContractPaymentEntity payment = systemService.get(ContractPaymentEntity.class, id);
  924. setFinancialData(payment);
  925. contractPaymentService.saveOrUpdate(payment);
  926. }
  927. }
  928. }catch (ParseException pe) {
  929. logger.equals(pe.getMessage());
  930. }
  931. }
  932. }
  933. /**
  934. * 回写合同累计支付金额
  935. *
  936. * */
  937. private void updateContract(String ids,String newStatus) {
  938. StringBuffer strIDs= new StringBuffer();
  939. if(ids != null) {
  940. String[] splits = ids.split(",");
  941. if(splits.length > 0) {
  942. for(int i = 0;i < splits.length;i++) {
  943. if(i == 0)
  944. strIDs.append("'"+splits[i]+"'");
  945. else
  946. strIDs.append(",").append("'"+splits[i]+"'");
  947. }
  948. }
  949. }
  950. if(strIDs.length()>0) {
  951. String updateSql = "";
  952. //取消时,减去本次支付金额
  953. if(newStatus.equals(Globals.PAY_STATUS_NO))
  954. updateSql = "update t_b_contract c \n" +
  955. "set c.totalpayment = c.totalpayment - (\n" +
  956. " select sum(paymentamount) \n" +
  957. " from t_b_contract_payment p \n" +
  958. " where p.id in("+strIDs.toString()+")\n" +
  959. " and p.contractid = c.id) \n" +
  960. "where c.id in (select contractid from t_b_contract_payment pa \n" +
  961. " where pa.id in("+strIDs.toString()+"))";
  962. else
  963. //支付完成时,增加本次支付金额
  964. updateSql = "update t_b_contract c \n" +
  965. "set c.totalpayment = c.totalpayment + (\n" +
  966. " select sum(paymentamount) \n" +
  967. " from t_b_contract_payment p \n" +
  968. " where p.id in("+strIDs.toString()+")\n" +
  969. " and p.contractid = c.id) \n" +
  970. "where c.id in (select contractid from t_b_contract_payment pa \n" +
  971. " where pa.id in("+strIDs.toString()+"))";
  972. systemService.executeSql(updateSql);
  973. }
  974. }
  975. private List<Workbook> getWorkboodsByPayApplyIDs(List<ContractPaymentDto> dtolist,ModelMap map){
  976. getContractPaymentDtos(dtolist);
  977. ArrayList<Workbook> workbooklist = new ArrayList<>();
  978. String name = "外包合同支付清单"+DateUtils.yyyymmddhhmmss.format(new Date());
  979. map.put(NormalExcelConstants.FILE_NAME,name);
  980. map.put(NormalExcelConstants.CLASS,ContractPaymentDto.class);
  981. ExportParams params = new ExportParams();
  982. params.setSheetName(name);
  983. params.setAddIndex(false);
  984. map.put(NormalExcelConstants.PARAMS,params);
  985. map.put(NormalExcelConstants.DATA_LIST,dtolist);
  986. Workbook workbook = getSingleWorkbooksByModel(map);
  987. workbooklist.add(workbook);
  988. return workbooklist;
  989. }
  990. private List<ContractPaymentDto> getContractPaymentDtos(List<ContractPaymentDto> dtolist) {
  991. //设置默认值及默认规则
  992. for(ContractPaymentDto paydto : dtolist) {
  993. paydto.setAccountName(Globals.PAY_ACCOUNT_NAME);
  994. paydto.setPayAccountNo(Globals.PAY_ACCOUNT_NO);
  995. paydto.setPayCustomerNo(Globals.PAY_CustomerNo);
  996. //支付类型: if 转账类型 = 行内,为空;行外,上海=1,非上海=0
  997. if(paydto.getTransferType().equals("0")) {
  998. paydto.setPayType(null);
  999. }else {
  1000. if(paydto.getReceiveAcountBank().indexOf("上海") > -1) {
  1001. paydto.setPayType("1");
  1002. }else
  1003. paydto.setPayType("0");
  1004. }
  1005. // 收款账户名称长度大于等于8,则为对公
  1006. if(paydto.getReceiveAccountName().length() > 7)
  1007. paydto.setAccountSign("0");
  1008. else
  1009. paydto.setAccountSign("1");
  1010. }
  1011. return dtolist;
  1012. }
  1013. private Workbook getSingleWorkbooksByModel(Map<String, Object> model) {
  1014. Workbook workbook = ExcelExportUtil.exportExcel((ExportParams) model.get(NormalExcelConstants.PARAMS)
  1015. , (Class<?>) model.get(NormalExcelConstants.CLASS), (Collection<?>) model.get(NormalExcelConstants.DATA_LIST));
  1016. return workbook;
  1017. }
  1018. boolean isIE(HttpServletRequest request) {
  1019. return (request.getHeader("USER-AGENT").toLowerCase().indexOf("msie") > 0 || request.getHeader("USER-AGENT").toLowerCase().indexOf("rv:11.0") > 0) ? true : false;
  1020. }
  1021. @RequestMapping(params = "doCancelPay")
  1022. @ResponseBody
  1023. public AjaxJson doCancelAuditOrder(String id,String refundvalue, HttpServletRequest req) {
  1024. AjaxJson j = new AjaxJson();
  1025. String message = null;
  1026. // ContractPaymentEntity payment = contractPaymentService.getEntity(ContractPaymentEntity.class, id);
  1027. updateApplyStatus(id, Globals.PAY_STATUS_NO);
  1028. updateContract(id,Globals.PAY_STATUS_NO);
  1029. budgetWriteBack(id,Globals.PAY_STATUS_NO);
  1030. message = "成功取消支付";
  1031. j.setMsg(message);
  1032. return j;
  1033. }
  1034. /**
  1035. * 给支付申请人、行政部经理发送微信通知,通知其支付完毕
  1036. * */
  1037. private void sendWXmsgToRelatedPerson(String paymentids) {
  1038. StringBuffer strIDs= new StringBuffer();
  1039. if(paymentids != null) {
  1040. String[] splits = paymentids.split(",");
  1041. if(splits.length > 0) {
  1042. for(int i = 0;i < splits.length;i++) {
  1043. if(i == 0)
  1044. strIDs.append("'"+splits[i]+"'");
  1045. else
  1046. strIDs.append(",").append("'"+splits[i]+"'");
  1047. }
  1048. }
  1049. }
  1050. String sqlApplier = "select u.openid as openid,pay.code as paycode ,pay.paymentamount as payamount,unit.unit_name as partnername \n" +
  1051. "from t_b_contract_payment pay \n" +
  1052. "left join t_s_user u on pay.applyerid = u.id \n" +
  1053. "left join t_b_related_units unit on pay.partnerid = unit.id\n" +
  1054. "where pay.id in("+strIDs.toString()+")";
  1055. List<Map<String,Object>> payDetails = systemService.findForJdbc(sqlApplier);
  1056. String sqlXZBJL = "select openid from t_s_user tsu where id in "
  1057. + "(select userid from t_s_role_user ru "
  1058. + "left join t_s_role role on ru.roleid = role.id where role.rolecode = 'A_XZBJL')";
  1059. List<Map<String,Object>> xzbjlRes = systemService.findForJdbc(sqlXZBJL);
  1060. String xzbjlOpenid = null;
  1061. if(xzbjlRes!= null && xzbjlRes.size() > 0 && xzbjlRes.get(0).get("openid") != null){
  1062. xzbjlOpenid = xzbjlRes.get(0).get("openid").toString();
  1063. }
  1064. if(payDetails != null && payDetails.size() > 0) {
  1065. //行政部经理提醒信息内容
  1066. StringBuffer xzbjlKeyword1 = new StringBuffer();
  1067. StringBuffer xzbjlKeyword2 = new StringBuffer();
  1068. //申请人提醒信息
  1069. HashMap<String,StringBuffer> hmApplierKeyword1 = new HashMap<String, StringBuffer>();
  1070. HashMap<String,StringBuffer> hmApplierKeyword2 = new HashMap<String, StringBuffer>();
  1071. for(Map<String,Object> paydetail:payDetails) {
  1072. String openid = paydetail.get("openid") == null?"":paydetail.get("openid").toString();
  1073. //申请单号
  1074. String paycode = paydetail.get("paycode").toString();
  1075. //金额
  1076. String payamount = DecimalUtils.formatToStr((double)paydetail.get("payamount"));
  1077. //供应商
  1078. String partner = paydetail.get("partnername").toString();
  1079. if(StringUtils.isNotEmpty(openid)) {
  1080. if(hmApplierKeyword1.containsKey(openid)) {
  1081. hmApplierKeyword1.get(openid).append(paycode).append(",");
  1082. hmApplierKeyword2.get(openid).append(payamount).append("元,");
  1083. }else {
  1084. hmApplierKeyword1.put(openid, new StringBuffer(paycode+","));
  1085. hmApplierKeyword2.put(openid, new StringBuffer(payamount+"元,"));
  1086. }
  1087. }
  1088. xzbjlKeyword1.append(paycode).append(",");
  1089. xzbjlKeyword2.append("\n").append(partner).append(":").append(payamount).append("元");
  1090. }
  1091. List<Map<String,Object>> listParams = new ArrayList<Map<String,Object>>();
  1092. for(Entry<String, StringBuffer> userMSG : hmApplierKeyword1.entrySet()) {
  1093. Map<String,Object> oneMsg = new HashMap<String, Object>();
  1094. Map<String, Object> userMsgParms = new HashMap<String, Object>();
  1095. String keyword1SplitStr = userMSG.getValue().toString();
  1096. String keyword2SplitStr = hmApplierKeyword2.get(userMSG.getKey()).toString();
  1097. userMsgParms.put("first", "你有一个支付申请已经支付完毕");
  1098. userMsgParms.put("keyword1",keyword1SplitStr.substring(0, keyword1SplitStr.length()-1));
  1099. userMsgParms.put("keyword2", keyword2SplitStr.substring(0, keyword2SplitStr.length()-1));
  1100. userMsgParms.put("remark", "可以登录慧管理系统查看详细信息。");
  1101. oneMsg.put("openid", userMSG.getKey());//"oQ2vj04CDPxjrvp9WlyJkXEfg4S8"
  1102. oneMsg.put("userid", "");
  1103. oneMsg.put("tplParams", userMsgParms);
  1104. listParams.add(oneMsg);
  1105. }
  1106. if(StringUtils.isNotEmpty(xzbjlOpenid)) {
  1107. Map<String,Object> oneMsg = new HashMap<String, Object>();
  1108. Map<String, Object> userMsgParms = new HashMap<String, Object>();
  1109. userMsgParms.put("first", "今日供应商支付完毕");
  1110. userMsgParms.put("keyword1",xzbjlKeyword1.substring(0, xzbjlKeyword1.length()-1));
  1111. userMsgParms.put("keyword2", xzbjlKeyword2.toString());
  1112. userMsgParms.put("remark", "可以登录慧管理系统查看详细信息。");
  1113. oneMsg.put("openid", xzbjlOpenid);//"oQ2vj04CDPxjrvp9WlyJkXEfg4S8"
  1114. oneMsg.put("userid", "");
  1115. oneMsg.put("tplParams", userMsgParms);
  1116. listParams.add(oneMsg);
  1117. }
  1118. try {
  1119. wXServiceI.sendMsgToWXForPayComplete(listParams);
  1120. }catch (Exception e) {
  1121. logger.error("微信消息发送失败,请管理员检查配置");
  1122. logger.error(e.getMessage());
  1123. }
  1124. }
  1125. }
  1126. /**
  1127. * 设置开上年、开下年、开本年金额
  1128. * @throws ParseException
  1129. * */
  1130. private ContractPaymentEntity setFinancialData(ContractPaymentEntity payment) throws ParseException {
  1131. if(payment.getPeriodBegin().substring(0,4).equals(payment.getPeriodEnd().substring(0,4))) {
  1132. //不跨年
  1133. payment.setC2cpayment(payment.getPaymentamount());
  1134. payment.setC2npayment(DecimalUtils.ZERO);
  1135. payment.setC2lpayment(DecimalUtils.ZERO);
  1136. }else {
  1137. //跨年时,需要计算开上一年或开下一年金额
  1138. Date begin = DateUtils.datetimeFormat.parse(payment.getPeriodBegin()+" 00:00:00");
  1139. Date end = DateUtils.datetimeFormat.parse(payment.getPeriodEnd()+" 00:00:00");
  1140. //属于上一年的天数
  1141. int firstHalf = XcglDateUtils.differentDays2YearEnd(begin)+1;
  1142. //属于下一年的天数
  1143. int secondHalf = XcglDateUtils.differentDays2YearStart(end)+1;
  1144. double firstAmount = DecimalUtils.formatToDouble((payment.getPaymentamount()*firstHalf)/(firstHalf+secondHalf));
  1145. double secondAmount = DecimalUtils.formatToDouble(payment.getPaymentamount()-firstAmount);
  1146. //如果付款日期属于上半个阶段
  1147. if(payment.getPeriodBegin().substring(0,4).equals(
  1148. DateUtils.date_sdf.format(payment.getPaydate()).substring(0,4))) {
  1149. payment.setC2cpayment(firstAmount);//开本年
  1150. payment.setC2npayment(secondAmount);//开下年
  1151. payment.setC2lpayment(DecimalUtils.ZERO);//开上年
  1152. }else {
  1153. //付款日期属于下半个阶段
  1154. payment.setC2cpayment(firstAmount);//开本年
  1155. payment.setC2npayment(DecimalUtils.ZERO);//开下年
  1156. payment.setC2lpayment(secondAmount);//开上年
  1157. }
  1158. }
  1159. return payment;
  1160. }
  1161. /**
  1162. * 判断相同外包合同,7天内,付款金额相同情况,如果存在,则返回json fasle
  1163. * */
  1164. @RequestMapping(params = "checkDuplicate")
  1165. @ResponseBody
  1166. public AjaxJson checkDuplicate(ContractPaymentEntity payment, HttpServletRequest req) {
  1167. AjaxJson j = new AjaxJson();
  1168. String message = "无重复申请";
  1169. String hql = "";
  1170. List<ContractPaymentEntity> duplicateApply = new ArrayList<ContractPaymentEntity>();
  1171. if(StringUtils.isNotEmpty(payment.getId())) {
  1172. hql = " from ContractPaymentEntity where contractid =? and applypayamount =? and id <> ? ";
  1173. duplicateApply = systemService.findHql(hql, payment.getContractid(),payment.getApplypayamount(),payment.getId());
  1174. }else {
  1175. hql = " from ContractPaymentEntity where contractid =? and applypayamount =? ";
  1176. duplicateApply = systemService.findHql(hql, payment.getContractid(),payment.getApplypayamount());
  1177. }
  1178. for (ContractPaymentEntity contractPaymentEntity : duplicateApply) {
  1179. int deffDay = XcglDateUtils.differentDays(contractPaymentEntity.getCreateDate(), new Date());
  1180. if(deffDay < 8) {
  1181. j.setSuccess(false);
  1182. message = "此外包合同在"+DateUtils.date_sdf_wz.format(contractPaymentEntity.getCreateDate())+"提交过相同金额付款申请";
  1183. break;
  1184. }
  1185. }
  1186. j.setMsg(message);
  1187. return j;
  1188. }
  1189. @RequestMapping(params="exportMaintainbill")
  1190. public void exportDetailPdf4Mobile(@RequestParam("id") String id, HttpServletResponse response){
  1191. ContractPaymentEntity entity = systemService.getEntity(ContractPaymentEntity.class,id);
  1192. CriteriaQuery cq = new CriteriaQuery(MaintainBillEntity.class);
  1193. String ids = entity.getMaintainids();
  1194. String[] idArray = StringUtils.split(ids,",");
  1195. cq.in("id",idArray);
  1196. cq.add();
  1197. List<MaintainBillEntity> list =systemService.getListByCriteriaQuery(cq,false);
  1198. ActivitiPdfExport export = new ActivitiPdfExport();
  1199. export.table(6);
  1200. export.titleCell("合同名称","项目名称","供应商名称","维保月度","实际完成日期","服务评分");
  1201. for(MaintainBillEntity billEntity : list){
  1202. export.cell(billEntity.getContractname(),billEntity.getProjectname(),billEntity.getRelatedunitname()
  1203. ,billEntity.getMaintainMonth(),DateUtils.formatDate(billEntity.getServicedate()),String.valueOf(billEntity.getScore()));
  1204. }
  1205. export.view(response,false);
  1206. }
  1207. }