parent
ae4668ba97
commit
350564ad31
@ -0,0 +1,118 @@ |
||||
package com.bweb.controller; |
||||
|
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.github.pagehelper.PageHelper; |
||||
import com.github.pagehelper.PageInfo; |
||||
import com.hai.common.exception.ErrorCode; |
||||
import com.hai.common.exception.ErrorHelp; |
||||
import com.hai.common.exception.SysCode; |
||||
import com.hai.common.utils.ResponseMsgUtil; |
||||
import com.hai.model.ResponseData; |
||||
import com.hai.service.HighGasOilPriceTaskService; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.stereotype.Controller; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
import javax.annotation.Resource; |
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
@Controller |
||||
@RequestMapping(value = "/gasOilPriceTask") |
||||
@Api(value = "油品价格配置") |
||||
public class HighGasOilPriceTaskController { |
||||
|
||||
private static Logger log = LoggerFactory.getLogger(HighGasOilPriceTaskController.class); |
||||
|
||||
@Resource |
||||
private HighGasOilPriceTaskService gasOilPriceTaskService; |
||||
|
||||
@RequestMapping(value="/addTask",method = RequestMethod.POST) |
||||
@ResponseBody |
||||
@ApiOperation(value = "增加任务") |
||||
public ResponseData addTask(@RequestBody JSONObject body) { |
||||
try { |
||||
if (body.getLong("regionId") == null |
||||
|| body.getInteger("oilNo") == null |
||||
|| body.getBigDecimal("price") == null |
||||
) { |
||||
log.error("HighGasDiscountOilPriceController -> updateOilPriceOfficial() error!",""); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
|
||||
return ResponseMsgUtil.success("操作成功"); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("HighGasOilPriceTaskController -> addTask() error!",e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value="/delTask",method = RequestMethod.POST) |
||||
@ResponseBody |
||||
@ApiOperation(value = "删除任务") |
||||
public ResponseData delTask(@RequestBody JSONObject body) { |
||||
try { |
||||
if (body.getLong("taskId") == null) { |
||||
log.error("HighGasOilPriceTaskController -> delTask() error!",""); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
|
||||
gasOilPriceTaskService.delTask(body.getLong("taskId")); |
||||
|
||||
return ResponseMsgUtil.success("操作成功"); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("HighGasOilPriceTaskController -> delTask() error!",e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value="/getTaskDetail",method = RequestMethod.GET) |
||||
@ResponseBody |
||||
@ApiOperation(value = "查询任务详情") |
||||
public ResponseData getTaskDetail(@RequestParam(name = "taskId", required = true) Long taskId) { |
||||
try { |
||||
|
||||
return ResponseMsgUtil.success(gasOilPriceTaskService.getDetailById(taskId)); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("HighGasOilPriceTaskController -> getTaskDetail() error!",e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value="/getTaskList",method = RequestMethod.GET) |
||||
@ResponseBody |
||||
@ApiOperation(value = "查询任务列表") |
||||
public ResponseData getTaskList(@RequestParam(name = "regionId", required = false) Integer regionId, |
||||
@RequestParam(name = "regionName", required = false) String regionName, |
||||
@RequestParam(name = "merStoreId", required = false) Integer merStoreId, |
||||
@RequestParam(name = "merStoreName", required = false) String merStoreName, |
||||
@RequestParam(name = "oilType", required = false) Integer oilType, |
||||
@RequestParam(name = "oilNo", required = false) Integer oilNo, |
||||
@RequestParam(name = "priceType", required = false) Integer priceType, |
||||
@RequestParam(name = "executionType", required = false) Integer executionType, |
||||
@RequestParam(name = "status", required = false) Integer status, |
||||
@RequestParam(name = "pageNum", required = true) Integer pageNum, |
||||
@RequestParam(name = "pageSize", required = true) Integer pageSize) { |
||||
try { |
||||
Map<String, Object> param = new HashMap<>(); |
||||
param.put("regionId", regionId); |
||||
param.put("regionName", regionName); |
||||
param.put("status", status); |
||||
param.put("status", status); |
||||
|
||||
PageHelper.startPage(pageNum,pageSize); |
||||
return ResponseMsgUtil.success(new PageInfo<>(gasOilPriceTaskService.getTaskList(param))); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("HighGasOilPriceTaskController -> getTaskList() error!",e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,35 @@ |
||||
package com.hai.enum_type; |
||||
|
||||
/** |
||||
* 加油站价格任务 |
||||
* @author hurui |
||||
*/ |
||||
public enum GasTaskExecutionTypeEnum { |
||||
type1(1 , "立刻执行"), |
||||
type2(2 , "定时执行"), |
||||
; |
||||
|
||||
private Integer status; |
||||
private String name; |
||||
|
||||
GasTaskExecutionTypeEnum(int status , String name) { |
||||
this.status = status; |
||||
this.name = name; |
||||
} |
||||
|
||||
public Integer getStatus() { |
||||
return status; |
||||
} |
||||
|
||||
public void setStatus(Integer status) { |
||||
this.status = status; |
||||
} |
||||
|
||||
public String getName() { |
||||
return name; |
||||
} |
||||
|
||||
public void setName(String name) { |
||||
this.name = name; |
||||
} |
||||
} |
@ -0,0 +1,36 @@ |
||||
package com.hai.enum_type; |
||||
|
||||
/** |
||||
* 加油站价格任务 |
||||
* @author hurui |
||||
*/ |
||||
public enum GasTaskPriceTypeEnum { |
||||
type1(1 , "国标价"), |
||||
type2(2 , "油站价"), |
||||
type3(3 , "优惠幅度"), |
||||
; |
||||
|
||||
private Integer status; |
||||
private String name; |
||||
|
||||
GasTaskPriceTypeEnum(int status , String name) { |
||||
this.status = status; |
||||
this.name = name; |
||||
} |
||||
|
||||
public Integer getStatus() { |
||||
return status; |
||||
} |
||||
|
||||
public void setStatus(Integer status) { |
||||
this.status = status; |
||||
} |
||||
|
||||
public String getName() { |
||||
return name; |
||||
} |
||||
|
||||
public void setName(String name) { |
||||
this.name = name; |
||||
} |
||||
} |
@ -0,0 +1,36 @@ |
||||
package com.hai.enum_type; |
||||
|
||||
/** |
||||
* 加油站价格任务 |
||||
* @author hurui |
||||
*/ |
||||
public enum GasTaskStatusEnum { |
||||
status0(0 , "删除"), |
||||
status1(1 , "等待中"), |
||||
status2(2 , "已执行"), |
||||
; |
||||
|
||||
private Integer status; |
||||
private String name; |
||||
|
||||
GasTaskStatusEnum(int status , String name) { |
||||
this.status = status; |
||||
this.name = name; |
||||
} |
||||
|
||||
public Integer getStatus() { |
||||
return status; |
||||
} |
||||
|
||||
public void setStatus(Integer status) { |
||||
this.status = status; |
||||
} |
||||
|
||||
public String getName() { |
||||
return name; |
||||
} |
||||
|
||||
public void setName(String name) { |
||||
this.name = name; |
||||
} |
||||
} |
@ -0,0 +1,52 @@ |
||||
package com.hai.service; |
||||
|
||||
import com.hai.entity.HighGasOilPriceTask; |
||||
|
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* 加油站价格任务 |
||||
* @author hurui |
||||
*/ |
||||
public interface HighGasOilPriceTaskService { |
||||
|
||||
/** |
||||
* 编辑数据 |
||||
* @param gasOilPriceTask |
||||
*/ |
||||
void editData(HighGasOilPriceTask gasOilPriceTask); |
||||
|
||||
/** |
||||
* 增加价格任务 |
||||
* @param gasOilPriceTask |
||||
*/ |
||||
void addTask(HighGasOilPriceTask gasOilPriceTask); |
||||
|
||||
/** |
||||
* 业务处理 |
||||
* @param gasOilPriceTask |
||||
*/ |
||||
void businessHandle(HighGasOilPriceTask gasOilPriceTask); |
||||
|
||||
/** |
||||
* 根据id 查询详情 |
||||
* @param taskId |
||||
* @return |
||||
*/ |
||||
HighGasOilPriceTask getDetailById(Long taskId); |
||||
|
||||
/** |
||||
* 删除任务 |
||||
* @param taskId |
||||
*/ |
||||
void delTask(Long taskId); |
||||
|
||||
/** |
||||
* 查询任务列表 |
||||
* @param param |
||||
* @return |
||||
*/ |
||||
List<HighGasOilPriceTask> getTaskList(Map<String, Object> param); |
||||
|
||||
} |
@ -0,0 +1,171 @@ |
||||
package com.hai.service.impl; |
||||
|
||||
import com.hai.common.exception.ErrorCode; |
||||
import com.hai.common.exception.ErrorHelp; |
||||
import com.hai.common.exception.SysCode; |
||||
import com.hai.dao.HighGasOilPriceTaskMapper; |
||||
import com.hai.entity.HighGasOilPrice; |
||||
import com.hai.entity.HighGasOilPriceOfficial; |
||||
import com.hai.entity.HighGasOilPriceTask; |
||||
import com.hai.entity.HighGasOilPriceTaskExample; |
||||
import com.hai.enum_type.GasTaskExecutionTypeEnum; |
||||
import com.hai.enum_type.GasTaskPriceTypeEnum; |
||||
import com.hai.enum_type.GasTaskStatusEnum; |
||||
import com.hai.service.HighGasOilPriceOfficialService; |
||||
import com.hai.service.HighGasOilPriceService; |
||||
import com.hai.service.HighGasOilPriceTaskService; |
||||
import org.apache.commons.collections4.MapUtils; |
||||
import org.apache.commons.lang3.StringUtils; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import javax.annotation.Resource; |
||||
import java.util.Date; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
@Service("gasOilPriceTaskService") |
||||
public class HighGasOilPriceTaskServiceImpl implements HighGasOilPriceTaskService { |
||||
|
||||
@Resource |
||||
private HighGasOilPriceTaskMapper gasOilPriceTaskMapper; |
||||
|
||||
@Resource |
||||
private HighGasOilPriceService gasOilPriceService; |
||||
|
||||
@Resource |
||||
private HighGasOilPriceOfficialService gasOilPriceOfficialService; |
||||
|
||||
@Override |
||||
public void editData(HighGasOilPriceTask gasOilPriceTask) { |
||||
if (gasOilPriceTask.getId() == null) { |
||||
gasOilPriceTask.setStatus(GasTaskStatusEnum.status1.getStatus()); |
||||
gasOilPriceTask.setCreateTime(new Date()); |
||||
gasOilPriceTask.setUpdateTime(new Date()); |
||||
gasOilPriceTaskMapper.insert(gasOilPriceTask); |
||||
} else { |
||||
gasOilPriceTaskMapper.updateByPrimaryKey(gasOilPriceTask); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public void addTask(HighGasOilPriceTask gasOilPriceTask) { |
||||
editData(gasOilPriceTask); |
||||
|
||||
// 立刻执行
|
||||
if (gasOilPriceTask.getExecutionType().equals(GasTaskExecutionTypeEnum.type1.getStatus())) { |
||||
businessHandle(gasOilPriceTask); |
||||
} |
||||
|
||||
} |
||||
|
||||
@Override |
||||
public void businessHandle(HighGasOilPriceTask gasOilPriceTask) { |
||||
// 立刻执行
|
||||
if (gasOilPriceTask.getExecutionType().equals(GasTaskExecutionTypeEnum.type1.getStatus())) { |
||||
gasOilPriceTask.setStartTime(new Date()); |
||||
gasOilPriceTask.setStatus(GasTaskStatusEnum.status2.getStatus()); |
||||
editData(gasOilPriceTask); |
||||
|
||||
// 国标价
|
||||
if (gasOilPriceTask.getPriceType().equals(GasTaskPriceTypeEnum.type1.getStatus())) { |
||||
// 查询国标价油品价格
|
||||
HighGasOilPriceOfficial price = gasOilPriceOfficialService.getPrice(gasOilPriceTask.getRegionId(), gasOilPriceTask.getOilNo()); |
||||
if (price == null) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到油品价格"); |
||||
} |
||||
gasOilPriceOfficialService.editPrice(gasOilPriceTask.getRegionId(), gasOilPriceTask.getOilNo(), gasOilPriceTask.getPrice()); |
||||
|
||||
new Thread(() -> { |
||||
gasOilPriceOfficialService.refreshGasPriceOfficial(gasOilPriceTask.getRegionId(), gasOilPriceTask.getOilNo()); |
||||
}).start(); |
||||
} |
||||
|
||||
// 油站价
|
||||
if (gasOilPriceTask.getPriceType().equals(GasTaskPriceTypeEnum.type2.getStatus())) { |
||||
// 查询油品价格
|
||||
HighGasOilPrice price = gasOilPriceService.getGasOilPriceByStoreAndOilNo(gasOilPriceTask.getMerStoreId(), gasOilPriceTask.getOilNo()); |
||||
if (price == null) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到油品价格"); |
||||
} |
||||
price.setPriceGun(gasOilPriceTask.getPrice()); |
||||
price.setPriceVip(gasOilPriceTask.getPrice().subtract(price.getPreferentialMargin())); |
||||
gasOilPriceService.editGasOilPrice(price); |
||||
} |
||||
|
||||
// 优惠幅度
|
||||
if (gasOilPriceTask.getPriceType().equals(GasTaskPriceTypeEnum.type3.getStatus())) { |
||||
// 查询油品价格
|
||||
HighGasOilPrice price = gasOilPriceService.getGasOilPriceByStoreAndOilNo(gasOilPriceTask.getMerStoreId(), gasOilPriceTask.getOilNo()); |
||||
if (price == null) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到油品价格"); |
||||
} |
||||
price.setPreferentialMargin(gasOilPriceTask.getPrice()); |
||||
price.setPriceVip(price.getPriceGun().subtract(price.getPreferentialMargin())); |
||||
gasOilPriceService.editGasOilPrice(price); |
||||
} |
||||
|
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public HighGasOilPriceTask getDetailById(Long taskId) { |
||||
return gasOilPriceTaskMapper.selectByPrimaryKey(taskId); |
||||
} |
||||
|
||||
@Override |
||||
public void delTask(Long taskId) { |
||||
// 查询价格任务
|
||||
HighGasOilPriceTask detail = getDetailById(taskId); |
||||
if (detail == null) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_FOUND_ORDER, "未找到任务"); |
||||
} |
||||
detail.setStatus(GasTaskStatusEnum.status0.getStatus()); |
||||
editData(detail); |
||||
} |
||||
|
||||
@Override |
||||
public List<HighGasOilPriceTask> getTaskList(Map<String, Object> param) { |
||||
HighGasOilPriceTaskExample example = new HighGasOilPriceTaskExample(); |
||||
HighGasOilPriceTaskExample.Criteria criteria = example.createCriteria() |
||||
.andStatusNotEqualTo(GasTaskStatusEnum.status0.getStatus()); |
||||
|
||||
if (MapUtils.getLong(param, "regionId") != null) { |
||||
criteria.andRegionIdEqualTo(MapUtils.getLong(param, "regionId")); |
||||
} |
||||
|
||||
if (StringUtils.isNotBlank(MapUtils.getString(param, "regionName"))) { |
||||
criteria.andRegionNameLike("%" + MapUtils.getString(param, "regionName") + "%"); |
||||
} |
||||
|
||||
if (MapUtils.getLong(param, "merStoreId") != null) { |
||||
criteria.andMerStoreIdEqualTo(MapUtils.getLong(param, "merStoreId")); |
||||
} |
||||
|
||||
if (StringUtils.isNotBlank(MapUtils.getString(param, "merStoreName"))) { |
||||
criteria.andMerStoreNameLike("%" + MapUtils.getString(param, "merStoreName") + "%"); |
||||
} |
||||
|
||||
if (MapUtils.getInteger(param, "oilType") != null) { |
||||
criteria.andOilTypeEqualTo(MapUtils.getInteger(param, "oilType")); |
||||
} |
||||
|
||||
if (MapUtils.getInteger(param, "oilNo") != null) { |
||||
criteria.andOilNoEqualTo(MapUtils.getInteger(param, "oilNo")); |
||||
} |
||||
|
||||
if (MapUtils.getInteger(param, "priceType") != null) { |
||||
criteria.andPriceTypeEqualTo(MapUtils.getInteger(param, "priceType")); |
||||
} |
||||
|
||||
if (MapUtils.getInteger(param, "executionType") != null) { |
||||
criteria.andExecutionTypeEqualTo(MapUtils.getInteger(param, "executionType")); |
||||
} |
||||
|
||||
if (MapUtils.getInteger(param, "status") != null) { |
||||
criteria.andStatusEqualTo(MapUtils.getInteger(param, "status")); |
||||
} |
||||
|
||||
example.setOrderByClause("create_time desc"); |
||||
return gasOilPriceTaskMapper.selectByExample(example); |
||||
} |
||||
} |
Loading…
Reference in new issue