package com.yc.MaintenanceFee.service.impl; import com.yc.MaintenanceFee.entiy.Order; import com.yc.MaintenanceFee.entiy.PayInfo; import com.yc.MaintenanceFee.entiy.PayLog; import com.yc.MaintenanceFee.mapper.PayInfoMapper; import com.yc.MaintenanceFee.service.CltInfoService; import com.yc.MaintenanceFee.service.MaintainService; import com.yc.MaintenanceFee.service.PayLogService; import com.yc.abc.entity.OrderEntity; import com.yc.entity.DataSourceEntity; import com.yc.multiData.MultiDataSource; import com.yc.service.BaseService; import net.bytebuddy.implementation.bind.annotation.Super; import org.apache.commons.lang3.StringUtils; import org.apache.poi.util.StringUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.BeanPropertyRowMapper; import org.springframework.jdbc.core.RowMapper; import org.springframework.stereotype.Service; import java.sql.ResultSet; import java.sql.SQLException; import java.util.List; import java.util.Map; /** * @USER: xinyb_ * @DATE: 2021-11-22 17:56 */ @Service public class MaintainServiceImpl extends BaseService implements MaintainService { @Autowired PayLogService payLogService; @Autowired CltInfoService cltInfoService; @Autowired PayInfoMapper payInfoMapper; @Override public int saveOrUpdatePayLog(PayLog payLog) { try { return payLogService.saveOrUpdatePayLog(payLog); } catch (Exception e) { return 0; } } @Override public boolean savePostingLogic(String docCode) { try { Integer formId = 150101; StringBuffer sb = new StringBuffer(); sb.append(" set nocount on\n" + " declare @docCode varchar(50)='" + docCode + "' ,@FormId int=" + formId + ",@PostFormId int,@DocStatusValue int,@now datetime=getdate() \n"); sb.append(" declare @PreDocStatus int,@PostDocStatus int, @EnterCode varchar(50)='SYSTEM',@EnterName varchar(50)='系统管理员',@EnterDate dateTime=@now \n"); sb.append(" declare @Memo varchar(50), @LinkDocInfo varchar(50)\n"); //标记为在维护费线支付 sb.append(" update t" + formId + "H set OnlinePaymentReturnCode='0000' where DocCode=@docCode \n"); //更新推送消息表的字段 sb.append(" update t150372 \n" + " set ISpay = 1 ,PayDate=GETDATE() \n" + " where Refdoccode in(select SODoccode from t" + formId + "D where DocCode=@docCode) \n"); sb.append(createPostSql(formId)); sb.append(" select @docCode as docCode"); log.info("do120311sql:" + sb.toString()); this.jdbcTemplate.execute(sb.toString()); return true; } catch (Exception e) { return false; } } @Override public PayLog selectPayLog(String docCode) { try { return payLogService.getPayLog(docCode); } catch (Exception e) { return null; } } @Override public boolean selectMaintenanceFeeNotification(String userCode) { boolean bol = false; try { String sql = "select isReceiveMaintenanceFeeNotification,inactive,usercode,username from _sys_LoginUser where isReceiveMaintenanceFeeNotification=1 and inactive=0"; if (!StringUtils.isBlank(userCode)) { sql += " and userCode='" + userCode + "'"; } List> list = super.jdbcTemplate.queryForList(sql); if (list != null && list.size() > 0) { bol = true; } } catch (Exception e) { bol = false; } return bol; } @Override public List selectMaintainNoticeUser() { try { String sql = "select UserCode from _sys_LoginUser where isReceiveMaintenanceFeeNotification=1 and inActive=0"; return super.jdbcTemplate.query(sql, new RowMapper() { @Override public String mapRow(ResultSet resultSet, int i) throws SQLException { return resultSet.getString(1); } }, null); } catch (Exception e) { return null; } } @Override public boolean updateT150372(String autoIds) { boolean bol = false; try { String sql = "set nocount on\n" + " declare @autoids varchar(max) = '" + autoIds + "' \n" + " update a set ISpush = 1 ,PushDate = getdate() from t150372 a where a.autoid in (select list from GetInStr( @autoids)) \n" + " select @@ROWCOUNT"; Integer cunt = super.jdbcTemplate.update(sql); if (cunt != null && cunt > 0) { bol = true; } } catch (Exception e) { bol = false; } return bol; } @Override public String selectCltCodeDbId(String table, String docCode) throws Exception { try { PayInfo info = payInfoMapper.getPayInfoTable(table, docCode); if (info != null && !StringUtils.isBlank(info.getCltCode())) { Integer dbId = cltInfoService.queryDbIdByCltCode(info.getCltCode()); if (dbId == null || dbId == 0) { throw new Exception("获取不到客户编号:" + info.getCltCode() + "的dbId值,请完善【维护客户资料-110203】表内的dbId值"); } return dbId + ""; } else { throw new Exception("客户编号不能为空!"); } } catch (Exception e) { throw e; } } /** * 生成收款单 * * @param whCode * @param accountCode * @return * @throws Exception */ @Override public String createSKCode(String whCode, String accountCode) throws Exception { try { String sql = " declare @linkdocinfo varchar(8000) \n" + " declare @FromDocCode varchar(5000) ='" + whCode + "' ,@FromFormId int = 120311 , @usercode varchar(20) = 'SYSTEM' \n" + " declare @username varchar(50) = '系统管理员',@newdoccode varchar(20) ,@newformid int \n" + " declare @AccountCode varchar(20) = '" + accountCode + "' \n" + " exec p150105V6 @FromDocCode = @FromDocCode ,@FromFormId =@FromFormId , @usercode = @usercode , \n" + " @username =@username,@newdoccode = @newdoccode output,@newformid = @newformid output,@linkdocinfo = @linkdocinfo output \n" + " update a set AccountCode = @AccountCode from t150348 a where doccode = @newdoccode\n" + " select @newdoccode as DocCode "; return super.jdbcTemplate.queryForObject(sql, String.class); } catch (Exception e) { throw e; } } @Override public List> selectMaintainMsg() { try { String sql = "declare @today datetime = convert(varchar(10),getdate(),120) \n" + " select a.autoid,a.messagetxt,a.refdoccode,a.refformid,a.refformtype,a.insertactioncode," + " a.insertactionname,a.insertdate ,b.dbid,a.unvaliddate,a.tipcount \n" + " from t150372 a join t110203 b on a.cltcode = b.cltcode \n" + " where a.ScheduledSendDate <= @today and isnull(a.ispush,0) = 0 and isnull(a.ispay,0) = 0"; return super.jdbcTemplate.queryForList(sql); } catch (Exception e) { return null; } } @Override public Integer selectMaintainCunt(String dbId) { try { String sql = "select COUNT(*) from t120301H a join t110203 b on a.CltCode=b.cltCode and a.DocStatus=100 and isnull(a.ReceivMoney,0) - isnull(a.ShouKuanAmount,0)>0 where b.dbId=" + dbId; return super.jdbcTemplate.queryForObject(sql, Integer.class); } catch (Exception e) { return 0; } } @Override public Integer updateMessage(String whCode) { try { String sql = "set nocount on\n" + " declare @whCode varchar(max) = '" + whCode + "' \n" + " update a set a.tipcount = 0 from _sysMessage a where a.FromDbId=338 and a.formid=120311 \n" + " and a.origfields in(select list from GetInStr(@whCode)) \n" + " select @@ROWCOUNT"; Integer count= super.jdbcTemplate.update(sql); return count; } catch (Exception e) { return 0; } } @Override public List selectWHCode(String skCode) { try { String sql="select SODoccode from t150101D where DocCode='"+skCode+"'"; return super.jdbcTemplate.query(sql, new RowMapper() { @Override public String mapRow(ResultSet resultSet, int i) throws SQLException { return resultSet.getString(1); } },null); }catch (Exception e){ return null; } } /** * 通过生成单据保存及过账sql,默认以@doccode为单号变量 * * @param formid * @return */ private String createPostSql(int formid) { return " --执行保存及过账---维护费支付后进行的保存及过账---\n" + " exec p" + formid + "Save @doccode\n" + " select @PostFormId = FormId,@DocStatusValue = DocStatus from t" + formid + "H where docCode=@docCode\n" + " select @PreDocStatus = PreDocStatus,@PostDocStatus = a.PostDocStatus from gform a where a.formid = @PostFormId \n" + " if isnull(@DocStatusValue,0) = isnull(@PreDocStatus,0)\n" + " begin \n" + " update a set DocStatus = @PostDocStatus,PostCode=@EnterCode,PostName=@EnterName,PostDate=@now\n" + " from t" + formid + "H a where a.DocCode = @docCode \n" + " exec p" + formid + "Post @UserCode = @EnterCode,@UserName = @EnterName, \n" + " @DocCode = @docCode,@FormId = @PostFormId,\n" + " @DocStatusValue = @DocStatusValue,@ButtonType ='提交', \n" + " @Memo=@Memo output ,@LinkDocInfo = @LinkDocInfo output \n" + " end\n"; } }