package cn.fastfun.controller.api; import cn.fastfun.controller.param.*; import cn.fastfun.service.AppDeviceLogService; import cn.fastfun.service.AppDeviceService; import cn.fastfun.service.entity.AppDevice; import cn.fastfun.service.entity.AppDeviceLog; import cn.fastfun.util.DateUtils; import cn.fastfun.util.ObjectUtil; import com.bridge.dto.*; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import lombok.extern.slf4j.Slf4j; import org.springframework.data.domain.Page; import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; import java.math.BigInteger; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; /** * @author Bridge AutoGen */ @Slf4j @Api(tags = {"2.1 设备操作信息"}) @RestController @RequestMapping("/api/v1/app/device/log") public class ApiAppDeviceLogController { //业务类 @Resource(name = "appDeviceService") AppDeviceService appDeviceService; @Resource AppDeviceLogService deviceLogService; @ApiOperation(value = "新增入库 单个 or 批次") @RequestMapping(value = "instorage", method = RequestMethod.POST) public ApiDTO inStorage(@RequestBody @ApiParam(name = "入库参数", value = "指定sn", required = true) LibraryInFormParam param) { deviceLogService.putInStorage(param); return ApiDTO.ok(); } @ApiOperation(value = "设备自检") @RequestMapping(value = "selfcheck", method = RequestMethod.POST) public ApiDTO selfCheck(@RequestBody @ApiParam(name = "入库参数", value = "指定sn", required = true) LibraryInFormParam param) { AppDevice device = appDeviceService.getOne(QueryParamExp.eq("sn", param.getSn())); device.setCheckStatus(1); appDeviceService.save(device); return ApiDTO.ok(); } @ApiOperation(value = "批次入库 搜索 & 重置") @RequestMapping(value = "instorage/batch/Query", method = RequestMethod.POST) public ApiPageDTO inStorageBatchQuery(@RequestBody DeviceBatchQueryParam param) { StringBuffer sql = new StringBuffer(); sql.append("select t1.batch_num,t1.operate_id,t1.operator,t1.sn,t1.check_status,t1.imei,t1.deliver_time,count(0) as total,count(if(status = 1,true,null)) as in_storage,count(if(status = 2,true,null)) as transfer,"); sql.append("count(if(status = 3,true,null)) as out_storage,count(if(status = 4,true,null)) as handle,"); sql.append("t1.add_time,t1.received_place from app_device t1"); if (!StringUtils.isEmpty(param.getBatchNum())) { sql.append(" where t1.batch_num like '%").append(param.getBatchNum()).append("%'"); } sql.append(" group by t1.operate_id"); if (!StringUtils.isEmpty(param.getOrderBy())) { sql.append(param.getOrderBy()); } log.info("SQL: {}", sql.toString()); ApiPageDTO page = appDeviceService.getListBySQL(sql.toString(), new HashMap<>(), param); if (null != page.getData()) { // 组装数据 List> list = (List>) page.getData(); for (Map p : list) { AppDevice device = new AppDevice(); device.setImei(ObjectUtil.obj2String(p.get("imei"))); appDeviceService.addImeiTitle(device); p.put("type_title", device.getTypeTitle()); p.put("pack_title", device.getPackTitle()); p.put("deliver_time", DateUtils.toString(ObjectUtil.obj2Date(p.get("deliver_time")), DateUtils.YMD)); p.put("add_time", DateUtils.toString(ObjectUtil.obj2Date(p.get("add_time")), DateUtils.YMDHMS)); } page.setData(list); } return page; } @ApiOperation(value = "批次入库 --> 入库 搜索 & 重置") @RequestMapping(value = "instorage/batch/inStorageQuery", method = RequestMethod.POST) public ApiPageDTO inStorageBatchInStorageQuery(@RequestBody DeviceBatchQueryParam param) { if (!StringUtils.isEmpty(param)) { param.addParam(QueryParamExp.eq("batchNum", param.getBatchNum())); } Page devicePage = appDeviceService.findByParam(param); devicePage.getContent().forEach(p -> { appDeviceService.addImeiTitle(p); }); return new ApiPageDTO(null, devicePage); } @ApiOperation(value = "设备入库 搜索 & 重置") @RequestMapping(value = "instorage/pageQuery", method = RequestMethod.POST) public ApiPageDTO inStoragePageQuery(@RequestBody LibraryInQueryParam param) { StringBuffer sql = new StringBuffer(); if (StringUtils.isEmpty(param.getCheckStatus())) { sql.append("SELECT * FROM app_device_log WHERE type=1"); } else { sql.append("SELECT * FROM app_device_log WHERE type=1 AND sn IN(SELECT sn FROM app_device WHERE check_status=" + param.getCheckStatus().toString() + ")"); } if (!StringUtils.isEmpty(param.getSn())) { sql.append(" AND sn like '%" + param.getSn() + "%'"); } log.info("SQL: {}", sql.toString()); ApiPageDTO page = appDeviceService.getListBySQL(sql.toString(), new HashMap<>(), param); if (null != page.getData()) { // 组装数据 List> list = (List>) page.getData(); List> listRes = new ArrayList<>(); for (Map p : list) { Map pTemp = new HashMap<>(); AppDevice device = appDeviceService.getOne(QueryParamExp.eq("sn", p.get("sn"))); appDeviceService.addImeiTitle(device); pTemp.put("sn", p.get("sn")); pTemp.put("add_time", DateUtils.toString(ObjectUtil.obj2Date(p.get("add_time")), DateUtils.YMDHMS)); pTemp.put("type_title", device.getTypeTitle()); pTemp.put("pack_title", device.getPackTitle()); pTemp.put("batch_num", device.getBatchNum()); pTemp.put("check_status", device.getCheckStatus()); pTemp.put("status", device.getStatus()); pTemp.put("received_place", device.getReceivedPlace()); pTemp.put("operate_time", DateUtils.toString(ObjectUtil.obj2Date(device.getUpdateTime()), DateUtils.YMD)); listRes.add(pTemp); } page.setData(listRes); } return page; } @ApiOperation(value = "根据sn或batch调拨 ") @RequestMapping(value = "transfer", method = RequestMethod.POST) public ApiDTO transfer(@RequestBody @ApiParam(name = "划拨参数", value = "传入json格式", required = true) TransferFormParam param) { if (CollectionUtils.isEmpty(param.getBatchNum()) && CollectionUtils.isEmpty(param.getSn())) return ApiDTO.error("未设定设备号或sn"); deviceLogService.transfer(param); return ApiDTO.ok(); } @ApiOperation(value = "调回平台 ") @RequestMapping(value = "transferBack", method = RequestMethod.POST) public ApiDTO transferBack(@RequestBody @ApiParam(name = "回调参数", value = "输入sn", required = true) TransferFormParam param) { deviceLogService.transferBack(param); return ApiDTO.ok(); } @ApiOperation(value = "设备调拨 查看详情") @RequestMapping(value = "transfer/detialQuery", method = RequestMethod.POST) public ApiPageDTO transferDetialQuery(@RequestBody detialQueryParam param) { param.addParam(QueryParamExp.eq("operateID", param.getOperateID())); param.addParam(QueryParamExp.eq("type", 2)); Page deviceLogPage = deviceLogService.findByParam(param); deviceLogPage.getContent().forEach(p -> { AppDevice device = appDeviceService.getOne(QueryParamExp.eq("sn", p.getSn())); appDeviceService.addImeiTitle(device); p.appendFormDevice(device); p.appendInTime(device); }); return new ApiPageDTO(null, deviceLogPage); } @ApiOperation(value = "设备调拨 搜索 & 重置") @RequestMapping(value = "transfer/pageQuery", method = RequestMethod.POST) public ApiPageDTO transferPageQuery(@RequestBody LogTransferQueryParam param) { StringBuffer sql = new StringBuffer("select t.batch_num,t.operate_id, t.add_time,count(0) as total,t.tf_event,t.tf_device_type,t.tf_used,t.tf_describe,t.out_custom_id,t.operator,t.remarks from app_device_log t where t.type = 2 "); // sn搜索 if (!StringUtils.isEmpty(param.getSn())) { sql.append(" and t.sn like '%").append(param.getSn()).append("%'"); } // 类型搜索 if (!StringUtils.isEmpty(param.getType())) { sql.append(" and t.tf_device_type = ").append(param.getType()); } sql.append(" group by t.operate_id"); if (!StringUtils.isEmpty(param.getOrderBy())) { sql.append(param.getOrderBy()); } log.info("SQL: {}", sql.toString()); ApiPageDTO page = appDeviceService.getListBySQL(sql.toString(), new HashMap<>(), param); // 组装数据 if (null != page.getData()) { List> list = (List>) page.getData(); for (Map p : list) { p.put("add_time", DateUtils.toString(ObjectUtil.obj2Date(p.get("add_time")), DateUtils.YMDHMS)); p.put("customTitle", "骑享科技"); } page.setData(list); } return page; } @ApiOperation(value = "新增调拨 --> 选择设备 查询 & 重置") @RequestMapping(value = "transfer/bySn/pageQuery", method = RequestMethod.POST) public ApiPageDTO transferBySnPageQuery(@RequestBody TransferBySnQueryParam param) { param.addParam(QueryParamExp.eq("status", 1)); Page devicePage = appDeviceService.findByParam(param); devicePage.getContent().forEach(p -> { QueryParam finalQuery = new QueryParam(); finalQuery.addParam(QueryParamExp.desc("addTime")); finalQuery.addParam(QueryParamExp.eq("sn", p.getSn())); finalQuery.addParam(QueryParamExp.eq("type", 2)); Page deviceLogPage = deviceLogService.findByParam(finalQuery); AppDeviceLog lastDeviceLogPage = new AppDeviceLog(); if (!deviceLogPage.isEmpty()) { lastDeviceLogPage = deviceLogPage.getContent().get(0); } appDeviceService.addImeiTitle(p); p.appendInfo(lastDeviceLogPage); }); return new ApiPageDTO(null, devicePage); } @ApiOperation(value = "新增调拨 --> 选择批次 查询 & 重置") @RequestMapping(value = "transfer/byBatch/pageQuery", method = RequestMethod.POST) public ApiPageDTO transferByBatchPageQuery(@RequestBody DeviceBatchQueryParam param) { StringBuffer sql = new StringBuffer(); sql.append("select t1.batch_num,t1.operator,t1.operate_id,t1.sn,t1.imei,t1.deliver_time,count(0) as total,count(if(status = 1,true,null)) as in_storage,count(if(status = 2,true,null)) as transfer,"); sql.append("count(if(status = 3,true,null)) as out_storage,count(if(status = 4,true,null)) as handle,"); sql.append("t1.add_time,t1.received_place from app_device t1"); if (!StringUtils.isEmpty(param.getBatchNum())) { sql.append(" where t1.batch_num like '%").append(param.getBatchNum()).append("%'"); } sql.append(" group by t1.operate_id"); if (!StringUtils.isEmpty(param.getOrderBy())) { sql.append(param.getOrderBy()); } log.info("SQL: {}", sql.toString()); ApiPageDTO page = appDeviceService.getListBySQL(sql.toString(), new HashMap<>(), param); if (null != page.getData()) { // 组装数据 List> list = (List>) page.getData(); for (Map p : list) { AppDevice device = appDeviceService.getOne(QueryParamExp.eq("sn",p.get("sn"))); device.setImei(ObjectUtil.obj2String(p.get("imei"))); appDeviceService.addImeiTitle(device); p.put("type_title", device.getTypeTitle()); p.put("pack_title", device.getPackTitle()); p.put("deliver_time", DateUtils.toString(ObjectUtil.obj2Date(p.get("deliver_time")), DateUtils.YMD)); p.put("add_time", DateUtils.toString(ObjectUtil.obj2Date(p.get("add_time")), DateUtils.YMDHMS)); p.put("instorageTime", device.getInstorageTime()); } page.setData(list); } return page; } @ApiOperation(value = "新增调拨 --> 选择批次 查看") @RequestMapping(value = "transfer/batch/detailQuery", method = RequestMethod.POST) public ApiPageDTO transferByBatchDetailQuery(@RequestBody DeviceBatchQueryParam param) { if (!StringUtils.isEmpty(param)) { param.addParam(QueryParamExp.like("batchNum", "%".concat(param.getBatchNum()).concat("%"))); } Page devicePage = appDeviceService.findByParam(param); devicePage.getContent().forEach(p -> { appDeviceService.addImeiTitle(p); }); return new ApiPageDTO(null, devicePage); } @ApiOperation(value = "调回平台 搜索 & 重置") @RequestMapping(value = "transferBack/pageQuery", method = RequestMethod.POST) public ApiPageDTO transferBackPageQuery(@RequestBody TransferBySnQueryParam param) { param.addParam(QueryParamExp.eq("status", 3)); Page devicePage = appDeviceService.findByParam(param); return new ApiPageDTO(null, devicePage); } @ApiOperation(value = "根据sn或batch出库") @RequestMapping(value = "outstorage", method = RequestMethod.POST) public ApiDTO outStorage(@RequestBody @ApiParam(name = "出库参数", value = "传入json格式", required = true) LibraryOutFormParam param) { deviceLogService.outStorage(param); return ApiDTO.ok(); } @ApiOperation(value = "设备出库 查看详情") @RequestMapping(value = "outstorage/detialQuery", method = RequestMethod.POST) public ApiPageDTO outDetialQuery(@RequestBody detialQueryParam param) { param.addParam(QueryParamExp.eq("operateID", param.getOperateID())); param.addParam(QueryParamExp.eq("type", 3)); Page deviceLogPage = deviceLogService.findByParam(param); deviceLogPage.getContent().forEach(p -> { AppDevice device = new AppDevice(); device.setImei(p.getImei()); appDeviceService.addImeiTitle(device); device.setImei(p.getImei()); appDeviceService.addImeiTitle(device); p.appendFormDevice(device); p.appendInTime(device); }); return new ApiPageDTO(null, deviceLogPage); } @ApiOperation(value = "设备出库 搜索 & 重置") @RequestMapping(value = "outstorage/pageQuery", method = RequestMethod.POST) public ApiPageDTO outPageQuery(@RequestBody OutQueryParam param) { StringBuffer sql = new StringBuffer("select t.batch_num,t.operate_id,t.add_time,count(0) as total,t.out_type,t.receiver_name,t.receiver_phone,t.remarks,t.out_custom_id,t.operator,t.update_time from app_device_log t where t.type = 3"); // sn搜索 if (!StringUtils.isEmpty(param.getSn())) { sql.append(" and t.sn like '%").append(param.getSn()).append("%'"); } // 类型搜索 if (!StringUtils.isEmpty(param.getOutType())) { sql.append(" and t.out_type = ").append(param.getOutType()); } sql.append(" group by t.operate_id"); if (!StringUtils.isEmpty(param.getOrderBy())) { sql.append(param.getOrderBy()); } log.info("SQL: {}", sql.toString()); ApiPageDTO page = appDeviceService.getListBySQL(sql.toString(), new HashMap<>(), param); if (null != page.getData()) { // 组装数据 List> list = (List>) page.getData(); for (Map p : list) { p.put("add_time", DateUtils.toString(ObjectUtil.obj2Date(p.get("add_time")), DateUtils.YMDHMS)); p.put("update_time", DateUtils.toString(ObjectUtil.obj2Date(p.get("update_time")), DateUtils.YMDHMS)); p.put("out_type", String.valueOf(p.get("out_type"))); } page.setData(list); } return page; } @ApiOperation(value = "批次出库 --> 查看") @RequestMapping(value = "outstorage/batch/detailQuery", method = RequestMethod.POST) public ApiPageDTO outByBatchDetailQuery(@RequestBody detialQueryParam param) { param.addParam(QueryParamExp.eq("operateID", param.getOperateID())); Page devicePage = appDeviceService.findByParam(param); devicePage.getContent().forEach(p -> { appDeviceService.addImeiTitle(p); }); return new ApiPageDTO(null, devicePage); } @ApiOperation(value = "批次出库 搜索 & 重置") @RequestMapping(value = "outstorage/byBatch/pageQuery", method = RequestMethod.POST) public ApiPageDTO outByBatchPageQuery(@RequestBody DeviceBatchQueryParam param) { StringBuffer sql = new StringBuffer(); sql.append("select t1.batch_num,t1.operate_id,t1.operator,t1.sn,t1.imei,t1.deliver_time,count(0) as total,count(if(status = 1,true,null)) as in_storage,count(if(status = 2,true,null)) as transfer,"); sql.append("count(if(status = 3,true,null)) as out_storage,count(if(status = 4,true,null)) as handle,"); sql.append("t1.add_time,t1.received_place from app_device t1 where t1.status = 2"); if (!StringUtils.isEmpty(param.getBatchNum())) { sql.append(" and t1.batch_num like '%").append(param.getBatchNum()).append("%'"); } sql.append(" group by t1.operate_id"); if (!StringUtils.isEmpty(param.getOrderBy())) { sql.append(param.getOrderBy()); } log.info("SQL: {}", sql.toString()); ApiPageDTO page = appDeviceService.getListBySQL(sql.toString(), new HashMap<>(), param); if (null != page.getData()) { // 组装数据 List> list = (List>) page.getData(); for (Map p : list) { AppDevice device = appDeviceService.getOne(QueryParamExp.eq("sn",p.get("sn"))); device.setImei(ObjectUtil.obj2String(p.get("imei"))); appDeviceService.addImeiTitle(device); p.put("type_title", device.getTypeTitle()); p.put("pack_title", device.getPackTitle()); p.put("deliver_time", DateUtils.toString(ObjectUtil.obj2Date(p.get("deliver_time")), DateUtils.YMD)); p.put("add_time", DateUtils.toString(ObjectUtil.obj2Date(p.get("add_time")), DateUtils.YMDHMS)); p.put("instorageTime", DateUtils.toString(ObjectUtil.obj2Date(device.getInstorageTime()), DateUtils.YMDHMS)); } page.setData(list); } return page; } @ApiOperation(value = "新增处置") @RequestMapping(value = "handle", method = RequestMethod.POST) public ApiDTO handle(@RequestBody @ApiParam(name = "出库参数", value = "传入json格式", required = true) HandelFormParam param) { deviceLogService.handle(param); return ApiDTO.ok(); } @ApiOperation(value = "处置 搜索 & 重置") @RequestMapping(value = "handle/pageQuery", method = RequestMethod.POST) public ApiPageDTO deviceLogPageQuery(@RequestBody HandelQueryParam param) { param.addParam(QueryParamExp.eq("type", 4)); Page devicePage = deviceLogService.findByParam(param); devicePage.getContent().forEach(p -> { AppDevice device = appDeviceService.getOne(QueryParamExp.eq("sn", p.getSn())); p.appendInTime(device); }); return new ApiPageDTO(null,devicePage); } }