diff --git a/src/main/java/aiyh/utils/ecologyutil/modelutil/CusModelUtil.java b/src/main/java/aiyh/utils/ecologyutil/modelutil/CusModelUtil.java new file mode 100644 index 0000000..cadcf3f --- /dev/null +++ b/src/main/java/aiyh/utils/ecologyutil/modelutil/CusModelUtil.java @@ -0,0 +1,44 @@ +package aiyh.utils.ecologyutil.modelutil; + +import aiyh.utils.Util; +import aiyh.utils.httpUtil.cushttpclasses.CusHttpSession; +import com.alibaba.fastjson.JSONObject; +import com.engine.common.util.ServiceUtil; +import com.engine.cube.service.ModeAppService; +import com.engine.cube.service.impl.ModeAppServiceImpl; +import org.apache.log4j.Logger; +import weaver.hrm.User; +import java.util.HashMap; +import java.util.Map; + +/** + * 建模相关工具方法 + */ +public class CusModelUtil { + + private static Logger logger = Util.getLogger(); + public static ModeAppService modeAppService = ServiceUtil.getService(ModeAppServiceImpl.class, new User(1)); + + /** + * 建模数据全部权限重构 + * @param modeId + */ + public static void rebuildRight(String modeId) { + try{ + Map param = new HashMap<>(); + param.put("rebulidFlag", "1"); + param.put("righttype", "1"); + param.put("modeid", modeId); + param.put("rebulidFlag", "1"); + param.put("showProgress", "0"); + param.put("operation", "resetAllRight"); + param.put("session", new CusHttpSession()); + Map stringObjectMap = modeAppService.saveModeRightList(param, new User(1)); + logger.info("CusModelUtil.rebuildRight end;result:"+new JSONObject(stringObjectMap).toJSONString() + ";param:" + modeId); + }catch(Throwable e){ + logger.error("CusModelUtil.rebuildRight error;message:" + e.getMessage()); + } + + } + +} \ No newline at end of file diff --git a/src/main/java/aiyh/utils/ecologyutil/rightutil/RightMoveUtil.java b/src/main/java/aiyh/utils/ecologyutil/rightutil/RightMoveUtil.java new file mode 100644 index 0000000..840d0e2 --- /dev/null +++ b/src/main/java/aiyh/utils/ecologyutil/rightutil/RightMoveUtil.java @@ -0,0 +1,68 @@ +package aiyh.utils.ecologyutil.rightutil; + +import aiyh.utils.Util; +import aiyh.utils.httpUtil.cushttpclasses.CusHttpServletRequest; +import aiyh.utils.httpUtil.cushttpclasses.CusHttpSession; +import com.alibaba.fastjson.JSONObject; +import com.engine.hrm.cmd.permissiontoadjust.ProcessDataCmd; +import org.apache.log4j.Logger; +import weaver.hrm.User; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpSession; +import java.util.HashMap; +import java.util.Map; + + +/** + * ecology权限相关方法 + * + */ +public class RightMoveUtil { + + private static Logger logger = Util.getLogger(); + + /** + * 触发标准权限转移 转移待办已办等信息 + * @param param 入参按需填写如下等参数 + * fromid + * toid + * T133All + * T133AllNum + * @return + */ + public static JSONObject moveRight(JSONObject param){ + JSONObject result = new JSONObject(); + try{ + logger.info("RightMoveUtil moveRight begin;param:" + param.toJSONString()); + Map params = new HashMap<>(); + for(Object key : param.keySet()){ + params.put(key.toString(),param.get(key)); + } + HttpServletRequest request = new CusHttpServletRequest(){ + @Override + public String getParameter(String s) { + return param.getString(s); + } + @Override + public HttpSession getSession(boolean b) { + HttpSession session = new CusHttpSession(){ + @Override + public Object getAttribute(String s) { + return new User(1); + } + }; + return session; + } + }; + ProcessDataCmd cmd = new ProcessDataCmd(params,request,new User(1)); + Map execute = cmd.execute(null); + result = new JSONObject(execute); + logger.info("RightMoveUtil moveRight end;result:" + execute.toString()); + return result; + }catch (Throwable e){ + logger.error("RightMoveUtil moveRight error;message:" + e.getMessage()); + return result; + } + } + +} \ No newline at end of file diff --git a/src/main/java/aiyh/utils/httpUtil/cushttpclasses/CusHttpServletRequest.java b/src/main/java/aiyh/utils/httpUtil/cushttpclasses/CusHttpServletRequest.java new file mode 100644 index 0000000..231944e --- /dev/null +++ b/src/main/java/aiyh/utils/httpUtil/cushttpclasses/CusHttpServletRequest.java @@ -0,0 +1,274 @@ +package aiyh.utils.httpUtil.cushttpclasses; + +import javax.servlet.RequestDispatcher; +import javax.servlet.ServletInputStream; +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpSession; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.security.Principal; +import java.util.Enumeration; +import java.util.Locale; +import java.util.Map; + +public class CusHttpServletRequest implements HttpServletRequest { + + @Override + public String getMethod() { + return null; + } + + @Override + public String getRequestURI() { + return null; + } + + @Override + public StringBuffer getRequestURL() { + return null; + } + + @Override + public String getContextPath() { + return null; + } + + @Override + public String getServletPath() { + return null; + } + + @Override + public String getPathInfo() { + return null; + } + + @Override + public String getPathTranslated() { + return null; + } + + @Override + public String getQueryString() { + return null; + } + + @Override + public String getHeader(String s) { + return null; + } + + @Override + public Enumeration getHeaders(String s) { + return null; + } + + @Override + public Enumeration getHeaderNames() { + return null; + } + + @Override + public int getIntHeader(String s) { + return 0; + } + + @Override + public long getDateHeader(String s) { + return 0; + } + + @Override + public Cookie[] getCookies() { + return new Cookie[0]; + } + + @Override + public HttpSession getSession(boolean b) { + return null; + } + + @Override + public HttpSession getSession() { + return null; + } + + @Override + public String getRequestedSessionId() { + return null; + } + + @Override + public boolean isRequestedSessionIdValid() { + return false; + } + + @Override + public boolean isRequestedSessionIdFromCookie() { + return false; + } + + @Override + public boolean isRequestedSessionIdFromURL() { + return false; + } + + @Override + public String getAuthType() { + return null; + } + + @Override + public String getRemoteUser() { + return null; + } + + @Override + public boolean isUserInRole(String s) { + return false; + } + + @Override + public Principal getUserPrincipal() { + return null; + } + + /** + * @deprecated + */ + @Override + public boolean isRequestedSessionIdFromUrl() { + return false; + } + + @Override + public String getProtocol() { + return null; + } + + @Override + public String getScheme() { + return null; + } + + @Override + public String getServerName() { + return null; + } + + @Override + public int getServerPort() { + return 0; + } + + @Override + public String getRemoteAddr() { + return null; + } + + @Override + public String getRemoteHost() { + return null; + } + + @Override + public void setCharacterEncoding(String s) throws UnsupportedEncodingException { + + } + + @Override + public String getParameter(String s) { + return null; + } + + @Override + public String[] getParameterValues(String s) { + return new String[0]; + } + + @Override + public Enumeration getParameterNames() { + return null; + } + + @Override + public Map getParameterMap() { + return null; + } + + @Override + public ServletInputStream getInputStream() throws IOException { + return null; + } + + @Override + public BufferedReader getReader() throws IOException, IllegalStateException { + return null; + } + + @Override + public String getCharacterEncoding() { + return null; + } + + @Override + public int getContentLength() { + return 0; + } + + @Override + public String getContentType() { + return null; + } + + @Override + public Locale getLocale() { + return null; + } + + @Override + public Enumeration getLocales() { + return null; + } + + @Override + public boolean isSecure() { + return false; + } + + @Override + public Object getAttribute(String s) { + return null; + } + + @Override + public void setAttribute(String s, Object o) { + + } + + @Override + public Enumeration getAttributeNames() { + return null; + } + + @Override + public void removeAttribute(String s) { + + } + + @Override + public RequestDispatcher getRequestDispatcher(String s) { + return null; + } + + /** + * @param s + * @deprecated + */ + @Override + public String getRealPath(String s) { + return null; + } +} diff --git a/src/main/java/aiyh/utils/httpUtil/cushttpclasses/CusHttpSession.java b/src/main/java/aiyh/utils/httpUtil/cushttpclasses/CusHttpSession.java new file mode 100644 index 0000000..ba33838 --- /dev/null +++ b/src/main/java/aiyh/utils/httpUtil/cushttpclasses/CusHttpSession.java @@ -0,0 +1,113 @@ +package aiyh.utils.httpUtil.cushttpclasses; + +import javax.servlet.ServletContext; +import javax.servlet.http.HttpSession; +import javax.servlet.http.HttpSessionContext; +import java.util.Enumeration; + +public class CusHttpSession implements HttpSession { + + @Override + public String getId() { + return null; + } + + @Override + public boolean isNew() { + return false; + } + + @Override + public long getCreationTime() { + return 0; + } + + @Override + public long getLastAccessedTime() { + return 0; + } + + @Override + public void setMaxInactiveInterval(int i) { + + } + + @Override + public int getMaxInactiveInterval() { + return 0; + } + + @Override + public Object getAttribute(String s) { + return null; + } + + @Override + public Enumeration getAttributeNames() { + return null; + } + + @Override + public void setAttribute(String s, Object o) { + + } + + @Override + public void removeAttribute(String s) { + + } + + @Override + public void invalidate() { + + } + + /** + * @deprecated + */ + @Override + public HttpSessionContext getSessionContext() { + return null; + } + + @Override + public ServletContext getServletContext() { + return null; + } + + /** + * @param s + * @deprecated + */ + @Override + public Object getValue(String s) { + return null; + } + + /** + * @deprecated + */ + @Override + public String[] getValueNames() { + return new String[0]; + } + + /** + * @param s + * @param o + * @deprecated + */ + @Override + public void putValue(String s, Object o) { + + } + + /** + * @param s + * @deprecated + */ + @Override + public void removeValue(String s) { + + } +} diff --git a/src/main/java/com/api/chaoyang/he/hcy_hangtiankeji/accesscontractsystem/controller/PublishInformationAction.java b/src/main/java/com/api/chaoyang/he/hcy_hangtiankeji/accesscontractsystem/controller/PublishInformationAction.java new file mode 100644 index 0000000..a75bbe0 --- /dev/null +++ b/src/main/java/com/api/chaoyang/he/hcy_hangtiankeji/accesscontractsystem/controller/PublishInformationAction.java @@ -0,0 +1,45 @@ +package com.api.chaoyang.he.hcy_hangtiankeji.accesscontractsystem.controller; + + +import aiyh.utils.ApiResult; +import aiyh.utils.Util; + +import com.api.chaoyang.he.hcy_hangtiankeji.accesscontractsystem.entity.ContractParametersEntity; +import com.api.chaoyang.he.hcy_hangtiankeji.accesscontractsystem.service.PublishInformationService; +import com.api.chaoyang.he.hcy_hangtiankeji.accesscontractsystem.service.impl.PublishInformationServiceImpl; +import io.swagger.v3.oas.annotations.parameters.RequestBody; +import org.apache.log4j.Logger; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; +import java.util.Map; +//合同系统接收单位或部门编码,根据编码整理所有下级单位及部门的合同台账详细信息,并将数据返回给调用方。 +@Path("/pubish") +public class PublishInformationAction { + + //日志处理 + private final Logger log = Util.getLogger(); + + //service主要的业务逻辑 + private final PublishInformationService publishInformationService = new PublishInformationServiceImpl(); + + @Path("/information/action") + @POST + @Produces(MediaType.APPLICATION_JSON) + public String getReportData(@Context HttpServletRequest request, @Context HttpServletResponse response, @RequestBody Map param) { + //单位编码 + String divisionCode = request.getParameter("divisionCode"); + //部门编码 + String deptCode = request.getParameter("deptCode"); + ContractParametersEntity contractParametersEntity = publishInformationService.getResponseJson(divisionCode,deptCode); + if (contractParametersEntity!=null){ + return ApiResult.success(contractParametersEntity,200,"查询成功,结果如下"); + } + return ApiResult.error(404,"参数为空,请重新选择单位编码和部门编码"); + } +} diff --git a/src/main/java/com/api/chaoyang/he/hcy_hangtiankeji/accesscontractsystem/entity/ContractParametersEntity.java b/src/main/java/com/api/chaoyang/he/hcy_hangtiankeji/accesscontractsystem/entity/ContractParametersEntity.java new file mode 100644 index 0000000..17521f7 --- /dev/null +++ b/src/main/java/com/api/chaoyang/he/hcy_hangtiankeji/accesscontractsystem/entity/ContractParametersEntity.java @@ -0,0 +1,76 @@ +package com.api.chaoyang.he.hcy_hangtiankeji.accesscontractsystem.entity; + + +import lombok.Data; +/** + *

