123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445 |
- 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<Map<String, Object>> list = (List<Map<String, Object>>) page.getData();
- for (Map<String, Object> 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<AppDevice> 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<Map<String, Object>> list = (List<Map<String, Object>>) page.getData();
- List<Map<String, Object>> listRes = new ArrayList<>();
- for (Map<String, Object> p : list) {
- Map<String, Object> 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<AppDeviceLog> 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<Map<String, Object>> list = (List<Map<String, Object>>) page.getData();
- for (Map<String, Object> 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<AppDevice> 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<AppDeviceLog> 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<Map<String, Object>> list = (List<Map<String, Object>>) page.getData();
- for (Map<String, Object> 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<AppDevice> 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<AppDevice> 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<AppDeviceLog> 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<Map<String, Object>> list = (List<Map<String, Object>>) page.getData();
- for (Map<String, Object> 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<AppDevice> 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<Map<String, Object>> list = (List<Map<String, Object>>) page.getData();
- for (Map<String, Object> 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<AppDeviceLog> 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);
- }
- }
|