| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271 |
- package cn.com.lzt.contractpayment.controller;
- import cn.com.lzt.budget.data.util.BudgetConstant;
- import cn.com.lzt.budget.writeback.service.BudgetWriteBackServiceI;
- import cn.com.lzt.common.controller.BaseLztController;
- import cn.com.lzt.common.service.TSysFileServiceI;
- import cn.com.lzt.common.util.DictUtil;
- import cn.com.lzt.common.util.LztUtil;
- import cn.com.lzt.common.view.JsonDataModelAndView;
- import cn.com.lzt.contract.entity.ContractEntity;
- import cn.com.lzt.contractinvoice.entity.ContractInvoiceEntity;
- import cn.com.lzt.contractp.entity.ContractPEntity;
- import cn.com.lzt.contractpayment.dao.ContractPaymentDao;
- import cn.com.lzt.contractpayment.dto.ContractPaymentDto;
- import cn.com.lzt.contractpayment.entity.ContractPaymentEntity;
- import cn.com.lzt.contractpayment.page.ContractPaymentPage;
- import cn.com.lzt.contractpayment.service.ContractPaymentServiceI;
- import cn.com.lzt.maintainbill.entity.MaintainBillEntity;
- import cn.com.lzt.maintainbill.service.MaintainBillServiceI;
- import cn.com.lzt.project.entity.ProjectEntity;
- import cn.com.lzt.project.service.ProjectServiceI;
- import cn.com.lzt.relatedunits.entity.RelatedUnitsEntity;
- import cn.com.lzt.tools.DecimalUtils;
- import cn.com.lzt.tools.OrderNumTools;
- import cn.com.lzt.useractiviti.data.util.ActivitiPdfExport;
- import cn.com.lzt.workflow.service.WorkflowServiceI;
- import com.xcgl.utils.XcglDateUtils;
- import com.xcgl.weixin.entity.WXAjaxJson;
- import com.xcgl.weixin.service.WXServiceI;
- import org.apache.commons.lang.xwork.StringUtils;
- import org.apache.log4j.Logger;
- import org.apache.poi.ss.usermodel.Workbook;
- import org.jeecgframework.core.beanvalidator.BeanValidators;
- import org.jeecgframework.core.common.exception.BusinessException;
- import org.jeecgframework.core.common.hibernate.qbc.CriteriaQuery;
- import org.jeecgframework.core.common.model.json.AjaxJson;
- import org.jeecgframework.core.common.model.json.DataGrid;
- import org.jeecgframework.core.constant.Globals;
- import org.jeecgframework.core.util.*;
- import org.jeecgframework.poi.excel.ExcelExportUtil;
- import org.jeecgframework.poi.excel.ExcelImportUtil;
- import org.jeecgframework.poi.excel.entity.ExportParams;
- import org.jeecgframework.poi.excel.entity.ImportParams;
- import org.jeecgframework.poi.excel.entity.vo.NormalExcelConstants;
- import org.jeecgframework.tag.core.easyui.TagUtil;
- import org.jeecgframework.tag.vo.datatable.SortDirection;
- import org.jeecgframework.web.system.pojo.base.TSDepart;
- import org.jeecgframework.web.system.pojo.base.TSUser;
- import org.jeecgframework.web.system.service.SystemService;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.http.HttpHeaders;
- import org.springframework.http.HttpStatus;
- import org.springframework.http.MediaType;
- import org.springframework.http.ResponseEntity;
- import org.springframework.stereotype.Controller;
- import org.springframework.ui.ModelMap;
- import org.springframework.web.bind.annotation.*;
- import org.springframework.web.multipart.MultipartFile;
- import org.springframework.web.multipart.MultipartHttpServletRequest;
- import org.springframework.web.servlet.ModelAndView;
- import org.springframework.web.util.UriComponentsBuilder;
- import javax.servlet.ServletOutputStream;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import javax.validation.ConstraintViolation;
- import javax.validation.Validator;
- import java.io.IOException;
- import java.math.BigDecimal;
- import java.net.URI;
- import java.text.DecimalFormat;
- import java.text.ParseException;
- import java.text.SimpleDateFormat;
- import java.util.*;
- import java.util.Map.Entry;
- import java.util.zip.ZipEntry;
- import java.util.zip.ZipOutputStream;
- /**
- * @Title: Controller
- * @Description: 合同支付申请
- * @author onlineGenerator
- * @date 2019-03-26 16:36:02
- * @version V1.0
- *
- */
- @Controller
- @RequestMapping("/contractPaymentController")
- public class ContractPaymentController extends BaseLztController {
- /**
- * Logger for this class
- */
- private static final Logger logger = Logger.getLogger(ContractPaymentController.class);
- @Autowired
- private ContractPaymentServiceI contractPaymentService;
- @Autowired
- private SystemService systemService;
- @Autowired
- private Validator validator;
- @Autowired
- private ContractPaymentDao paydao;
- @Autowired
- private WorkflowServiceI workflowService;
- @Autowired
- private WXServiceI wXServiceI;
- @Autowired
- private ProjectServiceI projectServiceI;
- @Autowired
- private MaintainBillServiceI maintainService;
- @Autowired
- private TSysFileServiceI tSysFileService;
- @Autowired
- private BudgetWriteBackServiceI budgetWriteBackService;
- /**
- * 合同支付申请列表 页面跳转
- *
- * @return
- */
- @RequestMapping(params = "applylist")
- public ModelAndView applylist(HttpServletRequest request) {
- return new ModelAndView("cn/com/lzt/contractpayment/contractPaymentApplyList");
- }
- @RequestMapping(params = "datagrid4Apply")
- public void datagrid4Apply(ContractPaymentEntity contractPayment,HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
- CriteriaQuery cq = new CriteriaQuery(ContractPaymentEntity.class, dataGrid);
- String code = request.getParameter("code");
- contractPayment.setContractname(null);
- String projectName = request.getParameter("projectName");
- String partnerName =request.getParameter("partnerName");
-
- if(StringUtils.isNotEmpty(projectName)) {
- String sql = "select id from t_b_project where name like '%"+projectName+"%'";
- List<String> projectIDList = systemService.findListbySql(sql);
- cq.in("projectid", projectIDList.toArray());
- contractPayment.setProjectName(null);
- }
- if(StringUtils.isNotEmpty(partnerName)) {
- String sql = "select id from t_b_related_units where unit_name like '%"+partnerName+"%'";
- List<String> partnerIDList = systemService.findListbySql(sql);
- cq.in("partnerid", partnerIDList.toArray());
- contractPayment.setPartnerName(null);
- }
- //查询条件组装器
- if(StringUtils.isNotBlank(code)){
- //模糊查询
- cq.like("code", "%"+code+"%");
- contractPayment.setCode(null);
- }
- cq.addOrder("createDate", SortDirection.desc);
- //增加权限处理
- TSUser user = ResourceUtil.getSessionUser();
- String roleSql = "select rolecode from t_s_role where id in (select roleid from t_s_role_user where userid = ?)";
- List<Map<String, Object>> roleMapList = systemService.findForJdbc(roleSql, user.getId());
- String roles = "";
- if(roleMapList != null && roleMapList.size()>0) {
- for (Map<String, Object> roleMap :roleMapList) {
- roles += (roleMap.get("rolecode").toString()+",");
- }
- }
- if(roles.indexOf("admin") == -1
- && (roles.indexOf("P_XMNQ,") > -1 //项目内勤
- || roles.indexOf("P_XMJL,") > -1)/*项目经理*/) {
- contractPayment.setCreateBy(user.getUserName());
- }
- //查询条件组装器
- org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, contractPayment);
- cq.add();
- this.contractPaymentService.getDataGridReturn(cq, true);
- TagUtil.datagrid(response, dataGrid);
- }
-
- @RequestMapping(params = "paylist")
- public ModelAndView paylist(ContractPaymentEntity contractPayment,HttpServletRequest request) {
- request.setAttribute("contractPayment", contractPayment);
- return new ModelAndView("cn/com/lzt/contractpayment/contractPaymentList");
- }
-
- @RequestMapping(params = "payOverlookList")
- public ModelAndView payOverlooklist(HttpServletRequest request) {
- return new ModelAndView("cn/com/lzt/contractpayment/contractPaymentOverlook");
- }
-
- @RequestMapping(params = "datagrid4Pay")
- public void datagrid4pay(ContractPaymentEntity contractPayment,HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
- CriteriaQuery cq = new CriteriaQuery(ContractPaymentEntity.class, dataGrid);
- String projectName = request.getParameter("projectName");
- String partnerName =request.getParameter("partnerName");
-
- if(StringUtils.isNotEmpty(projectName)) {
- String sql = "select id from t_b_project where name like '%"+projectName+"%'";
- List<String> projectIDList = systemService.findListbySql(sql);
- cq.in("projectid", projectIDList.toArray());
- contractPayment.setProjectName(null);
- }
- if(StringUtils.isNotEmpty(partnerName)) {
- String sql = "select id from t_b_related_units where unit_name like '%"+partnerName+"%'";
- List<String> partnerIDList = systemService.findListbySql(sql);
- cq.in("partnerid", partnerIDList.toArray());
- contractPayment.setPartnerName(null);
- }
- contractPayment.setBpmStatus(Globals.BPM_STATUS_FINISHED.toString());
- //查询条件组装器
- org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, contractPayment);
- try{
- //自定义追加查询条件
- //增加权限处理
- TSUser user = ResourceUtil.getSessionUser();
- String roleSql = "select rolecode from t_s_role where id in (select roleid from t_s_role_user where userid = ?)";
- List<Map<String, Object>> roleMapList = systemService.findForJdbc(roleSql, user.getId());
- String roles = "";
- if(roleMapList != null && roleMapList.size()>0) {
- for (Map<String, Object> roleMap :roleMapList) {
- roles += (roleMap.get("rolecode").toString()+",");
- }
- }
- if(roles.indexOf("admin") == -1 && roles.indexOf("A_") == -1
- && (roles.indexOf("P_XMNQ,") > -1 //项目内勤
- || roles.indexOf("P_XMJL,") > -1)/*项目经理*/) {
- // 所属项目及兼职项目id
- List<String> projectList = projectServiceI.getProjectsByUserid(user.getId());
- cq.in("projectid", projectList.toArray());
- }
- }catch (Exception e) {
- throw new BusinessException(e.getMessage());
- }
- cq.add();
- this.contractPaymentService.getDataGridReturn(cq, true);
- TagUtil.datagrid(response, dataGrid);
- }
- /**
- * easyui AJAX请求数据
- *
- * @param request
- * @param response
- * @param dataGrid
- */
- @RequestMapping(params = "datagrid")
- public void datagrid(ContractPaymentEntity contractPayment,HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
- CriteriaQuery cq = new CriteriaQuery(ContractPaymentEntity.class, dataGrid);
- //查询条件组装器
- org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, contractPayment);
- try{
- //自定义追加查询条件
- String contractid = request.getParameter("contractid");
- if(StringUtil.isNotEmpty(contractid)) {
- cq.eq("contractid", contractid);
- cq.eq("paystatus", Globals.PAY_STATUS_YES);
- }
- }catch (Exception e) {
- throw new BusinessException(e.getMessage());
- }
- cq.add();
- this.contractPaymentService.getDataGridReturn(cq, true);
- dataGrid.setFooter("applypayamount:支付合计:,paymentamount");
- TagUtil.datagrid(response, dataGrid);
- }
- /**
- * 删除合同支付申请
- *
- * @return
- */
- @RequestMapping(params = "doDel")
- @ResponseBody
- public AjaxJson doDel(ContractPaymentEntity contractPayment, HttpServletRequest request) {
- AjaxJson j = new AjaxJson();
- contractPayment = systemService.getEntity(ContractPaymentEntity.class, contractPayment.getId());
- String message = "合同支付申请删除成功";
- try{
- maintainService.updatePaymentInfo(null, contractPayment.getId());
- contractPaymentService.delMain(contractPayment);
- systemService.addLog(message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO);
- }catch(Exception e){
- e.printStackTrace();
- message = "合同支付申请删除失败";
- throw new BusinessException(e.getMessage());
- }
- j.setMsg(message);
- return j;
- }
- /**
- * 批量删除合同支付申请
- *
- * @return
- */
- @RequestMapping(params = "doBatchDel")
- @ResponseBody
- public AjaxJson doBatchDel(String ids,HttpServletRequest request){
- AjaxJson j = new AjaxJson();
- String message = "合同支付申请删除成功";
- try{
- for(String id:ids.split(",")){
- ContractPaymentEntity contractPayment = systemService.getEntity(ContractPaymentEntity.class,
- id
- );
- contractPaymentService.delMain(contractPayment);
- systemService.addLog(message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO);
- }
- }catch(Exception e){
- e.printStackTrace();
- message = "合同支付申请删除失败";
- throw new BusinessException(e.getMessage());
- }
- j.setMsg(message);
- return j;
- }
- /**
- * 添加合同支付申请
- *
- * @return
- */
- @RequestMapping(params = "doAdd")
- @ResponseBody
- public AjaxJson doAdd(ContractPaymentEntity contractPayment,ContractPaymentPage contractPaymentPage, HttpServletRequest request) {
- List<ContractInvoiceEntity> contractInvoiceList = contractPaymentPage.getContractInvoiceList();
- AjaxJson j = new AjaxJson();
- String message = "添加成功";
- try{
- /*double payAmount = contractPayment.getApplypayamount();
- double totalAmount = contractPayment.getTotalamount();
- String contractId = contractPayment.getContractid();
- String sql = "select sum(applypayamount) from t_b_contract_payment where contractid=? ";
- List<Double> list = systemService.findListbySql(sql,contractId);
- if(!list.isEmpty()){
- Double hasPayAmount = list.get(0);
- if(hasPayAmount==null) hasPayAmount=0d;
- if(hasPayAmount+payAmount>totalAmount){
- j.setMsg("已经申请支付金额超过合同金额");
- j.setSuccess(false);
- return j;
- }
- }*/
- //默认支付金额=申请金额
- contractPayment.setPaymentamount(contractPayment.getApplypayamount());
- String maintainIds = contractPayment.getMaintainids();
- contractPaymentService.addMain(contractPayment, contractInvoiceList);
- tSysFileService.updateBusiId(contractPayment.getAttachment(), contractPayment.getId());
- maintainService.updatePaymentInfo(maintainIds, contractPayment.getId());
- systemService.addLog(message, Globals.Log_Type_INSERT, Globals.Log_Leavel_INFO);
- }catch(Exception e){
- e.printStackTrace();
- message = "合同支付申请添加失败";
- throw new BusinessException(e.getMessage());
- }
- j.setMsg(message);
- return j;
- }
-
- /**
- * 更新合同支付申请
- *
- * @return
- */
- @RequestMapping(params = "doUpdate")
- @ResponseBody
- public AjaxJson doUpdate(ContractPaymentEntity contractPayment,ContractPaymentPage contractPaymentPage, HttpServletRequest request) {
- List<ContractInvoiceEntity> contractInvoiceList = contractPaymentPage.getContractInvoiceList();
- AjaxJson j = new AjaxJson();
- String message = "更新成功";
- try{
- //默认支付金额=申请金额
- contractPayment.setPaymentamount(contractPayment.getApplypayamount());
- contractPaymentService.updateMain(contractPayment, contractInvoiceList);
- systemService.addLog(message, Globals.Log_Type_UPDATE, Globals.Log_Leavel_INFO);
- }catch(Exception e){
- e.printStackTrace();
- message = "更新合同支付申请失败";
- throw new BusinessException(e.getMessage());
- }
- j.setMsg(message);
- return j;
- }
- /**
- * 合同支付申请新增页面跳转
- *
- * @return
- */
- @RequestMapping(params = "goAdd")
- public ModelAndView goAdd(ContractPaymentEntity contractPayment, HttpServletRequest req) {
- String contractid = req.getParameter("cid");
- String contractType = req.getParameter("contractType");
- String maintainids = req.getParameter("maintainids");
-
- if(StringUtil.isNotEmpty(contractid)) {
-
- contractPayment.setApplyerid(ResourceUtil.getSessionUser().getId());
- contractPayment.setContractid(contractid);
- switch (contractType) {
- case "service":
- ContractEntity contract = systemService.getEntity(ContractEntity.class, contractid);
- contractPayment.setContractStartEnd(DateUtils.formatDate(contract.getStartdate(),"yyyy.MM.dd") +"~" +
- DateUtils.formatDate( contract.getEnddate(),"yyyy.MM.dd"));
- contractPayment.setProjectid(contract.getProjectid());
- contractPayment.setPartnerid(contract.getPartnerid());
- contractPayment.setTotalamount(contract.getTotalamount());
- //设置付款至数据
- contractPayment.setPayedPeriodEnd(getPayto(contractPayment.getContractid()));
- if(contract.getPaytype().equals("Onetime")) {
- contractPayment.setPeriodBegin(DateUtils.date_sdf.format(contract.getStartdate()));
- contractPayment.setPeriodEnd(DateUtils.date_sdf.format(contract.getEnddate()));
- }else if(contract.getPaytype().equals("Quarterly")) {
- String hql = " from ContractPaymentEntity where contractid =? order by createDate desc";
- List<ContractPaymentEntity> paymentHis = systemService.findHql(hql, contractid);
- if(paymentHis.size() == 0) {
- contractPayment.setPeriodBegin(DateUtils.date_sdf.format(contract.getStartdate()));
- contractPayment.setPeriodEnd(XcglDateUtils.addDateMonth(contract.getStartdate(), 3, DateUtils.date_sdf));
- }else {
- String begin = paymentHis.get(0).getPeriodEnd();
- contractPayment.setPeriodBegin(XcglDateUtils.addDateDay(begin, 1, DateUtils.date_sdf));
- try {
- String end = XcglDateUtils.addDateMonth(DateUtils.date_sdf.parse(begin), 3, DateUtils.date_sdf) ;
- if(DateUtils.date_sdf.format(contract.getEnddate()).compareTo(end) < 0) {
- contractPayment.setPeriodEnd(DateUtils.date_sdf.format(contract.getEnddate()));
- }else {
- contractPayment.setPeriodEnd(end);
- }
- }catch (Exception e) {
- logger.error(e.getMessage());
- }
- }
- }
- if(StringUtils.isNotEmpty(maintainids)) {
- setMaintainInfo(contractPayment,maintainids);
- }
- break;
- case "purchase":
- ContractPEntity contractp = systemService.getEntity(ContractPEntity.class, contractid);
- contractPayment.setProjectid(contractp.getProjectid());
- contractPayment.setPartnerid(contractp.getPartnerid());
- contractPayment.setTotalamount(contractp.getTotalamount());
- break;
- default:
- break;
- }
- //按照编码规则设置默认编码
- contractPayment.setCode(OrderNumTools.generateNextBillCode(getMaxLocalCode(),Globals.CODE_PREFIX_PAYAPPLY));
- //设置支付状态
- contractPayment.setPaystatus(Globals.PAY_STATUS_NO);
- //默认外包合同,如果传入参数,则设置为传入值
- contractPayment.setBilltype(StringUtils.isEmpty(contractType)?"service":contractType);
- req.setAttribute("contractPaymentPage", contractPayment);
- }
- return new ModelAndView("cn/com/lzt/contractpayment/contractPayment-add");
- }
- /**设置评价
- *
- * @param payment
- * @param maintainids
- */
- private void setMaintainInfo(ContractPaymentEntity payment,String maintainids) {
- payment.setMaintainids(maintainids);
- maintainids = maintainids.replaceAll(",", "','");
- maintainids = "'"+maintainids + "'";
- //取最低分评价,分数为平均值
- String sql = "select floor(temp1.score) as score,temp2.valuate as valuete \n" +
- " from \n" +
- " (select AVG(score) score ,projectid from t_b_maintain_bill where id in ("+maintainids+") group by projectid) temp1\n" +
- " left join \n" +
- " (select valuate,projectid \n" +
- " from t_b_maintain_bill \n" +
- " where id in ("+maintainids+")\n" +
- " and score = (select min(score) from t_b_maintain_bill where id in ("+maintainids+") group by projectid)) \n" +
- " temp2 on temp1.projectid = temp2.projectid";
- List<Map<String,Object>> infoList = systemService.findForJdbc(sql);
- if(infoList.size() > 0) {
- payment.setSupplierscore(((Long)infoList.get(0).get("score")).intValue());
- payment.setSupplierevaluate(infoList.get(0).get("valuete").toString());
- }
- }
-
- /**
- * 合同支付申请编辑页面跳转
- *
- * @return
- */
- @RequestMapping(params = "goUpdate")
- public ModelAndView goUpdate(ContractPaymentEntity contractPayment, HttpServletRequest req) {
- if (StringUtil.isNotEmpty(contractPayment.getId())) {
- contractPayment = contractPaymentService.getEntity(ContractPaymentEntity.class, contractPayment.getId());
- if(StringUtil.isNotEmpty(contractPayment.getProjectid())) {
- contractPayment.setProjectName(((ProjectEntity)systemService.getEntity(ProjectEntity.class, contractPayment.getProjectid())).getName());
- }
- if(StringUtil.isNotEmpty(contractPayment.getPartnerid())) {
- contractPayment.setPartnerName(((RelatedUnitsEntity)systemService.getEntity(RelatedUnitsEntity.class, contractPayment.getPartnerid())).getUnitName());
- }
- contractPayment.setPayedPeriodEnd(getPayto(contractPayment.getContractid()));
- ContractEntity contract = systemService.getEntity(ContractEntity.class, contractPayment.getContractid());
- contractPayment.setContractStartEnd(DateUtils.formatDate(contract.getStartdate(),"yyyy.MM.dd") +"~" +
- DateUtils.formatDate( contract.getEnddate(),"yyyy.MM.dd"));
- req.setAttribute("contractPaymentPage", contractPayment);
- }
- return new ModelAndView("cn/com/lzt/contractpayment/contractPayment-update");
- }
-
- private String getPayto(String contractid) {
- String payto = "--";
- String maxPeriodendSql = "select max(periodend) as payedperiodend from t_b_contract_payment where contractid = '"+contractid+"' and paystatus = '1' ";
- List<String> periodList = systemService.findListbySql(maxPeriodendSql);
- if(periodList.get(0) != null) {
- payto = periodList.get(0);
- }
- return payto;
- }
-
- @RequestMapping(params = "goUpdateMobile")
- public ModelAndView goUpdateMobile(ContractPaymentEntity contractPayment, HttpServletRequest req) {
- if (StringUtil.isNotEmpty(contractPayment.getId())) {
- contractPayment = contractPaymentService.getEntity(ContractPaymentEntity.class, contractPayment.getId());
- if(StringUtil.isNotEmpty(contractPayment.getProjectid())) {
- contractPayment.setProjectName(((ProjectEntity)systemService.getEntity(ProjectEntity.class, contractPayment.getProjectid())).getAbbreviation());
- }
- if(StringUtil.isNotEmpty(contractPayment.getPartnerid())) {
- contractPayment.setPartnerName(((RelatedUnitsEntity)systemService.getEntity(RelatedUnitsEntity.class, contractPayment.getPartnerid())).getUnitName());
- }
- //设置合同中的信息
- if(contractPayment.getBilltype().equals("service")) {
- ContractEntity contract = systemService.getEntity(ContractEntity.class, contractPayment.getContractid());
- contractPayment.setContractname(contract.getName());
- contractPayment.setTotalpayment(contract.getTotalpayment());
- }else if (contractPayment.getBilltype().equals("purchase")) {
- ContractPEntity contract = systemService.getEntity(ContractPEntity.class, contractPayment.getContractid());
- contractPayment.setContractname(contract.getName());
- contractPayment.setTotalpayment(contract.getTotalpayment());
- }
- String paytype = DictUtil.formatToTypeName(contractPayment.getPaytype(), "paytype");
- req.setAttribute("paytype", paytype);
- req.setAttribute("entity", contractPayment);
- }
- Map<String, Object> data = LztUtil.copyReqAttributes(new String[]{
- "paytype", "entity"});
- return new JsonDataModelAndView(WXAjaxJson.success(data));
- }
-
- @RequestMapping(params = "goView")
- public ModelAndView goView(ContractPaymentEntity contractPayment, HttpServletRequest request) {
- String taskId = request.getParameter("taskId");
- //【我发起的流程】-【详情】中查看业务数据时,只看单据信息,不预览审批流程
- if(StringUtils.isEmpty(taskId)) {
- contractPayment = contractPaymentService.getEntity(ContractPaymentEntity.class, contractPayment.getId());
- if(StringUtil.isNotEmpty(contractPayment.getProjectid())) {
- contractPayment.setProjectName(((ProjectEntity)systemService.getEntity(ProjectEntity.class, contractPayment.getProjectid())).getName());
- }
- if(StringUtil.isNotEmpty(contractPayment.getPartnerid())) {
- contractPayment.setPartnerName(((RelatedUnitsEntity)systemService.getEntity(RelatedUnitsEntity.class, contractPayment.getPartnerid())).getUnitName());
- }
- request.setAttribute("contractPaymentPage", contractPayment);
- request.setAttribute("viewFlag", 1);
- return new ModelAndView("cn/com/lzt/contractpayment/contractPayment-update");
- }
- if(StringUtils.isNotEmpty(request.getParameter("flag"))){
- //驳回重填表单
- request.setAttribute("url", "contractPaymentController.do?goUpdate&id="+workflowService.getBpmDataId(taskId));
- }else {
- request.setAttribute("url", "contractPaymentController.do?goUpdate&load=detail&audit=1&id="+workflowService.getBpmDataId(taskId));
- }
- Map<String, Object> taskDetails = workflowService.getTaskDetails(taskId);
- request.setAttribute("busititle", "付款申请详细信息");
- request.setAttribute("id", workflowService.getBpmDataId(taskId));
- request.setAttribute("bpmLogList", taskDetails.get("bpmLogList"));
- request.setAttribute("taskId", taskDetails.get("taskId"));
- request.setAttribute("taskName", taskDetails.get("taskName"));
- request.setAttribute("task", taskDetails.get("task"));
- request.setAttribute("transitionList", taskDetails.get("transitionList"));
- request.setAttribute("nextCodeCount", taskDetails.get("nextCodeCount"));
- request.setAttribute("bpmLogListCount", taskDetails.get("bpmLogListCount"));
- request.setAttribute("bpmLogNewList", taskDetails.get("bpmLogNewList"));
- request.setAttribute("bpmLogNewListCount", taskDetails.get("bpmLogNewListCount"));
- request.setAttribute("histListNode", taskDetails.get("histListNode"));
- request.setAttribute("histListSize", taskDetails.get("histListSize"));
- request.setAttribute("turnbackTaskId", taskDetails.get("turnbackTaskId"));
- request.setAttribute("height", "800px");
- return new ModelAndView("cn/com/lzt/workflow/task-option");
- }
-
-
- /**
- * 加载明细列表[发票明细]
- *
- * @return
- */
- @RequestMapping(params = "contractInvoiceList")
- public ModelAndView contractInvoiceList(ContractPaymentEntity contractPayment, HttpServletRequest req) {
-
- //===================================================================================
- //获取参数
- Object id0 = contractPayment.getId();
- //===================================================================================
- //查询-发票明细
- String hql0 = "from ContractInvoiceEntity where 1 = 1 AND pAYMENTID =? ";
- try{
- List<ContractInvoiceEntity> contractInvoiceEntityList = systemService.findHql(hql0,id0);
- req.setAttribute("contractInvoiceList", contractInvoiceEntityList);
- }catch(Exception e){
- logger.info(e.getMessage());
- }
- return new ModelAndView("cn/com/lzt/contractinvoice/contractInvoiceList");
- }
-
- @RequestMapping(params = "contractInvoiceListReadonly")
- public ModelAndView contractInvoiceListReadonly( HttpServletRequest req) {
- String contractid = req.getParameter("contractid");
- ModelAndView mv = new ModelAndView("cn/com/lzt/contractinvoice/contractInvoiceListReadonly");
- req.setAttribute("contractid", contractid);
- return mv;
- }
-
-
- @RequestMapping(params = "invoiceDatagrid")
- public void invoiceDatagrid(ContractInvoiceEntity contractInvoice,HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
- CriteriaQuery cq = new CriteriaQuery(ContractInvoiceEntity.class, dataGrid);
- //查询条件组装器
- org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, contractInvoice);
- cq.add();
- this.contractPaymentService.getDataGridReturn(cq, true);
- if (StringUtils.isNotEmpty(contractInvoice.getContractid())) {
- List<ContractInvoiceEntity> resualtlist = dataGrid.getResults();
- Double sum = 0.0;
- if (resualtlist.size() != 0) {
- for (ContractInvoiceEntity aa : resualtlist) {
- sum = sum + Double.valueOf(aa.getInvoiceamount());
- }
- }
- // 格式化为小数点2位数
- DecimalFormat df = new DecimalFormat("#.00");
- String total_salary = df.format(sum);
- dataGrid.setFooter("invoiceamount:合计:"+total_salary);
- }
- TagUtil.datagrid(response, dataGrid);
- }
-
- @RequestMapping(params = "contractPaymentListReadonly")
- public ModelAndView contractPaymentListReadonly( HttpServletRequest req) {
- String contractid = req.getParameter("contractid");
- ModelAndView mv = new ModelAndView("cn/com/lzt/contractpayment/contractPaymentListReadonly");
- req.setAttribute("contractid", contractid);
- return mv;
- }
- /**
- * 导出excel
- *
- * @param request
- * @param response
- */
- @RequestMapping(params = "exportXls")
- public String exportXls(ContractPaymentEntity contractPayment,HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid,ModelMap map) {
- CriteriaQuery cq = new CriteriaQuery(ContractPaymentEntity.class, dataGrid);
- contractPayment.setBpmStatus(Globals.BPM_STATUS_FINISHED.toString());
- cq.addOrder("createDate", SortDirection.desc);
- cq.add();
- //查询条件组装器
- org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, contractPayment);
- List<ContractPaymentEntity> list=this.contractPaymentService.getListByCriteriaQuery(cq, false);
- // List<ContractPaymentPage> pageList=new ArrayList<ContractPaymentPage>();
- // if(list!=null&&list.size()>0){
- // for(ContractPaymentEntity entity:list){
- // try{
- // ContractPaymentPage page=new ContractPaymentPage();
- // MyBeanUtils.copyBeanNotNull2Bean(entity,page);
- // Object id0 = entity.getId();
- // String hql0 = "from ContractInvoiceEntity where 1 = 1 AND pAYMENTID = ? ";
- // List<ContractInvoiceEntity> contractInvoiceEntityList = systemService.findHql(hql0,id0);
- // page.setContractInvoiceList(contractInvoiceEntityList);
- // pageList.add(page);
- // }catch(Exception e){
- // logger.info(e.getMessage());
- // }
- // }
- // }
- map.put(NormalExcelConstants.FILE_NAME,"合同支付申请"+DateUtils.yyyymmddhhmmss.format(new Date()));
- map.put(NormalExcelConstants.CLASS,ContractPaymentEntity.class);
- map.put(NormalExcelConstants.PARAMS,new ExportParams("合同支付列表", "导出人:"+ResourceUtil.getSessionUser().getRealName(),
- "导出信息"));
- map.put(NormalExcelConstants.DATA_LIST,list);
- return NormalExcelConstants.JEECG_EXCEL_VIEW;
- }
- /**
- * 通过excel导入数据
- * @param request
- * @param
- * @return
- */
- @RequestMapping(params = "importExcel", method = RequestMethod.POST)
- @ResponseBody
- public AjaxJson importExcel(HttpServletRequest request, HttpServletResponse response) {
- AjaxJson j = new AjaxJson();
- MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
- Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
- for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
- MultipartFile file = entity.getValue();// 获取上传文件对象
- ImportParams params = new ImportParams();
- params.setTitleRows(2);
- params.setHeadRows(2);
- params.setNeedSave(true);
- try {
- List<ContractPaymentPage> list = ExcelImportUtil.importExcel(file.getInputStream(), ContractPaymentPage.class, params);
- ContractPaymentEntity entity1=null;
- for (ContractPaymentPage page : list) {
- entity1=new ContractPaymentEntity();
- MyBeanUtils.copyBeanNotNull2Bean(page,entity1);
- contractPaymentService.addMain(entity1, page.getContractInvoiceList());
- }
- j.setMsg("文件导入成功!");
- } catch (Exception e) {
- j.setMsg("文件导入失败!");
- logger.error(ExceptionUtil.getExceptionMessage(e));
- }finally{
- try {
- file.getInputStream().close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- return j;
- }
- /**
- * 导出excel 使模板
- */
- @RequestMapping(params = "exportXlsByT")
- public String exportXlsByT(ModelMap map) {
- map.put(NormalExcelConstants.FILE_NAME,"合同支付申请");
- map.put(NormalExcelConstants.CLASS,ContractPaymentPage.class);
- map.put(NormalExcelConstants.PARAMS,new ExportParams("合同支付申请列表", "导出人:"+ ResourceUtil.getSessionUser().getRealName(),
- "导出信息"));
- map.put(NormalExcelConstants.DATA_LIST,new ArrayList());
- return NormalExcelConstants.JEECG_EXCEL_VIEW;
- }
- /**
- * 导入功能跳转
- *
- * @return
- */
- @RequestMapping(params = "upload")
- public ModelAndView upload(HttpServletRequest req) {
- req.setAttribute("controller_name", "contractPaymentController");
- return new ModelAndView("common/upload/pub_excel_upload");
- }
-
- @RequestMapping(method = RequestMethod.GET)
- @ResponseBody
- public List<ContractPaymentEntity> list() {
- List<ContractPaymentEntity> listContractPayments=contractPaymentService.getList(ContractPaymentEntity.class);
- return listContractPayments;
- }
-
- @RequestMapping(value = "/{id}", method = RequestMethod.GET)
- @ResponseBody
- public ResponseEntity<?> get(@PathVariable("id") String id) {
- ContractPaymentEntity task = contractPaymentService.get(ContractPaymentEntity.class, id);
- if (task == null) {
- return new ResponseEntity(HttpStatus.NOT_FOUND);
- }
- return new ResponseEntity(task, HttpStatus.OK);
- }
-
- @RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
- @ResponseBody
- public ResponseEntity<?> create(@RequestBody ContractPaymentPage contractPaymentPage, UriComponentsBuilder uriBuilder) {
- //调用JSR303 Bean Validator进行校验,如果出错返回含400错误码及json格式的错误信息.
- Set<ConstraintViolation<ContractPaymentPage>> failures = validator.validate(contractPaymentPage);
- if (!failures.isEmpty()) {
- return new ResponseEntity(BeanValidators.extractPropertyAndMessage(failures), HttpStatus.BAD_REQUEST);
- }
- //保存
- List<ContractInvoiceEntity> contractInvoiceList = contractPaymentPage.getContractInvoiceList();
-
- ContractPaymentEntity contractPayment = new ContractPaymentEntity();
- try{
- MyBeanUtils.copyBeanNotNull2Bean(contractPayment,contractPaymentPage);
- }catch(Exception e){
- logger.info(e.getMessage());
- }
- contractPaymentService.addMain(contractPayment, contractInvoiceList);
- //按照Restful风格约定,创建指向新任务的url, 也可以直接返回id或对象.
- String id = contractPaymentPage.getId();
- URI uri = uriBuilder.path("/rest/contractPaymentController/" + id).build().toUri();
- HttpHeaders headers = new HttpHeaders();
- headers.setLocation(uri);
- return new ResponseEntity(headers, HttpStatus.CREATED);
- }
-
- @RequestMapping(value = "/{id}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE)
- public ResponseEntity<?> update(@RequestBody ContractPaymentPage contractPaymentPage) {
- //调用JSR303 Bean Validator进行校验,如果出错返回含400错误码及json格式的错误信息.
- Set<ConstraintViolation<ContractPaymentPage>> failures = validator.validate(contractPaymentPage);
- if (!failures.isEmpty()) {
- return new ResponseEntity(BeanValidators.extractPropertyAndMessage(failures), HttpStatus.BAD_REQUEST);
- }
- //保存
- List<ContractInvoiceEntity> contractInvoiceList = contractPaymentPage.getContractInvoiceList();
-
- ContractPaymentEntity contractPayment = new ContractPaymentEntity();
- try{
- MyBeanUtils.copyBeanNotNull2Bean(contractPayment,contractPaymentPage);
- }catch(Exception e){
- logger.info(e.getMessage());
- }
- contractPaymentService.updateMain(contractPayment, contractInvoiceList);
- //按Restful约定,返回204状态码, 无内容. 也可以返回200状态码.
- return new ResponseEntity(HttpStatus.NO_CONTENT);
- }
- @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
- @ResponseStatus(HttpStatus.NO_CONTENT)
- public void delete(@PathVariable("id") String id) {
- ContractPaymentEntity contractPayment = contractPaymentService.get(ContractPaymentEntity.class, id);
- contractPaymentService.delMain(contractPayment);
- }
- private String getMaxLocalCode(){
- StringBuilder sb = new StringBuilder();
- sb.append("SELECT code FROM t_b_contract_payment ");
- sb.append(" where left(create_date,10) = '"+ DateUtils.date_sdf.format(new Date())+"' ");
- sb.append(" ORDER BY code DESC");
- List<Map<String, Object>> objMapList = systemService.findForJdbc(sb.toString(), 1, 1);
- String returnCode = null;
- if(objMapList!=null && objMapList.size()>0){
- returnCode = (String)objMapList.get(0).get("code");
- }
- return returnCode;
- }
-
-
- @RequestMapping(params = "exportXlsOfPay")
- public synchronized void exportXlsOfPay(String payapplyIDs, HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid,ModelMap map) {
- List<ContractPaymentDto> dtolist = new ArrayList<ContractPaymentDto>();
- if(payapplyIDs != null) {
- String[] splits = payapplyIDs.split(",");
- ArrayList<String> applyIDs = new ArrayList<String>();
- if(splits.length > 0) {
- for(String id :splits) {
- applyIDs.add(id);
- }
- // minidao
- dtolist = paydao.getPayFromApplyByApplyIDs(applyIDs);
- }
- }
- if(dtolist.isEmpty()) {
- try {
- response.sendRedirect(request.getContextPath()+"/contractPaymentController.do?paylist");
- } catch (IOException e) {
- e.printStackTrace();
- }
- return;
- }
- List<String> idList = new ArrayList<>();
- for(ContractPaymentDto dto :dtolist){
- idList.add(dto.getId());
- }
- payapplyIDs = StringUtils.join(idList,",");
- budgetWriteBack(payapplyIDs,Globals.PAY_STATUS_YES);
- List<Workbook> workbooklist = getWorkboodsByPayApplyIDs(dtolist, map);
- if(workbooklist == null || workbooklist.size() == 0 || workbooklist.get(0)==null) {
- return;
- }
- ServletOutputStream out = null;
- ZipOutputStream zipOutputStream = null;
- String timenow = "";
- SimpleDateFormat formater = new SimpleDateFormat("yyMMddHHmmss_sss");
- try {
- timenow = formater.format(new Date());
- } catch (Exception e) {
- }
- try {
- out=response.getOutputStream();
- String codedFileName = "合同支付清单_"+timenow+".zip";
- if (isIE(request)) {
- codedFileName = java.net.URLEncoder.encode(codedFileName, "UTF8");
- } else {
- codedFileName = new String(codedFileName.getBytes("UTF-8"), "ISO-8859-1");
- }
-
- zipOutputStream= new ZipOutputStream(out);
-
- response.setContentType("application/octet-stream ");
- response.setHeader("Connection", "close"); // 表示不能用浏览器直接打开
- response.setHeader("Accept-Ranges", "bytes");// 告诉客户端允许断点续传多线程连接下载
- response.setHeader("Content-Disposition",
- "attachment;filename=" + codedFileName);
- response.setCharacterEncoding("UTF-8");
-
- for(Workbook book : workbooklist) {
- ZipEntry entry = new ZipEntry(book.getSheetName(0) + ".xls");
- zipOutputStream.putNextEntry(entry);
- book.write(zipOutputStream);
- }
- zipOutputStream.flush();
- updateApplyStatus(payapplyIDs,Globals.PAY_STATUS_YES);
- updateContract(payapplyIDs,Globals.PAY_STATUS_YES);
- sendWXmsgToRelatedPerson(payapplyIDs);
- } catch (IOException e) {
- org.jeecgframework.core.util.LogUtil.error(e.getMessage());
- }finally {
- if(zipOutputStream != null) {
- try {
- zipOutputStream.close();
- } catch (IOException e) {
- org.jeecgframework.core.util.LogUtil.error(e.getMessage());
- }
- }
- }
- }
- private void budgetWriteBack(String payapplyIDs, String yes) {
- String[] idArray = payapplyIDs.split(",");
- for(String id :idArray){
- ContractPaymentEntity paymentEntity = systemService.getEntity(ContractPaymentEntity.class, id);
- String budgetMonth = paymentEntity.getBudgetMonth();
- String contractId = paymentEntity.getContractid();
- BigDecimal value = new BigDecimal(paymentEntity.getApplypayamount());
- ContractEntity contractEntity = systemService.getEntity(ContractEntity.class, contractId);
- String measureId = contractEntity.getBudgetMeasureId();
- String projectid = contractEntity.getProjectid();
- String departId=null;
- String findProjectDepartHql = "from TSDepart where projectid=? and length(orgCode)=6";
- List<TSDepart> list = systemService.findHql(findProjectDepartHql,projectid);
- if(!list.isEmpty()){
- departId =list.get(0).getId();
- }
- if(StringUtils.equals(yes,Globals.PAY_STATUS_NO )){
- value = value.negate();
- }
- budgetWriteBackService.writeBack(BudgetConstant.BusType.contract_payment, "contract_payment", departId, measureId,null, value,budgetMonth , "t_b_contract_payment", id);
- }
- // budgetWriteBackService
- }
- /**
- * 变更付款状态,支付操作员,支付日期
- *
- * */
- private void updateApplyStatus(String ids,String newStatus) {
- StringBuffer strIDs= new StringBuffer();
- String[] splits = null;
- if(ids != null) {
- splits = ids.split(",");
- if(splits.length > 0) {
- for(int i = 0;i < splits.length;i++) {
- if(i == 0)
- strIDs.append("'"+splits[i]+"'");
- else
- strIDs.append(",").append("'"+splits[i]+"'");
- }
- }
- }
- if(strIDs.length()>0) {
- String updateSql = "";
- if(newStatus.equals(Globals.PAY_STATUS_NO))
- updateSql = "update t_b_contract_payment set paystatus='"+newStatus+"' ,payOperator= null,paydate=null,c2cpayment=null,c2npayment=null,c2lpayment=null where id in ("+strIDs.toString()+")";
- else
- updateSql = "update t_b_contract_payment set paystatus='"+newStatus+"' ,"
- + "paydate ='"+DateUtils.datetimeFormat.format(new Date())+"' ,"
- + "payOperator = '"+ResourceUtil.getSessionUser().getId()+"' "
- // + "paymentamount = applypayamount"
- + " where id in ("+strIDs.toString()+")";
- systemService.executeSql(updateSql);
- //增加:拆分跨年度的付款金额
- try {
- if(newStatus.equals(Globals.PAY_STATUS_YES) && splits != null){
- for(String id:splits) {
- ContractPaymentEntity payment = systemService.get(ContractPaymentEntity.class, id);
- setFinancialData(payment);
- contractPaymentService.saveOrUpdate(payment);
- }
- }
- }catch (ParseException pe) {
- logger.equals(pe.getMessage());
- }
- }
- }
-
- /**
- * 回写合同累计支付金额
- *
- * */
- private void updateContract(String ids,String newStatus) {
- StringBuffer strIDs= new StringBuffer();
- if(ids != null) {
- String[] splits = ids.split(",");
- if(splits.length > 0) {
- for(int i = 0;i < splits.length;i++) {
- if(i == 0)
- strIDs.append("'"+splits[i]+"'");
- else
- strIDs.append(",").append("'"+splits[i]+"'");
- }
- }
- }
- if(strIDs.length()>0) {
- String updateSql = "";
- //取消时,减去本次支付金额
- if(newStatus.equals(Globals.PAY_STATUS_NO))
- updateSql = "update t_b_contract c \n" +
- "set c.totalpayment = c.totalpayment - (\n" +
- " select sum(paymentamount) \n" +
- " from t_b_contract_payment p \n" +
- " where p.id in("+strIDs.toString()+")\n" +
- " and p.contractid = c.id) \n" +
- "where c.id in (select contractid from t_b_contract_payment pa \n" +
- " where pa.id in("+strIDs.toString()+"))";
- else
- //支付完成时,增加本次支付金额
- updateSql = "update t_b_contract c \n" +
- "set c.totalpayment = c.totalpayment + (\n" +
- " select sum(paymentamount) \n" +
- " from t_b_contract_payment p \n" +
- " where p.id in("+strIDs.toString()+")\n" +
- " and p.contractid = c.id) \n" +
- "where c.id in (select contractid from t_b_contract_payment pa \n" +
- " where pa.id in("+strIDs.toString()+"))";
- systemService.executeSql(updateSql);
- }
- }
- private List<Workbook> getWorkboodsByPayApplyIDs(List<ContractPaymentDto> dtolist,ModelMap map){
- getContractPaymentDtos(dtolist);
- ArrayList<Workbook> workbooklist = new ArrayList<>();
- String name = "外包合同支付清单"+DateUtils.yyyymmddhhmmss.format(new Date());
- map.put(NormalExcelConstants.FILE_NAME,name);
- map.put(NormalExcelConstants.CLASS,ContractPaymentDto.class);
- ExportParams params = new ExportParams();
- params.setSheetName(name);
- params.setAddIndex(false);
- map.put(NormalExcelConstants.PARAMS,params);
- map.put(NormalExcelConstants.DATA_LIST,dtolist);
-
- Workbook workbook = getSingleWorkbooksByModel(map);
- workbooklist.add(workbook);
- return workbooklist;
- }
- private List<ContractPaymentDto> getContractPaymentDtos(List<ContractPaymentDto> dtolist) {
- //设置默认值及默认规则
- for(ContractPaymentDto paydto : dtolist) {
- paydto.setAccountName(Globals.PAY_ACCOUNT_NAME);
- paydto.setPayAccountNo(Globals.PAY_ACCOUNT_NO);
- paydto.setPayCustomerNo(Globals.PAY_CustomerNo);
- //支付类型: if 转账类型 = 行内,为空;行外,上海=1,非上海=0
- if(paydto.getTransferType().equals("0")) {
- paydto.setPayType(null);
- }else {
- if(paydto.getReceiveAcountBank().indexOf("上海") > -1) {
- paydto.setPayType("1");
- }else
- paydto.setPayType("0");
- }
- // 收款账户名称长度大于等于8,则为对公
- if(paydto.getReceiveAccountName().length() > 7)
- paydto.setAccountSign("0");
- else
- paydto.setAccountSign("1");
-
- }
- return dtolist;
- }
- private Workbook getSingleWorkbooksByModel(Map<String, Object> model) {
- Workbook workbook = ExcelExportUtil.exportExcel((ExportParams) model.get(NormalExcelConstants.PARAMS)
- , (Class<?>) model.get(NormalExcelConstants.CLASS), (Collection<?>) model.get(NormalExcelConstants.DATA_LIST));
- return workbook;
- }
- boolean isIE(HttpServletRequest request) {
- return (request.getHeader("USER-AGENT").toLowerCase().indexOf("msie") > 0 || request.getHeader("USER-AGENT").toLowerCase().indexOf("rv:11.0") > 0) ? true : false;
- }
-
- @RequestMapping(params = "doCancelPay")
- @ResponseBody
- public AjaxJson doCancelAuditOrder(String id,String refundvalue, HttpServletRequest req) {
- AjaxJson j = new AjaxJson();
- String message = null;
- // ContractPaymentEntity payment = contractPaymentService.getEntity(ContractPaymentEntity.class, id);
- updateApplyStatus(id, Globals.PAY_STATUS_NO);
- updateContract(id,Globals.PAY_STATUS_NO);
- budgetWriteBack(id,Globals.PAY_STATUS_NO);
- message = "成功取消支付";
- j.setMsg(message);
- return j;
- }
-
- /**
- * 给支付申请人、行政部经理发送微信通知,通知其支付完毕
- * */
- private void sendWXmsgToRelatedPerson(String paymentids) {
- StringBuffer strIDs= new StringBuffer();
- if(paymentids != null) {
- String[] splits = paymentids.split(",");
- if(splits.length > 0) {
- for(int i = 0;i < splits.length;i++) {
- if(i == 0)
- strIDs.append("'"+splits[i]+"'");
- else
- strIDs.append(",").append("'"+splits[i]+"'");
- }
- }
- }
- String sqlApplier = "select u.openid as openid,pay.code as paycode ,pay.paymentamount as payamount,unit.unit_name as partnername \n" +
- "from t_b_contract_payment pay \n" +
- "left join t_s_user u on pay.applyerid = u.id \n" +
- "left join t_b_related_units unit on pay.partnerid = unit.id\n" +
- "where pay.id in("+strIDs.toString()+")";
- List<Map<String,Object>> payDetails = systemService.findForJdbc(sqlApplier);
- String sqlXZBJL = "select openid from t_s_user tsu where id in "
- + "(select userid from t_s_role_user ru "
- + "left join t_s_role role on ru.roleid = role.id where role.rolecode = 'A_XZBJL')";
- List<Map<String,Object>> xzbjlRes = systemService.findForJdbc(sqlXZBJL);
- String xzbjlOpenid = null;
- if(xzbjlRes!= null && xzbjlRes.size() > 0 && xzbjlRes.get(0).get("openid") != null){
- xzbjlOpenid = xzbjlRes.get(0).get("openid").toString();
- }
- if(payDetails != null && payDetails.size() > 0) {
- //行政部经理提醒信息内容
- StringBuffer xzbjlKeyword1 = new StringBuffer();
- StringBuffer xzbjlKeyword2 = new StringBuffer();
- //申请人提醒信息
- HashMap<String,StringBuffer> hmApplierKeyword1 = new HashMap<String, StringBuffer>();
- HashMap<String,StringBuffer> hmApplierKeyword2 = new HashMap<String, StringBuffer>();
- for(Map<String,Object> paydetail:payDetails) {
- String openid = paydetail.get("openid") == null?"":paydetail.get("openid").toString();
- //申请单号
- String paycode = paydetail.get("paycode").toString();
- //金额
- String payamount = DecimalUtils.formatToStr((double)paydetail.get("payamount"));
- //供应商
- String partner = paydetail.get("partnername").toString();
- if(StringUtils.isNotEmpty(openid)) {
- if(hmApplierKeyword1.containsKey(openid)) {
- hmApplierKeyword1.get(openid).append(paycode).append(",");
- hmApplierKeyword2.get(openid).append(payamount).append("元,");
- }else {
- hmApplierKeyword1.put(openid, new StringBuffer(paycode+","));
- hmApplierKeyword2.put(openid, new StringBuffer(payamount+"元,"));
- }
- }
- xzbjlKeyword1.append(paycode).append(",");
- xzbjlKeyword2.append("\n").append(partner).append(":").append(payamount).append("元");
- }
-
- List<Map<String,Object>> listParams = new ArrayList<Map<String,Object>>();
- for(Entry<String, StringBuffer> userMSG : hmApplierKeyword1.entrySet()) {
- Map<String,Object> oneMsg = new HashMap<String, Object>();
- Map<String, Object> userMsgParms = new HashMap<String, Object>();
- String keyword1SplitStr = userMSG.getValue().toString();
- String keyword2SplitStr = hmApplierKeyword2.get(userMSG.getKey()).toString();
- userMsgParms.put("first", "你有一个支付申请已经支付完毕");
- userMsgParms.put("keyword1",keyword1SplitStr.substring(0, keyword1SplitStr.length()-1));
- userMsgParms.put("keyword2", keyword2SplitStr.substring(0, keyword2SplitStr.length()-1));
- userMsgParms.put("remark", "可以登录慧管理系统查看详细信息。");
- oneMsg.put("openid", userMSG.getKey());//"oQ2vj04CDPxjrvp9WlyJkXEfg4S8"
- oneMsg.put("userid", "");
- oneMsg.put("tplParams", userMsgParms);
- listParams.add(oneMsg);
- }
- if(StringUtils.isNotEmpty(xzbjlOpenid)) {
- Map<String,Object> oneMsg = new HashMap<String, Object>();
- Map<String, Object> userMsgParms = new HashMap<String, Object>();
- userMsgParms.put("first", "今日供应商支付完毕");
- userMsgParms.put("keyword1",xzbjlKeyword1.substring(0, xzbjlKeyword1.length()-1));
- userMsgParms.put("keyword2", xzbjlKeyword2.toString());
- userMsgParms.put("remark", "可以登录慧管理系统查看详细信息。");
- oneMsg.put("openid", xzbjlOpenid);//"oQ2vj04CDPxjrvp9WlyJkXEfg4S8"
- oneMsg.put("userid", "");
- oneMsg.put("tplParams", userMsgParms);
- listParams.add(oneMsg);
- }
- try {
- wXServiceI.sendMsgToWXForPayComplete(listParams);
- }catch (Exception e) {
- logger.error("微信消息发送失败,请管理员检查配置");
- logger.error(e.getMessage());
- }
- }
- }
-
- /**
- * 设置开上年、开下年、开本年金额
- * @throws ParseException
- * */
- private ContractPaymentEntity setFinancialData(ContractPaymentEntity payment) throws ParseException {
- if(payment.getPeriodBegin().substring(0,4).equals(payment.getPeriodEnd().substring(0,4))) {
- //不跨年
- payment.setC2cpayment(payment.getPaymentamount());
- payment.setC2npayment(DecimalUtils.ZERO);
- payment.setC2lpayment(DecimalUtils.ZERO);
- }else {
- //跨年时,需要计算开上一年或开下一年金额
- Date begin = DateUtils.datetimeFormat.parse(payment.getPeriodBegin()+" 00:00:00");
- Date end = DateUtils.datetimeFormat.parse(payment.getPeriodEnd()+" 00:00:00");
- //属于上一年的天数
- int firstHalf = XcglDateUtils.differentDays2YearEnd(begin)+1;
- //属于下一年的天数
- int secondHalf = XcglDateUtils.differentDays2YearStart(end)+1;
- double firstAmount = DecimalUtils.formatToDouble((payment.getPaymentamount()*firstHalf)/(firstHalf+secondHalf));
- double secondAmount = DecimalUtils.formatToDouble(payment.getPaymentamount()-firstAmount);
- //如果付款日期属于上半个阶段
- if(payment.getPeriodBegin().substring(0,4).equals(
- DateUtils.date_sdf.format(payment.getPaydate()).substring(0,4))) {
- payment.setC2cpayment(firstAmount);//开本年
- payment.setC2npayment(secondAmount);//开下年
- payment.setC2lpayment(DecimalUtils.ZERO);//开上年
- }else {
- //付款日期属于下半个阶段
- payment.setC2cpayment(firstAmount);//开本年
- payment.setC2npayment(DecimalUtils.ZERO);//开下年
- payment.setC2lpayment(secondAmount);//开上年
- }
- }
- return payment;
- }
- /**
- * 判断相同外包合同,7天内,付款金额相同情况,如果存在,则返回json fasle
- * */
- @RequestMapping(params = "checkDuplicate")
- @ResponseBody
- public AjaxJson checkDuplicate(ContractPaymentEntity payment, HttpServletRequest req) {
- AjaxJson j = new AjaxJson();
- String message = "无重复申请";
- String hql = "";
- List<ContractPaymentEntity> duplicateApply = new ArrayList<ContractPaymentEntity>();
- if(StringUtils.isNotEmpty(payment.getId())) {
- hql = " from ContractPaymentEntity where contractid =? and applypayamount =? and id <> ? ";
- duplicateApply = systemService.findHql(hql, payment.getContractid(),payment.getApplypayamount(),payment.getId());
- }else {
- hql = " from ContractPaymentEntity where contractid =? and applypayamount =? ";
- duplicateApply = systemService.findHql(hql, payment.getContractid(),payment.getApplypayamount());
- }
- for (ContractPaymentEntity contractPaymentEntity : duplicateApply) {
- int deffDay = XcglDateUtils.differentDays(contractPaymentEntity.getCreateDate(), new Date());
- if(deffDay < 8) {
- j.setSuccess(false);
- message = "此外包合同在"+DateUtils.date_sdf_wz.format(contractPaymentEntity.getCreateDate())+"提交过相同金额付款申请";
- break;
- }
- }
- j.setMsg(message);
- return j;
- }
- @RequestMapping(params="exportMaintainbill")
- public void exportDetailPdf4Mobile(@RequestParam("id") String id, HttpServletResponse response){
- ContractPaymentEntity entity = systemService.getEntity(ContractPaymentEntity.class,id);
- CriteriaQuery cq = new CriteriaQuery(MaintainBillEntity.class);
- String ids = entity.getMaintainids();
- String[] idArray = StringUtils.split(ids,",");
- cq.in("id",idArray);
- cq.add();
- List<MaintainBillEntity> list =systemService.getListByCriteriaQuery(cq,false);
- ActivitiPdfExport export = new ActivitiPdfExport();
- export.table(6);
- export.titleCell("合同名称","项目名称","供应商名称","维保月度","实际完成日期","服务评分");
- for(MaintainBillEntity billEntity : list){
- export.cell(billEntity.getContractname(),billEntity.getProjectname(),billEntity.getRelatedunitname()
- ,billEntity.getMaintainMonth(),DateUtils.formatDate(billEntity.getServicedate()),String.valueOf(billEntity.getScore()));
- }
- export.view(response,false);
- }
- }
|