Commit c7dc6680 by yangll

合并1.60.0分支到主干

git-svn-id: svn://192.168.3.233/frms/code/car-service/trunk/car-service@35443 aeb6102e-e053-11e5-9fec-f9ebc45caf4b
1 parent 48023f41
Showing 71 changed files with 4568 additions and 482 deletions
...@@ -68,6 +68,11 @@ ...@@ -68,6 +68,11 @@
<version>1.2.0-SNAPSHOT</version> <version>1.2.0-SNAPSHOT</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>3.1.1</version>
</dependency>
<dependency>
<groupId>org.jasypt</groupId> <groupId>org.jasypt</groupId>
<artifactId>jasypt</artifactId> <artifactId>jasypt</artifactId>
<version>1.9.3</version> <version>1.9.3</version>
...@@ -78,6 +83,7 @@ ...@@ -78,6 +83,7 @@
<artifactId>ore-jms</artifactId> <artifactId>ore-jms</artifactId>
<version>2.2.0-SNAPSHOT</version> <version>2.2.0-SNAPSHOT</version>
</dependency> </dependency>
</dependencies> </dependencies>
<build> <build>
......
...@@ -9,6 +9,7 @@ import org.springframework.boot.web.servlet.support.SpringBootServletInitializer ...@@ -9,6 +9,7 @@ import org.springframework.boot.web.servlet.support.SpringBootServletInitializer
import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients; import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.ComponentScan;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.annotation.EnableTransactionManagement; import org.springframework.transaction.annotation.EnableTransactionManagement;
/** /**
...@@ -27,6 +28,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement; ...@@ -27,6 +28,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
@EnableTransactionManagement @EnableTransactionManagement
@EnableFeignClients(basePackages = {"com.glsx.common.feign.client"}) @EnableFeignClients(basePackages = {"com.glsx.common.feign.client"})
@MapperScan(basePackages={"com.glsx.ordercenter.mapper"}) @MapperScan(basePackages={"com.glsx.ordercenter.mapper"})
@EnableScheduling
public class Application extends SpringBootServletInitializer { public class Application extends SpringBootServletInitializer {
/** /**
......
package com.glsx.ordercenter.common;
import java.lang.annotation.*;
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface PermissionControl {
/**
* 要关联的表名
* @return String
*/
String tableName() default "" ;
/**
* 表的别名
* @return String
*/
String tableAlias() default "";
/**
* 关联的字段名
* @return String
*/
String columnName() default "id";
/**
* 权限控制条件字段参数名称
* @return String
*/
String fieldName() default "id";
/**
* 参数的下标,从2开始,一般的分页查询查询条件都是从第二个开始的(多个参数时使用)
* @return int
*/
int paramIndex() default 2;
}
...@@ -115,6 +115,7 @@ public enum ResultCodeEnum { ...@@ -115,6 +115,7 @@ public enum ResultCodeEnum {
DEVICE_NOT_STOCK_IN_EDUN(5009, "未在虎哥e盾入库"), DEVICE_NOT_STOCK_IN_EDUN(5009, "未在虎哥e盾入库"),
DEVICE_NOT_REPLACED(5010, "更换或者重新安装设备,设备号与故障设备号不能相同"), DEVICE_NOT_REPLACED(5010, "更换或者重新安装设备,设备号与故障设备号不能相同"),
DEVICE_GPS_VERIFY_FAIL(5011, "设备GPS定位验证失败"), DEVICE_GPS_VERIFY_FAIL(5011, "设备GPS定位验证失败"),
DEVICE_OWNERSHIP_FAIL(5012, "部分设备归属修改失败"),
/** /**
* 订货单相关 * 订货单相关
...@@ -129,6 +130,13 @@ public enum ResultCodeEnum { ...@@ -129,6 +130,13 @@ public enum ResultCodeEnum {
INDENT_NOT_MATCH(5107, "不是当前用户的订货单,不能确认收货"), INDENT_NOT_MATCH(5107, "不是当前用户的订货单,不能确认收货"),
INDENT_LOGISTICS_NOT_EXIST(5108, "订货单物流信息不存在"), INDENT_LOGISTICS_NOT_EXIST(5108, "订货单物流信息不存在"),
INDENT_CAN_NOT_CANCEL(5109, "订货单已发货,不允许取消"), INDENT_CAN_NOT_CANCEL(5109, "订货单已发货,不允许取消"),
INDENT_DEVICE_NOT_EXIST(5110, "订货单导入的设备为空"),
DEVICE_NOT_EXIST(5111, "设备不存在"),
SECONDMENT_NOT_EXIST(5112, "借调单不存在"),
INDENT_DEVICE_ERROR_EXIST(5113, "收货失败,请联系运营人员"),
/** /**
* 库存相关 * 库存相关
*/ */
...@@ -148,6 +156,11 @@ public enum ResultCodeEnum { ...@@ -148,6 +156,11 @@ public enum ResultCodeEnum {
RECONCILIATION_AUDIT(5401, "有对账详单被运营审核,不支持重新生成"), RECONCILIATION_AUDIT(5401, "有对账详单被运营审核,不支持重新生成"),
/** /**
* 借调单相关
*/
SECONDMENT_DEVICE_NOT_EXIST(5500, "借调单导入的设备为空"),
/**
* 大搜车相关 * 大搜车相关
*/ */
SOUCHE_SIGN_ERROR(1, "签名错误"), SOUCHE_SIGN_ERROR(1, "签名错误"),
......
package com.glsx.ordercenter.constants;
public enum SecondmentStatusEnum {
SECONDMENT_UNCHECKED(10, "待审核"),
SECONDMENT_WAITDELIVER(20, "待发货"),
SECONDMENT_DELIVERED(30, "待收货"),
SECONDMENT_COMPLETE(40, "已完成"),
SECONDMENT_CANCEL(50, "已取消"),
;
/**
* 借调单状态
*/
private int secondmentStatus;
/**
* 状态对应的信息
*/
private String msg;
private SecondmentStatusEnum(int secondmentStatus, String msg) {
this.secondmentStatus = secondmentStatus;
this.msg = msg;
}
public int getSecondmentStatus() {
return secondmentStatus;
}
public void setSecondmentStatus(int secondmentStatus) {
this.secondmentStatus = secondmentStatus;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
}
...@@ -70,8 +70,28 @@ public class DeviceController { ...@@ -70,8 +70,28 @@ public class DeviceController {
return new ResultObject(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMsg()); return new ResultObject(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMsg());
} }
/**
* 订货单批量添加设备以及相关验证
*/
@RequestMapping(value = "/indentNoBatchInsertDevice", method = { RequestMethod.GET, RequestMethod.POST })
public ResultObject indentNoBatchInsertDevice(HttpServletRequest request,String indentNo) {
if (StringUtils.isEmpty(indentNo)) {
return new ResultObject(ResultCodeEnum.PARAM_ERROR.getCode(), ResultCodeEnum.PARAM_ERROR.getMsg());
}
return deviceService.indentNoBatchInsertDevice(indentNo,request);
}
/**
* 订货单批量添加设备以及相关验证
*/
@RequestMapping(value = "/secondmentBatchInsertDevice", method = { RequestMethod.GET, RequestMethod.POST })
public ResultObject secondmentBatchInsertDevice(HttpServletRequest request,String secondmentNo) {
if (StringUtils.isEmpty(secondmentNo)) {
return new ResultObject(ResultCodeEnum.PARAM_ERROR.getCode(), ResultCodeEnum.PARAM_ERROR.getMsg());
}
int userId=UserUtils.getUserId(request);
return deviceService.secondmentBatchInsertDevice(secondmentNo,userId);
}
} }
package com.glsx.ordercenter.controller; package com.glsx.ordercenter.controller;
import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import com.glsx.common.utils.PropertiesUtil;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
...@@ -142,7 +144,42 @@ public class DeviceRepertoryController { ...@@ -142,7 +144,42 @@ public class DeviceRepertoryController {
page.setTotalCount((int) pages.getTotal()); page.setTotalCount((int) pages.getTotal());
result.put("page", page); result.put("page", page);
result.put("items", list); result.put("items", list);
result.put("deviceNumWarn", checkRepertoryStockNum((list.size())));
int count = 0;
int stockDayWarn = Integer.parseInt(PropertiesUtil.getProperty("repertory.stock.day.warn"));
Date now = new Date();
for (SysDevice device : list) {
long subTime = (now.getTime() - device.getStockTime().getTime())/(24 * 60 * 60 * 1000);
if (subTime > stockDayWarn) {
count++;
}
}
result.put("deviceDayWarn", checkRepertoryStockDayNum(count));
return new ResultObject(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMsg(), result); return new ResultObject(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMsg(), result);
} }
/*
检查服务商库存/下属技工库存是否小于阈值,小于则提醒
*/
public String checkRepertoryStockNum(Integer deviceNum) {
if (deviceNum == null) {
deviceNum = 0;
}
int stockNumWarn = Integer.parseInt(PropertiesUtil.getProperty("repertory.stock.num.warn"));
if (deviceNum < stockNumWarn) {
return "库存<" + stockNumWarn;
}
return null;
}
/*
检查服务商库存/下属技工库存入库时间是否大于阈值,大于则提醒
*/
public String checkRepertoryStockDayNum(Integer deviceNum) {
if (deviceNum <= 0) {
return null;
}
int stockDayWarn = Integer.parseInt(PropertiesUtil.getProperty("repertory.stock.day.warn"));
return "库龄>" + stockDayWarn + "天:" + deviceNum + "台";
}
} }
...@@ -8,15 +8,15 @@ import java.util.Map; ...@@ -8,15 +8,15 @@ import java.util.Map;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.validation.groups.Default; import javax.validation.groups.Default;
import com.glsx.ordercenter.dto.IndentImportDeviceReq;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult; import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.glsx.common.annotation.AuthCheck; import com.glsx.common.annotation.AuthCheck;
...@@ -31,6 +31,7 @@ import com.glsx.ordercenter.pojo.SysIndent; ...@@ -31,6 +31,7 @@ import com.glsx.ordercenter.pojo.SysIndent;
import com.glsx.ordercenter.pojo.SysIndentLog; import com.glsx.ordercenter.pojo.SysIndentLog;
import com.glsx.ordercenter.pojo.SysIndentLogistics; import com.glsx.ordercenter.pojo.SysIndentLogistics;
import com.glsx.ordercenter.service.IndentService; import com.glsx.ordercenter.service.IndentService;
import org.springframework.web.multipart.MultipartFile;
/** /**
* *
...@@ -108,6 +109,9 @@ public class IndentController extends BaseController{ ...@@ -108,6 +109,9 @@ public class IndentController extends BaseController{
Map<String, String> errorMap = getErrors(bindingResult); Map<String, String> errorMap = getErrors(bindingResult);
return new ResultObject(ResultCodeEnum.PARAM_ERROR.getCode(), ResultCodeEnum.PARAM_ERROR.getMsg(), errorMap); return new ResultObject(ResultCodeEnum.PARAM_ERROR.getCode(), ResultCodeEnum.PARAM_ERROR.getMsg(), errorMap);
} }
if (indent.getIndentType() != null && indent.getIndentType() == 2 && CollectionUtils.isEmpty(indent.getDeviceNoList())) {
return new ResultObject(ResultCodeEnum.PARAM_ERROR.getCode(), ResultCodeEnum.PARAM_ERROR.getMsg());
}
ResultObject result = indentService.add(request, indent); ResultObject result = indentService.add(request, indent);
return result; return result;
} }
...@@ -183,6 +187,7 @@ public class IndentController extends BaseController{ ...@@ -183,6 +187,7 @@ public class IndentController extends BaseController{
* @param indentId * @param indentId
* @return * @return
*/ */
@AuthCheck
@RequestMapping(value = "/listIndentLog", method = RequestMethod.GET) @RequestMapping(value = "/listIndentLog", method = RequestMethod.GET)
public ResultObject listIndentLog(String indentId) { public ResultObject listIndentLog(String indentId) {
List<SysIndentLog> list=indentService.listIndentLog(indentId); List<SysIndentLog> list=indentService.listIndentLog(indentId);
...@@ -329,7 +334,60 @@ public class IndentController extends BaseController{ ...@@ -329,7 +334,60 @@ public class IndentController extends BaseController{
if (id == null) { if (id == null) {
return new ResultObject(ResultCodeEnum.PARAM_ERROR.getCode(), ResultCodeEnum.PARAM_ERROR.getMsg()); return new ResultObject(ResultCodeEnum.PARAM_ERROR.getCode(), ResultCodeEnum.PARAM_ERROR.getMsg());
} }
ResultObject result = indentService.confirmReceipt(request, id); ResultObject result = indentService.confirmReceipt(request, id, null);
return result; return result;
} }
/**
*
* @author zhangzc
* @Title: getImportDeviceDetail
* @Description: 订货单批量导入设备详情列表(PC)
* @param request
* @param indentId 订货单id
* @param deviceNo 设备号
* @return
* ResultObject
*
*/
@AuthCheck
@RequestMapping(value = "/getImportDeviceDetail", method = RequestMethod.GET)
public ResultObject getImportDeviceDetail(HttpServletRequest request, @RequestParam(defaultValue = "1") int pageIndex, @RequestParam(defaultValue = "10") int pageSize, Integer indentId, String deviceNo) {
Map<String, Object> result = new HashMap<String, Object>();
Page page = new Page(pageIndex, pageSize);
List<IndentImportDeviceReq> list = indentService.getImportDeviceDetail(page, indentId, deviceNo);
com.github.pagehelper.Page<IndentImportDeviceReq> pages = (com.github.pagehelper.Page<IndentImportDeviceReq>) list;
page.setTotalCount((int) pages.getTotal());
result.put("page", page);
result.put("items", list);
return new ResultObject(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMsg(), result);
}
/**
*
* @author zhangzc
* @Title: getImportDeviceDetail
* @Description: 删除批量导入的订货单设备(PC)
* @param id 订货单设备id
* @return
* ResultObject
*
*/
@AuthCheck
@RequestMapping(value = "/deleteImportDevice", method = RequestMethod.GET)
public ResultObject deleteImportDevice(Integer id) {
return new ResultObject(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMsg(), indentService.deleteIndentImportDeviceById(id));
}
@AuthCheck
@RequestMapping(value = "/importDeviceExcel", method = RequestMethod.POST)
public ResultObject checkImportIndentDevice(@RequestParam("file") MultipartFile file) {
return new ResultObject(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMsg(), indentService.checkImportIndentDevice(file));
}
@InitBinder
public void initListBinder(WebDataBinder binder) {
// 设置需要包裹的元素个数,默认为256
binder.setAutoGrowCollectionLimit(5500);
}
} }
...@@ -22,6 +22,7 @@ import com.glsx.ordercenter.dto.req.*; ...@@ -22,6 +22,7 @@ import com.glsx.ordercenter.dto.req.*;
import com.glsx.ordercenter.exception.BusinessException; import com.glsx.ordercenter.exception.BusinessException;
import com.glsx.ordercenter.pojo.*; import com.glsx.ordercenter.pojo.*;
import com.glsx.ordercenter.service.*; import com.glsx.ordercenter.service.*;
import com.glsx.plat.core.web.R;
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.validation.BindingResult; import org.springframework.validation.BindingResult;
...@@ -1259,4 +1260,19 @@ public class OrderController extends BaseController { ...@@ -1259,4 +1260,19 @@ public class OrderController extends BaseController {
logger.info("==== /getDeviceReuse result: {}", JSON.toJSONString(deviceReuseFlag)); logger.info("==== /getDeviceReuse result: {}", JSON.toJSONString(deviceReuseFlag));
return new ResultObject(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMsg(), deviceReuseFlag); return new ResultObject(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMsg(), deviceReuseFlag);
} }
/**
* 工单完成时校验车架号和设备号
*/
@RequestMapping(value = "/checkVinAndSn", method = {RequestMethod.POST, RequestMethod.GET})
public R checkVinAndSn(Integer orderId, Integer serviceItemId) {
super.logInfo("==== /order/checkVinAndSn param:orderId:{};serviceItemId:{}", orderId, serviceItemId);
Map<String, Object> resultMap = orderService.checkVinAndSn(orderId,serviceItemId);
R result = R.ok().data(resultMap);
super.logInfo("==== /order/checkVinAndSn result", result);
return result;
}
} }
...@@ -20,33 +20,13 @@ import com.glsx.common.utils.StringUtils; ...@@ -20,33 +20,13 @@ import com.glsx.common.utils.StringUtils;
import com.glsx.common.utils.UserUtils; import com.glsx.common.utils.UserUtils;
import com.glsx.ordercenter.constants.*; import com.glsx.ordercenter.constants.*;
import com.glsx.ordercenter.dto.*; import com.glsx.ordercenter.dto.*;
import com.glsx.ordercenter.dto.req.AuditOrderQueryReq; import com.glsx.ordercenter.dto.req.*;
import com.glsx.ordercenter.dto.req.CarOrderQueryReq;
import com.glsx.ordercenter.dto.req.DeliveryQueryReq;
import com.glsx.ordercenter.dto.req.InsuranceReq;
import com.glsx.ordercenter.dto.req.OrderReportReq;
import com.glsx.ordercenter.dto.req.ReconciliationListQuery;
import com.glsx.ordercenter.dto.resp.ExportReconciliationVo; import com.glsx.ordercenter.dto.resp.ExportReconciliationVo;
import com.glsx.ordercenter.dto.resp.InsuranceResp; import com.glsx.ordercenter.dto.resp.InsuranceResp;
import com.glsx.ordercenter.exception.BusinessException; import com.glsx.ordercenter.exception.BusinessException;
import com.glsx.ordercenter.exception.SysException; import com.glsx.ordercenter.exception.SysException;
import com.glsx.ordercenter.pojo.*; import com.glsx.ordercenter.pojo.*;
import com.glsx.ordercenter.service.AuditOrderService; import com.glsx.ordercenter.service.*;
import com.glsx.ordercenter.service.CarOrderService;
import com.glsx.ordercenter.service.DeliveryService;
import com.glsx.ordercenter.service.DeviceRepertoryService;
import com.glsx.ordercenter.service.IAreaService;
import com.glsx.ordercenter.service.IDictionaryDataService;
import com.glsx.ordercenter.service.IOrderBiddingService;
import com.glsx.ordercenter.service.IOrderExceptionService;
import com.glsx.ordercenter.service.IOrderService;
import com.glsx.ordercenter.service.IUnknownOrderService;
import com.glsx.ordercenter.service.IndentService;
import com.glsx.ordercenter.service.InsuranceService;
import com.glsx.ordercenter.service.OperationAdvanceService;
import com.glsx.ordercenter.service.OrderReportService;
import com.glsx.ordercenter.service.ReconciliationDetailService;
import com.glsx.ordercenter.service.ReconciliationService;
import com.glsx.ordercenter.utils.OrderUtil; import com.glsx.ordercenter.utils.OrderUtil;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
...@@ -113,6 +93,9 @@ public class ReportController extends BaseReportController { ...@@ -113,6 +93,9 @@ public class ReportController extends BaseReportController {
@Autowired @Autowired
private OrderUtil orderUtil; private OrderUtil orderUtil;
@Autowired
private SysSecondmentService secondmentService;
@RequestMapping(value = "/exportUnknownOrder", method = {RequestMethod.GET, RequestMethod.POST}) @RequestMapping(value = "/exportUnknownOrder", method = {RequestMethod.GET, RequestMethod.POST})
public void exportUnknownOrder(HttpServletRequest request, HttpServletResponse response, public void exportUnknownOrder(HttpServletRequest request, HttpServletResponse response,
SysOrder order) { SysOrder order) {
...@@ -408,6 +391,41 @@ public class ReportController extends BaseReportController { ...@@ -408,6 +391,41 @@ public class ReportController extends BaseReportController {
} }
} }
@RequestMapping(value = "/exportServiceRepertoryDetail", method = {RequestMethod.GET, RequestMethod.POST})
public void exportServiceRepertoryDetail(HttpServletRequest request, HttpServletResponse response,
String deviceType, String deviceNo, Integer userId) {
List<SysDevice> list = deviceRepertoryService.getServiceRepertoryDetail(userId, deviceType, deviceNo);
if (list.size() > 10000) {
throw SysException.create(ResultCodeEnum.EXPORT_OEDER_OUTOF_NUMBER.getCode(),
ResultCodeEnum.EXPORT_OEDER_OUTOF_NUMBER.getMsg());
}
try {
this.exportObject(response, list, "导出服务商库存详情");
} catch (IOException e) {
this.logger.info("导出服务商库存详情异常");
}
}
@RequestMapping(value = "/exportMechanicRepertoryDetail", method = {RequestMethod.GET, RequestMethod.POST})
public void exportMechanicRepertoryDetail(HttpServletRequest request, HttpServletResponse response,
String deviceType, String deviceNo, Integer serviceId, Integer mechanicId) {
List<SysDevice> list = deviceRepertoryService.getMechanicRepertoryDetail(serviceId, deviceType, deviceNo, mechanicId);
if (list.size() > 10000) {
throw SysException.create(ResultCodeEnum.EXPORT_OEDER_OUTOF_NUMBER.getCode(),
ResultCodeEnum.EXPORT_OEDER_OUTOF_NUMBER.getMsg());
}
List<MechanicRepertoryDeviceExport> exportList = new ArrayList<>();
for (SysDevice device : list) {
MechanicRepertoryDeviceExport export = new MechanicRepertoryDeviceExport();
BeanUtils.copyProperties(device, export);
exportList.add(export);
}
try {
this.exportObject(response, exportList, "导出下属技工库存详情");
} catch (IOException e) {
this.logger.info("导出下属技工库存详情异常");
}
}
@RequestMapping(value = "/exportIndent", method = {RequestMethod.GET, RequestMethod.POST}) @RequestMapping(value = "/exportIndent", method = {RequestMethod.GET, RequestMethod.POST})
public void exporRepertoryList(HttpServletRequest request, HttpServletResponse response, public void exporRepertoryList(HttpServletRequest request, HttpServletResponse response,
...@@ -422,6 +440,7 @@ public class ReportController extends BaseReportController { ...@@ -422,6 +440,7 @@ public class ReportController extends BaseReportController {
IndentExport indentExport = new IndentExport(); IndentExport indentExport = new IndentExport();
BeanUtils.copyProperties(sysIndent, indentExport); BeanUtils.copyProperties(sysIndent, indentExport);
indentExport.setIndentStatus(this.tranceIndentStatu(sysIndent.getIndentStatus())); indentExport.setIndentStatus(this.tranceIndentStatu(sysIndent.getIndentStatus()));
indentExport.setUsername(this.tranceIndentUsername(sysIndent));
exports.add(indentExport); exports.add(indentExport);
} }
try { try {
...@@ -432,6 +451,39 @@ public class ReportController extends BaseReportController { ...@@ -432,6 +451,39 @@ public class ReportController extends BaseReportController {
} }
@RequestMapping(value = "/exportSecondment", method = {RequestMethod.GET, RequestMethod.POST})
public void exportSecondmentList(HttpServletRequest request, HttpServletResponse response,
SecondmentQueryReq req) {
List<SecondmentExport> exports = new ArrayList<>();
Integer secondmentStatus = req.getSecondmentStatus();
/**
* 50定义为取消
*/
if (secondmentStatus != null && 50 == secondmentStatus) {
req.setIsCanceled(1);
req.setSecondmentStatus(null);
} else if (secondmentStatus != null) {
req.setIsCanceled(0);
}
List<SecondmentDto> list = this.secondmentService.getListByPage(null, req);
if (list.size() > 10000) {
throw SysException.create(ResultCodeEnum.EXPORT_OEDER_OUTOF_NUMBER.getCode(),
ResultCodeEnum.EXPORT_OEDER_OUTOF_NUMBER.getMsg());
}
for (SecondmentDto dto : list) {
SecondmentExport secondmentExport = new SecondmentExport();
BeanUtils.copyProperties(dto, secondmentExport);
secondmentExport.setSecondmentStatus(tranceIndentStatu(dto.getSecondmentStatus()));
secondmentExport.setUsername(tranceSecondmentUsername(dto));
exports.add(secondmentExport);
}
try {
this.exportObject(response, exports, "导出借调单列表");
} catch (IOException e) {
this.logger.info("导出借调单列表异常");
}
}
private String tranceIndentStatu(Integer indentStatu) { private String tranceIndentStatu(Integer indentStatu) {
if (indentStatu == 10) { if (indentStatu == 10) {
return "待审核订单"; return "待审核订单";
...@@ -451,6 +503,29 @@ public class ReportController extends BaseReportController { ...@@ -451,6 +503,29 @@ public class ReportController extends BaseReportController {
return ""; return "";
} }
private String tranceIndentUsername(SysIndent indent) {
if (indent.getUser() != null) {
if (indent.getUser().getUserType() == BizConstants.USER_TYPE_MECHANIC) {
return indent.getUser().getName();
} else {
return indent.getUsername();
}
}
return "";
}
private String tranceSecondmentUsername(SecondmentDto secondmentDto) {
if (secondmentDto != null) {
if (secondmentDto.getUserType() == BizConstants.USER_TYPE_MECHANIC) {
return secondmentDto.getName();
} else {
return secondmentDto.getUsername();
}
}
return "";
}
@Autowired @Autowired
private IOrderBiddingService biddingOrderService; private IOrderBiddingService biddingOrderService;
......
package com.glsx.ordercenter.controller;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.glsx.common.annotation.AuthCheck;
import com.glsx.common.constants.ResultObject;
import com.glsx.common.feign.client.CommonClient;
import com.glsx.common.feign.client.UserClient;
import com.glsx.common.utils.Page;
import com.glsx.common.utils.UserUtils;
import com.glsx.ordercenter.constants.ResultCodeEnum;
import com.glsx.ordercenter.dto.SecondmentDto;
import com.glsx.ordercenter.dto.req.InsertSecondmentReq;
import com.glsx.ordercenter.dto.req.SecondmentImportDeviceReq;
import com.glsx.ordercenter.dto.req.SecondmentQueryReq;
import com.glsx.ordercenter.dto.req.UpdateSecondmentReq;
import com.glsx.ordercenter.pojo.*;
import com.glsx.ordercenter.service.SysSecondmentService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping(value="/secondment")
public class SysSecondmentController extends BaseController{
private Logger logger = LoggerFactory.getLogger(getClass());
@Autowired
private SysSecondmentService secondmentService;
@Autowired
private CommonClient commonClient;
@Autowired
private UserClient userClient;
@AuthCheck
@RequestMapping(value="/getListByPage", method=RequestMethod.GET)
public ResultObject getListByPage(@RequestParam(defaultValue = "1") int pageIndex, @RequestParam(defaultValue = "10") int pageSize, SecondmentQueryReq req) {
Map<String, Object> result = new HashMap<String, Object>();
if (req != null) {
logger.info("借调单列表搜索传递的参数:" + JSONObject.toJSONString(req));
}
Integer secondmentStatus = req.getSecondmentStatus();
/**
* 50定义为取消
*/
if (secondmentStatus != null && 50 == secondmentStatus) {
req.setIsCanceled(1);
req.setSecondmentStatus(null);
} else if (secondmentStatus != null) {
req.setIsCanceled(0);
}
Page page = new Page(pageIndex, pageSize);
if (req.getPageSize() != null) {
page = new Page(req.getPageIndex(), req.getPageSize());
}
List<SecondmentDto> list = secondmentService.getListByPage(page, req);
com.github.pagehelper.Page<SecondmentDto> pages = (com.github.pagehelper.Page<SecondmentDto>) list;
page.setTotalCount((int) pages.getTotal());
result.put("page", page);
result.put("items", list);
return new ResultObject(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMsg(), result);
}
@AuthCheck
@RequestMapping(value="/getDetail", method=RequestMethod.GET)
public ResultObject getDetail(Integer id) {
SecondmentDto secondmentDto = secondmentService.getDetail(id);
return new ResultObject(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMsg(), secondmentDto);
}
@AuthCheck
@RequestMapping(value="/getDeviceBySecondmentNo", method=RequestMethod.GET)
public ResultObject getDeviceBySecondmentNo(Page page,SysSecondmentImportDevice secondmentImportDevice) {
Map<String, Object> result = new HashMap<String, Object>(16);
PageHelper.startPage(page.getPageIndex(), page.getPageSize(), true);
List<SysSecondmentImportDevice> list = secondmentService.getDeviceBySecondmentNo(secondmentImportDevice);
com.github.pagehelper.Page<SysSecondmentImportDevice> pages = (com.github.pagehelper.Page<SysSecondmentImportDevice>) list;
page.setTotalCount((int) pages.getTotal());
result.put("page", page);
result.put("items", list);
return new ResultObject(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMsg(), result);
}
@AuthCheck
@RequestMapping(value="/getListByUserId", method=RequestMethod.GET)
public ResultObject getListByUserId(@RequestParam(defaultValue = "1") int pageIndex, @RequestParam(defaultValue = "10") int pageSize, SecondmentQueryReq req) {
Map<String, Object> result = new HashMap<String, Object>();
if (req != null) {
logger.info("小程序端借调单列表搜索传递的参数:" + JSONObject.toJSONString(req));
}
Integer secondmentStatus = req.getSecondmentStatus();
/**
* 50定义为取消
*/
if (secondmentStatus != null && 50 == secondmentStatus) {
req.setIsCanceled(1);
req.setSecondmentStatus(null);
} else if (secondmentStatus != null) {
req.setIsCanceled(0);
}
Page page = new Page(pageIndex, pageSize);
if (req.getPageSize() != null) {
page = new Page(req.getPageIndex(), req.getPageSize());
}
List<SecondmentDto> list = secondmentService.getListByUserId(page, req);
com.github.pagehelper.Page<SecondmentDto> pages = (com.github.pagehelper.Page<SecondmentDto>) list;
page.setTotalCount((int) pages.getTotal());
result.put("page", page);
result.put("items", list);
return new ResultObject(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMsg(), result);
}
@AuthCheck
@RequestMapping(value = "/importSecondmentDevice", method = RequestMethod.POST)
public ResultObject checkImportSecondmentDevice(HttpServletRequest request, @Validated SecondmentImportDeviceReq importDeviceReq) {
return new ResultObject(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMsg(), secondmentService.checkImportSecondmentDevice(request, importDeviceReq));
}
@AuthCheck
@RequestMapping(value = "/addSecondment", method = RequestMethod.POST)
public ResultObject addSecondment(HttpServletRequest request, @Validated InsertSecondmentReq secondmentReq) {
return new ResultObject(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMsg(), secondmentService.addSecondment(request, secondmentReq));
}
@AuthCheck
@RequestMapping(value = "/updateSecondment", method = RequestMethod.POST)
public ResultObject updateSecondment(HttpServletRequest request, @Validated UpdateSecondmentReq secondmentReq) {
return new ResultObject(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMsg(), secondmentService.updateSecondment(request, secondmentReq));
}
@AuthCheck
@RequestMapping(value = "/deleteSecondmentDevice", method = RequestMethod.GET)
public ResultObject deleteSecondmentDevice(Integer id) {
return new ResultObject(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMsg(), secondmentService.deleteSecondmentDeviceById(id));
}
@AuthCheck
@RequestMapping(value = "/dispatchSecondment", method = RequestMethod.POST)
public ResultObject dispatchSecondment(HttpServletRequest request, SysIndentLogistics sysIndentLogistics) {
sysIndentLogistics.setOrderType(2);
Integer result = secondmentService.dispatchSecondment(request, sysIndentLogistics);
//发送短信提示已发货(发给提单的人)
if(result != null ){
SecondmentDto secondmentDto = secondmentService.getDetail(sysIndentLogistics.getIndentId());
JSONObject userObj = userClient.getUserById(secondmentDto.getSecondedId());
JSONObject data = userObj.getJSONObject("data");
String phone = data.getString("phoneNumber");
JSONObject obj = commonClient.sendDeviceSms(phone, secondmentDto.getSecondmentNo());
if (obj != null && obj.getIntValue("code") != com.glsx.common.constants.ResultCodeEnum.SUCCESS.getCode()) {
return new ResultObject(obj.getIntValue("code"), obj.getString("message"));
}
}
return new ResultObject(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMsg());
}
@AuthCheck
@RequestMapping(value = "/listSecondmentLog", method = RequestMethod.GET)
public ResultObject getSecondmentLogList(Integer secondmentId) {
List<SysSecondmentLog> list = secondmentService.getSecondmentLogList(secondmentId);
return new ResultObject(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMsg(), list);
}
@InitBinder
public void initListBinder(WebDataBinder binder) {
// 设置需要包裹的元素个数,默认为256
binder.setAutoGrowCollectionLimit(5500);
}
}
...@@ -2,6 +2,7 @@ package com.glsx.ordercenter.dto; ...@@ -2,6 +2,7 @@ package com.glsx.ordercenter.dto;
import com.glsx.excel.poi.annotation.ExcelColumn; import com.glsx.excel.poi.annotation.ExcelColumn;
import com.glsx.excel.poi.annotation.ExcelExport; import com.glsx.excel.poi.annotation.ExcelExport;
import lombok.Data;
/** /**
* @author duanht * @author duanht
...@@ -11,6 +12,7 @@ import com.glsx.excel.poi.annotation.ExcelExport; ...@@ -11,6 +12,7 @@ import com.glsx.excel.poi.annotation.ExcelExport;
* @Description $库存列表 * @Description $库存列表
* @date 2019/6/3 15:13 * @date 2019/6/3 15:13
*/ */
@Data
@ExcelExport @ExcelExport
public class DeviceRepertoryReq { public class DeviceRepertoryReq {
...@@ -39,67 +41,19 @@ public class DeviceRepertoryReq { ...@@ -39,67 +41,19 @@ public class DeviceRepertoryReq {
private String deviceType; private String deviceType;
public String getUsername() { // 服务商库存数量阈值警告
return username; private String serviceDeviceNumWarn;
}
public void setUsername(String username) { // 服务商库存入库时间阈值警告
this.username = username; private String serviceDeviceDayWarn;
}
public String getDeviceType() { // 下属技工存数量阈值警告
return deviceType; private String mechanicDeviceNumWarn;
}
public void setDeviceType(String deviceType) { // 下属技工库存入库时间阈值警告
this.deviceType = deviceType; private String mechanicDeviceDayWarn;
}
public Integer getUserId() { private Integer userType;
return userId;
}
public void setUserId(Integer userId) {
this.userId = userId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDeviceName() {
return deviceName;
}
public void setDeviceName(String deviceName) {
this.deviceName = deviceName;
}
public Integer getServiceDeviceNum() {
return serviceDeviceNum;
}
public void setServiceDeviceNum(Integer serviceDeviceNum) {
this.serviceDeviceNum = serviceDeviceNum;
}
public Integer getSendDeviceNum() {
return sendDeviceNum;
}
public void setSendDeviceNum(Integer sendDeviceNum) {
this.sendDeviceNum = sendDeviceNum;
}
public Integer getMechanicDeviceNum() {
return mechanicDeviceNum;
}
public void setMechanicDeviceNum(Integer mechanicDeviceNum) {
this.mechanicDeviceNum = mechanicDeviceNum;
}
} }
package com.glsx.ordercenter.dto;
import com.alibaba.excel.annotation.ExcelProperty;
import lombok.Data;
import java.io.Serializable;
/**
* @title IndentImportDeviceDataExportModel
* @Author zhangzc
* @Description 订货单批量导入设备
* @Date 2024/4/10 15:15
**/
@Data
public class IndentImportDeviceDataExportModel implements Serializable {
private static final long serialVersionUID = -5449399709572310476L;
@ExcelProperty(value = "设备号")
private String deviceNo;
}
package com.glsx.ordercenter.dto;
import com.alibaba.excel.annotation.ExcelProperty;
import com.glsx.excel.poi.annotation.ExcelExport;
import lombok.Data;
import java.io.Serializable;
/**
* @title IndentImportDeviceDataExportModelImport
* @Author zhangzc
* @Description 订货单批量导入设备错误信息
* @Date 2024/4/10 16:19
**/
@Data
@ExcelExport
public class IndentImportDeviceDataExportModelImport implements Serializable {
private static final long serialVersionUID = 4156527327982218042L;
@ExcelProperty(value = "错误内容")
private String deviceNo;
@ExcelProperty(value = "备注")
private String importFailReason;
}
package com.glsx.ordercenter.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* @title IndentImportDeviceReq
* @Author zhangzc
* @Description 订货单批量导入设备详情
* @Date 2024/4/9 16:15
**/
@Data
public class IndentImportDeviceReq implements Serializable {
private static final long serialVersionUID = -2161602390043604984L;
@ApiModelProperty(notes = "id")
private Integer id;
@ApiModelProperty(notes = "设备类型")
private String deviceType;
@ApiModelProperty(notes = "设备类型名称")
private String deviceName;
@ApiModelProperty(notes = "设备号")
private String deviceNo;
@ApiModelProperty(notes = "导入时间")
private Date importTime;
}
package com.glsx.ordercenter.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
/**
* @title IndentImportDeviceResponse
* @Author zhangzc
* @Description 订货单批量导入设备返回信息
* @Date 2024/4/10 15:08
**/
@Data
public class IndentImportDeviceResponse implements Serializable {
private static final long serialVersionUID = 5333124670903207609L;
@ApiModelProperty(notes = "匹配成功总条数")
private Integer successCount;
@ApiModelProperty(notes = "匹配失败总条数")
private Integer errorCount;
@ApiModelProperty(notes = "匹配失败的url")
private String errUrl;
@ApiModelProperty(notes = "设备号列表")
private List<String> deviceNoList;
}
package com.glsx.ordercenter.dto;
import com.glsx.excel.poi.annotation.ExcelColumn;
import com.glsx.excel.poi.annotation.ExcelExport;
import lombok.Data;
import java.util.Date;
/**
* @title MechanicRepertoryDeviceExport
* @Author zhangzc
* @Description 下属技工库存详情
* @Date 2024/4/3 16:49
**/
@ExcelExport
@Data
public class MechanicRepertoryDeviceExport {
@ExcelColumn(value = "服务商名称",index = 0)
private String serviceName;
@ExcelColumn(value = "所属技工",index = 1)
private String name;
@ExcelColumn(value = "设备名称",index = 2)
private String deviceName;
@ExcelColumn(value = "设备号",index = 3)
private String deviceNo;
@ExcelColumn(value = "入库时间", index = 4, pattern = "yyyy-MM-dd HH:mm:ss")
private Date stockTime;
@ExcelColumn(value = "备注",index = 5)
private String remark;
}
package com.glsx.ordercenter.dto; package com.glsx.ordercenter.dto;
import lombok.Data;
import java.io.Serializable; import java.io.Serializable;
/** /**
...@@ -10,6 +12,7 @@ import java.io.Serializable; ...@@ -10,6 +12,7 @@ import java.io.Serializable;
* @Description $技工库存 * @Description $技工库存
* @date 2019/6/5 10:25 * @date 2019/6/5 10:25
*/ */
@Data
public class MechanicRepertoryReq implements Serializable { public class MechanicRepertoryReq implements Serializable {
/** /**
...@@ -25,35 +28,10 @@ public class MechanicRepertoryReq implements Serializable { ...@@ -25,35 +28,10 @@ public class MechanicRepertoryReq implements Serializable {
private Integer deviceNum; private Integer deviceNum;
public Integer getId() { // 技工存数量阈值警告
return id; private String deviceNumWarn;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPhoneNumber() {
return phoneNumber;
}
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
public Integer getDeviceNum() { // 技工库存入库时间阈值警告
return deviceNum; private String deviceDayWarn;
}
public void setDeviceNum(Integer deviceNum) {
this.deviceNum = deviceNum;
}
} }
package com.glsx.ordercenter.dto;
import com.glsx.ordercenter.pojo.SysArea;
import com.glsx.ordercenter.pojo.SysIndentLogistics;
import com.glsx.ordercenter.pojo.SysSecondment;
import com.glsx.ordercenter.pojo.SysSecondmentImportDevice;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
@Data
public class SecondmentDto extends SysSecondment {
private static final long serialVersionUID = 5960250385455923520L;
private String username;
private String deviceName;
private SysIndentLogistics sysIndentLogistics;
private SysArea sysArea;
/**
* 物流轨迹
*/
private Traces traces;
private String cancelOperatorName;
private String name;
private Integer userType;
@ApiModelProperty(notes = "借调单设备列表")
private List<SysSecondmentImportDevice> importDevices;
}
package com.glsx.ordercenter.dto;
import com.glsx.excel.poi.annotation.ExcelColumn;
import com.glsx.excel.poi.annotation.ExcelExport;
import lombok.Data;
import java.util.Date;
/**
* @title SecondmentExport
* @Author zhangzc
* @Description
* @Date 2024/4/11 15:45
**/
@Data
@ExcelExport
public class SecondmentExport {
@ExcelColumn(index = 0,value = "借调单号")
private String secondmentNo;
@ExcelColumn(index = 1,value = "借调时间",pattern = "yyyy-MM-dd HH:mm:ss")
private Date createTime;
@ExcelColumn(index = 2,value = "借调用户名称")
private String username;
@ExcelColumn(index = 3,value = "设备名称")
private String deviceName;
@ExcelColumn(index = 4,value = "数量")
private Integer secondmentAmount;
@ExcelColumn(index = 5,value = "借调单状态")
private String secondmentStatus;
}
package com.glsx.ordercenter.dto;
import com.alibaba.excel.annotation.ExcelProperty;
import com.glsx.excel.poi.annotation.ExcelExport;
import lombok.Data;
import java.io.Serializable;
/**
* @title SecondmentImportDeviceDataExportModelImport
* @Author zhangzc
* @Description 借调单批量导入设备错误信息
* @Date 2024/4/15 15:08
**/
@Data
@ExcelExport
public class SecondmentImportDeviceDataExportModelImport implements Serializable {
private static final long serialVersionUID = -5809347814892878445L;
@ExcelProperty(value = "错误内容")
private String deviceNo;
@ExcelProperty(value = "备注")
private String importFailReason;
}
package com.glsx.ordercenter.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
/**
* @title SecondmentImportDeviceResponse
* @Author zhangzc
* @Description 借调单批量导入设备返回信息
* @Date 2024/4/15 15:14
**/
@Data
public class SecondmentImportDeviceResponse implements Serializable {
private static final long serialVersionUID = -3734323326892100449L;
@ApiModelProperty(notes = "匹配成功总条数")
private Integer successCount;
@ApiModelProperty(notes = "匹配失败总条数")
private Integer errorCount;
@ApiModelProperty(notes = "匹配失败的url")
private String errUrl;
@ApiModelProperty(notes = "设备号列表")
private List<String> deviceNoList;
}
package com.glsx.ordercenter.dto.req;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.List;
/**
* @title InsertSecondmentReq
* @Author zhangzc
* @Description
* @Date 2024/4/15 20:11
**/
@Data
public class InsertSecondmentReq implements Serializable {
private static final long serialVersionUID = 7337327051887026997L;
@NotNull(message = "借调人id不能为空")
@ApiModelProperty(notes = "借调人id")
private Integer secondmentUserId;
@NotBlank(message = "设备类型不能为空")
@ApiModelProperty(notes = "设备类型")
private String deviceType;
@NotNull
@ApiModelProperty(notes = "设备号列表")
private List<String> deviceNoList;
@NotNull(message = "收货地址id不能为空")
@ApiModelProperty(notes = "收货地址id")
private Integer receiveAddressId;
@ApiModelProperty(notes = "备注")
private String remark;
}
package com.glsx.ordercenter.dto.req;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.web.multipart.MultipartFile;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.List;
/**
* @title SecondmentImportDeviceReq
* @Author zhangzc
* @Description
* @Date 2024/4/15 15:17
**/
@Data
public class SecondmentImportDeviceReq implements Serializable {
private static final long serialVersionUID = -2378594680227605725L;
@NotNull(message = "导入类型不能为空")
@ApiModelProperty(notes = "导入类型: 1-手动录入;2-文件导入")
private Integer exportType;
@NotNull(message = "借调人id不能为空")
@ApiModelProperty(notes = "借调人id")
private Integer secondmentUserId;
@NotBlank(message = "设备类型不能为空")
@ApiModelProperty(notes = "设备类型")
private String deviceType;
@ApiModelProperty(notes = "文件(exportType=2必传)")
private MultipartFile file;
@ApiModelProperty(notes = "设备号列表(exportType=1必传)")
private List<String> deviceNoList;
}
package com.glsx.ordercenter.dto.req;
import com.glsx.common.pojo.PagedReq;
import lombok.Data;
import lombok.ToString;
@Data
@ToString
public class SecondmentQueryReq extends PagedReq {
private static final long serialVersionUID = -6148990754937464349L;
/**
* 查询:开始时间
*/
private String beginDate;
/**
* 查询:结束时间
*/
private String endDate;
/**
* 订单状态10:待审核;20:待发货;30:待收货;40:已完成;
*/
private Integer secondmentStatus;
private Integer isCanceled;
private String username;
private Integer userId;
private String secondmentNo;
}
package com.glsx.ordercenter.dto.req;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.List;
/**
* @title UpdateSecondmentReq
* @Author zhangzc
* @Description
* @Date 2024/4/16 15:28
**/
@Data
public class UpdateSecondmentReq implements Serializable {
private static final long serialVersionUID = -3086503071645105621L;
@NotNull(message = "借调单id不能为空")
@ApiModelProperty(notes = "借调单id")
private Integer id;
@NotNull(message = "借调人id不能为空")
@ApiModelProperty(notes = "借调人id")
private Integer secondmentUserId;
@NotBlank(message = "设备类型不能为空")
@ApiModelProperty(notes = "设备类型")
private String deviceType;
@NotNull
@ApiModelProperty(notes = "设备号列表")
private List<String> deviceNoList;
@ApiModelProperty(notes = "收货地址id")
private Integer receiveAddressId;
@ApiModelProperty(notes = "备注")
private String remark;
}
package com.glsx.ordercenter.interceptor;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ReflectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.druid.sql.ast.SQLExpr;
import com.alibaba.druid.sql.ast.SQLStatement;
import com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr;
import com.alibaba.druid.sql.ast.expr.SQLBinaryOperator;
import com.alibaba.druid.sql.ast.statement.SQLSelect;
import com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock;
import com.alibaba.druid.sql.ast.statement.SQLSelectStatement;
import com.alibaba.druid.sql.parser.SQLExprParser;
import com.alibaba.druid.sql.parser.SQLParserUtils;
import com.alibaba.druid.sql.parser.SQLStatementParser;
import com.alibaba.druid.util.JdbcUtils;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.glsx.common.utils.UserUtils;
import com.glsx.ordercenter.common.PermissionControl;
import com.glsx.ordercenter.constants.BizConstants;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.cache.CacheKey;
import org.apache.ibatis.executor.Executor;
import org.apache.ibatis.mapping.BoundSql;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.mapping.ParameterMapping;
import org.apache.ibatis.mapping.SqlCommandType;
import org.apache.ibatis.plugin.*;
import org.apache.ibatis.reflection.MetaObject;
import org.apache.ibatis.session.Configuration;
import org.apache.ibatis.session.ResultHandler;
import org.apache.ibatis.session.RowBounds;
import org.apache.ibatis.type.TypeHandlerRegistry;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.regex.Matcher;
@Intercepts(
{
@Signature(type = Executor.class, method = "query", args = {MappedStatement.class, Object.class, RowBounds.class, ResultHandler.class}),
@Signature(type = Executor.class, method = "query", args = {MappedStatement.class, Object.class, RowBounds.class, ResultHandler.class, CacheKey.class, BoundSql.class}),
}
)
@Slf4j
public class PermissionControlInterceptor implements Interceptor {
@Override
public Object intercept(Invocation invocation) throws Throwable {
Object[] args = invocation.getArgs();
MappedStatement mappedStatement = (MappedStatement) args[0];
SqlCommandType sqlCommandType = mappedStatement.getSqlCommandType();
//获取参数,语句成立,表示sql语句有参数,参数格式是map形式
Object parameter = args.length > 1 ? args[1] : null;
//id为执行的mapper方法的全路径名,如com.xxx.xxxMapper.insertXxx
String sqlId = mappedStatement.getId();
Executor executor = (Executor) invocation.getTarget();
PermissionControl permissionControl = getAnnotation(sqlId);
// 非select语句直接过滤
if (!SqlCommandType.SELECT.equals(sqlCommandType) || permissionControl == null) {
return invocation.proceed();
}
Byte currentUserType = UserUtils.getCurrentUserType();
//登录信息为空或运营账号不用添加权限控制
if (currentUserType == null || BizConstants.USER_TYPE_ADMIN == currentUserType) {
return invocation.proceed();
}
Integer currentUserId = null;
if (BizConstants.USER_TYPE_MERCHANT == currentUserType) {
currentUserId = UserUtils.getCurrentUserId();
}
MappedStatement ms = (MappedStatement) args[0];
Object parameterObject = args[1];
RowBounds rowBounds = (RowBounds) args[2];
ResultHandler resultHandler = (ResultHandler) args[3];
CacheKey cacheKey;
BoundSql boundSql;
//由于逻辑关系,只会进入一次
if(args.length == 4){
//4 个参数时
boundSql = mappedStatement.getBoundSql(parameter);
cacheKey = executor.createCacheKey(ms, parameterObject, rowBounds, boundSql);
} else {
//6 个参数时
cacheKey = (CacheKey) args[4];
boundSql = (BoundSql) args[5];
}
//[BoundSql]封装mybatis最终产生的sql类
// BoundSql boundSql = mappedStatement.getBoundSql(parameter);
//获取节点的配置
Configuration configuration = mappedStatement.getConfiguration();
String sql = getSql(configuration, boundSql, sqlId, false);
String beforeSql = boundSql.getSql().replaceAll("[\\s]+", " ");
log.info("之前的sql {}", beforeSql);
String afterSql = contactConditions(beforeSql, permissionControl,parameter,currentUserId);
log.info("权限控制之后的sql {}", afterSql);
ReflectUtil.setFieldValue(boundSql, "sql", afterSql);
log.info("最终执行的sql {}", getSql(configuration, boundSql, sqlId, false));
//可以对参数做各种处理
// CacheKey cacheKey = executor.createCacheKey(ms, parameterObject, rowBounds, boundSql);
return executor.query(ms, parameterObject, rowBounds, resultHandler, cacheKey, boundSql);
}
private Object proceed(Invocation invocation, String sqlId, String sql) throws Throwable{
try {
//执行完上面的任务后,执行原有sql的执行过程
return invocation.proceed();
} catch (InvocationTargetException e) {
log.error("当前sql执行错误\n {} \n, 方法id ::: {}\n 执行sql ::: {}", e.getMessage(), sqlId, sql);
log.error("sql执行异常", e);
throw new RuntimeException("sql执行异常" + sqlId);
}
}
/**
* 获取Mapper类上带有自定义注解{@link PermissionControl}的方法
* 类上有{@link PermissionControl}注解的 方法上没有的话返回类上的
* 类上和方法上都有 {@link PermissionControl} 注解的话用方法上的
*
* @param sqlId mapper方法的全路径名
* @return PermissionControl
*/
private PermissionControl getAnnotation(String sqlId) {
PermissionControl permissionControl = null;
try {
//通过执行方法全路径获取Class对象
Class<?> classType = Class.forName(sqlId.substring(0, sqlId.lastIndexOf(".")));
// 如果类上有@PermissionControl注解的话直接返回
permissionControl = classType.getAnnotation(PermissionControl.class);
//获取当前截取的方法名称
String methodName = sqlId.substring(sqlId.lastIndexOf(".") + 1);
// 遍历类中所有方法名称,并if匹配上当前所拦截的方法
for (Method method : classType.getDeclaredMethods()) {
if (StrUtil.equals(methodName, method.getName())) {
// 判断方法上是否带有自定义@PermissionControl注解
return method.getAnnotation(PermissionControl.class);
}
}
} catch (ClassNotFoundException e) {
log.error("ClassNotFoundException!", e);
}
return permissionControl;
}
@SneakyThrows
private static String contactConditions(String sql, PermissionControl permissionControl, Object parameter, Integer currentUserId) {
SQLStatementParser parser = SQLParserUtils.createSQLStatementParser(sql, JdbcUtils.MYSQL);
List<SQLStatement> stmtList = parser.parseStatementList();
SQLStatement stmt = stmtList.get(0);
if (stmt instanceof SQLSelectStatement) {
StringBuffer constraintsBuffer = new StringBuffer();
String tableAlias = permissionControl.tableAlias();
if (StrUtil.isBlank(tableAlias)) {
tableAlias = permissionControl.tableName();
}
String columnName = permissionControl.columnName();
// ObjectMapper mapper = new ObjectMapper();
// String json = mapper.writeValueAsString(parameter); // 将对象转换为JSON字符串
// Map<String, Object> paramMap = mapper.readValue(json, Map.class); // 将JSON字符串转换为Map
// String fieldName = permissionControl.fieldName();
// Object fieldValue = paramMap.get(fieldName);
//多个参数时使用
// String paramIndex = "param" + permissionControl.paramIndex();
// Object param = paramMap.get(paramIndex);
// Object fieldValue = ReflectUtil.getFieldValue(param, permissionControl.fieldName());
if (currentUserId == null) {
return sql;
}
if (StrUtil.isNotBlank(tableAlias) && StrUtil.isNotBlank(columnName)) {
String str = StrUtil.format("{}.{} in (select ssm.mechanic_id from sys_service_mechanic ssm where ssm.service_id = {} union select {} from DUAL))",
tableAlias, columnName, String.valueOf(currentUserId),String.valueOf(currentUserId));
constraintsBuffer.append(str);
}
SQLExprParser constraintsParser = SQLParserUtils.createExprParser(constraintsBuffer.toString(), JdbcUtils.MYSQL);
SQLExpr constraintsExpr = constraintsParser.expr();
SQLSelectStatement selectStmt = (SQLSelectStatement) stmt;
// 拿到SQLSelect
SQLSelect sqlselect = selectStmt.getSelect();
SQLSelectQueryBlock query = (SQLSelectQueryBlock) sqlselect.getQuery();
SQLExpr whereExpr = query.getWhere();
// 修改where表达式
if (whereExpr == null) {
query.setWhere(constraintsExpr);
} else {
SQLBinaryOpExpr newWhereExpr = new SQLBinaryOpExpr(whereExpr, SQLBinaryOperator.BooleanAnd, constraintsExpr);
query.setWhere(newWhereExpr);
}
sqlselect.setQuery(query);
return sqlselect.toString();
}
return sql;
}
/**
* 获取最终的sql语句
*
* @param configuration 节点配置
* @param boundSql BoundSql
* @param sqlId mapper方法的全路径名
* @param flag 是否需要拼接mapper方法的全路径名
* @return String
*/
private String getSql(Configuration configuration, BoundSql boundSql, String sqlId, boolean flag) throws NoSuchFieldException {
String sql = showSql(configuration, boundSql);
return flag ? sqlId + ":" + sql : sql;
}
/**
* 进行?的替换
*
* @param configuration 节点的配置
* @param boundSql BoundSql
* @return String
*/
private String showSql(Configuration configuration, BoundSql boundSql) {
//获取参数
Object parameterObject = boundSql.getParameterObject();
List<ParameterMapping> parameterMappings = boundSql.getParameterMappings();
//sql语句
String sql = boundSql.getSql().replaceAll("[\\s]+", " ");
if (CollUtil.isNotEmpty(parameterMappings) && parameterObject != null) {
//获取类型处理器
TypeHandlerRegistry typeHandlerRegistry = configuration.getTypeHandlerRegistry();
//对应的类型则进行替换
if (typeHandlerRegistry.hasTypeHandler(parameterObject.getClass())) {
sql = sql.replaceFirst("\\?", Matcher.quoteReplacement(getParameterValue(parameterObject)));
} else {
MetaObject metaObject = configuration.newMetaObject(parameterObject);
for (ParameterMapping parameterMapping : parameterMappings) {
String propertyName = parameterMapping.getProperty();
if (metaObject.hasGetter(propertyName)) {
Object objectValue = metaObject.getValue(propertyName);
sql = sql.replaceFirst("\\?", Matcher.quoteReplacement(getParameterValue(objectValue)));
}
if (boundSql.hasAdditionalParameter(propertyName)) {
//动态sql
Object additionalParameter = boundSql.getAdditionalParameter(propertyName);
sql = sql.replaceFirst("\\?", Matcher.quoteReplacement(getParameterValue(additionalParameter)));
}
//else {
// sql = sql.replaceFirst("\\?", "");
//}
}
}
}
return sql;
}
/**
* 参数二次处理
*
* @param parameterObject parameterObject
* @return String
*/
private String getParameterValue(Object parameterObject) {
String format = "'%s'";
String value = "";
if (null != parameterObject) {
value = String.valueOf(parameterObject);
}
if (parameterObject instanceof String) {
value = String.valueOf(parameterObject);
}
if (parameterObject instanceof Date) {
//DateFormat dateTimeInstance = DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.DEFAULT,
// Locale.CHINA);
//value = dateTimeInstance.format(parameterObject);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
value = sdf.format((Date) parameterObject);
}
if (parameterObject instanceof LocalDateTime) {
value = ((LocalDateTime) parameterObject).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
}
if (parameterObject instanceof LocalDate) {
value = ((LocalDate) parameterObject).format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
}
if (parameterObject instanceof LocalTime) {
value = ((LocalTime) parameterObject).format(DateTimeFormatter.ofPattern("HH:mm:ss"));
}
if (parameterObject instanceof Timestamp) {
value = ((Timestamp) parameterObject).toString();
}
return String.format(format, value);
}
@Override
public Object plugin(Object target) {
return Plugin.wrap(target, this);
}
@Override
public void setProperties(Properties properties) {
Interceptor.super.setProperties(properties);
}
}
package com.glsx.ordercenter.listener;
import com.glsx.ordercenter.interceptor.PermissionControlInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.plugin.Interceptor;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import java.util.List;
/**
* 此类为了控制mybatis Interceptor执行的顺序,Interceptor调用顺序为后加入的先执行
*/
@Slf4j
@Order
@Component
public class DataCommandLineRunner implements CommandLineRunner {
@Autowired
private List<SqlSessionFactory> sqlSessionFactoryList;
@Override
public void run(String... args) throws Exception {
log.info("CommandLineRunner DataPermissionInterceptor init...");
//先加的后执行
for (SqlSessionFactory sqlSessionFactory : sqlSessionFactoryList) {
sqlSessionFactory.getConfiguration().addInterceptor(new PermissionControlInterceptor());
List<Interceptor> interceptorList = sqlSessionFactory.getConfiguration().getInterceptors();
interceptorList.forEach(interceptor -> {
log.info(interceptor.getClass().getSimpleName());
});
}
}
}
package com.glsx.ordercenter.listener;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.excel.metadata.data.ReadCellData;
import com.alibaba.excel.util.ConverterUtils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.glsx.common.utils.HttpUtils;
import com.glsx.common.utils.PropertiesUtil;
import com.glsx.ordercenter.dto.IndentImportDeviceDataExportModel;
import com.glsx.ordercenter.dto.IndentImportDeviceDataExportModelImport;
import com.glsx.ordercenter.dto.IndentImportDeviceResponse;
import com.glsx.ordercenter.mapper.SysDeviceMapper;
import com.glsx.ordercenter.mapper.SysIndentImportDeviceMapper;
import com.glsx.ordercenter.utils.EasyExcelUtils;
import com.glsx.ordercenter.utils.FileUploadServerData;
import com.glsx.ordercenter.utils.FileUtils;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.StringUtils;
import java.io.ByteArrayOutputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* @title IndentImportDeviceDataListener
* @Author zhangzc
* @Description
* @Date 2024/4/10 15:15
**/
@Slf4j
@NoArgsConstructor
public class IndentImportDeviceDataListener extends AnalysisEventListener<IndentImportDeviceDataExportModel> {
IndentImportDeviceResponse importDeviceResponse = new IndentImportDeviceResponse();
public List<IndentImportDeviceDataExportModel> modelList = new ArrayList<>();
public List<IndentImportDeviceDataExportModelImport> errorList = new ArrayList<>();
List<String> deviceNoList = new ArrayList<>();
private Logger logger = LoggerFactory.getLogger(getClass());
HttpUtils httpUtils = new HttpUtils();
private SysIndentImportDeviceMapper importDeviceMapper;
private SysDeviceMapper sysDeviceMapper;
public IndentImportDeviceDataListener(SysIndentImportDeviceMapper importDeviceMapper, SysDeviceMapper sysDeviceMapper) {
this.importDeviceMapper = importDeviceMapper;
this.sysDeviceMapper = sysDeviceMapper;
}
@Override
public void invokeHead(Map<Integer, ReadCellData<?>> headMap, AnalysisContext context) {
Map<Integer, String> headerMap = ConverterUtils.convertToStringMap(headMap, context);
if (headerMap.isEmpty()) {
throw new RuntimeException("导入的excel表头错误,请检查后重试!");
}
String deviceNo = headerMap.get(0);
if (!"设备号".equals(deviceNo)) {
throw new RuntimeException("导入文件与指定模板不匹配,请检查后重试!");
}
super.invokeHead(headMap, context);
}
@Override
public void invoke(IndentImportDeviceDataExportModel indentImportDeviceDataExportModel, AnalysisContext analysisContext) {
IndentImportDeviceDataExportModelImport error = new IndentImportDeviceDataExportModelImport();
if (indentImportDeviceDataExportModel == null) {
error.setImportFailReason("设备号为空");
errorList.add(error);
return;
}
String deviceNo = indentImportDeviceDataExportModel.getDeviceNo();
error.setDeviceNo(deviceNo);
if (StringUtils.isEmpty(deviceNo)) {
error.setImportFailReason("设备号为空");
errorList.add(error);
return;
}
if (deviceNoList.contains(deviceNo)) {
error.setImportFailReason("设备号重复");
errorList.add(error);
return;
}
String deviceUrl = PropertiesUtil.getProperty("bhg.device.verify.sn") + deviceNo;
String result = null;
try {
result = httpUtils.get(deviceUrl, null, 60);
logger.info("设备No:{}获取设备验证信息响应数据:{}", deviceNo, result);
JSONObject jsonObject = JSON.parseObject(result);
if (!returnMessageHandler(jsonObject)) {
error.setImportFailReason("设备未入库");
errorList.add(error);
return;
}
} catch (Exception e) {
throw new RuntimeException(e);
}
if (importDeviceMapper.countImportDeviceByDeviceNo(deviceNo) > 0) {
error.setImportFailReason("设备已归属");
errorList.add(error);
return;
}
if (sysDeviceMapper.countDeviceByDeviceNo(deviceNo) > 0) {
error.setImportFailReason("设备已归属");
errorList.add(error);
return;
}
modelList.add(indentImportDeviceDataExportModel);
deviceNoList.add(indentImportDeviceDataExportModel.getDeviceNo());
}
@Override
public void doAfterAllAnalysed(AnalysisContext analysisContext) {
importDeviceResponse.setSuccessCount(modelList.size());
importDeviceResponse.setErrorCount(errorList.size());
importDeviceResponse.setDeviceNoList(deviceNoList);
importDeviceResponse.setErrUrl(buildFailFile("批量导出设备错误列表", errorList));
}
public String buildFailFile(String filename, List<IndentImportDeviceDataExportModelImport> errorList) {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
EasyExcelUtils.writeExcel(outputStream, errorList, filename, IndentImportDeviceDataExportModelImport.class);
byte[] bytes = outputStream.toByteArray();
FileUploadServerData fileUploadServerData = FileUtils.uploadToFileSystem(filename, bytes, "xlsx");
return fileUploadServerData.getSecureUrl();
}
public IndentImportDeviceResponse getImportDeviceResponse() {
return importDeviceResponse;
}
private Boolean returnMessageHandler(JSONObject jsonObject) {
if (!"0".equals(jsonObject.getString("returnCode"))) {
return false;
}
JSONObject data = jsonObject.getJSONObject("data");
return data != null;
}
}
package com.glsx.ordercenter.listener;
import org.springframework.context.ApplicationContext;
import org.springframework.context.event.ApplicationContextEvent;
public class SqlSessionEvent extends ApplicationContextEvent {
/**
* Create a new ContextStartedEvent.
*
* @param source the {@code ApplicationContext} that the event is raised for
* (must not be {@code null})
*/
public SqlSessionEvent(ApplicationContext source) {
super(source);
}
}
package com.glsx.ordercenter.listener;
import com.glsx.ordercenter.interceptor.PermissionControlInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import java.util.List;
@Slf4j
//@Component
public class SqlSessionListener implements ApplicationListener<SqlSessionEvent> {
@Autowired
private List<SqlSessionFactory> sqlSessionFactoryList;
@Override
public void onApplicationEvent(SqlSessionEvent event) {
log.info("SqlSessionListener DataPermissionInterceptor init...");
//先加的后执行
for (SqlSessionFactory sqlSessionFactory : sqlSessionFactoryList) {
sqlSessionFactory.getConfiguration().addInterceptor(new PermissionControlInterceptor());
}
}
}
...@@ -51,4 +51,14 @@ public interface SysDeviceMapper { ...@@ -51,4 +51,14 @@ public interface SysDeviceMapper {
int updateDevicesByIndentNo(String indentNo); int updateDevicesByIndentNo(String indentNo);
List<SysDevice> getByIndentNo(String indentNo); List<SysDevice> getByIndentNo(String indentNo);
int countDeviceByDeviceNo(@Param("deviceNo")String deviceNo);
int updateUserByDeviceNo(@Param("beSecondedId")Integer beSecondedId, @Param("secondedId") Integer secondedId, @Param("deviceNo")String deviceNo, @Param("updateBy")int updateBy);
SysDevice selectByDeviceNo(@Param("deviceNo")String deviceNo);
int updateUserByDeviceNoList(@Param("beSecondedId")Integer beSecondedId, @Param("secondedId") Integer secondedId, @Param("deviceNoList") List<String> deviceNoList, @Param("updateBy") int updateBy);
int countByIndentNo(String indentNo);
} }
\ No newline at end of file \ No newline at end of file
package com.glsx.ordercenter.mapper; package com.glsx.ordercenter.mapper;
import com.glsx.ordercenter.common.PermissionControl;
import com.glsx.ordercenter.dto.DeviceRepertoryReq; import com.glsx.ordercenter.dto.DeviceRepertoryReq;
import com.glsx.ordercenter.dto.MechanicRepertoryReq; import com.glsx.ordercenter.dto.MechanicRepertoryReq;
import com.glsx.ordercenter.pojo.SysDevice; import com.glsx.ordercenter.pojo.SysDevice;
...@@ -31,6 +32,7 @@ public interface SysDeviceRepertoryMapper { ...@@ -31,6 +32,7 @@ public interface SysDeviceRepertoryMapper {
int updateByPrimaryKey(SysDeviceRepertory record); int updateByPrimaryKey(SysDeviceRepertory record);
@PermissionControl(tableAlias = "sdr",columnName = "user_id")
List<DeviceRepertoryReq> getDeviceRepertoryList(Map<String, Object> params); List<DeviceRepertoryReq> getDeviceRepertoryList(Map<String, Object> params);
int updateSelective(SysDeviceRepertory deviceRepertory); int updateSelective(SysDeviceRepertory deviceRepertory);
...@@ -42,4 +44,10 @@ public interface SysDeviceRepertoryMapper { ...@@ -42,4 +44,10 @@ public interface SysDeviceRepertoryMapper {
List<SysDevice> getRepertoryDetailByUserId(Map<String, Object> params); List<SysDevice> getRepertoryDetailByUserId(Map<String, Object> params);
List<MechanicRepertoryReq> getMechanicRepertoryList(Map<String, Object> params); List<MechanicRepertoryReq> getMechanicRepertoryList(Map<String, Object> params);
Integer countServiceRepertoryDetail(Map<String, Object> params);
Integer countMechanicRepertoryDetail(Map<String, Object> params);
Integer countMechanicRepertoryStock(Map<String, Object> params);
} }
\ No newline at end of file \ No newline at end of file
package com.glsx.ordercenter.mapper;
import com.glsx.ordercenter.dto.IndentImportDeviceReq;
import com.glsx.ordercenter.pojo.SysIndentImportDevice;
import com.glsx.ordercenter.pojo.SysOrderDeviceSupplier;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface SysIndentImportDeviceMapper {
int insertBatchSelective(List<SysIndentImportDevice> list);
int deleteByPrimaryKey(Integer id);
List<IndentImportDeviceReq> selectImportDeviceList(@Param("indentId")Integer indentId, @Param("deviceNo")String deviceNo);
int countImportDeviceByDeviceNo(@Param("deviceNo")String deviceNo);
String selectIndentNoById(Integer id);
String selectDeviceNoById(Integer id);
List<String> getDeviceNoListByIndentNo(@Param("indentNo")String indentNo);
int deleteByIndentNo(@Param("indentNo")String indentNo);
}
\ No newline at end of file \ No newline at end of file
...@@ -28,5 +28,5 @@ public interface SysIndentLogisticsMapper { ...@@ -28,5 +28,5 @@ public interface SysIndentLogisticsMapper {
int updateByPrimaryKey(SysIndentLogistics record); int updateByPrimaryKey(SysIndentLogistics record);
SysIndentLogistics getByIndentId(Integer indentId); SysIndentLogistics getByIndentId(Integer indentId, Integer orderType);
} }
\ No newline at end of file \ No newline at end of file
...@@ -2,6 +2,7 @@ package com.glsx.ordercenter.mapper; ...@@ -2,6 +2,7 @@ package com.glsx.ordercenter.mapper;
import java.util.List; import java.util.List;
import com.glsx.ordercenter.common.PermissionControl;
import com.glsx.ordercenter.pojo.SysIndent; import com.glsx.ordercenter.pojo.SysIndent;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
...@@ -34,6 +35,7 @@ public interface SysIndentMapper { ...@@ -34,6 +35,7 @@ public interface SysIndentMapper {
* List<SysIndent> * List<SysIndent>
* *
*/ */
@PermissionControl(tableAlias = "si",columnName = "user_id")
List<SysIndent> getIndentListByPage(SysIndent indent); List<SysIndent> getIndentListByPage(SysIndent indent);
SysIndent getByIndentNo(String indentNo); SysIndent getByIndentNo(String indentNo);
...@@ -96,4 +98,10 @@ public interface SysIndentMapper { ...@@ -96,4 +98,10 @@ public interface SysIndentMapper {
* *
*/ */
List<SysIndent> getMechanicIndentListByPage(SysIndent indent); List<SysIndent> getMechanicIndentListByPage(SysIndent indent);
List<Integer> selectUnReceivedIndentIds();
Integer updateIndentStatusByIds(List<Integer> ids);
SysIndent selectByIndentNo(String indentNo);
} }
\ No newline at end of file \ No newline at end of file
package com.glsx.ordercenter.mapper;
import com.glsx.ordercenter.pojo.SysSecondmentImportDevice;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface SysSecondmentImportDeviceMapper {
List<SysSecondmentImportDevice> getDeviceBySecondmentNo(SysSecondmentImportDevice secondmentImportDevice);
List<SysSecondmentImportDevice> getListBySecondmentNo(@Param("secondmentNo") String secondmentNo);
String selectSecondmentNoById(Integer id);
String selectDeviceNoById(Integer id);
int deleteByPrimaryKey(Integer id);
int insertBatchSelective(List<SysSecondmentImportDevice> list);
int countImportDeviceByDeviceNo(@Param("deviceNo")String deviceNo);
int deleteBySecondmentNo(@Param("secondmentNo") String secondmentNo);
}
\ No newline at end of file \ No newline at end of file
package com.glsx.ordercenter.mapper;
import com.glsx.ordercenter.pojo.SysSecondmentLog;
import java.util.List;
public interface SysSecondmentLogMapper {
int insertSelective(SysSecondmentLog secondmentLog);
SysSecondmentLog get(SysSecondmentLog secondmentLog);
List<SysSecondmentLog> selectSecondmentLogList(Integer secondmentId);
}
\ No newline at end of file \ No newline at end of file
package com.glsx.ordercenter.mapper;
import com.glsx.ordercenter.common.PermissionControl;
import com.glsx.ordercenter.dto.SecondmentDto;
import com.glsx.ordercenter.dto.req.SecondmentQueryReq;
import com.glsx.ordercenter.pojo.SysSecondment;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface SysSecondmentMapper {
List<Integer> selectUnReceivedSecondmentIds();
Integer updateSecondmentStatusByIds(List<Integer> ids);
@PermissionControl(tableAlias = "ss",columnName = "seconded_id")
List<SecondmentDto> getListByPage(SecondmentQueryReq req);
SecondmentDto getDetail(Integer id);
List<SecondmentDto> getListByUserId(SecondmentQueryReq req);
SysSecondment getBySecondmentNo(@Param("secondmentNo") String secondmentNo);
SysSecondment selectByPrimaryKey(Integer id);
void updateSecondmentStatusById(@Param("secondmentStatus")int secondmentStatus, @Param("userId")int userId, @Param("id")Integer id);
SysSecondment selectBySecondmentNo(String secondmentNo);
int insertSelective(SysSecondment record);
int countSecondment(String beginDate, String endDate);
int updateByPrimaryKeySelective(SysSecondment record);
String selectSecondmentNoById(Integer id);
}
\ No newline at end of file \ No newline at end of file
package com.glsx.ordercenter.pojo; package com.glsx.ordercenter.pojo;
import com.glsx.excel.poi.annotation.ExcelColumn;
import com.glsx.excel.poi.annotation.ExcelExport;
import lombok.Data;
import java.util.Date; import java.util.Date;
@Data
@ExcelExport
public class SysDevice { public class SysDevice {
private Integer id; private Integer id;
private String deviceType; private String deviceType;
@ExcelColumn(value = "设备号",index = 3)
private String deviceNo; private String deviceNo;
private Integer deviceStatus; private Integer deviceStatus;
@ExcelColumn(value = "用户ID",index = 0)
private Integer userId; private Integer userId;
@ExcelColumn(value = "用户名称",index = 1)
private String userName;
private String loginName;
private String indentNo; private String indentNo;
@ExcelColumn(value = "入库时间", index = 4, pattern = "yyyy-MM-dd HH:mm:ss")
private Date stockTime; private Date stockTime;
@ExcelColumn(value = "备注",index = 5)
private String remark; private String remark;
private Date createTime; private Date createTime;
...@@ -27,129 +42,13 @@ public class SysDevice { ...@@ -27,129 +42,13 @@ public class SysDevice {
private Integer updateBy; private Integer updateBy;
@ExcelColumn(value = "设备名称",index = 2)
private String deviceName; private String deviceName;
private String name; private String name;
private Integer deviceSource; private Integer deviceSource;
public String getName() { private String serviceName;
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDeviceName() {
return deviceName;
}
public void setDeviceName(String deviceName) {
this.deviceName = deviceName;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getDeviceType() {
return deviceType;
}
public void setDeviceType(String deviceType) {
this.deviceType = deviceType == null ? null : deviceType.trim();
}
public String getDeviceNo() {
return deviceNo;
}
public void setDeviceNo(String deviceNo) {
this.deviceNo = deviceNo == null ? null : deviceNo.trim();
}
public Integer getDeviceStatus() {
return deviceStatus;
}
public void setDeviceStatus(Integer deviceStatus) {
this.deviceStatus = deviceStatus;
}
public Integer getUserId() {
return userId;
}
public void setUserId(Integer userId) {
this.userId = userId;
}
public String getIndentNo() {
return indentNo;
}
public void setIndentNo(String indentNo) {
this.indentNo = indentNo == null ? null : indentNo.trim();
}
public Date getStockTime() {
return stockTime;
}
public void setStockTime(Date stockTime) {
this.stockTime = stockTime;
}
public String getRemark() {
return remark;
}
public void setRemark(String remark) {
this.remark = remark == null ? null : remark.trim();
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public Integer getCreateBy() {
return createBy;
}
public void setCreateBy(Integer createBy) {
this.createBy = createBy;
}
public Date getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
public Integer getUpdateBy() {
return updateBy;
}
public void setUpdateBy(Integer updateBy) {
this.updateBy = updateBy;
}
public Integer getDeviceSource() {
return deviceSource;
}
public void setDeviceSource(Integer deviceSource) {
this.deviceSource = deviceSource;
}
} }
\ No newline at end of file \ No newline at end of file
...@@ -7,8 +7,21 @@ import javax.validation.groups.Default; ...@@ -7,8 +7,21 @@ import javax.validation.groups.Default;
import com.glsx.ordercenter.dto.Traces; import com.glsx.ordercenter.dto.Traces;
import com.glsx.ordercenter.pojo.user.SysUser; import com.glsx.ordercenter.pojo.user.SysUser;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
public class SysIndent extends BaseModel{ import java.io.Serializable;
import java.util.List;
@Data
@NoArgsConstructor
@AllArgsConstructor
@ToString
public class SysIndent extends BaseModel implements Serializable {
private static final long serialVersionUID = 30305831970774368L;
@NotNull(message="{param.not.null}", groups={GroupA.class}) @NotNull(message="{param.not.null}", groups={GroupA.class})
private Integer id; private Integer id;
...@@ -88,210 +101,14 @@ public class SysIndent extends BaseModel{ ...@@ -88,210 +101,14 @@ public class SysIndent extends BaseModel{
private SysUser user; private SysUser user;
private String cancelOperatorName; private String cancelOperatorName;
/**
* 订货方式 1.新增 2.批量导入
*/
private Integer indentType;
public Integer getId() { /**
return id; * 设备号列表 (indentType =2 时使用)
} */
private List<String> deviceNoList;
public void setId(Integer id) {
this.id = id;
}
public String getIndentNo() {
return indentNo;
}
public void setIndentNo(String indentNo) {
this.indentNo = indentNo == null ? null : indentNo.trim();
}
public Integer getUserId() {
return userId;
}
public void setUserId(Integer userId) {
this.userId = userId;
}
public String getDeviceType() {
return deviceType;
}
public void setDeviceType(String deviceType) {
this.deviceType = deviceType == null ? null : deviceType.trim();
}
public Integer getDeviceAmount() {
return deviceAmount;
}
public void setDeviceAmount(Integer deviceAmount) {
this.deviceAmount = deviceAmount;
}
public Integer getIndentStatus() {
return indentStatus;
}
public void setIndentStatus(Integer indentStatus) {
this.indentStatus = indentStatus;
}
public Integer getIsCanceled() {
return isCanceled;
}
public void setIsCanceled(Integer isCanceled) {
this.isCanceled = isCanceled;
}
public Integer getDistrictCode() {
return districtCode;
}
public void setDistrictCode(Integer districtCode) {
this.districtCode = districtCode;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address == null ? null : address.trim();
}
public String getBeginDate() {
return beginDate;
}
public void setBeginDate(String beginDate) {
this.beginDate = beginDate;
}
public String getEndDate() {
return endDate;
}
public void setEndDate(String endDate) {
this.endDate = endDate;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getReceiverName() {
return receiverName;
}
public void setReceiverName(String receiverName) {
this.receiverName = receiverName;
}
public Integer getSendType() {
return sendType;
}
public void setSendType(Integer sendType) {
this.sendType = sendType;
}
public Integer getReceiveAddressId() {
return receiveAddressId;
}
public void setReceiveAddressId(Integer receiveAddressId) {
this.receiveAddressId = receiveAddressId;
}
public String getDeviceName() {
return deviceName;
}
public void setDeviceName(String deviceName) {
this.deviceName = deviceName;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public SysIndentLogistics getSysIndentLogistics() {
return sysIndentLogistics;
}
public void setSysIndentLogistics(SysIndentLogistics sysIndentLogistics) {
this.sysIndentLogistics = sysIndentLogistics;
}
public SysArea getSysArea() {
return sysArea;
}
public void setSysArea(SysArea sysArea) {
this.sysArea = sysArea;
}
public Integer getTerminalType() {
return terminalType;
}
public void setTerminalType(Integer terminalType) {
this.terminalType = terminalType;
}
public String getQueryContent() {
return queryContent;
}
public void setQueryContent(String queryContent) {
this.queryContent = queryContent;
}
public Traces getTraces() {
return traces;
}
public void setTraces(Traces traces) {
this.traces = traces;
}
public SysUser getUser() {
return user;
}
public void setUser(SysUser user) {
this.user = user;
}
public String getCancelOperatorName() {
return cancelOperatorName;
}
public void setCancelOperatorName(String cancelOperatorName) {
this.cancelOperatorName = cancelOperatorName;
}
@Override
public String toString() {
return "SysIndent [id=" + id + ", indentNo=" + indentNo + ", sendType="
+ sendType + ", userId=" + userId + ", username=" + username
+ ", deviceType=" + deviceType + ", deviceName=" + deviceName
+ ", deviceAmount=" + deviceAmount + ", indentStatus="
+ indentStatus + ", isCanceled=" + isCanceled
+ ", districtCode=" + districtCode + ", address=" + address
+ ", receiveAddressId=" + receiveAddressId + ", phone=" + phone
+ ", receiverName=" + receiverName + ", beginDate=" + beginDate
+ ", endDate=" + endDate + "]";
}
} }
\ No newline at end of file \ No newline at end of file
package com.glsx.ordercenter.pojo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.*;
@Table(name = "sys_indent_import_device")
@Data
@NoArgsConstructor
@AllArgsConstructor
@ToString
public class SysIndentImportDevice implements Serializable {
@Id
private Integer id;
/**
* 订货单号
*/
@Column(name = "indent_no")
private String indentNo;
/**
* 设备号
*/
@Column(name = "device_no")
private String deviceNo;
/**
* 批量导入时间
*/
@Column(name = "batch_import_time")
private Date batchImportTime;
/**
* 创建时间
*/
@Column(name = "create_time")
private Date createTime;
/**
* 创建人
*/
@Column(name = "create_by")
private Integer createBy;
/**
* 更新时间
*/
@Column(name = "update_time")
private Date updateTime;
/**
* 更新人
*/
@Column(name = "update_by")
private Integer updateBy;
private static final long serialVersionUID = 1L;
}
\ No newline at end of file \ No newline at end of file
...@@ -13,6 +13,7 @@ public class SysIndentLogistics { ...@@ -13,6 +13,7 @@ public class SysIndentLogistics {
@NotNull(message="{param.not.null}", groups={Default.class}) @NotNull(message="{param.not.null}", groups={Default.class})
private Integer indentId; private Integer indentId;
private Integer orderType;
private String logisticsNo; private String logisticsNo;
private String logisticsUnicode; private String logisticsUnicode;
...@@ -120,4 +121,11 @@ public class SysIndentLogistics { ...@@ -120,4 +121,11 @@ public class SysIndentLogistics {
this.expressCompany = expressCompany; this.expressCompany = expressCompany;
} }
public Integer getOrderType() {
return orderType;
}
public void setOrderType(Integer orderType) {
this.orderType = orderType;
}
} }
\ No newline at end of file \ No newline at end of file
package com.glsx.ordercenter.pojo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.*;
@Table(name = "sys_secondment")
@Data
@NoArgsConstructor
@AllArgsConstructor
@ToString
public class SysSecondment implements Serializable {
/**
* id
*/
@Id
private Integer id;
/**
* 借调单号
*/
@Column(name = "secondment_no")
private String secondmentNo;
/**
* 发货方式(1:服务商发货;2:广联发货)
*/
@Column(name = "send_type")
private Byte sendType;
/**
* 借调人用户id
*/
@Column(name = "seconded_id")
private Integer secondedId;
/**
* 设备类型,从字典中获取,如有线GPS:sys_order_service_item_gps,无线GPS:sys_order_service_item_gps_wireless。。。
*/
@Column(name = "device_type")
private String deviceType;
/**
* 借调数量
*/
@Column(name = "secondment_amount")
private Integer secondmentAmount;
/**
* 订单状态10:待审核;20:待发货;30:待收货;40:已完成;
*/
@Column(name = "secondment_status")
private Integer secondmentStatus;
/**
* 0:未取消,1:已取消
*/
@Column(name = "is_canceled")
private Byte isCanceled;
/**
* 收货地址的电话
*/
private String phone;
/**
* 收货地址的姓名
*/
@Column(name = "receiver_name")
private String receiverName;
/**
* 收货地址区编码
*/
@Column(name = "district_code")
private Integer districtCode;
/**
* 收货详细地址
*/
private String address;
/**
* 备注
*/
private String remark;
/**
* 创建人
*/
@Column(name = "create_by")
private Integer createBy;
/**
* 创建时间
*/
@Column(name = "create_time")
private Date createTime;
/**
* 更新人
*/
@Column(name = "update_by")
private Integer updateBy;
/**
* 更新时间
*/
@Column(name = "update_time")
private Date updateTime;
private static final long serialVersionUID = 1L;
}
\ No newline at end of file \ No newline at end of file
package com.glsx.ordercenter.pojo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.*;
@Table(name = "sys_secondment_import_device")
@Data
@NoArgsConstructor
@AllArgsConstructor
@ToString
public class SysSecondmentImportDevice implements Serializable {
@Id
private Integer id;
/**
* 借调单号
*/
@Column(name = "secondment_no")
private String secondmentNo;
/**
* 设备号
*/
@Column(name = "device_no")
private String deviceNo;
/**
* 借调人id
*/
@Column(name = "seconded_id")
private Integer secondedId;
/**
* 被借调人id
*/
@Column(name = "be_seconded_id")
private Integer beSecondedId;
/**
* 批量导入时间
*/
@Column(name = "batch_import_time")
private Date batchImportTime;
/**
* 创建时间
*/
@Column(name = "create_time")
private Date createTime;
/**
* 创建人
*/
@Column(name = "create_by")
private Integer createBy;
/**
* 更新时间
*/
@Column(name = "update_time")
private Date updateTime;
/**
* 更新人
*/
@Column(name = "update_by")
private Integer updateBy;
//借调人
private String username;
private String name;
private Integer userType;
//被借调人
private String beUsername;
private String beName;
private Integer beUserType;
//设备名称
private String deviceName;
private static final long serialVersionUID = 1L;
}
\ No newline at end of file \ No newline at end of file
package com.glsx.ordercenter.pojo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.*;
@Table(name = "sys_secondment_log")
@Data
@NoArgsConstructor
@AllArgsConstructor
@ToString
public class SysSecondmentLog implements Serializable {
/**
* id
*/
@Id
private Integer id;
/**
* 借调单id
*/
@Column(name = "secondment_id")
private Integer secondmentId;
/**
* 订单状态10:待审核;20:待发货;30:待收货;40:已完成;50:已取消
*/
@Column(name = "secondment_status")
private Integer secondmentStatus;
/**
* 备注
*/
private String remark;
/**
* 创建人
*/
@Column(name = "create_by")
private Integer createBy;
/**
* 创建时间
*/
@Column(name = "create_time")
private Date createTime;
private String operatorName;
private static final long serialVersionUID = 1L;
}
\ No newline at end of file \ No newline at end of file
...@@ -5,6 +5,8 @@ import java.util.List; ...@@ -5,6 +5,8 @@ import java.util.List;
import com.glsx.common.constants.ResultObject; import com.glsx.common.constants.ResultObject;
import com.glsx.ordercenter.pojo.SysDevice; import com.glsx.ordercenter.pojo.SysDevice;
import javax.servlet.http.HttpServletRequest;
public interface DeviceService { public interface DeviceService {
List<SysDevice> catIndentDevices(String indentNo); List<SysDevice> catIndentDevices(String indentNo);
...@@ -41,4 +43,14 @@ public interface DeviceService { ...@@ -41,4 +43,14 @@ public interface DeviceService {
* @return * @return
*/ */
int updateServiceDeviceStatu(String indentNo); int updateServiceDeviceStatu(String indentNo);
ResultObject indentNoBatchInsertDevice(String indentNo, HttpServletRequest request);
ResultObject secondmentBatchInsertDevice(String secondmentNo, int userId);
int updateUserByDeviceNo(Integer beSecondedId, Integer secondedId, String deviceNo, int updateBy);
SysDevice selectByDeviceNo(String deviceNo);
int updateUserByDeviceNoList(Integer beSecondedId, Integer secondedId, List<String> deviceNoList, int updateBy);
} }
...@@ -403,4 +403,6 @@ public interface IOrderService { ...@@ -403,4 +403,6 @@ public interface IOrderService {
void pushSxjOrderData(Byte pushType, Integer id, Integer status); void pushSxjOrderData(Byte pushType, Integer id, Integer status);
void syncDismantleOrder(Integer orderId); void syncDismantleOrder(Integer orderId);
Map<String, Object> checkVinAndSn(Integer orderId, Integer serviceItemId);
} }
...@@ -17,6 +17,6 @@ public interface IndentLogisticsService { ...@@ -17,6 +17,6 @@ public interface IndentLogisticsService {
int addOrUpdateIndentLogistics(HttpServletRequest request, SysIndentLogistics indentLogistics); int addOrUpdateIndentLogistics(HttpServletRequest request, SysIndentLogistics indentLogistics);
SysIndentLogistics getByIndentId(Integer indentId); SysIndentLogistics getByIndentId(Integer indentId, Integer orderType);
} }
...@@ -6,9 +6,12 @@ import javax.servlet.http.HttpServletRequest; ...@@ -6,9 +6,12 @@ import javax.servlet.http.HttpServletRequest;
import com.glsx.common.constants.ResultObject; import com.glsx.common.constants.ResultObject;
import com.glsx.common.utils.Page; import com.glsx.common.utils.Page;
import com.glsx.ordercenter.dto.IndentImportDeviceReq;
import com.glsx.ordercenter.dto.IndentImportDeviceResponse;
import com.glsx.ordercenter.pojo.SysIndent; import com.glsx.ordercenter.pojo.SysIndent;
import com.glsx.ordercenter.pojo.SysIndentLog; import com.glsx.ordercenter.pojo.SysIndentLog;
import com.glsx.ordercenter.pojo.SysIndentLogistics; import com.glsx.ordercenter.pojo.SysIndentLogistics;
import org.springframework.web.multipart.MultipartFile;
/** /**
...@@ -155,7 +158,7 @@ public interface IndentService { ...@@ -155,7 +158,7 @@ public interface IndentService {
* ResultObject * ResultObject
* *
*/ */
ResultObject confirmReceipt(HttpServletRequest request, Integer id); ResultObject confirmReceipt(HttpServletRequest request, Integer id, Integer currentUserId);
/** /**
* *
...@@ -171,4 +174,14 @@ public interface IndentService { ...@@ -171,4 +174,14 @@ public interface IndentService {
*/ */
List<SysIndent> getMechanicIndentListByPage(HttpServletRequest request, List<SysIndent> getMechanicIndentListByPage(HttpServletRequest request,
Page page, SysIndent indent); Page page, SysIndent indent);
List<IndentImportDeviceReq> getImportDeviceDetail(Page page, Integer indentId, String deviceNo);
Boolean deleteIndentImportDeviceById(Integer id);
IndentImportDeviceResponse checkImportIndentDevice(MultipartFile file);
List<String> getDeviceNoList(String indentNo);
void addIndentDeviceLog(Integer id, Integer indentStatus, String remark, Integer createBy);
} }
package com.glsx.ordercenter.service;
import com.glsx.common.constants.ResultObject;
import com.glsx.common.utils.Page;
import com.glsx.ordercenter.dto.SecondmentDto;
import com.glsx.ordercenter.dto.SecondmentImportDeviceResponse;
import com.glsx.ordercenter.dto.req.InsertSecondmentReq;
import com.glsx.ordercenter.dto.req.SecondmentImportDeviceReq;
import com.glsx.ordercenter.dto.req.SecondmentQueryReq;
import com.glsx.ordercenter.dto.req.UpdateSecondmentReq;
import com.glsx.ordercenter.pojo.SysIndentLogistics;
import com.glsx.ordercenter.pojo.SysSecondment;
import com.glsx.ordercenter.pojo.SysSecondmentImportDevice;
import com.glsx.ordercenter.pojo.SysSecondmentLog;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
/**
* @title SysSecondmentService
* @Author zhangzc
* @Description
* @Date 2024/4/10 14:25
**/
public interface SysSecondmentService {
List<SecondmentDto> getListByPage(Page page, SecondmentQueryReq req);
SecondmentDto getDetail(Integer id);
List<SysSecondmentImportDevice> getDeviceBySecondmentNo(SysSecondmentImportDevice secondmentImportDevice);
List<SecondmentDto> getListByUserId(Page page, SecondmentQueryReq req);
ResultObject confirmReceipt(String secondmentNo, int userId);
SecondmentImportDeviceResponse checkImportSecondmentDevice(HttpServletRequest request, SecondmentImportDeviceReq importDeviceReq);
Boolean addSecondment(HttpServletRequest request, InsertSecondmentReq secondmentReq);
Boolean updateSecondment(HttpServletRequest request, UpdateSecondmentReq secondmentReq);
Boolean deleteSecondmentDeviceById(Integer id);
Integer dispatchSecondment(HttpServletRequest request, SysIndentLogistics sysIndentLogistics);
List<SysSecondmentLog> getSecondmentLogList(Integer secondmentId);
}
...@@ -5,7 +5,11 @@ import java.util.HashMap; ...@@ -5,7 +5,11 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import com.glsx.common.utils.PropertiesUtil;
import com.glsx.ordercenter.mapper.SysManagerMapper;
import com.glsx.ordercenter.pojo.user.SysManager;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.glsx.common.constants.ResultObject; import com.glsx.common.constants.ResultObject;
...@@ -36,6 +40,9 @@ public class DeviceRepertoryServiceImpl implements DeviceRepertoryService { ...@@ -36,6 +40,9 @@ public class DeviceRepertoryServiceImpl implements DeviceRepertoryService {
@Autowired @Autowired
private SysIndentMapper sysIndentMapper; private SysIndentMapper sysIndentMapper;
@Autowired
private SysManagerMapper sysManagerMapper;
@Override @Override
public List<DeviceRepertoryReq> getRepertoryList(Integer sortType, String username, String deviceType) { public List<DeviceRepertoryReq> getRepertoryList(Integer sortType, String username, String deviceType) {
Map<String, Object> params = new HashMap<>(); Map<String, Object> params = new HashMap<>();
...@@ -47,6 +54,7 @@ public class DeviceRepertoryServiceImpl implements DeviceRepertoryService { ...@@ -47,6 +54,7 @@ public class DeviceRepertoryServiceImpl implements DeviceRepertoryService {
if (!deviceRepertoryReqs.isEmpty()) { if (!deviceRepertoryReqs.isEmpty()) {
for (DeviceRepertoryReq deviceRepertoryReq : deviceRepertoryReqs) { for (DeviceRepertoryReq deviceRepertoryReq : deviceRepertoryReqs) {
Integer stockDayWarn = Integer.valueOf(PropertiesUtil.getProperty("repertory.stock.day.warn"));
Integer userId = deviceRepertoryReq.getUserId(); Integer userId = deviceRepertoryReq.getUserId();
//在途库存 //在途库存
Integer sendDeviceNum = 0; Integer sendDeviceNum = 0;
...@@ -60,6 +68,7 @@ public class DeviceRepertoryServiceImpl implements DeviceRepertoryService { ...@@ -60,6 +68,7 @@ public class DeviceRepertoryServiceImpl implements DeviceRepertoryService {
int mechanicDeviceCount = 0; int mechanicDeviceCount = 0;
Map<String, Object> param = new HashMap<>(16); Map<String, Object> param = new HashMap<>(16);
param.put("userId", userId); param.put("userId", userId);
param.put("deviceType", deviceRepertoryReq.getDeviceType());
List<MechanicRepertoryReq> mechanicRepertoryReqs = sysDeviceRepertoryMapper.getMechanicRepertoryList(param); List<MechanicRepertoryReq> mechanicRepertoryReqs = sysDeviceRepertoryMapper.getMechanicRepertoryList(param);
if(!mechanicRepertoryReqs.isEmpty()){ if(!mechanicRepertoryReqs.isEmpty()){
for(MechanicRepertoryReq mechanicRepertoryReq : mechanicRepertoryReqs){ for(MechanicRepertoryReq mechanicRepertoryReq : mechanicRepertoryReqs){
...@@ -67,6 +76,20 @@ public class DeviceRepertoryServiceImpl implements DeviceRepertoryService { ...@@ -67,6 +76,20 @@ public class DeviceRepertoryServiceImpl implements DeviceRepertoryService {
} }
} }
deviceRepertoryReq.setMechanicDeviceNum(mechanicDeviceCount); deviceRepertoryReq.setMechanicDeviceNum(mechanicDeviceCount);
deviceRepertoryReq.setServiceDeviceNumWarn(checkRepertoryStockNum(deviceRepertoryReq.getServiceDeviceNum()));
Map<String, Object> countMap = new HashMap<>();
countMap.put("userId", userId);
countMap.put("day", stockDayWarn);
countMap.put("deviceType", deviceRepertoryReq.getDeviceType());
Integer count = sysDeviceRepertoryMapper.countServiceRepertoryDetail(countMap);
deviceRepertoryReq.setServiceDeviceDayWarn(checkRepertoryStockDayNum(count));
deviceRepertoryReq.setMechanicDeviceNumWarn(checkRepertoryStockNum((deviceRepertoryReq.getMechanicDeviceNum())));
countMap.clear();
countMap.put("serviceId", userId);
countMap.put("day", stockDayWarn);
countMap.put("deviceType", deviceRepertoryReq.getDeviceType());
count = sysDeviceRepertoryMapper.countMechanicRepertoryDetail(countMap);
deviceRepertoryReq.setMechanicDeviceDayWarn(checkRepertoryStockDayNum(count));
} }
} }
return deviceRepertoryReqs; return deviceRepertoryReqs;
...@@ -92,6 +115,13 @@ public class DeviceRepertoryServiceImpl implements DeviceRepertoryService { ...@@ -92,6 +115,13 @@ public class DeviceRepertoryServiceImpl implements DeviceRepertoryService {
params.put("mechanicId", mechanicId); params.put("mechanicId", mechanicId);
List<SysDevice> sysDeviceList = sysDeviceRepertoryMapper.getMechanicRepertoryDetail(params); List<SysDevice> sysDeviceList = sysDeviceRepertoryMapper.getMechanicRepertoryDetail(params);
SysManager manager = sysManagerMapper.selectByUserId(serviceId);
if (manager == null) {
return sysDeviceList;
}
for (SysDevice device : sysDeviceList) {
device.setServiceName(manager.getProviderName());
}
return sysDeviceList; return sysDeviceList;
} }
...@@ -116,6 +146,14 @@ public class DeviceRepertoryServiceImpl implements DeviceRepertoryService { ...@@ -116,6 +146,14 @@ public class DeviceRepertoryServiceImpl implements DeviceRepertoryService {
params.put("name", name); params.put("name", name);
params.put("userId", userId); params.put("userId", userId);
List<MechanicRepertoryReq> sysDeviceList = sysDeviceRepertoryMapper.getMechanicRepertoryList(params); List<MechanicRepertoryReq> sysDeviceList = sysDeviceRepertoryMapper.getMechanicRepertoryList(params);
Map<String, Object> mechanicParams = new HashMap<>();
mechanicParams.put("day", Integer.parseInt(PropertiesUtil.getProperty("repertory.stock.day.warn")));
mechanicParams.put("deviceType", deviceType);
for (MechanicRepertoryReq repertoryReq : sysDeviceList) {
repertoryReq.setDeviceNumWarn(checkRepertoryStockNum(repertoryReq.getDeviceNum()));
mechanicParams.put("userId", repertoryReq.getId());
repertoryReq.setDeviceDayWarn(checkRepertoryStockDayNum(sysDeviceRepertoryMapper.countMechanicRepertoryStock(mechanicParams)));
}
return sysDeviceList; return sysDeviceList;
} }
...@@ -192,4 +230,31 @@ public class DeviceRepertoryServiceImpl implements DeviceRepertoryService { ...@@ -192,4 +230,31 @@ public class DeviceRepertoryServiceImpl implements DeviceRepertoryService {
} }
return num; return num;
} }
/*
检查服务商库存/下属技工库存是否小于阈值,小于则提醒
*/
public String checkRepertoryStockNum(Integer deviceNum) {
if (deviceNum == null) {
deviceNum = 0;
}
int stockNumWarn = Integer.parseInt(PropertiesUtil.getProperty("repertory.stock.num.warn"));
if (deviceNum < stockNumWarn) {
return "库存<" + stockNumWarn;
}
return null;
}
/*
检查服务商库存/下属技工库存入库时间是否大于阈值,大于则提醒
*/
public String checkRepertoryStockDayNum(Integer deviceNum) {
if (deviceNum <= 0) {
return null;
}
int stockDayWarn = Integer.parseInt(PropertiesUtil.getProperty("repertory.stock.day.warn"));
return "库龄>" + stockDayWarn + "天:" + deviceNum + "台";
}
} }
...@@ -6,7 +6,14 @@ import java.util.Date; ...@@ -6,7 +6,14 @@ import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.TreeMap; import java.util.TreeMap;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import com.alibaba.fastjson.JSONObject;
import com.glsx.common.utils.StringUtils;
import com.glsx.common.utils.UserUtils;
import com.glsx.ordercenter.exception.BusinessException;
import com.glsx.ordercenter.service.SysSecondmentService;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -28,6 +35,9 @@ import com.glsx.ordercenter.pojo.SysDeviceExample; ...@@ -28,6 +35,9 @@ import com.glsx.ordercenter.pojo.SysDeviceExample;
import com.glsx.ordercenter.pojo.SysIndent; import com.glsx.ordercenter.pojo.SysIndent;
import com.glsx.ordercenter.service.DeviceService; import com.glsx.ordercenter.service.DeviceService;
import com.glsx.ordercenter.service.IndentService; import com.glsx.ordercenter.service.IndentService;
import javax.servlet.http.HttpServletRequest;
@Service @Service
public class DeviceServiceImpl implements DeviceService{ public class DeviceServiceImpl implements DeviceService{
...@@ -37,6 +47,9 @@ public class DeviceServiceImpl implements DeviceService{ ...@@ -37,6 +47,9 @@ public class DeviceServiceImpl implements DeviceService{
@Autowired @Autowired
private IndentService indentService; private IndentService indentService;
@Autowired
private SysSecondmentService secondmentService;
@Override @Override
public List<SysDevice> catIndentDevices(String indentNo) { public List<SysDevice> catIndentDevices(String indentNo) {
List<SysDevice> list=sysDeviceMapper.catIndentDevices(indentNo); List<SysDevice> list=sysDeviceMapper.catIndentDevices(indentNo);
...@@ -45,6 +58,26 @@ public class DeviceServiceImpl implements DeviceService{ ...@@ -45,6 +58,26 @@ public class DeviceServiceImpl implements DeviceService{
@Override @Override
public void updateDeviceNo(Integer id, String deviceNo) { public void updateDeviceNo(Integer id, String deviceNo) {
if (StringUtils.isBlank(deviceNo)) {
throw BusinessException.create(ResultCodeEnum.FAIL.getCode(), "设备号不能为空!");
}
SysDevice device = sysDeviceMapper.selectByDeviceNo(deviceNo);
if (device != null && device.getId().intValue() != id) {
throw BusinessException.create(ResultCodeEnum.FAIL.getCode(), "设备已归属!");
}
String deviceUrl = PropertiesUtil.getProperty("bhg.device.verify.sn") + deviceNo;
String result = null;
HttpUtils httpUtils = new HttpUtils();
try {
result = httpUtils.get(deviceUrl, null, 60);
logger.info("设备No:{}获取设备验证信息响应数据:{}", deviceNo, result);
JSONObject jsonObject = JSON.parseObject(result);
if (!returnMessageHandler(jsonObject)) {
throw BusinessException.create(ResultCodeEnum.FAIL.getCode(), "设备未入库!");
}
} catch (Exception e) {
throw BusinessException.create(ResultCodeEnum.FAIL.getCode(), e.getMessage());
}
SysDevice sysDevice = new SysDevice(); SysDevice sysDevice = new SysDevice();
sysDevice.setId(id); sysDevice.setId(id);
sysDevice.setDeviceNo(deviceNo); sysDevice.setDeviceNo(deviceNo);
...@@ -102,17 +135,32 @@ public class DeviceServiceImpl implements DeviceService{ ...@@ -102,17 +135,32 @@ public class DeviceServiceImpl implements DeviceService{
String deviceType = sysIndent.getDeviceType(); String deviceType = sysIndent.getDeviceType();
if (BizConstants.SYS_ORDER_SERVICE_ITEM_GPS.equals(deviceType) || BizConstants.SYS_ORDER_SERVICE_ITEM_GPS_WIRELESS.equals(deviceType) if (BizConstants.SYS_ORDER_SERVICE_ITEM_GPS.equals(deviceType) || BizConstants.SYS_ORDER_SERVICE_ITEM_GPS_WIRELESS.equals(deviceType)
|| BizConstants.SYS_ORDER_SERVICE_ITEM_GPS_GT700F.equals(deviceType)) { || BizConstants.SYS_ORDER_SERVICE_ITEM_GPS_GT700F.equals(deviceType)) {
//数据大于500 请求url参数过长 切割后再请求
int limit = 500;
if (deviceNos.size() > limit) {
List<List<String>> splitData = splitData(deviceNos,limit);
for (List<String> stringList : splitData) {
String dataStr = StringUtils.join(stringList, ",");
ResultObject result = checkDeviceTypeFromEdun(deviceType, dataStr, errorDevices);
if (result != null) {
return result;
}
}
} else {
ResultObject result = checkDeviceTypeFromEdun(deviceType, deviceNoList, errorDevices); ResultObject result = checkDeviceTypeFromEdun(deviceType, deviceNoList, errorDevices);
if (result != null) { if (result != null) {
return result; return result;
} }
} }
}
if (sysDeviceMapper.countByIndentNo(sysIndent.getIndentNo()) > 0) {
//1.清除用户的订货单设备 //1.清除用户的订货单设备
SysDevice device=new SysDevice(); SysDevice device = new SysDevice();
device.setUserId(userId); device.setUserId(userId);
device.setIndentNo(sysIndent.getIndentNo()); device.setIndentNo(sysIndent.getIndentNo());
sysDeviceMapper.deleteDevices(device); sysDeviceMapper.deleteDevices(device);
}
if (sysIndent.getSendType() == 2) { if (sysIndent.getSendType() == 2) {
for (int i = 0; i < deviceNos.size(); i++) { for (int i = 0; i < deviceNos.size(); i++) {
...@@ -284,4 +332,96 @@ public class DeviceServiceImpl implements DeviceService{ ...@@ -284,4 +332,96 @@ public class DeviceServiceImpl implements DeviceService{
List<SysDevice> list=sysDeviceMapper.getByIndentNo(indentNo); List<SysDevice> list=sysDeviceMapper.getByIndentNo(indentNo);
return sysDeviceMapper.updates(list); return sysDeviceMapper.updates(list);
} }
@Override
@Transactional
public ResultObject indentNoBatchInsertDevice(String indentNo, HttpServletRequest request) {
SysIndent indent = indentService.getByIndentNo(indentNo);
if (indent == null) {
return new ResultObject(ResultCodeEnum.INDENT_NOT_EXIST.getCode(), ResultCodeEnum.INDENT_NOT_EXIST.getMsg());
}
int userId= UserUtils.getUserId(request);
List<String> deviceNoList = indentService.getDeviceNoList(indentNo);
if (deviceNoList.isEmpty()){
return new ResultObject(ResultCodeEnum.INDENT_DEVICE_NOT_EXIST.getCode(), ResultCodeEnum.INDENT_DEVICE_NOT_EXIST.getMsg());
}
String deviceNoListStr = StringUtils.join(deviceNoList, ",");
ResultObject resultObject = checkAndInserts(deviceNoListStr, indentNo, userId);
if (resultObject.getCode() != ResultCodeEnum.SUCCESS.getCode()) {
String remark = "订货单收货失败:" + resultObject.getMessage();
indentService.addIndentDeviceLog(indent.getId(), null, remark, userId);
logger.error("订货单:" + indentNo + "收货失败原因===:" + resultObject.getMessage());
return resultObject;
}
if (resultObject.getData() != null) {
String remark = "收货失败,请联系运营人员";
indentService.addIndentDeviceLog(indent.getId(), null, remark, userId);
StringBuilder stb = new StringBuilder();
List<ErrorDevice> errorDeviceList = (List<ErrorDevice>) resultObject.getData();
for (ErrorDevice errorDevice : errorDeviceList) {
stb.append("设备号:").append(errorDevice.getDeviceNo()).append("--").append(errorDevice.getError());
stb.append("\n");
}
logger.error("订货单:" + indentNo + "收货失败原因===:" + stb);
return new ResultObject(ResultCodeEnum.INDENT_DEVICE_ERROR_EXIST.getCode(), ResultCodeEnum.INDENT_DEVICE_ERROR_EXIST.getMsg());
}
ResultObject object = indentService.confirmReceipt(request,indent.getId(),null);
if (object.getCode() != ResultCodeEnum.SUCCESS.getCode()) {
String remark = "订货单收货失败:" + object.getMessage();
indentService.addIndentDeviceLog(indent.getId(), null, remark, userId);
logger.error("订货单:" + indentNo + "收货失败原因===:" + object.getMessage());
return object;
}
return object;
}
private List<List<String>> splitData(List<String> deviceNoList, int limit) {
// 使用流来平均分割List
List<List<String>> chunkedLists = IntStream.range(0, deviceNoList.size())
.boxed() // 将int流转换为Integer流
.collect(Collectors.groupingBy(
i -> i / limit, // 分组函数,计算每个元素属于哪个子List
Collectors.mapping(deviceNoList::get, Collectors.toList()) // 收集器,将每个子List的元素收集起来
))
.values() // 获取分组后的值(即子List)
.stream() // 将值的集合转换为流
.collect(Collectors.toList()); // 收集最终的子List到新的List中
return chunkedLists;
}
@Override
@Transactional
public ResultObject secondmentBatchInsertDevice(String secondmentNo, int userId) {
//主要逻辑都在借调单service
return secondmentService.confirmReceipt(secondmentNo,userId);
}
@Override
@Transactional
public int updateUserByDeviceNo(Integer beSecondedId, Integer secondedId, String deviceNo, int updateBy) {
//更新设备归属人
return sysDeviceMapper.updateUserByDeviceNo(beSecondedId,secondedId,deviceNo,updateBy);
}
public SysDevice selectByDeviceNo(String deviceNo) {
return sysDeviceMapper.selectByDeviceNo(deviceNo);
}
@Override
@Transactional
public int updateUserByDeviceNoList(Integer beSecondedId, Integer secondedId, List<String> deviceNoList, int updateBy) {
//批量更新设备归属人
return sysDeviceMapper.updateUserByDeviceNoList(beSecondedId,secondedId,deviceNoList,updateBy);
}
private Boolean returnMessageHandler(JSONObject jsonObject) {
if (!"0".equals(jsonObject.getString("returnCode"))) {
return false;
}
JSONObject data = jsonObject.getJSONObject("data");
return data != null;
}
} }
...@@ -32,7 +32,10 @@ public class IndentLogisticsServiceImpl implements IndentLogisticsService{ ...@@ -32,7 +32,10 @@ public class IndentLogisticsServiceImpl implements IndentLogisticsService{
// TODO Auto-generated method stub // TODO Auto-generated method stub
Integer userId = UserUtils.getUserId(request); Integer userId = UserUtils.getUserId(request);
Integer indentId = indentLogistics.getIndentId(); Integer indentId = indentLogistics.getIndentId();
SysIndentLogistics sysIndentLogistics = indentLogisticsDao.getByIndentId(indentId); if (indentLogistics.getOrderType() == null) {
indentLogistics.setOrderType(1);
}
SysIndentLogistics sysIndentLogistics = indentLogisticsDao.getByIndentId(indentId, indentLogistics.getOrderType());
Date now = new Date(); Date now = new Date();
int num = 0; int num = 0;
if (sysIndentLogistics == null) { if (sysIndentLogistics == null) {
...@@ -50,8 +53,8 @@ public class IndentLogisticsServiceImpl implements IndentLogisticsService{ ...@@ -50,8 +53,8 @@ public class IndentLogisticsServiceImpl implements IndentLogisticsService{
} }
@Override @Override
public SysIndentLogistics getByIndentId(Integer indentId) { public SysIndentLogistics getByIndentId(Integer indentId, Integer orderType) {
return indentLogisticsDao.getByIndentId(indentId); return indentLogisticsDao.getByIndentId(indentId, orderType);
} }
} }
package com.glsx.ordercenter.service.impl; package com.glsx.ordercenter.service.impl;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PushbackInputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
...@@ -9,10 +13,33 @@ import java.util.UUID; ...@@ -9,10 +13,33 @@ import java.util.UUID;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import com.alibaba.excel.EasyExcel;
import com.alibaba.fastjson.JSON;
import com.glsx.common.utils.*;
import com.glsx.common.utils.DateUtil;
import com.glsx.excel.poi.CellType;
import com.glsx.excel.poi.ExcelUtil;
import com.glsx.ordercenter.dto.*;
import com.glsx.ordercenter.listener.IndentImportDeviceDataListener;
import com.glsx.ordercenter.mapper.SysIndentImportDeviceMapper;
import com.glsx.ordercenter.pojo.*;
import com.glsx.ordercenter.utils.EasyExcelUtils;
import com.glsx.ordercenter.utils.FileUploadServerData;
import com.glsx.ordercenter.utils.FileUtils;
import org.apache.commons.collections.CollectionUtils;
import org.apache.poi.POIXMLDocument;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
...@@ -22,24 +49,13 @@ import com.glsx.common.constants.Constants; ...@@ -22,24 +49,13 @@ import com.glsx.common.constants.Constants;
import com.glsx.common.constants.ResultObject; import com.glsx.common.constants.ResultObject;
import com.glsx.common.feign.client.CommonClient; import com.glsx.common.feign.client.CommonClient;
import com.glsx.common.feign.client.UserClient; import com.glsx.common.feign.client.UserClient;
import com.glsx.common.utils.DateUtil;
import com.glsx.common.utils.Page;
import com.glsx.common.utils.RedisCacheUtil;
import com.glsx.common.utils.UserUtils;
import com.glsx.ordercenter.constants.BizConstants; import com.glsx.ordercenter.constants.BizConstants;
import com.glsx.ordercenter.constants.IndentStatusEnum; import com.glsx.ordercenter.constants.IndentStatusEnum;
import com.glsx.ordercenter.constants.ResultCodeEnum; import com.glsx.ordercenter.constants.ResultCodeEnum;
import com.glsx.ordercenter.dto.Traces;
import com.glsx.ordercenter.dto.TracesVo;
import com.glsx.ordercenter.exception.BusinessException; import com.glsx.ordercenter.exception.BusinessException;
import com.glsx.ordercenter.mapper.SysDeviceMapper; import com.glsx.ordercenter.mapper.SysDeviceMapper;
import com.glsx.ordercenter.mapper.SysIndentLogMapper; import com.glsx.ordercenter.mapper.SysIndentLogMapper;
import com.glsx.ordercenter.mapper.SysIndentMapper; import com.glsx.ordercenter.mapper.SysIndentMapper;
import com.glsx.ordercenter.pojo.SysDevice;
import com.glsx.ordercenter.pojo.SysIndent;
import com.glsx.ordercenter.pojo.SysIndentLog;
import com.glsx.ordercenter.pojo.SysIndentLogistics;
import com.glsx.ordercenter.pojo.SysReceiveAddress;
import com.glsx.ordercenter.pojo.user.SysUser; import com.glsx.ordercenter.pojo.user.SysUser;
import com.glsx.ordercenter.service.DeviceRepertoryService; import com.glsx.ordercenter.service.DeviceRepertoryService;
import com.glsx.ordercenter.service.DeviceService; import com.glsx.ordercenter.service.DeviceService;
...@@ -49,6 +65,7 @@ import com.glsx.ordercenter.service.IndentService; ...@@ -49,6 +65,7 @@ import com.glsx.ordercenter.service.IndentService;
import com.glsx.ordercenter.service.LogisticsService; import com.glsx.ordercenter.service.LogisticsService;
import com.glsx.ordercenter.service.ReceiveAddressService; import com.glsx.ordercenter.service.ReceiveAddressService;
import com.glsx.ordercenter.utils.IndentUtil; import com.glsx.ordercenter.utils.IndentUtil;
import org.springframework.web.multipart.MultipartFile;
@Service @Service
public class IndentServiceImpl implements IndentService { public class IndentServiceImpl implements IndentService {
...@@ -95,6 +112,9 @@ public class IndentServiceImpl implements IndentService { ...@@ -95,6 +112,9 @@ public class IndentServiceImpl implements IndentService {
@Autowired @Autowired
private IndentUtil indentUtil; private IndentUtil indentUtil;
@Autowired
private SysIndentImportDeviceMapper importDeviceMapper;
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public ResultObject add(HttpServletRequest request, SysIndent indent) { public ResultObject add(HttpServletRequest request, SysIndent indent) {
...@@ -152,6 +172,26 @@ public class IndentServiceImpl implements IndentService { ...@@ -152,6 +172,26 @@ public class IndentServiceImpl implements IndentService {
int num = indentDao.insertSelective(indent); int num = indentDao.insertSelective(indent);
if (num >0) { if (num >0) {
// 批量导入的订货单
if (indent.getIndentType() != null && indent.getIndentType() == 2) {
List<SysIndentImportDevice> list = new ArrayList<>();
Date now = new Date();
for (String deviceNo : indent.getDeviceNoList()) {
SysIndentImportDevice importDevice = new SysIndentImportDevice();
importDevice.setIndentNo(indentNo);
importDevice.setDeviceNo(deviceNo);
importDevice.setBatchImportTime(now);
importDevice.setCreateTime(now);
importDevice.setCreateBy(currentUserId);
list.add(importDevice);
}
importDeviceMapper.insertBatchSelective(list);
// 更新订货单设备数量
SysIndent record = new SysIndent();
record.setDeviceAmount(list.size());
record.setId(indent.getId());
indentDao.updateByPrimaryKeySelective(record);
}
/* /*
* 添加操作日志 * 添加操作日志
*/ */
...@@ -285,6 +325,34 @@ public class IndentServiceImpl implements IndentService { ...@@ -285,6 +325,34 @@ public class IndentServiceImpl implements IndentService {
@Transactional @Transactional
@Override @Override
public ResultObject update(SysIndent indent) { public ResultObject update(SysIndent indent) {
SysIndent o = indentDao.getDetail(indent.getId());
if (o == null) {
throw BusinessException.create(ResultCodeEnum.SECONDMENT_NOT_EXIST.getCode(), ResultCodeEnum.SECONDMENT_NOT_EXIST.getMsg());
}
if (o.getIndentType() == 2) {
if (CollectionUtils.isEmpty(indent.getDeviceNoList())) {
return new ResultObject(ResultCodeEnum.PARAM_ERROR.getCode(), "设备号列表不能为空");
}
// 验证设备号是否变更
List<String> deviceNoList = indent.getDeviceNoList();
List<String> odeviceNos = importDeviceMapper.getDeviceNoListByIndentNo(o.getIndentNo());
if (odeviceNos.size() != deviceNoList.size()) {
// 发生变更
importDeviceMapper.deleteByIndentNo(o.getIndentNo());
List<SysIndentImportDevice> n = new ArrayList<>();
Date now = new Date();
for (String deviceNo : deviceNoList) {
SysIndentImportDevice device = new SysIndentImportDevice();
device.setIndentNo(o.getIndentNo());
device.setDeviceNo(deviceNo);
device.setBatchImportTime(now);
device.setCreateTime(now);
device.setCreateBy(indent.getUpdateBy());
n.add(device);
}
importDeviceMapper.insertBatchSelective(n);
}
}
// TODO Auto-generated method stub // TODO Auto-generated method stub
Integer receiveAddressId = indent.getReceiveAddressId(); Integer receiveAddressId = indent.getReceiveAddressId();
if (receiveAddressId != null) { if (receiveAddressId != null) {
...@@ -339,7 +407,7 @@ public class IndentServiceImpl implements IndentService { ...@@ -339,7 +407,7 @@ public class IndentServiceImpl implements IndentService {
} }
indentLog.setRemark(remark); indentLog.setRemark(remark);
indentLog.setCreateBy(indent.getUpdateBy()); indentLog.setCreateBy(indent.getUpdateBy());
indentLog.setCreateTime(indent.getUpdateTime()); indentLog.setCreateTime(new Date());
int num = indentLogDao.insertSelective(indentLog); int num = indentLogDao.insertSelective(indentLog);
return num; return num;
} }
...@@ -377,9 +445,12 @@ public class IndentServiceImpl implements IndentService { ...@@ -377,9 +445,12 @@ public class IndentServiceImpl implements IndentService {
public SysIndent getDetail(Integer id) { public SysIndent getDetail(Integer id) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
SysIndent indent = indentDao.getDetail(id); SysIndent indent = indentDao.getDetail(id);
if (indent == null) {
throw BusinessException.create(ResultCodeEnum.SECONDMENT_NOT_EXIST.getCode(), ResultCodeEnum.SECONDMENT_NOT_EXIST.getMsg());
}
Integer districtCode = indent.getDistrictCode(); Integer districtCode = indent.getDistrictCode();
indent.setSysArea(areaService.getAllChargeItems(districtCode)); indent.setSysArea(areaService.getAllChargeItems(districtCode));
SysIndentLogistics sysIndentLogistics=indentLogisticsService.getByIndentId(id); SysIndentLogistics sysIndentLogistics=indentLogisticsService.getByIndentId(id, 1);
if (sysIndentLogistics != null) { if (sysIndentLogistics != null) {
String expCode=sysIndentLogistics.getLogisticsUnicode(); String expCode=sysIndentLogistics.getLogisticsUnicode();
String expNo=sysIndentLogistics.getLogisticsNo(); String expNo=sysIndentLogistics.getLogisticsNo();
...@@ -396,6 +467,10 @@ public class IndentServiceImpl implements IndentService { ...@@ -396,6 +467,10 @@ public class IndentServiceImpl implements IndentService {
} }
} }
if (indent.getIndentType() == 2){
indent.setDeviceNoList(importDeviceMapper.getDeviceNoListByIndentNo(indent.getIndentNo()));
}
/* /*
* 取消单,获取取消人的姓名 * 取消单,获取取消人的姓名
*/ */
...@@ -570,9 +645,11 @@ public class IndentServiceImpl implements IndentService { ...@@ -570,9 +645,11 @@ public class IndentServiceImpl implements IndentService {
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@Override @Override
public ResultObject confirmReceipt(HttpServletRequest request, Integer id) { public ResultObject confirmReceipt(HttpServletRequest request, Integer id, Integer currentUserId) {
if (currentUserId == null) {
currentUserId = UserUtils.getUserId(request);
}
// TODO Auto-generated method stub // TODO Auto-generated method stub
Integer currentUserId = UserUtils.getUserId(request);
SysIndent indent = indentDao.getDetail(id); SysIndent indent = indentDao.getDetail(id);
if (indent != null) { if (indent != null) {
Integer indentStatus = indent.getIndentStatus(); Integer indentStatus = indent.getIndentStatus();
...@@ -686,5 +763,283 @@ public class IndentServiceImpl implements IndentService { ...@@ -686,5 +763,283 @@ public class IndentServiceImpl implements IndentService {
return list; return list;
} }
@Override
public List<IndentImportDeviceReq> getImportDeviceDetail(Page page, Integer indentId, String deviceNo) {
PageHelper.startPage(page.getPageIndex(), page.getPageSize(), true);
return importDeviceMapper.selectImportDeviceList(indentId, deviceNo);
}
@Override
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = {Exception.class})
public Boolean deleteIndentImportDeviceById(Integer id) {
String indentNo = importDeviceMapper.selectIndentNoById(id);
if (StringUtils.isEmpty(indentNo)) {
throw BusinessException.create(ResultCodeEnum.FAIL.getCode(), "删除失败,设备不存在!");
}
SysIndent indent = indentDao.selectByIndentNo(indentNo);
if (indent == null) {
throw BusinessException.create(ResultCodeEnum.FAIL.getCode(), "删除失败,订单号不存在!");
}
if (indent.getIndentStatus() == 40) {
throw BusinessException.create(ResultCodeEnum.FAIL.getCode(), "删除失败,订单已收货!");
}
if (indent.getDeviceAmount() <= 1) {
throw BusinessException.create(ResultCodeEnum.FAIL.getCode(), "删除失败,设备数量不足!");
}
String deviceNo = importDeviceMapper.selectDeviceNoById(id);
importDeviceMapper.deleteByPrimaryKey(id);
indent.setDeviceAmount(indent.getDeviceAmount() - 1);
indent.setUpdateTime(new Date());
indentDao.updateByPrimaryKeySelective(indent);
//添加操作日志
Integer indentId = indent.getId();
String remark = "删除设备" + deviceNo;
addIndentLog(indentId, null, remark);
return true;
}
/*
每天凌晨0点更新7天未收货的订货单状态为已完成(定时任务)
*/
@Scheduled(cron = "0 1 0 * * ?")
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = {Exception.class})
public void updateUnReceivedIndentIds() {
List<Integer> indentIds = indentDao.selectUnReceivedIndentIds();
if (indentIds.isEmpty()) {
return;
}
String lockKey = "carservice:lock:indent:id";
String value = UUID.randomUUID().toString();
try {
boolean result = redisCacheUtil.lock(lockKey, value, 60);
if (result) {
for (Integer id : indentIds) {
SysIndent indent = indentDao.selectByPrimaryKey(id);
if (indent == null) {
continue;
}
List<String> deviceNoList = getDeviceNoList(indent.getIndentNo());
if (deviceNoList.isEmpty()) {
continue;
}
String deviceNoListStr = String.join(",", deviceNoList);
ResultObject resultObject = deviceService.checkAndInserts(deviceNoListStr, indent.getIndentNo(), indent.getUserId());
if (resultObject.getCode() != ResultCodeEnum.SUCCESS.getCode()) {
String remark = "订货单7天自动收货失败:" + resultObject.getMessage();
addIndentDeviceLog(indent.getId(), null, remark, -1);
logger.error("订货单:" + indent.getIndentNo() + "收货失败原因===:" + resultObject.getMessage());
continue;
}
if (resultObject.getData() != null) {
String remark = "订货单7天自动收货失败,请联系运营人员";
addIndentDeviceLog(indent.getId(), null, remark, -1);
StringBuilder stb = new StringBuilder();
List<ErrorDevice> errorDeviceList = (List<ErrorDevice>) resultObject.getData();
for (ErrorDevice errorDevice : errorDeviceList) {
stb.append("设备号:").append(errorDevice.getDeviceNo()).append("--").append(errorDevice.getError());
stb.append("\n");
}
logger.error("订货单:" + indent.getIndentNo() + "收货失败原因===:" + stb);
continue;
}
ResultObject object = confirmReceipt(null, indent.getId(), indent.getUserId());;
if (object.getCode() != ResultCodeEnum.SUCCESS.getCode()) {
String remark = "订货单收货失败:" + object.getMessage();
addIndentDeviceLog(indent.getId(), null, remark, -1);
logger.error("订货单:" + indent.getIndentNo() + "收货失败原因===:" + object.getMessage());
}
}
}
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
redisCacheUtil.releaseLock(lockKey, value);
}
}
public IndentImportDeviceResponse checkImportIndentDevice(MultipartFile file) {
Workbook workbook = null;
try {
InputStream inputStream = file.getInputStream();
if (!inputStream.markSupported()) {
inputStream = new PushbackInputStream(inputStream, 8);
}
if (POIFSFileSystem.hasPOIFSHeader(inputStream)) {
workbook = new HSSFWorkbook(inputStream);
}
else if (POIXMLDocument.hasOOXMLHeader(inputStream)) {
workbook = new XSSFWorkbook(OPCPackage.open(inputStream));
}
} catch (Exception e) {
throw new RuntimeException(e);
}
Sheet sheet = workbook.getSheetAt(0);
if (sheet == null) {
throw BusinessException.create(ResultCodeEnum.FAIL.getCode(), "导入的excel数据为空,请检查后重试!");
}
Row hRow = sheet.getRow(0);
if (hRow == null) {
throw BusinessException.create(ResultCodeEnum.FAIL.getCode(), "导入的excel数据为空,请检查后重试!");
}
Cell hCell = hRow.getCell(0);
if (hCell == null) {
throw BusinessException.create(ResultCodeEnum.FAIL.getCode(), "导入的excel数据为空,请检查后重试!");
}
String deviceNo = hCell.getStringCellValue();
if (!"设备号".equals(deviceNo)) {
throw BusinessException.create(ResultCodeEnum.FAIL.getCode(), "导入文件与指定模板不匹配,请检查后重试!");
}
IndentImportDeviceResponse importDeviceResponse = new IndentImportDeviceResponse();
List<IndentImportDeviceDataExportModelImport> errorList = new ArrayList<>();
List<String> deviceNoList = new ArrayList<>();
HttpUtils httpUtils = new HttpUtils();
for (int i = 1; i < sheet.getPhysicalNumberOfRows(); i++) {
Cell c = sheet.getRow(i).getCell(0);
c.setCellType(CellType.CELL_TYPE_STRING.getValue());
deviceNo = c.getStringCellValue();
IndentImportDeviceDataExportModelImport error = new IndentImportDeviceDataExportModelImport();
error.setDeviceNo(deviceNo);
if (StringUtils.isEmpty(deviceNo)) {
error.setImportFailReason("设备号为空");
errorList.add(error);
continue;
}
if (deviceNoList.size() >= 5000) {
error.setImportFailReason("导入设备数超限");
errorList.add(error);
continue;
}
if (deviceNoList.contains(deviceNo)) {
error.setImportFailReason("设备号重复");
errorList.add(error);
continue;
}
if (importDeviceMapper.countImportDeviceByDeviceNo(deviceNo) > 0) {
error.setImportFailReason("设备已归属");
errorList.add(error);
continue;
}
if (deviceDao.countDeviceByDeviceNo(deviceNo) > 0) {
error.setImportFailReason("设备已归属");
errorList.add(error);
continue;
}
String deviceUrl = PropertiesUtil.getProperty("bhg.device.verify.sn") + deviceNo;
String result = null;
try {
result = httpUtils.get(deviceUrl, null, 60);
logger.info("设备No:{}获取设备验证信息响应数据:{}", deviceNo, result);
JSONObject jsonObject = JSON.parseObject(result);
if (!returnMessageHandler(jsonObject)) {
error.setImportFailReason("设备未入库");
errorList.add(error);
continue;
}
} catch (Exception e) {
throw new RuntimeException(e);
}
deviceNoList.add(deviceNo);
}
importDeviceResponse.setSuccessCount(deviceNoList.size());
importDeviceResponse.setErrorCount(errorList.size());
importDeviceResponse.setDeviceNoList(deviceNoList);
if (!errorList.isEmpty()) {
importDeviceResponse.setErrUrl(buildFailFile("批量导入设备失败记录", errorList));
}
return importDeviceResponse;
}
private Boolean returnMessageHandler(JSONObject jsonObject) {
if (!"0".equals(jsonObject.getString("returnCode"))) {
return false;
}
JSONObject data = jsonObject.getJSONObject("data");
return data != null;
}
private String buildFailFile(String fileName, List<IndentImportDeviceDataExportModelImport> errorList) {
try {
ByteArrayOutputStream outputStream = writeToExcel(errorList);
byte[] bytes = outputStream.toByteArray();
FileUploadServerData fileUploadServerData = FileUtils.uploadToFileSystem(fileName, bytes, "xlsx");
return fileUploadServerData.getSecureUrl();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
@Override
public List<String> getDeviceNoList(String indentNo) {
return importDeviceMapper.getDeviceNoListByIndentNo(indentNo);
}
@Override
public void addIndentDeviceLog(Integer id, Integer indentStatus, String remark, Integer createBy) {
SysIndent indent = indentDao.selectByPrimaryKey(id);
SysIndentLog indentLog = new SysIndentLog();
indentLog.setIndentId(id);
if (indentStatus == null) {
indentLog.setIndentStatus(indent.getIndentStatus());
} else {
indentLog.setIndentStatus(indentStatus);
}
indentLog.setRemark(remark);
indentLog.setCreateBy(createBy);
indentLog.setCreateTime(new Date());
int num = indentLogDao.insertSelective(indentLog);
}
private ByteArrayOutputStream writeToExcel(List<IndentImportDeviceDataExportModelImport> errorList) throws IOException {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
// 创建新的SXSSFWorkbook
SXSSFWorkbook workbook = new SXSSFWorkbook();
// 创建一个工作表
Sheet sheet = workbook.createSheet("Sheet1");
// 创建行对象
Row row;
// 创建单元格
Cell cell;
CellStyle titleStyle = workbook.createCellStyle();
setCellStyle(titleStyle, IndexedColors.LIGHT_GREEN, true, false);
row = sheet.createRow(0);
cell = row.createCell(0);
cell.setCellValue("错误内容");
cell.setCellStyle(titleStyle);
cell = row.createCell(1);
cell.setCellValue("备注");
cell.setCellStyle(titleStyle);
int rowNum = 1;
CellStyle bodyStyle = workbook.createCellStyle();
setCellStyle(bodyStyle, IndexedColors.LIGHT_YELLOW, true, false);
for (IndentImportDeviceDataExportModelImport data : errorList) {
int i = 0;
row = sheet.createRow(rowNum++);
cell = row.createCell(i);
cell.setCellValue(data.getDeviceNo());
cell.setCellStyle(bodyStyle);
cell = row.createCell(i+1);
cell.setCellValue(data.getImportFailReason());
cell.setCellStyle(bodyStyle);
}
workbook.write(outputStream);
// 关闭工作簿资源
workbook.dispose();
return outputStream;
}
private void setCellStyle(CellStyle style, IndexedColors background, boolean center, boolean wrapText) {
style.setFillForegroundColor(background.getIndex());
style.setFillPattern((short) 1);
style.setBorderBottom((short) 1);
style.setBorderLeft((short) 1);
style.setBorderRight((short) 1);
style.setBorderTop((short) 1);
if (center) {
style.setAlignment((short) 2);
style.setVerticalAlignment((short) 1);
}
style.setWrapText(wrapText);
}
} }
...@@ -36,7 +36,7 @@ public class LogisticsServiceImpl implements LogisticsService{ ...@@ -36,7 +36,7 @@ public class LogisticsServiceImpl implements LogisticsService{
@Override @Override
public ResultObject catLogisticsTrail(Integer indentId) { public ResultObject catLogisticsTrail(Integer indentId) {
//查询订单物流详情 //查询订单物流详情
SysIndentLogistics sysIndentLogistics=indentLogisticsDao.getByIndentId(indentId); SysIndentLogistics sysIndentLogistics=indentLogisticsDao.getByIndentId(indentId, 1);
if (org.springframework.util.StringUtils.isEmpty(sysIndentLogistics)) { if (org.springframework.util.StringUtils.isEmpty(sysIndentLogistics)) {
return new ResultObject(ResultCodeEnum.INDENT_NOT_EXIST.getCode(), ResultCodeEnum.INDENT_NOT_EXIST.getMsg()); return new ResultObject(ResultCodeEnum.INDENT_NOT_EXIST.getCode(), ResultCodeEnum.INDENT_NOT_EXIST.getMsg());
} }
......
...@@ -17,10 +17,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -17,10 +17,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.Arrays; import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Slf4j @Slf4j
...@@ -44,12 +41,17 @@ public class OcrResultServiceImpl implements OcrResultService { ...@@ -44,12 +41,17 @@ public class OcrResultServiceImpl implements OcrResultService {
SysOrderOcrSnResult snResult = snResultList.get(0); SysOrderOcrSnResult snResult = snResultList.get(0);
String[] split = snResult.getDbSn().split(","); String[] split = snResult.getDbSn().split(",");
List<String> sns = Arrays.asList(split); List<String> sns = Arrays.asList(split);
List<SysOrderOcrSnResult> resultList = snResultList.stream().filter(i -> StringUtils.isNotBlank(i.getOcrSn()) && sns.contains(i.getOcrSn())).collect(Collectors.toList()); //ocr识别出来的结果去重
Set<String> ocrSns = snResultList.stream().map(SysOrderOcrSnResult::getOcrSn).collect(Collectors.toSet());
if (sns.size() == ocrSns.size()) {
List<String> resultList = ocrSns.stream().filter(i -> StringUtils.isNotBlank(i) && sns.contains(i)).collect(Collectors.toList());
boolean a = sns.size() == resultList.size(); boolean a = sns.size() == resultList.size();
map.put("snResult", a); map.put("snResult", a);
} else {
map.put("snResult", false);
} }
}
List<SysOrderOcrVinResult> vinResultList = sysOrderOcrVinResultMapper.selectByOrderId(orderId); List<SysOrderOcrVinResult> vinResultList = sysOrderOcrVinResultMapper.selectByOrderId(orderId);
if (CollectionUtils.isEmpty(vinResultList)) { if (CollectionUtils.isEmpty(vinResultList)) {
...@@ -57,7 +59,6 @@ public class OcrResultServiceImpl implements OcrResultService { ...@@ -57,7 +59,6 @@ public class OcrResultServiceImpl implements OcrResultService {
} else { } else {
SysOrderOcrVinResult vinResult = vinResultList.get(0); SysOrderOcrVinResult vinResult = vinResultList.get(0);
boolean b = vinResult.getDbVin().equals(vinResult.getOcrVin()); boolean b = vinResult.getDbVin().equals(vinResult.getOcrVin());
map.put("vinResult", b); map.put("vinResult", b);
} }
...@@ -84,5 +85,4 @@ public class OcrResultServiceImpl implements OcrResultService { ...@@ -84,5 +85,4 @@ public class OcrResultServiceImpl implements OcrResultService {
log.info("manualOcrRecognition ===>send Kafka info:" + jsonString); log.info("manualOcrRecognition ===>send Kafka info:" + jsonString);
} }
} }
...@@ -65,6 +65,7 @@ import java.util.concurrent.Executors; ...@@ -65,6 +65,7 @@ import java.util.concurrent.Executors;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
* @author Zheng Xiajun * @author Zheng Xiajun
* @ClassName: OrderServiceImpl * @ClassName: OrderServiceImpl
...@@ -4310,6 +4311,9 @@ public class OrderServiceImpl implements IOrderService { ...@@ -4310,6 +4311,9 @@ public class OrderServiceImpl implements IOrderService {
if (!verifyStockMap.isEmpty()) { if (!verifyStockMap.isEmpty()) {
return new ResultObject(ResultCodeEnum.DEVICE_BELONG_USER.getCode(), ResultCodeEnum.DEVICE_BELONG_USER.getMsg()); return new ResultObject(ResultCodeEnum.DEVICE_BELONG_USER.getCode(), ResultCodeEnum.DEVICE_BELONG_USER.getMsg());
} }
//扣减库存
reduceStock(orderDeviceList,userId);
//保存数据 //保存数据
boolean isAudit = (item.getIsAudit() == 1 || order.getAuditStatus() != -1); boolean isAudit = (item.getIsAudit() == 1 || order.getAuditStatus() != -1);
byte auditStatus = this.saveOrderData(deviceReq, order, userId, isAudit); byte auditStatus = this.saveOrderData(deviceReq, order, userId, isAudit);
...@@ -4324,6 +4328,39 @@ public class OrderServiceImpl implements IOrderService { ...@@ -4324,6 +4328,39 @@ public class OrderServiceImpl implements IOrderService {
return resultObject; return resultObject;
} }
private void reduceStock(List<SysOrderDevice> orderDeviceList, int userId){
try {
List<String> list = orderDeviceList.stream().map(SysOrderDevice::getDeviceNo).collect(Collectors.toList());
SysDeviceExample deviceExample = new SysDeviceExample();
deviceExample.createCriteria().andUserIdEqualTo(userId).andDeviceStatusEqualTo(Constants.DEVICE_STATUS_NO_ACTIVE).andDeviceNoIn(list);
List<SysDevice> sysDevices = deviceMapper.selectByExample(deviceExample);
if (sysDevices.isEmpty()){
return;
}
for (SysDevice device : sysDevices) {
//设备关联的订单未确认收货不允许激活(通过拆除或者检修入库的设备没有订货单,单号可以为空)
SysIndent sysIndent = indentMapper.getByUserIdAndDeviceNo(userId, device.getDeviceNo());
if (sysIndent == null){
continue;
}
if (sysIndent.getIndentStatus() != IndentStatusEnum.INDENT_COMPLETE.getIndentStatus()) {
continue;
}
//技工设备库存减一
deviceRepertoryService.reduceDeviceRepertory(userId, device.getDeviceType(), 1);
//设备状态改为已激活
SysDevice sysDevice = new SysDevice();
sysDevice.setDeviceStatus(Constants.DEVICE_STATUS_ISACTIVE);
sysDevice.setId(device.getId());
deviceMapper.updateByPrimaryKeySelective(sysDevice);
//添加设备消耗记录
addDeviceConsumeLog(userId, device.getDeviceNo(), device.getDeviceType(), 1);
}
} catch (Exception e) {
logger.error("安装设备扣减库存异常 error:" + e.getMessage(), e);
}
}
/** /**
* 安装单保存数据封装 * 安装单保存数据封装
* *
...@@ -5362,4 +5399,36 @@ public class OrderServiceImpl implements IOrderService { ...@@ -5362,4 +5399,36 @@ public class OrderServiceImpl implements IOrderService {
} }
logger.info("同步拆机数据结束===" + orderId); logger.info("同步拆机数据结束===" + orderId);
} }
@Override
public Map<String, Object> checkVinAndSn(Integer orderId, Integer serviceItemId) {
SysOrder sysOrder = orderMapper.selectByPrimaryKey(orderId);
if (sysOrder == null) {
throw BusinessException.create(ResultCodeEnum.ORDER_NOT_EXIST.getCode(), ResultCodeEnum.ORDER_NOT_EXIST.getMsg());
}
String checkVin = sysOrder.getVinNoDecode().toUpperCase();
if (StringUtils.isBlank(checkVin) || StringUtils.isBlank(sysOrder.getVinHash())) {
throw BusinessException.create(ResultCodeEnum.VIN_CHECK_ERROR.getCode(), ResultCodeEnum.VIN_CHECK_ERROR.getMsg());
}
SysServiceItem item = serviceItemMapper.selectByPrimaryKey(serviceItemId);
if (item == null || StringUtils.isBlank(sysOrder.getServiceCode())) {
throw BusinessException.create(ResultCodeEnum.SERVICE_ITEM_CODE_NOT_EXIST.getCode(), ResultCodeEnum.SERVICE_ITEM_CODE_NOT_EXIST.getMsg());
}
Map<String, Object> resMap = new HashMap<>();
resMap.put("vinCheckResult", true);
resMap.put("snCheckResult", true);
//将车架号加密变成密文和数据库的vinHash密文进行校验
if (!sysOrder.getVinHash().equals(DigestUtils.md5DigestAsHex(checkVin.getBytes()))) {
resMap.put("vinCheckResult", false);
}
//校验订单的ServiceCode和入参进来的服务项的ServiceCode是否相同
if (!sysOrder.getServiceCode().equals(item.getServiceCode())) {
resMap.put("snCheckResult", false);
}
return resMap;
}
} }
package com.glsx.ordercenter.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.glsx.common.constants.Constants;
import com.glsx.common.constants.ResultObject;
import com.glsx.common.feign.client.UserClient;
import com.glsx.common.utils.*;
import com.glsx.common.utils.DateUtil;
import com.glsx.excel.poi.CellType;
import com.glsx.ordercenter.constants.BizConstants;
import com.glsx.ordercenter.constants.IndentStatusEnum;
import com.glsx.ordercenter.constants.ResultCodeEnum;
import com.glsx.ordercenter.constants.SecondmentStatusEnum;
import com.glsx.ordercenter.dto.*;
import com.glsx.ordercenter.dto.req.InsertSecondmentReq;
import com.glsx.ordercenter.dto.req.SecondmentImportDeviceReq;
import com.glsx.ordercenter.dto.req.SecondmentQueryReq;
import com.glsx.ordercenter.dto.req.UpdateSecondmentReq;
import com.glsx.ordercenter.exception.BusinessException;
import com.glsx.ordercenter.mapper.SysSecondmentImportDeviceMapper;
import com.glsx.ordercenter.mapper.SysSecondmentLogMapper;
import com.glsx.ordercenter.mapper.SysSecondmentMapper;
import com.glsx.ordercenter.pojo.*;
import com.glsx.ordercenter.pojo.user.SysUser;
import com.glsx.ordercenter.service.*;
import com.glsx.ordercenter.utils.FileUploadServerData;
import com.glsx.ordercenter.utils.FileUtils;
import org.apache.commons.collections.CollectionUtils;
import org.apache.poi.POIXMLDocument;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import javax.servlet.http.HttpServletRequest;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PushbackInputStream;
import java.util.*;
import java.util.stream.Collectors;
/**
* @title SysSecondmentServiceImpl
* @Author zhangzc
* @Description
* @Date 2024/4/10 14:24
**/
@Component
public class SysSecondmentServiceImpl implements SysSecondmentService {
@Autowired
private SysSecondmentMapper secondmentMapper;
@Autowired
private IndentLogisticsService indentLogisticsService;
@Autowired
private LogisticsService logisticsService;
@Autowired
private UserClient userClient;
@Autowired
private IAreaService areaService;
@Autowired
private SysSecondmentImportDeviceMapper secondmentImportDeviceMapper;
@Autowired
private DeviceRepertoryService deviceRepertoryService;
@Autowired
private DeviceService deviceService;
@Autowired
private SysSecondmentLogMapper sysSecondmentLogMapper;
@Autowired
private ReceiveAddressService receiveAddressService;
@Autowired
private RedisCacheUtil redisCacheUtil;
private Logger logger = LoggerFactory.getLogger(SysSecondmentServiceImpl.class);
/*
每天凌晨1点更新7天未收货的借调单状态为已完成(定时任务)
*/
@Scheduled(cron = "0 0 1 * * ?")
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = {Exception.class})
public void updateUnReceivedSecondmentIds() {
List<Integer> secondmentIds = secondmentMapper.selectUnReceivedSecondmentIds();
if (secondmentIds.isEmpty()) {
return;
}
for (Integer id : secondmentIds) {
String secondmentNo = secondmentMapper.selectSecondmentNoById(id);
if (secondmentNo == null) {
continue;
}
deviceService.secondmentBatchInsertDevice(secondmentNo,-1);
}
}
@Override
public List<SecondmentDto> getListByPage(Page page, SecondmentQueryReq req) {
if(page!=null){
int pageIndex = page.getPageIndex();
int pageSize = page.getPageSize();
PageHelper.startPage(pageIndex, pageSize, true);
}
List<SecondmentDto> list = secondmentMapper.getListByPage(req);
return list;
}
@Override
public SecondmentDto getDetail(Integer id) {
SecondmentDto detail = secondmentMapper.getDetail(id);
if (detail == null) {
throw BusinessException.create("借调单不存在");
}
detail.setImportDevices(secondmentImportDeviceMapper.getListBySecondmentNo(detail.getSecondmentNo()));
Integer districtCode = detail.getDistrictCode();
detail.setSysArea(areaService.getAllChargeItems(districtCode));
SysIndentLogistics sysIndentLogistics=indentLogisticsService.getByIndentId(id, 2);
if (sysIndentLogistics != null) {
String expCode=sysIndentLogistics.getLogisticsUnicode();
String expNo=sysIndentLogistics.getLogisticsNo();
if(!StringUtils.isEmpty(expCode) && !StringUtils.isEmpty(expNo)){
ResultObject result = logisticsService.catLogisticsTrail(id);
if (ResultCodeEnum.SUCCESS.getCode() == result.getCode()) {
TracesVo tracesVo = (com.glsx.ordercenter.dto.TracesVo) result.getData();
List<Traces> traces = tracesVo.getTraces();
if (traces != null && traces.size() >0) {
Traces trace = traces.get(0);
detail.setTraces(trace);
}
}
}
}
/*
* 取消单,获取取消人的姓名
*/
Byte isCancel = detail.getIsCanceled();
String cancelOperatorName = null;
if (BizConstants.INDENT_CANCEL == isCancel) {
Integer secondmentStatus = SecondmentStatusEnum.SECONDMENT_CANCEL.getSecondmentStatus();
SysSecondmentLog secondmentLog = new SysSecondmentLog();
secondmentLog.setSecondmentId(id);
secondmentLog.setSecondmentStatus(secondmentStatus);
secondmentLog = sysSecondmentLogMapper.get(secondmentLog);
if (secondmentLog != null) {
Integer createBy = secondmentLog.getCreateBy();
JSONObject result = userClient.getUserById(createBy);
if (result != null && result.getIntValue("code") == ResultCodeEnum.SUCCESS.getCode()) {
JSONObject object = result.getJSONObject("data");
cancelOperatorName = object.getString("name");
detail.setCancelOperatorName(cancelOperatorName);
}
}
}
return detail;
}
@Override
public List<SysSecondmentImportDevice> getDeviceBySecondmentNo(SysSecondmentImportDevice secondmentImportDevice) {
if (StringUtils.isBlank(secondmentImportDevice.getSecondmentNo())){
throw BusinessException.create("secondmentNo must not be null");
}
return secondmentImportDeviceMapper.getDeviceBySecondmentNo(secondmentImportDevice);
}
@Override
public List<SecondmentDto> getListByUserId(Page page, SecondmentQueryReq req) {
if (page != null) {
int pageIndex = page.getPageIndex();
int pageSize = page.getPageSize();
PageHelper.startPage(pageIndex, pageSize, true);
}
Integer userId = UserUtils.getCurrentUserId();
req.setUserId(userId);
List<SecondmentDto> list = secondmentMapper.getListByUserId(req);
return list;
}
@Override
@Transactional
public ResultObject confirmReceipt(String secondmentNo, int userId) {
SysSecondment secondment = secondmentMapper.getBySecondmentNo(secondmentNo);
//查询借调人信息
Integer userType;
JSONObject obj = userClient.getUserById(secondment.getSecondedId());
if (obj != null && obj.getIntValue("code") == ResultCodeEnum.SUCCESS.getCode()) {
JSONObject sysUser = obj.getJSONObject("data");
userType = sysUser.getInteger("userType");
} else {
throw BusinessException.create(ResultCodeEnum.FAIL.getCode(), ResultCodeEnum.FAIL.getMsg());
}
Integer serviceId = -1;
if(userType == Constants.USER_TYPE_MECHANIC){
JSONObject object = userClient.getMechanicSP(secondment.getSecondedId());
if (object != null && object.getIntValue("code") == ResultCodeEnum.SUCCESS.getCode()) {
SysUser user = object.getObject("data", SysUser.class);
if (user != null) {
serviceId = user.getId();
}
} else {
throw BusinessException.create(ResultCodeEnum.FAIL.getCode(), ResultCodeEnum.FAIL.getMsg());
}
}
List<SysSecondmentImportDevice> list = secondmentImportDeviceMapper.getListBySecondmentNo(secondmentNo);
if (list.isEmpty()){
return new ResultObject(ResultCodeEnum.SECONDMENT_DEVICE_NOT_EXIST.getCode(), ResultCodeEnum.SECONDMENT_DEVICE_NOT_EXIST.getMsg());
}
//同一个借调单借调人相同 被借调人可能不同 根据被借调人来分组
Map<Integer, List<SysSecondmentImportDevice>> listMap = list.stream().collect(Collectors.groupingBy(SysSecondmentImportDevice::getBeSecondedId));
//更新设备归属人、更新库存
Integer finalServiceId = serviceId;
listMap.values().forEach(deviceList -> {
if (!deviceList.isEmpty()) {
SysSecondmentImportDevice item = deviceList.get(0);
List<String> deviceNoList = deviceList.stream().map(SysSecondmentImportDevice::getDeviceNo).collect(Collectors.toList());
int a = deviceService.updateUserByDeviceNoList(item.getBeSecondedId(), item.getSecondedId(), deviceNoList, userId);
if (a != deviceNoList.size()) {
logger.error("借调单号:{},被借调人id:{},借调设备列表数量:{},更新归属人成功数量:{}",item.getSecondmentNo(),item.getBeSecondedId(),deviceList.size(),a);
}
deviceRepertoryService.addDeviceRepertory(item.getSecondedId(), secondment.getDeviceType(), deviceList.size());
ResultObject result = deviceRepertoryService.reduceDeviceRepertory(item.getBeSecondedId(), secondment.getDeviceType(), deviceList.size());
if (result != null) {
throw BusinessException.create(result.getCode(), result.getMessage());
}
//如果借调人为技工 需要更新对应服务商的库存
if(userType == Constants.USER_TYPE_MECHANIC){
deviceRepertoryService.addDeviceRepertory(finalServiceId, secondment.getDeviceType(), 0);
}
}
});
secondmentMapper.updateSecondmentStatusById(SecondmentStatusEnum.SECONDMENT_COMPLETE.getSecondmentStatus(),userId,secondment.getId());
//新增借调单日志
String remark = "确认收货";
addSecondmentLog(secondment.getId(),null,remark);
return new ResultObject(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMsg());
}
@Override
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = {Exception.class})
public Boolean deleteSecondmentDeviceById(Integer id) {
String secondmentNo = secondmentImportDeviceMapper.selectSecondmentNoById(id);
if (StringUtils.isBlank(secondmentNo)) {
throw BusinessException.create(ResultCodeEnum.FAIL.getCode(), "删除失败,设备不存在!");
}
SysSecondment secondment = secondmentMapper.selectBySecondmentNo(secondmentNo);
if (secondment == null) {
throw BusinessException.create(ResultCodeEnum.FAIL.getCode(), "删除失败,订单号不存在!");
}
if (secondment.getSecondmentStatus() == 40) {
throw BusinessException.create(ResultCodeEnum.FAIL.getCode(), "删除失败,订单已收货!");
}
if (secondment.getSecondmentAmount() <= 1) {
throw BusinessException.create(ResultCodeEnum.FAIL.getCode(), "删除失败,设备数量不足!");
}
String deviceNo = secondmentImportDeviceMapper.selectDeviceNoById(id);
secondmentImportDeviceMapper.deleteByPrimaryKey(id);
secondment.setSecondmentAmount(secondment.getSecondmentAmount() - 1);
secondment.setUpdateTime(new Date());
secondmentMapper.updateByPrimaryKeySelective(secondment);
//新增借调单日志
String remark = "删除设备" + deviceNo;
addSecondmentLog(secondment.getId(),null,remark);
return true;
}
@Override
public Integer dispatchSecondment(HttpServletRequest request, SysIndentLogistics sysIndentLogistics) {
SysSecondment s = secondmentMapper.selectByPrimaryKey(sysIndentLogistics.getIndentId());
if (s == null) {
throw BusinessException.create(ResultCodeEnum.FAIL.getCode(), "借调单不存在");
}
if (IndentStatusEnum.INDENT_WAITDELIVER.getIndentStatus() != s.getSecondmentStatus()) {
throw BusinessException.create(ResultCodeEnum.FAIL.getCode(), "借调单已发货,不能重复发货");
}
Integer userId = UserUtils.getUserId(request);
//修改借调单状态为待收货
SysSecondment secondment = new SysSecondment();
secondment.setId(sysIndentLogistics.getIndentId());
secondment.setSecondmentStatus(IndentStatusEnum.INDENT_DELIVERED.getIndentStatus());
secondment.setUpdateBy(userId);
secondment.setUpdateTime(new Date());
secondmentMapper.updateByPrimaryKeySelective(secondment);
//添加订单操作日志
String remark = "发货";
addSecondmentLog(secondment.getId(), null, remark);
//添加到物流信息表
return indentLogisticsService.addOrUpdateIndentLogistics(request, sysIndentLogistics);
}
@Override
public List<SysSecondmentLog> getSecondmentLogList(Integer secondmentId) {
return sysSecondmentLogMapper.selectSecondmentLogList(secondmentId);
}
private int addSecondmentLog(Integer id, Integer secondmentStatus, String remark) {
SysSecondment secondment = secondmentMapper.selectByPrimaryKey(id);
SysSecondmentLog secondmentLog = new SysSecondmentLog();
secondmentLog.setSecondmentId(id);
if (secondmentStatus == null) {
secondmentLog.setSecondmentStatus(secondment.getSecondmentStatus());
} else {
secondmentLog.setSecondmentStatus(secondmentStatus);
}
secondmentLog.setRemark(remark);
secondmentLog.setCreateBy(secondment.getUpdateBy());
secondmentLog.setCreateTime(secondment.getUpdateTime());
int num = sysSecondmentLogMapper.insertSelective(secondmentLog);
return num;
}
public SecondmentImportDeviceResponse checkImportSecondmentDevice(HttpServletRequest request, SecondmentImportDeviceReq importDeviceReq) {
Integer currentUserId = UserUtils.getUserId(request);
Byte currentUserType = UserUtils.getCurrentUserType();
SecondmentImportDeviceResponse response = new SecondmentImportDeviceResponse();
List<SecondmentImportDeviceDataExportModelImport> errorList = new ArrayList<>();
HttpUtils httpUtils = new HttpUtils();
List<String> successDeviceNoList = new ArrayList<>();
if (importDeviceReq.getExportType() == 1) {
if (CollectionUtils.isEmpty(importDeviceReq.getDeviceNoList())) {
SecondmentImportDeviceDataExportModelImport error = new SecondmentImportDeviceDataExportModelImport();
error.setImportFailReason("设备号为空");
errorList.add(error);
response.setSuccessCount(0);
response.setErrorCount(1);
response.setErrUrl(buildFailFile("批量导入设备失败记录-借调单", errorList));
return response;
}
List<String> deviceNoList = importDeviceReq.getDeviceNoList();
for (String deviceNo : deviceNoList) {
SecondmentImportDeviceDataExportModelImport error = new SecondmentImportDeviceDataExportModelImport();
if (StringUtils.isBlank(deviceNo)) {
error.setImportFailReason("设备号为空");
errorList.add(error);
continue;
}
error.setDeviceNo(deviceNo);
if (successDeviceNoList.contains(deviceNo)) {
error.setImportFailReason("设备号重复");
errorList.add(error);
continue;
}
if (successDeviceNoList.size() >= 5000) {
error.setImportFailReason("导入设备数超限");
errorList.add(error);
continue;
}
String deviceUrl = PropertiesUtil.getProperty("bhg.device.verify.sn") + deviceNo;
String result = null;
try {
result = httpUtils.get(deviceUrl, null, 60);
logger.info("设备No:{}获取设备验证信息响应数据:{}", deviceNo, result);
JSONObject jsonObject = JSON.parseObject(result);
if (!returnMessageHandler(jsonObject)) {
error.setImportFailReason("设备未入库");
errorList.add(error);
continue;
}
SysDevice device = deviceService.selectByDeviceNo(deviceNo);
if (device == null) {
error.setImportFailReason("设备归属异常");
errorList.add(error);
continue;
}
if (BizConstants.USER_TYPE_ADMIN != currentUserType && !currentUserId.equals(device.getUserId())) {
error.setImportFailReason("设备归属异常");
errorList.add(error);
continue;
}
if (importDeviceReq.getSecondmentUserId().equals(device.getUserId())) {
error.setImportFailReason("设备重复归属");
errorList.add(error);
continue;
}
if (!importDeviceReq.getDeviceType().equals(device.getDeviceType())) {
error.setImportFailReason("设备号与设备名称不匹配");
errorList.add(error);
continue;
}
if (secondmentImportDeviceMapper.countImportDeviceByDeviceNo(deviceNo) > 0) {
error.setImportFailReason("设备归属异常");
errorList.add(error);
continue;
}
successDeviceNoList.add(deviceNo);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
response.setSuccessCount(successDeviceNoList.size());
response.setDeviceNoList(successDeviceNoList);
response.setErrorCount(errorList.size());
if (!errorList.isEmpty()) {
response.setErrUrl(buildFailFile("批量导入设备失败记录-借调单", errorList));
}
return response;
}
if (importDeviceReq.getFile() == null) {
throw BusinessException.create(ResultCodeEnum.FAIL.getCode(), "文件未上传,请检查后重试!");
}
Workbook workbook = null;
try {
InputStream inputStream = importDeviceReq.getFile().getInputStream();
if (!inputStream.markSupported()) {
inputStream = new PushbackInputStream(inputStream, 8);
}
if (POIFSFileSystem.hasPOIFSHeader(inputStream)) {
workbook = new HSSFWorkbook(inputStream);
}
else if (POIXMLDocument.hasOOXMLHeader(inputStream)) {
workbook = new XSSFWorkbook(OPCPackage.open(inputStream));
}
} catch (Exception e) {
throw new RuntimeException(e);
}
Sheet sheet = workbook.getSheetAt(0);
if (sheet == null) {
throw BusinessException.create(ResultCodeEnum.FAIL.getCode(), "导入的excel数据为空,请检查后重试!");
}
Row hRow = sheet.getRow(0);
if (hRow == null) {
throw BusinessException.create(ResultCodeEnum.FAIL.getCode(), "导入的excel数据为空,请检查后重试!");
}
Cell hCell = hRow.getCell(0);
if (hCell == null) {
throw BusinessException.create(ResultCodeEnum.FAIL.getCode(), "导入的excel数据为空,请检查后重试!");
}
String deviceNo = hCell.getStringCellValue();
if (!"设备号".equals(deviceNo)) {
throw BusinessException.create(ResultCodeEnum.FAIL.getCode(), "导入文件与指定模板不匹配,请检查后重试!");
}
for (int i = 1; i < sheet.getPhysicalNumberOfRows(); i++) {
Cell c = sheet.getRow(i).getCell(0);
c.setCellType(CellType.CELL_TYPE_STRING.getValue());
deviceNo = c.getStringCellValue();
SecondmentImportDeviceDataExportModelImport error = new SecondmentImportDeviceDataExportModelImport();
error.setDeviceNo(deviceNo);
if (StringUtils.isBlank(deviceNo)) {
error.setImportFailReason("设备号为空");
errorList.add(error);
continue;
}
if (successDeviceNoList.contains(deviceNo)) {
error.setImportFailReason("设备号重复");
errorList.add(error);
continue;
}
if (successDeviceNoList.size() >= 5000) {
error.setImportFailReason("导入设备数超限");
errorList.add(error);
continue;
}
String deviceUrl = PropertiesUtil.getProperty("bhg.device.verify.sn") + deviceNo;
String result = null;
try {
result = httpUtils.get(deviceUrl, null, 60);
logger.info("设备No:{}获取设备验证信息响应数据:{}", deviceNo, result);
JSONObject jsonObject = JSON.parseObject(result);
if (!returnMessageHandler(jsonObject)) {
error.setImportFailReason("设备未入库");
errorList.add(error);
continue;
}
} catch (Exception e) {
throw new RuntimeException(e);
}
SysDevice device = deviceService.selectByDeviceNo(deviceNo);
if (device == null) {
error.setImportFailReason("设备归属异常");
errorList.add(error);
continue;
}
if (BizConstants.USER_TYPE_ADMIN != currentUserType && !currentUserId.equals(device.getUserId())) {
error.setImportFailReason("设备归属异常");
errorList.add(error);
continue;
}
if (secondmentImportDeviceMapper.countImportDeviceByDeviceNo(deviceNo) > 0) {
error.setImportFailReason("设备归属异常");
errorList.add(error);
continue;
}
if (importDeviceReq.getSecondmentUserId().equals(device.getUserId())) {
error.setImportFailReason("设备重复归属");
errorList.add(error);
continue;
}
if (!importDeviceReq.getDeviceType().equals(device.getDeviceType())) {
error.setImportFailReason("设备号与设备名称不匹配");
errorList.add(error);
continue;
}
successDeviceNoList.add(deviceNo);
}
response.setSuccessCount(successDeviceNoList.size());
response.setDeviceNoList(successDeviceNoList);
response.setErrorCount(errorList.size());
if (!errorList.isEmpty()) {
response.setErrUrl(buildFailFile("批量导入设备失败记录-借调单", errorList));
}
return response;
}
@Override
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = {Exception.class})
public Boolean addSecondment(HttpServletRequest request, InsertSecondmentReq secondmentReq) {
Integer currentUserId = UserUtils.getUserId(request);
int sendType = BizConstants.INDENT_SEND_TYPE_GLSX;
SysSecondment secondment = new SysSecondment();
secondment.setSecondmentNo(getSecondmentNo());
secondment.setSendType((byte)sendType);
secondment.setSecondedId(secondmentReq.getSecondmentUserId());
secondment.setDeviceType(secondmentReq.getDeviceType());
secondment.setSecondmentAmount(secondmentReq.getDeviceNoList().size());
secondment.setSecondmentStatus(IndentStatusEnum.INDENT_WAITDELIVER.getIndentStatus());
Integer receiveAddressId = secondmentReq.getReceiveAddressId();
SysReceiveAddress receiveAddress = receiveAddressService.get(receiveAddressId);
if (receiveAddress == null) {
throw BusinessException.create(ResultCodeEnum.INDENT_RECEIVE_ADDRESSID_NOT_EXIST.getCode(), ResultCodeEnum.INDENT_RECEIVE_ADDRESSID_NOT_EXIST.getMsg());
}
String phone = receiveAddress.getPhone();
String receiverName = receiveAddress.getName();
Integer districtCode = receiveAddress.getDistrictCode();
String address = receiveAddress.getAddress();
secondment.setPhone(phone);
secondment.setReceiverName(receiverName);
secondment.setDistrictCode(districtCode);
secondment.setAddress(address);
secondment.setCreateBy(currentUserId);
secondment.setRemark(secondmentReq.getRemark());
Date now = new Date();
secondment.setCreateTime(now);
secondment.setUpdateBy(currentUserId);
secondment.setUpdateTime(now);
secondmentMapper.insertSelective(secondment);
List<SysSecondmentImportDevice> list = new ArrayList<>();
for (String deviceNo : secondmentReq.getDeviceNoList()) {
SysDevice device = deviceService.selectByDeviceNo(deviceNo);
if (device == null) {
throw BusinessException.create(ResultCodeEnum.DEVICE_NOT_EXIST.getCode(), ResultCodeEnum.DEVICE_NOT_EXIST.getMsg());
}
if (!secondment.getDeviceType().equals(device.getDeviceType())) {
throw BusinessException.create(ResultCodeEnum.DEVICE_TYPE_NOT_MATCH.getCode(), ResultCodeEnum.DEVICE_TYPE_NOT_MATCH.getMsg());
}
SysSecondmentImportDevice importDevice = new SysSecondmentImportDevice();
importDevice.setSecondmentNo(secondment.getSecondmentNo());
importDevice.setDeviceNo(deviceNo);
importDevice.setSecondedId(secondmentReq.getSecondmentUserId());
importDevice.setBeSecondedId(device.getUserId());
importDevice.setBatchImportTime(now);
importDevice.setCreateBy(currentUserId);
importDevice.setCreateTime(now);
list.add(importDevice);
}
secondmentImportDeviceMapper.insertBatchSelective(list);
//新增借调单日志
String remark = "新增借调单";
addSecondmentLog(secondment.getId(),null,remark);
return true;
}
@Override
public Boolean updateSecondment(HttpServletRequest request, UpdateSecondmentReq secondmentReq) {
SysSecondment secondment = secondmentMapper.selectByPrimaryKey(secondmentReq.getId());
if (secondment == null) {
throw BusinessException.create(ResultCodeEnum.SECONDMENT_NOT_EXIST.getCode(), ResultCodeEnum.SECONDMENT_NOT_EXIST.getMsg());
}
Integer currentUserId = UserUtils.getUserId(request);
Date now = new Date();
Integer receiveAddressId = secondmentReq.getReceiveAddressId();
if (receiveAddressId != null) {
SysReceiveAddress receiveAddress = receiveAddressService.get(receiveAddressId);
if (receiveAddress == null) {
throw BusinessException.create(ResultCodeEnum.INDENT_RECEIVE_ADDRESSID_NOT_EXIST.getCode(), ResultCodeEnum.INDENT_RECEIVE_ADDRESSID_NOT_EXIST.getMsg());
}
secondment.setPhone(receiveAddress.getPhone());
secondment.setReceiverName(receiveAddress.getName());
secondment.setDistrictCode(receiveAddress.getDistrictCode());
secondment.setAddress(receiveAddress.getAddress());
}
boolean flag = true;
List<String> secondmentDeviceNos = secondmentImportDeviceMapper.getListBySecondmentNo(secondment.getSecondmentNo()).stream().map(SysSecondmentImportDevice::getDeviceNo).collect(Collectors.toList());
if (secondmentReq.getDeviceNoList().size() != secondmentDeviceNos.size()) {
flag = false;
}
if (flag) {
for (String deviceNo : secondmentReq.getDeviceNoList()) {
if (!secondmentDeviceNos.contains(deviceNo)) {
flag = false;
break;
}
}
}
// 设备有更新
if (!secondment.getDeviceType().equals(secondmentReq.getDeviceType()) || !flag) {
List<SysSecondmentImportDevice> list = new ArrayList<>();
for (String deviceNo : secondmentReq.getDeviceNoList()) {
SysDevice device = deviceService.selectByDeviceNo(deviceNo);
if (device == null) {
throw BusinessException.create(ResultCodeEnum.DEVICE_NOT_EXIST.getCode(), ResultCodeEnum.DEVICE_NOT_EXIST.getMsg());
}
if (!secondmentReq.getDeviceType().equals(device.getDeviceType())) {
throw BusinessException.create(ResultCodeEnum.DEVICE_TYPE_NOT_MATCH.getCode(), ResultCodeEnum.DEVICE_TYPE_NOT_MATCH.getMsg());
}
SysSecondmentImportDevice importDevice = new SysSecondmentImportDevice();
importDevice.setSecondmentNo(secondment.getSecondmentNo());
importDevice.setDeviceNo(deviceNo);
importDevice.setSecondedId(secondmentReq.getSecondmentUserId());
importDevice.setBeSecondedId(device.getUserId());
importDevice.setBatchImportTime(now);
importDevice.setCreateBy(currentUserId);
importDevice.setCreateTime(now);
list.add(importDevice);
}
secondmentImportDeviceMapper.deleteBySecondmentNo(secondment.getSecondmentNo());
secondmentImportDeviceMapper.insertBatchSelective(list);
}
secondment.setSecondedId(secondmentReq.getSecondmentUserId());
secondment.setDeviceType(secondmentReq.getDeviceType());
secondment.setSecondmentAmount(secondmentReq.getDeviceNoList().size());
secondment.setUpdateBy(currentUserId);
secondment.setUpdateTime(now);
secondment.setRemark(secondmentReq.getRemark());
secondmentMapper.updateByPrimaryKeySelective(secondment);
//新增借调单日志
String remark = "编辑借调单";
addSecondmentLog(secondment.getId(), null, remark);
return true;
}
private synchronized String getSecondmentNo() {
String orderSn = "";
String lockKey = "carservice:lock:secondment:no";
String value = UUID.randomUUID().toString();
try {
boolean result = redisCacheUtil.lock(lockKey, value, 30);
if (result) {
String orderNoPrefix = "9000";
String currentDateStr = DateUtil.formatDateYmd2(new Date());
String currentDateStr2 = DateUtil.formatDateYmd(new Date());
String beginDate = currentDateStr2 + " 00:00:00";
String endDate = currentDateStr2 + " 23:59:59";
int todayOrderCounts = countSecondment(beginDate, endDate);
int countNum = todayOrderCounts + 1;
/*
* 订单类型编号+年+月+日+当日订单数
*/
orderSn = orderNoPrefix + currentDateStr + countNum;
}
} catch (Exception e) {
logger.error("获取借调单号异常", e);
} finally {
redisCacheUtil.releaseLock(lockKey, value);
}
return orderSn;
}
private int countSecondment(String beginDate, String endDate) {
return secondmentMapper.countSecondment(beginDate, endDate);
}
private String buildFailFile(String fileName, List<SecondmentImportDeviceDataExportModelImport> errorList) {
try {
ByteArrayOutputStream outputStream = writeToExcel(errorList);
byte[] bytes = outputStream.toByteArray();
FileUploadServerData fileUploadServerData = FileUtils.uploadToFileSystem(fileName, bytes, "xlsx");
return fileUploadServerData.getSecureUrl();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
private ByteArrayOutputStream writeToExcel(List<SecondmentImportDeviceDataExportModelImport> errorList) throws IOException {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
// 创建新的SXSSFWorkbook
SXSSFWorkbook workbook = new SXSSFWorkbook();
// 创建一个工作表
Sheet sheet = workbook.createSheet("Sheet1");
// 创建行对象
Row row;
// 创建单元格
Cell cell;
CellStyle titleStyle = workbook.createCellStyle();
setCellStyle(titleStyle, IndexedColors.LIGHT_GREEN, true, false);
row = sheet.createRow(0);
cell = row.createCell(0);
cell.setCellValue("错误内容");
cell.setCellStyle(titleStyle);
cell = row.createCell(1);
cell.setCellValue("备注");
cell.setCellStyle(titleStyle);
int rowNum = 1;
CellStyle bodyStyle = workbook.createCellStyle();
setCellStyle(bodyStyle, IndexedColors.LIGHT_YELLOW, true, false);
for (SecondmentImportDeviceDataExportModelImport data : errorList) {
int i = 0;
row = sheet.createRow(rowNum++);
cell = row.createCell(i);
cell.setCellValue(data.getDeviceNo());
cell.setCellStyle(bodyStyle);
cell = row.createCell(i+1);
cell.setCellValue(data.getImportFailReason());
cell.setCellStyle(bodyStyle);
}
workbook.write(outputStream);
// 关闭工作簿资源
workbook.dispose();
return outputStream;
}
private void setCellStyle(CellStyle style, IndexedColors background, boolean center, boolean wrapText) {
style.setFillForegroundColor(background.getIndex());
style.setFillPattern((short) 1);
style.setBorderBottom((short) 1);
style.setBorderLeft((short) 1);
style.setBorderRight((short) 1);
style.setBorderTop((short) 1);
if (center) {
style.setAlignment((short) 2);
style.setVerticalAlignment((short) 1);
}
style.setWrapText(wrapText);
}
private Boolean returnMessageHandler(JSONObject jsonObject) {
if (!"0".equals(jsonObject.getString("returnCode"))) {
return false;
}
JSONObject data = jsonObject.getJSONObject("data");
return data != null;
}
}
package com.glsx.ordercenter.utils;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.support.ExcelTypeEnum;
import com.alibaba.excel.write.metadata.style.WriteCellStyle;
import com.alibaba.excel.write.metadata.style.WriteFont;
import com.alibaba.excel.write.style.HorizontalCellStyleStrategy;
import org.apache.commons.io.IOUtils;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import javax.servlet.http.HttpServletResponse;
import java.io.OutputStream;
import java.net.URLEncoder;
import java.util.List;
/**
* @title EasyExcelUtils
* @Author zhangzc
* @Description
* @Date 2024/4/10 19:57
**/
public class EasyExcelUtils {
/**
* 导出
*
* @param response
* @param data
* @param fileName
* @param sheetName
* @param clazz
* @throws Exception
*/
public static void writeExcel(HttpServletResponse response, List<? extends Object> data, String fileName, String sheetName, Class clazz) throws Exception {
//表头样式
WriteCellStyle headWriteCellStyle = new WriteCellStyle();
//设置表头居中对齐
headWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
WriteFont writeFont = new WriteFont();
writeFont.setFontHeightInPoints((short) 12);
headWriteCellStyle.setWriteFont(writeFont);
//内容样式
WriteCellStyle contentWriteCellStyle = new WriteCellStyle();
//设置内容靠左对齐
contentWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.LEFT);
HorizontalCellStyleStrategy horizontalCellStyleStrategy = new HorizontalCellStyleStrategy(headWriteCellStyle, contentWriteCellStyle);
EasyExcel.write(getOutputStream(fileName, response), clazz).excelType(ExcelTypeEnum.XLSX).sheet(sheetName).registerWriteHandler(horizontalCellStyleStrategy).doWrite(data);
response.getOutputStream().flush();
IOUtils.closeQuietly(response.getOutputStream());
}
/**
* 导出
*
* @param os
* @param data
* @param sheetName
* @param clazz
*/
public static void writeExcel(OutputStream os, List<? extends Object> data, String sheetName, Class clazz) {
//表头样式
WriteCellStyle headWriteCellStyle = new WriteCellStyle();
//设置表头居中对齐
headWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
WriteFont writeFont = new WriteFont();
writeFont.setFontHeightInPoints((short) 12);
headWriteCellStyle.setWriteFont(writeFont);
//内容样式
WriteCellStyle contentWriteCellStyle = new WriteCellStyle();
//设置内容靠左对齐
contentWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.LEFT);
HorizontalCellStyleStrategy horizontalCellStyleStrategy = new HorizontalCellStyleStrategy(headWriteCellStyle, contentWriteCellStyle);
EasyExcel.write(os).head(clazz).excelType(ExcelTypeEnum.XLSX).sheet(sheetName).registerWriteHandler(horizontalCellStyleStrategy).doWrite(data);
}
/**
* 导出
*
* @param response
* @param data
* @param fileName
* @param sheetName
* @param head
* @throws Exception
*/
public static void writeExcel(HttpServletResponse response, List<? extends Object> data, String fileName, String sheetName, List<List<String>> head) throws Exception {
//表头样式
WriteCellStyle headWriteCellStyle = new WriteCellStyle();
//设置表头居中对齐
headWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
WriteFont writeFont = new WriteFont();
writeFont.setFontHeightInPoints((short) 12);
headWriteCellStyle.setWriteFont(writeFont);
//内容样式
WriteCellStyle contentWriteCellStyle = new WriteCellStyle();
//设置内容靠左对齐
contentWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.LEFT);
HorizontalCellStyleStrategy horizontalCellStyleStrategy = new HorizontalCellStyleStrategy(headWriteCellStyle, contentWriteCellStyle);
EasyExcel.write(getOutputStream(fileName, response)).head(head).excelType(ExcelTypeEnum.XLSX).sheet(sheetName).registerWriteHandler(horizontalCellStyleStrategy).doWrite(data);
response.getOutputStream().flush();
IOUtils.closeQuietly(response.getOutputStream());
}
/**
* 导出
*
* @param os
* @param data
* @param sheetName
* @param head
*/
public static void writeExcel(OutputStream os, List<? extends Object> data, String sheetName, List<List<String>> head) {
//表头样式
WriteCellStyle headWriteCellStyle = new WriteCellStyle();
//设置表头居中对齐
headWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
WriteFont writeFont = new WriteFont();
writeFont.setFontHeightInPoints((short) 12);
headWriteCellStyle.setWriteFont(writeFont);
//内容样式
WriteCellStyle contentWriteCellStyle = new WriteCellStyle();
//设置内容靠左对齐
contentWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.LEFT);
HorizontalCellStyleStrategy horizontalCellStyleStrategy = new HorizontalCellStyleStrategy(headWriteCellStyle, contentWriteCellStyle);
EasyExcel.write(os).head(head).excelType(ExcelTypeEnum.XLSX).sheet(sheetName).registerWriteHandler(horizontalCellStyleStrategy).doWrite(data);
}
private static OutputStream getOutputStream(String fileName, HttpServletResponse response) throws Exception {
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8") + ExcelTypeEnum.XLSX.getValue());
response.setContentType("application/msexcel;charset=UTF-8");//设置类型
response.setHeader("Pragma", "No-cache");//设置头
response.setHeader("Cache-Control", "no-cache");//设置头
response.setDateHeader("Expires", 0);//设置日期头
return response.getOutputStream();
}
}
package com.glsx.ordercenter.utils;
import lombok.Data;
import java.io.Serializable;
/**
* @title FileUploadServerData
* @Author zhangzc
* @Description
* @Date 2024/4/10 19:45
**/
@Data
public class FileUploadServerData implements Serializable {
private static final long serialVersionUID = -5236956344360089868L;
private Integer status = 0;
private String message = "";
private String url = "";
private String systemSign;
private String filePath;
private String param1;
private String param2;
private String param3;
private String secureUrl;
}
package com.glsx.ordercenter.utils;
import org.apache.commons.codec.binary.Base64;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.List;
/**
* @title FileUtils
* @Author zhangzc
* @Description
* @Date 2024/4/10 17:24
**/
public class FileUtils {
public static final String FILE_UPLOAD_URL = "http://gfs.glsx.com.cn/file/upstring";
// blib 供应链
// biz 业务
private static final String dir_content = "biz";
public static InputStream getInputStreamFromUrl(String urlStr) {
InputStream inputStream = null;
try {
//url解码
URL url = new URL(java.net.URLDecoder.decode(urlStr, "UTF-8"));
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
//设置超时间为3秒
conn.setConnectTimeout(3 * 1000);
//防止屏蔽程序抓取而返回403错误
conn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
//得到输入流
inputStream = conn.getInputStream();
} catch (IOException e) {
e.getStackTrace();
}
return inputStream;
}
/**
* 将文件上传至文件服务器
* @param uploadData
* @param fileType
* @return
*/
public static FileUploadServerData uploadToFileSystem(String fileName, byte[] uploadData, String fileType) {
RestTemplate restTemplate = new RestTemplate();
MultiValueMap<String, String> form = new LinkedMultiValueMap<String, String>();
form.add("systemSign", dir_content);
form.add("param1", fileName);
form.add("files", fileType + "@" + Base64.encodeBase64String(uploadData));
// return restTemplate.postForObject(FILE_UPLOAD_URL, form, FileUploadServerData.class);
return restTemplate.postForObject(FILE_UPLOAD_URL, form, FileUploadServerData.class);
}
}
...@@ -398,8 +398,46 @@ ...@@ -398,8 +398,46 @@
UPDATE sys_device SET stock_time=now() where indent_no=#{indentNo} UPDATE sys_device SET stock_time=now() where indent_no=#{indentNo}
</update> </update>
<update id="updateUserByDeviceNo">
UPDATE sys_device
SET user_id = #{secondedId}
update_time = now(),
update_by = #{updateBy}, where user_id=#{beSecondedId} and device_no = #{deviceNo}
</update>
<update id="updateUserByDeviceNoList">
UPDATE sys_device
SET user_id = #{secondedId},
update_time = now(),
update_by = #{updateBy}
where user_id=#{beSecondedId} and device_status!=2
<if test="deviceNoList != null and deviceNoList.size() != 0">
and device_no in
<foreach collection="deviceNoList" item="item" open="(" separator="," close=")">
#{item,jdbcType=VARCHAR}
</foreach>
</if>
</update>
<select id="getByIndentNo" resultMap="BaseResultMap"> <select id="getByIndentNo" resultMap="BaseResultMap">
SELECT * from sys_device where indent_no=#{indentNo} SELECT * from sys_device where indent_no=#{indentNo}
</select> </select>
<select id="countDeviceByDeviceNo" resultType="java.lang.Integer">
select count(*)
from sys_device d
where d.device_status = 1 and d.device_no = #{deviceNo}
</select>
<select id="selectByDeviceNo" resultMap="BaseResultMap">
select *
from sys_device
where device_status = 1 and device_no = #{deviceNo}
order by id desc
limit 1
</select>
<select id="countByIndentNo" resultType="java.lang.Integer">
SELECT count(*) from sys_device where indent_no=#{indentNo}
</select>
</mapper> </mapper>
\ No newline at end of file \ No newline at end of file
...@@ -277,14 +277,15 @@ ...@@ -277,14 +277,15 @@
sdr.device_type deviceType, sdr.device_type deviceType,
su.name name, su.name name,
su.username username, su.username username,
su.user_type userType,
sdd.data_value deviceName sdd.data_value deviceName
FROM FROM
sys_device_repertory sdr sys_device_repertory sdr
LEFT JOIN sys_user su ON sdr.user_id = su.id LEFT JOIN sys_user su ON sdr.user_id = su.id
LEFT JOIN sys_dict_data sdd ON sdr.device_type = sdd.data_key LEFT JOIN sys_dict_data sdd ON sdr.device_type = sdd.data_key
WHERE su.user_type=1 WHERE su.user_type=1
<if test="username != null"> <if test="username != null and username != ''">
and su.username LIKE "%"#{username}"%" and su.username LIKE concat('%',#{username},'%')
</if> </if>
<if test="deviceType != null and deviceType != ''"> <if test="deviceType != null and deviceType != ''">
and sdr.device_type = #{deviceType} and sdr.device_type = #{deviceType}
...@@ -306,11 +307,15 @@ ...@@ -306,11 +307,15 @@
sdd.data_value deviceName, sdd.data_value deviceName,
sd.device_no deviceNo, sd.device_no deviceNo,
sd.stock_time stockTime, sd.stock_time stockTime,
sd.remark remark sd.remark remark,
su.id userId,
su.name userName,
su.username loginName
FROM FROM
sys_device sd sys_device sd
LEFT JOIN sys_dict_data sdd ON sd.device_type = sdd.data_key LEFT JOIN sys_dict_data sdd ON sd.device_type = sdd.data_key
LEFT JOIN sys_indent si ON sd.indent_no = si.indent_no LEFT JOIN sys_indent si ON sd.indent_no = si.indent_no
LEFT JOIN sys_user su ON su.id = sd.user_id
WHERE si.indent_status = 40 WHERE si.indent_status = 40
AND sd.device_status = 1 AND sd.device_status = 1
AND sd.user_id = #{userId} AND sd.user_id = #{userId}
...@@ -331,6 +336,7 @@ ...@@ -331,6 +336,7 @@
sdd.data_value deviceName, sdd.data_value deviceName,
sd.device_no deviceNo, sd.device_no deviceNo,
sd.stock_time stockTime, sd.stock_time stockTime,
sd.remark remark,
su.name name su.name name
FROM FROM
sys_device sd sys_device sd
...@@ -349,8 +355,8 @@ ...@@ -349,8 +355,8 @@
<if test="mechanicId != null"> <if test="mechanicId != null">
and sd.user_id = #{mechanicId} and sd.user_id = #{mechanicId}
</if> </if>
<if test="deviceNo != null"> <if test="deviceNo != null and deviceNo != ''">
and sd.device_no LIKE "%"#{deviceNo}"%" and sd.device_no LIKE concat('%',#{deviceNo},'%')
</if> </if>
<if test="deviceType != null and deviceType != ''"> <if test="deviceType != null and deviceType != ''">
and sd.device_type = #{deviceType} and sd.device_type = #{deviceType}
...@@ -420,4 +426,58 @@ ...@@ -420,4 +426,58 @@
</otherwise> </otherwise>
</choose> </choose>
</select> </select>
<select id="countServiceRepertoryDetail" parameterType="java.util.Map"
resultType="java.lang.Integer">
SELECT count(*)
FROM sys_device sd
LEFT JOIN sys_dict_data sdd ON sd.device_type = sdd.data_key
LEFT JOIN sys_indent si ON sd.indent_no = si.indent_no
WHERE si.indent_status = 40
AND sd.device_status = 1
AND sd.user_id = #{userId}
<if test="day != null">
AND TIMESTAMPDIFF(DAY, sd.stock_time, NOW()) > #{day}
</if>
<if test="deviceType != null and deviceType != '' ">
AND sd.device_type = #{deviceType}
</if>
</select>
<select id="countMechanicRepertoryDetail" parameterType="java.util.Map"
resultType="java.lang.Integer">
SELECT count(*)
FROM sys_device sd
LEFT JOIN sys_user su ON sd.user_id = su.id
LEFT JOIN sys_dict_data sdd ON sd.device_type = sdd.data_key
LEFT JOIN sys_indent si ON sd.indent_no = si.indent_no
WHERE ( (si.indent_status = 40 AND sd.device_source = 1) OR sd.device_source IN (2,3))
AND sd.device_status = 1
AND
sd.user_id IN (
select
ssm.mechanic_id
from sys_service_mechanic ssm
where ssm.service_id = #{serviceId}
)
<if test="day != null">
AND TIMESTAMPDIFF(DAY, sd.stock_time, NOW()) > #{day}
</if>
<if test="deviceType != null and deviceType != ''">
and sd.device_type = #{deviceType}
</if>
</select>
<select id="countMechanicRepertoryStock" parameterType="java.util.Map"
resultType="java.lang.Integer">
SELECT count(*)
FROM sys_device sd
where sd.device_status = 1 and sd.user_id = #{userId}
<if test="day != null">
AND TIMESTAMPDIFF(DAY, sd.stock_time, NOW()) > #{day}
</if>
<if test="deviceType != null and deviceType != ''">
and sd.device_type = #{deviceType}
</if>
</select>
</mapper> </mapper>
\ No newline at end of file \ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.glsx.ordercenter.mapper.SysIndentImportDeviceMapper">
<resultMap id="BaseResultMap" type="com.glsx.ordercenter.pojo.SysIndentImportDevice">
<!--
WARNING - @mbg.generated
-->
<id column="id" jdbcType="INTEGER" property="id" />
<result column="indent_no" jdbcType="VARCHAR" property="indentNo" />
<result column="device_no" jdbcType="VARCHAR" property="deviceNo" />
<result column="batch_import_time" jdbcType="TIMESTAMP" property="batchImportTime" />
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
<result column="create_by" jdbcType="INTEGER" property="createBy" />
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
<result column="update_by" jdbcType="INTEGER" property="updateBy" />
</resultMap>
<resultMap id="IndentImportDeviceMap" type="com.glsx.ordercenter.dto.IndentImportDeviceReq">
<result column="id" jdbcType="INTEGER" property="id" />
<result column="device_type" jdbcType="VARCHAR" property="deviceType" />
<result column="data_value" jdbcType="VARCHAR" property="deviceName" />
<result column="device_no" jdbcType="VARCHAR" property="deviceNo" />
<result column="batch_import_time" jdbcType="TIMESTAMP" property="importTime" />
</resultMap>
<sql id="Base_Column_List">
<!--
WARNING - @mbg.generated
-->
id, indent_no, device_no, batch_import_time, create_time, create_by, update_time,
update_by
</sql>
<insert id="insertBatchSelective" parameterType="java.util.List">
insert into sys_indent_import_device(indent_no , device_no ,batch_import_time ,create_time ,create_by)
values
<foreach collection="list" item="item" separator=",">
(#{item.indentNo}, #{item.deviceNo},#{item.batchImportTime},#{item.createTime},#{item.createBy})
</foreach>
</insert>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
delete from sys_indent_import_device
where id = #{id,jdbcType=INTEGER}
</delete>
<select id="selectImportDeviceList" resultMap="IndentImportDeviceMap">
select iid.id, iid.device_no, iid.batch_import_time,
si.device_type,
sdd.data_value
from sys_indent_import_device iid
left join sys_indent si on iid.indent_no = si.indent_no
left join sys_dict_data sdd on si.device_type = sdd.data_key
where si.id = #{indentId}
<if test="deviceNo != null and deviceNo != ''">
and iid.device_no like concat('%',#{deviceNo},'%')
</if>
</select>
<select id="countImportDeviceByDeviceNo" resultType="java.lang.Integer">
select count(*)
from sys_indent_import_device iid
left join sys_indent si on iid.indent_no = si.indent_no
where iid.device_no = #{deviceNo}
</select>
<select id="selectIndentNoById" resultType="java.lang.String">
select indent_no
from sys_indent_import_device
where id = #{id}
</select>
<select id="selectDeviceNoById" resultType="java.lang.String">
select device_no
from sys_indent_import_device
where id = #{id}
</select>
<select id="getDeviceNoListByIndentNo" resultType="java.lang.String">
select device_no
from sys_indent_import_device
where indent_no = #{indentNo}
</select>
<delete id="deleteByIndentNo" parameterType="java.lang.String">
delete from sys_indent_import_device
where indent_no = #{indentNo}
</delete>
</mapper>
\ No newline at end of file \ No newline at end of file
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
<resultMap id="BaseResultMap" type="com.glsx.ordercenter.pojo.SysIndentLogistics"> <resultMap id="BaseResultMap" type="com.glsx.ordercenter.pojo.SysIndentLogistics">
<id column="id" jdbcType="INTEGER" property="id" /> <id column="id" jdbcType="INTEGER" property="id" />
<result column="indent_id" jdbcType="INTEGER" property="indentId" /> <result column="indent_id" jdbcType="INTEGER" property="indentId" />
<result column="order_type" jdbcType="INTEGER" property="orderType" />
<result column="logistics_no" jdbcType="VARCHAR" property="logisticsNo" /> <result column="logistics_no" jdbcType="VARCHAR" property="logisticsNo" />
<result column="logistics_unicode" jdbcType="VARCHAR" property="logisticsUnicode" /> <result column="logistics_unicode" jdbcType="VARCHAR" property="logisticsUnicode" />
<result column="logistics_time" jdbcType="TIMESTAMP" property="logisticsTime" /> <result column="logistics_time" jdbcType="TIMESTAMP" property="logisticsTime" />
...@@ -128,6 +129,9 @@ ...@@ -128,6 +129,9 @@
<if test="indentId != null"> <if test="indentId != null">
indent_id, indent_id,
</if> </if>
<if test="orderType != null">
order_type,
</if>
<if test="logisticsNo != null"> <if test="logisticsNo != null">
logistics_no, logistics_no,
</if> </if>
...@@ -157,6 +161,9 @@ ...@@ -157,6 +161,9 @@
<if test="indentId != null"> <if test="indentId != null">
#{indentId,jdbcType=INTEGER}, #{indentId,jdbcType=INTEGER},
</if> </if>
<if test="orderType != null">
#{orderType,jdbcType=INTEGER},
</if>
<if test="logisticsNo != null"> <if test="logisticsNo != null">
#{logisticsNo,jdbcType=VARCHAR}, #{logisticsNo,jdbcType=VARCHAR},
</if> </if>
...@@ -307,6 +314,7 @@ ...@@ -307,6 +314,7 @@
FROM FROM
sys_indent_logistics sil sys_indent_logistics sil
LEFT JOIN sys_logistics sl ON sil.logistics_unicode = sl.unicode LEFT JOIN sys_logistics sl ON sil.logistics_unicode = sl.unicode
WHERE sil.indent_id=#{indentId} LIMIT 1 WHERE sil.indent_id=#{indentId} and sil.order_type=#{orderType}
LIMIT 1
</select> </select>
</mapper> </mapper>
\ No newline at end of file \ No newline at end of file
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
<result column="district_code" jdbcType="INTEGER" property="districtCode" /> <result column="district_code" jdbcType="INTEGER" property="districtCode" />
<result column="address" jdbcType="VARCHAR" property="address" /> <result column="address" jdbcType="VARCHAR" property="address" />
<result column="remark" jdbcType="VARCHAR" property="remark" /> <result column="remark" jdbcType="VARCHAR" property="remark" />
<result column="indent_type" jdbcType="INTEGER" property="indentType" />
<result column="create_by" jdbcType="INTEGER" property="createBy" /> <result column="create_by" jdbcType="INTEGER" property="createBy" />
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" /> <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
<result column="update_by" jdbcType="INTEGER" property="updateBy" /> <result column="update_by" jdbcType="INTEGER" property="updateBy" />
...@@ -23,6 +24,7 @@ ...@@ -23,6 +24,7 @@
<result column="deviceName" jdbcType="VARCHAR" property="deviceName" /> <result column="deviceName" jdbcType="VARCHAR" property="deviceName" />
<association property="user" javaType="com.glsx.ordercenter.pojo.user.SysUser"> <association property="user" javaType="com.glsx.ordercenter.pojo.user.SysUser">
<result column="name" jdbcType="VARCHAR" property="name" /> <result column="name" jdbcType="VARCHAR" property="name" />
<result column="user_type" jdbcType="INTEGER" property="userType" />
<result column="phone_number" jdbcType="VARCHAR" property="phoneNumber" /> <result column="phone_number" jdbcType="VARCHAR" property="phoneNumber" />
</association> </association>
</resultMap> </resultMap>
...@@ -99,6 +101,9 @@ ...@@ -99,6 +101,9 @@
<if test="remark != null"> <if test="remark != null">
remark, remark,
</if> </if>
<if test="indentType != null">
indent_type,
</if>
<if test="createBy != null"> <if test="createBy != null">
create_by, create_by,
</if> </if>
...@@ -149,6 +154,9 @@ ...@@ -149,6 +154,9 @@
<if test="remark != null"> <if test="remark != null">
#{remark,jdbcType=VARCHAR}, #{remark,jdbcType=VARCHAR},
</if> </if>
<if test="indentType != null">
#{indentType,jdbcType=INTEGER},
</if>
<if test="createBy != null"> <if test="createBy != null">
#{createBy,jdbcType=INTEGER}, #{createBy,jdbcType=INTEGER},
</if> </if>
...@@ -276,9 +284,9 @@ ...@@ -276,9 +284,9 @@
select select
si.id, si.indent_no, si.send_type, si.user_id, si.device_type, si.id, si.indent_no, si.send_type, si.user_id, si.device_type,
si.device_amount, si.indent_status, si.is_canceled, si.phone, si.device_amount, si.indent_status, si.is_canceled, si.phone,
si.receiver_name, si.district_code, si.address, si.remark, si.receiver_name, si.district_code, si.address, si.remark, si.indent_type,
si.create_by, si.create_time, si.update_by, si.update_time, si.create_by, si.create_time, si.update_by, si.update_time,
su.username, su.username,su.name,su.user_type,
sdd.data_value as deviceName sdd.data_value as deviceName
FROM FROM
sys_indent si sys_indent si
...@@ -298,8 +306,8 @@ ...@@ -298,8 +306,8 @@
<if test="endDate != null and endDate != ''"> <if test="endDate != null and endDate != ''">
and si.create_time &lt;= #{endDate} and si.create_time &lt;= #{endDate}
</if> </if>
<if test="username != null"> <if test="username != null and username != ''">
and su.username like #{username} and ((su.user_type=1 and su.username like #{username}) or (su.user_type=3 and su.name like #{username}))
</if> </if>
</where> </where>
ORDER BY si.create_time desc, si.id DESC ORDER BY si.create_time desc, si.id DESC
...@@ -328,6 +336,7 @@ ...@@ -328,6 +336,7 @@
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" /> <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
<result column="username" jdbcType="VARCHAR" property="username" /> <result column="username" jdbcType="VARCHAR" property="username" />
<result column="deviceName" jdbcType="VARCHAR" property="deviceName" /> <result column="deviceName" jdbcType="VARCHAR" property="deviceName" />
<result column="indent_type" jdbcType="INTEGER" property="indentType" />
<association property="sysIndentLogistics" javaType="com.glsx.ordercenter.pojo.SysIndentLogistics"> <association property="sysIndentLogistics" javaType="com.glsx.ordercenter.pojo.SysIndentLogistics">
<id property="id" column="logisticsId" /> <id property="id" column="logisticsId" />
<result property="indentId" column="indent_id"/> <result property="indentId" column="indent_id"/>
...@@ -337,14 +346,19 @@ ...@@ -337,14 +346,19 @@
<result property="remark" column="logisticsRemark"/> <result property="remark" column="logisticsRemark"/>
<result property="expressCompany" column="express_company"/> <result property="expressCompany" column="express_company"/>
</association> </association>
<association property="user" javaType="com.glsx.ordercenter.pojo.user.SysUser">
<result column="name" jdbcType="VARCHAR" property="name" />
<result column="user_type" jdbcType="INTEGER" property="userType" />
<result column="phone_number" jdbcType="VARCHAR" property="phoneNumber" />
</association>
</resultMap> </resultMap>
<select id="getDetail" parameterType="java.lang.Integer" resultMap="detailResultMap"> <select id="getDetail" parameterType="java.lang.Integer" resultMap="detailResultMap">
select select
si.id, si.indent_no, si.send_type, si.user_id, si.device_type, si.id, si.indent_no, si.send_type, si.user_id, si.device_type,
si.device_amount, si.indent_status, si.is_canceled, si.phone, si.device_amount, si.indent_status, si.is_canceled, si.phone,
si.receiver_name, si.district_code, si.address, si.remark, si.receiver_name, si.district_code, si.address, si.remark,
si.create_by, si.create_time, si.update_by, si.update_time, si.create_by, si.create_time, si.update_by, si.update_time,si.indent_type,
su.username, su.username,su.name,su.user_type,
sdd.data_value as deviceName, sdd.data_value as deviceName,
sil.id as logisticsId, sil.indent_id, sil.logistics_no, sil.logistics_time, sil.logistics_unicode, sil.remark as logisticsRemark, sil.id as logisticsId, sil.indent_id, sil.logistics_no, sil.logistics_time, sil.logistics_unicode, sil.remark as logisticsRemark,
sl.express_company, sl.express_company,
...@@ -379,7 +393,7 @@ ...@@ -379,7 +393,7 @@
si.id, si.indent_no, si.send_type, si.user_id, si.device_type, si.id, si.indent_no, si.send_type, si.user_id, si.device_type,
si.device_amount, si.indent_status, si.is_canceled, si.phone, si.device_amount, si.indent_status, si.is_canceled, si.phone,
si.receiver_name, si.district_code, si.address, si.remark, si.receiver_name, si.district_code, si.address, si.remark,
si.create_by, si.create_time, si.update_by, si.update_time, si.create_by, si.create_time, si.update_by, si.update_time,si.indent_type,
su.username, su.username,
sdd.data_value as deviceName sdd.data_value as deviceName
FROM FROM
...@@ -414,7 +428,7 @@ ...@@ -414,7 +428,7 @@
si.id, si.indent_no, si.send_type, si.user_id, si.device_type, si.id, si.indent_no, si.send_type, si.user_id, si.device_type,
si.device_amount, si.indent_status, si.is_canceled, si.phone, si.device_amount, si.indent_status, si.is_canceled, si.phone,
si.receiver_name, si.district_code, si.address, si.remark, si.receiver_name, si.district_code, si.address, si.remark,
si.create_by, si.create_time, si.update_by, si.update_time, si.create_by, si.create_time, si.update_by, si.update_time,si.indent_type,
su.username, su.username,
sdd.data_value as deviceName sdd.data_value as deviceName
FROM FROM
...@@ -479,4 +493,26 @@ ...@@ -479,4 +493,26 @@
ORDER BY si.create_time DESC, si.id DESC ORDER BY si.create_time DESC, si.id DESC
</select> </select>
<select id="selectUnReceivedIndentIds" resultType="java.lang.Integer">
select il.indent_id
from sys_indent_logistics il
left join sys_indent i on il.indent_id = i.id
where il.order_type = 1 and i.indent_type = 2 and i.indent_status = 30 and TIMESTAMPDIFF(DAY, il.logistics_time, NOW()) > 7
</select>
<update id="updateIndentStatusByIds">
update sys_indent
set indent_status = 40, update_time = now()
where id in
<foreach collection="ids" item="item" open="(" close=")" separator="," >
#{item}
</foreach>
</update>
<select id="selectByIndentNo" parameterType="java.lang.String" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from sys_indent
where indent_no = #{indentNo}
</select>
</mapper> </mapper>
\ No newline at end of file \ No newline at end of file
...@@ -1064,13 +1064,18 @@ ...@@ -1064,13 +1064,18 @@
update sys_order update sys_order
set set
active_status = #{activeStatus,jdbcType=TINYINT}, active_status = #{activeStatus,jdbcType=TINYINT},
<if test="shopId != null">
shop_id = #{shopId,jdbcType=INTEGER}, shop_id = #{shopId,jdbcType=INTEGER},
</if>
district = #{district,jdbcType=INTEGER}, district = #{district,jdbcType=INTEGER},
address = #{address,jdbcType=VARCHAR}, address = #{address,jdbcType=VARCHAR},
contact = #{contact,jdbcType=VARCHAR}, contact = #{contact,jdbcType=VARCHAR},
phone_number = #{phoneNumber,jdbcType=VARCHAR}, phone_number = #{phoneNumber,jdbcType=VARCHAR},
car_type = #{carType,jdbcType=VARCHAR}, car_type = #{carType,jdbcType=VARCHAR},
vin_no = #{vinNo,jdbcType=VARCHAR}, vin_no = #{vinNo,jdbcType=VARCHAR},
<if test="vinHash != null and vinHash != ''">
vin_hash = #{vinHash,jdbcType=VARCHAR},
</if>
car_color = #{carColor,jdbcType=VARCHAR}, car_color = #{carColor,jdbcType=VARCHAR},
expect_install_time = #{expectInstallTime,jdbcType=TIMESTAMP}, expect_install_time = #{expectInstallTime,jdbcType=TIMESTAMP},
<if test="serviceType != null and serviceType != ''"> <if test="serviceType != null and serviceType != ''">
...@@ -1078,8 +1083,12 @@ ...@@ -1078,8 +1083,12 @@
</if> </if>
car_owner = #{carOwner,jdbcType=VARCHAR}, car_owner = #{carOwner,jdbcType=VARCHAR},
car_owner_phone = #{carOwnerPhone,jdbcType=VARCHAR}, car_owner_phone = #{carOwnerPhone,jdbcType=VARCHAR},
<if test="merchantId != null">
merchant_id = #{merchantId,jdbcType=INTEGER}, merchant_id = #{merchantId,jdbcType=INTEGER},
</if>
<if test="mechanicId != null">
mechanic_id = #{mechanicId,jdbcType=INTEGER}, mechanic_id = #{mechanicId,jdbcType=INTEGER},
</if>
remark = #{remark,jdbcType=VARCHAR}, remark = #{remark,jdbcType=VARCHAR},
update_time = #{updateTime,jdbcType=TIMESTAMP}, update_time = #{updateTime,jdbcType=TIMESTAMP},
update_by = #{updateBy,jdbcType=INTEGER}, update_by = #{updateBy,jdbcType=INTEGER},
......
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.glsx.ordercenter.mapper.SysSecondmentImportDeviceMapper">
<resultMap id="BaseResultMap" type="com.glsx.ordercenter.pojo.SysSecondmentImportDevice">
<!--
WARNING - @mbg.generated
-->
<id column="id" jdbcType="INTEGER" property="id" />
<result column="secondment_no" jdbcType="VARCHAR" property="secondmentNo" />
<result column="device_no" jdbcType="VARCHAR" property="deviceNo" />
<result column="seconded_id" jdbcType="INTEGER" property="secondedId" />
<result column="be_seconded_id" jdbcType="INTEGER" property="beSecondedId" />
<result column="batch_import_time" jdbcType="TIMESTAMP" property="batchImportTime" />
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
<result column="create_by" jdbcType="INTEGER" property="createBy" />
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
<result column="update_by" jdbcType="INTEGER" property="updateBy" />
<result column="username" jdbcType="VARCHAR" property="username" />
<result column="name" jdbcType="VARCHAR" property="name" />
<result column="user_type" jdbcType="INTEGER" property="userType"/>
<result column="beUsername" jdbcType="VARCHAR" property="beUsername" />
<result column="beName" jdbcType="VARCHAR" property="beName" />
<result column="beUserType" jdbcType="INTEGER" property="beUserType"/>
<result column="deviceName" jdbcType="VARCHAR" property="deviceName" />
</resultMap>
<sql id="Base_Column_List">
<!--
WARNING - @mbg.generated
-->
id, secondment_no, device_no, seconded_id, be_seconded_id, batch_import_time, create_time,
create_by, update_time, update_by
</sql>
<select id="getDeviceBySecondmentNo" resultMap="BaseResultMap">
select
ssid.id, ssid.secondment_no, ssid.seconded_id, ssid.be_seconded_id,
ssid.device_no, ss.create_by, ss.create_time, ss.update_by, ss.update_time,
su1.username,su1.name,su1.user_type,
su2.username as beUsername,su2.name as beName,su2.user_type as beUserType,
sdd.data_value as deviceName
FROM
sys_secondment_import_device ssid
LEFT JOIN sys_secondment ss ON ssid.secondment_no = ss.secondment_no
LEFT JOIN sys_user su1 ON ssid.seconded_id = su1.id
LEFT JOIN sys_user su2 ON ssid.be_seconded_id = su2.id
LEFT JOIN sys_dict_data sdd ON ss.device_type = sdd.data_key
where ssid.secondment_no=#{secondmentNo}
<if test="deviceNo != null and deviceNo != ''">
and ssid.device_no=#{deviceNo}
</if>
</select>
<select id="getListBySecondmentNo" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
FROM
sys_secondment_import_device
where secondment_no=#{secondmentNo}
</select>
<select id="selectSecondmentNoById" resultType="java.lang.String">
select secondment_no
from sys_secondment_import_device
where id = #{id}
</select>
<select id="selectDeviceNoById" resultType="java.lang.String">
select device_no
from sys_secondment_import_device
where id = #{id}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
delete from sys_secondment_import_device
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insertBatchSelective" parameterType="java.util.List">
insert into sys_secondment_import_device(secondment_no , device_no ,seconded_id ,be_seconded_id, batch_import_time ,create_time ,create_by)
values
<foreach collection="list" item="item" separator=",">
(#{item.secondmentNo}, #{item.deviceNo}, #{item.secondedId}, #{item.beSecondedId},#{item.batchImportTime},#{item.createTime},#{item.createBy})
</foreach>
</insert>
<select id="countImportDeviceByDeviceNo" resultType="java.lang.Integer">
select count(*)
from sys_secondment_import_device sid
left join sys_secondment s on s.secondment_no = sid.secondment_no
where s.secondment_status != 40 and sid.device_no = #{deviceNo}
</select>
<delete id="deleteBySecondmentNo" parameterType="java.lang.String">
delete from sys_secondment_import_device
where secondment_no = #{secondmentNo}
</delete>
</mapper>
\ No newline at end of file \ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.glsx.ordercenter.mapper.SysSecondmentLogMapper">
<resultMap id="BaseResultMap" type="com.glsx.ordercenter.pojo.SysSecondmentLog">
<!--
WARNING - @mbg.generated
-->
<id column="id" jdbcType="INTEGER" property="id" />
<result column="secondment_id" jdbcType="INTEGER" property="secondmentId" />
<result column="secondment_status" jdbcType="INTEGER" property="secondmentStatus" />
<result column="remark" jdbcType="VARCHAR" property="remark" />
<result column="create_by" jdbcType="INTEGER" property="createBy" />
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
</resultMap>
<sql id="Base_Column_List">
<!--
WARNING - @mbg.generated
-->
id, secondment_id, secondment_status, remark, create_by, create_time
</sql>
<insert id="insertSelective" parameterType="com.glsx.ordercenter.pojo.SysSecondmentLog">
<selectKey keyProperty="id" order="AFTER" resultType="java.lang.Integer">
SELECT LAST_INSERT_ID()
</selectKey>
insert into sys_secondment_log
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="secondmentId != null">
secondment_id,
</if>
<if test="secondmentStatus != null">
secondment_status,
</if>
<if test="remark != null">
remark,
</if>
<if test="createBy != null">
create_by,
</if>
<if test="createTime != null">
create_time,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="secondmentId != null">
#{secondmentId,jdbcType=INTEGER},
</if>
<if test="secondmentStatus != null">
#{secondmentStatus,jdbcType=INTEGER},
</if>
<if test="remark != null">
#{remark,jdbcType=VARCHAR},
</if>
<if test="createBy != null">
#{createBy,jdbcType=INTEGER},
</if>
<if test="createTime != null">
#{createTime,jdbcType=TIMESTAMP},
</if>
</trim>
</insert>
<select id="get" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from sys_secondment_log
<where>
<if test="id != null">
and id = #{id}
</if>
<if test="secondmentId != null">
and secondment_id = #{secondmentId}
</if>
<if test="secondmentStatus != null">
and secondment_status = #{secondmentStatus}
</if>
</where>
</select>
<select id="selectSecondmentLogList" resultMap="BaseResultMap">
select
sl.id, sl.secondment_id, sl.secondment_status, sl.remark, sl.create_by, sl.create_time,
su.name operatorName
from sys_secondment_log sl
LEFT JOIN sys_user su ON sl.create_by = su.id
where sl.secondment_id = #{secondmentId}
order by sl.id desc
</select>
</mapper>
\ No newline at end of file \ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.glsx.ordercenter.mapper.SysSecondmentMapper">
<resultMap id="BaseResultMap" type="com.glsx.ordercenter.pojo.SysSecondment">
<!--
WARNING - @mbg.generated
-->
<id column="id" jdbcType="INTEGER" property="id" />
<result column="secondment_no" jdbcType="VARCHAR" property="secondmentNo" />
<result column="send_type" jdbcType="TINYINT" property="sendType" />
<result column="seconded_id" jdbcType="INTEGER" property="secondedId" />
<result column="device_type" jdbcType="VARCHAR" property="deviceType" />
<result column="secondment_amount" jdbcType="INTEGER" property="secondmentAmount" />
<result column="secondment_status" jdbcType="INTEGER" property="secondmentStatus" />
<result column="is_canceled" jdbcType="TINYINT" property="isCanceled" />
<result column="phone" jdbcType="VARCHAR" property="phone" />
<result column="receiver_name" jdbcType="VARCHAR" property="receiverName" />
<result column="district_code" jdbcType="INTEGER" property="districtCode" />
<result column="address" jdbcType="VARCHAR" property="address" />
<result column="remark" jdbcType="VARCHAR" property="remark" />
<result column="create_by" jdbcType="INTEGER" property="createBy" />
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
<result column="update_by" jdbcType="INTEGER" property="updateBy" />
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
</resultMap>
<resultMap id="DTOResultMap" type="com.glsx.ordercenter.dto.SecondmentDto" extends="BaseResultMap">
<result column="deviceName" jdbcType="VARCHAR" property="deviceName"/>
<result column="username" jdbcType="VARCHAR" property="username"/>
<result column="name" jdbcType="VARCHAR" property="name"/>
<result column="user_type" jdbcType="INTEGER" property="userType"/>
<association property="sysIndentLogistics" javaType="com.glsx.ordercenter.pojo.SysIndentLogistics">
<id property="id" column="logisticsId" />
<result property="indentId" column="indent_id"/>
<result property="logisticsNo" column="logistics_no"/>
<result property="logisticsTime" column="logistics_time"/>
<result property="logisticsUnicode" column="logistics_unicode"/>
<result property="remark" column="logisticsRemark"/>
<result property="expressCompany" column="express_company"/>
</association>
</resultMap>
<sql id="Base_Column_List">
<!--
WARNING - @mbg.generated
-->
id, secondment_no, send_type, seconded_id, device_type, secondment_amount, secondment_status,
is_canceled, phone, receiver_name, district_code, address, remark, create_by, create_time,
update_by, update_time
</sql>
<select id="selectUnReceivedSecondmentIds" resultType="java.lang.Integer">
select il.indent_id
from sys_indent_logistics il
left join sys_secondment s on il.indent_id = s.id
where il.order_type = 2 and s.secondment_status = 30 and TIMESTAMPDIFF(DAY, il.logistics_time, NOW()) > 7
</select>
<update id="updateSecondmentStatusByIds">
update sys_secondment
set secondment_status = 40, update_time = now()
where id in
<foreach collection="ids" item="item" open="(" close=")" separator="," >
#{item}
</foreach>
</update>
<update id="updateSecondmentStatusById">
update sys_secondment
set secondment_status = #{secondmentStatus}, update_time = now() ,update_by=#{userId}
where id = #{id}
</update>
<select id="getListByPage" resultMap="DTOResultMap">
<if test="username != null and username != ''">
<bind name="username" value="'%' + username + '%'"/>
</if>
<if test="beginDate != null and beginDate != ''">
<bind name="beginDate" value=" beginDate + ' 00:00'"/>
</if>
<if test="endDate != null and endDate != ''">
<bind name="endDate" value="endDate + ' 23:59'"/>
</if>
select
ss.id, ss.secondment_no, ss.send_type, ss.seconded_id, ss.device_type,
ss.secondment_amount, ss.secondment_status, ss.is_canceled, ss.phone,
ss.receiver_name, ss.district_code, ss.address, ss.remark,
ss.create_by, ss.create_time, ss.update_by, ss.update_time,
su.username,su.name,su.user_type,
sdd.data_value as deviceName
FROM
sys_secondment ss
LEFT JOIN sys_user su ON ss.seconded_id = su.id
LEFT JOIN sys_dict_data sdd ON ss.device_type = sdd.data_key
<where>
ss.send_type = 2
<if test="secondmentStatus != null">
and ss.secondment_status = #{secondmentStatus}
</if>
<if test="isCanceled != null">
and ss.is_canceled = #{isCanceled}
</if>
<if test="beginDate != null and beginDate != ''">
and ss.create_time &gt;= #{beginDate}
</if>
<if test="endDate != null and endDate != ''">
and ss.create_time &lt;= #{endDate}
</if>
<if test="username != null and username != ''">
and ((su.user_type=1 and su.username like #{username}) or (su.user_type=3 and su.name like #{username}))
</if>
</where>
ORDER BY ss.create_time desc, ss.id DESC
</select>
<select id="getDetail" resultMap="DTOResultMap">
select
ss.id, ss.secondment_no, ss.send_type, ss.seconded_id, ss.device_type,
ss.secondment_amount, ss.secondment_status, ss.is_canceled, ss.phone,
ss.receiver_name, ss.district_code, ss.address, ss.remark,
ss.create_by, ss.create_time, ss.update_by, ss.update_time,
su.username,su.name,su.user_type,
sdd.data_value as deviceName,
sil.id as logisticsId, sil.indent_id, sil.logistics_no, sil.logistics_time, sil.logistics_unicode, sil.remark as logisticsRemark,
sl.express_company
FROM
sys_secondment ss
LEFT JOIN sys_user su ON ss.seconded_id = su.id
LEFT JOIN sys_dict_data sdd ON ss.device_type = sdd.data_key
LEFT JOIN sys_indent_logistics sil ON ss.id = sil.indent_id
LEFT JOIN sys_logistics sl ON sil.logistics_unicode = sl.unicode
where ss.id = #{id}
</select>
<select id="getListByUserId" resultMap="DTOResultMap">
select
ss.id, ss.secondment_no, ss.send_type, ss.seconded_id, ss.device_type,
ss.secondment_amount, ss.secondment_status, ss.is_canceled, ss.phone,
ss.receiver_name, ss.district_code, ss.address, ss.remark,
ss.create_by, ss.create_time, ss.update_by, ss.update_time,
su.username,
sdd.data_value as deviceName
FROM
sys_secondment ss
LEFT JOIN sys_user su ON ss.seconded_id = su.id
LEFT JOIN sys_dict_data sdd ON ss.device_type = sdd.data_key
<where>
ss.send_type = 2
<if test="secondmentStatus != null">
and ss.secondment_status = #{secondmentStatus}
</if>
<if test="isCanceled != null">
and ss.is_canceled = #{isCanceled}
</if>
<if test="beginDate != null and beginDate != ''">
and date_format(ss.create_time, '%Y-%m') = #{beginDate}
</if>
<if test="userId != null">
and ss.seconded_id = #{userId}
</if>
<if test="secondmentNo != null and secondmentNo != ''">
and ss.secondment_no like concat('%',#{secondmentNo},'%')
</if>
</where>
ORDER BY ss.create_time desc, ss.id DESC
</select>
<select id="getBySecondmentNo" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from sys_secondment
where secondment_no = #{secondmentNo}
</select>
<select id="selectByPrimaryKey" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from sys_secondment
where id = #{id}
</select>
<select id="selectBySecondmentNo" parameterType="java.lang.String" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from sys_secondment
where secondment_no = #{secondmentNo}
</select>
<insert id="insertSelective" parameterType="com.glsx.ordercenter.pojo.SysSecondment">
<selectKey keyProperty="id" order="AFTER" resultType="java.lang.Integer">
SELECT LAST_INSERT_ID()
</selectKey>
insert into sys_secondment
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="secondmentNo != null">
secondment_no,
</if>
<if test="sendType != null">
send_type,
</if>
<if test="secondedId != null">
seconded_id,
</if>
<if test="deviceType != null">
device_type,
</if>
<if test="secondmentAmount != null">
secondment_amount,
</if>
<if test="secondmentStatus != null">
secondment_status,
</if>
<if test="isCanceled != null">
is_canceled,
</if>
<if test="phone != null">
phone,
</if>
<if test="receiverName != null">
receiver_name,
</if>
<if test="districtCode != null">
district_code,
</if>
<if test="address != null">
address,
</if>
<if test="remark != null">
remark,
</if>
<if test="createBy != null">
create_by,
</if>
<if test="createTime != null">
create_time,
</if>
<if test="updateBy != null">
update_by,
</if>
<if test="updateTime != null">
update_time,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="secondmentNo != null">
#{secondmentNo,jdbcType=VARCHAR},
</if>
<if test="sendType != null">
#{sendType,jdbcType=TINYINT},
</if>
<if test="secondedId != null">
#{secondedId,jdbcType=INTEGER},
</if>
<if test="deviceType != null">
#{deviceType,jdbcType=VARCHAR},
</if>
<if test="secondmentAmount != null">
#{secondmentAmount,jdbcType=INTEGER},
</if>
<if test="secondmentStatus != null">
#{secondmentStatus,jdbcType=INTEGER},
</if>
<if test="isCanceled != null">
#{isCanceled,jdbcType=TINYINT},
</if>
<if test="phone != null">
#{phone,jdbcType=VARCHAR},
</if>
<if test="receiverName != null">
#{receiverName,jdbcType=VARCHAR},
</if>
<if test="districtCode != null">
#{districtCode,jdbcType=INTEGER},
</if>
<if test="address != null">
#{address,jdbcType=VARCHAR},
</if>
<if test="remark != null">
#{remark,jdbcType=VARCHAR},
</if>
<if test="createBy != null">
#{createBy,jdbcType=INTEGER},
</if>
<if test="createTime != null">
#{createTime,jdbcType=TIMESTAMP},
</if>
<if test="updateBy != null">
#{updateBy,jdbcType=INTEGER},
</if>
<if test="updateTime != null">
#{updateTime,jdbcType=TIMESTAMP},
</if>
</trim>
</insert>
<select id="countSecondment" resultType="java.lang.Integer">
select count(*) from sys_secondment
<where>
<if test="beginDate != null and beginDate != ''">
and create_time &gt; #{beginDate}
</if>
<if test="endDate != null and endDate != ''">
and create_time &lt; #{endDate}
</if>
</where>
</select>
<insert id="updateByPrimaryKeySelective" parameterType="com.glsx.ordercenter.pojo.SysSecondment">
update sys_secondment
<set>
<if test="secondmentNo != null">
secondment_no = #{secondmentNo,jdbcType=VARCHAR},
</if>
<if test="sendType != null">
send_type = #{sendType,jdbcType=TINYINT},
</if>
<if test="secondedId != null">
seconded_id = #{secondedId,jdbcType=INTEGER},
</if>
<if test="deviceType != null">
device_type = #{deviceType,jdbcType=VARCHAR},
</if>
<if test="secondmentAmount != null">
secondment_amount = #{secondmentAmount,jdbcType=INTEGER},
</if>
<if test="secondmentStatus != null">
secondment_status = #{secondmentStatus,jdbcType=INTEGER},
</if>
<if test="isCanceled != null">
is_canceled = #{isCanceled,jdbcType=TINYINT},
</if>
<if test="phone != null">
phone = #{phone,jdbcType=VARCHAR},
</if>
<if test="receiverName != null">
receiver_name = #{receiverName,jdbcType=VARCHAR},
</if>
<if test="districtCode != null">
district_code = #{districtCode,jdbcType=INTEGER},
</if>
<if test="address != null">
address = #{address,jdbcType=VARCHAR},
</if>
<if test="remark != null">
remark = #{remark,jdbcType=VARCHAR},
</if>
<if test="createBy != null">
create_by = #{createBy,jdbcType=INTEGER},
</if>
<if test="createTime != null">
create_time = #{createTime,jdbcType=TIMESTAMP},
</if>
<if test="updateBy != null">
update_by = #{updateBy,jdbcType=INTEGER},
</if>
<if test="updateTime != null">
update_time = #{updateTime,jdbcType=TIMESTAMP},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</insert>
<select id="selectSecondmentNoById" resultType="java.lang.String">
select secondment_no
from sys_secondment
where id = #{id}
</select>
</mapper>
\ No newline at end of file \ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!