合同系统响应返回参数实体类

+ * @Author 何朝阳 + * @Date 2023/4/21 17:59 + */ +@Data +public class ContractParametersEntity { + //合同编码 + private String contractno; + //合同名称 + private String contractname; + //合同密级 + private String contractsecret; + //合同类别 + private String contracttype; + //合同审批流程 + private String contractworkflow; + //合同性质 + private String contractproperties; + //对应型号 + private String correspond; + //甲方 + private String partya; + //甲方单位属性 + private String partyaprop; + //乙方 + private String partyb; + //项目名称 + private String entryname; + //订单编号 + private String orderno; + //合同总金额 + private String totalamount; + //价款类型 + private String pricetype; + //已收/付金额 + private String receivedamount; + //已开/收票金额 + private String issuedamount; + //剩余未收/付金额 + private String remainingamount; + //币种 + private String currency; + //合同状态 + private String contractstatus; + //收付款进度 + private String collectionprogress; + //收付款方式 + private String paymentmethod; + //签约日期 + private String signingdate; + //签约地 + private String signingplace; + //是否需要飞行试验 + private String flighttest; + //二级单位名称 + private String secondaryunit; + //承办单位名称 + private String organizername; + //承办部门 + private String undertakedepart; + //承办人 + private String undertakeperson; + //签订人 + private String signedby; + //合同用印文件 + private String contractfile; + //其他合同附件 + private String otherattachments; + + // getter and setter methods +} diff --git a/src/main/java/com/api/chaoyang/he/hcy_hangtiankeji/accesscontractsystem/mapper/PublishInformationMapper.java b/src/main/java/com/api/chaoyang/he/hcy_hangtiankeji/accesscontractsystem/mapper/PublishInformationMapper.java new file mode 100644 index 0000000..30b7b6a --- /dev/null +++ b/src/main/java/com/api/chaoyang/he/hcy_hangtiankeji/accesscontractsystem/mapper/PublishInformationMapper.java @@ -0,0 +1,20 @@ +package com.api.chaoyang.he.hcy_hangtiankeji.accesscontractsystem.mapper; + +import aiyh.utils.annotation.recordset.Select; +import aiyh.utils.annotation.recordset.SqlMapper; +import com.api.chaoyang.he.hcy_hangtiankeji.accesscontractsystem.entity.ContractParametersEntity; + +@SqlMapper +public interface PublishInformationMapper { + + /** + *

这里可以根据单位编码和部门编码查询uf_xyz表中的合同信息,并将结果存储到 ContractParametersEntity对象中

+ * @param divisionCode 单位编码 + * @param deptCode 部门编码 + * @return ContractParametersEntity 处理DB查询返回参数的实体类 + * @author hcy + * @Date 2023/4/23 9:47 + */ + @Select("select * from uf_xyz where division = #{divisionCode} and deptment =#{deptCode}") + ContractParametersEntity getDeptList(String divisionCode, String deptCode); +} diff --git a/src/main/java/com/api/chaoyang/he/hcy_hangtiankeji/accesscontractsystem/service/PublishInformationService.java b/src/main/java/com/api/chaoyang/he/hcy_hangtiankeji/accesscontractsystem/service/PublishInformationService.java new file mode 100644 index 0000000..765f127 --- /dev/null +++ b/src/main/java/com/api/chaoyang/he/hcy_hangtiankeji/accesscontractsystem/service/PublishInformationService.java @@ -0,0 +1,7 @@ +package com.api.chaoyang.he.hcy_hangtiankeji.accesscontractsystem.service; + +import com.api.chaoyang.he.hcy_hangtiankeji.accesscontractsystem.entity.ContractParametersEntity; + +public interface PublishInformationService { + ContractParametersEntity getResponseJson(String divisionCode, String deptCode); +} diff --git a/src/main/java/com/api/chaoyang/he/hcy_hangtiankeji/accesscontractsystem/service/impl/PublishInformationServiceImpl.java b/src/main/java/com/api/chaoyang/he/hcy_hangtiankeji/accesscontractsystem/service/impl/PublishInformationServiceImpl.java new file mode 100644 index 0000000..3a5e74c --- /dev/null +++ b/src/main/java/com/api/chaoyang/he/hcy_hangtiankeji/accesscontractsystem/service/impl/PublishInformationServiceImpl.java @@ -0,0 +1,30 @@ +package com.api.chaoyang.he.hcy_hangtiankeji.accesscontractsystem.service.impl; + +import aiyh.utils.Util; +import com.api.chaoyang.he.hcy_hangtiankeji.accesscontractsystem.entity.ContractParametersEntity; +import com.api.chaoyang.he.hcy_hangtiankeji.accesscontractsystem.mapper.PublishInformationMapper; +import com.api.chaoyang.he.hcy_hangtiankeji.accesscontractsystem.service.PublishInformationService; +import org.apache.log4j.Logger; + + + +public class PublishInformationServiceImpl implements PublishInformationService { + + //日志 + private final Logger logger = Util.getLogger(); + //处理业务的sql + private final PublishInformationMapper publishInformationMapper = Util.getMapper(PublishInformationMapper.class); + + + @Override + public ContractParametersEntity getResponseJson(String divisionCode, String deptCode) { + + if (!"".equals(divisionCode)&& !"".equals(deptCode)){ + ContractParametersEntity dataDb = publishInformationMapper.getDeptList(divisionCode,deptCode); + if (dataDb == null){ + return dataDb; + } + } + return null; + } +} diff --git a/src/main/java/com/api/chaoyang/he/hcy_hangtiankeji/gmlowgroupsenddata/controller/SendContractInfoController.java b/src/main/java/com/api/chaoyang/he/hcy_hangtiankeji/gmlowgroupsenddata/controller/SendContractInfoController.java new file mode 100644 index 0000000..0975d12 --- /dev/null +++ b/src/main/java/com/api/chaoyang/he/hcy_hangtiankeji/gmlowgroupsenddata/controller/SendContractInfoController.java @@ -0,0 +1,50 @@ +package com.api.chaoyang.he.hcy_hangtiankeji.gmlowgroupsenddata.controller; + +import aiyh.utils.ApiResult; +import aiyh.utils.Util; +import com.api.chaoyang.he.hcy_hangtiankeji.gmlowgroupsenddata.service.SendContractInfoService; +import com.api.chaoyang.he.hcy_hangtiankeji.gmlowgroupsenddata.service.impl.SendContractInfoServiceImpl; +import org.apache.log4j.Logger; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; +import java.util.List; +import java.util.Map; + +/** + *

GM集团下级单位合同台账信息上报接口

+ * @author hcy + * @date 2023/5/8 13:36 + */ +@Path("/send") +public class SendContractInfoController { + + + /** + * 日志处理 + */ + private final Logger logger = Util.getLogger(); + + /** + * 接口主要业务处理,service层 + */ + private final SendContractInfoService sendContractInfoService = new SendContractInfoServiceImpl(); + + @POST + @Path("/Contract/Info") + @Produces(MediaType.APPLICATION_JSON) + public String sendContractInfo(@Context HttpServletRequest request, @Context HttpServletResponse response){ + String zbzt = request.getParameter("zbzt"); + List> contractInfo = sendContractInfoService.sendContractData(zbzt); + if (contractInfo.size() == 0){ + return ApiResult.error("接口数据为空,请检查台账数据是否为空"); + } + return ApiResult.success(contractInfo,200,"成功"); + } + +} diff --git a/src/main/java/com/api/chaoyang/he/hcy_hangtiankeji/gmlowgroupsenddata/mapper/SendContractInfoMapper.java b/src/main/java/com/api/chaoyang/he/hcy_hangtiankeji/gmlowgroupsenddata/mapper/SendContractInfoMapper.java new file mode 100644 index 0000000..3bf9a14 --- /dev/null +++ b/src/main/java/com/api/chaoyang/he/hcy_hangtiankeji/gmlowgroupsenddata/mapper/SendContractInfoMapper.java @@ -0,0 +1,42 @@ +package com.api.chaoyang.he.hcy_hangtiankeji.gmlowgroupsenddata.mapper; + +import aiyh.utils.annotation.recordset.ParamMapper; +import aiyh.utils.annotation.recordset.Select; +import aiyh.utils.annotation.recordset.SqlMapper; + +import java.util.List; +import java.util.Map; + +@SqlMapper +public interface SendContractInfoMapper { + + @Select("select * from uf_httztb where wybs = #{uniqueIdentification} ") + List> selectConfigData(@ParamMapper("uniqueIdentification") String uniqueIdentification); + + + @Select("select * from uf_httztb_dt1 where mainid = #{mainid}") + List> getConfigDetal1Information(@ParamMapper("mainid")String mainid); + + @Select("select * from uf_httztb_dt2 where mainid = #{mainid}") + List> getConfigDetal2Information(@ParamMapper("mainid")String mainid); + + @Select("select $t{selectKeys} from $t{tableName}") + List> selectAllDBData(@ParamMapper("selectKeys") String selectKeys, + @ParamMapper("tableName") String tableName); + + @Select("select $t{selectKeys} from $t{tableName} where LEFT(modedatacreatedate,10) = LEFT(#{yesterday},10) or LEFT(modedatamodifydatetime,10) = LEFT(#{yesterday},10)") + List> selectYesterdayDBData(@ParamMapper("selectKeys")String selectKeys, + @ParamMapper("tableName")String tableName, + @ParamMapper("yesterday")String yesterday); + + @Select("select $t{selectDatailTableKeys} from $t{s} where mainid = #{mainid}") + List> selectAllDetailDBData(@ParamMapper("selectDatailTableKeys") String selectDatailTableKeys, + @ParamMapper("s")String s, + @ParamMapper("mainid")String mainid); + + @Select("select imagefileid from DocImageFile where docid = #{lcqzyj} order by versionId") + String getImageFileId(@ParamMapper("lcqzyj") String lcqzyj); + + @Select("select imagefilename from DocImageFile where docid = #{lcqzyj} order by versionId desc") + String getImagefilename(@ParamMapper("lcqzyj") String lcqzyj); +} diff --git a/src/main/java/com/api/chaoyang/he/hcy_hangtiankeji/gmlowgroupsenddata/service/SendContractInfoService.java b/src/main/java/com/api/chaoyang/he/hcy_hangtiankeji/gmlowgroupsenddata/service/SendContractInfoService.java new file mode 100644 index 0000000..3d16c73 --- /dev/null +++ b/src/main/java/com/api/chaoyang/he/hcy_hangtiankeji/gmlowgroupsenddata/service/SendContractInfoService.java @@ -0,0 +1,8 @@ +package com.api.chaoyang.he.hcy_hangtiankeji.gmlowgroupsenddata.service; + +import java.util.List; +import java.util.Map; + +public interface SendContractInfoService { + List> sendContractData(String zbzt); +} diff --git a/src/main/java/com/api/chaoyang/he/hcy_hangtiankeji/gmlowgroupsenddata/service/impl/SendContractInfoServiceImpl.java b/src/main/java/com/api/chaoyang/he/hcy_hangtiankeji/gmlowgroupsenddata/service/impl/SendContractInfoServiceImpl.java new file mode 100644 index 0000000..0989c1e --- /dev/null +++ b/src/main/java/com/api/chaoyang/he/hcy_hangtiankeji/gmlowgroupsenddata/service/impl/SendContractInfoServiceImpl.java @@ -0,0 +1,222 @@ +package com.api.chaoyang.he.hcy_hangtiankeji.gmlowgroupsenddata.service.impl; + +import aiyh.utils.Util; +import com.api.chaoyang.he.hcy_hangtiankeji.gmlowgroupsenddata.mapper.SendContractInfoMapper; +import com.api.chaoyang.he.hcy_hangtiankeji.gmlowgroupsenddata.service.SendContractInfoService; +import com.google.common.base.Joiner; +import com.weaver.formmodel.util.DateHelper; +import org.apache.log4j.Logger; +import sun.misc.BASE64Decoder; +import weaver.file.ImageFileManager; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.*; + +public class SendContractInfoServiceImpl implements SendContractInfoService { + + /** + * 日志处理 + */ + private final Logger logger = Util.getLogger(); + /** + * deal sql + */ + private final SendContractInfoMapper sendContractInfoMapper = Util.getMapper(SendContractInfoMapper.class); + + /** + * 查询国密下级单位台账中数据并返回 + * @return 返回台账数据集合 + * @param zbzt 同步状态:0 全量同步 1 增量同步 + */ + public List> sendContractData(String zbzt) { + //获取配置表主表数据 + List> configMainTableData = sendContractInfoMapper.selectConfigData("fw002"); + if (configMainTableData.size()==0)return configMainTableData; + String mainid = Util.null2String(configMainTableData.get(0).get("id")); + //配置表明细表1数据: + List> configDetal1TableData = sendContractInfoMapper.getConfigDetal1Information(mainid); + logger.info("配置表明细表数据---configDetal1TableData---"+configDetal1TableData); + //明细表2数据 + List> configDetal2TableData = sendContractInfoMapper.getConfigDetal2Information(mainid); + + List> configDetal2TableNewData = new ArrayList<>();//处理完大小写问题后 + filterUppercaseField(configDetal2TableData,configDetal2TableNewData); + logger.info("配置表明细表数据---configDetal2TableNewData---"+configDetal2TableNewData); + + + if (configDetal1TableData.size()==0) return configDetal1TableData; + String tableName = Util.null2String(configDetal1TableData.get(0).get("ejdwtzb"));//二级单位台账表数据库名称 + String bz = Util.null2String(configDetal1TableData.get(0).get("bz")); //备注 + logger.info("二级单位台账表数据库名称===="+tableName+" 二级单位台账表数名称==="+bz); + + if (configDetal2TableNewData.size()==0)return configDetal1TableData; + List mainTableKeys = new ArrayList<>();//用于insert和update的key + List detailTableKeys = new ArrayList<>();//用于insert和update的key + + for (Map configdetal2 : configDetal2TableNewData) { + String sfzb = Util.null2String(configdetal2.get("sfzb"));//是否主表 + if ("0".equals(sfzb)){ + mainTableKeys.add(Util.null2String(configdetal2.get("tbzd")));//添加主表key + }else { + detailTableKeys.add(Util.null2String(configdetal2.get("tbzd")));//添加明细表key + } + } + mainTableKeys.add("id");//拼接id + String selectMainTableKeys = Joiner.on(",").join((Iterable) mainTableKeys);//拼接主表的查询条件 + String selectDatailTableKeys = Joiner.on(",").join((Iterable) detailTableKeys);//拼接明细表的查询条件 + + + List> returnDataList = new ArrayList<>();//返回一个空数组 + logger.info("selectMainTableKeys:"+selectMainTableKeys+"------selectDatailTableKeys:"+selectDatailTableKeys ); + if ("0".equals(zbzt)) {//全量数据 + List> allDBData = sendContractInfoMapper.selectAllDBData(selectMainTableKeys, tableName); + logger.info("-------allDBData------"+allDBData); + List> filterUppercaseNewAllDBData = new ArrayList<>(); + filterUppercaseField(allDBData,filterUppercaseNewAllDBData); + for (Map allDBDatum : filterUppercaseNewAllDBData) { + String ejdw_mainid = Util.null2String(allDBDatum.get("id")); + List> detalData = sendContractInfoMapper.selectAllDetailDBData(selectDatailTableKeys, tableName + "_dt1", ejdw_mainid);//查询到主表对应的明细表数据 + logger.info("------detalData------"+detalData); + List> filterUppercaseFieldDetailData = new ArrayList<>(); + filterUppercaseField(detalData,filterUppercaseFieldDetailData);//处理掉大写字母的问题 + logger.info("------filterUppercaseFieldDetailData------"+filterUppercaseFieldDetailData); + allDBDatum.put("detailData", filterUppercaseFieldDetailData);//向主表数据中放入明细表数据 + } + logger.info("-------filterUppercaseNewAllDBData------"+filterUppercaseNewAllDBData); + List> newAllDBData = this.dealwithSpecialFields(filterUppercaseNewAllDBData); + logger.info("-------newAllDBData------"+newAllDBData); + return newAllDBData; + }else if ("1".equals(zbzt)) {//增量数据 + List> yesterDayDBData = sendContractInfoMapper.selectYesterdayDBData(selectMainTableKeys, tableName, DateHelper.getYesterday()); + logger.info("-------yesterDayDBData------"+yesterDayDBData); + List> filterUppercasenewYesterDayDBData = new ArrayList<>(); + filterUppercaseField(yesterDayDBData,filterUppercasenewYesterDayDBData); + for (Map yesterDayDBDatum : filterUppercasenewYesterDayDBData) { + String id = Util.null2String(yesterDayDBDatum.get("id")); + List> detalData = sendContractInfoMapper.selectAllDetailDBData(selectDatailTableKeys, tableName + "_dt1", id);//查询到主表对应的明细表数据 + logger.info("-------detalData------"+detalData); + List> filterUppercaseFieldDetailData = new ArrayList<>(); + filterUppercaseField(detalData,filterUppercaseFieldDetailData);//处理掉大写字母的问题 + logger.info("-------filterUppercaseFieldDetailData------"+filterUppercaseFieldDetailData); + yesterDayDBDatum.put("detailData", filterUppercaseFieldDetailData);//向主表数据中放入明细表数据 + } + logger.info("-------filterUppercasenewYesterDayDBData------"+filterUppercasenewYesterDayDBData); + List> newYesterDayDBData = this.dealwithSpecialFields(filterUppercasenewYesterDayDBData); + logger.info("-------newYesterDayDBData------"+newYesterDayDBData); + return newYesterDayDBData; + } + return returnDataList; + } + + /** + * 过滤大写字段问题 + * @param oldListMap 旧的字段 + * @param newListMap 处理完的字段 + */ + public void filterUppercaseField(List> oldListMap,List> newListMap){ + for (Map configDetal2TableDatum : oldListMap) { + Map newData = new HashMap<>(); + for (Map.Entry entry : configDetal2TableDatum.entrySet()) { + String key = entry.getKey().toLowerCase(); + Object value = entry.getValue(); + newData.put(key, value); + } + // 创建新数据集合 + newListMap.add(newData); + } + } + + /** + * 处理双方用印文件、其它合同附件、流程签字意见三个字段 + * @param allDBData 处理之前的数据 + * @return 处理完逻辑之后的数据 + */ + private List> dealwithSpecialFields(List> allDBData) { + for (Map allDBDatum : allDBData) { + String htyywj = Util.null2String(allDBDatum.get("htyywj"));//双方用印文件 + String qthtfj = Util.null2String(allDBDatum.get("qthtfj"));//其它合同附件 + String lcqzyj = Util.null2String(allDBDatum.get("lcqzyj"));//流程签字意见:需要流程存为文档 + String ip = Util.getCusConfigValue("setIp_htkj");//获取配置表中自定义参数,用来配置ip地址、 + if (!"".equals(htyywj)){ + String newIp = ip + htyywj; + allDBDatum.put("htyywj",newIp);//链接地址:ip://xxx--docid + } + if (!"".equals(qthtfj)){ + String newIp = ip +qthtfj; + allDBDatum.put("qthtfj",newIp);//链接地址:ip:xxx--docid + } + if (!"".equals(lcqzyj) && !"-1".equals(lcqzyj)){ + //根据docid获取文件名称 + String imagefilename = sendContractInfoMapper.getImagefilename(lcqzyj); + if (!"".equals(imagefilename)) { + allDBDatum.put("imagefilename",imagefilename); + }else{ + allDBDatum.put("imagefilename", UUID.randomUUID()+".pdf"); + } + int imagefileid = Util.getIntValue(sendContractInfoMapper.getImageFileId(lcqzyj));//根据docid,查询到imageFileid + InputStream inputStream = ImageFileManager.getInputStreamById(imagefileid);//根据imagefileid查询到文件流 + if (inputStream!=null){ + try { + allDBDatum.put("lcqzyj",Util.null2String(inputStream2Base64(inputStream)));//将处理好的文件消息重新放入字段中 + } catch (Exception e) { + e.printStackTrace(); + logger.error("流转换异常===="+e); + } + } + + }else{ + allDBDatum.put("lcqzyj", ""); + } + } + return allDBData; + } + + /** + * 将inputstream转为Base64 + * @param is 字节流 + * @return String 加密后的字符串 + */ + private static String inputStream2Base64(InputStream is) throws Exception { + byte[] data = null; + try { + ByteArrayOutputStream swapStream = new ByteArrayOutputStream(); + byte[] buff = new byte[1024]; + int rc = 0; + while ((rc = is.read(buff, 0, 100)) > 0) { + swapStream.write(buff, 0, rc); + } + data = swapStream.toByteArray(); + } catch (IOException e) { + e.printStackTrace(); + } finally { + if (is != null) { + try { + is.close(); + } catch (IOException e) { + throw new Exception("输入流关闭异常"); + } + } + } + return Base64.getEncoder().encodeToString(data); + } + + + /** + * base64转inputStream + * @param base64string 包含输入流的字符串 + * @return inputStream + */ + private static InputStream base2InputStream(String base64string) { + ByteArrayInputStream stream = null; + try { + BASE64Decoder decoder = new BASE64Decoder(); + byte[] bytes1 = decoder.decodeBuffer(base64string); + stream = new ByteArrayInputStream(bytes1); + } catch (Exception e) { + e.printStackTrace(); + } + return stream; + } +} diff --git a/src/main/java/weaver/chaoyang/he/hcy_hangtiankeji/gmgetdatafromlowgroup/controller/GMGatherOtherSystemInfoController.java b/src/main/java/weaver/chaoyang/he/hcy_hangtiankeji/gmgetdatafromlowgroup/controller/GMGatherOtherSystemInfoController.java index 9915190..421f7c5 100644 --- a/src/main/java/weaver/chaoyang/he/hcy_hangtiankeji/gmgetdatafromlowgroup/controller/GMGatherOtherSystemInfoController.java +++ b/src/main/java/weaver/chaoyang/he/hcy_hangtiankeji/gmgetdatafromlowgroup/controller/GMGatherOtherSystemInfoController.java @@ -1,6 +1,5 @@ package weaver.chaoyang.he.hcy_hangtiankeji.gmgetdatafromlowgroup.controller; - import aiyh.utils.Util; import org.apache.log4j.Logger; import weaver.chaoyang.he.hcy_hangtiankeji.gmgetdatafromlowgroup.service.GMGatherOtherSystemInfoService; @@ -33,6 +32,7 @@ public class GMGatherOtherSystemInfoController extends BaseCronJob { boolean insertDataBool = gmgatherOtherSystemInfoService.insertDataIntoGM(syncStandard,URL,formTableNameGM); if (insertDataBool){ logger.info("GM集团获取GM集团下级单位合同台账信息执行成功!"); + logger.info(""); }else { logger.error("GM集团获取GM集团下级单位合同台账信息执行失败!"); } diff --git a/src/main/java/weaver/chaoyang/he/hcy_hangtiankeji/gmgetdatafromlowgroup/controller/GMGatherSMInfoController.java b/src/main/java/weaver/chaoyang/he/hcy_hangtiankeji/gmgetdatafromlowgroup/controller/GMGatherSMInfoController.java deleted file mode 100644 index 5660339..0000000 --- a/src/main/java/weaver/chaoyang/he/hcy_hangtiankeji/gmgetdatafromlowgroup/controller/GMGatherSMInfoController.java +++ /dev/null @@ -1,15 +0,0 @@ -package weaver.chaoyang.he.hcy_hangtiankeji.gmgetdatafromlowgroup.controller; - -import weaver.interfaces.schedule.BaseCronJob; - -/** - *

GM集团获取商密集团合同台账信息

- * @author hcy - * @date 2023/5/9 18:20 - */ -public class GMGatherSMInfoController extends BaseCronJob { - - public void execute() { - - } -} diff --git a/src/main/java/weaver/chaoyang/he/hcy_hangtiankeji/gmgetdatafromlowgroup/controller/GMGatherSameSystemInfoController.java b/src/main/java/weaver/chaoyang/he/hcy_hangtiankeji/gmgetdatafromlowgroup/controller/GMGatherSameSystemInfoController.java index 14a4ada..0a3490e 100644 --- a/src/main/java/weaver/chaoyang/he/hcy_hangtiankeji/gmgetdatafromlowgroup/controller/GMGatherSameSystemInfoController.java +++ b/src/main/java/weaver/chaoyang/he/hcy_hangtiankeji/gmgetdatafromlowgroup/controller/GMGatherSameSystemInfoController.java @@ -14,10 +14,8 @@ import weaver.interfaces.schedule.BaseCronJob; */ public class GMGatherSameSystemInfoController extends BaseCronJob { - //业务主要逻辑 - private final GMGatherSameSystemInfoService gmgatherSameSystemInfoService = new GMGatherSameSystemInfoServiceImpl(); - + private final GMGatherSameSystemInfoService gmCountLowGroupData = new GMGatherSameSystemInfoServiceImpl(); //日志处理 private final Logger logger = Util.getLogger(); @@ -33,7 +31,43 @@ public class GMGatherSameSystemInfoController extends BaseCronJob { //唯一标识 public String uniqueIdentification; + + public void execute() { - gmgatherSameSystemInfoService.dealMainLogic(configurationMainTableName,configurationDetailTableName1,configurationDetailTableName2,uniqueIdentification); + gmCountLowGroupData.dealMainLogic(configurationMainTableName,configurationDetailTableName1,configurationDetailTableName2,uniqueIdentification);//处理业务主要逻辑 + } + + public String getConfigurationDetailTableName1() { + return configurationDetailTableName1; + } + + public void setConfigurationDetailTableName1(String configurationDetailTableName1) { + this.configurationDetailTableName1 = configurationDetailTableName1; + } + + public String getConfigurationDetailTableName2() { + return configurationDetailTableName2; + } + + public void setConfigurationDetailTableName2(String configurationDetailTableName2) { + this.configurationDetailTableName2 = configurationDetailTableName2; + } + + + + public String getConfigurationMainTableName() { + return configurationMainTableName; + } + + public void setConfigurationMainTableName(String configurationMainTableName) { + this.configurationMainTableName = configurationMainTableName; + } + + public String getUniqueIdentification() { + return uniqueIdentification; + } + + public void setUniqueIdentification(String uniqueIdentification) { + this.uniqueIdentification = uniqueIdentification; } } diff --git a/src/main/java/weaver/chaoyang/he/hcy_hangtiankeji/gmgetdatafromlowgroup/mapper/GMGatherSMInfoMapper.java b/src/main/java/weaver/chaoyang/he/hcy_hangtiankeji/gmgetdatafromlowgroup/mapper/GMGatherSMInfoMapper.java deleted file mode 100644 index 97ace43..0000000 --- a/src/main/java/weaver/chaoyang/he/hcy_hangtiankeji/gmgetdatafromlowgroup/mapper/GMGatherSMInfoMapper.java +++ /dev/null @@ -1,7 +0,0 @@ -package weaver.chaoyang.he.hcy_hangtiankeji.gmgetdatafromlowgroup.mapper; - -import aiyh.utils.annotation.recordset.SqlMapper; - -@SqlMapper -public class GMGatherSMInfoMapper { -} diff --git a/src/main/java/weaver/chaoyang/he/hcy_hangtiankeji/gmgetdatafromlowgroup/mapper/GMGatherSameSystemInfoMapper.java b/src/main/java/weaver/chaoyang/he/hcy_hangtiankeji/gmgetdatafromlowgroup/mapper/GMGatherSameSystemInfoMapper.java index 6655d4a..a470072 100644 --- a/src/main/java/weaver/chaoyang/he/hcy_hangtiankeji/gmgetdatafromlowgroup/mapper/GMGatherSameSystemInfoMapper.java +++ b/src/main/java/weaver/chaoyang/he/hcy_hangtiankeji/gmgetdatafromlowgroup/mapper/GMGatherSameSystemInfoMapper.java @@ -1,5 +1,6 @@ package weaver.chaoyang.he.hcy_hangtiankeji.gmgetdatafromlowgroup.mapper; +import aiyh.utils.annotation.recordset.Delete; import aiyh.utils.annotation.recordset.ParamMapper; import aiyh.utils.annotation.recordset.Select; import aiyh.utils.annotation.recordset.SqlMapper; @@ -9,29 +10,50 @@ import java.util.Map; @SqlMapper public interface GMGatherSameSystemInfoMapper { - - - @Select("select * from #{configurationMainTableName} where wybs = #{uniqueIdentification}") + @Select("select * from $t{configurationMainTableName} where wybs = #{uniqueIdentification}") List> getConfigInformation(@ParamMapper("configurationMainTableName") String configurationMainTableName, @ParamMapper("uniqueIdentification") String uniqueIdentification); - @Select("select * from #{configurationDetailTableName1} where mainid = #{mainid}") + @Select("select * from $t{configurationDetailTableName1} where mainid = #{mainid}") List> getConfigDetal1Information(@ParamMapper("configurationDetailTableName1")String configurationDetailTableName1, @ParamMapper("mainid")String mainid); - @Select("select * from #{configurationDetailTableName2} where mainid = #{mainid}") + @Select("select * from $t{configurationDetailTableName2} where mainid = #{mainid}") List> getConfigDetal2Information(@ParamMapper("configurationDetailTableName2")String configurationDetailTableName2, @ParamMapper("mainid")String mainid); - @Select("select * from #{ejdwtzb_name} where LEFT(modedatacreatedate,7) = LEFT(#{yesterday},7)") + @Select("select * from $t{ejdwtzb_name} where LEFT(modedatacreatedate,7) = LEFT(#{yesterday},7) ") List> getSMCountLowGroupdata(@ParamMapper("ejdwtzb_name")String ejdwtzb_name, @ParamMapper("yesterday")String yesterday); - @Select("select * from #{ejdwtzb_name} where LEFT(modedatacreatedate,7) = LEFT(#{yesterday},7)") + @Select("select * from $t{ejdwtzb_name} where LEFT(modedatamodifydatetime,7) = LEFT(#{yesterday},7)") List> getSMCountLowGroupDataUpdate(@ParamMapper("ejdwtzb_name")String ejdwtzb_name, @ParamMapper("yesterday")String yesterday); - @Select("select * from #{jttzbd} where htbm = #{htbm}") + @Select("select * from $t{jttzbd} where htbm = #{htbm}") List> selectHtbmData(@ParamMapper("jttzbd")String jttzbd, @ParamMapper("htbm")String htbm); + + @Select("select * from $t{ejdwtzb_name}") + List> getSMCountLowGroupTotalData(@ParamMapper("ejdwtzb_name") String ejdwtzb_name); + + @Select("select id from $t{jttzbd} where htbm = #{htbm}") + String selectIdByHtbm(@ParamMapper("jttzbd")String jttzbd, + @ParamMapper("htbm")String htbm); + + + @Delete("delete from $t{s} where mainid = #{id}") + boolean deleteDetalDataByMainId(@ParamMapper("s")String s, + @ParamMapper("id")String id); + + + @Select("select id from $t{ejdwtzb_name} where htbm = #{htbm1}") + String selectDetailTableSouceId(@ParamMapper("ejdwtzb_name")String ejdwtzb_name, + @ParamMapper("htbm1")String htbm1); + + + @Select("select * from $t{s} where mainid = #{ejdw_id}") + List> selectDetailTableSouceData(@ParamMapper("s")String s, + @ParamMapper("ejdw_id")String ejdw_id); + } diff --git a/src/main/java/weaver/chaoyang/he/hcy_hangtiankeji/gmgetdatafromlowgroup/service/GMGatherSMInfoService.java b/src/main/java/weaver/chaoyang/he/hcy_hangtiankeji/gmgetdatafromlowgroup/service/GMGatherSMInfoService.java deleted file mode 100644 index e985245..0000000 --- a/src/main/java/weaver/chaoyang/he/hcy_hangtiankeji/gmgetdatafromlowgroup/service/GMGatherSMInfoService.java +++ /dev/null @@ -1,4 +0,0 @@ -package weaver.chaoyang.he.hcy_hangtiankeji.gmgetdatafromlowgroup.service; - -public interface GMGatherSMInfoService { -} diff --git a/src/main/java/weaver/chaoyang/he/hcy_hangtiankeji/gmgetdatafromlowgroup/service/impl/GMGatherOtherSystemInfoServiceImpl.java b/src/main/java/weaver/chaoyang/he/hcy_hangtiankeji/gmgetdatafromlowgroup/service/impl/GMGatherOtherSystemInfoServiceImpl.java index 09c2301..e27cd4e 100644 --- a/src/main/java/weaver/chaoyang/he/hcy_hangtiankeji/gmgetdatafromlowgroup/service/impl/GMGatherOtherSystemInfoServiceImpl.java +++ b/src/main/java/weaver/chaoyang/he/hcy_hangtiankeji/gmgetdatafromlowgroup/service/impl/GMGatherOtherSystemInfoServiceImpl.java @@ -7,13 +7,17 @@ import aiyh.utils.sqlUtil.builderSql.impl.BuilderSqlImpl; import aiyh.utils.sqlUtil.sqlResult.impl.PrepSqlResultImpl; import aiyh.utils.sqlUtil.whereUtil.impl.PrepWhereImpl; import org.apache.log4j.Logger; +import sun.misc.BASE64Decoder; import weaver.chaoyang.he.hcy_hangtiankeji.gmgetdatafromlowgroup.mapper.GMGatherOtherSystemInfoMapper; import weaver.chaoyang.he.hcy_hangtiankeji.gmgetdatafromlowgroup.service.GMGatherOtherSystemInfoService; import weaver.conn.RecordSet; import weaver.formmode.setup.ModeRightInfo; import weaver.general.TimeUtil; + +import java.io.ByteArrayInputStream; import java.io.IOException; +import java.io.InputStream; import java.util.*; import java.util.stream.Collectors; @@ -37,9 +41,10 @@ public class GMGatherOtherSystemInfoServiceImpl implements GMGatherOtherSystemIn //连接GM下级单位暴露的接口获取台账所有的数据 this.getEntityInsertDB(syncStandard,URL,formTableNameGM); } catch (Exception e) { - e.printStackTrace(); + logger.error("执行数据插入逻辑异常,e:"+e.getMessage()); + return false; } - return false; + return true; } /** @@ -59,18 +64,28 @@ public class GMGatherOtherSystemInfoServiceImpl implements GMGatherOtherSystemIn } Map entityMap = responeVo.getResponseMap(); List> datas = (List>) entityMap.get("data"); + logger.info("从异构系统的台账中获取的一次数据datas==="+datas); if (datas.isEmpty()) return false;//数据为空返回:数据为空 + logger.info("同步标准,syncStandard为:"+syncStandard+"]"); if ("1".equals(syncStandard)) { int failNum = 0;//失败的次数 for (Map totalDataMap : datas) { + String imagefilename = Util.null2String(totalDataMap.get("imagefilename")); //用于存放全部主表数据,排除所有明细表数据 Map newDataMap = new HashMap<>(totalDataMap.entrySet().stream() - .filter(entry -> !("detailData".equals(entry.getKey()) || "id".equals(entry.getKey()))) + .filter(entry -> !("detailData".equals(entry.getKey()) || "id".equals(entry.getKey()) || "imagefilename".equals(entry.getKey()))) .collect(Collectors.toMap( Map.Entry::getKey, Map.Entry::getValue))); String htbm = Util.null2String(totalDataMap.get("htbm")); + logger.info("合同编号,htbm:["+htbm+"]"); + //处理主表中特定字段的逻辑处理 + this.dealwithLcqzyj(newDataMap,imagefilename); + if ("".equals(htbm)){//合同编号不能为空 + continue; + } int countHtbm = gmGatherOtherSystemInfoMapper.selectCountHtbm(formTableNameGM,htbm); + logger.info("合同编号的数量,countHtbm:["+countHtbm+"]"); RecordSet recordSet = new RecordSet(); if (countHtbm == 0){ int mainid = this.createmodedata(formTableNameGM, 1, newDataMap);//先插入数据id,在根据数据id,插入所有明细数据 @@ -95,29 +110,35 @@ public class GMGatherOtherSystemInfoServiceImpl implements GMGatherOtherSystemIn }else { //先删明细数据 String mainid = gmGatherOtherSystemInfoMapper.selectId(formTableNameGM,htbm); + logger.info("mainid=="+mainid); + //先删明细数据 + boolean deleteBool = gmGatherOtherSystemInfoMapper.deleteByMainId(formTableNameGM+"_dt1",Util.null2String(mainid)); + logger.info("deleteBool==="+deleteBool); //开始插入明细表 List> detailData = (List>) totalDataMap.get("detailData"); - for (Map detailDatum : detailData) { - //先删明细数据 - boolean deleteBool = gmGatherOtherSystemInfoMapper.deleteByMainId(formTableNameGM+"_dt1",Util.null2String(mainid)); - if (deleteBool){ - detailDatum.put("mainid",mainid); - insertSql(formTableNameGM,detailDatum);//插入明细表 + logger.info("detailData==="+detailData); + if (deleteBool) { + for (Map detailDatum : detailData) { + logger.info("处理完明细表之前==="+detailDatum); + detailDatum.put("mainid",mainid); + logger.info("处理完明细表之前==="+detailDatum); + insertSql(formTableNameGM,detailDatum);//插入明细表 } } } - } } logger.info("数据更新失败"+failNum+"次"); } else if ("0".equals(syncStandard)){ for (Map totalDataMap : datas) { + String imagefilename = Util.null2String(totalDataMap.get("imagefilename")); //用于存放全部主表数据,排除所有明细表数据 Map newDataMap = new HashMap<>(totalDataMap.entrySet().stream() - .filter(entry -> !("detailData".equals(entry.getKey()) || "id".equals(entry.getKey()))) + .filter(entry -> !("detailData".equals(entry.getKey()) || "id".equals(entry.getKey()) || "imagefilename".equals(entry.getKey()))) .collect(Collectors.toMap( Map.Entry::getKey, Map.Entry::getValue))); + this.dealwithLcqzyj(newDataMap, imagefilename); int createmodedata = createmodedata(formTableNameGM, 1, newDataMap); if (createmodedata>0){ List> detailData = (List>) totalDataMap.get("detailData"); @@ -130,9 +151,10 @@ public class GMGatherOtherSystemInfoServiceImpl implements GMGatherOtherSystemIn } } } catch (Exception e) { - e.printStackTrace(); + logger.error("异常e:"+e.getMessage()); + return false; } - return false; + return true; } /** @@ -180,7 +202,7 @@ public class GMGatherOtherSystemInfoServiceImpl implements GMGatherOtherSystemIn StringBuilder updatesql = new StringBuilder("update " + tablename + " set "); Set keySet = map.keySet(); for (String key : keySet) { - updatesql.append(key).append("='").append(map.get(key).toString()).append("',"); + updatesql.append(key).append("='").append(Util.null2String(map.get(key))).append("',"); } if (updatesql.toString().endsWith(",")) { updatesql = new StringBuilder(updatesql.substring(0, updatesql.length() - 1)); @@ -202,9 +224,9 @@ public class GMGatherOtherSystemInfoServiceImpl implements GMGatherOtherSystemIn } /** - * 获取没一张表的modeid + * 获取每一张表的modeid * @param tablename 表名称 - * @return + * @return modeid */ public Integer getModeidByTableName(String tablename) { RecordSet rs = new RecordSet(); @@ -225,8 +247,57 @@ public class GMGatherOtherSystemInfoServiceImpl implements GMGatherOtherSystemIn PrepSqlResultImpl prepSqlResult = builderSql.insertSql(tableName + "_dt1", datas); RecordSet recordSet1 = new RecordSet(); boolean insertBool = recordSet1.executeUpdate(prepSqlResult.getSqlStr(), prepSqlResult.getArgs()); + logger.info("明细表是否插入成功---insertBool===="+insertBool); if (!insertBool){ logger.error("数据插入失败,失败SQL:["+prepSqlResult+"]"); } } + + /** + * base64转inputStream + * @param base64string 包含输入流的字符串 + * @return inputStream + */ + private static InputStream base2InputStream(String base64string) { + ByteArrayInputStream stream = null; + try { + BASE64Decoder decoder = new BASE64Decoder(); + byte[] bytes1 = decoder.decodeBuffer(base64string); + stream = new ByteArrayInputStream(bytes1); + } catch (Exception e) { + e.printStackTrace(); + } + return stream; + } + + /** + * 处理流程签字意见字段 + * @param newDataMap 一条数据 + * @param imagefilename + */ + public void dealwithLcqzyj(Map newDataMap, String imagefilename){ + String lcqzyj = Util.null2String(newDataMap.get("lcqzyj"));//流程签字意见:需要流程存为文档 + logger.info("文件名称==="+imagefilename); +// logger.info("流程签字意见字段,处理之前==="+lcqzyj); + if (!"".equals(lcqzyj)&&!"-1".equals(lcqzyj)){ + InputStream inputStream = base2InputStream(lcqzyj); + if (inputStream!=null){ + int fileByInputSteam = Util.createFileByInputSteam(inputStream, imagefilename); + logger.info("fileByInputSteam:"+fileByInputSteam); + int docByImageFileId; + try { + String path = Util.getCusConfigValue("pathKey");//配置文档存放路径 + logger.info("文档存放路径,path:["+path+"]"); + docByImageFileId = Util.createDocByImageFileId(Util.getIntValue(path), fileByInputSteam, 1); + if (docByImageFileId>0){ + newDataMap.put("lcqzyj",docByImageFileId); + logger.info("流程签字意见字段,docid存放成功,docid为:["+docByImageFileId+"]"); + } + } catch (Exception e) { + e.printStackTrace(); + logger.error("流程签字一键字段,docid存放失败,失败原因:["+e+"]"); + } + } + } + } } diff --git a/src/main/java/weaver/chaoyang/he/hcy_hangtiankeji/gmgetdatafromlowgroup/service/impl/GMGatherSMInfoServiceImpl.java b/src/main/java/weaver/chaoyang/he/hcy_hangtiankeji/gmgetdatafromlowgroup/service/impl/GMGatherSMInfoServiceImpl.java deleted file mode 100644 index 5c6c05f..0000000 --- a/src/main/java/weaver/chaoyang/he/hcy_hangtiankeji/gmgetdatafromlowgroup/service/impl/GMGatherSMInfoServiceImpl.java +++ /dev/null @@ -1,7 +0,0 @@ -package weaver.chaoyang.he.hcy_hangtiankeji.gmgetdatafromlowgroup.service.impl; - - -import weaver.chaoyang.he.hcy_hangtiankeji.gmgetdatafromlowgroup.service.GMGatherSMInfoService; - -public class GMGatherSMInfoServiceImpl implements GMGatherSMInfoService { -} diff --git a/src/main/java/weaver/chaoyang/he/hcy_hangtiankeji/gmgetdatafromlowgroup/service/impl/GMGatherSameSystemInfoServiceImpl.java b/src/main/java/weaver/chaoyang/he/hcy_hangtiankeji/gmgetdatafromlowgroup/service/impl/GMGatherSameSystemInfoServiceImpl.java index 8511d29..6a24ea5 100644 --- a/src/main/java/weaver/chaoyang/he/hcy_hangtiankeji/gmgetdatafromlowgroup/service/impl/GMGatherSameSystemInfoServiceImpl.java +++ b/src/main/java/weaver/chaoyang/he/hcy_hangtiankeji/gmgetdatafromlowgroup/service/impl/GMGatherSameSystemInfoServiceImpl.java @@ -1,33 +1,32 @@ package weaver.chaoyang.he.hcy_hangtiankeji.gmgetdatafromlowgroup.service.impl; import aiyh.utils.Util; -import com.google.common.base.Joiner; +import aiyh.utils.sqlUtil.builderSql.impl.BuilderSqlImpl; +import aiyh.utils.sqlUtil.sqlResult.impl.PrepSqlResultImpl; +import aiyh.utils.sqlUtil.whereUtil.impl.PrepWhereImpl; import com.weaver.formmodel.util.DateHelper; import org.apache.log4j.Logger; import weaver.chaoyang.he.hcy_hangtiankeji.gmgetdatafromlowgroup.mapper.GMGatherSameSystemInfoMapper; import weaver.chaoyang.he.hcy_hangtiankeji.gmgetdatafromlowgroup.service.GMGatherSameSystemInfoService; import weaver.conn.RecordSet; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; +import weaver.formmode.setup.ModeRightInfo; +import weaver.general.TimeUtil; +import java.util.*; public class GMGatherSameSystemInfoServiceImpl implements GMGatherSameSystemInfoService { - /** - * 日志 - */ - private final Logger logger = Util.getLogger(); - //sql + //处理sql private final GMGatherSameSystemInfoMapper gmGatherSameSystemInfoMapper = Util.getMapper(GMGatherSameSystemInfoMapper.class); - /** - * 处理从国密集团下级单位台账数据库查询数据向国密集团总台账数据库中插入或者更新数据 - * @param configurationMainTableName 配置表主表名称 - * @param configurationDetailTableName1 配置表明细表1名称 - * @param configurationDetailTableName2 配置表明细表2名称 - * @param uniqueIdentification 唯一标识 - */ + + + //构建inser、update 的sql语句 + private final BuilderSqlImpl builderSqlImpl = new BuilderSqlImpl(); + + //日志 + private final Logger logger = Util.getLogger(); + + @Override public void dealMainLogic(String configurationMainTableName, String configurationDetailTableName1, String configurationDetailTableName2, String uniqueIdentification) { //第一步获取配置表中数据 if (configurationMainTableName.equals("") && configurationDetailTableName1.equals("") && uniqueIdentification.equals("")) return; @@ -37,9 +36,9 @@ public class GMGatherSameSystemInfoServiceImpl implements GMGatherSameSystemInfo if (configMainTableData.isEmpty()) return; String jttzbd = Util.null2String(configMainTableData.get(0).get("jttzbd"));//集团台账表单 - String mainid = Util.null2String(configMainTableData.get(0).get("mainid")); + String mainid = Util.null2String(configMainTableData.get(0).get("id")); logger.info("配置表主表数据---mainid---"+mainid); - if (mainid.equals("")) return; + if (mainid.equals("") && "".equals(jttzbd)) return; //配置表明细表1数据:用来统计商密下级单位台账名称 List> configDetal1TableData = gmGatherSameSystemInfoMapper.getConfigDetal1Information(configurationDetailTableName1,mainid); @@ -47,9 +46,15 @@ public class GMGatherSameSystemInfoServiceImpl implements GMGatherSameSystemInfo //明细表2数据 List> configDetal2TableData = gmGatherSameSystemInfoMapper.getConfigDetal2Information(configurationDetailTableName2,mainid); logger.info("配置表明细表数据---configDetal2TableData---"+configDetal2TableData); - List keys = new ArrayList<>();//用于insert和update的key + List mainTablekeys = new ArrayList<>();//用于存放主表中insert和update的key + List detalTablekeys = new ArrayList<>();//用于存放主表中insert和update的key for (Map configdetal2 : configDetal2TableData) { - keys.add(Util.null2String(configdetal2.get("tbzd"))); + String sfzb = Util.null2String(configdetal2.get("sfzb")); + if ("0".equals(sfzb)){ + mainTablekeys.add(Util.null2String(configdetal2.get("tbzd"))); + }else if ("1".equals(sfzb)){ + detalTablekeys.add(Util.null2String(configdetal2.get("tbzd"))); + } } @@ -58,59 +63,94 @@ public class GMGatherSameSystemInfoServiceImpl implements GMGatherSameSystemInfo for (Map config1 : configDetal1TableData) { String ejdwtzb_name = Util.null2String(config1.get("ejdwtzb")); //二级单位台账表数据库名称 String bz = Util.null2String(config1.get("bz")); //备注 - logger.info("二级单位台账表数据库名称===="+ejdwtzb_name+" 二级单位台账表数名称==="+bz); - //获取当天日期的前一天,如果和创建时间吻合,并且满足修改时间为空那么,这条数据就是纯插入的数据 - List> smCountLowGroupDataInsert = gmGatherSameSystemInfoMapper.getSMCountLowGroupdata(ejdwtzb_name, DateHelper.getYesterday()); - logger.info("smCountLowGroupDataInsert===="+smCountLowGroupDataInsert); + String tbzt = Util.null2String(config1.get("tbzt")); + logger.info("二级单位台账表数据库名称===="+ejdwtzb_name+" 二级单位台账表数名称==="+bz+" 同步状态==="+tbzt); - //获取当天日期的前一天,如果和修改时间吻合,那么这条数据就是更新操作的数据 - List> smCountLowGroupDataupdate = gmGatherSameSystemInfoMapper.getSMCountLowGroupDataUpdate(ejdwtzb_name,DateHelper.getYesterday()); - logger.info("smCountLowGroupDataupdate===="+smCountLowGroupDataupdate); + if ("0".equals(tbzt)){ + //查询全量数据 + List> smCountLowGroupTotalData = gmGatherSameSystemInfoMapper.getSMCountLowGroupTotalData(ejdwtzb_name);//第一次同步数据 + logger.info("全量数据---smCountLowGroupTotalData==="+smCountLowGroupTotalData); + if (smCountLowGroupTotalData.size()>0){ + this.insertData(smCountLowGroupTotalData,jttzbd,ejdwtzb_name,mainTablekeys,detalTablekeys,tbzt);//全增量主表数据执行插入 并且包含明细表的删除,和再次添加 + } + }else if ("1".equals(tbzt)){ //非第一次同步数据 + //获取当天日期的前一天,如果和创建时间吻合,并且满足修改时间为空那么,这条数据就是纯插入的数据 + List> smCountLowGroupDataInsert = gmGatherSameSystemInfoMapper.getSMCountLowGroupdata(ejdwtzb_name,DateHelper.getYesterday()); + logger.info("smCountLowGroupDataInsert===="+smCountLowGroupDataInsert); - //数据插入商密集团总台账 - if (smCountLowGroupDataInsert.size()>0){ - this.insertData(smCountLowGroupDataInsert,jttzbd,keys); - } - //数据更新商密集团总台账 - if (smCountLowGroupDataupdate.size()>0){ - this.updateData(smCountLowGroupDataupdate,jttzbd,keys); + //获取当天日期的前一天,如果和修改时间吻合,那么这条数据就是更新操作的数据 + List> smCountLowGroupDataupdate = gmGatherSameSystemInfoMapper.getSMCountLowGroupDataUpdate(ejdwtzb_name,DateHelper.getYesterday()); + logger.info("smCountLowGroupDataupdate===="+smCountLowGroupDataupdate); + + //数据插入商密集团总台账 + if (smCountLowGroupDataInsert.size()>0){ + this.insertData(smCountLowGroupDataInsert,jttzbd,ejdwtzb_name,mainTablekeys,detalTablekeys, tbzt); + } + //数据更新商密集团总台账 + if (smCountLowGroupDataupdate.size()>0){ + this.updateData(smCountLowGroupDataupdate,jttzbd,ejdwtzb_name,mainTablekeys,detalTablekeys); + } } + } } - /** *

插入数据

* @param smCountLowGroupDataInsert 插入数据集合 * @param jttzbd 集团台账数据库名 + * @param ejdwtzb_name 二级单位数据库名 * @param keys 需要insert的字段key + * @param detalTablekeys 需要插入的明细表字段数据库名组成的list + * @param tbzt 同步状态用来判断是第一次同步还是非首次同步 * @author hcy * 2023/5/6 17:41 */ - private void insertData(List> smCountLowGroupDataInsert, String jttzbd,List keys) { + private void insertData(List> smCountLowGroupDataInsert, String jttzbd, String ejdwtzb_name, List keys, List detalTablekeys, String tbzt) { RecordSet recordSet = new RecordSet(); + int successNum = 0; + int failNum = 0; for (Map insertDatas : smCountLowGroupDataInsert) { String htbm = Util.null2String(insertDatas.get("htbm")); List> selectHtbmData = gmGatherSameSystemInfoMapper.selectHtbmData(jttzbd,htbm); if (selectHtbmData.size()==0){ - - String insertKey = Joiner.on(",").join((Iterable) keys);//key - ArrayList valueList = new ArrayList<>(); +// String insertKey = Joiner.on(",").join((Iterable) keys);//key + Map keyValueMap = new HashMap<>(); for (String key : keys) { - String v = Util.null2String(insertDatas.get(key)); - valueList.add(v); +// if("htzje".equals(key) || "htjrrmb".equals(key)){ +// String o = Util.null2String(insertDatas.get(key)); +// if ("".equals(o)){ +// keyValueMap.put(key, null); +// }else { +// keyValueMap.put(key, o); +// } +// }else { +// Object o = insertDatas.get(key); +// keyValueMap.put(key, o); +// } + Object o = insertDatas.get(key); + keyValueMap.put(key, o); } +// PrepSqlResultImpl prepSqlResult = builderSqlImpl.insertSql(jttzbd, keyValueMap); +// boolean insertBool = recordSet.executeUpdate(prepSqlResult.getSqlStr(), prepSqlResult.getArgs()); - String insertValue = Joiner.on(",").join((Iterable) valueList);//value - - String insertSql = "insert into "+jttzbd + "(" +insertKey + ")"+ "value " +"("+insertValue+")";//拼接插入的sql语句 - boolean insertBool = recordSet.executeQuery(insertSql); - if (insertBool){ - logger.info("数据插入成功"); - }else{ - logger.info("数据插入失败"); + int createmodedata = createmodedata(jttzbd, 1, keyValueMap); + if (createmodedata>0){ + String htbm1 = Util.null2String(keyValueMap.get("htbm")); + deleteAndInsertDetailTable(htbm1,jttzbd,ejdwtzb_name,detalTablekeys); } +// if(insertBool){ +// successNum++; +// String htbm1 = Util.null2String(keyValueMap.get("htbm")); +// //执行明细表的数据删除和数据插入 +// deleteAndInsertDetailTable(htbm1,jttzbd,ejdwtzb_name,detalTablekeys); +// }else{ +// failNum++; +// logger.error("台账数据插入失败,失败SQL:["+ prepSqlResult +"----失败次数:"+failNum+"]"); +// } + logger.info("台账数据插入成功 "+successNum+"次"); + } } } @@ -119,44 +159,161 @@ public class GMGatherSameSystemInfoServiceImpl implements GMGatherSameSystemInfo *

更新数据

* @param smCountLowGroupDataupdate 更新语句集合 * @param jttzbd 集团台账数据库名 + * @param ejdwtzb_name 二级单位数据库名 * @param keys 数据更新的key组成的集合 + * @param detalTablekeys 需要插入的明细表字段数据库名组成的list * @author hcy * 2023/5/6 17:40 */ - private void updateData(List> smCountLowGroupDataupdate, String jttzbd, List keys) { + private void updateData(List> smCountLowGroupDataupdate, String jttzbd, String ejdwtzb_name, List keys, List detalTablekeys) { + RecordSet recordSet = new RecordSet(); + int failNum = 0; + int successNum = 0; + for (Map updateDates : smCountLowGroupDataupdate) { + String htbm = Util.null2String(updateDates.get("htbm")); + List> selecthtbmData = gmGatherSameSystemInfoMapper.selectHtbmData(jttzbd, htbm); + if (selecthtbmData.size()>0){ + Map keyValueMap = getKeyValueMap(updateDates, keys); + PrepWhereImpl prepWhere = new PrepWhereImpl(); + prepWhere.whereAnd("htbm = ?"); + prepWhere.addArgs(htbm); + PrepSqlResultImpl prepSqlResult = builderSqlImpl.updateSql(jttzbd, keyValueMap, prepWhere); + boolean insertBool = recordSet.executeUpdate(prepSqlResult.getSqlStr(), prepSqlResult.getArgs()); + if (insertBool){ + String htbm1 = Util.null2String(keyValueMap.get("htbm")); + //执行明细表的数据删除和数据插入 + deleteAndInsertDetailTable(htbm1,jttzbd,ejdwtzb_name,detalTablekeys); + successNum++; + }else { + failNum++; + logger.error("台账数据更新失败,SQL:["+ prepSqlResult +"------失败次数:"+failNum+"]"); + } + logger.info("台账数据更新成功 "+successNum + "次"); + } + } + } + + /** + * 用于封装insert或者update的key,value的map集合 + * @param datas 数据源 + * @param keys 需要更新或者插入的keys + * @return 预期的key,value对应的map集合 + */ + public Map getKeyValueMap(Map datas ,List keys){ + Map keyValueMap = new HashMap<>(); + for (String key : keys) { + String v = Util.null2String(datas.get(key)); + keyValueMap.put(key, v); + } + return keyValueMap; + } + + /** + * 删除并插入明细表中的数据 + * @param htbm1 合同编号用来作为唯一标识 + * @param jttzbd 商密集团台账数据库名称 + * @param ejdwtzb_name 二级单位名称 + * @param detalTablekeys 需要插入的明细表字段数据库名组成的list + */ + public void deleteAndInsertDetailTable(String htbm1,String jttzbd,String ejdwtzb_name,List detalTablekeys){ + try { - - RecordSet recordSet = new RecordSet(); - for (Map updateDates : smCountLowGroupDataupdate) { - String htbm = Util.null2String(updateDates.get("htbm")); - List> updateDatas = gmGatherSameSystemInfoMapper.selectHtbmData(jttzbd, htbm); - if (updateDatas.size()>0){ - //拼接sql - List updateValueList = new ArrayList<>(); - for (String key : keys) { - String value = Util.null2String(updateDates.get(key)); - updateValueList.add(value); + RecordSet insertDatailRS = new RecordSet(); + //执行明细表的插入语句 + String id = gmGatherSameSystemInfoMapper.selectIdByHtbm(jttzbd,htbm1); + int successNum = 0; + int failNum = 0; + if (!"".equals(id)){ + boolean deleteBool = gmGatherSameSystemInfoMapper.deleteDetalDataByMainId(jttzbd+"_dt1",id);//明细表插入数据之前,先执行删除语句 + if (deleteBool){ + //执行明细表插入逻辑 + String ejdw_id = gmGatherSameSystemInfoMapper.selectDetailTableSouceId(ejdwtzb_name,htbm1); + List> souceDetailDatas = gmGatherSameSystemInfoMapper.selectDetailTableSouceData(ejdwtzb_name+"_dt1",ejdw_id); + if (souceDetailDatas.size()==0) return; + for (Map souceDetailData : souceDetailDatas) { + Map dealwithData = new HashMap<>();//根据配置表处理完需要字段后的数据Map + for (String key : detalTablekeys) { + dealwithData.put(key,souceDetailData.get(key)); + } + //将mainid拼进去 + dealwithData.put("mainid",id); + //开始插入明细表数据 + PrepSqlResultImpl prepSqlResult = builderSqlImpl.insertSql(jttzbd+"_dt1", dealwithData); + boolean detailInsertBool = insertDatailRS.executeUpdate(prepSqlResult.getSqlStr(), prepSqlResult.getArgs()); + if (detailInsertBool){ + successNum++; + }else { + failNum++; + logger.error("明细表数据插入失败,SQL:["+prepSqlResult+"------失败次数:"+failNum+"]"); + } + logger.info("明细表数据插入成功数量:"+successNum); } - StringBuilder builder = new StringBuilder(); - Joiner.on(", ").appendTo(builder, keys); - builder.append(" = "); - Joiner.on(", ").appendTo(builder, updateValueList); - - - String updateSql = "update "+jttzbd + "set " + builder + " where htbm = ?"; - boolean updateBool = recordSet.executeQuery(updateSql, htbm); - if (updateBool){ - logger.info("======数据更新成功======"); - }else { - logger.info("======数据更新失败======"); - } } } } catch (Exception e) { e.printStackTrace(); - logger.info("----GMGatherSameSystemInfoServiceImpl----smCountLowGroupDataupdate----异常如下===="+e); + logger.error("报错=="+e); } } + + /** + * 方法描述 : 将数据插入表单建模 + * @param tablename 建模表明 + * @param userid 创建人id + * @param map 数据map + * @return int 返回数据id + */ + public int createmodedata(String tablename, int userid, Map map) { + Integer modeid = getModeidByTableName(tablename); + int dataid = 0; + RecordSet rs = new RecordSet(); + + String uuid = map.containsKey("modeuuid") ? map.get("modeuuid").toString() : UUID.randomUUID().toString(); + boolean flag = rs.execute("insert into " + tablename + + "(modeuuid,modedatacreater,modedatacreatedate,modedatacreatetime,formmodeid) values('" + uuid + "'," + + userid + ",'" + TimeUtil.getCurrentDateString() + "','" + TimeUtil.getOnlyCurrentTimeString() + "'," + + modeid + ")"); + if (flag) { + rs.execute("select id from " + tablename + " where modeuuid='" + uuid + "'"); + rs.next(); + dataid = weaver.general.Util.getIntValue(rs.getString("id")); + + if (dataid > 0) { + // 遍历数据 进行update + String updatesql = "update " + tablename + " set "; + Set keySet = map.keySet(); + for (String key : keySet) { + updatesql += key + "='" + map.get(key).toString() + "',"; + } + if (updatesql.endsWith(",")) { + updatesql = updatesql.substring(0, updatesql.length() - 1); + + updatesql += " where id=" + dataid; + boolean execute = rs.execute(updatesql); + if(!execute){ + logger.info("出错的sql==="+updatesql); + } + } + /* + * 进行权限重构 + */ + ModeRightInfo moderight = new ModeRightInfo(); + moderight.editModeDataShare(userid, modeid, dataid); + } + } + + return dataid; + } + + + public static Integer getModeidByTableName(String tablename) { + RecordSet rs = new RecordSet(); + String sql = "select b.TABLENAME,a.FORMID,a.id modeid from modeinfo a left join workflow_bill b on a.FORMID=b.id where b.TABLENAME= '" + + tablename + "'"; + rs.execute(sql); + rs.next(); + return Math.abs(rs.getInt("modeid")); + } } diff --git a/src/main/java/weaver/chaoyang/he/hcy_hangtiankeji/smcountlowgruop/mapper/SMCountLowGroupDataMapper.java b/src/main/java/weaver/chaoyang/he/hcy_hangtiankeji/smcountlowgruop/mapper/SMCountLowGroupDataMapper.java index 25b67ea..f553333 100644 --- a/src/main/java/weaver/chaoyang/he/hcy_hangtiankeji/smcountlowgruop/mapper/SMCountLowGroupDataMapper.java +++ b/src/main/java/weaver/chaoyang/he/hcy_hangtiankeji/smcountlowgruop/mapper/SMCountLowGroupDataMapper.java @@ -23,11 +23,11 @@ public interface SMCountLowGroupDataMapper { List> getConfigDetal2Information(@ParamMapper("configurationDetailTableName2")String configurationDetailTableName2, @ParamMapper("mainid")String mainid); - @Select("select * from $t{ejdwtzb_name} where LEFT(modedatacreatedate,7) = LEFT(#{yesterday},7) ") + @Select("select * from $t{ejdwtzb_name} where LEFT(modedatacreatedate,10) = LEFT(#{yesterday},10) ") List> getSMCountLowGroupdata(@ParamMapper("ejdwtzb_name")String ejdwtzb_name, @ParamMapper("yesterday")String yesterday); - @Select("select * from $t{ejdwtzb_name} where LEFT(modedatamodifydatetime,7) = LEFT(#{yesterday},7)") + @Select("select * from $t{ejdwtzb_name} where LEFT(modedatamodifydatetime,10) = #{yesterday}") List> getSMCountLowGroupDataUpdate(@ParamMapper("ejdwtzb_name")String ejdwtzb_name, @ParamMapper("yesterday")String yesterday); diff --git a/src/main/java/weaver/chaoyang/he/hcy_hangtiankeji/smcountlowgruop/service/impl/SMCountLowGroupDataServiceImpl.java b/src/main/java/weaver/chaoyang/he/hcy_hangtiankeji/smcountlowgruop/service/impl/SMCountLowGroupDataServiceImpl.java index 728f3d0..946bc9c 100644 --- a/src/main/java/weaver/chaoyang/he/hcy_hangtiankeji/smcountlowgruop/service/impl/SMCountLowGroupDataServiceImpl.java +++ b/src/main/java/weaver/chaoyang/he/hcy_hangtiankeji/smcountlowgruop/service/impl/SMCountLowGroupDataServiceImpl.java @@ -77,16 +77,21 @@ public class SMCountLowGroupDataServiceImpl implements SMCountLowGroupDataServic if ("0".equals(tbzt)){ //查询全量数据 List> smCountLowGroupTotalData = smCountLowGroupDataMapper.getSMCountLowGroupTotalData(ejdwtzb_name);//第一次同步数据 + logger.info("查询到的全量数据,smCountLowGroupTotalData:["+smCountLowGroupTotalData+"]"); if (smCountLowGroupTotalData.size()>0){ this.insertData(smCountLowGroupTotalData,jttzbd,ejdwtzb_name,mainTablekeys,detalTablekeys,tbzt);//全增量主表数据执行插入 并且包含明细表的删除,和再次添加 } }else if ("1".equals(tbzt)){ //非第一次同步数据 //获取当天日期的前一天,如果和创建时间吻合,并且满足修改时间为空那么,这条数据就是纯插入的数据 + String yesterday = DateHelper.getYesterday(); List> smCountLowGroupDataInsert = smCountLowGroupDataMapper.getSMCountLowGroupdata(ejdwtzb_name,DateHelper.getYesterday()); logger.info("smCountLowGroupDataInsert===="+smCountLowGroupDataInsert); //获取当天日期的前一天,如果和修改时间吻合,那么这条数据就是更新操作的数据 + + logger.info("yesterday:"+yesterday); List> smCountLowGroupDataupdate = smCountLowGroupDataMapper.getSMCountLowGroupDataUpdate(ejdwtzb_name,DateHelper.getYesterday()); + logger.info("smCountLowGroupDataupdate===="+smCountLowGroupDataupdate); //数据插入商密集团总台账 @@ -116,47 +121,27 @@ public class SMCountLowGroupDataServiceImpl implements SMCountLowGroupDataServic */ private void insertData(List> smCountLowGroupDataInsert, String jttzbd, String ejdwtzb_name, List keys, List detalTablekeys, String tbzt) { - RecordSet recordSet = new RecordSet(); int successNum = 0; - int failNum = 0; for (Map insertDatas : smCountLowGroupDataInsert) { String htbm = Util.null2String(insertDatas.get("htbm")); + logger.info("htbm:["+htbm+"]"); List> selectHtbmData = smCountLowGroupDataMapper.selectHtbmData(jttzbd,htbm); + logger.info("selectHtbmData:["+selectHtbmData+"]"); if (selectHtbmData.size()==0){ -// String insertKey = Joiner.on(",").join((Iterable) keys);//key Map keyValueMap = new HashMap<>(); for (String key : keys) { -// if("htzje".equals(key) || "htjrrmb".equals(key)){ -// String o = Util.null2String(insertDatas.get(key)); -// if ("".equals(o)){ -// keyValueMap.put(key, null); -// }else { -// keyValueMap.put(key, o); -// } -// }else { -// Object o = insertDatas.get(key); -// keyValueMap.put(key, o); -// } Object o = insertDatas.get(key); keyValueMap.put(key, o); } -// PrepSqlResultImpl prepSqlResult = builderSqlImpl.insertSql(jttzbd, keyValueMap); -// boolean insertBool = recordSet.executeUpdate(prepSqlResult.getSqlStr(), prepSqlResult.getArgs()); - + logger.info("keyValueMap:["+keyValueMap+"]"+"jttzbd:["+jttzbd+"]"); int createmodedata = createmodedata(jttzbd, 1, keyValueMap); + logger.info("createmodedata:["+createmodedata+"]"); if (createmodedata>0){ String htbm1 = Util.null2String(keyValueMap.get("htbm")); + logger.info("htbm1:["+htbm1+"]"); deleteAndInsertDetailTable(htbm1,jttzbd,ejdwtzb_name,detalTablekeys); + successNum++; } -// if(insertBool){ -// successNum++; -// String htbm1 = Util.null2String(keyValueMap.get("htbm")); -// //执行明细表的数据删除和数据插入 -// deleteAndInsertDetailTable(htbm1,jttzbd,ejdwtzb_name,detalTablekeys); -// }else{ -// failNum++; -// logger.error("台账数据插入失败,失败SQL:["+ prepSqlResult +"----失败次数:"+failNum+"]"); -// } logger.info("台账数据插入成功 "+successNum+"次"); } @@ -173,7 +158,6 @@ public class SMCountLowGroupDataServiceImpl implements SMCountLowGroupDataServic * @author hcy * 2023/5/6 17:40 */ - private void updateData(List> smCountLowGroupDataupdate, String jttzbd, String ejdwtzb_name, List keys, List detalTablekeys) { RecordSet recordSet = new RecordSet(); int failNum = 0; @@ -229,15 +213,20 @@ public class SMCountLowGroupDataServiceImpl implements SMCountLowGroupDataServic try { RecordSet insertDatailRS = new RecordSet(); //执行明细表的插入语句 + logger.info("htbm1:["+htbm1+"] jttzbd:["+jttzbd+"] ejdwtzb_name:["+ejdwtzb_name+"] detalTablekeys:["+detalTablekeys+"]"); String id = smCountLowGroupDataMapper.selectIdByHtbm(jttzbd,htbm1); + logger.info("id:["+id+"]"); int successNum = 0; int failNum = 0; if (!"".equals(id)){ boolean deleteBool = smCountLowGroupDataMapper.deleteDetalDataByMainId(jttzbd+"_dt1",id);//明细表插入数据之前,先执行删除语句 + logger.info("是否删除成功deleteBool:["+deleteBool+"]"); if (deleteBool){ //执行明细表插入逻辑 String ejdw_id = smCountLowGroupDataMapper.selectDetailTableSouceId(ejdwtzb_name,htbm1); + logger.info("ejdw_id:["+ejdw_id+"]"); List> souceDetailDatas = smCountLowGroupDataMapper.selectDetailTableSouceData(ejdwtzb_name+"_dt1",ejdw_id); + logger.info("souceDetailDatas:["+souceDetailDatas+"]"); if (souceDetailDatas.size()==0) return; for (Map souceDetailData : souceDetailDatas) { Map dealwithData = new HashMap<>();//根据配置表处理完需要字段后的数据Map @@ -246,9 +235,11 @@ public class SMCountLowGroupDataServiceImpl implements SMCountLowGroupDataServic } //将mainid拼进去 dealwithData.put("mainid",id); + logger.info("dealwithData:["+dealwithData+"]"); //开始插入明细表数据 PrepSqlResultImpl prepSqlResult = builderSqlImpl.insertSql(jttzbd+"_dt1", dealwithData); boolean detailInsertBool = insertDatailRS.executeUpdate(prepSqlResult.getSqlStr(), prepSqlResult.getArgs()); + logger.info("detailInsertBool:["+detailInsertBool+"]"); if (detailInsertBool){ successNum++; }else { @@ -274,45 +265,60 @@ public class SMCountLowGroupDataServiceImpl implements SMCountLowGroupDataServic * @return int 返回数据id */ public int createmodedata(String tablename, int userid, Map map) { - Integer modeid = getModeidByTableName(tablename); - int dataid = 0; - RecordSet rs = new RecordSet(); + try { + Integer modeid = getModeidByTableName(tablename); + logger.info("modeid:["+modeid+"]"); + int dataid = 0; + RecordSet rs = new RecordSet(); + String uuid = map.containsKey("modeuuid") ? map.get("modeuuid").toString() : UUID.randomUUID().toString(); + logger.info("uuid:["+uuid+"]"); + String insertSql = "insert into " + tablename + + "(modeuuid,modedatacreater,modedatacreatedate,modedatacreatetime,formmodeid) values('" + uuid + "'," + + userid + ",'" + TimeUtil.getCurrentDateString() + "','" + TimeUtil.getOnlyCurrentTimeString() + "'," + + modeid + ")"; + logger.info("insertSql:["+insertSql+"]"); + boolean flag = rs.execute(insertSql); + logger.info("flag:["+flag+"]"); + if (flag) { + rs.execute("select id from " + tablename + " where modeuuid='" + uuid + "'"); + rs.next(); + dataid = weaver.general.Util.getIntValue(rs.getString("id")); + logger.info("dataid:["+dataid+"]"); - String uuid = map.containsKey("modeuuid") ? map.get("modeuuid").toString() : UUID.randomUUID().toString(); - boolean flag = rs.execute("insert into " + tablename - + "(modeuuid,modedatacreater,modedatacreatedate,modedatacreatetime,formmodeid) values('" + uuid + "'," - + userid + ",'" + TimeUtil.getCurrentDateString() + "','" + TimeUtil.getOnlyCurrentTimeString() + "'," - + modeid + ")"); - if (flag) { - rs.execute("select id from " + tablename + " where modeuuid='" + uuid + "'"); - rs.next(); - dataid = weaver.general.Util.getIntValue(rs.getString("id")); - - if (dataid > 0) { - // 遍历数据 进行update - String updatesql = "update " + tablename + " set "; - Set keySet = map.keySet(); - for (String key : keySet) { - updatesql += key + "='" + map.get(key).toString() + "',"; - } - if (updatesql.endsWith(",")) { - updatesql = updatesql.substring(0, updatesql.length() - 1); - - updatesql += " where id=" + dataid; - boolean execute = rs.execute(updatesql); - if(!execute){ - logger.info("出错的sql==="+updatesql); + if (dataid > 0) { + // 遍历数据 进行update + String updatesql = "update " + tablename + " set "; + logger.info("updatesql:["+updatesql+"]"); + Set keySet = map.keySet(); + for (String key : keySet) { + updatesql += key + "='" + Util.null2String(map.get(key)) + "',"; } - } - /* - * 进行权限重构 - */ - ModeRightInfo moderight = new ModeRightInfo(); - moderight.editModeDataShare(userid, modeid, dataid); - } - } + logger.info("updatesql:["+updatesql+"]"); + if (updatesql.endsWith(",")) { + updatesql = updatesql.substring(0, updatesql.length() - 1); - return dataid; + updatesql += " where id=" + dataid; + logger.info("updatesql:["+updatesql+"]"); + boolean execute = rs.execute(updatesql); + logger.info("execute:["+execute+"]"); + if(!execute){ + logger.info("出错的sql==="+updatesql); + } + } + /* + * 进行权限重构 + */ + ModeRightInfo moderight = new ModeRightInfo(); + moderight.editModeDataShare(userid, modeid, dataid); + } + } + + return dataid; + } catch (Exception e) { + e.printStackTrace(); + logger.error("更新报错,e:["+e+"]"); + } + return -1; }