update sort
This commit is contained in:
parent
0eacfd742b
commit
61ebcf7ed6
@ -122,20 +122,24 @@ public class ApplicationServiceSupport
|
||||
final String updatedBy = form.getUpdatedBy();
|
||||
validatePerm(applicationId, updatedBy, form.isAdmin());
|
||||
|
||||
// client sort is array index
|
||||
boolean sortUpdated = false;
|
||||
final float sort = form.getSort();
|
||||
final float sortOld = appImage.getSort();
|
||||
if (sort < sortOld) {
|
||||
sortUpdated = true;
|
||||
appImage.setSort(sortOld - 1.5f);
|
||||
}
|
||||
else if (sort > sortOld) {
|
||||
sortUpdated = true;
|
||||
appImage.setSort(sortOld + 1.5f);
|
||||
}
|
||||
appImage.setNote(form.getNote());
|
||||
appImage.setDateUpdated(new Date());
|
||||
appImage.setUpdatedBy(updatedBy);
|
||||
imageMapper.update(appImage);
|
||||
imageMapper.updateSort(applicationId);
|
||||
if (sortUpdated) {
|
||||
imageMapper.listSort(applicationId).forEach(imageMapper::update);
|
||||
}
|
||||
}
|
||||
|
||||
private void uploadImages(final String applicationId, int sort, final MultipartFile[] images, final String[] titles, final String createdBy) {
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.pudonghot.ambition.crm.mapper;
|
||||
|
||||
import java.util.List;
|
||||
import me.chyxion.tigon.mybatis.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.hibernate.validator.constraints.NotBlank;
|
||||
@ -25,4 +26,14 @@ public interface ApplicationImageMapper extends BaseMapper<String, ApplicationIm
|
||||
* @return effected rows
|
||||
*/
|
||||
int updateSort(@NotBlank @Param("applicationId") String applicationId);
|
||||
|
||||
/**
|
||||
* list application images
|
||||
* @param applicationId
|
||||
* @return images
|
||||
*/
|
||||
List<ApplicationImage> listSort(
|
||||
@NotBlank
|
||||
@Param("applicationId")
|
||||
String applicationId);
|
||||
}
|
||||
|
@ -28,4 +28,16 @@
|
||||
on a.id = s.id
|
||||
set a.sort = s.sort
|
||||
</update>
|
||||
|
||||
<select id="listSort" resultType="com.pudonghot.ambition.crm.model.ApplicationImage">
|
||||
select id, application_id,
|
||||
created_by, date_created,
|
||||
updated_by, date_updated,
|
||||
enabled, note,
|
||||
@cur_row := @cur_row + 1 sort
|
||||
from <include refid="table" />
|
||||
join (select @cur_row := 0) r
|
||||
where application_id = #{applicationId}
|
||||
order by crm_application_image.sort
|
||||
</select>
|
||||
</mapper>
|
||||
|
@ -0,0 +1,32 @@
|
||||
package com.pudonghot.ambition.crm.mapper;
|
||||
|
||||
import org.junit.Test;
|
||||
import java.util.List;
|
||||
import org.junit.runner.RunWith;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import com.pudonghot.ambition.crm.model.ApplicationImage;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
|
||||
|
||||
/**
|
||||
* @version 0.0.1
|
||||
* @author Auto Generated <br>
|
||||
* Tech Support <a href="mailto:chyxion@163.com">Shaun Chyxion</a><br>
|
||||
* Jun 19, 2017 10:35:51 PM
|
||||
*/
|
||||
@Slf4j
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration("classpath*:spring/spring-*.xml")
|
||||
public class ApplicationImageMapperTest extends AbstractTransactionalJUnit4SpringContextTests {
|
||||
@Autowired
|
||||
private ApplicationImageMapper mapper;
|
||||
|
||||
@Test
|
||||
public void testListSort() {
|
||||
final List<ApplicationImage> images =
|
||||
mapper.listSort("5aadc3be13987ee957e00caf");
|
||||
log.info("Images: [{}].", images);
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
# MySQL
|
||||
datasource.host=127.0.0.1
|
||||
datasource.port=63306
|
||||
datasource.database-name=ambition_crm
|
||||
datasource.database-name=ambition_crm_test
|
||||
datasource.username=root
|
||||
datasource.password=696@2^~)oZ@^#*Q
|
||||
|
@ -5,7 +5,11 @@ export default BaseEditRoute.extend({
|
||||
afterModel(model) {
|
||||
const me = this;
|
||||
me._super(...arguments);
|
||||
// model.images = [{}];
|
||||
if (model.owner && model.users) {
|
||||
let owner = model.users.findBy('id', model.owner);
|
||||
owner && (owner.selected = true);
|
||||
}
|
||||
|
||||
this.set('breadcrumbs',
|
||||
[{route: 'customer-application.list', params: 1, text: 'Customer Application'},
|
||||
{text: 'Edit Customer Application[' + model.name + ']'}]);
|
||||
|
Loading…
x
Reference in New Issue
Block a user