添加序列号功能
This commit is contained in:
@@ -1,9 +1,13 @@
|
||||
package com.jsh.erp;
|
||||
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
import org.springframework.web.servlet.DispatcherServlet;
|
||||
|
||||
@SpringBootApplication
|
||||
@MapperScan(basePackages = {"com.jsh.erp.datasource.mappers"})
|
||||
@@ -15,4 +19,5 @@ public class ErpApplication{
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
29
src/main/java/com/jsh/erp/constants/BusinessConstants.java
Normal file
29
src/main/java/com/jsh/erp/constants/BusinessConstants.java
Normal file
@@ -0,0 +1,29 @@
|
||||
package com.jsh.erp.constants;
|
||||
|
||||
/**
|
||||
* @ClassName:BusinessConstants
|
||||
* @Description 业务字典类
|
||||
* @Author linshengming
|
||||
* @Date 2018-9-15 17:58
|
||||
* @Version 1.0
|
||||
**/
|
||||
public class BusinessConstants {
|
||||
|
||||
/**
|
||||
* 默认的日期格式
|
||||
*/
|
||||
public static final String DEFAULT_DATETIME_FORMAT = "yyyy-MM-dd HH:mm:ss";
|
||||
/**
|
||||
* 默认的分页起始页页码
|
||||
*/
|
||||
public static final String DEFAULT_PAGINATION_PAGE_NUMBER = "1";
|
||||
/**
|
||||
* 默认的分页页数
|
||||
*/
|
||||
public static final String DEFAULT_PAGINATION_PAGE_SIZE = "10";
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
61
src/main/java/com/jsh/erp/constants/ExceptionConstants.java
Normal file
61
src/main/java/com/jsh/erp/constants/ExceptionConstants.java
Normal file
@@ -0,0 +1,61 @@
|
||||
package com.jsh.erp.constants;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
public class ExceptionConstants {
|
||||
/**
|
||||
* code 格式 type+五位数字,例如3500000
|
||||
* ResourceInfo(value = "inOutItem", type = 35)
|
||||
*
|
||||
* */
|
||||
|
||||
public static final String GLOBAL_RETURNS_CODE = "code";
|
||||
public static final String GLOBAL_RETURNS_MESSAGE = "msg";
|
||||
public static final String GLOBAL_RETURNS_DATA = "data";
|
||||
|
||||
/**
|
||||
* 正常返回/操作成功
|
||||
**/
|
||||
public static final int SERVICE_SUCCESS_CODE = 200;
|
||||
public static final String SERVICE_SUCCESS_MSG = "操作成功";
|
||||
/**
|
||||
* 系统运行时未知错误
|
||||
**/
|
||||
public static final int SERVICE_SYSTEM_ERROR_CODE = 500;
|
||||
public static final String SERVICE_SYSTEM_ERROR_MSG = "未知异常";
|
||||
|
||||
/**
|
||||
* 序列号
|
||||
* type = 105
|
||||
* */
|
||||
/**序列号已存在*/
|
||||
public static final int SERIAL_NUMBERE_ALREADY_EXISTS_CODE = 10500000;
|
||||
public static final String SERIAL_NUMBERE_ALREADY_EXISTS_MSG = "序列号已存在";
|
||||
/**序列号不能为为空*/
|
||||
public static final int SERIAL_NUMBERE_NOT_BE_EMPTY_CODE = 10500000;
|
||||
public static final String SERIAL_NUMBERE_NOT_BE_EMPTY_MSG = "序列号不能为为空";
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 商品信息
|
||||
* type = 80
|
||||
* */
|
||||
//商品信息不存在
|
||||
public static final int MATERIAL_NOT_EXISTS_CODE = 8000000;
|
||||
public static final String MATERIAL_NOT_EXISTS__MSG = "商品信息不存在";
|
||||
//商品信息不唯一
|
||||
public static final int MATERIAL_NOT_ONLY_CODE = 8000001;
|
||||
public static final String MATERIAL_NOT_ONLY__MSG = "商品信息不唯一";
|
||||
|
||||
/**
|
||||
* 标准正常返回/操作成功返回
|
||||
* @return
|
||||
*/
|
||||
public static JSONObject standardSuccess () {
|
||||
JSONObject success = new JSONObject();
|
||||
success.put(GLOBAL_RETURNS_CODE, SERVICE_SUCCESS_CODE);
|
||||
success.put(GLOBAL_RETURNS_MESSAGE, SERVICE_SUCCESS_MSG);
|
||||
return success;
|
||||
}
|
||||
}
|
||||
106
src/main/java/com/jsh/erp/controller/SerialNumberController.java
Normal file
106
src/main/java/com/jsh/erp/controller/SerialNumberController.java
Normal file
@@ -0,0 +1,106 @@
|
||||
package com.jsh.erp.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.jsh.erp.constants.ExceptionConstants;
|
||||
import com.jsh.erp.datasource.entities.SerialNumberEx;
|
||||
import com.jsh.erp.exception.BusinessParamCheckingException;
|
||||
import com.jsh.erp.service.serialNumber.SerialNumberService;
|
||||
import com.jsh.erp.utils.StringUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @Author: cjl
|
||||
* @Date: 2019/1/22 10:29
|
||||
*/
|
||||
@RestController
|
||||
public class SerialNumberController {
|
||||
private Logger logger = LoggerFactory.getLogger(SerialNumberController.class);
|
||||
|
||||
@Resource
|
||||
private SerialNumberService serialNumberService;
|
||||
/**
|
||||
* create by: cjl
|
||||
* description:
|
||||
* 检查序列号是否存在
|
||||
* create time: 2019/1/22 11:02
|
||||
* @Param: id
|
||||
* @Param: materialName
|
||||
* @Param: serialNumber
|
||||
* @Param: request
|
||||
* @return java.lang.Object
|
||||
*/
|
||||
@PostMapping("/serialNumber/checkIsExist")
|
||||
@ResponseBody
|
||||
public Object checkIsExist(@RequestParam("id") Long id, @RequestParam("materialName") String materialName,
|
||||
@RequestParam("serialNumber") String serialNumber, HttpServletRequest request) throws Exception{
|
||||
JSONObject result = ExceptionConstants.standardSuccess();
|
||||
if(StringUtil.isEmpty(serialNumber)){
|
||||
throw new BusinessParamCheckingException(ExceptionConstants.SERIAL_NUMBERE_NOT_BE_EMPTY_CODE,
|
||||
ExceptionConstants.SERIAL_NUMBERE_NOT_BE_EMPTY_MSG);
|
||||
}
|
||||
serialNumberService.checkIsExist(id, materialName, serialNumber);
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
* create by: cjl
|
||||
* description:
|
||||
* 新增序列号信息
|
||||
* create time: 2019/1/22 17:10
|
||||
* @Param: beanJson
|
||||
* @Param: request
|
||||
* @return java.lang.Object
|
||||
*/
|
||||
@PostMapping("/serialNumber/addSerialNumber")
|
||||
@ResponseBody
|
||||
public Object addSerialNumber(@RequestParam("info") String beanJson){
|
||||
JSONObject result = ExceptionConstants.standardSuccess();
|
||||
SerialNumberEx sne= JSON.parseObject(beanJson, SerialNumberEx.class);
|
||||
serialNumberService.addSerialNumber(sne);
|
||||
return result;
|
||||
|
||||
}
|
||||
/**
|
||||
* create by: cjl
|
||||
* description:
|
||||
* 修改序列号信息
|
||||
* create time: 2019/1/23 13:56
|
||||
* @Param: beanJson
|
||||
* @return java.lang.Object
|
||||
*/
|
||||
@PostMapping("/serialNumber/updateSerialNumber")
|
||||
@ResponseBody
|
||||
public Object updateSerialNumber(@RequestParam("info") String beanJson){
|
||||
|
||||
JSONObject result = ExceptionConstants.standardSuccess();
|
||||
SerialNumberEx sne= JSON.parseObject(beanJson, SerialNumberEx.class);
|
||||
serialNumberService.updateSerialNumber(sne);
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -186,6 +186,11 @@ public class Material {
|
||||
* @mbggenerated
|
||||
*/
|
||||
private String otherfield3;
|
||||
/**
|
||||
* 2019-01-21新增字段enableSerialNumber
|
||||
*是否开启序列号
|
||||
* */
|
||||
private Boolean enableSerialNumber;
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
@@ -738,4 +743,12 @@ public class Material {
|
||||
public void setOtherfield3(String otherfield3) {
|
||||
this.otherfield3 = otherfield3 == null ? null : otherfield3.trim();
|
||||
}
|
||||
|
||||
public Boolean getEnableSerialNumber() {
|
||||
return enableSerialNumber;
|
||||
}
|
||||
|
||||
public void setEnableSerialNumber(Boolean enableSerialNumber) {
|
||||
this.enableSerialNumber = enableSerialNumber;
|
||||
}
|
||||
}
|
||||
@@ -55,6 +55,11 @@ public class MaterialVo4Unit {
|
||||
private String categoryName;
|
||||
|
||||
private String materialOther;
|
||||
/**
|
||||
* 2019-01-21新增字段enableSerialNumber
|
||||
*是否开启序列号
|
||||
* */
|
||||
private Boolean enableSerialNumber;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
@@ -263,4 +268,12 @@ public class MaterialVo4Unit {
|
||||
public void setMaterialOther(String materialOther) {
|
||||
this.materialOther = materialOther;
|
||||
}
|
||||
|
||||
public Boolean getEnableSerialNumber() {
|
||||
return enableSerialNumber;
|
||||
}
|
||||
|
||||
public void setEnableSerialNumber(Boolean enableSerialNumber) {
|
||||
this.enableSerialNumber = enableSerialNumber;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.jsh.erp.datasource.entities;
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @Author: cjl
|
||||
* @Date: 2019/1/21 17:32
|
||||
*/
|
||||
public class SerialNumberEx extends SerialNumber{
|
||||
/**
|
||||
* 商品名称
|
||||
* */
|
||||
private String materialName;
|
||||
/**
|
||||
* 创建者名称
|
||||
* */
|
||||
private String creatorName;
|
||||
/**
|
||||
* 更新者名称
|
||||
* */
|
||||
private String updaterName;
|
||||
|
||||
public String getMaterialName() {
|
||||
return materialName;
|
||||
}
|
||||
|
||||
public void setMaterialName(String materialName) {
|
||||
this.materialName = materialName;
|
||||
}
|
||||
|
||||
public String getCreatorName() {
|
||||
return creatorName;
|
||||
}
|
||||
|
||||
public void setCreatorName(String creatorName) {
|
||||
this.creatorName = creatorName;
|
||||
}
|
||||
|
||||
public String getUpdaterName() {
|
||||
return updaterName;
|
||||
}
|
||||
|
||||
public void setUpdaterName(String updaterName) {
|
||||
this.updaterName = updaterName;
|
||||
}
|
||||
}
|
||||
@@ -96,35 +96,5 @@ public interface MaterialMapper {
|
||||
*/
|
||||
int updateByPrimaryKey(Material record);
|
||||
|
||||
List<MaterialVo4Unit> selectByConditionMaterial(
|
||||
@Param("name") String name,
|
||||
@Param("model") String model,
|
||||
@Param("categoryId") Long categoryId,
|
||||
@Param("categoryIds") String categoryIds,
|
||||
@Param("mpList") String mpList,
|
||||
@Param("offset") Integer offset,
|
||||
@Param("rows") Integer rows);
|
||||
|
||||
int countsByMaterial(
|
||||
@Param("name") String name,
|
||||
@Param("model") String model,
|
||||
@Param("categoryId") Long categoryId,
|
||||
@Param("categoryIds") String categoryIds,
|
||||
@Param("mpList") String mpList);
|
||||
|
||||
String findUnitName(@Param("mId") Long mId);
|
||||
|
||||
List<MaterialVo4Unit> findById(@Param("id") Long id);
|
||||
|
||||
List<MaterialVo4Unit> findBySelect();
|
||||
|
||||
int updatePriceNullByPrimaryKey(Long id);
|
||||
|
||||
int updateUnitIdNullByPrimaryKey(Long id);
|
||||
|
||||
List<MaterialVo4Unit> findByAll(
|
||||
@Param("name") String name,
|
||||
@Param("model") String model,
|
||||
@Param("categoryId") Long categoryId,
|
||||
@Param("categoryIds") String categoryIds);
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.jsh.erp.datasource.mappers;
|
||||
|
||||
import com.jsh.erp.datasource.entities.Material;
|
||||
import com.jsh.erp.datasource.entities.MaterialVo4Unit;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @Author: cjl
|
||||
* @Date: 2019/1/22 14:54
|
||||
*/
|
||||
public interface MaterialMapperEx {
|
||||
|
||||
List<MaterialVo4Unit> selectByConditionMaterial(
|
||||
@Param("name") String name,
|
||||
@Param("model") String model,
|
||||
@Param("categoryId") Long categoryId,
|
||||
@Param("categoryIds") String categoryIds,
|
||||
@Param("mpList") String mpList,
|
||||
@Param("offset") Integer offset,
|
||||
@Param("rows") Integer rows);
|
||||
|
||||
int countsByMaterial(
|
||||
@Param("name") String name,
|
||||
@Param("model") String model,
|
||||
@Param("categoryId") Long categoryId,
|
||||
@Param("categoryIds") String categoryIds,
|
||||
@Param("mpList") String mpList);
|
||||
|
||||
String findUnitName(@Param("mId") Long mId);
|
||||
|
||||
List<MaterialVo4Unit> findById(@Param("id") Long id);
|
||||
|
||||
List<MaterialVo4Unit> findBySelect();
|
||||
|
||||
int updatePriceNullByPrimaryKey(Long id);
|
||||
|
||||
int updateUnitIdNullByPrimaryKey(Long id);
|
||||
|
||||
List<MaterialVo4Unit> findByAll(
|
||||
@Param("name") String name,
|
||||
@Param("model") String model,
|
||||
@Param("categoryId") Long categoryId,
|
||||
@Param("categoryIds") String categoryIds);
|
||||
/**
|
||||
* 通过商品名称查询商品信息
|
||||
* */
|
||||
List<Material> findByMaterialName(@Param("name") String name);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.jsh.erp.datasource.mappers;
|
||||
|
||||
import com.jsh.erp.datasource.entities.SerialNumber;
|
||||
import com.jsh.erp.datasource.entities.SerialNumberEx;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @Author: cjl
|
||||
* @Date: 2019/1/21 17:09
|
||||
*/
|
||||
public interface SerialNumberMapperEx {
|
||||
/**
|
||||
* 根据条件查询序列号列表
|
||||
* */
|
||||
List<SerialNumberEx> selectByConditionSerialNumber(@Param("serialNumber") String serialNumber, @Param("materialName") String materialName,@Param("offset") Integer offset,@Param("rows") Integer rows);
|
||||
/**
|
||||
* 根据条件查询序列号数量
|
||||
* */
|
||||
int countSerialNumber(@Param("serialNumber")String serialNumber,@Param("materialName")String materialName);
|
||||
/**
|
||||
* 通过id查询序列号复合信息
|
||||
* */
|
||||
List<SerialNumberEx> findById(Long id);
|
||||
/**
|
||||
* 通过序列号查询序列号实体信息
|
||||
* */
|
||||
List<SerialNumberEx> findBySerialNumber(@Param("serialNumber") String serialNumber);
|
||||
/**
|
||||
* 新增序列号信息
|
||||
* */
|
||||
int addSerialNumber(SerialNumberEx serialNumberEx);
|
||||
/**
|
||||
* 修改序列号信息
|
||||
* */
|
||||
int updateSerialNumber(SerialNumberEx serialNumberEx);
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.jsh.erp.exception;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
@Getter
|
||||
public class BusinessParamCheckingException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private int code;
|
||||
private String reason;
|
||||
|
||||
public BusinessParamCheckingException(int code, String reason) {
|
||||
super(reason);
|
||||
this.code = code;
|
||||
this.reason = reason;
|
||||
}
|
||||
|
||||
public BusinessParamCheckingException(int code, String reason, Throwable throwable) {
|
||||
super(reason, throwable);
|
||||
this.code = code;
|
||||
this.reason = reason;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.jsh.erp.exception;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
@Getter
|
||||
public class BusinessRunTimeException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private int code;
|
||||
private String reason;
|
||||
|
||||
public BusinessRunTimeException(int code, String reason) {
|
||||
super(reason);
|
||||
this.code = code;
|
||||
this.reason = reason;
|
||||
}
|
||||
|
||||
public BusinessRunTimeException(int code, String reason, Throwable throwable) {
|
||||
super(reason, throwable);
|
||||
this.code = code;
|
||||
this.reason = reason;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.jsh.erp.exception;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.jsh.erp.constants.ExceptionConstants;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
@Slf4j
|
||||
@RestControllerAdvice
|
||||
public class GlobalExceptionHandler {
|
||||
|
||||
@ExceptionHandler(value = Exception.class)
|
||||
@ResponseBody
|
||||
public Object handleException(Exception e, HttpServletRequest request) {
|
||||
JSONObject status = new JSONObject();
|
||||
|
||||
// 针对业务参数异常的处理
|
||||
if (e instanceof BusinessParamCheckingException) {
|
||||
status.put(ExceptionConstants.GLOBAL_RETURNS_CODE, ((BusinessParamCheckingException) e).getCode());
|
||||
status.put(ExceptionConstants.GLOBAL_RETURNS_MESSAGE, ((BusinessParamCheckingException) e).getReason());
|
||||
return status;
|
||||
}
|
||||
|
||||
//针对业务运行时异常的处理
|
||||
if (e instanceof BusinessRunTimeException) {
|
||||
status.put(ExceptionConstants.GLOBAL_RETURNS_CODE, ((BusinessRunTimeException) e).getCode());
|
||||
status.put(ExceptionConstants.GLOBAL_RETURNS_MESSAGE, ((BusinessRunTimeException) e).getReason());
|
||||
return status;
|
||||
}
|
||||
|
||||
status.put(ExceptionConstants.GLOBAL_RETURNS_CODE, ExceptionConstants.SERVICE_SYSTEM_ERROR_CODE);
|
||||
status.put(ExceptionConstants.GLOBAL_RETURNS_MESSAGE, ExceptionConstants.SERVICE_SYSTEM_ERROR_MSG);
|
||||
log.error("Global Exception Occured => url : {}, msg : {}", request.getRequestURL(), e.getMessage());
|
||||
e.printStackTrace();
|
||||
return status;
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import com.jsh.erp.datasource.entities.Material;
|
||||
import com.jsh.erp.datasource.entities.MaterialExample;
|
||||
import com.jsh.erp.datasource.entities.MaterialVo4Unit;
|
||||
import com.jsh.erp.datasource.mappers.MaterialMapper;
|
||||
import com.jsh.erp.datasource.mappers.MaterialMapperEx;
|
||||
import com.jsh.erp.utils.BaseResponseInfo;
|
||||
import com.jsh.erp.utils.StringUtil;
|
||||
import org.slf4j.Logger;
|
||||
@@ -25,6 +26,8 @@ public class MaterialService {
|
||||
|
||||
@Resource
|
||||
private MaterialMapper materialMapper;
|
||||
@Resource
|
||||
private MaterialMapperEx materialMapperEx;
|
||||
|
||||
public Material getMaterial(long id) {
|
||||
return materialMapper.selectByPrimaryKey(id);
|
||||
@@ -38,7 +41,7 @@ public class MaterialService {
|
||||
public List<MaterialVo4Unit> select(String name, String model,Long categoryId, String categoryIds,String mpList, int offset, int rows) {
|
||||
String[] mpArr = mpList.split(",");
|
||||
List<MaterialVo4Unit> resList = new ArrayList<MaterialVo4Unit>();
|
||||
List<MaterialVo4Unit> list = materialMapper.selectByConditionMaterial(name, model,categoryId,categoryIds,mpList, offset, rows);
|
||||
List<MaterialVo4Unit> list = materialMapperEx.selectByConditionMaterial(name, model,categoryId,categoryIds,mpList, offset, rows);
|
||||
if (null != list) {
|
||||
for (MaterialVo4Unit m : list) {
|
||||
//扩展信息
|
||||
@@ -71,7 +74,7 @@ public class MaterialService {
|
||||
}
|
||||
|
||||
public int countMaterial(String name, String model,Long categoryId, String categoryIds,String mpList) {
|
||||
return materialMapper.countsByMaterial(name, model,categoryId,categoryIds,mpList);
|
||||
return materialMapperEx.countsByMaterial(name, model,categoryId,categoryIds,mpList);
|
||||
}
|
||||
|
||||
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
|
||||
@@ -88,9 +91,9 @@ public class MaterialService {
|
||||
int res = materialMapper.updateByPrimaryKeySelective(material);
|
||||
Long unitId = material.getUnitid();
|
||||
if(unitId != null) {
|
||||
materialMapper.updatePriceNullByPrimaryKey(id); //将价格置空
|
||||
materialMapperEx.updatePriceNullByPrimaryKey(id); //将价格置空
|
||||
} else {
|
||||
materialMapper.updateUnitIdNullByPrimaryKey(id); //将多单位置空
|
||||
materialMapperEx.updateUnitIdNullByPrimaryKey(id); //将多单位置空
|
||||
}
|
||||
return res;
|
||||
}
|
||||
@@ -146,15 +149,15 @@ public class MaterialService {
|
||||
}
|
||||
|
||||
public String findUnitName(Long mId){
|
||||
return materialMapper.findUnitName(mId);
|
||||
return materialMapperEx.findUnitName(mId);
|
||||
}
|
||||
|
||||
public List<MaterialVo4Unit> findById(Long id){
|
||||
return materialMapper.findById(id);
|
||||
return materialMapperEx.findById(id);
|
||||
}
|
||||
|
||||
public List<MaterialVo4Unit> findBySelect(){
|
||||
return materialMapper.findBySelect();
|
||||
return materialMapperEx.findBySelect();
|
||||
}
|
||||
|
||||
public List<Material> findByOrder(){
|
||||
@@ -165,7 +168,7 @@ public class MaterialService {
|
||||
|
||||
public List<MaterialVo4Unit> findByAll(String name, String model, Long categoryId, String categoryIds) {
|
||||
List<MaterialVo4Unit> resList = new ArrayList<MaterialVo4Unit>();
|
||||
List<MaterialVo4Unit> list = materialMapper.findByAll(name, model, categoryId, categoryIds);
|
||||
List<MaterialVo4Unit> list = materialMapperEx.findByAll(name, model, categoryId, categoryIds);
|
||||
if (null != list) {
|
||||
for (MaterialVo4Unit m : list) {
|
||||
resList.add(m);
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
package com.jsh.erp.service.serialNumber;
|
||||
|
||||
import com.jsh.erp.service.ICommonQuery;
|
||||
import com.jsh.erp.service.material.MaterialResource;
|
||||
import com.jsh.erp.service.material.MaterialService;
|
||||
import com.jsh.erp.utils.Constants;
|
||||
import com.jsh.erp.utils.QueryUtils;
|
||||
import com.jsh.erp.utils.StringUtil;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @Author: cjl
|
||||
* @Date: 2019/1/21 16:33
|
||||
*/
|
||||
@Service(value = "serialNumber_component")
|
||||
@SerialNumberResource
|
||||
public class SerialNumberComponent implements ICommonQuery {
|
||||
@Resource
|
||||
private SerialNumberService serialNumberService;
|
||||
|
||||
@Override
|
||||
public Object selectOne(String condition) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<?> select(Map<String, String> map) {
|
||||
return getSerialNumberList(map);
|
||||
}
|
||||
|
||||
private List<?> getSerialNumberList(Map<String, String> map) {
|
||||
String search = map.get(Constants.SEARCH);
|
||||
String serialNumber = StringUtil.getInfo(search, "serialNumber");
|
||||
String materialName = StringUtil.getInfo(search, "materialName");
|
||||
return serialNumberService.select(serialNumber,materialName,QueryUtils.offset(map), QueryUtils.rows(map));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int counts(Map<String, String> map) {
|
||||
String search = map.get(Constants.SEARCH);
|
||||
String serialNumber = StringUtil.getInfo(search, "serialNumber");
|
||||
String materialName = StringUtil.getInfo(search, "materialName");
|
||||
return serialNumberService.countSerialNumber(serialNumber, materialName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int insert(String beanJson, HttpServletRequest request) {
|
||||
return serialNumberService.insertSerialNumber(beanJson, request);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int update(String beanJson, Long id) {
|
||||
return serialNumberService.updateSerialNumber(beanJson, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int delete(Long id) {
|
||||
return serialNumberService.deleteSerialNumber(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int batchDelete(String ids) {
|
||||
return serialNumberService.batchDeleteSerialNumber(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int checkIsNameExist(Long id, String serialNumber) {
|
||||
return serialNumberService.checkIsNameExist(id, serialNumber);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.jsh.erp.service.serialNumber;
|
||||
|
||||
import com.jsh.erp.service.ResourceInfo;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @Author: cjl
|
||||
* @Date: 2019/1/21 16:33
|
||||
*/
|
||||
@ResourceInfo(value = "serialNumber", type = 105)
|
||||
@Inherited
|
||||
@Target(ElementType.TYPE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface SerialNumberResource {
|
||||
}
|
||||
@@ -0,0 +1,235 @@
|
||||
package com.jsh.erp.service.serialNumber;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.jsh.erp.constants.ExceptionConstants;
|
||||
import com.jsh.erp.datasource.entities.*;
|
||||
import com.jsh.erp.datasource.mappers.MaterialMapperEx;
|
||||
import com.jsh.erp.datasource.mappers.SerialNumberMapper;
|
||||
import com.jsh.erp.datasource.mappers.SerialNumberMapperEx;
|
||||
import com.jsh.erp.exception.BusinessRunTimeException;
|
||||
import com.jsh.erp.service.material.MaterialService;
|
||||
import com.jsh.erp.utils.StringUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
* @Author: cjl
|
||||
* @Date: 2019/1/21 16:33
|
||||
*/
|
||||
@Service
|
||||
public class SerialNumberService {
|
||||
private Logger logger = LoggerFactory.getLogger(MaterialService.class);
|
||||
|
||||
@Resource
|
||||
private SerialNumberMapper serialNumberMapper;
|
||||
@Resource
|
||||
private SerialNumberMapperEx serialNumberMapperEx;
|
||||
@Resource
|
||||
private MaterialMapperEx materialMapperEx;
|
||||
|
||||
|
||||
public SerialNumber getSerialNumber(long id) {
|
||||
return serialNumberMapper.selectByPrimaryKey(id);
|
||||
}
|
||||
|
||||
public List<SerialNumber> getSerialNumber() {
|
||||
SerialNumberExample example = new SerialNumberExample();
|
||||
return serialNumberMapper.selectByExample(example);
|
||||
}
|
||||
|
||||
public List<SerialNumberEx> select(String serialNumber, String materialName, Integer offset, Integer rows) {
|
||||
return serialNumberMapperEx.selectByConditionSerialNumber(serialNumber, materialName,offset, rows);
|
||||
|
||||
}
|
||||
|
||||
public int countSerialNumber(String serialNumber,String materialName) {
|
||||
return serialNumberMapperEx.countSerialNumber(serialNumber, materialName);
|
||||
}
|
||||
|
||||
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
|
||||
public int insertSerialNumber(String beanJson, HttpServletRequest request) {
|
||||
SerialNumber serialNumber = JSONObject.parseObject(beanJson, SerialNumber.class);
|
||||
return serialNumberMapper.insertSelective(serialNumber);
|
||||
}
|
||||
|
||||
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
|
||||
public int updateSerialNumber(String beanJson, Long id) {
|
||||
SerialNumber serialNumber = JSONObject.parseObject(beanJson, SerialNumber.class);
|
||||
serialNumber.setId(id);
|
||||
int res = serialNumberMapper.updateByPrimaryKeySelective(serialNumber);
|
||||
return res;
|
||||
}
|
||||
|
||||
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
|
||||
public int deleteSerialNumber(Long id) {
|
||||
return serialNumberMapper.deleteByPrimaryKey(id);
|
||||
}
|
||||
|
||||
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
|
||||
public int batchDeleteSerialNumber(String ids) {
|
||||
List<Long> idList = StringUtil.strToLongList(ids);
|
||||
SerialNumberExample example = new SerialNumberExample();
|
||||
example.createCriteria().andIdIn(idList);
|
||||
return serialNumberMapper.deleteByExample(example);
|
||||
}
|
||||
|
||||
public int checkIsNameExist(Long id, String serialNumber) {
|
||||
SerialNumberExample example = new SerialNumberExample();
|
||||
example.createCriteria().andIdNotEqualTo(id).andSerialNumberEqualTo(serialNumber);
|
||||
List<SerialNumber> list = serialNumberMapper.selectByExample(example);
|
||||
return list.size();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
|
||||
public int batchSetEnable(Boolean enabled, String materialIDs) {
|
||||
List<Long> ids = StringUtil.strToLongList(materialIDs);
|
||||
SerialNumber serialNumber = new SerialNumber();
|
||||
SerialNumberExample example = new SerialNumberExample();
|
||||
example.createCriteria().andIdIn(ids);
|
||||
return serialNumberMapper.updateByExampleSelective(serialNumber, example);
|
||||
}
|
||||
|
||||
|
||||
public List<SerialNumberEx> findById(Long id){
|
||||
return serialNumberMapperEx.findById(id);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void checkIsExist(Long id, String materialName, String serialNumber) {
|
||||
/**
|
||||
* 商品名称不为空时,检查商品名称是否存在
|
||||
* */
|
||||
if(StringUtil.isNotEmpty(materialName)){
|
||||
List<Material> mlist = materialMapperEx.findByMaterialName(materialName);
|
||||
if(mlist==null||mlist.size()<1){
|
||||
//商品名称不存在
|
||||
throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_NOT_EXISTS_CODE,
|
||||
ExceptionConstants.MATERIAL_NOT_EXISTS__MSG);
|
||||
}else if(mlist.size()>1){
|
||||
//商品信息不唯一
|
||||
throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_NOT_ONLY_CODE,
|
||||
ExceptionConstants.MATERIAL_NOT_ONLY__MSG);
|
||||
|
||||
}
|
||||
}
|
||||
/***
|
||||
* 判断序列号是否已存在
|
||||
* */
|
||||
List <SerialNumberEx> list = serialNumberMapperEx.findBySerialNumber(serialNumber);
|
||||
if(list!=null&&list.size()>0){
|
||||
if(list.size()>1){
|
||||
//存在多个同名序列号
|
||||
throw new BusinessRunTimeException(ExceptionConstants.SERIAL_NUMBERE_ALREADY_EXISTS_CODE,
|
||||
ExceptionConstants.SERIAL_NUMBERE_ALREADY_EXISTS_MSG);
|
||||
}else{
|
||||
//存在一个序列号
|
||||
if(id==null){
|
||||
//新增,存在要添加的序列号
|
||||
throw new BusinessRunTimeException(ExceptionConstants.SERIAL_NUMBERE_ALREADY_EXISTS_CODE,
|
||||
ExceptionConstants.SERIAL_NUMBERE_ALREADY_EXISTS_MSG);
|
||||
}
|
||||
if(id.equals(list.get(0).getId())){
|
||||
//修改的是同一条数据
|
||||
}else{
|
||||
//存在一条不同的序列号信息
|
||||
throw new BusinessRunTimeException(ExceptionConstants.SERIAL_NUMBERE_ALREADY_EXISTS_CODE,
|
||||
ExceptionConstants.SERIAL_NUMBERE_ALREADY_EXISTS_MSG);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增序列号信息
|
||||
* */
|
||||
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
|
||||
public SerialNumberEx addSerialNumber(SerialNumberEx serialNumberEx) {
|
||||
if(serialNumberEx==null){
|
||||
return null;
|
||||
}
|
||||
/**处理商品id*/
|
||||
if(serialNumberEx.getMaterialId()==null){
|
||||
if(StringUtil.isNotEmpty(serialNumberEx.getMaterialName())){
|
||||
List<Material> mlist = materialMapperEx.findByMaterialName(serialNumberEx.getMaterialName());
|
||||
if(mlist==null||mlist.size()<1){
|
||||
//商品名称不存在
|
||||
throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_NOT_EXISTS_CODE,
|
||||
ExceptionConstants.MATERIAL_NOT_EXISTS__MSG);
|
||||
}else if(mlist.size()>1){
|
||||
//商品信息不唯一
|
||||
throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_NOT_ONLY_CODE,
|
||||
ExceptionConstants.MATERIAL_NOT_ONLY__MSG);
|
||||
|
||||
}else{
|
||||
serialNumberEx.setMaterialId(mlist.get(0).getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
//删除标记,默认未删除
|
||||
serialNumberEx.setDeleteFlag(false);
|
||||
//已卖出,默认未否
|
||||
serialNumberEx.setIsSell(false);
|
||||
Date date=new Date();
|
||||
serialNumberEx.setCreateTime(date);
|
||||
serialNumberEx.setUpdateTime(date);
|
||||
HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest();
|
||||
User userInfo=(User)request.getSession().getAttribute("user");
|
||||
serialNumberEx.setCreator(userInfo==null?null:userInfo.getId());
|
||||
serialNumberEx.setUpdater(userInfo==null?null:userInfo.getId());
|
||||
int result=serialNumberMapperEx.addSerialNumber(serialNumberEx);
|
||||
if(result==1){
|
||||
return serialNumberEx;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
|
||||
public SerialNumberEx updateSerialNumber(SerialNumberEx serialNumberEx) {
|
||||
if(serialNumberEx==null){
|
||||
return null;
|
||||
}
|
||||
/**处理商品id*/
|
||||
if(StringUtil.isNotEmpty(serialNumberEx.getMaterialName())){
|
||||
List<Material> mlist = materialMapperEx.findByMaterialName(serialNumberEx.getMaterialName());
|
||||
if(mlist==null||mlist.size()<1){
|
||||
//商品名称不存在
|
||||
throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_NOT_EXISTS_CODE,
|
||||
ExceptionConstants.MATERIAL_NOT_EXISTS__MSG);
|
||||
}else if(mlist.size()>1){
|
||||
//商品信息不唯一
|
||||
throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_NOT_ONLY_CODE,
|
||||
ExceptionConstants.MATERIAL_NOT_ONLY__MSG);
|
||||
|
||||
}else{
|
||||
serialNumberEx.setMaterialId(mlist.get(0).getId());
|
||||
}
|
||||
}
|
||||
Date date=new Date();
|
||||
serialNumberEx.setUpdateTime(date);
|
||||
HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest();
|
||||
User userInfo=(User)request.getSession().getAttribute("user");
|
||||
serialNumberEx.setUpdater(userInfo==null?null:userInfo.getId());
|
||||
int result = serialNumberMapperEx.updateSerialNumber(serialNumberEx);
|
||||
if(result==1){
|
||||
return serialNumberEx;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,21 +1,22 @@
|
||||
package com.jsh.erp.utils;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
/**
|
||||
* Created by jishenghua 2018-5-11 09:48:08
|
||||
*
|
||||
* @author jishenghua
|
||||
*/
|
||||
public class JsonUtils {
|
||||
|
||||
public static JSONObject ok(){
|
||||
JSONObject obj = new JSONObject();
|
||||
JSONObject tmp = new JSONObject();
|
||||
tmp.put("message", "成功");
|
||||
obj.put("code", 200);
|
||||
obj.put("data", tmp);
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
package com.jsh.erp.utils;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
/**
|
||||
* Created by jishenghua 2018-5-11 09:48:08
|
||||
*
|
||||
* @author jishenghua
|
||||
*/
|
||||
public class JsonUtils {
|
||||
|
||||
public static JSONObject ok(){
|
||||
JSONObject obj = new JSONObject();
|
||||
JSONObject tmp = new JSONObject();
|
||||
tmp.put("message", "成功");
|
||||
obj.put("code", 200);
|
||||
obj.put("data", tmp);
|
||||
return obj;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,214 +1,218 @@
|
||||
package com.jsh.erp.utils;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author jishenghua qq752718920 2018-10-7 15:26:27
|
||||
*/
|
||||
public class StringUtil {
|
||||
|
||||
private StringUtil() {
|
||||
|
||||
}
|
||||
|
||||
private static String DEFAULT_FORMAT = "yyyy-MM-dd HH:mm:ss";
|
||||
|
||||
public static String filterNull(String str) {
|
||||
if (str == null) {
|
||||
return "";
|
||||
} else {
|
||||
return str.trim();
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean stringEquels(String source,String target) {
|
||||
if(isEmpty(source)||isEmpty(target)){
|
||||
return false;
|
||||
}else{
|
||||
return source.equals(target);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isEmpty(String str) {
|
||||
return str == null || "".equals(str.trim());
|
||||
}
|
||||
|
||||
public static boolean isNotEmpty(String str) {
|
||||
return !isEmpty(str);
|
||||
}
|
||||
|
||||
public static String getSysDate(String format) {
|
||||
if (StringUtil.isEmpty(format)) {
|
||||
format = DEFAULT_FORMAT;
|
||||
}
|
||||
SimpleDateFormat df = new SimpleDateFormat(format);
|
||||
return df.format(new Date());
|
||||
}
|
||||
|
||||
public static Date getDateByString(String date, String format) {
|
||||
if (StringUtil.isEmpty(format)) {
|
||||
format = DEFAULT_FORMAT;
|
||||
}
|
||||
if (StringUtil.isNotEmpty(date)) {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat(format);
|
||||
try {
|
||||
return sdf.parse(date);
|
||||
} catch (ParseException e) {
|
||||
throw new RuntimeException("转换为日期类型错误:DATE:" + date + " FORMAT:" + format);
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static Date getDateByLongDate(Long millis) {
|
||||
if (millis == null) {
|
||||
return new Date();
|
||||
}
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.setTimeInMillis(millis);
|
||||
return cal.getTime();
|
||||
|
||||
}
|
||||
|
||||
public static UUID stringToUUID(String id) {
|
||||
if (StringUtil.isNotEmpty(id)) {
|
||||
return UUID.fromString(id);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static Integer parseInteger(String str) {
|
||||
if (StringUtil.isNotEmpty(str)) {
|
||||
return Integer.parseInt(str);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static List<UUID> listToUUID(List<String> listStrs) {
|
||||
if (listStrs != null && listStrs.size() > 0) {
|
||||
List<UUID> uuidList = new ArrayList<UUID>();
|
||||
for (String str : listStrs) {
|
||||
uuidList.add(UUID.fromString(str));
|
||||
}
|
||||
return uuidList;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static List<UUID> arrayToUUIDList(String[] uuids) {
|
||||
if (uuids != null && uuids.length > 0) {
|
||||
List<UUID> uuidList = new ArrayList<UUID>();
|
||||
for (String str : uuids) {
|
||||
uuidList.add(UUID.fromString(str));
|
||||
}
|
||||
return uuidList;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
//是否是JSON
|
||||
public static boolean containsAny(String str, String... flag) {
|
||||
if (str != null) {
|
||||
if (flag == null || flag.length == 0) {
|
||||
flag = "[-{-}-]-,".split("-");
|
||||
}
|
||||
for (String s : flag) {
|
||||
if (str.contains(s)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static String getModifyOrgOperateData(UUID resourceId, UUID orgId) {
|
||||
if (resourceId != null && orgId != null) {
|
||||
Map<UUID, UUID> map = new HashMap<UUID, UUID>();
|
||||
map.put(resourceId, orgId);
|
||||
return JSON.toJSONString(map);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public static String[] listToStringArray(List<String> list) {
|
||||
if (list != null && !list.isEmpty()) {
|
||||
return list.toArray(new String[list.size()]);
|
||||
}
|
||||
return new String[0];
|
||||
}
|
||||
|
||||
public static List<String> stringToListArray(String[] strings) {
|
||||
if (strings != null && strings.length > 0) {
|
||||
return Arrays.asList(strings);
|
||||
}
|
||||
return new ArrayList<String>();
|
||||
}
|
||||
|
||||
/**
|
||||
* String字符串转成List<Long>数据格式
|
||||
* String str = "1,2,3,4,5,6" -> List<Long> listLong [1,2,3,4,5,6];
|
||||
*
|
||||
* @param strArr
|
||||
* @return
|
||||
*/
|
||||
public static List<Long> strToLongList(String strArr) {
|
||||
List<Long> idList=new ArrayList<Long>();
|
||||
String[] d=strArr.split(",");
|
||||
for (int i = 0, size = d.length; i < size; i++) {
|
||||
if(d[i]!=null) {
|
||||
idList.add(Long.parseLong(d[i]));
|
||||
}
|
||||
}
|
||||
return idList;
|
||||
}
|
||||
|
||||
/**
|
||||
* String字符串转成List<String>数据格式
|
||||
* String str = "1,2,3,4,5,6" -> List<Long> listLong [1,2,3,4,5,6];
|
||||
*
|
||||
* @param strArr
|
||||
* @return
|
||||
*/
|
||||
public static List<String> strToStringList(String strArr) {
|
||||
List<String> idList=new ArrayList<String>();
|
||||
String[] d=strArr.split(",");
|
||||
for (int i = 0, size = d.length; i < size; i++) {
|
||||
if(d[i]!=null) {
|
||||
idList.add(d[i].toString());
|
||||
}
|
||||
}
|
||||
return idList;
|
||||
}
|
||||
|
||||
public static List<String> searchCondition(String search) {
|
||||
if (isEmpty(search)) {
|
||||
return new ArrayList<String>();
|
||||
}else{
|
||||
//String[] split = search.split(" ");
|
||||
String[] split = search.split("#");
|
||||
return stringToListArray(split);
|
||||
}
|
||||
}
|
||||
|
||||
public static String getInfo(String search, String key){
|
||||
String value = "";
|
||||
if(search!=null) {
|
||||
JSONObject obj = JSONObject.parseObject(search);
|
||||
value = obj.getString(key);
|
||||
if(value.equals("")) {
|
||||
value = null;
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
package com.jsh.erp.utils;
|
||||
|
||||
import com.alibaba.druid.util.StringUtils;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author jishenghua qq752718920 2018-10-7 15:26:27
|
||||
*/
|
||||
public class StringUtil {
|
||||
|
||||
private StringUtil() {
|
||||
|
||||
}
|
||||
|
||||
private static String DEFAULT_FORMAT = "yyyy-MM-dd HH:mm:ss";
|
||||
|
||||
public static String filterNull(String str) {
|
||||
if (str == null) {
|
||||
return "";
|
||||
} else {
|
||||
return str.trim();
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean stringEquels(String source,String target) {
|
||||
if(isEmpty(source)||isEmpty(target)){
|
||||
return false;
|
||||
}else{
|
||||
return source.equals(target);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isEmpty(String str) {
|
||||
return str == null || "".equals(str.trim());
|
||||
}
|
||||
|
||||
public static boolean isNotEmpty(String str) {
|
||||
return !isEmpty(str);
|
||||
}
|
||||
|
||||
public static String getSysDate(String format) {
|
||||
if (StringUtil.isEmpty(format)) {
|
||||
format = DEFAULT_FORMAT;
|
||||
}
|
||||
SimpleDateFormat df = new SimpleDateFormat(format);
|
||||
return df.format(new Date());
|
||||
}
|
||||
|
||||
public static Date getDateByString(String date, String format) {
|
||||
if (StringUtil.isEmpty(format)) {
|
||||
format = DEFAULT_FORMAT;
|
||||
}
|
||||
if (StringUtil.isNotEmpty(date)) {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat(format);
|
||||
try {
|
||||
return sdf.parse(date);
|
||||
} catch (ParseException e) {
|
||||
throw new RuntimeException("转换为日期类型错误:DATE:" + date + " FORMAT:" + format);
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static Date getDateByLongDate(Long millis) {
|
||||
if (millis == null) {
|
||||
return new Date();
|
||||
}
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.setTimeInMillis(millis);
|
||||
return cal.getTime();
|
||||
|
||||
}
|
||||
|
||||
public static UUID stringToUUID(String id) {
|
||||
if (StringUtil.isNotEmpty(id)) {
|
||||
return UUID.fromString(id);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static Integer parseInteger(String str) {
|
||||
if (StringUtil.isNotEmpty(str)) {
|
||||
return Integer.parseInt(str);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static List<UUID> listToUUID(List<String> listStrs) {
|
||||
if (listStrs != null && listStrs.size() > 0) {
|
||||
List<UUID> uuidList = new ArrayList<UUID>();
|
||||
for (String str : listStrs) {
|
||||
uuidList.add(UUID.fromString(str));
|
||||
}
|
||||
return uuidList;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static List<UUID> arrayToUUIDList(String[] uuids) {
|
||||
if (uuids != null && uuids.length > 0) {
|
||||
List<UUID> uuidList = new ArrayList<UUID>();
|
||||
for (String str : uuids) {
|
||||
uuidList.add(UUID.fromString(str));
|
||||
}
|
||||
return uuidList;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
//是否是JSON
|
||||
public static boolean containsAny(String str, String... flag) {
|
||||
if (str != null) {
|
||||
if (flag == null || flag.length == 0) {
|
||||
flag = "[-{-}-]-,".split("-");
|
||||
}
|
||||
for (String s : flag) {
|
||||
if (str.contains(s)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static String getModifyOrgOperateData(UUID resourceId, UUID orgId) {
|
||||
if (resourceId != null && orgId != null) {
|
||||
Map<UUID, UUID> map = new HashMap<UUID, UUID>();
|
||||
map.put(resourceId, orgId);
|
||||
return JSON.toJSONString(map);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public static String[] listToStringArray(List<String> list) {
|
||||
if (list != null && !list.isEmpty()) {
|
||||
return list.toArray(new String[list.size()]);
|
||||
}
|
||||
return new String[0];
|
||||
}
|
||||
|
||||
public static List<String> stringToListArray(String[] strings) {
|
||||
if (strings != null && strings.length > 0) {
|
||||
return Arrays.asList(strings);
|
||||
}
|
||||
return new ArrayList<String>();
|
||||
}
|
||||
|
||||
/**
|
||||
* String字符串转成List<Long>数据格式
|
||||
* String str = "1,2,3,4,5,6" -> List<Long> listLong [1,2,3,4,5,6];
|
||||
*
|
||||
* @param strArr
|
||||
* @return
|
||||
*/
|
||||
public static List<Long> strToLongList(String strArr) {
|
||||
List<Long> idList=new ArrayList<Long>();
|
||||
String[] d=strArr.split(",");
|
||||
for (int i = 0, size = d.length; i < size; i++) {
|
||||
if(d[i]!=null) {
|
||||
idList.add(Long.parseLong(d[i]));
|
||||
}
|
||||
}
|
||||
return idList;
|
||||
}
|
||||
|
||||
/**
|
||||
* String字符串转成List<String>数据格式
|
||||
* String str = "1,2,3,4,5,6" -> List<Long> listLong [1,2,3,4,5,6];
|
||||
*
|
||||
* @param strArr
|
||||
* @return
|
||||
*/
|
||||
public static List<String> strToStringList(String strArr) {
|
||||
if(StringUtils.isEmpty(strArr)){
|
||||
return null;
|
||||
}
|
||||
List<String> idList=new ArrayList<String>();
|
||||
String[] d=strArr.split(",");
|
||||
for (int i = 0, size = d.length; i < size; i++) {
|
||||
if(d[i]!=null) {
|
||||
idList.add(d[i].toString());
|
||||
}
|
||||
}
|
||||
return idList;
|
||||
}
|
||||
|
||||
public static List<String> searchCondition(String search) {
|
||||
if (isEmpty(search)) {
|
||||
return new ArrayList<String>();
|
||||
}else{
|
||||
//String[] split = search.split(" ");
|
||||
String[] split = search.split("#");
|
||||
return stringToListArray(split);
|
||||
}
|
||||
}
|
||||
|
||||
public static String getInfo(String search, String key){
|
||||
String value = "";
|
||||
if(search!=null) {
|
||||
JSONObject obj = JSONObject.parseObject(search);
|
||||
value = obj.getString(key);
|
||||
if(value.equals("")) {
|
||||
value = null;
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user