diff --git a/src/main/java/com/api/bokang/xiao/sh_bigdata/service/ReportService.java b/src/main/java/com/api/bokang/xiao/sh_bigdata/service/ReportService.java index 0c1940a..bc47347 100644 --- a/src/main/java/com/api/bokang/xiao/sh_bigdata/service/ReportService.java +++ b/src/main/java/com/api/bokang/xiao/sh_bigdata/service/ReportService.java @@ -47,19 +47,20 @@ public class ReportService { String whereSql = " and (frhsz = 0 or frhsz is null) "; if(!"".equals(beginDate) && !"".equals(endDate)){ whereSql += " and (dlsk1 between #{param.beginDate} and #{param.endDate} )"; - }else { - param.put("today", TimeUtil.getCurrentDateString()); - whereSql += " and dlsk1 >= #{param.today} "; } if(!"".equals(registrationPeople)){ whereSql += " and dyjbr = #{param.registrationPeople} "; } if(!"".equals(flightAndTrain)){ - whereSql += " and hbcc = #{param.flightAndTrain} "; + whereSql += " and hbcc like '%"+flightAndTrain+"%' "; } if(!"".equals(project)){ //whereSql += " and exits (select 1 from uf_zwfwdjjmb_dt1 where mainid = main.id and ysdx = #{param.project}) "; - whereSql += " and exits (select 1 from uf_zwfwdjjmb_dt1 where mainid = main.id and wb like '%$t{param.project}%') "; + whereSql += " and exits (select 1 from uf_zwfwdjjmb_dt1 where mainid = main.id and wb like '%"+project+"%') "; + } + if(("".equals(beginDate) || "".equals(endDate)) && "".equals(registrationPeople) && "".equals(flightAndTrain)){ + param.put("today", TimeUtil.getCurrentDateString()); + whereSql += " and dlsk1 >= #{param.today} "; } whereSql = whereSql.replaceFirst(" and "," where "); return whereSql; diff --git a/src/main/java/com/api/bokang/xiao/zxyh/generate_code/mapper/GenerateMapper.java b/src/main/java/com/api/bokang/xiao/zxyh/generate_code/mapper/GenerateMapper.java index a9873c6..c373571 100644 --- a/src/main/java/com/api/bokang/xiao/zxyh/generate_code/mapper/GenerateMapper.java +++ b/src/main/java/com/api/bokang/xiao/zxyh/generate_code/mapper/GenerateMapper.java @@ -20,7 +20,7 @@ public interface GenerateMapper { * @return 更新结果 */ @Update("update uf_contract_num_log set workflow_info = #{workflowInfo},file_info = #{fileInfo},detail_id = #{detailId}," + - "row_id = #{rowId},contract_name = #{contractName},contract_num = #{contractNum},flow_num = #{flowNum},contract_month = #{contractMonth} where id = #{dataId}") + "row_id = #{rowId},contract_name = #{contractName},contract_num = #{contractNum},flow_num = #{flowNum},contract_month = #{contractMonth},contract_year = #{contractYear} where id = #{dataId}") boolean updateContractLog(Map param); /** @@ -34,8 +34,8 @@ public interface GenerateMapper { *

查询最大的流水号

* @return 最大的流水号 */ - @Select("select max(flow_num) from uf_contract_num_log where contract_month = #{month}") - int getMaxFlowByMonth(@ParamMapper("month")int month); + @Select("select max(flow_num) from uf_contract_num_log where contract_month = #{month} and contract_year = {year}") + int getMaxFlowByMonth(@ParamMapper("month")int month,@ParamMapper("year")int year); /** *

删除编号信息

diff --git a/src/main/java/com/api/bokang/xiao/zxyh/generate_code/service/GenerateContractNoService.java b/src/main/java/com/api/bokang/xiao/zxyh/generate_code/service/GenerateContractNoService.java index fe7953f..9362b95 100644 --- a/src/main/java/com/api/bokang/xiao/zxyh/generate_code/service/GenerateContractNoService.java +++ b/src/main/java/com/api/bokang/xiao/zxyh/generate_code/service/GenerateContractNoService.java @@ -32,8 +32,9 @@ public class GenerateContractNoService { public String generateCode(Map param){ Calendar calendar = Calendar.getInstance(); int month = calendar.get(Calendar.MONTH); + int year = calendar.get(Calendar.YEAR); //int maxFlow = generateMapper.getMaxFlow(); - int maxFlow = generateMapper.getMaxFlowByMonth(month); + int maxFlow = generateMapper.getMaxFlowByMonth(month,year); maxFlow = Math.max(maxFlow,0); maxFlow++; String contractNo = ""; @@ -52,6 +53,7 @@ public class GenerateContractNoService { param.put("contractNum",contractNo); param.put("flowNum",maxFlow); param.put("contractMonth",month); + param.put("contractYear",year); boolean updateFlag = generateMapper.updateContractLog(param); Util.rebuildModeDataShareByAsync(1,TABLE_NAME,dataId); if(updateFlag){ diff --git a/src/main/java/weaver/bokang/xiao/zxyh/depart_sync/entity/Depart.java b/src/main/java/weaver/bokang/xiao/zxyh/depart_sync/entity/Depart.java new file mode 100644 index 0000000..8d9b0e7 --- /dev/null +++ b/src/main/java/weaver/bokang/xiao/zxyh/depart_sync/entity/Depart.java @@ -0,0 +1,52 @@ +package weaver.bokang.xiao.zxyh.depart_sync.entity; + +import lombok.Data; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; + +/** + * Depart 类是表示部门信息的实体类。 + * + * @Author 肖博亢 + * @Date 2023/7/21 11:11 + * @Description 此类用于封装部门信息,用于数据同步。 + **/ +@Data +@XmlRootElement(name = "dept") +@XmlAccessorType(XmlAccessType.FIELD) +public class Depart { + + private int id; + + /** + * 部门名称 + */ + private String deptName; + + /** + * 部门ID + */ + private int deptId; + + /** + * 系统类型 + */ + private String systemType; + + /** + * 系统编码 + */ + private String systemCode; + + /** + * 业务名称 + */ + private String businessName; + + /** + * 业务ID + */ + private String businessId; +} diff --git a/src/main/java/weaver/bokang/xiao/zxyh/depart_sync/entity/DepartVO.java b/src/main/java/weaver/bokang/xiao/zxyh/depart_sync/entity/DepartVO.java new file mode 100644 index 0000000..7c15f07 --- /dev/null +++ b/src/main/java/weaver/bokang/xiao/zxyh/depart_sync/entity/DepartVO.java @@ -0,0 +1,72 @@ +package weaver.bokang.xiao.zxyh.depart_sync.entity; + +import lombok.Data; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElementWrapper; +import javax.xml.bind.annotation.XmlRootElement; +import java.util.List; + +/** + * DepartVO 类是用于传递部门信息的实体类。 + * + * @Author 肖博亢 + * @Date 2023/7/21 11:10 + * @Description 此类用于封装发送部门信息的数据。 + **/ +@Data +@XmlRootElement(name = "root") +@XmlAccessorType(XmlAccessType.FIELD) +public class DepartVO { + /** + * 发送者名称 + */ + private String sender; + + /** + * 接收者名称 + */ + private String receiver; + + /** + * 传输数据 + */ + private String trans; + + /** + * 交易流水号 + */ + private String serials; + + /** + * 返回代码 + */ + private String retCode; + + /** + * 返回信息 + */ + private String retmsg; + + /** + * 是否成功 + */ + private boolean success; + + /** + * 消息 + */ + private String message; + + /** + * 代码 + */ + private int code; + + /** + * 部门列表 + */ + @XmlElementWrapper(name = "deptList") + private List dept; +} diff --git a/src/main/java/weaver/bokang/xiao/zxyh/depart_sync/entity/SendDTO.java b/src/main/java/weaver/bokang/xiao/zxyh/depart_sync/entity/SendDTO.java new file mode 100644 index 0000000..9c76163 --- /dev/null +++ b/src/main/java/weaver/bokang/xiao/zxyh/depart_sync/entity/SendDTO.java @@ -0,0 +1,56 @@ +package weaver.bokang.xiao.zxyh.depart_sync.entity; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; + +/** + * SendDTO 类是用于传递数据的实体类。 + * + * @Author 肖博亢 + * @Date 2023/7/21 11:10 + * @Description 此类用于封装发送数据的信息。 + **/ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@XmlRootElement(name = "root") +@XmlAccessorType(XmlAccessType.FIELD) +public class SendDTO { + + /** + * 发送者名称 + */ + private String sender; + + /** + * 接收者名称 + */ + private String receiver; + + /** + * 传输数据 + */ + private String trans; + + /** + * 交易流水号 + */ + private String serials; + + /** + * 系统编码 + */ + private String systemCode; + + /** + * 发送类型 + */ + private String sendType; +} diff --git a/src/main/java/weaver/bokang/xiao/zxyh/depart_sync/mapper/SyncMapper.java b/src/main/java/weaver/bokang/xiao/zxyh/depart_sync/mapper/SyncMapper.java new file mode 100644 index 0000000..22da669 --- /dev/null +++ b/src/main/java/weaver/bokang/xiao/zxyh/depart_sync/mapper/SyncMapper.java @@ -0,0 +1,25 @@ +package weaver.bokang.xiao.zxyh.depart_sync.mapper; + +import aiyh.utils.annotation.recordset.*; +import weaver.bokang.xiao.zxyh.depart_sync.entity.Depart; + +import java.util.List; + +/** + * @ClassName SyncMapper + * @Author 肖博亢 + * @Date 2023/7/21 11:09 + * @Description

+ **/ +@SqlMapper +public interface SyncMapper { + + @Select("select * from uf_depart_info") + List queryDepartList(); + + @BatchUpdate("update uf_depart_info set dept_name = #{item.deptName}, dept_id = #{item.deptId}, system_type = #{item.systemType}, system_code = #{item.systemCode}, " + + " business_name= #{item.businessName}, business_id = #{item.businessId} " + + "where id = #{item.id}") + boolean updateDepart(@BatchSqlArgs List departList); + +} diff --git a/src/main/java/weaver/bokang/xiao/zxyh/depart_sync/schedule/DepartSyncSchedule.java b/src/main/java/weaver/bokang/xiao/zxyh/depart_sync/schedule/DepartSyncSchedule.java new file mode 100644 index 0000000..92c2ff9 --- /dev/null +++ b/src/main/java/weaver/bokang/xiao/zxyh/depart_sync/schedule/DepartSyncSchedule.java @@ -0,0 +1,110 @@ +package weaver.bokang.xiao.zxyh.depart_sync.schedule; + +import aiyh.utils.Util; +import aiyh.utils.action.CusBaseCronJob; +import aiyh.utils.annotation.ActionDesc; +import aiyh.utils.annotation.PrintParamMark; +import aiyh.utils.annotation.RequiredMark; +import com.alibaba.fastjson.JSON; +import lombok.Setter; +import weaver.bokang.xiao.zxyh.depart_sync.entity.Depart; +import weaver.bokang.xiao.zxyh.depart_sync.entity.DepartVO; +import weaver.bokang.xiao.zxyh.depart_sync.entity.SendDTO; +import weaver.bokang.xiao.zxyh.depart_sync.mapper.SyncMapper; +import weaver.general.TimeUtil; +import weaver.xiao.commons.utils.RequestUtil; +import weaver.xiao.commons.utils.VerifyUtil; + +import java.io.IOException; +import java.util.*; +import java.util.stream.Collectors; + +/** + * @ClassName DepartSyncSchedule + * @Author 肖博亢 + * @Date 2023/7/21 11:07 + * @Description

+ **/ +@Setter +@ActionDesc(value = "同步总行部门信息", author = "bokang.xiao") +public class DepartSyncSchedule extends CusBaseCronJob { + + @RequiredMark("发送请求地址") + @PrintParamMark + private String sendUrl; + + @RequiredMark("部门模块ID") + @PrintParamMark + private String departModeId; + + @RequiredMark("发送者名称") + @PrintParamMark + private String sender; + + @RequiredMark("接收者名称") + @PrintParamMark + private String receiver; + + @RequiredMark("传输数据") + @PrintParamMark + private String trans; + + @RequiredMark("系统编码") + @PrintParamMark + private String systemCode; + + @RequiredMark("发送类型") + @PrintParamMark + private String sendType; + + private final SyncMapper syncMapper = Util.getMapper(SyncMapper.class); + + @Override + public void runCode() throws IOException { + try { + List sourceDepartList = syncMapper.queryDepartList(); + Map departMap = new HashMap<>(); + if(Objects.nonNull(sourceDepartList) && !sourceDepartList.isEmpty()) { + departMap = sourceDepartList.stream().collect(Collectors.toMap(Depart::getDeptId, Depart::getId)); + } + log.info("sync depart departMap ==>"+JSON.toJSONString(departMap)); + SendDTO sendDTO = SendDTO.builder() + .sendType(this.sendType) + .sender(this.sender) + .receiver(this.receiver) + .trans(this.trans) + .systemCode(this.systemCode) + .serials(this.sender + TimeUtil.getFormartString(new Date(),"yyyyMMddHHmmSSsss")).build(); + log.info("sendDTO =>"+sendDTO); + String sendXml = VerifyUtil.beanToXml(sendDTO); + log.info("depart req param ==>"+sendXml); + String resultXml = RequestUtil.sendToTPCG2(sendXml, sendUrl); + if (!"".equals(resultXml)) { + DepartVO departVO = VerifyUtil.xmlStrToObject(DepartVO.class, resultXml); + log.info("depart List ==>"+ JSON.toJSONString(departVO)); + if(!departVO.isSuccess()){ + log.error("请求不成功"); + return; + } + List departList = departVO.getDept(); + if(Objects.nonNull(departList) && !departList.isEmpty()){ + List dataIdList = new ArrayList<>(); + for (Depart depart : departList) { + if(departMap.containsKey(depart.getDeptId())){ + depart.setId(departMap.get(depart.getDeptId())); + }else { + int dataId = Util.getModeDataId("uf_depart_info", Util.getIntValue(departModeId), 1); + depart.setId(dataId); + dataIdList.add(dataId); + } + } + syncMapper.updateDepart(departList); + Util.rebuildModeDataShareByAsyncList(1,Util.getIntValue(departModeId),dataIdList); + } + } + }catch (Exception e){ + log.error("同步发生异常 ==>"+ Util.getErrString(e)); + } + } + +} diff --git a/src/main/java/weaver/xiao/commons/utils/RequestUtil.java b/src/main/java/weaver/xiao/commons/utils/RequestUtil.java index c31a037..5eb60a3 100644 --- a/src/main/java/weaver/xiao/commons/utils/RequestUtil.java +++ b/src/main/java/weaver/xiao/commons/utils/RequestUtil.java @@ -2,6 +2,7 @@ package weaver.xiao.commons.utils; import com.alibaba.fastjson.JSON; import com.fasterxml.jackson.databind.ObjectMapper; +import org.apache.commons.io.IOUtils; import org.apache.http.HttpEntity; import org.apache.http.client.methods.*; import org.apache.http.entity.ContentType; @@ -13,12 +14,13 @@ import org.apache.http.util.EntityUtils; import weaver.wechat.request.HttpManager; import weaver.xiao.commons.exception.RequestException; import weaver.zwl.common.ToolUtil; +import weaver.zwl.common.logging.Logger; +import weaver.zwl.common.logging.LoggerFactory; import javax.ws.rs.core.MediaType; -import java.io.IOException; -import java.io.InputStream; -import java.io.PrintWriter; -import java.io.StringWriter; +import java.io.*; +import java.net.URL; +import java.net.URLConnection; import java.nio.charset.StandardCharsets; import java.util.Map; @@ -30,6 +32,8 @@ import java.util.Map; public class RequestUtil { + private static final Logger logger = LoggerFactory.getLogger(); + public static T apiRequest(RequestBaseInfo requestInfo, Class tClass){ Map headers = requestInfo.getHeaders(); @@ -135,6 +139,50 @@ public class RequestUtil { return res; } + public static String sendToTPCG2(String xml, String URL) { + byte[] data = xml.getBytes(); + InputStream instr = null; + String res = ""; + try { + logger.info("--- 开始调用外联平台接口 url => " + URL + " ---"); + java.net.URL url = new URL(URL); + URLConnection urlCon = url.openConnection(); + int time = 180000; + urlCon.setConnectTimeout(time); + urlCon.setReadTimeout(time); + urlCon.setDoOutput(true); + urlCon.setDoInput(true); + urlCon.setUseCaches(false); + urlCon.setRequestProperty("content-Type", "application/xml"); + urlCon.setRequestProperty("charset", "utf-8"); + DataOutputStream printout = new DataOutputStream( + urlCon.getOutputStream()); + printout.write(data); + printout.flush(); + printout.close(); + instr = urlCon.getInputStream(); + byte[] bis = IOUtils.toByteArray(instr); + res = new String(bis, StandardCharsets.UTF_8); + if ("".equals(res.trim())) { + throw new RuntimeException("调用 " +URL + " 接口响应为空!"); + } + logger.info("外联平台返回信息 => " + res); + return res; + } catch (IOException e) { + logger.info("异常[" + e.getMessage() + "]"); + throw new RuntimeException(e.getMessage()); + } finally { + try { + if (instr != null) { + instr.close(); + } + } catch (IOException e) { + throw new RuntimeException(e.getMessage()); + } + } + } + + public static String serializableUrl(String url,Map params){ if(params == null || params.isEmpty()){ return url; diff --git a/src/main/java/weaver/xiao/commons/utils/VerifyUtil.java b/src/main/java/weaver/xiao/commons/utils/VerifyUtil.java index b727a0a..6cc9499 100644 --- a/src/main/java/weaver/xiao/commons/utils/VerifyUtil.java +++ b/src/main/java/weaver/xiao/commons/utils/VerifyUtil.java @@ -130,6 +130,27 @@ public class VerifyUtil { return xmlStr; } + public static String beanToXml(T t){ + String xmlStr = ""; + try { + //1、创建上下文 + JAXBContext context = JAXBContext.newInstance(t.getClass()); + StringWriter writer = new StringWriter(); + //2、创建Marshaller 这个是用于转换成xml的 + Marshaller marshaller = context.createMarshaller(); + //3、设置marshaller的属性 + //JAXB_FORMATTED_OUTPUT:格式化 + //JAXB_ENCODING:编码格式 +// marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); + //4、将实体类读取到writer中 + marshaller.marshal(t, writer); + xmlStr = writer.toString(); + }catch (Exception e){ + logger.info("java bean 转换 xml异常 ==>"+LogUtil.getExceptionStr(e)); + } + return xmlStr; + } + public static String mapToXml(Map map) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append("").append("\n").append("").append("\n"); diff --git a/src/test/java/bokang/xiao/NormalTest.java b/src/test/java/bokang/xiao/NormalTest.java index 9364a92..b276337 100644 --- a/src/test/java/bokang/xiao/NormalTest.java +++ b/src/test/java/bokang/xiao/NormalTest.java @@ -56,6 +56,7 @@ import weaver.bokang.xiao.zscq.action.StatusChangeAction; import weaver.bokang.xiao.zscq.config.service.ModeChangeService; import weaver.bokang.xiao.zscq.store.TableNameStore; import weaver.bokang.xiao.zxyh.RepeatSubmitAction; +import weaver.bokang.xiao.zxyh.depart_sync.schedule.DepartSyncSchedule; import weaver.conn.RecordSet; import weaver.general.StaticObj; import weaver.hrm.User; @@ -85,7 +86,7 @@ public class NormalTest extends BaseTest { @Test public void testWord(){ - GenerateFileUtil.createCronJobDocument(SyncTeachDataSchedule.class); + GenerateFileUtil.createCronJobDocument(DepartSyncSchedule.class); //GenerateFileUtil.createActionDocument(DataPushAction.class); //GenerateFileUtil.createActionDocument(DateFieldUpdateAction.class); }