feat():sqlserver数据库连接

master
jiyufei 2 months ago
parent 67ed7b35b2
commit ab0d73badd

@ -59,6 +59,7 @@ spring:
statementPrepareAfterLogEnabled: false statementPrepareAfterLogEnabled: false
statementPrepareCallAfterLogEnabled: false statementPrepareCallAfterLogEnabled: false
statementParameterSetLogEnabled: false statementParameterSetLogEnabled: false
validation-query: SELECT 1
datasource: datasource:
master: master:
url: jdbc:mysql://${spring.datasource.host}:${spring.datasource.port}/${spring.datasource.dbname}?useUnicode=true&characterEncoding=utf-8&useSSL=false&allowMultiQueries=true&serverTimezone=UTC url: jdbc:mysql://${spring.datasource.host}:${spring.datasource.port}/${spring.datasource.dbname}?useUnicode=true&characterEncoding=utf-8&useSSL=false&allowMultiQueries=true&serverTimezone=UTC
@ -70,6 +71,11 @@ spring:
username: ${spring.datasource.username} username: ${spring.datasource.username}
password: ${spring.datasource.password} password: ${spring.datasource.password}
driver-class-name: com.mysql.cj.jdbc.Driver driver-class-name: com.mysql.cj.jdbc.Driver
slave_2:
url: jdbc:sqlserver://localhost:1433;DatabaseName=UFDATA_888_2018;trustServerCertificate=true
username: sa
password: '123456'
driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
# ===================== Redis配置 ===================== # ===================== Redis配置 =====================
# redis单机模式 # redis单机模式

@ -32,4 +32,5 @@ public interface YysSupplierInformationService extends IService<YysSupplierInfor
void saveOrUpdate(YysSupplierInformationForm yysSupplierInformationForm,String id, boolean isSave) throws Exception; void saveOrUpdate(YysSupplierInformationForm yysSupplierInformationForm,String id, boolean isSave) throws Exception;
List<Map<String, Object>> test();
} }

@ -1,5 +1,6 @@
package jnpf.service.impl; package jnpf.service.impl;
import com.baomidou.dynamic.datasource.annotation.DS;
import jnpf.entity.*; import jnpf.entity.*;
import jnpf.mapper.YysSupplierInformationMapper; import jnpf.mapper.YysSupplierInformationMapper;
import jnpf.service.*; import jnpf.service.*;
@ -18,6 +19,7 @@ import java.util.regex.Pattern;
import jnpf.model.QueryModel; import jnpf.model.QueryModel;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import jnpf.base.model.ColumnDataModel; import jnpf.base.model.ColumnDataModel;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import jnpf.database.model.superQuery.SuperJsonModel; import jnpf.database.model.superQuery.SuperJsonModel;
@ -46,6 +48,9 @@ public class YysSupplierInformationServiceImpl extends ServiceImpl<YysSupplierIn
@Autowired @Autowired
private UserProvider userProvider; private UserProvider userProvider;
@Autowired
private JdbcTemplate jdbcTemplate;
@Override @Override
public List<YysSupplierInformationEntity> getList(YysSupplierInformationPagination yysSupplierInformationPagination){ public List<YysSupplierInformationEntity> getList(YysSupplierInformationPagination yysSupplierInformationPagination){
return getTypeList(yysSupplierInformationPagination,yysSupplierInformationPagination.getDataType()); return getTypeList(yysSupplierInformationPagination,yysSupplierInformationPagination.getDataType());
@ -284,4 +289,11 @@ public class YysSupplierInformationServiceImpl extends ServiceImpl<YysSupplierIn
this.saveOrUpdate(entity); this.saveOrUpdate(entity);
} }
@Override
@DS("slave_2")
public List<Map<String, Object>> test() {
String sql = "select * from dbo.Vendor";
return jdbcTemplate.queryForList(sql);
}
} }

