设置审核开关状态

This commit is contained in:
liuchengqian 2022-06-01 21:36:28 +08:00
parent ec709c426e
commit fd9b01bc77
5 changed files with 147 additions and 0 deletions

View File

@ -0,0 +1,46 @@
package com.xkrs.controller;
import com.xkrs.common.encapsulation.PromptMessageEnum;
import com.xkrs.dao.SettingDao;
import com.xkrs.model.entity.SettingEntity;
import com.xkrs.model.qo.SettingQo;
import org.apache.http.util.TextUtils;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;
import java.util.Locale;
import static com.xkrs.common.encapsulation.OutputEncapsulation.outputEncapsulationObject;
/**
* 设置审核开关状态
*/
@RestController
public class SettingController {
@Resource
private SettingDao settingDao;
@PostMapping("/updateswitchstate")
public String updateSwitchState(@RequestBody SettingQo settingQo) {
Locale locale = LocaleContextHolder.getLocale();
if (TextUtils.isEmpty(settingQo.getSwitchState())) {
return outputEncapsulationObject(PromptMessageEnum.PARAM_NULL, "switchState参数不能为空", locale);
}
List<SettingEntity> settingEntityList = settingDao.findAll();
if (settingEntityList.isEmpty()) {
SettingEntity settingEntity = new SettingEntity();
settingEntity.setSwitchState(settingQo.getSwitchState());
settingDao.save(settingEntity);
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "修改成功", locale);
}
SettingEntity settingEntity = settingEntityList.get(0);
settingDao.updateSwitchStateById(settingEntity.getId(), settingQo.getSwitchState());
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "修改成功", locale);
}
}

View File

@ -0,0 +1,20 @@
package com.xkrs.dao;
import com.xkrs.model.entity.SettingEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Component;
/**
* @author xkrs
*/
@Component
public interface SettingDao extends JpaRepository<SettingEntity, Long>, JpaSpecificationExecutor<SettingEntity> {
@Modifying(clearAutomatically = true)
@Query(value = "UPDATE setting SET switch_state = ?2 where id = ?1", nativeQuery = true)
void updateSwitchStateById(Long id, String switchState);
}

View File

@ -0,0 +1,50 @@
package com.xkrs.model.entity;
import javax.persistence.*;
import java.io.Serializable;
/**
* @author xkrs
*/
@Entity
@Table(name = "setting")
public class SettingEntity implements Serializable {
/**
* 主键id
*/
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "setting_seq_gen")
@SequenceGenerator(name = "setting_seq_gen", sequenceName = "setting_id_seq", allocationSize = 1)
private Long id;
/**
* 01
*/
@Column(length = 64, columnDefinition = "varchar(64)")
private String switchState;
public SettingEntity() {
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getSwitchState() {
return switchState;
}
public void setSwitchState(String switchState) {
this.switchState = switchState;
}
@Override
public String toString() {
return "SettingEntity{" + "id=" + id + ", switchState='" + switchState + '\'' + '}';
}
}

View File

@ -0,0 +1,27 @@
package com.xkrs.model.qo;
import com.xkrs.model.validation.SettingQoUpdate;
import javax.validation.constraints.NotNull;
public class SettingQo {
@NotNull(message = "{Setting.switchState.blank}", groups = {SettingQoUpdate.class})
private String switchState;
public SettingQo() {
}
public String getSwitchState() {
return switchState;
}
public void setSwitchState(String switchState) {
this.switchState = switchState;
}
@Override
public String toString() {
return "SettingQo{" + "switchState='" + switchState + '\'' + '}';
}
}

View File

@ -0,0 +1,4 @@
package com.xkrs.model.validation;
public interface SettingQoUpdate {
}