package com.taauav.admin.controller; | |||||
import com.taauav.admin.entity.TauvWaterStandard; | |||||
import com.taauav.admin.query.TauvWaterStandardQuery; | |||||
import com.taauav.admin.service.ITauvWaterStandardService; | |||||
import com.taauav.common.bean.Response; | |||||
import com.taauav.common.constant.PermissionConstants; | |||||
import org.apache.shiro.authz.annotation.RequiresPermissions; | |||||
import org.springframework.beans.factory.annotation.Autowired; | |||||
import org.springframework.validation.BindingResult; | |||||
import org.springframework.web.bind.annotation.*; | |||||
import javax.validation.Valid; | |||||
/** | |||||
* 地表水环境质量标准控制器 | |||||
* | |||||
* @author daixiantong | |||||
* @since 2020-05-13 | |||||
*/ | |||||
@RestController | |||||
@RequestMapping("/admin/waterStandard") | |||||
public class TauvWaterStandardController { | |||||
@Autowired | |||||
private ITauvWaterStandardService waterStandardService; | |||||
@Autowired | |||||
private Response response; | |||||
private static final String controllerName = "/admin/waterStandard"; | |||||
/** | |||||
* 标准列表 | |||||
* | |||||
* @return | |||||
*/ | |||||
@GetMapping("/index") | |||||
@RequiresPermissions(controllerName + ":" + PermissionConstants.LIST_PERMISSION) | |||||
public Response index(TauvWaterStandardQuery waterStandardQuery) { | |||||
return waterStandardService.getPageList(waterStandardQuery); | |||||
} | |||||
/** | |||||
* 添加标准 | |||||
* @param waterStandard | |||||
* @param bindingResult | |||||
* @return | |||||
*/ | |||||
@PostMapping("/add") | |||||
@RequiresPermissions(controllerName + ":" + PermissionConstants.ADD_PERMISSION) | |||||
public Response add(@Valid @RequestBody TauvWaterStandard waterStandard, BindingResult bindingResult) { | |||||
if (bindingResult.hasErrors()) { | |||||
String msg = bindingResult.getFieldError().getDefaultMessage(); | |||||
return response.failure(msg); | |||||
} | |||||
return waterStandardService.editStandard(waterStandard); | |||||
} | |||||
/** | |||||
* 编辑标准 | |||||
* @param waterStandard | |||||
* @param bindingResult | |||||
* @return | |||||
*/ | |||||
@PostMapping("/edit") | |||||
@RequiresPermissions(controllerName + ":" + PermissionConstants.EDIT_PERMISSION) | |||||
public Response edit(@Valid @RequestBody TauvWaterStandard waterStandard, BindingResult bindingResult) { | |||||
if (bindingResult.hasErrors()) { | |||||
String msg = bindingResult.getFieldError().getDefaultMessage(); | |||||
return response.failure(msg); | |||||
} | |||||
return waterStandardService.editStandard(waterStandard); | |||||
} | |||||
/** | |||||
* 删除 | |||||
* @param waterStandard | |||||
* @return | |||||
*/ | |||||
@PostMapping("/drop") | |||||
@RequiresPermissions(controllerName + ":" + PermissionConstants.REMOVE_PERMISSION) | |||||
public Response drop(TauvWaterStandard waterStandard) { | |||||
return waterStandardService.dropStandard(waterStandard); | |||||
} | |||||
} |
package com.taauav.admin.entity; | |||||
import com.baomidou.mybatisplus.annotation.TableName; | |||||
import com.taauav.common.domain.Entity; | |||||
import io.swagger.annotations.ApiModelProperty; | |||||
import lombok.Data; | |||||
import lombok.EqualsAndHashCode; | |||||
import lombok.experimental.Accessors; | |||||
import javax.validation.constraints.NotEmpty; | |||||
import javax.validation.constraints.NotNull; | |||||
import javax.validation.constraints.Size; | |||||
/** | |||||
* 地表水环境质量标准 实体类 | |||||
* | |||||
* @author daixiantong | |||||
* @date 2020-05-13 | |||||
*/ | |||||
@Data | |||||
@EqualsAndHashCode(callSuper = false) | |||||
@Accessors(chain = true) | |||||
@TableName("tauv_water_standard") | |||||
public class TauvWaterStandard extends Entity { | |||||
@ApiModelProperty(value = "参数名称") | |||||
@NotEmpty(message = "参数名称不能为空") | |||||
@Size(min = 1, max = 20, message = "参数名称长度为1-20个字符") | |||||
private String name; | |||||
@ApiModelProperty(value = "英文名称") | |||||
@NotEmpty(message = "英文名称不能为空") | |||||
@Size(min = 1, max = 20, message = "英文名称长度为1-20个字符") | |||||
private String code; | |||||
@ApiModelProperty(value = "对比方式") | |||||
@NotEmpty(message = "比对方式不能为空") | |||||
private String method; | |||||
@ApiModelProperty(value = "Ⅰ类") | |||||
private Integer categoryOne; | |||||
@ApiModelProperty(value = "Ⅱ类") | |||||
private Integer categoryTwo; | |||||
@ApiModelProperty(value = "Ⅲ类") | |||||
private Integer categoryThree; | |||||
@ApiModelProperty(value = "Ⅳ类") | |||||
private Integer categoryFour; | |||||
@ApiModelProperty(value = "Ⅴ类") | |||||
private Integer categoryFive; | |||||
} |
package com.taauav.admin.mapper; | |||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; | |||||
import com.taauav.admin.entity.TauvWaterStandard; | |||||
public interface TauvWaterStandardMapper extends BaseMapper<TauvWaterStandard> { | |||||
} |
package com.taauav.admin.query; | |||||
import com.taauav.common.core.mps.BaseQuery; | |||||
/** | |||||
* 地表水环境质量标准 | |||||
* @author daixiantong | |||||
* @date 2020-05-13 | |||||
*/ | |||||
public class TauvWaterStandardQuery extends BaseQuery { | |||||
} |
package com.taauav.admin.service; | |||||
import com.taauav.admin.entity.TauvWaterStandard; | |||||
import com.taauav.admin.query.TauvWaterStandardQuery; | |||||
import com.taauav.common.bean.Response; | |||||
import com.taauav.common.service.IBaseService; | |||||
import java.util.Map; | |||||
/** | |||||
* 地表水环境质量标准 服务类 | |||||
* | |||||
* @author daixiantong | |||||
* @date 2020-05-13 | |||||
*/ | |||||
public interface ITauvWaterStandardService extends IBaseService<TauvWaterStandard> { | |||||
/** | |||||
* 自定义分类列表 | |||||
* @param query | |||||
* @return | |||||
*/ | |||||
Response getPageList(TauvWaterStandardQuery query); | |||||
/** | |||||
* 添加、编辑标准 | |||||
* @param waterStandard | |||||
* @return | |||||
*/ | |||||
Response editStandard(TauvWaterStandard waterStandard); | |||||
/** | |||||
* 删除 | |||||
* @param waterStandard | |||||
* @return | |||||
*/ | |||||
Response dropStandard(TauvWaterStandard waterStandard); | |||||
} |
package com.taauav.admin.service.impl; | |||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; | |||||
import com.baomidou.mybatisplus.core.metadata.IPage; | |||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | |||||
import com.taauav.admin.entity.TauvWaterStandard; | |||||
import com.taauav.admin.mapper.TauvWaterStandardMapper; | |||||
import com.taauav.admin.query.TauvWaterStandardQuery; | |||||
import com.taauav.admin.service.ITauvWaterStandardService; | |||||
import com.taauav.common.bean.Response; | |||||
import com.taauav.common.service.impl.BaseServiceImpl; | |||||
import com.taauav.common.util.DateUtil; | |||||
import com.taauav.common.util.ShiroUtils; | |||||
import com.taauav.common.util.StringUtils; | |||||
import org.springframework.beans.factory.annotation.Value; | |||||
import org.springframework.stereotype.Service; | |||||
import javax.annotation.Resource; | |||||
/** | |||||
* 地表水环境质量标准 服务类 | |||||
* | |||||
* @author daixiantong | |||||
* @date 2020-05-13 | |||||
*/ | |||||
@Service | |||||
public class TauvWaterStandardServiceImpl extends BaseServiceImpl<TauvWaterStandardMapper, TauvWaterStandard> implements ITauvWaterStandardService { | |||||
@Value("${spring.pageSize}") | |||||
private Integer pageSize; | |||||
@Resource | |||||
private Response response; | |||||
/** | |||||
* 自定义分类列表 | |||||
* @return | |||||
*/ | |||||
@Override | |||||
public Response getPageList(TauvWaterStandardQuery query) { | |||||
IPage<TauvWaterStandard> page = new Page<>(query.getPage(), query.getPageSize()); | |||||
IPage<TauvWaterStandard> data = baseMapper.selectPage(page, null); | |||||
return response.success(data); | |||||
} | |||||
/** | |||||
* 添加、编辑 | |||||
* @param waterStandard | |||||
* @return | |||||
*/ | |||||
@Override | |||||
public Response editStandard(TauvWaterStandard waterStandard) { | |||||
if (StringUtils.isEmpty(waterStandard.getId().toString()) || waterStandard.getId() <= 0) { | |||||
waterStandard.setCreateUser(ShiroUtils.getAdminId()); | |||||
waterStandard.setCreateTime(DateUtil.now()); | |||||
} else { | |||||
waterStandard.setUpdateUser(ShiroUtils.getAdminId()); | |||||
waterStandard.setUpdateTime(DateUtil.now()); | |||||
} | |||||
Boolean res = saveOrUpdate(waterStandard); | |||||
if (!res) { | |||||
return response.failure("操作失败"); | |||||
} | |||||
return response.success("操作成功"); | |||||
} | |||||
/** | |||||
* 删除 | |||||
* @param waterStandard | |||||
* @return | |||||
*/ | |||||
@Override | |||||
public Response dropStandard(TauvWaterStandard waterStandard) { | |||||
if (StringUtils.isEmpty(waterStandard.getId().toString()) || waterStandard.getId() <= 0) { | |||||
return response.failure("质量标准id不能为空"); | |||||
} | |||||
UpdateWrapper wrapper = new UpdateWrapper(); | |||||
wrapper.eq("id", waterStandard.getId()); | |||||
wrapper.set("mark", 0); | |||||
update(wrapper); | |||||
return response.success("操作成功"); | |||||
} | |||||
} |
* @return | * @return | ||||
*/ | */ | ||||
public static SysAdmin getAdminInfo() { | public static SysAdmin getAdminInfo() { | ||||
SysAdmin admin = (SysAdmin) getObject(); | |||||
SysAdmin admin = (SysAdmin) SecurityUtils.getSubject().getPrincipal(); | |||||
return admin; | return admin; | ||||
} | } | ||||