diff --git a/api-admin/src/main/java/com/glxp/udidl/admin/config/AuthAspect.java b/api-admin/src/main/java/com/glxp/udidl/admin/config/AuthAspect.java new file mode 100644 index 0000000..0e4b271 --- /dev/null +++ b/api-admin/src/main/java/com/glxp/udidl/admin/config/AuthAspect.java @@ -0,0 +1,52 @@ +package com.glxp.udidl.admin.config; + +import com.glxp.udidl.admin.annotation.AuthRuleAnnotation; +import com.glxp.udidl.admin.dao.sys.SysUserMapper; +import com.glxp.udidl.admin.exception.JsonException; +import org.aspectj.lang.JoinPoint; +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.Before; +import org.aspectj.lang.annotation.Pointcut; +import org.aspectj.lang.reflect.MethodSignature; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; + +import javax.servlet.http.HttpServletRequest; +import java.lang.reflect.Method; + +@Aspect +@Component +public class AuthAspect { + @Autowired + private SysUserMapper sysUserMapper; + @Autowired + private GlobalConfig globalConfig; + @Pointcut("@annotation(com.glxp.udidl.admin.annotation.AuthRuleAnnotation)") + private void authMethod() { + } + + @Before(value = "authMethod()") + public void before(JoinPoint joinPoint) { + if(globalConfig.isOpenAuth() == false) + return; + ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); + + if (attributes == null) { + throw new JsonException(-1, "attributes = null"); + } + HttpServletRequest request = attributes.getRequest(); + + String key = request.getHeader("key"); + if (key == null || key == "") + throw new JsonException(401, "key不能为空"); + MethodSignature signature = (MethodSignature) joinPoint.getSignature(); + Method method = signature.getMethod(); + AuthRuleAnnotation action = method.getAnnotation(AuthRuleAnnotation.class); + String perms = action.value(); + Integer res = sysUserMapper.hasAuthPerms(key,perms); + if(res == 0) + throw new JsonException(402, "无权限!"); + } +} diff --git a/api-admin/src/main/java/com/glxp/udidl/admin/config/GlobalConfig.java b/api-admin/src/main/java/com/glxp/udidl/admin/config/GlobalConfig.java index 7ea7eb2..9d5af5d 100644 --- a/api-admin/src/main/java/com/glxp/udidl/admin/config/GlobalConfig.java +++ b/api-admin/src/main/java/com/glxp/udidl/admin/config/GlobalConfig.java @@ -9,4 +9,6 @@ import org.springframework.stereotype.Component; public class GlobalConfig { @Value("${config.downloadPath}") private String downloadPath; + @Value("${config.openAuth}") + private boolean openAuth; } diff --git a/api-admin/src/main/java/com/glxp/udidl/admin/controller/device/ContactController.java b/api-admin/src/main/java/com/glxp/udidl/admin/controller/device/ContactController.java index 3d7c7aa..dc58b1d 100644 --- a/api-admin/src/main/java/com/glxp/udidl/admin/controller/device/ContactController.java +++ b/api-admin/src/main/java/com/glxp/udidl/admin/controller/device/ContactController.java @@ -1,11 +1,12 @@ package com.glxp.udidl.admin.controller.device; +import com.glxp.udidl.admin.annotation.AuthRuleAnnotation; import com.glxp.udidl.admin.entity.udid.Contactlist; import com.glxp.udidl.admin.entity.udid.Device; import com.glxp.udidl.admin.req.DlConnactRequest; import com.glxp.udidl.admin.res.DLConnactResponse; -import com.glxp.udidl.admin.service.inout.DlConnactService; import com.glxp.udidl.admin.service.inout.DeviceService; +import com.glxp.udidl.admin.service.inout.DlConnactService; import com.glxp.udidl.common.enums.ResultEnum; import com.glxp.udidl.common.res.BaseResponse; import com.glxp.udidl.common.util.ResultVOUtils; @@ -28,6 +29,7 @@ public class ContactController { @Resource private DeviceService deviceService; + @AuthRuleAnnotation("udidl_contact_all") @GetMapping("udidl/device/dlconnact") public BaseResponse dlconnacts(@Valid DlConnactRequest dlConnactRequest, BindingResult bindingResult) { if (bindingResult.hasErrors()) { diff --git a/api-admin/src/main/java/com/glxp/udidl/admin/controller/device/DeviceController.java b/api-admin/src/main/java/com/glxp/udidl/admin/controller/device/DeviceController.java index cbc04f2..b45fdfd 100644 --- a/api-admin/src/main/java/com/glxp/udidl/admin/controller/device/DeviceController.java +++ b/api-admin/src/main/java/com/glxp/udidl/admin/controller/device/DeviceController.java @@ -1,6 +1,7 @@ package com.glxp.udidl.admin.controller.device; import com.github.pagehelper.PageInfo; +import com.glxp.udidl.admin.annotation.AuthRuleAnnotation; import com.glxp.udidl.admin.dao.udid.DevicedownloadMapper; import com.glxp.udidl.admin.entity.udid.*; import com.glxp.udidl.admin.req.udid.*; @@ -44,7 +45,7 @@ public class DeviceController { @Resource UdiCompanyService udiCompanyService; - + @AuthRuleAnnotation("udidl_device_all") @GetMapping("warehouse/device/list") public BaseResponse listDevices(@Valid DeviceListRequest deviceListRequest, BindingResult bindingResult) { diff --git a/api-admin/src/main/java/com/glxp/udidl/admin/controller/device/FileInfoController.java b/api-admin/src/main/java/com/glxp/udidl/admin/controller/device/FileInfoController.java index dd02cf6..adc0fa9 100644 --- a/api-admin/src/main/java/com/glxp/udidl/admin/controller/device/FileInfoController.java +++ b/api-admin/src/main/java/com/glxp/udidl/admin/controller/device/FileInfoController.java @@ -1,5 +1,6 @@ package com.glxp.udidl.admin.controller.device; +import com.glxp.udidl.admin.annotation.AuthRuleAnnotation; import com.glxp.udidl.admin.req.ListPageRequest; import com.glxp.udidl.admin.service.DataSync.ProductInfoDlService; import com.glxp.udidl.admin.service.info.FileInfoService; @@ -20,12 +21,12 @@ public class FileInfoController { FileInfoService fileInfoService; @Autowired ProductInfoDlService productInfoDlService; - + @AuthRuleAnnotation("udidl_fileInfo_all") @PostMapping("/getlist") public BaseResponse getList(@RequestBody ListPageRequest param) { return fileInfoService.getList(param); } - + @AuthRuleAnnotation("udidl_fileInfo_all") @PostMapping("/exportToFile") public BaseResponse exportToFile(@DateTimeFormat(pattern = "yyyy-MM-dd") Date startDate, @DateTimeFormat(pattern = "yyyy-MM-dd") Date endDate) { return productInfoDlService.ExportToFile(startDate, endDate, "manual"); diff --git a/api-admin/src/main/java/com/glxp/udidl/admin/controller/device/PosTaggerController.java b/api-admin/src/main/java/com/glxp/udidl/admin/controller/device/PosTaggerController.java index 17cf3f0..27fb6eb 100644 --- a/api-admin/src/main/java/com/glxp/udidl/admin/controller/device/PosTaggerController.java +++ b/api-admin/src/main/java/com/glxp/udidl/admin/controller/device/PosTaggerController.java @@ -1,6 +1,7 @@ package com.glxp.udidl.admin.controller.device; import com.github.pagehelper.PageInfo; +import com.glxp.udidl.admin.annotation.AuthRuleAnnotation; import com.glxp.udidl.admin.entity.udi.ProductInfoEntity; import com.glxp.udidl.admin.req.ProductInfoFilterRequest; import com.glxp.udidl.admin.res.PageSimpleResponse; @@ -32,7 +33,7 @@ public class PosTaggerController { UdiCompanyService udiCompanyService; @Resource ProductInfoService productInfoService; - + @AuthRuleAnnotation("udidl_posTagger_all") @GetMapping("udi/company/findByCreditNo") public BaseResponse findByCreditNo(ProductInfoFilterRequest productInfoFilterRequest, BindingResult bindingResult) { if (bindingResult.hasErrors()) { @@ -50,7 +51,7 @@ public class PosTaggerController { pageSimpleResponse.setList(productInfoEntities); return ResultVOUtils.success(pageSimpleResponse); } - + @AuthRuleAnnotation("udidl_posTagger_all") @GetMapping("udi/company/findCoName") public BaseResponse findCoName(ProductInfoFilterRequest productInfoFilterRequest, BindingResult bindingResult) { if (bindingResult.hasErrors()) { @@ -74,7 +75,7 @@ public class PosTaggerController { pageSimpleResponse.setList(names); return ResultVOUtils.success(pageSimpleResponse); } - + @AuthRuleAnnotation("udidl_posTagger_all") @GetMapping("udi/company/findTreeData") public BaseResponse findTreeData(ProductInfoFilterRequest productInfoFilterRequest, BindingResult bindingResult) { if (bindingResult.hasErrors()) { @@ -96,7 +97,6 @@ public class PosTaggerController { return ResultVOUtils.success(pageSimpleResponse); } - public List transferTreeData(List productInfoEntities) { List posTaggerResponses = new ArrayList<>(); @@ -218,7 +218,7 @@ public class PosTaggerController { return tops; } - + @AuthRuleAnnotation("udidl_posTagger_all") @GetMapping("udi/company/findByUuid") public BaseResponse findByDi(ProductInfoFilterRequest productInfoFilterRequest, BindingResult bindingResult) { if (bindingResult.hasErrors()) { diff --git a/api-admin/src/main/java/com/glxp/udidl/admin/controller/device/ProductInfoController.java b/api-admin/src/main/java/com/glxp/udidl/admin/controller/device/ProductInfoController.java index cdfe622..8ba85af 100644 --- a/api-admin/src/main/java/com/glxp/udidl/admin/controller/device/ProductInfoController.java +++ b/api-admin/src/main/java/com/glxp/udidl/admin/controller/device/ProductInfoController.java @@ -31,7 +31,7 @@ public class ProductInfoController { //手持枪扫码查询 - @AuthRuleAnnotation("udidl_ProductInfo_findProductInfo") + @AuthRuleAnnotation("udidl_productInfo_all") @GetMapping("udidl/device/findBydi") public BaseResponse findProductInfo(ProductInfoFilterRequest productInfoFilterRequest) { @@ -66,6 +66,7 @@ public class ProductInfoController { } //管理平台扫码查询 + @AuthRuleAnnotation("udidl_productInfo_all") @GetMapping("udidl/wms/findBydi") public BaseResponse findBydiWms(ProductInfoFilterRequest productInfoFilterRequest) { @@ -113,6 +114,7 @@ public class ProductInfoController { } //出入库同步下载 + @AuthRuleAnnotation("udidl_productInfo_all") @GetMapping("udidl/udiwms/syncUdi") public BaseResponse syncUdi(ProductInfoFilterRequest productInfoFilterRequest) { @@ -123,6 +125,7 @@ public class ProductInfoController { //开放查询 查询只查询主DI, + @AuthRuleAnnotation("udidl_productInfo_all") @GetMapping("udidl/device/filterUdi") public BaseResponse filterUdi(ProductInfoFilterRequest productInfoFilterRequest) { @@ -177,6 +180,7 @@ public class ProductInfoController { //开放查询 查询全部,不会过滤只显示主 + @AuthRuleAnnotation("udidl_productInfo_all") @GetMapping("udidl/device/filterAllUdi") public BaseResponse filterAllUdi(ProductInfoFilterRequest productInfoFilterRequest) { @@ -230,12 +234,14 @@ public class ProductInfoController { @GetMapping("udidl/device/filterByUuid") + @AuthRuleAnnotation("udidl_productInfo_all") public BaseResponse filterByUuid(ProductInfoFilterRequest productInfoFilterRequest) { List productInfoEntityList = productInfoService.findAll(productInfoFilterRequest); return ResultVOUtils.success(productInfoEntityList); } @GetMapping("udidl/device/filterByNameCode") + @AuthRuleAnnotation("udidl_productInfo_all") public BaseResponse filterByNameCode(ProductInfoFilterRequest productInfoFilterRequest) { List productInfoEntityList = productInfoService.findAll(productInfoFilterRequest); Map> listMap = productInfoEntityList.stream().collect(Collectors.groupingBy(ProductInfoEntity::getUuid)); diff --git a/api-admin/src/main/java/com/glxp/udidl/admin/controller/device/TestController.java b/api-admin/src/main/java/com/glxp/udidl/admin/controller/device/TestController.java index 1b9f1ff..745d285 100644 --- a/api-admin/src/main/java/com/glxp/udidl/admin/controller/device/TestController.java +++ b/api-admin/src/main/java/com/glxp/udidl/admin/controller/device/TestController.java @@ -14,14 +14,11 @@ import com.glxp.udidl.common.util.ResultVOUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.format.annotation.DateTimeFormat; import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; -import java.util.Date; import java.util.List; @RestController @@ -99,38 +96,7 @@ public class TestController { asyncDownloadTask.downloadByMonth(month, page); } - @GetMapping("udidl/device/dlByDay") - public String dlByDay(String day) { - logger.info(day + "---按天开启下载"); - asyncDownloadTask.downloadByDay(day); - return "ok"; - } - @GetMapping("udidl/device/dlByDays") - public BaseResponse dlByDays(@DateTimeFormat(pattern = "yyyy-MM-dd") Date startDate, @DateTimeFormat(pattern = "yyyy-MM-dd") Date endDate) { - logger.info("---按日期段下载"); - //logger.info(startDate.toString()); - //logger.info(endDate.toString()); - return deviceSyncService.downloadUdi(startDate, endDate); - } - @PostMapping("udidl/device/dlByDi") - public BaseResponse downloadByDi(String deviceId) { - return deviceSyncService.downloadByDi(deviceId); - } - /** - * 获取产品标识详情 - * - * @param deviceId - * @return - */ - @PostMapping("udidl/device/downloadSingle") - public BaseResponse downloadSingle(String deviceId) { - return deviceSyncService.downloadSingle(deviceId); - } - @PostMapping("udidl/device/downloadHistory") - public BaseResponse downloadHistory(String key) { - return deviceSyncService.downloadHistory(key); - } } diff --git a/api-admin/src/main/java/com/glxp/udidl/admin/controller/device/UdiCompanyController.java b/api-admin/src/main/java/com/glxp/udidl/admin/controller/device/UdiCompanyController.java index 7c55a02..69808bc 100644 --- a/api-admin/src/main/java/com/glxp/udidl/admin/controller/device/UdiCompanyController.java +++ b/api-admin/src/main/java/com/glxp/udidl/admin/controller/device/UdiCompanyController.java @@ -1,6 +1,7 @@ package com.glxp.udidl.admin.controller.device; import com.github.pagehelper.PageInfo; +import com.glxp.udidl.admin.annotation.AuthRuleAnnotation; import com.glxp.udidl.admin.entity.udi.ProductInfoEntity; import com.glxp.udidl.admin.entity.udi.UdiCompanyEntity; import com.glxp.udidl.admin.req.ProductInfoFilterRequest; @@ -29,6 +30,7 @@ public class UdiCompanyController { @Resource ProductInfoService productInfoService; + @AuthRuleAnnotation("udidl_udiCompany_all") @GetMapping("udi/company/filter") public BaseResponse filterCompany(@Valid UdiCompanyRequest udiCompanyRequest, BindingResult bindingResult) { @@ -38,7 +40,7 @@ public class UdiCompanyController { List udiCompanyEntities = udiCompanyService.filterUdiCompany(udiCompanyRequest); return ResultVOUtils.success(udiCompanyEntities); } - + @AuthRuleAnnotation("udidl_udiCompany_all") @GetMapping("udi/company/filtertByTD") public BaseResponse filtertByTD(ProductInfoFilterRequest productInfoFilterRequest, BindingResult bindingResult) { if (bindingResult.hasErrors()) { @@ -49,6 +51,7 @@ public class UdiCompanyController { } //udi查询app接口,获取企业最新DI + @AuthRuleAnnotation("udidl_udiCompany_all") @GetMapping("udi/company/filtertUdi") public BaseResponse filtertUdi(ProductInfoFilterRequest productInfoFilterRequest, BindingResult bindingResult) { if (bindingResult.hasErrors()) { diff --git a/api-admin/src/main/java/com/glxp/udidl/admin/controller/device/UdiCooperController.java b/api-admin/src/main/java/com/glxp/udidl/admin/controller/device/UdiCooperController.java index d560757..c5549d2 100644 --- a/api-admin/src/main/java/com/glxp/udidl/admin/controller/device/UdiCooperController.java +++ b/api-admin/src/main/java/com/glxp/udidl/admin/controller/device/UdiCooperController.java @@ -1,5 +1,6 @@ package com.glxp.udidl.admin.controller.device; +import com.glxp.udidl.admin.annotation.AuthRuleAnnotation; import com.glxp.udidl.admin.entity.udi.ProductInfoEntity; import com.glxp.udidl.admin.req.ProductInfoFilterRequest; import com.glxp.udidl.admin.service.inout.ProductInfoService; @@ -23,6 +24,7 @@ public class UdiCooperController { @Resource AsyncDownloadTask asyncDownloadTask; + @AuthRuleAnnotation("udidl_udiCooper_all") @GetMapping("udidl/cooper/findBydi") public BaseResponse findProductInfo(ProductInfoFilterRequest productInfoFilterRequest) { diff --git a/api-admin/src/main/java/com/glxp/udidl/admin/controller/device/UdiDownloadController.java b/api-admin/src/main/java/com/glxp/udidl/admin/controller/device/UdiDownloadController.java index 1dc0110..c4f4f06 100644 --- a/api-admin/src/main/java/com/glxp/udidl/admin/controller/device/UdiDownloadController.java +++ b/api-admin/src/main/java/com/glxp/udidl/admin/controller/device/UdiDownloadController.java @@ -1,5 +1,6 @@ package com.glxp.udidl.admin.controller.device; +import com.glxp.udidl.admin.annotation.AuthRuleAnnotation; import com.glxp.udidl.admin.entity.udid.*; import com.glxp.udidl.admin.req.DownloadUdiRequest; import com.glxp.udidl.admin.service.inout.UdiDownloadService; @@ -19,6 +20,7 @@ public class UdiDownloadController { @Resource private UdiDownloadService udiDownloadService; + @AuthRuleAnnotation("udidl_udiDownload_all") @GetMapping("udi/download/device") public BaseResponse downloadDevice(@Valid DownloadUdiRequest downloadUdiRequest, BindingResult bindingResult) { @@ -28,7 +30,7 @@ public class UdiDownloadController { List deviceList = udiDownloadService.downloadDevice(downloadUdiRequest); return ResultVOUtils.success(deviceList); } - + @AuthRuleAnnotation("udidl_udiDownload_all") @GetMapping("udi/download/contactlist") public BaseResponse downloadContactlist(@Valid DownloadUdiRequest downloadUdiRequest, BindingResult bindingResult) { @@ -38,7 +40,7 @@ public class UdiDownloadController { List deviceList = udiDownloadService.downloadContactlist(downloadUdiRequest); return ResultVOUtils.success(deviceList); } - + @AuthRuleAnnotation("udidl_udiDownload_all") @GetMapping("udi/download/deviceclinical") public BaseResponse downloadDeviceclinical(@Valid DownloadUdiRequest downloadUdiRequest, BindingResult bindingResult) { @@ -48,7 +50,7 @@ public class UdiDownloadController { List deviceList = udiDownloadService.downloadDeviceclinical(downloadUdiRequest); return ResultVOUtils.success(deviceList); } - + @AuthRuleAnnotation("udidl_udiDownload_all") @GetMapping("udi/download/devicepackage") public BaseResponse downloadDevicepackage(@Valid DownloadUdiRequest downloadUdiRequest, BindingResult bindingResult) { @@ -58,7 +60,7 @@ public class UdiDownloadController { List deviceList = udiDownloadService.downloadDevicepackage(downloadUdiRequest); return ResultVOUtils.success(deviceList); } - + @AuthRuleAnnotation("udidl_udiDownload_all") @GetMapping("udi/download/devicestorage") public BaseResponse downloadDevicestorage(@Valid DownloadUdiRequest downloadUdiRequest, BindingResult bindingResult) { diff --git a/api-admin/src/main/java/com/glxp/udidl/admin/controller/device/UdidlDeviceController.java b/api-admin/src/main/java/com/glxp/udidl/admin/controller/device/UdidlDeviceController.java new file mode 100644 index 0000000..297e1be --- /dev/null +++ b/api-admin/src/main/java/com/glxp/udidl/admin/controller/device/UdidlDeviceController.java @@ -0,0 +1,58 @@ +package com.glxp.udidl.admin.controller.device; + +import com.glxp.udidl.admin.annotation.AuthRuleAnnotation; +import com.glxp.udidl.admin.service.DataSync.DeviceSyncService; +import com.glxp.udidl.common.res.BaseResponse; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.format.annotation.DateTimeFormat; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.Date; + +@RestController +public class UdidlDeviceController { + private static final Logger logger = LoggerFactory.getLogger(UdidlDeviceController.class); + @Autowired + DeviceSyncService deviceSyncService; + + @AuthRuleAnnotation("udidl_udidlDevice_all") + @GetMapping("udidl/device/dlByDays") + public BaseResponse dlByDays(@DateTimeFormat(pattern = "yyyy-MM-dd") Date startDate, @DateTimeFormat(pattern = "yyyy-MM-dd") Date endDate) { + logger.info("---按日期段下载"); + return deviceSyncService.downloadUdi(startDate, endDate); + } + @AuthRuleAnnotation("udidl_udidlDevice_all") + @GetMapping("udidl/device/dlByDay") + public String dlByDay(String day) { + logger.info(day + "---按天开启下载"); + deviceSyncService.downloadUdi(day,"manual"); + //asyncDownloadTask.downloadByDay(day); + return "ok"; + } + @AuthRuleAnnotation("udidl_udidlDevice_all") + @PostMapping("udidl/device/dlByDi") + public BaseResponse downloadByDi(String deviceId) { + return deviceSyncService.downloadByDi(deviceId); + } + + /** + * 获取产品标识详情 + * + * @param deviceId + * @return + */ + @AuthRuleAnnotation("udidl_udidlDevice_all") + @PostMapping("udidl/device/downloadSingle") + public BaseResponse downloadSingle(String deviceId) { + return deviceSyncService.downloadSingle(deviceId); + } + @AuthRuleAnnotation("udidl_udidlDevice_all") + @PostMapping("udidl/device/downloadHistory") + public BaseResponse downloadHistory(String key) { + return deviceSyncService.downloadHistory(key); + } +} diff --git a/api-admin/src/main/java/com/glxp/udidl/admin/controller/info/CompanyController.java b/api-admin/src/main/java/com/glxp/udidl/admin/controller/info/CompanyController.java index df95270..a16bf89 100644 --- a/api-admin/src/main/java/com/glxp/udidl/admin/controller/info/CompanyController.java +++ b/api-admin/src/main/java/com/glxp/udidl/admin/controller/info/CompanyController.java @@ -1,5 +1,6 @@ package com.glxp.udidl.admin.controller.info; +import com.glxp.udidl.admin.annotation.AuthRuleAnnotation; import com.glxp.udidl.admin.entity.info.CompanyEntity; import com.glxp.udidl.admin.service.info.CompanyService; import com.glxp.udidl.common.res.BaseResponse; @@ -16,7 +17,7 @@ public class CompanyController { @Resource private CompanyService companyService; - + @AuthRuleAnnotation("udidl_company_all") @GetMapping("/warehouse/info/company") public BaseResponse getCompanyInfo() { CompanyEntity companyEntity = companyService.findCompany(); @@ -25,7 +26,7 @@ public class CompanyController { } return ResultVOUtils.error(500, "企业信息为空"); } - + @AuthRuleAnnotation("udidl_company_all") @PostMapping("/warehouse/info/modifyCompany") public BaseResponse modifyCompany(@RequestBody CompanyEntity companyEntity) { diff --git a/api-admin/src/main/java/com/glxp/udidl/admin/controller/info/JobLogController.java b/api-admin/src/main/java/com/glxp/udidl/admin/controller/info/JobLogController.java index 2204a18..699b3b4 100644 --- a/api-admin/src/main/java/com/glxp/udidl/admin/controller/info/JobLogController.java +++ b/api-admin/src/main/java/com/glxp/udidl/admin/controller/info/JobLogController.java @@ -1,5 +1,6 @@ package com.glxp.udidl.admin.controller.info; +import com.glxp.udidl.admin.annotation.AuthRuleAnnotation; import com.glxp.udidl.admin.req.udid.JobLogFilterRequest; import com.glxp.udidl.admin.service.udi.JobLogService; import com.glxp.udidl.common.res.BaseResponse; @@ -14,6 +15,8 @@ import org.springframework.web.bind.annotation.RestController; public class JobLogController { @Autowired JobLogService jobLogService; + + @AuthRuleAnnotation("udidl_jobLog_all") @PostMapping("/list") public BaseResponse getList(@RequestBody JobLogFilterRequest jobLogFilterRequest){ //System.out.println(jobLogFilterRequest); diff --git a/api-admin/src/main/java/com/glxp/udidl/admin/controller/udplat/UdplatGoodsController.java b/api-admin/src/main/java/com/glxp/udidl/admin/controller/udplat/UdplatGoodsController.java new file mode 100644 index 0000000..02c6876 --- /dev/null +++ b/api-admin/src/main/java/com/glxp/udidl/admin/controller/udplat/UdplatGoodsController.java @@ -0,0 +1,30 @@ +package com.glxp.udidl.admin.controller.udplat; + +import com.glxp.udidl.admin.annotation.AuthRuleAnnotation; +import com.glxp.udidl.admin.service.udplat.UdplatGoodsService; +import com.glxp.udidl.common.res.BaseResponse; +import com.glxp.udidl.common.util.ResultVOUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.multipart.MultipartFile; + +@RestController +@RequestMapping("udplat/goods") +public class UdplatGoodsController { + @Autowired + private UdplatGoodsService udplatGoodsService; + + @AuthRuleAnnotation("udidl_udplatGoods_all") + @PostMapping("/inport") + public BaseResponse importExcel(MultipartFile file,int type){ + try + { + return udplatGoodsService.importExcel(file.getInputStream(),type); + }catch (Exception e){ + return ResultVOUtils.error(-1,e.getMessage()); + } + + } +} diff --git a/api-admin/src/main/java/com/glxp/udidl/admin/dao/sys/SysMenuMapper.java b/api-admin/src/main/java/com/glxp/udidl/admin/dao/sys/SysMenuMapper.java new file mode 100644 index 0000000..58f6cea --- /dev/null +++ b/api-admin/src/main/java/com/glxp/udidl/admin/dao/sys/SysMenuMapper.java @@ -0,0 +1,19 @@ +package com.glxp.udidl.admin.dao.sys; + +import com.glxp.udidl.admin.entity.sys.SysMenu; +import org.apache.ibatis.annotations.Mapper; + +import java.util.List; + +@Mapper +public interface SysMenuMapper { + int deleteByPrimaryKey(Integer id); + + int insert(SysMenu record); + + SysMenu selectByPrimaryKey(Integer id); + + List selectAll(); + + int updateByPrimaryKey(SysMenu record); +} \ No newline at end of file diff --git a/api-admin/src/main/java/com/glxp/udidl/admin/dao/sys/SysRoleMapper.java b/api-admin/src/main/java/com/glxp/udidl/admin/dao/sys/SysRoleMapper.java new file mode 100644 index 0000000..9246358 --- /dev/null +++ b/api-admin/src/main/java/com/glxp/udidl/admin/dao/sys/SysRoleMapper.java @@ -0,0 +1,19 @@ +package com.glxp.udidl.admin.dao.sys; + +import com.glxp.udidl.admin.entity.sys.SysRole; +import org.apache.ibatis.annotations.Mapper; + +import java.util.List; + +@Mapper +public interface SysRoleMapper { + int deleteByPrimaryKey(Integer id); + + int insert(SysRole record); + + SysRole selectByPrimaryKey(Integer id); + + List selectAll(); + + int updateByPrimaryKey(SysRole record); +} \ No newline at end of file diff --git a/api-admin/src/main/java/com/glxp/udidl/admin/dao/sys/SysRoleMenuMapper.java b/api-admin/src/main/java/com/glxp/udidl/admin/dao/sys/SysRoleMenuMapper.java new file mode 100644 index 0000000..d25e827 --- /dev/null +++ b/api-admin/src/main/java/com/glxp/udidl/admin/dao/sys/SysRoleMenuMapper.java @@ -0,0 +1,13 @@ +package com.glxp.udidl.admin.dao.sys; + +import com.glxp.udidl.admin.entity.sys.SysRoleMenu; +import org.apache.ibatis.annotations.Mapper; + +import java.util.List; + +@Mapper +public interface SysRoleMenuMapper { + int insert(SysRoleMenu record); + + List selectAll(); +} \ No newline at end of file diff --git a/api-admin/src/main/java/com/glxp/udidl/admin/dao/sys/SysUserMapper.java b/api-admin/src/main/java/com/glxp/udidl/admin/dao/sys/SysUserMapper.java new file mode 100644 index 0000000..a85580b --- /dev/null +++ b/api-admin/src/main/java/com/glxp/udidl/admin/dao/sys/SysUserMapper.java @@ -0,0 +1,21 @@ +package com.glxp.udidl.admin.dao.sys; + +import com.glxp.udidl.admin.entity.sys.SysUser; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +@Mapper +public interface SysUserMapper { + int deleteByPrimaryKey(Integer id); + + int insert(SysUser record); + + SysUser selectByPrimaryKey(Integer id); + + List selectAll(); + + int updateByPrimaryKey(SysUser record); + int hasAuthPerms(@Param("userKey") String user_key, @Param("perms" ) String perms); +} \ No newline at end of file diff --git a/api-admin/src/main/java/com/glxp/udidl/admin/dao/udplat/UdplatGoodsMapper.java b/api-admin/src/main/java/com/glxp/udidl/admin/dao/udplat/UdplatGoodsMapper.java new file mode 100644 index 0000000..abf125e --- /dev/null +++ b/api-admin/src/main/java/com/glxp/udidl/admin/dao/udplat/UdplatGoodsMapper.java @@ -0,0 +1,19 @@ +package com.glxp.udidl.admin.dao.udplat; + +import com.glxp.udidl.admin.entity.udplat.UdplatGoods; +import org.apache.ibatis.annotations.Mapper; + +import java.util.List; + +@Mapper +public interface UdplatGoodsMapper { + int deleteByPrimaryKey(Long id); + + int insert(UdplatGoods record); + + UdplatGoods selectByGoodId(String deliveryGoodId); + + List selectAll(); + + int update(UdplatGoods record); +} diff --git a/api-admin/src/main/java/com/glxp/udidl/admin/dto/udplat/DeliveryGoods.java b/api-admin/src/main/java/com/glxp/udidl/admin/dto/udplat/DeliveryGoods.java new file mode 100644 index 0000000..c134df0 --- /dev/null +++ b/api-admin/src/main/java/com/glxp/udidl/admin/dto/udplat/DeliveryGoods.java @@ -0,0 +1,52 @@ +package com.glxp.udidl.admin.dto.udplat; + +import com.glxp.udidl.common.annotation.Excel; +import lombok.Data; +import java.util.Date; + +@Data +public class DeliveryGoods { + @Excel(name = "*采购平台产品ID") + private String deliveryGoodId;//配送目录ID/bigint + private String projectGoodsCode;//联采目录编码/varchar(50) + private String deliveryGoodsCode;//配送目录编码/varchar(50) + private long manufactureId;//平台生产企业ID/bigint(20) + private String manufactureName;//平台生产企业名称/varchar(50) + private long distributorId; //平台配送企业ID/bigint(20) + private String distributorName;//平台配送企业名称/varchar(50) + @Excel(name = "产品名称") + private String productName; //产品通用名/varchar(255) + private Integer compId; //组件id/bigint + @Excel(name = "型号") + private String model;//型号/varchar(1000) + @Excel(name = "规格") + private String spec;//规格/varchar(1000) + @Excel(name = "材质") + private String prodMaterial;//材质/varchar(255) + @Excel(name = "包材") + private String packMaterial;//包材/varchar(255) + @Excel(name = "注册证编号") + private String regNum;//注册证编号/varchar(255) + @Excel(name = "注册证名称") + private String regName;//注册证名称/varchar(255) + @Excel(name = "注册证有效期截止时间") + private String regValidTo;//注册证有效期截止时间/varchar(255) + private long unionProjectId;//联采项目ID/bigint(20) + private String unionProjectName;//采购项目名称/varchar(255) + private double salePrice;//价格/decimal(18,4) + private String priceUnitText;//价格单位/varchar(100) + private double topSalePrice;//最高销售限价,可能为空/decimal(18,4) + private double settlePayPrice;//医保支付标准,可能为空/varchar(255) + private Integer goodsSource;//数据来源/int(11)(取值:1.集中采购 2.耗材联采 3.医院HIS/医疗机构新增 4.备案采购 9. 阳光采购10. 新型冠状病毒相关检测试剂省级集中采购14. 限新冠病毒核酸快速检测采购使用) + @Excel(name = "*缺货状态",convertExp="1=有货,2=缺货") + private String stockStatus;//缺货状态(1有货、2缺货)/int + @Excel(name = "更新内容") + private String changedContent;//更新内容 + @Excel(name = "更新时间") + private Date changedTime;//更新时间 + private String proxyName;//申报企业名称/ varchar(50) + @Excel(name = "挂网状态") + private Integer onlineStatus;//挂网状态 1挂网2挂网状态为空 6 撤销申报 + @Excel(name = "医用耗材代码") + private String medicalCode;//医保编码 +} diff --git a/api-admin/src/main/java/com/glxp/udidl/admin/dto/udplat/HospitalGoods.java b/api-admin/src/main/java/com/glxp/udidl/admin/dto/udplat/HospitalGoods.java new file mode 100644 index 0000000..deee107 --- /dev/null +++ b/api-admin/src/main/java/com/glxp/udidl/admin/dto/udplat/HospitalGoods.java @@ -0,0 +1,53 @@ +package com.glxp.udidl.admin.dto.udplat; + +import com.glxp.udidl.common.annotation.Excel; +import lombok.Data; +import java.util.Date; + +@Data +public class HospitalGoods { + @Excel(name = "采购平台产品ID") + private String deliveryGoodId;//配送目录ID/bigint + private String projectGoodsCode;//联采目录编码/varchar(50) + private String deliveryGoodsCode;//配送目录编码/varchar(50) + private long manufactureId;//平台生产企业ID/bigint(20) + @Excel(name = "生产企业") + private String manufactureName;//平台生产企业名称/varchar(50) + private long distributorId; //平台配送企业ID/bigint(20) + @Excel(name = "配送企业") + private String distributorName;//平台配送企业名称/varchar(50) + @Excel(name = "产品名称") + private String productName; //产品通用名/varchar(255) + private Integer compId; //组件id/bigint + @Excel(name = "型号") + private String model;//型号/varchar(1000) + @Excel(name = "规格") + private String spec;//规格/varchar(1000) + @Excel(name = "材质") + private String prodMaterial;//材质/varchar(255) + private String packMaterial;//包材/varchar(255) + @Excel(name = "注册证编号") + private String regNum;//注册证编号/varchar(255) + @Excel(name = "注册证名称") + private String regName;//注册证名称/varchar(255) + @Excel(name = "注册证有效期截止时间") + private String regValidTo;//注册证有效期截止时间/varchar(255) + private long unionProjectId;//联采项目ID/bigint(20) + private String unionProjectName;//采购项目名称/varchar(255) + @Excel(name = "企业报价(元)") + private double salePrice;//价格/decimal(18,4) + @Excel(name = "价格单位") + private String priceUnitText;//价格单位/varchar(100) + private double topSalePrice;//最高销售限价,可能为空/decimal(18,4) + private double settlePayPrice;//医保支付标准,可能为空/varchar(255) + private Integer goodsSource;//数据来源/int(11)(取值:1.集中采购 2.耗材联采 3.医院HIS/医疗机构新增 4.备案采购 9. 阳光采购10. 新型冠状病毒相关检测试剂省级集中采购14. 限新冠病毒核酸快速检测采购使用) + private String stockStatus;//缺货状态(1有货、2缺货)/int + @Excel(name = "更新内容") + private String changedContent;//更新内容 + @Excel(name = "更新时间") + private Date changedTime;//更新时间 + private String proxyName;//申报企业名称/ varchar(50) + private Integer onlineStatus;//挂网状态 1挂网2挂网状态为空 6 撤销申报 + @Excel(name = "医用耗材代码") + private String medicalCode;//医保编码 +} diff --git a/api-admin/src/main/java/com/glxp/udidl/admin/entity/sys/SysMenu.java b/api-admin/src/main/java/com/glxp/udidl/admin/entity/sys/SysMenu.java new file mode 100644 index 0000000..fd5655a --- /dev/null +++ b/api-admin/src/main/java/com/glxp/udidl/admin/entity/sys/SysMenu.java @@ -0,0 +1,102 @@ +package com.glxp.udidl.admin.entity.sys; + +import java.util.Date; + +/** + * + * + * @author hong + * @date 2022/01/17 + */ +public class SysMenu { + /** + * 编号 + */ + private Integer id; + + /** + * 菜单名称 + */ + private String name; + + /** + * 父菜单ID + */ + private Integer parentId; + + /** + * 菜单类型M: 目录, C: 菜单,F: 资源 + */ + private String type; + + /** + * 权限标识 + */ + private String perms; + + /** + * 状态(0启用 1禁用) + */ + private String status; + + /** + * 创建时间 + */ + private Date createTime; + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name == null ? null : name.trim(); + } + + public Integer getParentId() { + return parentId; + } + + public void setParentId(Integer parentId) { + this.parentId = parentId; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type == null ? null : type.trim(); + } + + public String getPerms() { + return perms; + } + + public void setPerms(String perms) { + this.perms = perms == null ? null : perms.trim(); + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status == null ? null : status.trim(); + } + + public Date getCreateTime() { + return createTime; + } + + public void setCreateTime(Date createTime) { + this.createTime = createTime; + } +} \ No newline at end of file diff --git a/api-admin/src/main/java/com/glxp/udidl/admin/entity/sys/SysRole.java b/api-admin/src/main/java/com/glxp/udidl/admin/entity/sys/SysRole.java new file mode 100644 index 0000000..cf6f064 --- /dev/null +++ b/api-admin/src/main/java/com/glxp/udidl/admin/entity/sys/SysRole.java @@ -0,0 +1,76 @@ +package com.glxp.udidl.admin.entity.sys; + +import java.util.Date; + +/** + * + * + * @author hong + * @date 2022/01/17 + */ +public class SysRole { + /** + * + */ + private Integer id; + + /** + * 角色名称 + */ + private String name; + + /** + * 角色代码 + */ + private String code; + + /** + * 状态0: 启用,1: 禁用 + */ + private String status; + + /** + * 创建时间 + */ + private Date createTime; + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name == null ? null : name.trim(); + } + + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code == null ? null : code.trim(); + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status == null ? null : status.trim(); + } + + public Date getCreateTime() { + return createTime; + } + + public void setCreateTime(Date createTime) { + this.createTime = createTime; + } +} \ No newline at end of file diff --git a/api-admin/src/main/java/com/glxp/udidl/admin/entity/sys/SysRoleMenu.java b/api-admin/src/main/java/com/glxp/udidl/admin/entity/sys/SysRoleMenu.java new file mode 100644 index 0000000..fe6beab --- /dev/null +++ b/api-admin/src/main/java/com/glxp/udidl/admin/entity/sys/SysRoleMenu.java @@ -0,0 +1,35 @@ +package com.glxp.udidl.admin.entity.sys; + +/** + * + * + * @author hong + * @date 2022/01/17 + */ +public class SysRoleMenu { + /** + * + */ + private Integer roleId; + + /** + * + */ + private Integer menuId; + + public Integer getRoleId() { + return roleId; + } + + public void setRoleId(Integer roleId) { + this.roleId = roleId; + } + + public Integer getMenuId() { + return menuId; + } + + public void setMenuId(Integer menuId) { + this.menuId = menuId; + } +} \ No newline at end of file diff --git a/api-admin/src/main/java/com/glxp/udidl/admin/entity/sys/SysUser.java b/api-admin/src/main/java/com/glxp/udidl/admin/entity/sys/SysUser.java new file mode 100644 index 0000000..1098d73 --- /dev/null +++ b/api-admin/src/main/java/com/glxp/udidl/admin/entity/sys/SysUser.java @@ -0,0 +1,102 @@ +package com.glxp.udidl.admin.entity.sys; + +import java.util.Date; + +/** + * + * + * @author hong + * @date 2022/01/17 + */ +public class SysUser { + /** + * 用户ID + */ + private Integer id; + + /** + * 用户key, 登录用 + */ + private String userKey; + + /** + * 用户账号 + */ + private String userName; + + /** + * 用户昵称 + */ + private String nickName; + + /** + * 密码 + */ + private String password; + + /** + * 创建时间 + */ + private Date createTime; + + /** + * 角色ID + */ + private Integer roleId; + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getUserKey() { + return userKey; + } + + public void setUserKey(String userKey) { + this.userKey = userKey == null ? null : userKey.trim(); + } + + public String getUserName() { + return userName; + } + + public void setUserName(String userName) { + this.userName = userName == null ? null : userName.trim(); + } + + public String getNickName() { + return nickName; + } + + public void setNickName(String nickName) { + this.nickName = nickName == null ? null : nickName.trim(); + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password == null ? null : password.trim(); + } + + public Date getCreateTime() { + return createTime; + } + + public void setCreateTime(Date createTime) { + this.createTime = createTime; + } + + public Integer getRoleId() { + return roleId; + } + + public void setRoleId(Integer roleId) { + this.roleId = roleId; + } +} \ No newline at end of file diff --git a/api-admin/src/main/java/com/glxp/udidl/admin/entity/udplat/UdplatGoods.java b/api-admin/src/main/java/com/glxp/udidl/admin/entity/udplat/UdplatGoods.java new file mode 100644 index 0000000..2d710a5 --- /dev/null +++ b/api-admin/src/main/java/com/glxp/udidl/admin/entity/udplat/UdplatGoods.java @@ -0,0 +1,42 @@ +package com.glxp.udidl.admin.entity.udplat; + +import lombok.Data; + +import java.util.Date; + +@Data +public class UdplatGoods { + private long id; + private String uuid; + private String deliveryGoodId;//配送目录ID/bigint + private String projectGoodsCode;//联采目录编码/varchar(50) + private String deliveryGoodsCode;//配送目录编码/varchar(50) + private long manufactureId;//平台生产企业ID/bigint(20) + private String manufactureName;//平台生产企业名称/varchar(50) + private long distributorId; //平台配送企业ID/bigint(20) + private String distributorName;//平台配送企业名称/varchar(50) + private String productName; //产品通用名/varchar(255) + private Integer compId; //组件id/bigint + private String model;//型号/varchar(1000) + private String spec;//规格/varchar(1000) + private String prodMaterial;//材质/varchar(255) + private String packMaterial;//包材/varchar(255) + private String regNum;//注册证编号/varchar(255) + private String regName;//注册证名称/varchar(255) + private String regValidTo;//注册证有效期截止时间/varchar(255) + private long unionProjectId;//联采项目ID/bigint(20) + private String unionProjectName;//采购项目名称/varchar(255) + private double salePrice;//价格/decimal(18,4) + private String priceUnitText;//价格单位/varchar(100) + private double topSalePrice;//最高销售限价,可能为空/decimal(18,4) + private double settlePayPrice;//医保支付标准,可能为空/varchar(255) + private Integer goodsSource;//数据来源/int(11)(取值:1.集中采购 2.耗材联采 3.医院HIS/医疗机构新增 4.备案采购 9. 阳光采购10. 新型冠状病毒相关检测试剂省级集中采购14. 限新冠病毒核酸快速检测采购使用) + private String stockStatus;//缺货状态(1有货、2缺货)/int + private String changedContent;//更新内容 + private Date changedTime;//更新时间 + private String proxyName;//申报企业名称/ varchar(50) + private Integer onlineStatus;//挂网状态 1挂网2挂网状态为空 6 撤销申报 + private String medicalCode;//医保编码 + private Date createTime;//创建时间 + private Date updateTime;//最后更新时间 +} diff --git a/api-admin/src/main/java/com/glxp/udidl/admin/service/udplat/UdplatGoodsService.java b/api-admin/src/main/java/com/glxp/udidl/admin/service/udplat/UdplatGoodsService.java new file mode 100644 index 0000000..ef75e03 --- /dev/null +++ b/api-admin/src/main/java/com/glxp/udidl/admin/service/udplat/UdplatGoodsService.java @@ -0,0 +1,15 @@ +package com.glxp.udidl.admin.service.udplat; + +import com.glxp.udidl.common.res.BaseResponse; + +import java.io.InputStream; + +public interface UdplatGoodsService { + /** + * excel导入 + * @param is + * @param type 1:院内的导入 2;配送目录 + * @return + */ + BaseResponse importExcel(InputStream is,int type) ; +} diff --git a/api-admin/src/main/java/com/glxp/udidl/admin/service/udplat/impl/UdplatGoodsServiceImpl.java b/api-admin/src/main/java/com/glxp/udidl/admin/service/udplat/impl/UdplatGoodsServiceImpl.java new file mode 100644 index 0000000..bbc01ce --- /dev/null +++ b/api-admin/src/main/java/com/glxp/udidl/admin/service/udplat/impl/UdplatGoodsServiceImpl.java @@ -0,0 +1,74 @@ +package com.glxp.udidl.admin.service.udplat.impl; + +import com.glxp.udidl.admin.dao.udplat.UdplatGoodsMapper; +import com.glxp.udidl.admin.dto.udplat.DeliveryGoods; +import com.glxp.udidl.admin.dto.udplat.HospitalGoods; +import com.glxp.udidl.admin.entity.udplat.UdplatGoods; +import com.glxp.udidl.admin.service.udplat.UdplatGoodsService; +import com.glxp.udidl.admin.util.BeanUtils; +import com.glxp.udidl.common.res.BaseResponse; +import com.glxp.udidl.common.util.ExcelUtil; +import com.glxp.udidl.common.util.ResultVOUtils; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.io.InputStream; +import java.util.List; + +@Service +@Slf4j +public class UdplatGoodsServiceImpl implements UdplatGoodsService { + @Autowired + private UdplatGoodsMapper udplatGoodsMapper; + @Override + public BaseResponse importExcel(InputStream is, int type) { + List list; + try{ + if(type == 1) { + List list1 = getData1(is); + list = BeanUtils.convertList2List(list1,UdplatGoods.class); + }else + if(type == 2){ + List list2 = getData2(is); + //log.info(JSONUtil.toJsonStr(list2)); + list = BeanUtils.convertList2List(list2,UdplatGoods.class); + }else + return ResultVOUtils.error(-1,"文件类型不匹配!"); + return save(list); + }catch (Exception e){ + return ResultVOUtils.error(-1,"转换格式出错:"+e.getMessage()); + } + + //return ResultVOUtils.success(); + } + private List getData1(InputStream is) throws Exception{ + ExcelUtil util = new ExcelUtil(HospitalGoods.class); + return util.importExcel(is); + } + private List getData2(InputStream is) throws Exception{ + ExcelUtil util = new ExcelUtil(DeliveryGoods.class); + return util.importExcel(is); + } + private BaseResponse save(List list){ + if(list == null || list.size()<1) + return ResultVOUtils.error(-1,"无数据!"); + //log.info("数据:"+JSONUtil.toJsonStr(list)); + int count=0; + for(UdplatGoods item:list){ + String goodId = item.getDeliveryGoodId(); + if(goodId == null || goodId.isEmpty()) + continue; + UdplatGoods goods = udplatGoodsMapper.selectByGoodId(goodId); + if(goods != null) + { + BeanUtils.copyProperties(item,goods); + udplatGoodsMapper.update(goods); + }else + item.setUuid(BeanUtils.getUUId()); + udplatGoodsMapper.insert(item); + count++; + } + return ResultVOUtils.success(count); + } +} diff --git a/api-admin/src/main/java/com/glxp/udidl/admin/util/BeanUtils.java b/api-admin/src/main/java/com/glxp/udidl/admin/util/BeanUtils.java new file mode 100644 index 0000000..4d54dd9 --- /dev/null +++ b/api-admin/src/main/java/com/glxp/udidl/admin/util/BeanUtils.java @@ -0,0 +1,34 @@ +package com.glxp.udidl.admin.util; + +import org.springframework.util.CollectionUtils; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +public class BeanUtils extends org.springframework.beans.BeanUtils{ + /** + * list复制 + * @param input + * @param clzz + * @param + * @param + * @return + */ + public static List convertList2List(List input, Class clzz){ + List output = new ArrayList<>(); + if(!CollectionUtils.isEmpty(input)){ + for(E source:input){ + T target = org.springframework.beans.BeanUtils.instantiate(clzz); + org.springframework.beans.BeanUtils.copyProperties(source,target); + output.add(target); + } + } + return output; + } + public static String getUUId() { + UUID uuid = UUID.randomUUID(); + return uuid.toString().replace("-", ""); + } + +} diff --git a/api-admin/src/main/resources/application-dev.properties b/api-admin/src/main/resources/application-dev.properties index 1c743ee..524e87d 100644 --- a/api-admin/src/main/resources/application-dev.properties +++ b/api-admin/src/main/resources/application-dev.properties @@ -14,4 +14,7 @@ cors.allowed-methods=GET,POST,OPTIONS #mips服务地址 UDIC_MIPSDOWNLOAD_URL = http://127.0.0.1:8080/UDIC_MIPSDL_Server #UDIC_MIPSDOWNLOAD_URL=http://127.0.0.1:9997 -config.downloadPath=E:/temp \ No newline at end of file +config.downloadPath=E:/temp +config.openAuth=true +spring.servlet.multipart.max-file-size=100MB +spring.servlet.multipart.max-request-size=1000MB \ No newline at end of file diff --git a/api-admin/src/main/resources/mybatis/mapper/sys/SysMenuMapper.xml b/api-admin/src/main/resources/mybatis/mapper/sys/SysMenuMapper.xml new file mode 100644 index 0000000..aef8dba --- /dev/null +++ b/api-admin/src/main/resources/mybatis/mapper/sys/SysMenuMapper.xml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + delete from sys_menu + where id = #{id,jdbcType=INTEGER} + + + insert into sys_menu (id, name, parent_id, + type, perms, status, create_time + ) + values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, #{parentId,jdbcType=INTEGER}, + #{type,jdbcType=CHAR}, #{perms,jdbcType=VARCHAR}, #{status,jdbcType=CHAR}, #{createTime,jdbcType=TIMESTAMP} + ) + + + update sys_menu + set name = #{name,jdbcType=VARCHAR}, + parent_id = #{parentId,jdbcType=INTEGER}, + type = #{type,jdbcType=CHAR}, + perms = #{perms,jdbcType=VARCHAR}, + status = #{status,jdbcType=CHAR}, + create_time = #{createTime,jdbcType=TIMESTAMP} + where id = #{id,jdbcType=INTEGER} + + + + \ No newline at end of file diff --git a/api-admin/src/main/resources/mybatis/mapper/sys/SysRoleMapper.xml b/api-admin/src/main/resources/mybatis/mapper/sys/SysRoleMapper.xml new file mode 100644 index 0000000..2fdb3e0 --- /dev/null +++ b/api-admin/src/main/resources/mybatis/mapper/sys/SysRoleMapper.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + delete from sys_role + where id = #{id,jdbcType=INTEGER} + + + insert into sys_role (id, name, code, + status, create_time) + values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, #{code,jdbcType=VARCHAR}, + #{status,jdbcType=CHAR}, #{createTime,jdbcType=TIMESTAMP}) + + + update sys_role + set name = #{name,jdbcType=VARCHAR}, + code = #{code,jdbcType=VARCHAR}, + status = #{status,jdbcType=CHAR}, + create_time = #{createTime,jdbcType=TIMESTAMP} + where id = #{id,jdbcType=INTEGER} + + + + \ No newline at end of file diff --git a/api-admin/src/main/resources/mybatis/mapper/sys/SysRoleMenuMapper.xml b/api-admin/src/main/resources/mybatis/mapper/sys/SysRoleMenuMapper.xml new file mode 100644 index 0000000..a27b820 --- /dev/null +++ b/api-admin/src/main/resources/mybatis/mapper/sys/SysRoleMenuMapper.xml @@ -0,0 +1,16 @@ + + + + + + + + + insert into sys_role_menu (role_id, menu_id) + values (#{roleId,jdbcType=INTEGER}, #{menuId,jdbcType=INTEGER}) + + + \ No newline at end of file diff --git a/api-admin/src/main/resources/mybatis/mapper/sys/SysUserMapper.xml b/api-admin/src/main/resources/mybatis/mapper/sys/SysUserMapper.xml new file mode 100644 index 0000000..fb27911 --- /dev/null +++ b/api-admin/src/main/resources/mybatis/mapper/sys/SysUserMapper.xml @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + delete from sys_user + where id = #{id,jdbcType=INTEGER} + + + insert into sys_user (id, user_key, user_name, + nick_name, password, create_time, + role_id) + values (#{id,jdbcType=INTEGER}, #{userKey,jdbcType=VARCHAR}, #{userName,jdbcType=VARCHAR}, + #{nickName,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, + #{roleId,jdbcType=INTEGER}) + + + update sys_user + set user_key = #{userKey,jdbcType=VARCHAR}, + user_name = #{userName,jdbcType=VARCHAR}, + nick_name = #{nickName,jdbcType=VARCHAR}, + password = #{password,jdbcType=VARCHAR}, + create_time = #{createTime,jdbcType=TIMESTAMP}, + role_id = #{roleId,jdbcType=INTEGER} + where id = #{id,jdbcType=INTEGER} + + + + + \ No newline at end of file diff --git a/api-admin/src/main/resources/mybatis/mapper/udplat/UdplatGoodsMapper.xml b/api-admin/src/main/resources/mybatis/mapper/udplat/UdplatGoodsMapper.xml new file mode 100644 index 0000000..bdb7d9b --- /dev/null +++ b/api-admin/src/main/resources/mybatis/mapper/udplat/UdplatGoodsMapper.xml @@ -0,0 +1,122 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + delete from udplat_goods + where id = #{id,jdbcType=BIGINT} + + + insert into udplat_goods (id, uuid, deliveryGoodId, + projectGoodsCode, deliveryGoodsCode, manufactureId, + manufactureName, distributorId, distributorName, + productName, compId, model, + spec, prodMaterial, packMaterial, + regNum, regName, regValidTo, + unionProjectId, unionProjectName, salePrice, + priceUnitText, topSalePrice, settlePayPrice, + goodsSource, stockStatus, changedContent, + changedTime, proxyName, onlineStatus, + medicalCode, createTime + ) + values (#{id,jdbcType=BIGINT}, #{uuid,jdbcType=VARCHAR}, #{deliveryGoodId,jdbcType=VARCHAR}, + #{projectGoodsCode,jdbcType=VARCHAR}, #{deliveryGoodsCode,jdbcType=VARCHAR}, #{manufactureId,jdbcType=BIGINT}, + #{manufactureName,jdbcType=VARCHAR}, #{distributorId,jdbcType=BIGINT}, #{distributorName,jdbcType=VARCHAR}, + #{productName,jdbcType=VARCHAR}, #{compId,jdbcType=BIGINT}, #{model,jdbcType=VARCHAR}, + #{spec,jdbcType=VARCHAR}, #{prodMaterial,jdbcType=VARCHAR}, #{packMaterial,jdbcType=VARCHAR}, + #{regNum,jdbcType=VARCHAR}, #{regName,jdbcType=VARCHAR}, #{regValidTo,jdbcType=VARCHAR}, + #{unionProjectId,jdbcType=BIGINT}, #{unionProjectName,jdbcType=VARCHAR}, #{salePrice,jdbcType=DECIMAL}, + #{priceUnitText,jdbcType=VARCHAR}, #{topSalePrice,jdbcType=DECIMAL}, #{settlePayPrice,jdbcType=DECIMAL}, + #{goodsSource,jdbcType=INTEGER}, #{stockStatus,jdbcType=VARCHAR}, #{changedContent,jdbcType=VARCHAR}, + #{changedTime,jdbcType=TIMESTAMP}, #{proxyName,jdbcType=VARCHAR}, #{onlineStatus,jdbcType=INTEGER}, + #{medicalCode,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP} + ) + + + update udplat_goods + set uuid = #{uuid,jdbcType=VARCHAR}, + deliveryGoodId = #{deliveryGoodId,jdbcType=VARCHAR}, + projectGoodsCode = #{projectGoodsCode,jdbcType=VARCHAR}, + deliveryGoodsCode = #{deliveryGoodsCode,jdbcType=VARCHAR}, + manufactureId = #{manufactureId,jdbcType=BIGINT}, + manufactureName = #{manufactureName,jdbcType=VARCHAR}, + distributorId = #{distributorId,jdbcType=BIGINT}, + distributorName = #{distributorName,jdbcType=VARCHAR}, + productName = #{productName,jdbcType=VARCHAR}, + compId = #{compId,jdbcType=BIGINT}, + model = #{model,jdbcType=VARCHAR}, + spec = #{spec,jdbcType=VARCHAR}, + prodMaterial = #{prodMaterial,jdbcType=VARCHAR}, + packMaterial = #{packMaterial,jdbcType=VARCHAR}, + regNum = #{regNum,jdbcType=VARCHAR}, + regName = #{regName,jdbcType=VARCHAR}, + regValidTo = #{regValidTo,jdbcType=VARCHAR}, + unionProjectId = #{unionProjectId,jdbcType=BIGINT}, + unionProjectName = #{unionProjectName,jdbcType=VARCHAR}, + salePrice = #{salePrice,jdbcType=DECIMAL}, + priceUnitText = #{priceUnitText,jdbcType=VARCHAR}, + topSalePrice = #{topSalePrice,jdbcType=DECIMAL}, + settlePayPrice = #{settlePayPrice,jdbcType=DECIMAL}, + goodsSource = #{goodsSource,jdbcType=INTEGER}, + stockStatus = #{stockStatus,jdbcType=VARCHAR}, + changedContent = #{changedContent,jdbcType=VARCHAR}, + changedTime = #{changedTime,jdbcType=TIMESTAMP}, + proxyName = #{proxyName,jdbcType=VARCHAR}, + onlineStatus = #{onlineStatus,jdbcType=INTEGER}, + medicalCode = #{medicalCode,jdbcType=VARCHAR}, + createTime = #{createTime,jdbcType=TIMESTAMP}, + updateTime = #{updateTime,jdbcType=TIMESTAMP} + where id = #{id,jdbcType=BIGINT} + + + + \ No newline at end of file diff --git a/api-admin/target/classes/application-dev.properties b/api-admin/target/classes/application-dev.properties index 1c743ee..524e87d 100644 --- a/api-admin/target/classes/application-dev.properties +++ b/api-admin/target/classes/application-dev.properties @@ -14,4 +14,7 @@ cors.allowed-methods=GET,POST,OPTIONS #mips服务地址 UDIC_MIPSDOWNLOAD_URL = http://127.0.0.1:8080/UDIC_MIPSDL_Server #UDIC_MIPSDOWNLOAD_URL=http://127.0.0.1:9997 -config.downloadPath=E:/temp \ No newline at end of file +config.downloadPath=E:/temp +config.openAuth=true +spring.servlet.multipart.max-file-size=100MB +spring.servlet.multipart.max-request-size=1000MB \ No newline at end of file diff --git a/api-admin/target/classes/com/glxp/udidl/admin/config/GlobalConfig.class b/api-admin/target/classes/com/glxp/udidl/admin/config/GlobalConfig.class index 749e1ba..198bfe4 100644 Binary files a/api-admin/target/classes/com/glxp/udidl/admin/config/GlobalConfig.class and b/api-admin/target/classes/com/glxp/udidl/admin/config/GlobalConfig.class differ diff --git a/api-admin/target/classes/com/glxp/udidl/admin/controller/device/ContactController.class b/api-admin/target/classes/com/glxp/udidl/admin/controller/device/ContactController.class index a6bcec3..36d3d0e 100644 Binary files a/api-admin/target/classes/com/glxp/udidl/admin/controller/device/ContactController.class and b/api-admin/target/classes/com/glxp/udidl/admin/controller/device/ContactController.class differ diff --git a/api-admin/target/classes/com/glxp/udidl/admin/controller/device/DeviceController.class b/api-admin/target/classes/com/glxp/udidl/admin/controller/device/DeviceController.class index b07fbd9..0f9a190 100644 Binary files a/api-admin/target/classes/com/glxp/udidl/admin/controller/device/DeviceController.class and b/api-admin/target/classes/com/glxp/udidl/admin/controller/device/DeviceController.class differ diff --git a/api-admin/target/classes/com/glxp/udidl/admin/controller/device/FileInfoController.class b/api-admin/target/classes/com/glxp/udidl/admin/controller/device/FileInfoController.class index d9462e7..ed4dd74 100644 Binary files a/api-admin/target/classes/com/glxp/udidl/admin/controller/device/FileInfoController.class and b/api-admin/target/classes/com/glxp/udidl/admin/controller/device/FileInfoController.class differ diff --git a/api-admin/target/classes/com/glxp/udidl/admin/controller/device/PosTaggerController.class b/api-admin/target/classes/com/glxp/udidl/admin/controller/device/PosTaggerController.class index e883bd0..2e9ae5f 100644 Binary files a/api-admin/target/classes/com/glxp/udidl/admin/controller/device/PosTaggerController.class and b/api-admin/target/classes/com/glxp/udidl/admin/controller/device/PosTaggerController.class differ diff --git a/api-admin/target/classes/com/glxp/udidl/admin/controller/device/ProductInfoController.class b/api-admin/target/classes/com/glxp/udidl/admin/controller/device/ProductInfoController.class index 97aa2f6..26e98f9 100644 Binary files a/api-admin/target/classes/com/glxp/udidl/admin/controller/device/ProductInfoController.class and b/api-admin/target/classes/com/glxp/udidl/admin/controller/device/ProductInfoController.class differ diff --git a/api-admin/target/classes/com/glxp/udidl/admin/controller/device/TestController.class b/api-admin/target/classes/com/glxp/udidl/admin/controller/device/TestController.class index 001bbb2..f79f61e 100644 Binary files a/api-admin/target/classes/com/glxp/udidl/admin/controller/device/TestController.class and b/api-admin/target/classes/com/glxp/udidl/admin/controller/device/TestController.class differ diff --git a/api-admin/target/classes/com/glxp/udidl/admin/controller/device/UdiCompanyController.class b/api-admin/target/classes/com/glxp/udidl/admin/controller/device/UdiCompanyController.class index 0476885..5ed69c6 100644 Binary files a/api-admin/target/classes/com/glxp/udidl/admin/controller/device/UdiCompanyController.class and b/api-admin/target/classes/com/glxp/udidl/admin/controller/device/UdiCompanyController.class differ diff --git a/api-admin/target/classes/com/glxp/udidl/admin/controller/device/UdiCooperController.class b/api-admin/target/classes/com/glxp/udidl/admin/controller/device/UdiCooperController.class index 573e8ac..a3cfaac 100644 Binary files a/api-admin/target/classes/com/glxp/udidl/admin/controller/device/UdiCooperController.class and b/api-admin/target/classes/com/glxp/udidl/admin/controller/device/UdiCooperController.class differ diff --git a/api-admin/target/classes/com/glxp/udidl/admin/controller/device/UdiDownloadController.class b/api-admin/target/classes/com/glxp/udidl/admin/controller/device/UdiDownloadController.class index d7dd2cb..66c30b3 100644 Binary files a/api-admin/target/classes/com/glxp/udidl/admin/controller/device/UdiDownloadController.class and b/api-admin/target/classes/com/glxp/udidl/admin/controller/device/UdiDownloadController.class differ diff --git a/api-admin/target/classes/com/glxp/udidl/admin/controller/info/CompanyController.class b/api-admin/target/classes/com/glxp/udidl/admin/controller/info/CompanyController.class index 63b183b..e30052e 100644 Binary files a/api-admin/target/classes/com/glxp/udidl/admin/controller/info/CompanyController.class and b/api-admin/target/classes/com/glxp/udidl/admin/controller/info/CompanyController.class differ diff --git a/api-admin/target/classes/com/glxp/udidl/admin/controller/info/JobLogController.class b/api-admin/target/classes/com/glxp/udidl/admin/controller/info/JobLogController.class index 9b62d22..6d3d08e 100644 Binary files a/api-admin/target/classes/com/glxp/udidl/admin/controller/info/JobLogController.class and b/api-admin/target/classes/com/glxp/udidl/admin/controller/info/JobLogController.class differ diff --git a/api-admin/target/classes/com/glxp/udidl/admin/res/udid/DataSetResult$ClinicalInfo.class b/api-admin/target/classes/com/glxp/udidl/admin/res/udid/DataSetResult$ClinicalInfo.class index e9066d1..74b95fc 100644 Binary files a/api-admin/target/classes/com/glxp/udidl/admin/res/udid/DataSetResult$ClinicalInfo.class and b/api-admin/target/classes/com/glxp/udidl/admin/res/udid/DataSetResult$ClinicalInfo.class differ diff --git a/api-admin/target/classes/com/glxp/udidl/admin/res/udid/DataSetResult$DeviceInfo.class b/api-admin/target/classes/com/glxp/udidl/admin/res/udid/DataSetResult$DeviceInfo.class index c38c28a..54dbd33 100644 Binary files a/api-admin/target/classes/com/glxp/udidl/admin/res/udid/DataSetResult$DeviceInfo.class and b/api-admin/target/classes/com/glxp/udidl/admin/res/udid/DataSetResult$DeviceInfo.class differ diff --git a/api-admin/target/classes/com/glxp/udidl/admin/res/udid/DataSetResult$PackingInfo.class b/api-admin/target/classes/com/glxp/udidl/admin/res/udid/DataSetResult$PackingInfo.class index 1515a85..2c25a04 100644 Binary files a/api-admin/target/classes/com/glxp/udidl/admin/res/udid/DataSetResult$PackingInfo.class and b/api-admin/target/classes/com/glxp/udidl/admin/res/udid/DataSetResult$PackingInfo.class differ diff --git a/api-admin/target/classes/com/glxp/udidl/admin/res/udid/DataSetResult$StorageInfo.class b/api-admin/target/classes/com/glxp/udidl/admin/res/udid/DataSetResult$StorageInfo.class index 9ffa25e..37ecaa5 100644 Binary files a/api-admin/target/classes/com/glxp/udidl/admin/res/udid/DataSetResult$StorageInfo.class and b/api-admin/target/classes/com/glxp/udidl/admin/res/udid/DataSetResult$StorageInfo.class differ diff --git a/api-admin/target/classes/com/glxp/udidl/admin/service/DataSync/DeviceSaveService.class b/api-admin/target/classes/com/glxp/udidl/admin/service/DataSync/DeviceSaveService.class index 74e188b..2aa81c5 100644 Binary files a/api-admin/target/classes/com/glxp/udidl/admin/service/DataSync/DeviceSaveService.class and b/api-admin/target/classes/com/glxp/udidl/admin/service/DataSync/DeviceSaveService.class differ diff --git a/api-common/pom.xml b/api-common/pom.xml index b234626..461fffd 100644 --- a/api-common/pom.xml +++ b/api-common/pom.xml @@ -23,7 +23,16 @@ org.apache.commons commons-lang3 - + + org.apache.poi + poi-ooxml + 4.1.0 + + + cn.hutool + hutool-all + 5.5.1 + \ No newline at end of file diff --git a/api-common/src/main/java/com/glxp/udidl/common/annotation/Excel.java b/api-common/src/main/java/com/glxp/udidl/common/annotation/Excel.java new file mode 100644 index 0000000..8d7731d --- /dev/null +++ b/api-common/src/main/java/com/glxp/udidl/common/annotation/Excel.java @@ -0,0 +1,101 @@ +package com.glxp.udidl.common.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.FIELD) +public @interface Excel { + /** + * 导出到Excel中的名字. + */ + public String name() default ""; + + /** + * 日期格式, 如: yyyy-MM-dd + */ + public String dateFormat() default ""; + + /** + * 读取内容转表达式 (如: 0=男,1=女,2=未知) + */ + public String convertExp() default ""; + + /** + * 导出类型(0数字 1字符串) + */ + public ColumnType cellType() default ColumnType.STRING; + + /** + * 导出时在excel中每个列的高度 单位为字符 + */ + public double height() default 14; + + /** + * 导出时在excel中每个列的宽 单位为字符 + */ + public double width() default 16; + + /** + * 文字后缀,如% 90 变成90% + */ + public String suffix() default ""; + + /** + * 当值为空时,字段的默认值 + */ + public String defaultValue() default ""; + + /** + * 提示信息 + */ + public String prompt() default ""; + + /** + * 设置只能选择不能输入的列内容. + */ + public String[] combo() default {}; + + /** + * 是否导出数据,应对需求:有时我们需要导出一份模板,这是标题需要但内容需要用户手工填写. + */ + public boolean isExport() default true; + + /** + * 另一个类中的属性名称,支持多级获取,以小数点隔开 + */ + public String targetAttr() default ""; + + /** + * 字段类型(0:导出导入;1:仅导出;2:仅导入) + */ + Type type() default Type.ALL; + + public enum Type { + ALL(0), EXPORT(1), IMPORT(2); + private final int value; + + Type(int value) { + this.value = value; + } + + public int value() { + return this.value; + } + } + + public enum ColumnType { + NUMERIC(0), STRING(1); + private final int value; + + ColumnType(int value) { + this.value = value; + } + + public int value() { + return this.value; + } + } +} diff --git a/api-common/src/main/java/com/glxp/udidl/common/util/DateUtils.java b/api-common/src/main/java/com/glxp/udidl/common/util/DateUtils.java new file mode 100644 index 0000000..017ee28 --- /dev/null +++ b/api-common/src/main/java/com/glxp/udidl/common/util/DateUtils.java @@ -0,0 +1,15 @@ +package com.glxp.udidl.common.util; + +import java.util.Date; + +public class DateUtils extends cn.hutool.core.date.DateUtil{ + /** + * 日期型字符串转化为日期 格式 + */ + public static Date parseDate(Object str) { + if (str == null) { + return null; + } + return parse(str.toString()); + } +} \ No newline at end of file diff --git a/api-common/src/main/java/com/glxp/udidl/common/util/ExcelUtil.java b/api-common/src/main/java/com/glxp/udidl/common/util/ExcelUtil.java new file mode 100644 index 0000000..acfaa9a --- /dev/null +++ b/api-common/src/main/java/com/glxp/udidl/common/util/ExcelUtil.java @@ -0,0 +1,234 @@ +package com.glxp.udidl.common.util; + +import cn.hutool.core.convert.Convert; +import cn.hutool.core.util.ReflectUtil; +import cn.hutool.core.util.StrUtil; +import com.glxp.udidl.common.annotation.Excel; +import com.glxp.udidl.common.annotation.Excel.Type; +import org.apache.poi.hssf.usermodel.HSSFDateUtil; +import org.apache.poi.ss.usermodel.*; + +import java.io.IOException; +import java.io.InputStream; +import java.lang.reflect.Field; +import java.math.BigDecimal; +import java.text.DecimalFormat; +import java.util.*; + +//@Slf4j +public class ExcelUtil { + /** + * Excel sheet最大行数,默认65536 + */ + public static final int sheetSize = 65536; + + /** + * 工作表名称 + */ + private String sheetName; + + /** + * 导出类型(EXPORT:导出数据;IMPORT:导入模板) + */ + private Type type; + + /** + * 工作薄对象 + */ + private Workbook wb; + + /** + * 工作表对象 + */ + private Sheet sheet; + + /** + * 样式列表 + */ + private Map styles; + + /** + * 导入导出数据列表 + */ + private List list; + + /** + * 注解列表 + */ + private List fields; + + /** + * 实体对象 + */ + public Class clazz; + + public ExcelUtil(Class clazz) { + this.clazz = clazz; + } + public List importExcel(InputStream is) throws Exception { + return importExcel("", is); + } + public List importExcel(String sheetName, InputStream is) throws Exception { + this.type = Excel.Type.IMPORT; + this.wb = WorkbookFactory.create(is); + List list = new ArrayList(); + Sheet sheet = null; + if (!sheetName.isEmpty()) { + // 如果指定sheet名,则取指定sheet中的内容. + sheet = wb.getSheet(sheetName); + } else { + // 如果传入的sheet名不存在则默认指向第1个sheet. + sheet = wb.getSheetAt(0); + } + + if (sheet == null) { + throw new IOException("文件sheet不存在"); + } + + int rows = sheet.getPhysicalNumberOfRows(); + + if (rows > 0) { + // 定义一个map用于存放excel列的序号和field. + Map cellMap = new HashMap(); + // 获取表头 + Row heard = sheet.getRow(0); + for (int i = 0; i < heard.getPhysicalNumberOfCells(); i++) { + Cell cell = heard.getCell(i); + if (!StrUtil.isEmptyIfStr(cell)) { + String value = this.getCellValue(heard, i).toString(); + cellMap.put(value, i); + } else { + cellMap.put(null, i); + } + } + // 有数据时才处理 得到类的所有field. + Field[] allFields = clazz.getDeclaredFields(); + // 定义一个map用于存放列的序号和field. + Map fieldsMap = new HashMap(); + for (int col = 0; col < allFields.length; col++) { + Field field = allFields[col]; + Excel attr = field.getAnnotation(Excel.class); + if (attr != null && (attr.type() == Type.ALL || attr.type() == type)) { + // 设置类的私有字段属性可访问. + field.setAccessible(true); + Integer column = cellMap.get(attr.name()); + fieldsMap.put(column, field); + } + } + for (int i = 1; i < rows; i++) { + // 从第2行开始取数据,默认第一行是表头. + Row row = sheet.getRow(i); + T entity = null; + for (Map.Entry entry : fieldsMap.entrySet()) { + Object val = this.getCellValue(row, entry.getKey()); + + // 如果不存在实例则新建. + entity = (entity == null ? clazz.newInstance() : entity); + // 从map中得到对应列的field. + Field field = fieldsMap.get(entry.getKey()); + // 取得类型,并根据对象类型设置值. + Class fieldType = field.getType(); + if (String.class == fieldType) { + String s = Convert.toStr(val); + if (StrUtil.endWith(s, ".0")) { + val = StrUtil.subBefore(s, ".0", true); + } else { + val = Convert.toStr(val); + } + } else if ((Integer.TYPE == fieldType) || (Integer.class == fieldType)) { + val = Convert.toInt(val); + } else if ((Long.TYPE == fieldType) || (Long.class == fieldType)) { + val = Convert.toLong(val); + } else if ((Double.TYPE == fieldType) || (Double.class == fieldType)) { + val = Convert.toDouble(val); + } else if ((Float.TYPE == fieldType) || (Float.class == fieldType)) { + val = Convert.toFloat(val); + } else if (BigDecimal.class == fieldType) { + val = Convert.toBigDecimal(val); + } else if (Date.class == fieldType) { + if (val instanceof String) { + val = DateUtils.parseDate(val); + } else if (val instanceof Double) { + val = DateUtil.getJavaDate((Double) val); + } + } + if (!StrUtil.isEmptyIfStr(fieldType)) { + Excel attr = field.getAnnotation(Excel.class); + String propertyName = field.getName(); + if (StrUtil.isNotEmpty(attr.targetAttr())) { + propertyName = field.getName() + "." + attr.targetAttr(); + } else if (StrUtil.isNotEmpty(attr.convertExp())) { + val = reverseByExp(String.valueOf(val), attr.convertExp()); + } + ReflectUtil.setFieldValue(entity, propertyName, val); + } + } + list.add(entity); + } + } + return list; + } + /** + * 获取单元格值 + * + * @param row 获取的行 + * @param column 获取单元格列号 + * @return 单元格值 + */ + public Object getCellValue(Row row, int column) { + if (row == null) { + return row; + } + Object val = ""; + try { + Cell cell = row.getCell(column); + if (cell != null) { + if (cell.getCellTypeEnum() == CellType.NUMERIC || cell.getCellTypeEnum() == CellType.FORMULA) { + val = cell.getNumericCellValue(); + if (HSSFDateUtil.isCellDateFormatted(cell)) { + val = DateUtil.getJavaDate((Double) val); // POI Excel 日期格式转换 + } else { + if ((Double) val % 1 > 0) { + val = new DecimalFormat("0.00").format(val); + } else { + val = new DecimalFormat("0").format(val); + } + } + } else if (cell.getCellTypeEnum() == CellType.STRING) { + val = cell.getStringCellValue(); + } else if (cell.getCellTypeEnum() == CellType.BOOLEAN) { + val = cell.getBooleanCellValue(); + } else if (cell.getCellTypeEnum() == CellType.ERROR) { + val = cell.getErrorCellValue(); + } + + } + } catch (Exception e) { + return val; + } + return val; + } + /** + * 反向解析值 男=0,女=1,未知=2 + * + * @param propertyValue 参数值 + * @param converterExp 翻译注解 + * @return 解析后值 + * @throws Exception + */ + public static String reverseByExp(String propertyValue, String converterExp) throws Exception { + try { + String[] convertSource = converterExp.split(","); + for (String item : convertSource) { + String[] itemArray = item.split("="); + if (itemArray[1].equals(propertyValue)) { + return itemArray[0]; + } + } + } catch (Exception e) { + throw e; + } + return propertyValue; + } + +}