@ -15,22 +15,27 @@ import jnpf.model.yyssupplierinformation.*;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.validation.Valid; import javax.validation.Valid;
import java.util.*; import java.util.*;
import jnpf.annotation.JnpfField; import jnpf.annotation.JnpfField;
import jnpf.base.vo.PageListVO; import jnpf.base.vo.PageListVO;
import jnpf.base.vo.PaginationVO; import jnpf.base.vo.PaginationVO;
import jnpf.base.vo.DownloadVO; import jnpf.base.vo.DownloadVO;
import jnpf.config.ConfigValueUtil; import jnpf.config.ConfigValueUtil;
import jnpf.base.entity.ProvinceEntity; import jnpf.base.entity.ProvinceEntity;
import java.io.IOException; import java.io.IOException;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import jnpf.engine.entity.FlowTaskEntity; import jnpf.engine.entity.FlowTaskEntity;
import jnpf.exception.WorkFlowException; import jnpf.exception.WorkFlowException;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
/** /**
* yysSupplierInformation * yysSupplierInformation
*
* @ V3.5 * @ V3.5
* @ https://www.jnpfsoft.com * @ https://www.jnpfsoft.com
* @ JNPF * @ JNPF
@ -38,7 +43,7 @@ import org.springframework.transaction.annotation.Transactional;
*/ */
@Slf4j @Slf4j
@RestController @RestController
@Tag(name = "yysSupplierInformation" , description = "example") @Tag(name = "yysSupplierInformation", description = "example")
@RequestMapping("/api/example/YysSupplierInformation") @RequestMapping("/api/example/YysSupplierInformation")
public class YysSupplierInformationController { public class YysSupplierInformationController {
@ -52,27 +57,26 @@ public class YysSupplierInformationController {
private YysSupplierInformationService yysSupplierInformationService; private YysSupplierInformationService yysSupplierInformationService;
/** /**
* *
* *
* @param yysSupplierInformationPagination * @param yysSupplierInformationPagination
* @return * @return
*/ */
@Operation(summary = "获取列表") @Operation(summary = "获取列表")
@PostMapping("/getList") @PostMapping("/getList")
public ActionResult list(@RequestBody YysSupplierInformationPagination yysSupplierInformationPagination)throws IOException{ public ActionResult list(@RequestBody YysSupplierInformationPagination yysSupplierInformationPagination) throws IOException {
List<YysSupplierInformationEntity> list= yysSupplierInformationService.getList(yysSupplierInformationPagination); List<YysSupplierInformationEntity> list = yysSupplierInformationService.getList(yysSupplierInformationPagination);
List<Map<String, Object>> realList=new ArrayList<>(); List<Map<String, Object>> realList = new ArrayList<>();
for (YysSupplierInformationEntity entity : list) { for (YysSupplierInformationEntity entity : list) {
Map<String, Object> yysSupplierInformationMap=JsonUtil.entityToMap(entity); Map<String, Object> yysSupplierInformationMap = JsonUtil.entityToMap(entity);
yysSupplierInformationMap.put("id", yysSupplierInformationMap.get("id")); yysSupplierInformationMap.put("id", yysSupplierInformationMap.get("id"));
//副表数据 //副表数据
//子表数据 //子表数据
realList.add(yysSupplierInformationMap); realList.add(yysSupplierInformationMap);
} }
//数据转换 //数据转换
realList = generaterSwapUtil.swapDataList(realList, YysSupplierInformationConstant.getFormData(), YysSupplierInformationConstant.getColumnData(), yysSupplierInformationPagination.getModuleId(),false); realList = generaterSwapUtil.swapDataList(realList, YysSupplierInformationConstant.getFormData(), YysSupplierInformationConstant.getColumnData(), yysSupplierInformationPagination.getModuleId(), false);
//返回对象 //返回对象
PageListVO vo = new PageListVO(); PageListVO vo = new PageListVO();
@ -81,110 +85,125 @@ public class YysSupplierInformationController {
vo.setPagination(page); vo.setPagination(page);
return ActionResult.success(vo); return ActionResult.success(vo);
} }
/** /**
* *
* *
* @param yysSupplierInformationForm * @param yysSupplierInformationForm
* @return * @return
*/ */
@PostMapping() @PostMapping()
@Operation(summary = "创建") @Operation(summary = "创建")
public ActionResult create(@RequestBody @Valid YysSupplierInformationForm yysSupplierInformationForm) { public ActionResult create(@RequestBody @Valid YysSupplierInformationForm yysSupplierInformationForm) {
String b = yysSupplierInformationService.checkForm(yysSupplierInformationForm,0); String b = yysSupplierInformationService.checkForm(yysSupplierInformationForm, 0);
if (StringUtil.isNotEmpty(b)){ if (StringUtil.isNotEmpty(b)) {
return ActionResult.fail(b ); return ActionResult.fail(b);
} }
try{ try {
yysSupplierInformationService.saveOrUpdate(yysSupplierInformationForm, null ,true); yysSupplierInformationService.saveOrUpdate(yysSupplierInformationForm, null, true);
}catch(Exception e){ } catch (Exception e) {
return ActionResult.fail("新增数据失败"); return ActionResult.fail("新增数据失败");
} }
return ActionResult.success("创建成功"); return ActionResult.success("创建成功");
} }
/** /**
* *
* @param id *
* @param yysSupplierInformationForm * @param id
* @return * @param yysSupplierInformationForm
*/ * @return
*/
@PutMapping("/{id}") @PutMapping("/{id}")
@Operation(summary = "更新") @Operation(summary = "更新")
public ActionResult update(@PathVariable("id") String id,@RequestBody @Valid YysSupplierInformationForm yysSupplierInformationForm, public ActionResult update(@PathVariable("id") String id, @RequestBody @Valid YysSupplierInformationForm yysSupplierInformationForm,
@RequestParam(value = "isImport", required = false) boolean isImport){ @RequestParam(value = "isImport", required = false) boolean isImport) {
yysSupplierInformationForm.setId(id); yysSupplierInformationForm.setId(id);
if (!isImport) { if (!isImport) {
String b = yysSupplierInformationService.checkForm(yysSupplierInformationForm,1); String b = yysSupplierInformationService.checkForm(yysSupplierInformationForm, 1);
if (StringUtil.isNotEmpty(b)){ if (StringUtil.isNotEmpty(b)) {
return ActionResult.fail(b ); return ActionResult.fail(b);
} }
} }
YysSupplierInformationEntity entity= yysSupplierInformationService.getInfo(id); YysSupplierInformationEntity entity = yysSupplierInformationService.getInfo(id);
if(entity!=null){ if (entity != null) {
try{ try {
yysSupplierInformationService.saveOrUpdate(yysSupplierInformationForm,id,false); yysSupplierInformationService.saveOrUpdate(yysSupplierInformationForm, id, false);
}catch(Exception e){ } catch (Exception e) {
return ActionResult.fail("修改数据失败"); return ActionResult.fail("修改数据失败");
} }
return ActionResult.success("更新成功"); return ActionResult.success("更新成功");
}else{ } else {
return ActionResult.fail("更新失败,数据不存在"); return ActionResult.fail("更新失败,数据不存在");
} }
} }
/** /**
* *
* @param id *
* @return * @param id
*/ * @return
*/
@Operation(summary = "删除") @Operation(summary = "删除")
@DeleteMapping("/{id}") @DeleteMapping("/{id}")
@Transactional @Transactional
public ActionResult delete(@PathVariable("id") String id){ public ActionResult delete(@PathVariable("id") String id) {
YysSupplierInformationEntity entity= yysSupplierInformationService.getInfo(id); YysSupplierInformationEntity entity = yysSupplierInformationService.getInfo(id);
if(entity!=null){ if (entity != null) {
//主表数据删除 //主表数据删除
yysSupplierInformationService.delete(entity); yysSupplierInformationService.delete(entity);
} }
return ActionResult.success("删除成功"); return ActionResult.success("删除成功");
} }
/** /**
* () * ()
* 使- * 使-
* @param id *
* @return * @param id
*/ * @return
*/
@Operation(summary = "表单信息(详情页)") @Operation(summary = "表单信息(详情页)")
@GetMapping("/detail/{id}") @GetMapping("/detail/{id}")
public ActionResult detailInfo(@PathVariable("id") String id){ public ActionResult detailInfo(@PathVariable("id") String id) {
YysSupplierInformationEntity entity= yysSupplierInformationService.getInfo(id); YysSupplierInformationEntity entity = yysSupplierInformationService.getInfo(id);
if(entity==null){ if (entity == null) {
return ActionResult.fail("表单数据不存在!"); return ActionResult.fail("表单数据不存在!");
} }
Map<String, Object> yysSupplierInformationMap=JsonUtil.entityToMap(entity); Map<String, Object> yysSupplierInformationMap = JsonUtil.entityToMap(entity);
yysSupplierInformationMap.put("id", yysSupplierInformationMap.get("id")); yysSupplierInformationMap.put("id", yysSupplierInformationMap.get("id"));
//副表数据 //副表数据
//子表数据 //子表数据
yysSupplierInformationMap = generaterSwapUtil.swapDataDetail(yysSupplierInformationMap,YysSupplierInformationConstant.getFormData(),"591239930433244933",false); yysSupplierInformationMap = generaterSwapUtil.swapDataDetail(yysSupplierInformationMap, YysSupplierInformationConstant.getFormData(), "591239930433244933", false);
return ActionResult.success(yysSupplierInformationMap); return ActionResult.success(yysSupplierInformationMap);
} }
/** /**
* () * ()
* 使- * 使-
* @param id *
* @return * @param id
*/ * @return
*/
@Operation(summary = "信息") @Operation(summary = "信息")
@GetMapping("/{id}") @GetMapping("/{id}")
public ActionResult info(@PathVariable("id") String id){ public ActionResult info(@PathVariable("id") String id) {
YysSupplierInformationEntity entity= yysSupplierInformationService.getInfo(id); YysSupplierInformationEntity entity = yysSupplierInformationService.getInfo(id);
if(entity==null){ if (entity == null) {
return ActionResult.fail("表单数据不存在!"); return ActionResult.fail("表单数据不存在!");
} }
Map<String, Object> yysSupplierInformationMap=JsonUtil.entityToMap(entity); Map<String, Object> yysSupplierInformationMap = JsonUtil.entityToMap(entity);
yysSupplierInformationMap.put("id", yysSupplierInformationMap.get("id")); yysSupplierInformationMap.put("id", yysSupplierInformationMap.get("id"));
//副表数据 //副表数据
//子表数据 //子表数据
yysSupplierInformationMap = generaterSwapUtil.swapDataForm(yysSupplierInformationMap,YysSupplierInformationConstant.getFormData(),YysSupplierInformationConstant.TABLEFIELDKEY,YysSupplierInformationConstant.TABLERENAMES); yysSupplierInformationMap = generaterSwapUtil.swapDataForm(yysSupplierInformationMap, YysSupplierInformationConstant.getFormData(), YysSupplierInformationConstant.TABLEFIELDKEY, YysSupplierInformationConstant.TABLERENAMES);
return ActionResult.success(yysSupplierInformationMap); return ActionResult.success(yysSupplierInformationMap);
} }
@Operation(summary = "测试连接sqlserver数据库返回数据")
@GetMapping("/test")
public ActionResult test() {
return ActionResult.success(yysSupplierInformationService.test());
}
} }

Loading…
Cancel
Save